2 * Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 * SECTION:element-alsasrc
24 * @short_description: capture audio from an alsa device
25 * @see_also: alsasink, alsamixer
29 * This element reads data from an audio card using the ALSA API.
31 * <title>Example pipelines</title>
33 * Record from a sound card using ALSA and encode to Ogg/Vorbis.
36 * gst-launch -v alsasrc ! audioconvert ! vorbisenc ! oggmux ! filesink location=alsasrc.ogg
40 * Last reviewed on 2006-03-01 (0.10.4)
46 #include <sys/ioctl.h>
52 #include <alsa/asoundlib.h>
54 #include "gstalsasrc.h"
55 #include "gstalsadeviceprobe.h"
57 #include <gst/gst-i18n-plugin.h>
59 /* elementfactory information */
60 static const GstElementDetails gst_alsasrc_details =
61 GST_ELEMENT_DETAILS ("Audio source (ALSA)",
63 "Read from a sound card via ALSA",
64 "Wim Taymans <wim@fluendo.com>");
66 #define DEFAULT_PROP_DEVICE "default"
67 #define DEFAULT_PROP_DEVICE_NAME ""
76 static void gst_alsasrc_init_interfaces (GType type);
78 GST_BOILERPLATE_FULL (GstAlsaSrc, gst_alsasrc, GstAudioSrc,
79 GST_TYPE_AUDIO_SRC, gst_alsasrc_init_interfaces);
81 GST_IMPLEMENT_ALSA_MIXER_METHODS (GstAlsaSrc, gst_alsasrc_mixer);
83 static void gst_alsasrc_finalize (GObject * object);
84 static void gst_alsasrc_set_property (GObject * object,
85 guint prop_id, const GValue * value, GParamSpec * pspec);
86 static void gst_alsasrc_get_property (GObject * object,
87 guint prop_id, GValue * value, GParamSpec * pspec);
89 static GstCaps *gst_alsasrc_getcaps (GstBaseSrc * bsrc);
91 static gboolean gst_alsasrc_open (GstAudioSrc * asrc);
92 static gboolean gst_alsasrc_prepare (GstAudioSrc * asrc,
93 GstRingBufferSpec * spec);
94 static gboolean gst_alsasrc_unprepare (GstAudioSrc * asrc);
95 static gboolean gst_alsasrc_close (GstAudioSrc * asrc);
96 static guint gst_alsasrc_read (GstAudioSrc * asrc, gpointer data, guint length);
97 static guint gst_alsasrc_delay (GstAudioSrc * asrc);
98 static void gst_alsasrc_reset (GstAudioSrc * asrc);
100 /* AlsaSrc signals and args */
106 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
107 # define ALSA_SRC_FACTORY_ENDIANNESS "LITTLE_ENDIAN, BIG_ENDIAN"
109 # define ALSA_SRC_FACTORY_ENDIANNESS "BIG_ENDIAN, LITTLE_ENDIAN"
112 static GstStaticPadTemplate alsasrc_src_factory =
113 GST_STATIC_PAD_TEMPLATE ("src",
116 GST_STATIC_CAPS ("audio/x-raw-int, "
117 "endianness = (int) { " ALSA_SRC_FACTORY_ENDIANNESS " }, "
118 "signed = (boolean) { TRUE, FALSE }, "
121 "rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]; "
123 "endianness = (int) { " ALSA_SRC_FACTORY_ENDIANNESS " }, "
124 "signed = (boolean) { TRUE, FALSE }, "
127 "rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]; "
129 "endianness = (int) { " ALSA_SRC_FACTORY_ENDIANNESS " }, "
130 "signed = (boolean) { TRUE, FALSE }, "
133 "rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]; "
135 "endianness = (int) { " ALSA_SRC_FACTORY_ENDIANNESS " }, "
136 "signed = (boolean) { TRUE, FALSE }, "
139 "rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]; "
141 "signed = (boolean) { TRUE, FALSE }, "
144 "rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]")
148 gst_alsasrc_finalize (GObject * object)
150 GstAlsaSrc *src = GST_ALSA_SRC (object);
152 g_free (src->device);
153 g_mutex_free (src->alsa_lock);
155 G_OBJECT_CLASS (parent_class)->finalize (object);
159 gst_alsasrc_interface_supported (GstAlsaSrc * this, GType interface_type)
161 /* only support this one interface (wrapped by GstImplementsInterface) */
162 g_assert (interface_type == GST_TYPE_MIXER);
164 return gst_alsasrc_mixer_supported (this, interface_type);
168 gst_implements_interface_init (GstImplementsInterfaceClass * klass)
170 klass->supported = (gpointer) gst_alsasrc_interface_supported;
174 gst_alsasrc_init_interfaces (GType type)
176 static const GInterfaceInfo implements_iface_info = {
177 (GInterfaceInitFunc) gst_implements_interface_init,
181 static const GInterfaceInfo mixer_iface_info = {
182 (GInterfaceInitFunc) gst_alsasrc_mixer_interface_init,
187 g_type_add_interface_static (type, GST_TYPE_IMPLEMENTS_INTERFACE,
188 &implements_iface_info);
189 g_type_add_interface_static (type, GST_TYPE_MIXER, &mixer_iface_info);
191 gst_alsa_type_add_device_property_probe_interface (type);
195 gst_alsasrc_base_init (gpointer g_class)
197 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
199 gst_element_class_set_details (element_class, &gst_alsasrc_details);
201 gst_element_class_add_pad_template (element_class,
202 gst_static_pad_template_get (&alsasrc_src_factory));
206 gst_alsasrc_class_init (GstAlsaSrcClass * klass)
208 GObjectClass *gobject_class;
209 GstElementClass *gstelement_class;
210 GstBaseSrcClass *gstbasesrc_class;
211 GstBaseAudioSrcClass *gstbaseaudiosrc_class;
212 GstAudioSrcClass *gstaudiosrc_class;
214 gobject_class = (GObjectClass *) klass;
215 gstelement_class = (GstElementClass *) klass;
216 gstbasesrc_class = (GstBaseSrcClass *) klass;
217 gstbaseaudiosrc_class = (GstBaseAudioSrcClass *) klass;
218 gstaudiosrc_class = (GstAudioSrcClass *) klass;
220 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_alsasrc_finalize);
221 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_alsasrc_get_property);
222 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_alsasrc_set_property);
224 gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_alsasrc_getcaps);
226 gstaudiosrc_class->open = GST_DEBUG_FUNCPTR (gst_alsasrc_open);
227 gstaudiosrc_class->prepare = GST_DEBUG_FUNCPTR (gst_alsasrc_prepare);
228 gstaudiosrc_class->unprepare = GST_DEBUG_FUNCPTR (gst_alsasrc_unprepare);
229 gstaudiosrc_class->close = GST_DEBUG_FUNCPTR (gst_alsasrc_close);
230 gstaudiosrc_class->read = GST_DEBUG_FUNCPTR (gst_alsasrc_read);
231 gstaudiosrc_class->delay = GST_DEBUG_FUNCPTR (gst_alsasrc_delay);
232 gstaudiosrc_class->reset = GST_DEBUG_FUNCPTR (gst_alsasrc_reset);
234 g_object_class_install_property (gobject_class, PROP_DEVICE,
235 g_param_spec_string ("device", "Device",
236 "ALSA device, as defined in an asound configuration file",
237 DEFAULT_PROP_DEVICE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
239 g_object_class_install_property (gobject_class, PROP_DEVICE_NAME,
240 g_param_spec_string ("device-name", "Device name",
241 "Human-readable name of the sound device",
242 DEFAULT_PROP_DEVICE_NAME, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
246 gst_alsasrc_set_property (GObject * object, guint prop_id,
247 const GValue * value, GParamSpec * pspec)
251 src = GST_ALSA_SRC (object);
255 g_free (src->device);
256 src->device = g_value_dup_string (value);
257 if (src->device == NULL) {
258 src->device = g_strdup (DEFAULT_PROP_DEVICE);
262 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
268 gst_alsasrc_get_property (GObject * object, guint prop_id,
269 GValue * value, GParamSpec * pspec)
273 src = GST_ALSA_SRC (object);
277 g_value_set_string (value, src->device);
279 case PROP_DEVICE_NAME:
280 g_value_take_string (value,
281 gst_alsa_find_device_name (GST_OBJECT_CAST (src),
282 src->device, src->handle, SND_PCM_STREAM_CAPTURE));
285 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
291 gst_alsasrc_init (GstAlsaSrc * alsasrc, GstAlsaSrcClass * g_class)
293 GST_DEBUG_OBJECT (alsasrc, "initializing");
295 alsasrc->device = g_strdup (DEFAULT_PROP_DEVICE);
296 alsasrc->cached_caps = NULL;
298 alsasrc->alsa_lock = g_mutex_new ();
301 #define CHECK(call, error) \
303 if ((err = call) < 0) \
309 gst_alsasrc_getcaps (GstBaseSrc * bsrc)
311 GstElementClass *element_class;
312 GstPadTemplate *pad_template;
316 src = GST_ALSA_SRC (bsrc);
318 if (src->handle == NULL) {
319 GST_DEBUG_OBJECT (src, "device not open, using template caps");
320 return NULL; /* base class will get template caps for us */
323 if (src->cached_caps) {
324 GST_LOG_OBJECT (src, "Returning cached caps");
325 return gst_caps_ref (src->cached_caps);
328 element_class = GST_ELEMENT_GET_CLASS (src);
329 pad_template = gst_element_class_get_pad_template (element_class, "src");
330 g_return_val_if_fail (pad_template != NULL, NULL);
332 caps = gst_alsa_probe_supported_formats (GST_OBJECT (src), src->handle,
333 gst_pad_template_get_caps (pad_template));
336 src->cached_caps = gst_caps_ref (caps);
339 GST_INFO_OBJECT (src, "returning caps %" GST_PTR_FORMAT, caps);
345 set_hwparams (GstAlsaSrc * alsa)
349 snd_pcm_hw_params_t *params;
351 snd_pcm_hw_params_malloc (¶ms);
353 /* choose all parameters */
354 CHECK (snd_pcm_hw_params_any (alsa->handle, params), no_config);
355 /* set the interleaved read/write format */
356 CHECK (snd_pcm_hw_params_set_access (alsa->handle, params, alsa->access),
358 /* set the sample format */
359 CHECK (snd_pcm_hw_params_set_format (alsa->handle, params, alsa->format),
361 /* set the count of channels */
362 CHECK (snd_pcm_hw_params_set_channels (alsa->handle, params, alsa->channels),
364 /* set the stream rate */
366 CHECK (snd_pcm_hw_params_set_rate_near (alsa->handle, params, &rrate, NULL),
368 if (rrate != alsa->rate)
371 if (alsa->buffer_time != -1) {
372 /* set the buffer time */
373 CHECK (snd_pcm_hw_params_set_buffer_time_near (alsa->handle, params,
374 &alsa->buffer_time, &dir), buffer_time);
376 if (alsa->period_time != -1) {
377 /* set the period time */
378 CHECK (snd_pcm_hw_params_set_period_time_near (alsa->handle, params,
379 &alsa->period_time, &dir), period_time);
382 /* write the parameters to device */
383 CHECK (snd_pcm_hw_params (alsa->handle, params), set_hw_params);
385 CHECK (snd_pcm_hw_params_get_buffer_size (params, &alsa->buffer_size),
388 CHECK (snd_pcm_hw_params_get_period_size (params, &alsa->period_size, &dir),
391 snd_pcm_hw_params_free (params);
397 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
398 ("Broken configuration for recording: no configurations available: %s",
399 snd_strerror (err)));
400 snd_pcm_hw_params_free (params);
405 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
406 ("Access type not available for recording: %s", snd_strerror (err)));
407 snd_pcm_hw_params_free (params);
412 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
413 ("Sample format not available for recording: %s", snd_strerror (err)));
414 snd_pcm_hw_params_free (params);
421 if ((alsa->channels) == 1)
422 msg = g_strdup (_("Could not open device for recording in mono mode."));
423 if ((alsa->channels) == 2)
424 msg = g_strdup (_("Could not open device for recording in stereo mode."));
425 if ((alsa->channels) > 2)
428 ("Could not open device for recording in %d-channel mode"),
430 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (msg), (snd_strerror (err)));
432 snd_pcm_hw_params_free (params);
437 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
438 ("Rate %iHz not available for recording: %s",
439 alsa->rate, snd_strerror (err)));
440 snd_pcm_hw_params_free (params);
445 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
446 ("Rate doesn't match (requested %iHz, get %iHz)", alsa->rate, err));
447 snd_pcm_hw_params_free (params);
452 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
453 ("Unable to set buffer time %i for recording: %s",
454 alsa->buffer_time, snd_strerror (err)));
455 snd_pcm_hw_params_free (params);
460 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
461 ("Unable to get buffer size for recording: %s", snd_strerror (err)));
462 snd_pcm_hw_params_free (params);
467 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
468 ("Unable to set period time %i for recording: %s", alsa->period_time,
469 snd_strerror (err)));
470 snd_pcm_hw_params_free (params);
475 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
476 ("Unable to get period size for recording: %s", snd_strerror (err)));
477 snd_pcm_hw_params_free (params);
482 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
483 ("Unable to set hw params for recording: %s", snd_strerror (err)));
484 snd_pcm_hw_params_free (params);
490 set_swparams (GstAlsaSrc * alsa)
493 snd_pcm_sw_params_t *params;
495 snd_pcm_sw_params_malloc (¶ms);
497 /* get the current swparams */
498 CHECK (snd_pcm_sw_params_current (alsa->handle, params), no_config);
499 /* allow the transfer when at least period_size samples can be processed */
500 CHECK (snd_pcm_sw_params_set_avail_min (alsa->handle, params,
501 alsa->period_size), set_avail);
502 /* start the transfer on first read */
503 CHECK (snd_pcm_sw_params_set_start_threshold (alsa->handle, params,
504 0), start_threshold);
506 #if GST_CHECK_ALSA_VERSION(1,0,16)
507 /* snd_pcm_sw_params_set_xfer_align() is deprecated, alignment is always 1 */
509 /* align all transfers to 1 sample */
510 CHECK (snd_pcm_sw_params_set_xfer_align (alsa->handle, params, 1), set_align);
513 /* write the parameters to the recording device */
514 CHECK (snd_pcm_sw_params (alsa->handle, params), set_sw_params);
516 snd_pcm_sw_params_free (params);
522 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
523 ("Unable to determine current swparams for playback: %s",
524 snd_strerror (err)));
525 snd_pcm_sw_params_free (params);
530 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
531 ("Unable to set start threshold mode for playback: %s",
532 snd_strerror (err)));
533 snd_pcm_sw_params_free (params);
538 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
539 ("Unable to set avail min for playback: %s", snd_strerror (err)));
540 snd_pcm_sw_params_free (params);
543 #if !GST_CHECK_ALSA_VERSION(1,0,16)
546 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
547 ("Unable to set transfer align for playback: %s", snd_strerror (err)));
548 snd_pcm_sw_params_free (params);
554 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
555 ("Unable to set sw params for playback: %s", snd_strerror (err)));
556 snd_pcm_sw_params_free (params);
562 alsasrc_parse_spec (GstAlsaSrc * alsa, GstRingBufferSpec * spec)
564 switch (spec->type) {
565 case GST_BUFTYPE_LINEAR:
566 alsa->format = snd_pcm_build_linear_format (spec->depth, spec->width,
567 spec->sign ? 0 : 1, spec->bigend ? 1 : 0);
569 case GST_BUFTYPE_FLOAT:
570 switch (spec->format) {
572 alsa->format = SND_PCM_FORMAT_FLOAT_LE;
575 alsa->format = SND_PCM_FORMAT_FLOAT_BE;
578 alsa->format = SND_PCM_FORMAT_FLOAT64_LE;
581 alsa->format = SND_PCM_FORMAT_FLOAT64_BE;
587 case GST_BUFTYPE_A_LAW:
588 alsa->format = SND_PCM_FORMAT_A_LAW;
590 case GST_BUFTYPE_MU_LAW:
591 alsa->format = SND_PCM_FORMAT_MU_LAW;
597 alsa->rate = spec->rate;
598 alsa->channels = spec->channels;
599 alsa->buffer_time = spec->buffer_time;
600 alsa->period_time = spec->latency_time;
601 alsa->access = SND_PCM_ACCESS_RW_INTERLEAVED;
613 gst_alsasrc_open (GstAudioSrc * asrc)
618 alsa = GST_ALSA_SRC (asrc);
620 CHECK (snd_pcm_open (&alsa->handle, alsa->device, SND_PCM_STREAM_CAPTURE,
621 SND_PCM_NONBLOCK), open_error);
624 alsa->mixer = gst_alsa_mixer_new (alsa->device, GST_ALSA_MIXER_CAPTURE);
632 GST_ELEMENT_ERROR (alsa, RESOURCE, BUSY,
633 (_("Could not open audio device for recording. "
634 "Device is being used by another application.")),
635 ("Device '%s' is busy", alsa->device));
637 GST_ELEMENT_ERROR (alsa, RESOURCE, OPEN_READ,
638 (_("Could not open audio device for recording.")),
639 ("Recording open error on device '%s': %s", alsa->device,
640 snd_strerror (err)));
647 gst_alsasrc_prepare (GstAudioSrc * asrc, GstRingBufferSpec * spec)
652 alsa = GST_ALSA_SRC (asrc);
654 if (!alsasrc_parse_spec (alsa, spec))
657 CHECK (snd_pcm_nonblock (alsa->handle, 0), non_block);
659 CHECK (set_hwparams (alsa), hw_params_failed);
660 CHECK (set_swparams (alsa), sw_params_failed);
661 CHECK (snd_pcm_prepare (alsa->handle), prepare_failed);
663 alsa->bytes_per_sample = spec->bytes_per_sample;
664 spec->segsize = alsa->period_size * spec->bytes_per_sample;
665 spec->segtotal = alsa->buffer_size / alsa->period_size;
666 spec->silence_sample[0] = 0;
667 spec->silence_sample[1] = 0;
668 spec->silence_sample[2] = 0;
669 spec->silence_sample[3] = 0;
676 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
677 ("Error parsing spec"));
682 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
683 ("Could not set device to blocking: %s", snd_strerror (err)));
688 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
689 ("Setting of hwparams failed: %s", snd_strerror (err)));
694 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
695 ("Setting of swparams failed: %s", snd_strerror (err)));
700 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
701 ("Prepare failed: %s", snd_strerror (err)));
707 gst_alsasrc_unprepare (GstAudioSrc * asrc)
712 alsa = GST_ALSA_SRC (asrc);
714 CHECK (snd_pcm_drop (alsa->handle), drop);
716 CHECK (snd_pcm_hw_free (alsa->handle), hw_free);
718 CHECK (snd_pcm_nonblock (alsa->handle, 1), non_block);
725 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
726 ("Could not drop samples: %s", snd_strerror (err)));
731 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
732 ("Could not free hw params: %s", snd_strerror (err)));
737 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
738 ("Could not set device to nonblocking: %s", snd_strerror (err)));
744 gst_alsasrc_close (GstAudioSrc * asrc)
746 GstAlsaSrc *alsa = GST_ALSA_SRC (asrc);
748 snd_pcm_close (alsa->handle);
751 gst_alsa_mixer_free (alsa->mixer);
755 gst_caps_replace (&alsa->cached_caps, NULL);
761 * Underrun and suspend recovery
764 xrun_recovery (GstAlsaSrc * alsa, snd_pcm_t * handle, gint err)
766 GST_DEBUG_OBJECT (alsa, "xrun recovery %d", err);
768 if (err == -EPIPE) { /* under-run */
769 err = snd_pcm_prepare (handle);
771 GST_WARNING_OBJECT (alsa,
772 "Can't recovery from underrun, prepare failed: %s",
775 } else if (err == -ESTRPIPE) {
776 while ((err = snd_pcm_resume (handle)) == -EAGAIN)
777 g_usleep (100); /* wait until the suspend flag is released */
780 err = snd_pcm_prepare (handle);
782 GST_WARNING_OBJECT (alsa,
783 "Can't recovery from suspend, prepare failed: %s",
792 gst_alsasrc_read (GstAudioSrc * asrc, gpointer data, guint length)
799 alsa = GST_ALSA_SRC (asrc);
801 cptr = length / alsa->bytes_per_sample;
804 GST_ALSA_SRC_LOCK (asrc);
806 if ((err = snd_pcm_readi (alsa->handle, ptr, cptr)) < 0) {
807 if (err == -EAGAIN) {
808 GST_DEBUG_OBJECT (asrc, "Read error: %s", snd_strerror (err));
810 } else if (xrun_recovery (alsa, alsa->handle, err) < 0) {
816 ptr += err * alsa->channels;
819 GST_ALSA_SRC_UNLOCK (asrc);
821 return length - cptr;
825 GST_ALSA_SRC_UNLOCK (asrc);
826 return length; /* skip one period */
831 gst_alsasrc_delay (GstAudioSrc * asrc)
834 snd_pcm_sframes_t delay;
837 alsa = GST_ALSA_SRC (asrc);
839 res = snd_pcm_delay (alsa->handle, &delay);
840 if (G_UNLIKELY (res < 0)) {
841 GST_DEBUG_OBJECT (alsa, "snd_pcm_delay returned %d", res);
845 return CLAMP (delay, 0, alsa->buffer_size);
849 gst_alsasrc_reset (GstAudioSrc * asrc)
854 alsa = GST_ALSA_SRC (asrc);
856 GST_ALSA_SRC_LOCK (asrc);
857 GST_DEBUG_OBJECT (alsa, "drop");
858 CHECK (snd_pcm_drop (alsa->handle), drop_error);
859 GST_DEBUG_OBJECT (alsa, "prepare");
860 CHECK (snd_pcm_prepare (alsa->handle), prepare_error);
861 GST_DEBUG_OBJECT (alsa, "reset done");
862 GST_ALSA_SRC_UNLOCK (asrc);
869 GST_ERROR_OBJECT (alsa, "alsa-reset: pcm drop error: %s",
871 GST_ALSA_SRC_UNLOCK (asrc);
876 GST_ERROR_OBJECT (alsa, "alsa-reset: pcm prepare error: %s",
878 GST_ALSA_SRC_UNLOCK (asrc);