sound: fix long latency.

This commit is contained in:
Zhang Zhaolong 2014-03-12 17:02:45 +08:00
parent 69c926eb37
commit 9cf6d1d9ae

View File

@ -115,9 +115,7 @@ static int rdpsnd_alsa_set_hw_params(rdpsndAlsaPlugin* alsa)
status = snd_pcm_hw_params_set_buffer_size_near(alsa->pcm_handle, hw_params, &alsa->buffer_size);
SND_PCM_CHECK("snd_pcm_hw_params_set_buffer_size_near", status);
/* Get period size */
status = snd_pcm_hw_params_get_period_size_min(hw_params, &alsa->period_size, NULL);
SND_PCM_CHECK("snd_pcm_hw_params_get_period_size_min", status);
alsa->period_size = alsa->buffer_size / 2;
/* Set period size */
status = snd_pcm_hw_params_set_period_size_near(alsa->pcm_handle, hw_params, &alsa->period_size, NULL);
@ -191,12 +189,12 @@ static int rdpsnd_alsa_set_params(rdpsndAlsaPlugin* alsa)
* It is also possible for the buffer size to not be an integer multiple of the period size.
*/
int interrupts_per_sec_near = 20;
int bytes_per_sec = alsa->actual_rate * alsa->bytes_per_channel * alsa->actual_channels;
snd_pcm_drop(alsa->pcm_handle);
if (alsa->latency < 0)
alsa->latency = 400;
alsa->buffer_size = alsa->latency * (alsa->actual_rate / 1000);
alsa->buffer_size = bytes_per_sec / (interrupts_per_sec_near / 2);
if (rdpsnd_alsa_set_hw_params(alsa) < 0)
return -1;