1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
/*
* Copyright (C) 2008 Jacob Meuser <jakemsr@sdf.lonestar.org>
* Copyright (C) 2012 Alexandre Ratchov <alex@caoua.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* SECTION:element-sndiosink
* @see_also: #GstAutoAudioSink
*
* <refsect2>
* <para>
* This element outputs sound to a sound card using sndio.
* </para>
* <para>
* Simple example pipeline that plays an Ogg/Vorbis file via sndio:
* <programlisting>
* gst-launch -v filesrc location=foo.ogg ! decodebin ! audioconvert ! audioresample ! sndiosink
* </programlisting>
* </para>
* </refsect2>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "sndiosink.h"
GST_DEBUG_CATEGORY_EXTERN (gst_sndio_debug);
#define GST_CAT_DEFAULT gst_sndio_debug
#define gst_sndiosink_parent_class parent_class
static GstStaticPadTemplate sndiosink_factory =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_SNDIO_CAPS_STRING)
);
G_DEFINE_TYPE_WITH_CODE (GstSndioSink, gst_sndiosink, GST_TYPE_AUDIO_SINK,
G_IMPLEMENT_INTERFACE (GST_TYPE_STREAM_VOLUME, NULL));
static void gst_sndiosink_finalize (GObject * object);
static GstCaps *gst_sndiosink_getcaps (GstBaseSink * bsink,
GstCaps * filter);
static gboolean gst_sndiosink_open (GstAudioSink * asink);
static gboolean gst_sndiosink_close (GstAudioSink * asink);
static gboolean gst_sndiosink_prepare (GstAudioSink * asink,
GstAudioRingBufferSpec * spec);
static gboolean gst_sndiosink_unprepare (GstAudioSink * asink);
static gint gst_sndiosink_write (GstAudioSink * asink, gpointer data,
guint length);
static guint gst_sndiosink_delay (GstAudioSink * asink);
static void gst_sndiosink_reset (GstAudioSink * asink);
static void gst_sndiosink_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_sndiosink_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static void
gst_sndiosink_init (GstSndioSink * sink)
{
gst_sndio_init (&sink->sndio, G_OBJECT(sink));
}
static void
gst_sndiosink_finalize (GObject * object)
{
GstSndioSink *sink = GST_SNDIOSINK (object);
gst_sndio_finalize (&sink->sndio);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static GstCaps *
gst_sndiosink_getcaps (GstBaseSink * bsink, GstCaps * filter)
{
GstSndioSink *sink = GST_SNDIOSINK (bsink);
return gst_sndio_getcaps (&sink->sndio, filter);
}
static gboolean
gst_sndiosink_open (GstAudioSink * asink)
{
GstSndioSink *sink = GST_SNDIOSINK (asink);
return gst_sndio_open (&sink->sndio, SIO_PLAY);
}
static gboolean
gst_sndiosink_close (GstAudioSink * asink)
{
GstSndioSink *sink = GST_SNDIOSINK (asink);
return gst_sndio_close (&sink->sndio);
}
static gboolean
gst_sndiosink_prepare (GstAudioSink * asink, GstAudioRingBufferSpec * spec)
{
GstSndioSink *sink = GST_SNDIOSINK (asink);
return gst_sndio_prepare (&sink->sndio, spec);
}
static gboolean
gst_sndiosink_unprepare (GstAudioSink * asink)
{
GstSndioSink *sink = GST_SNDIOSINK (asink);
return gst_sndio_unprepare (&sink->sndio);
}
static gint
gst_sndiosink_write (GstAudioSink * asink, gpointer data, guint length)
{
GstSndioSink *sink = GST_SNDIOSINK (asink);
guint done;
if (length == 0)
return 0;
done = sio_write (sink->sndio.hdl, data, length);
if (done == 0) {
GST_ELEMENT_ERROR (sink, RESOURCE, WRITE,
("Failed to write data to sndio"), (NULL));
return 0;
}
sink->sndio.delay += done;
return done;
}
static guint
gst_sndiosink_delay (GstAudioSink * asink)
{
GstSndioSink *sink = GST_SNDIOSINK (asink);
return GST_SNDIO_DELAY(&sink->sndio);
}
static void
gst_sndiosink_reset (GstAudioSink * asink)
{
}
static void
gst_sndiosink_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstSndioSink *sink = GST_SNDIOSINK (object);
gst_sndio_set_property (&sink->sndio, prop_id, value, pspec);
}
static void
gst_sndiosink_get_property (GObject * object, guint prop_id, GValue * value,
GParamSpec * pspec)
{
GstSndioSink *sink = GST_SNDIOSINK (object);
gst_sndio_get_property (&sink->sndio, prop_id, value, pspec);
}
static void
gst_sndiosink_class_init (GstSndioSinkClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *gstelement_class;
GstBaseSinkClass *gstbasesink_class;
GstAudioBaseSinkClass *gstbaseaudiosink_class;
GstAudioSinkClass *gstaudiosink_class;
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
gstbasesink_class = (GstBaseSinkClass *) klass;
gstbaseaudiosink_class = (GstAudioBaseSinkClass *) klass;
gstaudiosink_class = (GstAudioSinkClass *) klass;
parent_class = g_type_class_peek_parent (klass);
gobject_class->finalize = gst_sndiosink_finalize;
gobject_class->get_property = gst_sndiosink_get_property;
gobject_class->set_property = gst_sndiosink_set_property;
gst_element_class_set_static_metadata (gstelement_class,
"Audio sink (sndio)", "Sink/Audio",
"Output to a sound card via sndio",
"Jacob Meuser <jakemsr@sdf.lonestar.org>");
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&sndiosink_factory));
gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_sndiosink_getcaps);
gstaudiosink_class->open = GST_DEBUG_FUNCPTR (gst_sndiosink_open);
gstaudiosink_class->prepare = GST_DEBUG_FUNCPTR (gst_sndiosink_prepare);
gstaudiosink_class->unprepare = GST_DEBUG_FUNCPTR (gst_sndiosink_unprepare);
gstaudiosink_class->close = GST_DEBUG_FUNCPTR (gst_sndiosink_close);
gstaudiosink_class->write = GST_DEBUG_FUNCPTR (gst_sndiosink_write);
gstaudiosink_class->delay = GST_DEBUG_FUNCPTR (gst_sndiosink_delay);
gstaudiosink_class->reset = GST_DEBUG_FUNCPTR (gst_sndiosink_reset);
g_object_class_install_property (gobject_class, PROP_DEVICE,
g_param_spec_string ("device", "Device",
"sndio device as defined in sndio(7)",
SIO_DEVANY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_VOLUME,
g_param_spec_double ("volume", "Volume",
"Linear volume of this stream, 1.0=100%", 0.0, 1.0,
1.0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_MUTE,
g_param_spec_boolean ("mute", "Mute",
"Mute state of this stream", FALSE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
}
|