1 /*
2 * GStreamer
3 *
4 * Copyright (C) 2005 Thomas Vander Stichele <thomas@apestaart.org>
5 * Copyright (C) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
6 * Copyright (C) 2008 Victor Lin <bornstub@gmail.com>
7 * Copyright (C) 2013 Juan Manuel Borges Caño <juanmabcmail@gmail.com>
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 *
27 * Alternatively, the contents of this file may be used under the
28 * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
29 * which case the following provisions apply instead of the ones
30 * mentioned above:
31 *
32 * Copyright (C) 2013 Juan Manuel Borges Caño <juanmabcmail@gmail.com>
33 *
34 * This library is free software; you can redistribute it and/or
35 * modify it under the terms of the GNU Library General Public
36 * License as published by the Free Software Foundation; either
37 * version 2 of the License, or (at your option) any later version.
38 *
39 * This library is distributed in the hope that it will be useful,
40 * but WITHOUT ANY WARRANTY; without even the implied warranty of
41 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
42 * Library General Public License for more details.
43 *
44 * You should have received a copy of the GNU Library General Public
45 * License along with this library; if not, write to the
46 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
47 * Boston, MA 02110-1301, USA.
48 */
49
50 /**
51 * SECTION:element-openalsrc
52 * @title: openalsrc
53 * @see_also: openalsink
54 * @short_description: capture raw audio samples through OpenAL
55 *
56 * This element captures raw audio samples through OpenAL.
57 *
58 * ## Example pipelines
59 * |[
60 * gst-launch-1.0 -v openalsrc ! audioconvert ! wavenc ! filesink location=stream.wav
61 * ]| * will capture sound through OpenAL and encode it to a wav file.
62 * |[
63 * gst-launch-1.0 openalsrc ! "audio/x-raw,format=S16LE,rate=44100" ! audioconvert ! volume volume=0.25 ! openalsink
64 * ]| will capture and play audio through OpenAL.
65 *
66 */
67
68 /*
69 * DEV:
70 * To get better timing/delay information you may also be interested in this:
71 * http://kcat.strangesoft.net/openal-extensions/SOFT_source_latency.txt
72 */
73
74 #ifdef HAVE_CONFIG_H
75 #include <config.h>
76 #endif
77
78 #include <gst/gst.h>
79 #include <gst/gsterror.h>
80
81 GST_DEBUG_CATEGORY_EXTERN (openal_debug);
82 #define GST_CAT_DEFAULT openal_debug
83
84 #include "gstopenalsrc.h"
85
86 static void gst_openal_src_dispose (GObject * object);
87 static void gst_openal_src_finalize (GObject * object);
88 static void gst_openal_src_set_property (GObject * object, guint prop_id,
89 const GValue * value, GParamSpec * pspec);
90 static void gst_openal_src_get_property (GObject * object, guint prop_id,
91 GValue * value, GParamSpec * pspec);
92 static GstCaps *gst_openal_src_getcaps (GstBaseSrc * basesrc, GstCaps * filter);
93 static gboolean gst_openal_src_open (GstAudioSrc * audiosrc);
94 static gboolean gst_openal_src_prepare (GstAudioSrc * audiosrc,
95 GstAudioRingBufferSpec * spec);
96 static gboolean gst_openal_src_unprepare (GstAudioSrc * audiosrc);
97 static gboolean gst_openal_src_close (GstAudioSrc * audiosrc);
98 static guint gst_openal_src_read (GstAudioSrc * audiosrc, gpointer data,
99 guint length, GstClockTime * timestamp);
100 static guint gst_openal_src_delay (GstAudioSrc * audiosrc);
101 static void gst_openal_src_reset (GstAudioSrc * audiosrc);
102
103 #define OPENAL_DEFAULT_DEVICE_NAME NULL
104 #define OPENAL_DEFAULT_DEVICE NULL
105
106 #define OPENAL_MIN_RATE 8000
107 #define OPENAL_MAX_RATE 192000
108
109 enum
110 {
111 PROP_0,
112 PROP_DEVICE,
113 PROP_DEVICE_NAME
114 };
115
116 static GstStaticPadTemplate openalsrc_factory = GST_STATIC_PAD_TEMPLATE ("src",
117 GST_PAD_SRC,
118 GST_PAD_ALWAYS,
119 GST_STATIC_CAPS (
120 /* These caps do not work on my card */
121 // "audio/x-adpcm, " "layout = (string) ima, "
122 // "rate = (int) [ 1, MAX ], " "channels = (int) [ 1, 2 ]; "
123 // "audio/x-alaw, " "rate = (int) [ 1, MAX ], "
124 // "channels = (int) 1; "
125 // "audio/x-mulaw, " "rate = (int) [ 1, MAX ], "
126 // "channels = (int) 1; "
127 // "audio/x-raw, " "format = (string) " GST_AUDIO_NE (F64) ", "
128 // "rate = (int) [ 1, MAX ], " "channels = (int) 1; "
129 // "audio/x-raw, " "format = (string) " GST_AUDIO_NE (F32) ", "
130 // "rate = (int) [ 1, MAX ], " "channels = (int) 1; "
131 "audio/x-raw, " "format = (string) " GST_AUDIO_NE (S16) ", "
132 "rate = (int) [ 1, MAX ], " "channels = (int) 1; "
133 /* These caps work wrongly on my card */
134 // "audio/x-raw, " "format = (string) " GST_AUDIO_NE (U16) ", "
135 // "rate = (int) [ 1, MAX ], " "channels = (int) 1; "
136 // "audio/x-raw, " "format = (string) " G_STRINGIFY (S8) ", "
137 // "rate = (int) [ 1, MAX ], " "channels = (int) 1"));
138 "audio/x-raw, " "format = (string) " G_STRINGIFY (U8) ", "
139 "rate = (int) [ 1, MAX ], " "channels = (int) 1")
140 );
141
142 G_DEFINE_TYPE (GstOpenalSrc, gst_openal_src, GST_TYPE_AUDIO_SRC);
143
144 static void
gst_openal_src_dispose(GObject * object)145 gst_openal_src_dispose (GObject * object)
146 {
147 GstOpenalSrc *openalsrc = GST_OPENAL_SRC (object);
148
149 if (openalsrc->probed_caps)
150 gst_caps_unref (openalsrc->probed_caps);
151 openalsrc->probed_caps = NULL;
152
153 G_OBJECT_CLASS (gst_openal_src_parent_class)->dispose (object);
154 }
155
156 static void
gst_openal_src_class_init(GstOpenalSrcClass * klass)157 gst_openal_src_class_init (GstOpenalSrcClass * klass)
158 {
159 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
160 GstElementClass *gstelement_class = (GstElementClass *) klass;
161 GstBaseSrcClass *gstbasesrc_class = (GstBaseSrcClass *) klass;
162 GstAudioSrcClass *gstaudiosrc_class = (GstAudioSrcClass *) (klass);
163
164 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_openal_src_dispose);
165 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_openal_src_finalize);
166 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_openal_src_set_property);
167 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_openal_src_get_property);
168
169 gst_openal_src_parent_class = g_type_class_peek_parent (klass);
170
171 gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_openal_src_getcaps);
172
173 gstaudiosrc_class->open = GST_DEBUG_FUNCPTR (gst_openal_src_open);
174 gstaudiosrc_class->prepare = GST_DEBUG_FUNCPTR (gst_openal_src_prepare);
175 gstaudiosrc_class->unprepare = GST_DEBUG_FUNCPTR (gst_openal_src_unprepare);
176 gstaudiosrc_class->close = GST_DEBUG_FUNCPTR (gst_openal_src_close);
177 gstaudiosrc_class->read = GST_DEBUG_FUNCPTR (gst_openal_src_read);
178 gstaudiosrc_class->delay = GST_DEBUG_FUNCPTR (gst_openal_src_delay);
179 gstaudiosrc_class->reset = GST_DEBUG_FUNCPTR (gst_openal_src_reset);
180
181 g_object_class_install_property (gobject_class, PROP_DEVICE,
182 g_param_spec_string ("device", "ALCdevice",
183 "User device, default device if NULL", OPENAL_DEFAULT_DEVICE,
184 G_PARAM_READWRITE));
185
186 g_object_class_install_property (gobject_class, PROP_DEVICE_NAME,
187 g_param_spec_string ("device-name", "Device name",
188 "Human-readable name of the device", OPENAL_DEFAULT_DEVICE_NAME,
189 G_PARAM_READABLE));
190
191 gst_element_class_set_static_metadata (gstelement_class,
192 "OpenAL Audio Source", "Source/Audio", "Input audio through OpenAL",
193 "Juan Manuel Borges Caño <juanmabcmail@gmail.com>");
194
195 gst_element_class_add_static_pad_template (gstelement_class,
196 &openalsrc_factory);
197 }
198
199 static void
gst_openal_src_init(GstOpenalSrc * openalsrc)200 gst_openal_src_init (GstOpenalSrc * openalsrc)
201 {
202 GST_DEBUG_OBJECT (openalsrc, "initializing");
203
204 openalsrc->default_device_name = g_strdup (OPENAL_DEFAULT_DEVICE_NAME);
205 openalsrc->default_device = OPENAL_DEFAULT_DEVICE;
206 openalsrc->device = NULL;
207
208 openalsrc->buffer_length = 0;
209
210 openalsrc->probed_caps = NULL;
211 }
212
213 static void
gst_openal_src_finalize(GObject * object)214 gst_openal_src_finalize (GObject * object)
215 {
216 GstOpenalSrc *openalsrc = GST_OPENAL_SRC (object);
217
218 g_free (openalsrc->default_device_name);
219 g_free (openalsrc->default_device);
220
221 G_OBJECT_CLASS (gst_openal_src_parent_class)->finalize (object);
222 }
223
224 static void
gst_openal_src_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)225 gst_openal_src_set_property (GObject * object, guint prop_id,
226 const GValue * value, GParamSpec * pspec)
227 {
228 GstOpenalSrc *openalsrc = GST_OPENAL_SRC (object);
229
230 switch (prop_id) {
231 case PROP_DEVICE:
232 openalsrc->default_device = g_value_dup_string (value);
233 break;
234 case PROP_DEVICE_NAME:
235 openalsrc->default_device_name = g_value_dup_string (value);
236 break;
237 default:
238 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
239 break;
240 }
241 }
242
243 static void
gst_openal_src_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)244 gst_openal_src_get_property (GObject * object, guint prop_id, GValue * value,
245 GParamSpec * pspec)
246 {
247 GstOpenalSrc *openalsrc = GST_OPENAL_SRC (object);
248
249 switch (prop_id) {
250 case PROP_DEVICE:
251 g_value_set_string (value, openalsrc->default_device);
252 break;
253 case PROP_DEVICE_NAME:
254 g_value_set_string (value, openalsrc->default_device_name);
255 break;
256 default:
257 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
258 break;
259 }
260 }
261
262 static GstCaps *
gst_openal_helper_probe_caps(ALCcontext * context)263 gst_openal_helper_probe_caps (ALCcontext * context)
264 {
265 GstStructure *structure;
266 GstCaps *caps;
267 // ALCcontext *old;
268
269 // old = pushContext(context);
270
271 caps = gst_caps_new_empty ();
272
273 if (alIsExtensionPresent ("AL_EXT_DOUBLE")) {
274 structure =
275 gst_structure_new ("audio/x-raw", "format", G_TYPE_STRING,
276 GST_AUDIO_NE (F64), "rate", GST_TYPE_INT_RANGE, OPENAL_MIN_RATE,
277 OPENAL_MAX_RATE, "channels", G_TYPE_INT, 1, NULL);
278 gst_caps_append_structure (caps, structure);
279 }
280
281 if (alIsExtensionPresent ("AL_EXT_FLOAT32")) {
282 structure =
283 gst_structure_new ("audio/x-raw", "format", G_TYPE_STRING,
284 GST_AUDIO_NE (F32), "rate", GST_TYPE_INT_RANGE, OPENAL_MIN_RATE,
285 OPENAL_MAX_RATE, "channels", G_TYPE_INT, 1, NULL);
286 gst_caps_append_structure (caps, structure);
287 }
288
289 structure =
290 gst_structure_new ("audio/x-raw", "format", G_TYPE_STRING,
291 GST_AUDIO_NE (S16), "rate", GST_TYPE_INT_RANGE, OPENAL_MIN_RATE,
292 OPENAL_MAX_RATE, "channels", G_TYPE_INT, 1, NULL);
293 gst_caps_append_structure (caps, structure);
294
295 structure =
296 gst_structure_new ("audio/x-raw", "format", G_TYPE_STRING,
297 G_STRINGIFY (U8), "rate", GST_TYPE_INT_RANGE, OPENAL_MIN_RATE,
298 OPENAL_MAX_RATE, "channels", G_TYPE_INT, 1, NULL);
299 gst_caps_append_structure (caps, structure);
300
301 if (alIsExtensionPresent ("AL_EXT_IMA4")) {
302 structure =
303 gst_structure_new ("audio/x-adpcm", "layout", G_TYPE_STRING, "ima",
304 "rate", GST_TYPE_INT_RANGE, OPENAL_MIN_RATE, OPENAL_MAX_RATE,
305 "channels", G_TYPE_INT, 1, NULL);
306 gst_caps_append_structure (caps, structure);
307 }
308
309 if (alIsExtensionPresent ("AL_EXT_ALAW")) {
310 structure =
311 gst_structure_new ("audio/x-alaw", "rate", GST_TYPE_INT_RANGE,
312 OPENAL_MIN_RATE, OPENAL_MAX_RATE, "channels", G_TYPE_INT, 1, NULL);
313 gst_caps_append_structure (caps, structure);
314 }
315
316 if (alIsExtensionPresent ("AL_EXT_MULAW")) {
317 structure =
318 gst_structure_new ("audio/x-mulaw", "rate", GST_TYPE_INT_RANGE,
319 OPENAL_MIN_RATE, OPENAL_MAX_RATE, "channels", G_TYPE_INT, 1, NULL);
320 gst_caps_append_structure (caps, structure);
321 }
322 // popContext(old, context);
323
324 return caps;
325 }
326
327 static GstCaps *
gst_openal_src_getcaps(GstBaseSrc * basesrc,GstCaps * filter)328 gst_openal_src_getcaps (GstBaseSrc * basesrc, GstCaps * filter)
329 {
330 GstOpenalSrc *openalsrc = GST_OPENAL_SRC (basesrc);
331 GstCaps *caps;
332 ALCdevice *device;
333
334 device = alcOpenDevice (NULL);
335
336 if (device == NULL) {
337 GstPad *pad = GST_BASE_SRC_PAD (basesrc);
338 GstCaps *tcaps = gst_pad_get_pad_template_caps (pad);
339
340 GST_ELEMENT_WARNING (openalsrc, RESOURCE, OPEN_WRITE,
341 ("Could not open temporary device."), GST_ALC_ERROR (device));
342 caps = gst_caps_copy (tcaps);
343 gst_caps_unref (tcaps);
344 } else if (openalsrc->probed_caps)
345 caps = gst_caps_copy (openalsrc->probed_caps);
346 else {
347 ALCcontext *context = alcCreateContext (device, NULL);
348 if (context) {
349 caps = gst_openal_helper_probe_caps (context);
350 alcDestroyContext (context);
351 } else {
352 GST_ELEMENT_WARNING (openalsrc, RESOURCE, FAILED,
353 ("Could not create temporary context."), GST_ALC_ERROR (device));
354 caps = NULL;
355 }
356
357 if (caps && !gst_caps_is_empty (caps))
358 openalsrc->probed_caps = gst_caps_copy (caps);
359 }
360
361 if (device != NULL) {
362 if (alcCloseDevice (device) == ALC_FALSE) {
363 GST_ELEMENT_WARNING (openalsrc, RESOURCE, CLOSE,
364 ("Could not close temporary device."), GST_ALC_ERROR (device));
365 }
366 }
367
368 if (filter) {
369 GstCaps *intersection;
370
371 intersection =
372 gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
373 return intersection;
374 } else {
375 return caps;
376 }
377 }
378
379
380 static gboolean
gst_openal_src_open(GstAudioSrc * audiosrc)381 gst_openal_src_open (GstAudioSrc * audiosrc)
382 {
383 return TRUE;
384 }
385
386 static void
gst_openal_src_parse_spec(GstOpenalSrc * openalsrc,const GstAudioRingBufferSpec * spec)387 gst_openal_src_parse_spec (GstOpenalSrc * openalsrc,
388 const GstAudioRingBufferSpec * spec)
389 {
390 ALuint format = AL_NONE;
391
392 GST_DEBUG_OBJECT (openalsrc,
393 "looking up format for type %d, gst-format %d, and %d channels",
394 spec->type, GST_AUDIO_INFO_FORMAT (&spec->info),
395 GST_AUDIO_INFO_CHANNELS (&spec->info));
396
397 switch (spec->type) {
398 case GST_AUDIO_RING_BUFFER_FORMAT_TYPE_RAW:
399 switch (GST_AUDIO_INFO_FORMAT (&spec->info)) {
400 case GST_AUDIO_FORMAT_U8:
401 switch (GST_AUDIO_INFO_CHANNELS (&spec->info)) {
402 case 1:
403 format = AL_FORMAT_MONO8;
404 break;
405 default:
406 break;
407 }
408 break;
409
410 case GST_AUDIO_FORMAT_U16:
411 case GST_AUDIO_FORMAT_S16:
412 switch (GST_AUDIO_INFO_CHANNELS (&spec->info)) {
413 case 1:
414 format = AL_FORMAT_MONO16;
415 break;
416 default:
417 break;
418 }
419 break;
420
421 case GST_AUDIO_FORMAT_F32:
422 switch (GST_AUDIO_INFO_CHANNELS (&spec->info)) {
423 case 1:
424 format = AL_FORMAT_MONO_FLOAT32;
425 break;
426 default:
427 break;
428 }
429 break;
430
431 case GST_AUDIO_FORMAT_F64:
432 switch (GST_AUDIO_INFO_CHANNELS (&spec->info)) {
433 case 1:
434 format = AL_FORMAT_MONO_DOUBLE_EXT;
435 break;
436 default:
437 break;
438 }
439 break;
440
441 default:
442 break;
443 }
444 break;
445
446 case GST_AUDIO_RING_BUFFER_FORMAT_TYPE_IMA_ADPCM:
447 switch (GST_AUDIO_INFO_CHANNELS (&spec->info)) {
448 case 1:
449 format = AL_FORMAT_MONO_IMA4;
450 break;
451 default:
452 break;
453 }
454 break;
455
456 case GST_AUDIO_RING_BUFFER_FORMAT_TYPE_A_LAW:
457 switch (GST_AUDIO_INFO_CHANNELS (&spec->info)) {
458 case 1:
459 format = AL_FORMAT_MONO_ALAW_EXT;
460 break;
461 default:
462 break;
463 }
464 break;
465
466 case GST_AUDIO_RING_BUFFER_FORMAT_TYPE_MU_LAW:
467 switch (GST_AUDIO_INFO_CHANNELS (&spec->info)) {
468 case 1:
469 format = AL_FORMAT_MONO_MULAW;
470 break;
471 default:
472 break;
473 }
474 break;
475
476 default:
477 break;
478 }
479
480 openalsrc->bytes_per_sample = GST_AUDIO_INFO_BPS (&spec->info);
481 openalsrc->rate = GST_AUDIO_INFO_RATE (&spec->info);
482 openalsrc->buffer_length = spec->segsize;
483 openalsrc->format = format;
484 }
485
486 static gboolean
gst_openal_src_prepare(GstAudioSrc * audiosrc,GstAudioRingBufferSpec * spec)487 gst_openal_src_prepare (GstAudioSrc * audiosrc, GstAudioRingBufferSpec * spec)
488 {
489 GstOpenalSrc *openalsrc = GST_OPENAL_SRC (audiosrc);
490
491 gst_openal_src_parse_spec (openalsrc, spec);
492 if (openalsrc->format == AL_NONE) {
493 GST_ELEMENT_ERROR (openalsrc, RESOURCE, SETTINGS, (NULL),
494 ("Unable to get type %d, format %d, and %d channels", spec->type,
495 GST_AUDIO_INFO_FORMAT (&spec->info),
496 GST_AUDIO_INFO_CHANNELS (&spec->info)));
497 return FALSE;
498 }
499
500 openalsrc->device =
501 alcCaptureOpenDevice (openalsrc->default_device, openalsrc->rate,
502 openalsrc->format, openalsrc->buffer_length);
503
504 if (!openalsrc->device) {
505 GST_ELEMENT_ERROR (openalsrc, RESOURCE, OPEN_READ,
506 ("Could not open device."), GST_ALC_ERROR (openalsrc->device));
507 return FALSE;
508 }
509
510 openalsrc->default_device_name =
511 g_strdup (alcGetString (openalsrc->device, ALC_DEVICE_SPECIFIER));
512
513 alcCaptureStart (openalsrc->device);
514
515 return TRUE;
516 }
517
518 static gboolean
gst_openal_src_unprepare(GstAudioSrc * audiosrc)519 gst_openal_src_unprepare (GstAudioSrc * audiosrc)
520 {
521 GstOpenalSrc *openalsrc = GST_OPENAL_SRC (audiosrc);
522
523 if (openalsrc->device) {
524 alcCaptureStop (openalsrc->device);
525
526 if (alcCaptureCloseDevice (openalsrc->device) == ALC_FALSE) {
527 GST_ELEMENT_ERROR (openalsrc, RESOURCE, CLOSE,
528 ("Could not close device."), GST_ALC_ERROR (openalsrc->device));
529 return FALSE;
530 }
531 }
532
533 return TRUE;
534 }
535
536 static gboolean
gst_openal_src_close(GstAudioSrc * audiosrc)537 gst_openal_src_close (GstAudioSrc * audiosrc)
538 {
539 return TRUE;
540 }
541
542 static guint
gst_openal_src_read(GstAudioSrc * audiosrc,gpointer data,guint length,GstClockTime * timestamp)543 gst_openal_src_read (GstAudioSrc * audiosrc, gpointer data, guint length,
544 GstClockTime * timestamp)
545 {
546 GstOpenalSrc *openalsrc = GST_OPENAL_SRC (audiosrc);
547 gint samples;
548
549 alcGetIntegerv (openalsrc->device, ALC_CAPTURE_SAMPLES, sizeof (samples),
550 &samples);
551
552 if (samples * openalsrc->bytes_per_sample > length) {
553 samples = length / openalsrc->bytes_per_sample;
554 }
555
556 if (samples) {
557 GST_DEBUG_OBJECT (openalsrc, "read samples : %d", samples);
558 alcCaptureSamples (openalsrc->device, data, samples);
559 }
560
561 return samples * openalsrc->bytes_per_sample;
562 }
563
564 static guint
gst_openal_src_delay(GstAudioSrc * audiosrc)565 gst_openal_src_delay (GstAudioSrc * audiosrc)
566 {
567 GstOpenalSrc *openalsrc = GST_OPENAL_SRC (audiosrc);
568 ALint samples;
569
570 alcGetIntegerv (openalsrc->device, ALC_CAPTURE_SAMPLES, sizeof (samples),
571 &samples);
572
573 if (G_UNLIKELY (samples < 0)) {
574 /* make sure we never return a negative delay */
575 GST_WARNING_OBJECT (openal_debug, "negative delay");
576 samples = 0;
577 }
578
579 return samples;
580 }
581
582 static void
gst_openal_src_reset(GstAudioSrc * audiosrc)583 gst_openal_src_reset (GstAudioSrc * audiosrc)
584 {
585 }
586