From 1503b8cf9babe338e51598b0c689890f37d0850a Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 6 Sep 2010 15:26:19 +0200 Subject: alsa-source: refactor smoother and device start Move the code to start the capture and the smoother closer together to improve smoother accuracy. Rework things to look more like the alsa sink where the device is started in only one place. --- src/modules/alsa/alsa-source.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c index ecea1915..8b2cee50 100644 --- a/src/modules/alsa/alsa-source.c +++ b/src/modules/alsa/alsa-source.c @@ -116,6 +116,8 @@ struct userdata { pa_bool_t use_mmap:1, use_tsched:1; + pa_bool_t first; + pa_rtpoll_item *alsa_rtpoll_item; snd_mixer_selem_channel_id_t mixer_map[SND_MIXER_SCHN_LAST]; @@ -397,7 +399,7 @@ static int try_recover(struct userdata *u, const char *call, int err) { return -1; } - snd_pcm_start(u->pcm_handle); + u->first = TRUE; return 0; } @@ -946,13 +948,13 @@ static int unsuspend(struct userdata *u) { /* FIXME: We need to reload the volume somehow */ - snd_pcm_start(u->pcm_handle); - u->read_count = 0; - pa_smoother_reset(u->smoother, pa_rtclock_now(), FALSE); + pa_smoother_reset(u->smoother, pa_rtclock_now(), TRUE); u->smoother_interval = SMOOTHER_MIN_INTERVAL; u->last_smoother_update = 0; + u->first = TRUE; + pa_log_info("Resumed successfully..."); return 0; @@ -1003,8 +1005,6 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off if (u->source->thread_info.state == PA_SOURCE_INIT) { if (build_pollfd(u) < 0) return -PA_ERR_IO; - - snd_pcm_start(u->pcm_handle); } if (u->source->thread_info.state == PA_SOURCE_SUSPENDED) { @@ -1243,6 +1243,15 @@ static void thread_func(void *userdata) { pa_usec_t sleep_usec = 0; pa_bool_t on_timeout = pa_rtpoll_timer_elapsed(u->rtpoll); + if (u->first) { + pa_log_info("Starting capture."); + snd_pcm_start(u->pcm_handle); + + pa_smoother_resume(u->smoother, pa_rtclock_now(), TRUE); + + u->first = FALSE; + } + if (u->use_mmap) work_done = mmap_read(u, &sleep_usec, revents & POLLIN, on_timeout); else @@ -1302,7 +1311,7 @@ static void thread_func(void *userdata) { if (pa_alsa_recover_from_poll(u->pcm_handle, revents) < 0) goto fail; - snd_pcm_start(u->pcm_handle); + u->first = TRUE; } else if (revents && u->use_tsched && pa_log_ratelimit()) pa_log_debug("Wakeup from ALSA!"); @@ -1556,6 +1565,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p u->module = m; u->use_mmap = use_mmap; u->use_tsched = use_tsched; + u->first = TRUE; u->rtpoll = pa_rtpoll_new(); pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll); @@ -1566,7 +1576,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p TRUE, 5, pa_rtclock_now(), - FALSE); + TRUE); u->smoother_interval = SMOOTHER_MIN_INTERVAL; dev_id = pa_modargs_get_value( -- cgit