[alsa-devel] snd_pcm_avail_update returns 0
Hi,
Our audio driver uses the indirect PCM data transfer mechanism to transfer the buffer pointers and the size of the buffer to the Audio engine which DMAs the PCM data to the sound card.
The driver uses the .ack callback to receive the buffer pointer and the size. It also sends it to the audio engine.
We are facing a problem when we play long wav file using our driver.
The application has written the PCM data and the ring buffer is full. snd_pcm_avail_update returns 0 sporadically. But the .ack callback was not called. The playback is stuck. It is not progressing.
I have tried with pulseaudio (0.9.15) and with my own player. Both gives the same result.
I would appreciate if somebody could provide some pointer to identify the cause of this issue. Let me know if anybody needs more info.
Thanks Sing
On Thu, 14 Jan 2010, Singaravelan Nallasellan wrote:
Hi,
Our audio driver uses the indirect PCM data transfer mechanism to transfer the buffer pointers and the size of the buffer to the Audio engine which DMAs the PCM data to the sound card.
The driver uses the .ack callback to receive the buffer pointer and the size. It also sends it to the audio engine.
We are facing a problem when we play long wav file using our driver.
The application has written the PCM data and the ring buffer is full. snd_pcm_avail_update returns 0 sporadically. But the .ack callback was not called. The playback is stuck. It is not progressing.
I have tried with pulseaudio (0.9.15) and with my own player. Both gives the same result.
I would appreciate if somebody could provide some pointer to identify the cause of this issue. Let me know if anybody needs more info.
No idea. You may put some debug printk lines to snd_pcm_lib_write1() routine if all correspoding write sequences ends with ->ack callback call.
Jaroslav
----- Jaroslav Kysela perex@perex.cz Linux Kernel Sound Maintainer ALSA Project, Red Hat, Inc.
Thanks for the response.
I am using mmap for the playback. What is the return value of snd_pcm_avail_update when the ring buffer is empty? How does ALSA identify the empty buffer?
We incremented the hardware pointer continuously to large value more than the hw buffer size. ALSA core did not round of the hw_ptr properly. The firmware in the audio engine is now rounding of hw ptr in the audio engine itself. It will always report the hw ptr between 0 and hw buffer size.
Moreover our driver uses the batch mode and updates the hardware pointer for every period. Is it the right way to do?
Sing
On Thu, Jan 14, 2010 at 8:35 PM, Jaroslav Kysela perex@perex.cz wrote:
On Thu, 14 Jan 2010, Singaravelan Nallasellan wrote:
Hi,
Our audio driver uses the indirect PCM data transfer mechanism to transfer the buffer pointers and the size of the buffer to the Audio engine which DMAs the PCM data to the sound card.
The driver uses the .ack callback to receive the buffer pointer and the size. It also sends it to the audio engine.
We are facing a problem when we play long wav file using our driver.
The application has written the PCM data and the ring buffer is full. snd_pcm_avail_update returns 0 sporadically. But the .ack callback was not called. The playback is stuck. It is not progressing.
I have tried with pulseaudio (0.9.15) and with my own player. Both gives the same result.
I would appreciate if somebody could provide some pointer to identify the cause of this issue. Let me know if anybody needs more info.
No idea. You may put some debug printk lines to snd_pcm_lib_write1() routine if all correspoding write sequences ends with ->ack callback call.
Jaroslav
Jaroslav Kysela perex@perex.cz Linux Kernel Sound Maintainer ALSA Project, Red Hat, Inc.
On Thu, 14 Jan 2010, Singaravelan Nallasellan wrote:
Thanks for the response.
I am using mmap for the playback. What is the return value of snd_pcm_avail_update when the ring buffer is empty?
ring buffer size
How does ALSA identify the empty buffer?
hw_ptr == appl_ptr
We incremented the hardware pointer continuously to large value more than the hw buffer size. ALSA core did not round of the hw_ptr properly. The firmware in the audio engine is now rounding of hw ptr in the audio engine itself. It will always report the hw ptr between 0 and hw buffer size.
hw_ptr and appl_ptr are from range 0..boundary to detect xruns. The driver should not write to these values and should track own pointers.
Moreover our driver uses the batch mode and updates the hardware pointer for every period. Is it the right way to do?
I'm not sure about what pointers you're talking. If it's hw_ptr and appl_ptr, then driver shouldn't write to these pointers. The snd_pcm_period_elapsed() function should be called to synchronize hw_ptr when playback of period is finished.
Maybe you can put your code to a public place so we can check it.
Jaroslav
----- Jaroslav Kysela perex@perex.cz Linux Kernel Sound Maintainer ALSA Project, Red Hat, Inc.
Thanks again.
Sorry, I missed to ask you another question.
How does the ring buffer full detected in the core?
hw_ptr and appl_ptr are from range 0..boundary to detect xruns. The driver should not write to these values and should track own pointers.
The driver does not update the pointers. It has its own pointers wherever required.
Moreover our driver uses the batch mode and updates the hardware pointer for every period. Is it the right way to do?
Moreover our driver uses the batch mode and updates the hardware pointer for every period. Is it the right way to do?
I'm not sure about what pointers you're talking. If it's hw_ptr and appl_ptr, then driver shouldn't write to these pointers. The snd_pcm_period_elapsed() function should be called to synchronize hw_ptr when playback of period is finished.
The driver does not update the appl_ptr and hw_ptr. .pointer function just returns the pos returned by the snd_pcm_indirect_playback_pointer function. This function is called with the pointer returned from the audio engine.
Maybe you can put your code to a public place so we can check it.
Sure, can I send the complete code to this ml?
Jaroslav
Jaroslav Kysela perex@perex.cz Linux Kernel Sound Maintainer ALSA Project, Red Hat, Inc.
On Thu, 14 Jan 2010, Singaravelan Nallasellan wrote:
Thanks again.
Sorry, I missed to ask you another question.
How does the ring buffer full detected in the core?
For playback: appl_ptr - hw_ptr == ring buffer size.
Maybe you can put your code to a public place so we can check it.
Sure, can I send the complete code to this ml?
No, please. Use http://pastebin.com or something like that and send only URL to this list. Thanks.
Jaroslav
----- Jaroslav Kysela perex@perex.cz Linux Kernel Sound Maintainer ALSA Project, Red Hat, Inc.
participants (2)
-
Jaroslav Kysela
-
Singaravelan Nallasellan