From: Lennart Poettering Date: Fri, 4 Apr 2008 16:06:47 +0000 (+0000) Subject: propery calculate min_avail in frames instead of bytes. don't use device_id= paramete... X-Git-Tag: submit/2.0-panda/20130828.192557~2837^2^2~180 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b9c10f2c56fc34b5ff99b0a9b3959b4d37586a39;p=profile%2Fivi%2Fpulseaudio-panda.git propery calculate min_avail in frames instead of bytes. don't use device_id= parameter in alsa modules if parameter wasn't specified git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/glitch-free@2218 fefdeb5f-60dc-0310-8127-8f9354f1896f --- diff --git a/src/modules/alsa-util.c b/src/modules/alsa-util.c index d899eae..38ea863 100644 --- a/src/modules/alsa-util.c +++ b/src/modules/alsa-util.c @@ -426,7 +426,7 @@ finish: return ret; } -int pa_alsa_set_sw_params(snd_pcm_t *pcm, size_t avail_min) { +int pa_alsa_set_sw_params(snd_pcm_t *pcm, snd_pcm_uframes_t avail_min) { snd_pcm_sw_params_t *swparams; int err; diff --git a/src/modules/alsa-util.h b/src/modules/alsa-util.h index 62c1d43..dee955f 100644 --- a/src/modules/alsa-util.h +++ b/src/modules/alsa-util.h @@ -48,7 +48,7 @@ int pa_alsa_set_hw_params( pa_bool_t *use_tsched, pa_bool_t require_exact_channel_number); -int pa_alsa_set_sw_params(snd_pcm_t *pcm, size_t avail_min); +int pa_alsa_set_sw_params(snd_pcm_t *pcm, snd_pcm_uframes_t avail_min); int pa_alsa_prepare_mixer(snd_mixer_t *mixer, const char *dev); snd_mixer_elem_t *pa_alsa_find_elem(snd_mixer_t *mixer, const char *name, const char *fallback); diff --git a/src/modules/module-alsa-sink.c b/src/modules/module-alsa-sink.c index 1dccf67..cd3ebcc 100644 --- a/src/modules/module-alsa-sink.c +++ b/src/modules/module-alsa-sink.c @@ -74,7 +74,7 @@ PA_MODULE_USAGE( #define DEFAULT_DEVICE "default" #define DEFAULT_TSCHED_BUFFER_USEC (2*PA_USEC_PER_SEC) -#define DEFAULT_TSCHED_WATERMARK_USEC (10*PA_USEC_PER_MSEC) +#define DEFAULT_TSCHED_WATERMARK_USEC (100*PA_USEC_PER_MSEC) struct userdata { pa_core *core; @@ -160,8 +160,10 @@ static int mmap_write(struct userdata *u) { if ((err = snd_pcm_recover(u->pcm_handle, n, 1)) == 0) continue; - if (err == -EAGAIN) + if (err == -EAGAIN) { + pa_log_debug("EAGAIN"); return work_done; + } pa_log("snd_pcm_avail_update: %s", snd_strerror(err)); return -1; @@ -187,8 +189,10 @@ static int mmap_write(struct userdata *u) { if ((err = snd_pcm_recover(u->pcm_handle, err, 1)) == 0) continue; - if (err == -EAGAIN) + if (err == -EAGAIN) { + pa_log_debug("EAGAIN"); return work_done; + } pa_log("Failed to write data to DSP: %s", snd_strerror(err)); return -1; @@ -226,8 +230,10 @@ static int mmap_write(struct userdata *u) { if ((err = snd_pcm_recover(u->pcm_handle, err, 1)) == 0) continue; - if (err == -EAGAIN) + if (err == -EAGAIN) { + pa_log_debug("EAGAIN"); return work_done; + } pa_log("Failed to write data to DSP: %s", snd_strerror(err)); return -1; @@ -300,8 +306,10 @@ static int unix_write(struct userdata *u) { if ((frames = snd_pcm_recover(u->pcm_handle, frames, 1)) == 0) continue; - if (frames == -EAGAIN) + if (frames == -EAGAIN) { + pa_log_debug("EAGAIN"); return work_done; + } pa_log("Failed to write data to DSP: %s", snd_strerror(frames)); return -1; @@ -468,7 +476,7 @@ static void update_hwbuf_unused_frames(struct userdata *u) { } static int update_sw_params(struct userdata *u) { - size_t avail_min; + snd_pcm_uframes_t avail_min; int err; pa_assert(u); @@ -478,7 +486,7 @@ static int update_sw_params(struct userdata *u) { usec = hw_sleep_time(u); - avail_min = pa_usec_to_bytes(usec, &u->sink->sample_spec); + avail_min = pa_usec_to_bytes(usec, &u->sink->sample_spec) / u->frame_size; if (avail_min <= 0) avail_min = 1; @@ -486,6 +494,10 @@ static int update_sw_params(struct userdata *u) { } else avail_min = 1; + avail_min = (snd_pcm_uframes_t) -1; + + pa_log("setting avail_min=%lu", (unsigned long) avail_min); + if ((err = pa_alsa_set_sw_params(u->pcm_handle, avail_min)) < 0) { pa_log("Failed to set software parameters: %s", snd_strerror(err)); return err; @@ -493,6 +505,8 @@ static int update_sw_params(struct userdata *u) { update_hwbuf_unused_frames(u); + pa_log("hwbuf_unused_frames=%lu", (unsigned long) u->hwbuf_unused_frames); + return 0; } @@ -810,19 +824,26 @@ static void thread_func(void *userdata) { if (frames > limit) frames = limit; - pa_log_debug("Limited to %lu bytes.", (unsigned long) frames * u->frame_size); + frames = 0; - if ((frames = snd_pcm_rewind(u->pcm_handle, frames)) < 0) { - pa_log("snd_pcm_rewind() failed: %s", snd_strerror(frames)); - goto fail; - } + if (frames > 0) { + + pa_log_debug("Limited to %lu bytes.", (unsigned long) frames * u->frame_size); + + if ((frames = snd_pcm_rewind(u->pcm_handle, frames)) < 0) { + pa_log("snd_pcm_rewind() failed: %s", snd_strerror(frames)); + goto fail; + } - if ((u->sink->thread_info.rewind_nbytes = frames * u->frame_size) <= 0) - pa_log_info("Tried rewind, but was apparently not possible."); - else { - u->frame_index -= frames; - pa_log_debug("Rewound %lu bytes.", (unsigned long) u->sink->thread_info.rewind_nbytes); - pa_sink_process_rewind(u->sink); + if ((u->sink->thread_info.rewind_nbytes = frames * u->frame_size) <= 0) + pa_log_info("Tried rewind, but was apparently not possible."); + else { + u->frame_index -= frames; + pa_log_debug("Rewound %lu bytes.", (unsigned long) u->sink->thread_info.rewind_nbytes); + pa_sink_process_rewind(u->sink); + } + } else { + pa_log_debug("Mhmm, actually there is nothing to rewind."); } } @@ -851,7 +872,7 @@ static void thread_func(void *userdata) { } if (u->use_tsched) { - pa_usec_t usec, cusec; + pa_usec_t usec, cusec, sleep_usec; /* OK, the playback buffer is now full, let's * calculate when to wake up next */ @@ -866,8 +887,12 @@ static void thread_func(void *userdata) { pa_log_debug("Waking up in %0.2fms (system clock).", (double) cusec / PA_USEC_PER_MSEC); + sleep_usec = PA_MIN(usec, cusec); + + pa_log_debug("Waking up in %0.2fms (smaller value).", (double) sleep_usec / PA_USEC_PER_MSEC); + /* We don't trust the conversion, so we wake up whatever comes first */ - pa_rtpoll_set_timer_relative(u->rtpoll, PA_MIN(usec, cusec)); + pa_rtpoll_set_timer_relative(u->rtpoll, sleep_usec); } } else if (u->use_tsched) { @@ -1107,7 +1132,7 @@ int pa__init(pa_module*m) { if (pa_alsa_prepare_mixer(u->mixer_handle, u->device_name) >= 0) found = TRUE; - else { + else if (dev_id) { char *md = pa_sprintf_malloc("hw:%s", dev_id); if (strcmp(u->device_name, md)) diff --git a/src/modules/module-alsa-source.c b/src/modules/module-alsa-source.c index af20f81..901e342 100644 --- a/src/modules/module-alsa-source.c +++ b/src/modules/module-alsa-source.c @@ -979,7 +979,7 @@ int pa__init(pa_module*m) { if (pa_alsa_prepare_mixer(u->mixer_handle, u->device_name) >= 0) found = TRUE; - else { + else if (dev_id) { char *md = pa_sprintf_malloc("hw:%s", dev_id); if (strcmp(u->device_name, md))