Skip to content

audio: report the FRDDR FIFO fill as playback delay - #59

Open
matthane wants to merge 2 commits into
CoreELEC:5.15.196_20260225from
matthane:pr/ce-audio-fifo-delay
Open

matthane wants to merge 2 commits into
CoreELEC:5.15.196_20260225from
matthane:pr/ce-audio-fifo-delay

Conversation

@matthane

@matthane matthane commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Depends on no other PR. The CoreELEC/xbmc A/V sync PRs were measured with it.

Problem

On Amlogic boxes ALSA reports less playback delay than the audio really has, so a player that syncs to it plays audio up to 5.6 ms late at the HDMI output.

Change

The playback pointer reports the FRDDR fetch address, which runs up to 1 KiB of FIFO ahead of the serializer, so ALSA's delay leaves out the audio still queued in the chip. The pointers now read the fetch address and the FIFO fill as one consistent pair, and each output's DAI delay callback reports that fill, as davinci-mcasp reports its FIFO use. The ASoC core adds the DAI delay to the playback delay on 5.15, and on 6.12 it builds the delay from these callbacks only, so the change works on both. FRDDR_FIFO_CNT is corrected to bits 16:8.

On t7 both spdif DAIs, and on s4 the spdifa DAI, were named as the codec of their own link, so ASoC ran every op of that DAI twice and would add its delay twice. Those links now use the dummy codec, as on the other SoCs.

Tested with

The A/V offset is measured at the HDMI output at playback start on A/V marker clips (1080p23.976, a frame code and a click every second), six starts per codec on each device. Without this PR is the stock kernel with the amlvideo PR, and both arms run the same Kodi. A value is the median of one device's starts, and a cell gives the range over the four devices. Positive means the audio leaves the box after its picture. Full data in the measurement data. Every sample ran on each device listed under Tested on. The 1 KiB of FIFO holds about 2.7 ms of PCM 2.0, 5.3 ms of AC-3 or DTS, 1.3 ms of E-AC-3 and 0.3 ms of a DTS-HD MA or TrueHD stream, which is about how far each row moves.

Sample Without this PR, A/V offset at start (ms) With this PR, A/V offset at start (ms)
A/V marker clip, PCM 2.0 +2.6 to +2.9 +0.2 to +0.3
A/V marker clip, AC-3 +4.7 to +5.6 -0.6 to -0.1
A/V marker clip, E-AC-3 +0.4 to +1.1 -0.6 to -0.1
A/V marker clip, DTS +4.5 to +5.0 -0.7 to -0.2
A/V marker clip, DTS-HD MA -0.5 to +0.5 -0.7 to -0.3
A/V marker clip, TrueHD -0.3 to +0.1 -0.5 to -0.3

Result

Audio leaves the HDMI output when ALSA says it does, with every device's median start within 1 ms of the picture on every codec, so lip sync starts where the player set it. The s4 link change is untested because none of our devices is an S4.

Tested on

CoreELEC 22 nightly of 2026-11-28 with this PR's two commits, the commits of "audio: run the outputs from hifi_pll on g12, sm1, sc2 and t7" (#60), "amlvideo: report the field of each dequeued frame", the CoreELEC/xbmc A/V sync PRs of 2026-11-29 and the ffmpeg patch "ffmpeg: add patch to time a TrueHD major sync after skipped units", common_drivers on Linux 5.15.196, tested 2026-11-29. Without this PR is the same build with the stock kernel and the amlvideo commit, so it leaves out this PR and #60. Both kernels carry two capture taps and a snapshot of the audio playback ring, used only for the measurement. This PR needs no library change and no CoreELEC patch. AM9 Pro (S905X5), AM6B+ (S922X), R 4K Plus (S905X4), Fire TV Cube 3rd gen (T7).

Unlike the other SoCs, t7 names both spdif DAIs, and s4 its spdifa
DAI, as the codec of their own link. ASoC then runs every DAI op twice
on that DAI, so each start prepares and triggers it twice, and on HDMI
hdmitx sets up its audio twice.
The playback pointer reads the FRDDR fetch address, which runs up to
one FIFO depth (1 KiB) ahead of what the serializer has sent. ALSA's
delay leaves that queue out, so the HDMI output trails the reported
delay by 3 to 5.5 ms for PCM 2.0, AC-3 and DTS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant