[alsa-devel] [PATCH]fix mmap emulation bug of recording doesn't work

Roy Huang royhuang9 at gmail.com
Thu Jul 5 08:17:35 CEST 2007

Hi Takashi,

There is no problem with rate plugin. If no plugin is used, record can
works. If any plugin is used, it will have problem.

If mmap emulation is enabled, data is copied from driver to hw layer's
buffer, then to upper layer. In snd_pcm_hw_t, appl_ptr is used to
indicate the position in hw layer's buffer where last byte is copied
to upper layer. But there is no way to know the position in hw layer's
buffer where the last byte is copied from driver.

In function snd_pcm_hw_avail_update, it calls
snd_pcm_mmap_capture_avail to find how much data is available for
upper layer, denote the amount of available data as s1. Part of the
available data is already in hw layer's buffer, denote the amount of
this part of data as s2. But snd_pcm_hw_avail_update calls
snd_pcm_read_mmap to copy data as much as s1 from driver to hw layer's
buffer. In fact only (s1-s2) is needed to be copied.

So in new function snd_pcm_hw_avail_update, only data in amout of
(s1-s2) will be copied by snd_pcm_read_mmap.


On 7/5/07, Takashi Iwai <tiwai at suse.de> wrote:
> At Wed, 4 Jul 2007 22:18:24 +0800,
> Roy Huang wrote:
> >
> > Record doesn't work if enabling mmap emulation and rate conversion
> > needed, this patch fix this bug.
> Thanks for the patch.  I need to check your changes in detail as it's
> not so obvious.  What is the problem with rate plugin and
> mmap-emulation?  From what I find in your patch, it's something to do
> with the hw_ptr update mismatch.
> Takashi

More information about the Alsa-devel mailing list