diff --git a/branches/2.0/doubango/tinyDAV/src/audio/alsa/tdav_common_alsa.c b/branches/2.0/doubango/tinyDAV/src/audio/alsa/tdav_common_alsa.c index 8ddbffdf..d1deec89 100644 --- a/branches/2.0/doubango/tinyDAV/src/audio/alsa/tdav_common_alsa.c +++ b/branches/2.0/doubango/tinyDAV/src/audio/alsa/tdav_common_alsa.c @@ -24,6 +24,8 @@ #define ALSA_DEBUG_ERROR(FMT, ...) TSK_DEBUG_ERROR("[ALSA Common] " FMT, ##__VA_ARGS__) #define ALSA_DEBUG_FATAL(FMT, ...) TSK_DEBUG_FATAL("[ALSA Common] " FMT, ##__VA_ARGS__) +#define ALSA_PLAYBACK_PERIODS 6 + int tdav_common_alsa_init(tdav_common_alsa_t* p_self) { if (!p_self) { @@ -117,15 +119,22 @@ int tdav_common_alsa_prepare(tdav_common_alsa_t* p_self, tsk_bool_t is_capture, } ALSA_DEBUG_INFO("channels: req=%d, resp=%d", channels, val); p_self->channels = val; - -#if 1 - val = ((ptime * p_self->sample_rate * p_self->channels) / 1000); - if ((err = snd_pcm_hw_params_set_period_size_near(p_self->p_handle, p_self->p_params, &val, 0)) != 0) { - ALSA_DEBUG_ERROR ("Failed to prepare device (channels=%d, rate=%d, device=%s, err=%s)", p_self->channels, p_self->sample_rate, p_self->p_device_name, snd_strerror(err)); + + if (!is_capture) { + unsigned int periods = ALSA_PLAYBACK_PERIODS; + snd_pcm_uframes_t periodSize = (ptime * p_self->sample_rate * p_self->channels) / 1000; + if ((err = snd_pcm_hw_params_set_periods_near(p_self->p_handle, p_self->p_params, &periods, 0)) != 0) { + ALSA_DEBUG_ERROR ("Failed to set periods (val=%u, device=%s, err=%s)", periods, p_self->p_device_name, snd_strerror(err)); goto bail; + } + + snd_pcm_uframes_t bufferSize = (periodSize * periods); + if ((err = snd_pcm_hw_params_set_buffer_size(p_self->p_handle, p_self->p_params, bufferSize)) != 0) { + ALSA_DEBUG_ERROR ("Failed to set buffer size (val=%lu, device=%s, err=%s)", bufferSize, p_self->p_device_name, snd_strerror(err)); + goto bail; + } + ALSA_DEBUG_INFO("periods=%u, buffersize=%lu", periods, bufferSize); } - ALSA_DEBUG_INFO("period size: req=%d, resp=%d", val, val); // FIXME -#endif if ((err = snd_pcm_hw_params (p_self->p_handle, p_self->p_params)) != 0) { ALSA_DEBUG_ERROR ("Failed to set parameters (channels=%d, rate=%d, device=%s, err=%s)", p_self->channels, p_self->sample_rate, p_self->p_device_name, snd_strerror(err)); diff --git a/branches/2.0/doubango/tinyDAV/src/audio/alsa/tdav_consumer_alsa.c b/branches/2.0/doubango/tinyDAV/src/audio/alsa/tdav_consumer_alsa.c index 28128999..65bfcd86 100644 --- a/branches/2.0/doubango/tinyDAV/src/audio/alsa/tdav_consumer_alsa.c +++ b/branches/2.0/doubango/tinyDAV/src/audio/alsa/tdav_consumer_alsa.c @@ -171,20 +171,20 @@ static int tdav_consumer_alsa_consume(tmedia_consumer_t* self, const void* buffe tdav_consumer_alsa_t* p_alsa = (tdav_consumer_alsa_t*)self; if (!p_alsa || !buffer || !size) { - OSS_DEBUG_ERROR("Invalid paramter"); + ALSA_DEBUG_ERROR("Invalid paramter"); return -1; } //tdav_common_alsa_lock(&p_alsa->alsa_common); if (!p_alsa->b_started) { - OSS_DEBUG_WARN("Not started"); + ALSA_DEBUG_WARN("Not started"); err = -2; goto bail; } if ((err = tdav_consumer_audio_put(TDAV_CONSUMER_AUDIO(p_alsa), buffer, size, proto_hdr))) {//thread-safe - OSS_DEBUG_WARN("Failed to put audio data to the jitter buffer"); + ALSA_DEBUG_WARN("Failed to put audio data to the jitter buffer"); goto bail; }