[alsa-devel] ASoC PCM drivers without progress counters breaks snd_pcm_status
Hi,
To determine the timestamp of captured audio, we do something along the lines:
ts = snd_pcm_status_get_htstamp() - time(snd_pcm_status_get_delay()) snd_pcm_readi(buf) process(buf, ts)
However for PCM drivers that only update its hw_pointer in steps of periods (in irq-handler), the attributes in snd_pcm_status() struct will not be in sync even though ALSA thinks so. For example, the avail property will correspond to the time of the last IRQ, not at the specified timestamp returned by snd_pcm_status_get_htstamp(). This will introduce timestamp jitter which depends on system IRQ latency and also when the userspace application issues it syscall to read status. For an embedded system under heavy load, the A/V sync is unacceptable when using ALSA timestamps.
Several mainline PCM drivers do this kind of hw-pointer caching in their irq handlers, perhaps because the DMA HW does not support progress counting.
Possible solutions:
1) If DMA HW supports progress counter, implement it.
2) If DMA HW is not supported, implement it in software (estimate position using elapsed time since last irq). Only requires driver changes.
3) If DMA HW is not supported, return use last irq timestamp as the timestamp returned by snd_pcm_status_get_htstamp() . Probably requires ALSA Core changes.
I've tested 1) and results in much improved A/V sync on our systems. If would be kind of convenient if ALSA SoC Core could provide a generic pointercallback for solution 2), if the PCM driver specifies that it does not support HW progress counter. Otherwise we will see a lot of duplicate code for estimating position. AFAIK, ALSA already maintains a timestamp for last irq.
Magnus Olsson Axis Communications / Product Platforms
On Wed, Oct 26, 2011 at 11:25:03AM +0200, Magnus Olsson wrote:
Always CC maintainers on mails and fix your mail client so that it word wraps within paragraphs for legibility.
If DMA HW supports progress counter, implement it.
This is just a basic quality of implementation issue - if the driver isn't taking advantage of the hardware the driver is obviously not doing a good job and should be improved.
If DMA HW is not supported, implement it in software (estimate
position using elapsed time since last irq). Only requires driver changes.
No, we can't do this. The pointer isn't just there for AV sync, it also gives userspace information about where the hardware is at in the buffer so we need to keep in sync with what the driver is doing.
If DMA HW is not supported, return use last irq timestamp as
the timestamp returned by snd_pcm_status_get_htstamp() . Probably requires ALSA Core changes.
This is pretty much what's happening right now, userspace should be using the period information if it doesn't have anything better.
participants (2)
-
Magnus Olsson
-
Mark Brown