[alsa-devel] Alsa Pulse plugin pcm->ptr initialization problem
Dake Gu
Dake.Gu at palm.com
Thu Apr 16 01:40:15 CEST 2009
Hi all,
By looking through the pcm_pulse.c(1.0.18), I found there is a possible error in initializing the pcm->ptr.
Some background: see update_ptr() function in pcm_pulse.c:
Basically the pcm->ptr is increased when pa_stream_writable_size() increases. The last pa_stream_writable_size() is saved in pcm->last_size, so if new pa_stream_writable_size() value is larger than pcm->last_size, the pcm->ptr is increased. For example, the pa_stream_writable_size() increases from 800 to 1400, then pcm->ptr is increased by 400. Alsa-lib's snd_pcm_ioplug_hw_ptr_update() function is calling pulse_pointer() to get pcm->ptr, then pcm_ioplug.c calculates the hw.ptr from the changes of pulse_pointer(). The hw.ptr is used in snd_pcm_mmap_playback_avail().
However, there is an issue that during the pulse is started, the pcm->last_size jumps from 0 to a positive value, which should not be counted as pcm->ptr increase. It's causing the hw.ptr wrongly calculated.
Wrong senario
pa_writable (N/A) 1000 900 800 1200
pcm->ptr 0 1000 1000 1000 1400 .....
hw.ptr 0 1000 1000 1000 1400
Correct scenario:
pa_writable (N/A) 1000 900 800 1200
pcm->ptr 0 0 0 0 400 .....
hw.ptr 0 0 0 0 400
If hw.ptr is incorrectly set larger than actual size, it causes avail>"real avail" and client sends more data than pulse can accept.
Dake
More information about the Alsa-devel
mailing list