diff options
| author | Vineet Kumar <git@vineetk.net> | 2026-06-15 14:54:51 -0400 |
|---|---|---|
| committer | Vineet Kumar <git@vineetk.net> | 2026-06-15 14:54:51 -0400 |
| commit | e81f04fa53e7e01afdc834d9c22b5c982c98f59b (patch) | |
| tree | 763d6d68516ca9d184ddd2402978adcc4027a99d /multimedia/gstreamer1/plugins-base/files/gstsndio.c | |
| parent | 92e45e47c29ec037842c4a34ebc0c14143d413ff (diff) | |
This is due to the following two reasons:
1. it's very out of date compared with current ports tree (like by 2+
years!)
- some of the ports here were mainly just updates I didn't upstream,
which have since now been part of openbsd, like verilator
2. removing dependencies is a lot of headache to stay in sync and/or for
ports I no longer use
- e.g. dbus is very difficult to remove in a desktop while patching
to remove from gtk and downstream
- I don't want to spend more time reducing number of dependencies
when I can be working instead. I no longer have as much free time
as I did in high school :(
Diffstat (limited to 'multimedia/gstreamer1/plugins-base/files/gstsndio.c')
| -rw-r--r-- | multimedia/gstreamer1/plugins-base/files/gstsndio.c | 403 |
1 files changed, 0 insertions, 403 deletions
diff --git a/multimedia/gstreamer1/plugins-base/files/gstsndio.c b/multimedia/gstreamer1/plugins-base/files/gstsndio.c deleted file mode 100644 index 45644db..0000000 --- a/multimedia/gstreamer1/plugins-base/files/gstsndio.c +++ /dev/null | |||
| @@ -1,403 +0,0 @@ | |||
| 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 | #ifdef HAVE_CONFIG_H | ||
| 19 | #include "config.h" | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #include <stdio.h> | ||
| 23 | #include "gstsndio.h" | ||
| 24 | |||
| 25 | GST_DEBUG_CATEGORY (gst_sndio_debug); | ||
| 26 | #define GST_CAT_DEFAULT gst_sndio_debug | ||
| 27 | |||
| 28 | GType gst_sndiosink_get_type (void); | ||
| 29 | GType gst_sndiosrc_get_type (void); | ||
| 30 | |||
| 31 | static gboolean | ||
| 32 | plugin_init (GstPlugin * plugin) | ||
| 33 | { | ||
| 34 | GST_DEBUG_CATEGORY_INIT (gst_sndio_debug, "sndio", 0, "sndio plugins"); | ||
| 35 | |||
| 36 | /* prefer sndiosrc over pulsesrc (GST_RANK_PRIMARY + 10) */ | ||
| 37 | if (!gst_element_register (plugin, "sndiosrc", GST_RANK_PRIMARY + 20, | ||
| 38 | gst_sndiosrc_get_type())) | ||
| 39 | return FALSE; | ||
| 40 | /* prefer sndiosink over pulsesink (GST_RANK_PRIMARY + 10) */ | ||
| 41 | if (!gst_element_register (plugin, "sndiosink", GST_RANK_PRIMARY + 20, | ||
| 42 | gst_sndiosink_get_type())) | ||
| 43 | return FALSE; | ||
| 44 | return TRUE; | ||
| 45 | } | ||
| 46 | |||
| 47 | GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, | ||
| 48 | GST_VERSION_MINOR, | ||
| 49 | sndio, | ||
| 50 | "sndio plugin library", | ||
| 51 | plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN) | ||
| 52 | |||
| 53 | /* | ||
| 54 | * common code to src and sink | ||
| 55 | */ | ||
| 56 | |||
| 57 | void | ||
| 58 | gst_sndio_init (struct gstsndio *sio, GObject *obj) | ||
| 59 | { | ||
| 60 | sio->obj = obj; | ||
| 61 | sio->hdl = NULL; | ||
| 62 | sio->device = g_strdup (SIO_DEVANY); | ||
| 63 | /* XXX not implemented; only used for src, not sink */ | ||
| 64 | // sio->driver_timestamps = FALSE; | ||
| 65 | } | ||
| 66 | |||
| 67 | void | ||
| 68 | gst_sndio_finalize (struct gstsndio *sio) | ||
| 69 | { | ||
| 70 | gst_caps_replace (&sio->cur_caps, NULL); | ||
| 71 | g_free (sio->device); | ||
| 72 | } | ||
| 73 | |||
| 74 | GstCaps * | ||
| 75 | gst_sndio_getcaps (struct gstsndio *sio, GstCaps * filter) | ||
| 76 | { | ||
| 77 | if (sio->cur_caps == NULL) { | ||
| 78 | /* XXX */ | ||
| 79 | GST_LOG_OBJECT (sio->obj, "getcaps called, returning template caps"); | ||
| 80 | return NULL; | ||
| 81 | } | ||
| 82 | |||
| 83 | GST_LOG_OBJECT (sio->obj, "returning %" GST_PTR_FORMAT, sio->cur_caps); | ||
| 84 | |||
| 85 | if (filter) { | ||
| 86 | return gst_caps_intersect_full (filter, | ||
| 87 | sio->cur_caps, GST_CAPS_INTERSECT_FIRST); | ||
| 88 | } else { | ||
| 89 | return gst_caps_ref (sio->cur_caps); | ||
| 90 | } | ||
| 91 | } | ||
| 92 | |||
| 93 | static void | ||
| 94 | gst_sndio_onvol (void *arg, unsigned int vol) | ||
| 95 | { | ||
| 96 | struct gstsndio *sio = arg; | ||
| 97 | sio->volume = vol; | ||
| 98 | g_object_notify (G_OBJECT (sio->obj), "mute"); | ||
| 99 | g_object_notify (G_OBJECT (sio->obj), "volume"); | ||
| 100 | } | ||
| 101 | |||
| 102 | gboolean | ||
| 103 | gst_sndio_open (struct gstsndio *sio, gint mode) | ||
| 104 | { | ||
| 105 | GValue list = G_VALUE_INIT, item = G_VALUE_INIT; | ||
| 106 | GstStructure *s; | ||
| 107 | GstCaps *caps; | ||
| 108 | struct sio_enc *enc; | ||
| 109 | struct sio_cap cap; | ||
| 110 | char fmt[16]; | ||
| 111 | int i, chan; | ||
| 112 | |||
| 113 | GST_DEBUG_OBJECT (sio->obj, "open"); | ||
| 114 | |||
| 115 | sio->hdl = sio_open (sio->device, mode, 0); | ||
| 116 | if (sio->hdl == NULL) { | ||
| 117 | GST_ELEMENT_ERROR (sio->obj, RESOURCE, OPEN_READ_WRITE, | ||
| 118 | ("Couldn't open sndio device"), (NULL)); | ||
| 119 | return FALSE; | ||
| 120 | } | ||
| 121 | sio->mode = mode; | ||
| 122 | |||
| 123 | if (!sio_getcap(sio->hdl, &cap)) { | ||
| 124 | GST_ELEMENT_ERROR (sio, RESOURCE, OPEN_WRITE, | ||
| 125 | ("Couldn't get device capabilities"), (NULL)); | ||
| 126 | sio_close(sio->hdl); | ||
| 127 | sio->hdl = NULL; | ||
| 128 | return FALSE; | ||
| 129 | } | ||
| 130 | if (cap.nconf == 0) { | ||
| 131 | GST_ELEMENT_ERROR (sio, RESOURCE, OPEN_WRITE, | ||
| 132 | ("Device has empty capabilities"), (NULL)); | ||
| 133 | sio_close(sio->hdl); | ||
| 134 | sio->hdl = NULL; | ||
| 135 | return FALSE; | ||
| 136 | } | ||
| 137 | sio_onvol (sio->hdl, gst_sndio_onvol, sio); | ||
| 138 | |||
| 139 | caps = gst_caps_new_empty (); | ||
| 140 | s = gst_structure_new ("audio/x-raw", (char *)NULL, (void *)NULL); | ||
| 141 | |||
| 142 | /* | ||
| 143 | * scan supported rates | ||
| 144 | */ | ||
| 145 | g_value_init (&list, GST_TYPE_LIST); | ||
| 146 | g_value_init (&item, G_TYPE_INT); | ||
| 147 | for (i = 0; i < SIO_NRATE; i++) { | ||
| 148 | if ((cap.confs[0].rate & (1 << i)) == 0) | ||
| 149 | continue; | ||
| 150 | g_value_set_int(&item, cap.rate[i]); | ||
| 151 | gst_value_list_append_value (&list, &item); | ||
| 152 | } | ||
| 153 | gst_structure_set_value (s, "rate", &list); | ||
| 154 | g_value_unset (&item); | ||
| 155 | g_value_unset (&list); | ||
| 156 | |||
| 157 | /* | ||
| 158 | * scan supported channels | ||
| 159 | */ | ||
| 160 | g_value_init (&list, GST_TYPE_LIST); | ||
| 161 | g_value_init (&item, G_TYPE_INT); | ||
| 162 | chan = (mode == SIO_PLAY) ? cap.confs[0].pchan : cap.confs[0].rchan; | ||
| 163 | for (i = 0; i < SIO_NCHAN; i++) { | ||
| 164 | if ((chan & (1 << i)) == 0) | ||
| 165 | continue; | ||
| 166 | g_value_set_int(&item, (mode == SIO_PLAY) ? cap.pchan[i] : cap.rchan[i]); | ||
| 167 | gst_value_list_append_value (&list, &item); | ||
| 168 | } | ||
| 169 | gst_structure_set_value (s, "channels", &list); | ||
| 170 | g_value_unset (&item); | ||
| 171 | g_value_unset (&list); | ||
| 172 | |||
| 173 | /* | ||
| 174 | * scan supported encodings | ||
| 175 | */ | ||
| 176 | g_value_init (&list, GST_TYPE_LIST); | ||
| 177 | g_value_init (&item, G_TYPE_STRING); | ||
| 178 | for (i = 0; i < SIO_NENC; i++) { | ||
| 179 | if ((cap.confs[0].enc & (1 << i)) == 0) | ||
| 180 | continue; | ||
| 181 | enc = cap.enc + i; | ||
| 182 | if (enc->bits % 8 != 0) | ||
| 183 | continue; | ||
| 184 | if (enc->bits < enc->bps * 8 && enc->msb) | ||
| 185 | continue; | ||
| 186 | if (enc->bits == enc->bps * 8) { | ||
| 187 | snprintf(fmt, sizeof(fmt), "%s%u%s", | ||
| 188 | enc->sig ? "S" : "U", | ||
| 189 | enc->bits, | ||
| 190 | enc->bps > 1 ? (enc->le ? "LE" : "BE") : ""); | ||
| 191 | } else { | ||
| 192 | snprintf(fmt, sizeof(fmt), "%s%u_%u%s", | ||
| 193 | enc->sig ? "S" : "U", | ||
| 194 | enc->bits, | ||
| 195 | enc->bps * 8, | ||
| 196 | enc->bps > 1 ? (enc->le ? "LE" : "BE") : ""); | ||
| 197 | } | ||
| 198 | g_value_set_string(&item, fmt); | ||
| 199 | gst_value_list_append_value (&list, &item); | ||
| 200 | } | ||
| 201 | gst_structure_set_value (s, "format", &list); | ||
| 202 | g_value_unset (&item); | ||
| 203 | g_value_unset (&list); | ||
| 204 | |||
| 205 | /* | ||
| 206 | * add the only supported layout: interleaved | ||
| 207 | */ | ||
| 208 | g_value_init (&item, G_TYPE_STRING); | ||
| 209 | g_value_set_string(&item, "interleaved"); | ||
| 210 | gst_structure_set_value (s, "layout", &item); | ||
| 211 | g_value_unset (&item); | ||
| 212 | |||
| 213 | gst_caps_append_structure (caps, s); | ||
| 214 | sio->cur_caps = caps; | ||
| 215 | GST_DEBUG ("caps are %s", gst_caps_to_string(caps)); | ||
| 216 | return TRUE; | ||
| 217 | } | ||
| 218 | |||
| 219 | gboolean | ||
| 220 | gst_sndio_close (struct gstsndio *sio) | ||
| 221 | { | ||
| 222 | GST_DEBUG_OBJECT (sio->obj, "close"); | ||
| 223 | |||
| 224 | gst_caps_replace (&sio->cur_caps, NULL); | ||
| 225 | sio_close (sio->hdl); | ||
| 226 | sio->hdl = NULL; | ||
| 227 | return TRUE; | ||
| 228 | } | ||
| 229 | |||
| 230 | static void | ||
| 231 | gst_sndio_cb (void *addr, int delta) | ||
| 232 | { | ||
| 233 | struct gstsndio *sio = addr; | ||
| 234 | |||
| 235 | delta *= sio->bpf; | ||
| 236 | if (sio->mode == SIO_PLAY) | ||
| 237 | sio->delay -= delta; | ||
| 238 | else | ||
| 239 | sio->delay += delta; | ||
| 240 | } | ||
| 241 | |||
| 242 | gboolean | ||
| 243 | gst_sndio_prepare (struct gstsndio *sio, GstAudioRingBufferSpec *spec) | ||
| 244 | { | ||
| 245 | struct sio_par par, retpar; | ||
| 246 | unsigned nchannels; | ||
| 247 | |||
| 248 | GST_DEBUG_OBJECT (sio, "prepare"); | ||
| 249 | |||
| 250 | if (spec->type != GST_AUDIO_RING_BUFFER_FORMAT_TYPE_RAW) { | ||
| 251 | GST_ELEMENT_ERROR (sio, RESOURCE, OPEN_READ_WRITE, | ||
| 252 | ("Only raw buffer format supported by sndio"), (NULL)); | ||
| 253 | return FALSE; | ||
| 254 | } | ||
| 255 | if (!GST_AUDIO_INFO_IS_INTEGER(&spec->info)) { | ||
| 256 | GST_ELEMENT_ERROR (sio, RESOURCE, OPEN_READ_WRITE, | ||
| 257 | ("Only integer format supported"), (NULL)); | ||
| 258 | return FALSE; | ||
| 259 | } | ||
| 260 | if (GST_AUDIO_INFO_DEPTH(&spec->info) % 8) { | ||
| 261 | GST_ELEMENT_ERROR (sio, RESOURCE, OPEN_READ_WRITE, | ||
| 262 | ("Only depths multiple of 8 are supported"), (NULL)); | ||
| 263 | return FALSE; | ||
| 264 | } | ||
| 265 | |||
| 266 | sio_initpar (&par); | ||
| 267 | switch (GST_AUDIO_INFO_FORMAT (&spec->info)) { | ||
| 268 | case GST_AUDIO_FORMAT_S8: | ||
| 269 | case GST_AUDIO_FORMAT_U8: | ||
| 270 | case GST_AUDIO_FORMAT_S16LE: | ||
| 271 | case GST_AUDIO_FORMAT_S16BE: | ||
| 272 | case GST_AUDIO_FORMAT_U16LE: | ||
| 273 | case GST_AUDIO_FORMAT_U16BE: | ||
| 274 | case GST_AUDIO_FORMAT_S32LE: | ||
| 275 | case GST_AUDIO_FORMAT_S32BE: | ||
| 276 | case GST_AUDIO_FORMAT_U32LE: | ||
| 277 | case GST_AUDIO_FORMAT_U32BE: | ||
| 278 | case GST_AUDIO_FORMAT_S24_32LE: | ||
| 279 | case GST_AUDIO_FORMAT_S24_32BE: | ||
| 280 | case GST_AUDIO_FORMAT_U24_32LE: | ||
| 281 | case GST_AUDIO_FORMAT_U24_32BE: | ||
| 282 | case GST_AUDIO_FORMAT_S24LE: | ||
| 283 | case GST_AUDIO_FORMAT_S24BE: | ||
| 284 | case GST_AUDIO_FORMAT_U24LE: | ||
| 285 | case GST_AUDIO_FORMAT_U24BE: | ||
| 286 | break; | ||
| 287 | default: | ||
| 288 | GST_ELEMENT_ERROR (sio, RESOURCE, OPEN_READ_WRITE, | ||
| 289 | ("Unsupported audio format"), | ||
| 290 | ("format = %d", GST_AUDIO_INFO_FORMAT (&spec->info))); | ||
| 291 | return FALSE; | ||
| 292 | } | ||
| 293 | par.sig = GST_AUDIO_INFO_IS_SIGNED(&spec->info); | ||
| 294 | par.bits = GST_AUDIO_INFO_WIDTH(&spec->info); | ||
| 295 | par.bps = GST_AUDIO_INFO_DEPTH(&spec->info) / 8; | ||
| 296 | if (par.bps > 1) | ||
| 297 | par.le = GST_AUDIO_INFO_IS_LITTLE_ENDIAN(&spec->info); | ||
| 298 | if (par.bits < par.bps * 8) | ||
| 299 | par.msb = 0; | ||
| 300 | par.rate = GST_AUDIO_INFO_RATE(&spec->info); | ||
| 301 | if (sio->mode == SIO_PLAY) | ||
| 302 | par.pchan = GST_AUDIO_INFO_CHANNELS(&spec->info); | ||
| 303 | else | ||
| 304 | par.rchan = GST_AUDIO_INFO_CHANNELS(&spec->info); | ||
| 305 | par.round = par.rate / 1000000. * spec->latency_time; | ||
| 306 | par.appbufsz = par.rate / 1000000. * spec->buffer_time; | ||
| 307 | |||
| 308 | if (!sio_setpar (sio->hdl, &par)) { | ||
| 309 | GST_ELEMENT_ERROR (sio, RESOURCE, OPEN_WRITE, | ||
| 310 | ("Unsupported audio encoding"), (NULL)); | ||
| 311 | return FALSE; | ||
| 312 | } | ||
| 313 | if (!sio_getpar (sio->hdl, &retpar)) { | ||
| 314 | GST_ELEMENT_ERROR (sio, RESOURCE, OPEN_WRITE, | ||
| 315 | ("Couldn't get audio device parameters"), (NULL)); | ||
| 316 | return FALSE; | ||
| 317 | } | ||
| 318 | #if 0 | ||
| 319 | GST_DEBUG ("format = %s, " | ||
| 320 | "requested: sig = %d, bits = %d, bps = %d, le = %d, msb = %d, " | ||
| 321 | "rate = %d, pchan = %d, round = %d, appbufsz = %d; " | ||
| 322 | "returned: sig = %d, bits = %d, bps = %d, le = %d, msb = %d, " | ||
| 323 | "rate = %d, pchan = %d, round = %d, appbufsz = %d, bufsz = %d", | ||
| 324 | GST_AUDIO_INFO_NAME(&spec->info), | ||
| 325 | par.sig, par.bits, par.bps, par.le, par.msb, | ||
| 326 | par.rate, par.pchan, par.round, par.appbufsz, | ||
| 327 | retpar.sig, retpar.bits, retpar.bps, retpar.le, retpar.msb, | ||
| 328 | retpar.rate, retpar.pchan, retpar.round, retpar.appbufsz, retpar.bufsz); | ||
| 329 | #endif | ||
| 330 | if (par.bits != retpar.bits || | ||
| 331 | par.bps != retpar.bps || | ||
| 332 | par.rate != retpar.rate || | ||
| 333 | (sio->mode == SIO_PLAY && par.pchan != retpar.pchan) || | ||
| 334 | (sio->mode == SIO_REC && par.rchan != retpar.rchan) || | ||
| 335 | (par.bps > 1 && par.le != retpar.le) || | ||
| 336 | (par.bits < par.bps * 8 && par.msb != retpar.msb)) { | ||
| 337 | GST_ELEMENT_ERROR (sio, RESOURCE, OPEN_WRITE, | ||
| 338 | ("Audio device refused requested parameters"), (NULL)); | ||
| 339 | return FALSE; | ||
| 340 | } | ||
| 341 | |||
| 342 | nchannels = (sio->mode == SIO_PLAY) ? retpar.pchan : retpar.rchan; | ||
| 343 | spec->segsize = retpar.round * retpar.bps * nchannels; | ||
| 344 | spec->segtotal = retpar.bufsz / retpar.round; | ||
| 345 | sio->bpf = retpar.bps * nchannels; | ||
| 346 | sio->delay = 0; | ||
| 347 | sio_onmove (sio->hdl, gst_sndio_cb, sio); | ||
| 348 | |||
| 349 | if (!sio_start (sio->hdl)) { | ||
| 350 | GST_ELEMENT_ERROR (sio->obj, RESOURCE, OPEN_READ_WRITE, | ||
| 351 | ("Could not start sndio"), (NULL)); | ||
| 352 | return FALSE; | ||
| 353 | } | ||
| 354 | return TRUE; | ||
| 355 | } | ||
| 356 | |||
| 357 | gboolean | ||
| 358 | gst_sndio_unprepare (struct gstsndio *sio) | ||
| 359 | { | ||
| 360 | if (sio->hdl) | ||
| 361 | sio_stop (sio->hdl); | ||
| 362 | return TRUE; | ||
| 363 | } | ||
| 364 | |||
| 365 | void | ||
| 366 | gst_sndio_set_property (struct gstsndio *sio, guint prop_id, | ||
| 367 | const GValue * value, GParamSpec * pspec) | ||
| 368 | { | ||
| 369 | switch (prop_id) { | ||
| 370 | case PROP_DEVICE: | ||
| 371 | g_free (sio->device); | ||
| 372 | sio->device = g_value_dup_string (value); | ||
| 373 | break; | ||
| 374 | case PROP_VOLUME: | ||
| 375 | sio_setvol (sio->hdl, g_value_get_double (value) * SIO_MAXVOL); | ||
| 376 | break; | ||
| 377 | case PROP_MUTE: | ||
| 378 | if (g_value_get_boolean (value)) | ||
| 379 | sio_setvol (sio->hdl, 0); | ||
| 380 | break; | ||
| 381 | default: | ||
| 382 | break; | ||
| 383 | } | ||
| 384 | } | ||
| 385 | |||
| 386 | void | ||
| 387 | gst_sndio_get_property (struct gstsndio *sio, guint prop_id, | ||
| 388 | GValue * value, GParamSpec * pspec) | ||
| 389 | { | ||
| 390 | switch (prop_id) { | ||
| 391 | case PROP_DEVICE: | ||
| 392 | g_value_set_string (value, sio->device); | ||
| 393 | break; | ||
| 394 | case PROP_VOLUME: | ||
| 395 | g_value_set_double (value, (gdouble)sio->volume / SIO_MAXVOL); | ||
| 396 | break; | ||
| 397 | case PROP_MUTE: | ||
| 398 | g_value_set_boolean (value, (sio->volume == 0)); | ||
| 399 | break; | ||
| 400 | default: | ||
| 401 | G_OBJECT_WARN_INVALID_PROPERTY_ID (sio->obj, prop_id, pspec); | ||
| 402 | } | ||
| 403 | } | ||
