[alsa-devel] Underrun problem and some basic queries

ANISH KUMAR anish.singh at samsung.com
Mon Jan 4 12:09:53 CET 2010


Dear ALSA Team,
I have some queries.Please answer them.(previous post please ignore as they couldn't appear because of encoding problem)
I am getting underrun problem whenever the playback is about to get finished.
happening in snd_pcm_update_hw_ptr_post function:
if (avail >= stop_threshold) {
        if (substream->runtime->status->state == SNDRV_PCM_STATE_DRAINING)
            snd_pcm_drain_done(substream);
        else
            xrun(substream); //here it is happening..........
        return -EPIPE;
}
1. As i understand if i dont call drain function this will happen.Ismy understanding correct?Because if am calling drain function then thisproblem is not happening.If the application doesn't call drain functionthen xrun is the only way to stop ALSA or does ALSA detect that thereare no more samples to play and automatically stop the play(if yes,canyou point out the source code)?
2. snd_pcm_playback_avail() returns the number of samples that stillneeds to be played?Below is the diagram which is my understanding.
        
    Ring buffer (DMA buffer created using preallocated buffer during system initalisation)
-----------------------------------------------------------------
|          |          |          |          |          |          |
-----------------------------------------------------------------
    ^  ^            
    |   |
hw_ptr appl_ptr
After first write call:   
-----------------------------------------------------------------
|          |          |          |          |          |          |
-----------------------------------------------------------------
     ^                               ^            
     |                                |
 appl_ptr                     hw_ptr 
So my understanding is once wait_for_avail_min returns insnd_pcm_lib_write1 function.hw_ptr is increased by some amount(periodsize) but appl_ptr will increase only when wait_for_avail_minreturns.And difference of (hw_ptr+runtime->buffersize-appl_ptr) will give us unplayed samples in the case of playback?
Is this whole ring buffer is filled after the snd_pcm_lib_write_transfer function is returned?
3.In some rare cases (playback case) i have seen thatwait_for_avail_min doesn't return and driver pointer function keeps ongetting called causing hw_ptr to increase.This causessnd_pcm_playback_avail() function to return a value less than avail_min(as hw_ptr is increasing and appl_ptr is stagnant as it is stuck insnd_pcm_lib_write1 function) which inturn causes wake-up fromsnd_pcm_update_hw_ptr_post() not to get called.When this type ofscenario happens?Is it a normal scenario if yes,then how will it willever come out from wait_for_avail_min?
According to my understanding appl_ptr will increase only when we return from wait_for_avail_min?
4.how does alsa know that it is running short of data?As iunderstand that it does not free the memory and data is onlyoverwritten.So how does it distinguish between old and new data?
5.Burst of noise due to stale data problem reported by Jon Smirl and for which Mr Jaroslav has suggested this solution http://mailman.alsa-project.org/pipermail/alsa-devel/2009-May/017119.html.Is it implemented?
 
Best Regards..
 
 
 
 
 
 


More information about the Alsa-devel mailing list