Lines Matching refs:alsa
251 GstAlsaSrc *alsa = GST_ALSA_SRC (element); in gst_alsasrc_change_state() local
267 alsa->driver_timestamps = FALSE; in gst_alsasrc_change_state()
275 alsa->use_driver_timestamps) { in gst_alsasrc_change_state()
277 alsa->driver_timestamps = TRUE; in gst_alsasrc_change_state()
280 alsa->driver_timestamps = FALSE; in gst_alsasrc_change_state()
367 set_hwparams (GstAlsaSrc * alsa) in set_hwparams() argument
377 CHECK (snd_pcm_hw_params_any (alsa->handle, params), no_config); in set_hwparams()
379 CHECK (snd_pcm_hw_params_set_access (alsa->handle, params, alsa->access), in set_hwparams()
382 CHECK (snd_pcm_hw_params_set_format (alsa->handle, params, alsa->format), in set_hwparams()
385 CHECK (snd_pcm_hw_params_set_channels (alsa->handle, params, alsa->channels), in set_hwparams()
388 rrate = alsa->rate; in set_hwparams()
389 CHECK (snd_pcm_hw_params_set_rate_near (alsa->handle, params, &rrate, NULL), in set_hwparams()
391 if (rrate != alsa->rate) in set_hwparams()
402 GST_DEBUG_OBJECT (alsa, "buffer time %u, min %u, max %u", in set_hwparams()
403 alsa->buffer_time, min, max); in set_hwparams()
408 GST_DEBUG_OBJECT (alsa, "period time %u, min %u, max %u", in set_hwparams()
409 alsa->period_time, min, max); in set_hwparams()
414 GST_DEBUG_OBJECT (alsa, "periods min %u, max %u", min, max); in set_hwparams()
424 if (alsa->period_time != -1 && alsa->buffer_time != -1) { in set_hwparams()
425 if ((snd_pcm_hw_params_set_period_time_near (alsa->handle, params, in set_hwparams()
426 &alsa->period_time, NULL) >= 0) in set_hwparams()
427 && (snd_pcm_hw_params_set_buffer_time_near (alsa->handle, params, in set_hwparams()
428 &alsa->buffer_time, NULL) >= 0)) { in set_hwparams()
429 GST_DEBUG_OBJECT (alsa, "period time %u buffer time %u set correctly", in set_hwparams()
430 alsa->period_time, alsa->buffer_time); in set_hwparams()
436 if ((snd_pcm_hw_params_set_buffer_time_near (alsa->handle, params, in set_hwparams()
437 &alsa->buffer_time, NULL) >= 0) in set_hwparams()
438 && (snd_pcm_hw_params_set_period_time_near (alsa->handle, params, in set_hwparams()
439 &alsa->period_time, NULL) >= 0)) { in set_hwparams()
440 GST_DEBUG_OBJECT (alsa, "buffer time %u period time %u set correctly", in set_hwparams()
441 alsa->buffer_time, alsa->period_time); in set_hwparams()
445 if (alsa->period_time != -1) { in set_hwparams()
448 if ((snd_pcm_hw_params_set_period_time_near (alsa->handle, params, in set_hwparams()
449 &alsa->period_time, NULL) >= 0)) { in set_hwparams()
450 GST_DEBUG_OBJECT (alsa, "period time %u set correctly", in set_hwparams()
451 alsa->period_time); in set_hwparams()
455 if (alsa->buffer_time != -1) { in set_hwparams()
458 if ((snd_pcm_hw_params_set_buffer_time_near (alsa->handle, params, in set_hwparams()
459 &alsa->buffer_time, NULL) >= 0)) { in set_hwparams()
460 GST_DEBUG_OBJECT (alsa, "buffer time %u set correctly", in set_hwparams()
461 alsa->buffer_time); in set_hwparams()
467 GST_DEBUG_OBJECT (alsa, "Not setting period time and buffer time"); in set_hwparams()
471 CHECK (snd_pcm_hw_params (alsa->handle, params), set_hw_params); in set_hwparams()
472 CHECK (snd_pcm_hw_params_get_buffer_size (params, &alsa->buffer_size), in set_hwparams()
474 GST_DEBUG_OBJECT (alsa, "buffer size : %lu", alsa->buffer_size); in set_hwparams()
475 CHECK (snd_pcm_hw_params_get_period_size (params, &alsa->period_size, in set_hwparams()
477 GST_DEBUG_OBJECT (alsa, "period size : %lu", alsa->period_size); in set_hwparams()
483 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL), in set_hwparams()
490 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL), in set_hwparams()
496 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL), in set_hwparams()
504 if ((alsa->channels) == 1) in set_hwparams()
506 if ((alsa->channels) == 2) in set_hwparams()
508 if ((alsa->channels) > 2) in set_hwparams()
512 alsa->channels); in set_hwparams()
513 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, ("%s", msg), in set_hwparams()
520 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL), in set_hwparams()
522 alsa->rate, snd_strerror (err))); in set_hwparams()
527 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL), in set_hwparams()
528 ("Rate doesn't match (requested %iHz, get %iHz)", alsa->rate, err)); in set_hwparams()
534 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL), in set_hwparams()
540 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL), in set_hwparams()
546 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL), in set_hwparams()
558 set_swparams (GstAlsaSrc * alsa) in set_swparams() argument
566 CHECK (snd_pcm_sw_params_current (alsa->handle, params), no_config); in set_swparams()
568 CHECK (snd_pcm_sw_params_set_avail_min (alsa->handle, params, in set_swparams()
569 alsa->period_size), set_avail); in set_swparams()
571 CHECK (snd_pcm_sw_params_set_start_threshold (alsa->handle, params, in set_swparams()
574 CHECK (snd_pcm_sw_params_set_tstamp_mode (alsa->handle, params, in set_swparams()
581 CHECK (snd_pcm_sw_params_set_xfer_align (alsa->handle, params, 1), set_align); in set_swparams()
585 CHECK (snd_pcm_sw_params (alsa->handle, params), set_sw_params); in set_swparams()
593 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL), in set_swparams()
601 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL), in set_swparams()
609 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL), in set_swparams()
616 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL), in set_swparams()
624 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL), in set_swparams()
632 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL), in set_swparams()
640 alsasrc_parse_spec (GstAlsaSrc * alsa, GstAudioRingBufferSpec * spec) in alsasrc_parse_spec() argument
646 alsa->format = SND_PCM_FORMAT_U8; in alsasrc_parse_spec()
649 alsa->format = SND_PCM_FORMAT_S8; in alsasrc_parse_spec()
652 alsa->format = SND_PCM_FORMAT_S16_LE; in alsasrc_parse_spec()
655 alsa->format = SND_PCM_FORMAT_S16_BE; in alsasrc_parse_spec()
658 alsa->format = SND_PCM_FORMAT_U16_LE; in alsasrc_parse_spec()
661 alsa->format = SND_PCM_FORMAT_U16_BE; in alsasrc_parse_spec()
664 alsa->format = SND_PCM_FORMAT_S24_LE; in alsasrc_parse_spec()
667 alsa->format = SND_PCM_FORMAT_S24_BE; in alsasrc_parse_spec()
670 alsa->format = SND_PCM_FORMAT_U24_LE; in alsasrc_parse_spec()
673 alsa->format = SND_PCM_FORMAT_U24_BE; in alsasrc_parse_spec()
676 alsa->format = SND_PCM_FORMAT_S32_LE; in alsasrc_parse_spec()
679 alsa->format = SND_PCM_FORMAT_S32_BE; in alsasrc_parse_spec()
682 alsa->format = SND_PCM_FORMAT_U32_LE; in alsasrc_parse_spec()
685 alsa->format = SND_PCM_FORMAT_U32_BE; in alsasrc_parse_spec()
688 alsa->format = SND_PCM_FORMAT_S24_3LE; in alsasrc_parse_spec()
691 alsa->format = SND_PCM_FORMAT_S24_3BE; in alsasrc_parse_spec()
694 alsa->format = SND_PCM_FORMAT_U24_3LE; in alsasrc_parse_spec()
697 alsa->format = SND_PCM_FORMAT_U24_3BE; in alsasrc_parse_spec()
700 alsa->format = SND_PCM_FORMAT_S20_3LE; in alsasrc_parse_spec()
703 alsa->format = SND_PCM_FORMAT_S20_3BE; in alsasrc_parse_spec()
706 alsa->format = SND_PCM_FORMAT_U20_3LE; in alsasrc_parse_spec()
709 alsa->format = SND_PCM_FORMAT_U20_3BE; in alsasrc_parse_spec()
712 alsa->format = SND_PCM_FORMAT_S18_3LE; in alsasrc_parse_spec()
715 alsa->format = SND_PCM_FORMAT_S18_3BE; in alsasrc_parse_spec()
718 alsa->format = SND_PCM_FORMAT_U18_3LE; in alsasrc_parse_spec()
721 alsa->format = SND_PCM_FORMAT_U18_3BE; in alsasrc_parse_spec()
724 alsa->format = SND_PCM_FORMAT_FLOAT_LE; in alsasrc_parse_spec()
727 alsa->format = SND_PCM_FORMAT_FLOAT_BE; in alsasrc_parse_spec()
730 alsa->format = SND_PCM_FORMAT_FLOAT64_LE; in alsasrc_parse_spec()
733 alsa->format = SND_PCM_FORMAT_FLOAT64_BE; in alsasrc_parse_spec()
740 alsa->format = SND_PCM_FORMAT_A_LAW; in alsasrc_parse_spec()
743 alsa->format = SND_PCM_FORMAT_MU_LAW; in alsasrc_parse_spec()
749 alsa->rate = GST_AUDIO_INFO_RATE (&spec->info); in alsasrc_parse_spec()
750 alsa->channels = GST_AUDIO_INFO_CHANNELS (&spec->info); in alsasrc_parse_spec()
751 alsa->buffer_time = spec->buffer_time; in alsasrc_parse_spec()
752 alsa->period_time = spec->latency_time; in alsasrc_parse_spec()
753 alsa->access = SND_PCM_ACCESS_RW_INTERLEAVED; in alsasrc_parse_spec()
755 if (spec->type == GST_AUDIO_RING_BUFFER_FORMAT_TYPE_RAW && alsa->channels < 9) in alsasrc_parse_spec()
757 (alsa)->ringbuffer, alsa_position[alsa->channels - 1]); in alsasrc_parse_spec()
771 GstAlsaSrc *alsa; in gst_alsasrc_open() local
774 alsa = GST_ALSA_SRC (asrc); in gst_alsasrc_open()
776 CHECK (snd_pcm_open (&alsa->handle, alsa->device, SND_PCM_STREAM_CAPTURE, in gst_alsasrc_open()
777 (alsa->driver_timestamps) ? 0 : SND_PCM_NONBLOCK), open_error); in gst_alsasrc_open()
785 GST_ELEMENT_ERROR (alsa, RESOURCE, BUSY, in gst_alsasrc_open()
788 ("Device '%s' is busy", alsa->device)); in gst_alsasrc_open()
790 GST_ELEMENT_ERROR (alsa, RESOURCE, OPEN_READ, in gst_alsasrc_open()
792 ("Recording open error on device '%s': %s", alsa->device, in gst_alsasrc_open()
802 GstAlsaSrc *alsa; in gst_alsasrc_prepare() local
805 alsa = GST_ALSA_SRC (asrc); in gst_alsasrc_prepare()
807 if (!alsasrc_parse_spec (alsa, spec)) in gst_alsasrc_prepare()
810 CHECK (snd_pcm_nonblock (alsa->handle, 0), non_block); in gst_alsasrc_prepare()
812 CHECK (set_hwparams (alsa), hw_params_failed); in gst_alsasrc_prepare()
813 CHECK (set_swparams (alsa), sw_params_failed); in gst_alsasrc_prepare()
814 CHECK (snd_pcm_prepare (alsa->handle), prepare_failed); in gst_alsasrc_prepare()
816 alsa->bpf = GST_AUDIO_INFO_BPF (&spec->info); in gst_alsasrc_prepare()
817 spec->segsize = alsa->period_size * alsa->bpf; in gst_alsasrc_prepare()
818 spec->segtotal = alsa->buffer_size / alsa->period_size; in gst_alsasrc_prepare()
825 snd_pcm_dump_hw_setup (alsa->handle, out_buf); in gst_alsasrc_prepare()
827 GST_DEBUG_OBJECT (alsa, "Hardware setup: \n%s", msg); in gst_alsasrc_prepare()
830 snd_pcm_dump_sw_setup (alsa->handle, out_buf); in gst_alsasrc_prepare()
832 GST_DEBUG_OBJECT (alsa, "Software setup: \n%s", msg); in gst_alsasrc_prepare()
837 alsa_detect_channels_mapping (GST_OBJECT (alsa), alsa->handle, spec, in gst_alsasrc_prepare()
838 alsa->channels, GST_AUDIO_BASE_SRC (alsa)->ringbuffer); in gst_alsasrc_prepare()
846 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL), in gst_alsasrc_prepare()
852 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL), in gst_alsasrc_prepare()
858 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL), in gst_alsasrc_prepare()
864 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL), in gst_alsasrc_prepare()
870 GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL), in gst_alsasrc_prepare()
879 GstAlsaSrc *alsa; in gst_alsasrc_unprepare() local
881 alsa = GST_ALSA_SRC (asrc); in gst_alsasrc_unprepare()
883 snd_pcm_drop (alsa->handle); in gst_alsasrc_unprepare()
884 snd_pcm_hw_free (alsa->handle); in gst_alsasrc_unprepare()
885 snd_pcm_nonblock (alsa->handle, 1); in gst_alsasrc_unprepare()
893 GstAlsaSrc *alsa = GST_ALSA_SRC (asrc); in gst_alsasrc_close() local
895 snd_pcm_close (alsa->handle); in gst_alsasrc_close()
896 alsa->handle = NULL; in gst_alsasrc_close()
898 gst_caps_replace (&alsa->cached_caps, NULL); in gst_alsasrc_close()
907 xrun_recovery (GstAlsaSrc * alsa, snd_pcm_t * handle, gint err) in xrun_recovery() argument
909 GST_WARNING_OBJECT (alsa, "xrun recovery %d: %s", err, g_strerror (-err)); in xrun_recovery()
914 GST_WARNING_OBJECT (alsa, in xrun_recovery()
925 GST_WARNING_OBJECT (alsa, in xrun_recovery()
999 GstAlsaSrc *alsa; in gst_alsasrc_read() local
1004 alsa = GST_ALSA_SRC (asrc); in gst_alsasrc_read()
1006 cptr = length / alsa->bpf; in gst_alsasrc_read()
1010 if ((err = snd_pcm_readi (alsa->handle, ptr, cptr)) < 0) { in gst_alsasrc_read()
1016 } else if (xrun_recovery (alsa, alsa->handle, err) < 0) { in gst_alsasrc_read()
1022 ptr += snd_pcm_frames_to_bytes (alsa->handle, err); in gst_alsasrc_read()
1028 if (alsa->driver_timestamps && timestamp) in gst_alsasrc_read()
1029 *timestamp = gst_alsasrc_get_timestamp (alsa); in gst_alsasrc_read()
1031 return length - (cptr * alsa->bpf); in gst_alsasrc_read()
1051 GstAlsaSrc *alsa; in gst_alsasrc_delay() local
1055 alsa = GST_ALSA_SRC (asrc); in gst_alsasrc_delay()
1057 res = snd_pcm_delay (alsa->handle, &delay); in gst_alsasrc_delay()
1059 GST_DEBUG_OBJECT (alsa, "snd_pcm_delay returned %d", res); in gst_alsasrc_delay()
1063 return CLAMP (delay, 0, alsa->buffer_size); in gst_alsasrc_delay()
1069 GstAlsaSrc *alsa; in gst_alsasrc_reset() local
1072 alsa = GST_ALSA_SRC (asrc); in gst_alsasrc_reset()
1075 GST_DEBUG_OBJECT (alsa, "drop"); in gst_alsasrc_reset()
1076 CHECK (snd_pcm_drop (alsa->handle), drop_error); in gst_alsasrc_reset()
1077 GST_DEBUG_OBJECT (alsa, "prepare"); in gst_alsasrc_reset()
1078 CHECK (snd_pcm_prepare (alsa->handle), prepare_error); in gst_alsasrc_reset()
1079 GST_DEBUG_OBJECT (alsa, "reset done"); in gst_alsasrc_reset()
1087 GST_ERROR_OBJECT (alsa, "alsa-reset: pcm drop error: %s", in gst_alsasrc_reset()
1094 GST_ERROR_OBJECT (alsa, "alsa-reset: pcm prepare error: %s", in gst_alsasrc_reset()