[Android] AudioTrack (RAW) passthrough: old audio keeps playing after a seek, and sync corrections do not move the audio
Bug report
Describe the bug
Here is a clear and concise description of what the problem is:
With AudioTrack (RAW) passthrough on a Fire TV Cube, seeking in a local E-AC3 file on 22.0 RC1 leaves the audio from before the seek playing for a moment while the picture freezes, and afterwards the audio stays ~130 ms ahead of the picture: ActiveAE corrects it several times, but the corrections have no audible effect. I traced this to the flush handling in CActiveAESink and the pause-burst handling in CAESinkAUDIOTRACK, using extra LOGINFO markers around SyncStream() / AddPause() and the Fire OS audio HAL's own pause() / resume() / flush() lines in logcat.
@fritsch, this may be related to what you described in #27621: "sink is empty: pause bursts fill up until limit is reached" and "sink is already filled, but AE wants to move buffer a bit ahead … especially the second one is tricky" (https://github.com/xbmc/xbmc/pull/27621#issuecomment-3697207580), and your Fire TV Cube needing "a subtle way to reopen the sink once the seeking was done" (https://github.com/xbmc/xbmc/pull/27621#issuecomment-3699601823).
runN below refers to a folder in the attached zip (scrubbed log excerpts, HAL logcat lines, a merged timeline per run, README).
Reproducible on 22.0 RC1 with AE and sink unmodified (run9):
- A flush never reaches the sink.
CActiveAESinkhandlesCSinkControlProtocol::FLUSH(ActiveAESink.cpp:304) withReturnBuffers()only, andIAESinkhas noFlush(). After a seek the AudioTrack plays out what it still holds (roughly a second in RAW on this device); the HAL only seespause()/resume(), neverflush(). ActiveAE counts that stale audio into the sink delay (1030–1062 ms at the start sync after the seeks in run9), so the new audio only starts once it has played out. - Pause bursts on a filled sink do not delay the output. In 21.3 an AddPause burst blocked with the track paused, which shifted the audio. Since 9895ee3cc0 a burst is booked into
m_pause_mswithout blocking while there is free space: the track is paused for 2–5 ms,AddPackets()callsplay()with the next packet, and the credit is worked off by sleeping the writer thread while the track keeps playing from its buffer.GetDelay()adds the credit, so AE sees the error as corrected. In run9 the error stays at +105…+175 ms for seconds after each seek while 1–3 ADJUST rounds per seek pause the track for a few ms each (11 INSYNC→ADJUST and 17 AudioTrack pauses in 75 s). Two details in the same code:m_delayalready contains the credit, so it is counted twice inspace_ms, and them_audiotrackbuffer_secratchet grows with it (1.2 → 1.7 s in run6).
Once 1 is fixed, two more things show up. Adding only the Flush() (plus the drop fix mentioned below) makes it worse on this device — in run6 the cycle from point 2 never stops — so I list what else it takes:
- Pause bursts are booked on an empty sink. After the flush, the idle pause bursts between two streams and the start-up MUTE bursts are all booked as credit, and
GetDelay()reports up to a whole buffer of audio that does not exist while the new stream is aligned. (Unmodified RC1 books 224 ms at everyplay()after a seek, on top of the stale audio.) 21.3 + flush (run1): 1.2–1.4 s of credit atplay(), +800 ms error one second later, answered by a 0.9 s AudioTrack pause. - The start is aligned against a sink delay of 0. In RAW,
m_hw_delayis 0 until the first valid timestamp — and right afterflush(),getTimestamp()still returns the pre-flush position (run7: 8082.9 ms with nothing written since), which passes the freshness check. AE aligns the new stream against 0, the audio starts ~0.5 s late, and two drops of ~250 ms correct it audibly (run5).
Expected Behavior
Here is a clear and concise description of what was expected to happen:
After a seek or stream change in RAW passthrough the old audio stops, the new audio starts in sync with the picture, and a sync correction moves the audible output by the corrected amount.
Actual Behavior
Unmodified 22.0 RC1 with a local file: old audio after every seek, a short video freeze, then audio ~130 ms early that the corrections do not fix (points 1 and 2). With only a sink flush added: a permanent correction cycle with a micro-gap every ~1.2 s (points 2 and 3).
Possible Fix
What I have tested on the device (patches ready; I'd rather hear your view on the approach before opening a PR):
- For 1:
IAESink::Flush(), empty by default so no other sink changes; AudioTrack implements it aspause(); flush();plus a reset of every counter derived from the playback head. Called from theFLUSHhandler. - For 3: In
AddPause(): with nothing written since the last flush/drain (m_duration_written <= 0), sleep the burst out instead of booking it. - For 4: In RAW, until the first plausible timestamp, estimate the part below the track from
getLatency()minus the buffer time — the formula the PCM path already uses; 303 ms here, the HAL itself reports 328–335 ms. Whilem_timestampPos == 0, reject a timestamp whose position is beyond what was written since the flush. - For 2: Not changed. It needs a design decision on your side — for example blocking again when the sink is already filled, as 21.3 did.
With 1, 3 and 4 (plus the separate fix below) on RC1, the same file and seeks (run8): pause() + flush() on every seek, audio starts with 303 ms estimated delay, then no drop, no ADJUST and no AudioTrack pause; the residual offset is a constant ~-110 ms. Listening test: clean. Live TV channel changes behave the same (run7).
Separate, one line, and not Android specific: a RAW packet dropped for sync reaches CActiveAESink::OutputSamples() with 0 frames, skips the only GetDelay() call and hands a default AEDelayStatus (delay 0) to CEngineStats. On this device that is a ~+1 s mis-measurement after every drop: in run9 the start sync drops a packet in 4 of the 5 seeks, and the very next measurement is a large audio sync error of +1050 to +1071 ms, the AudioTrack delay at that point (1062.9 ms); the fifth seek needs no drop and shows none, with the same stale audio in the sink. I'll send that as its own PR.
To Reproduce
Steps to reproduce the behavior:
- Fire TV Cube 2nd gen (AFTR) → HDMI → AV receiver; audio device AudioTrack (RAW), passthrough on, E-AC3 enabled.
- Play a local E-AC3 5.1 file and seek. The zip contains the ffmpeg command for a 3-minute test file (a white flash and a 1 kHz beep every second, and a tone one semitone higher every 10 s, so audio from before a seek is audible as a different pitch) and a small JSON-RPC script that seeks to 65/25/125/95/45 s.
- Listen for old audio after the seek, compare beep and flash; logcat
DolbyAudioStreamOutshows the HAL side.
Debuglog
The debuglog can be found here: kodi-debug-22.0rc1-seek.log kodi-cube-raw-passthrough-logs-2026-09-28.zip
Debug logging enabled at runtime, run9 build (AE and sink unmodified), the test file and the five seeks from 16:51:23. Kodi logs CDVDAudio::Flush - flush audio stream on every seek, while the HAL (logcat in the zip, run9b) sees flush() exactly once in that minute — at CloseFile() via CAESinkAUDIOTRACK::Deinitialize. In between: 17 INSYNC→ADJUST and 23 AudioTrack pauses. The live-TV part before 16:51 comes from Kodi's startup channel and is not related; stream tokens, channel IDs and the channel list were removed from the log.
The zip additionally holds excerpts taken at the default log level with the SYNCDBG: LOGINFO markers, which also cover the runs with the changes above.
Additional context or screenshots (if appropriate)
Here is some additional context or explanation that might help:
- How I got here: I was working on passthrough for live TV. That question, including the realtime veto discussed in #28561, is a separate topic and not what this issue is about; everything above reproduces with a local file.
- Measured on one device family only (Fire TV Cube 2nd gen, Dolby MS12 HAL). The timestamp behaviour after
flush()in particular may be HAL specific. I can test proposals on this device. - Possibly relevant to the Fire TV Cube trouble mentioned in #27621: on 2026-09-26 the Fire OS audio HAL service crashed three times within 30 s (SIGSEGV, twice in
libasp.soon the capture path, once indolby::DolbyAudioStreamOut::write). It has not happened again. - #29085 touches the same files but a different path (passthrough that fails to open; silent fallback while
m_at_jniis null). The changes here do not depend on it and should merge next to it without overlap.
Your Environment
Used Operating system:
Android
iOS
tvOS
Linux
macOS
Windows
Windows UWP
Operating system version/name: Fire OS 7 (Android 9, API 28), Fire TV Cube 2nd gen (AFTR), armeabi-v7a, Marantz AV receiver
Kodi version: 22.0 RC1 (28ea2eac1e), built from source. run9 = AE and sink unmodified plus LOGINFO markers; the build also carries three unrelated local changes (realtime passthrough veto lifted, MediaCodec
NeedPassthrough()for the decrypt codec, HDMI audio re-enumeration), none of which is on the seek path of a local unencrypted file. run1 is 21.3 Omega.
note: Once the issue is made we require you to update it with new information or Kodi versions should that be required. Team Kodi will consider your problem report however, we will not make any promises the problem will be solved.
Source: xbmc/xbmc