Repository navigation
Description
What happened?
Problem
After audio playback reaches the end of the media, AudioPlaybackHost reports the playback as ended, but the AudioOutput master clock may continue running.
As a result, AudioOutput.currentTime continues increasing after playback has already finished.
This causes the reported playback position to exceed the actual end position of the media.
Current Behavior
The playback pipeline correctly detects end-of-media after:
- The decoder reaches EOF.
- Remaining decoded audio is drained.
- Pending audio samples are enqueued.
- The playback clock catches up with the end of the last enqueued audio.
However, after onEnd() is triggered, the synchronizer's master clock may still have a playback rate of 1.0.
Therefore:
Playback reaches EOF
↓
Remaining audio is drained
↓
All pending samples are rendered
↓
Master clock reaches lastEnqueuedEnd
↓
onEnd()
↓
Master clock is still running
↓
currentTime continues increasing
Root Cause
AudioOutput.currentTime is derived from the AVSampleBufferRenderSynchronizer master clock.
The end-of-media path in AudioPlaybackHost waits for the synchronizer to reach the end of the last enqueued audio:
lastEnqueuedEndbut does not necessarily stop or park the synchronizer afterward.
As a result, the synchronizer continues advancing even though playback has already reached the end.
Expected Behavior
Once the end of the last enqueued audio has been reached, the master clock should be parked at that exact position and its playback rate should be set to 0.
Expected lifecycle:
Decoder EOF
↓
Drain decoder
↓
Enqueue remaining samples
↓
Wait for synchronizer to reach lastEnqueuedEnd
↓
Park master clock at lastEnqueuedEnd
↓
Set clock rate to 0
↓
Call onEnd()
After this point:
audioOutput.currentTimeshould remain stable instead of continuing to increase.
Recommended Fix
In the end-of-media path of AudioPlaybackHost, after the synchronizer has caught up with lastEnqueuedEnd, explicitly park the master clock:
if let aOut = audioOutput,
lastEnqueuedEnd.isFinite,
lastEnqueuedEnd >= 0 {
let endTime = CMTime(
seconds: lastEnqueuedEnd,
preferredTimescale: 90000
)
aOut.seekClock(to: endTime, rate: 0)
EngineLog.emit(
"[AudioHost] end-of-media: park clock at "
+ String(format: "%.3f", lastEnqueuedEnd)
+ "s",
category: .swPlayback
)
}
onEnd()
return falseThe important part is:
aOut.seekClock(to: endTime, rate: 0)This both positions the clock at the actual end of the queued audio and stops it from advancing further.
Why lastEnqueuedEnd Should Be Used
The clock should not be stopped immediately when the decoder reports EOF.
Decoder EOF only means that no more packets are available. There may still be decoded audio samples waiting in the renderer.
Using lastEnqueuedEnd ensures that:
- all decoded audio can finish playing;
- the master clock reaches the actual end of the queued audio;
currentTimedoes not stop prematurely;- the final playback position remains stable.
Approaches to Avoid
Do not clamp currentTime
For example:
min(currentTime, duration)This hides the underlying clock lifecycle problem instead of fixing it.
Do not replace the synchronizer clock with a software timer
AVSampleBufferRenderSynchronizer should remain the source of truth for audio playback timing.
Replacing it with CACurrentMediaTime() or another software clock could introduce synchronization and seeking issues.
Do not stop the clock immediately at decoder EOF
Stopping the clock at the moment FFmpeg reports EOF can truncate audio that has already been decoded and queued.
The clock should only be parked after the renderer has caught up with the final queued audio.
Expected Result
After end-of-media:
currentTime → lastEnqueuedEnd
rate → 0
For example:
[AudioHost] end-of-media: park clock at 1.000s
After this point, repeated reads of:
audioOutput.currentTimeshould continue returning approximately:
1.000
1.000
1.000
1.000
rather than:
1.000
1.050
1.100
1.150
...
Acceptance Criteria
AudioPlaybackHostdetects end-of-media normally.- All already-decoded audio is allowed to finish rendering.
- The synchronizer reaches
lastEnqueuedEnd. - The master clock is parked at
lastEnqueuedEnd. - The master clock rate becomes
0. AudioOutput.currentTimeremains stable after playback ends.- Normal playback, seeking, pause/resume, and rate changes are unaffected.
- No changes to the underlying decoder or audio format handling are required.
Scope
The fix should be limited to the end-of-media clock lifecycle in:
AudioPlaybackHost.swift
No changes to the decoder implementation should be necessary.
Steps to reproduce
none
AetherEngine version or commit SHA
Host app
Custom / my own integration
Platform
iOS
OS version
iOS26
Device / chip
iPhone16
Playback path
Native AVPlayer
Source media (for playback bugs)
No response
Error codes / log lines
Anything else
No response
Activity
superuser404notfound commentedon Oct 4, 2026
Thanks for the precise report, the analysis is right.
AudioPlaybackHostsignalled end of media and left the synchronizer at rate 1, socurrentTimekept growing. The software host got a park for exactly this in #374; the audio-only host never did.Fix is in PR #698:
rategoes to 0 with it.play()after the end no longer restarts the parked clock as a stalled one; a seek clears the park.One deviation from the proposed patch: the park is a
pause()at the clock's own position after the tail has played, notseekClock(to: lastEnqueuedEnd, rate: 0). By then the clock sits on the last sample either way, and it keeps both hosts on the same implementation.Covered by an end-to-end test (1 s WAV through the real host): it fails on
mainwith the clock at rate 1.0 after the end, and passes with the fix, position at 1.0 s and standing still.This will ship in the next release after 7.27.0. A check on the iPhone integration once that is out would be appreciated.
Merge pull request #698 from superuser404notfound/fix/694-audio-host-…
superuser404notfound commentedon Oct 4, 2026
Released in 7.27.1 (
d9a0ce87, fix commit04343a6a). Leaving this open until it is confirmed on the iPhone integration.fix(audio): an end-of-media park that runs late still stops on the la…
fix(audio): the audio-only host parks its clock at end of media (supe…
superuser404notfound commentedon Oct 5, 2026
A follow-up is in 7.27.2 (
fb3b6327): when the deferred end-of-media park only gets the main actor late, the clock used to stop wherever it stood by then (1.149 s on a 1.0 s source in CI). It is now put back on the last sample. 7.27.2 is the version to confirm against.Merge upstream AetherEngine 7.36.0 (74c81b3) into the Silo fork