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