• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "gstopenalelements.h"
85 #include "gstopenalsrc.h"
86 
87 static void gst_openal_src_dispose (GObject * object);
88 static void gst_openal_src_finalize (GObject * object);
89 static void gst_openal_src_set_property (GObject * object, guint prop_id,
90     const GValue * value, GParamSpec * pspec);
91 static void gst_openal_src_get_property (GObject * object, guint prop_id,
92     GValue * value, GParamSpec * pspec);
93 static GstCaps *gst_openal_src_getcaps (GstBaseSrc * basesrc, GstCaps * filter);
94 static gboolean gst_openal_src_open (GstAudioSrc * audiosrc);
95 static gboolean gst_openal_src_prepare (GstAudioSrc * audiosrc,
96     GstAudioRingBufferSpec * spec);
97 static gboolean gst_openal_src_unprepare (GstAudioSrc * audiosrc);
98 static gboolean gst_openal_src_close (GstAudioSrc * audiosrc);
99 static guint gst_openal_src_read (GstAudioSrc * audiosrc, gpointer data,
100     guint length, GstClockTime * timestamp);
101 static guint gst_openal_src_delay (GstAudioSrc * audiosrc);
102 static void gst_openal_src_reset (GstAudioSrc * audiosrc);
103 
104 #define OPENAL_DEFAULT_DEVICE_NAME NULL
105 #define OPENAL_DEFAULT_DEVICE NULL
106 
107 #define OPENAL_MIN_RATE 8000
108 #define OPENAL_MAX_RATE 192000
109 
110 enum
111 {
112   PROP_0,
113   PROP_DEVICE,
114   PROP_DEVICE_NAME
115 };
116 
117 static GstStaticPadTemplate openalsrc_factory = GST_STATIC_PAD_TEMPLATE ("src",
118     GST_PAD_SRC,
119     GST_PAD_ALWAYS,
120     GST_STATIC_CAPS (
121         /* These caps do not work on my card */
122         // "audio/x-adpcm, " "layout = (string) ima, "
123         // "rate = (int) [ 1, MAX ], " "channels = (int) [ 1, 2 ]; "
124         // "audio/x-alaw, " "rate = (int) [ 1, MAX ], "
125         // "channels = (int) 1; "
126         // "audio/x-mulaw, " "rate = (int) [ 1, MAX ], "
127         // "channels = (int) 1; "
128         // "audio/x-raw, " "format = (string) " GST_AUDIO_NE (F64) ", "
129         // "rate = (int) [ 1, MAX ], " "channels = (int) 1; "
130         // "audio/x-raw, " "format = (string) " GST_AUDIO_NE (F32) ", "
131         // "rate = (int) [ 1, MAX ], " "channels = (int) 1; "
132         "audio/x-raw, " "format = (string) " GST_AUDIO_NE (S16) ", "
133         "rate = (int) [ 1, MAX ], " "channels = (int) 1; "
134         /* These caps work wrongly on my card */
135         // "audio/x-raw, " "format = (string) " GST_AUDIO_NE (U16) ", "
136         // "rate = (int) [ 1, MAX ], " "channels = (int) 1; "
137         // "audio/x-raw, " "format = (string) " G_STRINGIFY (S8) ", "
138         // "rate = (int) [ 1, MAX ], " "channels = (int) 1"));
139         "audio/x-raw, " "format = (string) " G_STRINGIFY (U8) ", "
140         "rate = (int) [ 1, MAX ], " "channels = (int) 1")
141     );
142 
143 G_DEFINE_TYPE (GstOpenalSrc, gst_openal_src, GST_TYPE_AUDIO_SRC);
144 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (openalsrc, "openalsrc",
145     GST_RANK_SECONDARY, GST_TYPE_OPENAL_SRC, openal_element_init (plugin));
146 
147 static void
gst_openal_src_dispose(GObject * object)148 gst_openal_src_dispose (GObject * object)
149 {
150   GstOpenalSrc *openalsrc = GST_OPENAL_SRC (object);
151 
152   if (openalsrc->probed_caps)
153     gst_caps_unref (openalsrc->probed_caps);
154   openalsrc->probed_caps = NULL;
155 
156   G_OBJECT_CLASS (gst_openal_src_parent_class)->dispose (object);
157 }
158 
159 static void
gst_openal_src_class_init(GstOpenalSrcClass * klass)160 gst_openal_src_class_init (GstOpenalSrcClass * klass)
161 {
162   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
163   GstElementClass *gstelement_class = (GstElementClass *) klass;
164   GstBaseSrcClass *gstbasesrc_class = (GstBaseSrcClass *) klass;
165   GstAudioSrcClass *gstaudiosrc_class = (GstAudioSrcClass *) (klass);
166 
167   gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_openal_src_dispose);
168   gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_openal_src_finalize);
169   gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_openal_src_set_property);
170   gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_openal_src_get_property);
171 
172   gst_openal_src_parent_class = g_type_class_peek_parent (klass);
173 
174   gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_openal_src_getcaps);
175 
176   gstaudiosrc_class->open = GST_DEBUG_FUNCPTR (gst_openal_src_open);
177   gstaudiosrc_class->prepare = GST_DEBUG_FUNCPTR (gst_openal_src_prepare);
178   gstaudiosrc_class->unprepare = GST_DEBUG_FUNCPTR (gst_openal_src_unprepare);
179   gstaudiosrc_class->close = GST_DEBUG_FUNCPTR (gst_openal_src_close);
180   gstaudiosrc_class->read = GST_DEBUG_FUNCPTR (gst_openal_src_read);
181   gstaudiosrc_class->delay = GST_DEBUG_FUNCPTR (gst_openal_src_delay);
182   gstaudiosrc_class->reset = GST_DEBUG_FUNCPTR (gst_openal_src_reset);
183 
184   g_object_class_install_property (gobject_class, PROP_DEVICE,
185       g_param_spec_string ("device", "ALCdevice",
186           "User device, default device if NULL", OPENAL_DEFAULT_DEVICE,
187           G_PARAM_READWRITE));
188 
189   g_object_class_install_property (gobject_class, PROP_DEVICE_NAME,
190       g_param_spec_string ("device-name", "Device name",
191           "Human-readable name of the device", OPENAL_DEFAULT_DEVICE_NAME,
192           G_PARAM_READABLE));
193 
194   gst_element_class_set_static_metadata (gstelement_class,
195       "OpenAL Audio Source", "Source/Audio", "Input audio through OpenAL",
196       "Juan Manuel Borges Caño <juanmabcmail@gmail.com>");
197 
198   gst_element_class_add_static_pad_template (gstelement_class,
199       &openalsrc_factory);
200 }
201 
202 static void
gst_openal_src_init(GstOpenalSrc * openalsrc)203 gst_openal_src_init (GstOpenalSrc * openalsrc)
204 {
205   GST_DEBUG_OBJECT (openalsrc, "initializing");
206 
207   openalsrc->default_device_name = g_strdup (OPENAL_DEFAULT_DEVICE_NAME);
208   openalsrc->default_device = OPENAL_DEFAULT_DEVICE;
209   openalsrc->device = NULL;
210 
211   openalsrc->buffer_length = 0;
212 
213   openalsrc->probed_caps = NULL;
214 }
215 
216 static void
gst_openal_src_finalize(GObject * object)217 gst_openal_src_finalize (GObject * object)
218 {
219   GstOpenalSrc *openalsrc = GST_OPENAL_SRC (object);
220 
221   g_free (openalsrc->default_device_name);
222   g_free (openalsrc->default_device);
223 
224   G_OBJECT_CLASS (gst_openal_src_parent_class)->finalize (object);
225 }
226 
227 static void
gst_openal_src_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)228 gst_openal_src_set_property (GObject * object, guint prop_id,
229     const GValue * value, GParamSpec * pspec)
230 {
231   GstOpenalSrc *openalsrc = GST_OPENAL_SRC (object);
232 
233   switch (prop_id) {
234     case PROP_DEVICE:
235       openalsrc->default_device = g_value_dup_string (value);
236       break;
237     case PROP_DEVICE_NAME:
238       openalsrc->default_device_name = g_value_dup_string (value);
239       break;
240     default:
241       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
242       break;
243   }
244 }
245 
246 static void
gst_openal_src_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)247 gst_openal_src_get_property (GObject * object, guint prop_id, GValue * value,
248     GParamSpec * pspec)
249 {
250   GstOpenalSrc *openalsrc = GST_OPENAL_SRC (object);
251 
252   switch (prop_id) {
253     case PROP_DEVICE:
254       g_value_set_string (value, openalsrc->default_device);
255       break;
256     case PROP_DEVICE_NAME:
257       g_value_set_string (value, openalsrc->default_device_name);
258       break;
259     default:
260       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
261       break;
262   }
263 }
264 
265 static GstCaps *
gst_openal_helper_probe_caps(ALCcontext * context)266 gst_openal_helper_probe_caps (ALCcontext * context)
267 {
268   GstStructure *structure;
269   GstCaps *caps;
270 //  ALCcontext *old;
271 
272 //  old = pushContext(context);
273 
274   caps = gst_caps_new_empty ();
275 
276   if (alIsExtensionPresent ("AL_EXT_DOUBLE")) {
277     structure =
278         gst_structure_new ("audio/x-raw", "format", G_TYPE_STRING,
279         GST_AUDIO_NE (F64), "rate", GST_TYPE_INT_RANGE, OPENAL_MIN_RATE,
280         OPENAL_MAX_RATE, "channels", G_TYPE_INT, 1, NULL);
281     gst_caps_append_structure (caps, structure);
282   }
283 
284   if (alIsExtensionPresent ("AL_EXT_FLOAT32")) {
285     structure =
286         gst_structure_new ("audio/x-raw", "format", G_TYPE_STRING,
287         GST_AUDIO_NE (F32), "rate", GST_TYPE_INT_RANGE, OPENAL_MIN_RATE,
288         OPENAL_MAX_RATE, "channels", G_TYPE_INT, 1, NULL);
289     gst_caps_append_structure (caps, structure);
290   }
291 
292   structure =
293       gst_structure_new ("audio/x-raw", "format", G_TYPE_STRING,
294       GST_AUDIO_NE (S16), "rate", GST_TYPE_INT_RANGE, OPENAL_MIN_RATE,
295       OPENAL_MAX_RATE, "channels", G_TYPE_INT, 1, NULL);
296   gst_caps_append_structure (caps, structure);
297 
298   structure =
299       gst_structure_new ("audio/x-raw", "format", G_TYPE_STRING,
300       G_STRINGIFY (U8), "rate", GST_TYPE_INT_RANGE, OPENAL_MIN_RATE,
301       OPENAL_MAX_RATE, "channels", G_TYPE_INT, 1, NULL);
302   gst_caps_append_structure (caps, structure);
303 
304   if (alIsExtensionPresent ("AL_EXT_IMA4")) {
305     structure =
306         gst_structure_new ("audio/x-adpcm", "layout", G_TYPE_STRING, "ima",
307         "rate", GST_TYPE_INT_RANGE, OPENAL_MIN_RATE, OPENAL_MAX_RATE,
308         "channels", G_TYPE_INT, 1, NULL);
309     gst_caps_append_structure (caps, structure);
310   }
311 
312   if (alIsExtensionPresent ("AL_EXT_ALAW")) {
313     structure =
314         gst_structure_new ("audio/x-alaw", "rate", GST_TYPE_INT_RANGE,
315         OPENAL_MIN_RATE, OPENAL_MAX_RATE, "channels", G_TYPE_INT, 1, NULL);
316     gst_caps_append_structure (caps, structure);
317   }
318 
319   if (alIsExtensionPresent ("AL_EXT_MULAW")) {
320     structure =
321         gst_structure_new ("audio/x-mulaw", "rate", GST_TYPE_INT_RANGE,
322         OPENAL_MIN_RATE, OPENAL_MAX_RATE, "channels", G_TYPE_INT, 1, NULL);
323     gst_caps_append_structure (caps, structure);
324   }
325 //  popContext(old, context);
326 
327   return caps;
328 }
329 
330 static GstCaps *
gst_openal_src_getcaps(GstBaseSrc * basesrc,GstCaps * filter)331 gst_openal_src_getcaps (GstBaseSrc * basesrc, GstCaps * filter)
332 {
333   GstOpenalSrc *openalsrc = GST_OPENAL_SRC (basesrc);
334   GstCaps *caps;
335   ALCdevice *device;
336 
337   device = alcOpenDevice (NULL);
338 
339   if (device == NULL) {
340     GstPad *pad = GST_BASE_SRC_PAD (basesrc);
341     GstCaps *tcaps = gst_pad_get_pad_template_caps (pad);
342 
343     GST_ELEMENT_WARNING (openalsrc, RESOURCE, OPEN_WRITE,
344         ("Could not open temporary device."), GST_ALC_ERROR (device));
345     caps = gst_caps_copy (tcaps);
346     gst_caps_unref (tcaps);
347   } else if (openalsrc->probed_caps)
348     caps = gst_caps_copy (openalsrc->probed_caps);
349   else {
350     ALCcontext *context = alcCreateContext (device, NULL);
351     if (context) {
352       caps = gst_openal_helper_probe_caps (context);
353       alcDestroyContext (context);
354     } else {
355       GST_ELEMENT_WARNING (openalsrc, RESOURCE, FAILED,
356           ("Could not create temporary context."), GST_ALC_ERROR (device));
357       caps = NULL;
358     }
359 
360     if (caps && !gst_caps_is_empty (caps))
361       openalsrc->probed_caps = gst_caps_copy (caps);
362   }
363 
364   if (device != NULL) {
365     if (alcCloseDevice (device) == ALC_FALSE) {
366       GST_ELEMENT_WARNING (openalsrc, RESOURCE, CLOSE,
367           ("Could not close temporary device."), GST_ALC_ERROR (device));
368     }
369   }
370 
371   if (filter) {
372     GstCaps *intersection;
373 
374     intersection =
375         gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
376     return intersection;
377   } else {
378     return caps;
379   }
380 }
381 
382 
383 static gboolean
gst_openal_src_open(GstAudioSrc * audiosrc)384 gst_openal_src_open (GstAudioSrc * audiosrc)
385 {
386   return TRUE;
387 }
388 
389 static void
gst_openal_src_parse_spec(GstOpenalSrc * openalsrc,const GstAudioRingBufferSpec * spec)390 gst_openal_src_parse_spec (GstOpenalSrc * openalsrc,
391     const GstAudioRingBufferSpec * spec)
392 {
393   ALuint format = AL_NONE;
394 
395   GST_DEBUG_OBJECT (openalsrc,
396       "looking up format for type %d, gst-format %d, and %d channels",
397       spec->type, GST_AUDIO_INFO_FORMAT (&spec->info),
398       GST_AUDIO_INFO_CHANNELS (&spec->info));
399 
400   switch (spec->type) {
401     case GST_AUDIO_RING_BUFFER_FORMAT_TYPE_RAW:
402       switch (GST_AUDIO_INFO_FORMAT (&spec->info)) {
403         case GST_AUDIO_FORMAT_U8:
404           switch (GST_AUDIO_INFO_CHANNELS (&spec->info)) {
405             case 1:
406               format = AL_FORMAT_MONO8;
407               break;
408             default:
409               break;
410           }
411           break;
412 
413         case GST_AUDIO_FORMAT_U16:
414         case GST_AUDIO_FORMAT_S16:
415           switch (GST_AUDIO_INFO_CHANNELS (&spec->info)) {
416             case 1:
417               format = AL_FORMAT_MONO16;
418               break;
419             default:
420               break;
421           }
422           break;
423 
424         case GST_AUDIO_FORMAT_F32:
425           switch (GST_AUDIO_INFO_CHANNELS (&spec->info)) {
426             case 1:
427               format = AL_FORMAT_MONO_FLOAT32;
428               break;
429             default:
430               break;
431           }
432           break;
433 
434         case GST_AUDIO_FORMAT_F64:
435           switch (GST_AUDIO_INFO_CHANNELS (&spec->info)) {
436             case 1:
437               format = AL_FORMAT_MONO_DOUBLE_EXT;
438               break;
439             default:
440               break;
441           }
442           break;
443 
444         default:
445           break;
446       }
447       break;
448 
449     case GST_AUDIO_RING_BUFFER_FORMAT_TYPE_IMA_ADPCM:
450       switch (GST_AUDIO_INFO_CHANNELS (&spec->info)) {
451         case 1:
452           format = AL_FORMAT_MONO_IMA4;
453           break;
454         default:
455           break;
456       }
457       break;
458 
459     case GST_AUDIO_RING_BUFFER_FORMAT_TYPE_A_LAW:
460       switch (GST_AUDIO_INFO_CHANNELS (&spec->info)) {
461         case 1:
462           format = AL_FORMAT_MONO_ALAW_EXT;
463           break;
464         default:
465           break;
466       }
467       break;
468 
469     case GST_AUDIO_RING_BUFFER_FORMAT_TYPE_MU_LAW:
470       switch (GST_AUDIO_INFO_CHANNELS (&spec->info)) {
471         case 1:
472           format = AL_FORMAT_MONO_MULAW;
473           break;
474         default:
475           break;
476       }
477       break;
478 
479     default:
480       break;
481   }
482 
483   openalsrc->bytes_per_sample = GST_AUDIO_INFO_BPS (&spec->info);
484   openalsrc->rate = GST_AUDIO_INFO_RATE (&spec->info);
485   openalsrc->buffer_length = spec->segsize;
486   openalsrc->format = format;
487 }
488 
489 static gboolean
gst_openal_src_prepare(GstAudioSrc * audiosrc,GstAudioRingBufferSpec * spec)490 gst_openal_src_prepare (GstAudioSrc * audiosrc, GstAudioRingBufferSpec * spec)
491 {
492   GstOpenalSrc *openalsrc = GST_OPENAL_SRC (audiosrc);
493 
494   gst_openal_src_parse_spec (openalsrc, spec);
495   if (openalsrc->format == AL_NONE) {
496     GST_ELEMENT_ERROR (openalsrc, RESOURCE, SETTINGS, (NULL),
497         ("Unable to get type %d, format %d, and %d channels", spec->type,
498             GST_AUDIO_INFO_FORMAT (&spec->info),
499             GST_AUDIO_INFO_CHANNELS (&spec->info)));
500     return FALSE;
501   }
502 
503   openalsrc->device =
504       alcCaptureOpenDevice (openalsrc->default_device, openalsrc->rate,
505       openalsrc->format, openalsrc->buffer_length);
506 
507   if (!openalsrc->device) {
508     GST_ELEMENT_ERROR (openalsrc, RESOURCE, OPEN_READ,
509         ("Could not open device."), GST_ALC_ERROR (openalsrc->device));
510     return FALSE;
511   }
512 
513   openalsrc->default_device_name =
514       g_strdup (alcGetString (openalsrc->device, ALC_DEVICE_SPECIFIER));
515 
516   alcCaptureStart (openalsrc->device);
517 
518   return TRUE;
519 }
520 
521 static gboolean
gst_openal_src_unprepare(GstAudioSrc * audiosrc)522 gst_openal_src_unprepare (GstAudioSrc * audiosrc)
523 {
524   GstOpenalSrc *openalsrc = GST_OPENAL_SRC (audiosrc);
525 
526   if (openalsrc->device) {
527     alcCaptureStop (openalsrc->device);
528 
529     if (alcCaptureCloseDevice (openalsrc->device) == ALC_FALSE) {
530       GST_ELEMENT_ERROR (openalsrc, RESOURCE, CLOSE,
531           ("Could not close device."), GST_ALC_ERROR (openalsrc->device));
532       return FALSE;
533     }
534   }
535 
536   return TRUE;
537 }
538 
539 static gboolean
gst_openal_src_close(GstAudioSrc * audiosrc)540 gst_openal_src_close (GstAudioSrc * audiosrc)
541 {
542   return TRUE;
543 }
544 
545 static guint
gst_openal_src_read(GstAudioSrc * audiosrc,gpointer data,guint length,GstClockTime * timestamp)546 gst_openal_src_read (GstAudioSrc * audiosrc, gpointer data, guint length,
547     GstClockTime * timestamp)
548 {
549   GstOpenalSrc *openalsrc = GST_OPENAL_SRC (audiosrc);
550   gint samples;
551 
552   alcGetIntegerv (openalsrc->device, ALC_CAPTURE_SAMPLES, sizeof (samples),
553       &samples);
554 
555   if (samples * openalsrc->bytes_per_sample > length) {
556     samples = length / openalsrc->bytes_per_sample;
557   }
558 
559   if (samples) {
560     GST_DEBUG_OBJECT (openalsrc, "read samples : %d", samples);
561     alcCaptureSamples (openalsrc->device, data, samples);
562   }
563 
564   return samples * openalsrc->bytes_per_sample;
565 }
566 
567 static guint
gst_openal_src_delay(GstAudioSrc * audiosrc)568 gst_openal_src_delay (GstAudioSrc * audiosrc)
569 {
570   GstOpenalSrc *openalsrc = GST_OPENAL_SRC (audiosrc);
571   ALint samples;
572 
573   alcGetIntegerv (openalsrc->device, ALC_CAPTURE_SAMPLES, sizeof (samples),
574       &samples);
575 
576   if (G_UNLIKELY (samples < 0)) {
577     /* make sure we never return a negative delay */
578     GST_WARNING_OBJECT (openal_debug, "negative delay");
579     samples = 0;
580   }
581 
582   return samples;
583 }
584 
585 static void
gst_openal_src_reset(GstAudioSrc * audiosrc)586 gst_openal_src_reset (GstAudioSrc * audiosrc)
587 {
588 }
589