Title: buffer producer/consumer sync

hi ,
        While debugging my alsa driver , some observations...

The flow goes like this

- cat  test.raw > /dev/pcm
- Middle layer fills up the buffer (size = period_size).   Why does middle layer only fills up period_size ??????
- ...(open / init etc)
- Trigger with PLAY command is called
        a) audio_dma_process routine is called
                This routine starts a dma transfer for a size of period_size
       
        b) We get a end of transfer interrupt and our callback is called.  In the callback function we call snd_pcm_period_elapsed to notify that one period is finished.  This function causes Trigger to be called again with STOP and then START again.  And the reason which I found after much debugging is this  :

               
--------------------------------------------------------------------------------------------------------------------------

         if (avail >= runtime->stop_threshold) {
                snd_pcm_stop(substream,
                             runtime->status->state == SNDRV_PCM_STATE_DRAINING ?
                             SNDRV_PCM_STATE_SETUP : SNDRV_PCM_STATE_XRUN);

this code is a part of snd_pcm_update_hw_ptr_post function in sound/core/pcm_lib.c
--------------------------------------------------------------------------------------------------------------------------

avail value is coming equal to runtime->stop_threshold and that is why we are getting a stop.  A trace of these values is :

initially
        hw_ptr = 0      appl_ptr = period_size          avail = runtime->buffersize     stop_threshold = runtime->buffersize    (this is set by default)

after one DMA transfer
        hw_ptr = period_size    appl_ptr = period_size(still the same value ... middle layer should have filled in more data and updated this )

       
        avail = hw_ptr + runtime->buffersize  - appl_ptr

        so again avail = runtime->buffersize  , since hw_ptr is equal to appl_ptr. 

What we analyzed here is that After the DMA transfer starts and before the finish of the DMA transfer the alsa middle layer should fill up data from application layer (cat command in this context).   So probably DMA transfer is happening at a much faster rate than the middle layer can fill up more application buffers.

Can someone comment on this and guide a little bit to solve this problem.

warm regards
-kshitij

Reply via email to