[alsa-devel] hw_params function and OSS emulation

Timur Tabi timur at freescale.com
Tue Aug 21 20:15:16 CEST 2007

I'm working on an ASoC driver, and I noticed that with OSS emulation enabled, 
my snd_pcm_ops.hw_params and and snd_pcm_ops.hw_free are called multiple times 
when an OSS driver uses the OSS emulation.  In my case, .hw_params is called 
*four* times, each time with a different DMA buffer size and number of periods.

The problem is that my driver allocates a DMA buffer in my .hw_params 
function.  For now, I have it deallocate the buffers at the top of the 
function and then allocate new ones based on the new hw_params values.

This is really annoying.  So I have a few questions:

1) Is there any way this can be fixed?  Can't the OSS emulation code figure 
out what it needs and wait until it's done before it calls .hw_params?

As a solution to the DMA buffer deallocate/reallocate hack I'm using, would it 
be okay to move the actual allocations to snd_pcm_ops.prepare()?  My 
.hw_params function will collect the relevant data and keep them in some 
private structure.  Then when .prepare() is called, I do the actual buffer 

2) Can I assume that .prepare() is called only once?

3) Can I assume that .hw_params() is never called after .prepare() is called?

Timur Tabi
Linux Kernel Developer @ Freescale

More information about the Alsa-devel mailing list