Repository navigation
fix(audio): count the silent-bridge gate in encoder frames, not source packets (#474) - #475
Merged
superuser404notfound merged 1 commit intoSep 3, 2026
Conversation
…e packets (#474) The AE#396 detector fired during a healthy start-up on every TrueHD session and announced a failure that was not happening: [AudioBridge] ERROR: AE#396 the bridge has produced no encoded audio at all (mode=surroundCompat): fed=64 decoded=64 enqueued=2560 emitted=0. ... this session will fail its first segment cut unless output starts. The threshold was 64 SOURCE PACKETS, but the quantity that bounds the encoder arm is one ENCODER FRAME: drainFIFOIntoEncoder(requireFull:) cannot encode below frame_size, so nothing can be emitted before that many samples have been enqueued. Its derivation named its two constants, an E-AC-3 frame of 1536 and a DTS packet of 512, and the FLAC arm breaks both: a FLAC frame is 4608 samples and a TrueHD access unit is 40, so the first output needs 116 packets. The enqueued=2560 in the reporter's own line is the proof, short of 4608 and short of any output being possible. Not confined to the opt-in .lossless mode either, .surroundCompat encodes two channels or fewer to FLAC. Each arm is now counted in the unit that bounds it: the encoder's own frame_size where PCM reached the FIFO, packets only where the FIFO never moved, and the latter from the LAST accepted sample rather than from the start, so a decoder that answers for a while and then stops is the same shape as one that never answered. Four frames rather than one, because the first is when output becomes possible and the second covers an encoder that holds it. The line arrives sooner than before on the arm it was written for (128 ms of source audio on E-AC-3 against 64 packets) and now names the encoder and the frame boundary it judged. Measured on media, both arms of the same fixture family: a stereo TrueHD MKV on the default mode printed the ERROR at fed=64 before, prints nothing after, and plays 20 s clean in both. The decoder arm is pinned through the real bridge in tests (80 undecodable MP3 packets still report), because no corruption that could be built here makes libavcodec stop producing frames for a whole session. Nothing else read the threshold: both sites that classify a silent bridge are gated on an actual failure (a pump death with muxerFailed, an exhausted revive), so a healthy start-up never reached them, and $audioDelivery is derived independently and read `bridged` correctly throughout. Reported by @cmcpherson274 in #462. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Q4QpZDsHPJfbz5gkxxPXF7
superuser404notfound
deleted the
fix/ae396-silent-feed-startup-false-positive
branch
September 4, 2026 06:57
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the start-up false positive reported by @cmcpherson274 in #462, filed as #474.
What was wrong
AudioBridge.noteSilentFeedIfNeeded(AE#396) fired at 64 source packets, but the quantity that bounds its encoder arm is one encoder frame:drainFIFOIntoEncoder(requireFull: true)cannot encode belowframe_size, so no output is possible until that many samples have been enqueued.The threshold's own comment named the two constants it was derived from, and the FLAC arm breaks both:
The
enqueued=2560in the reporter's line is the proof: short of 4608, so the drain had correctly declined to encode and nothing could have been emitted. The FLAC mode has been in the same file sinceec4723dc(2026-05-22) and predates the gate (9870892c, 2026-08-18).It is not confined to the opt-in
.losslessmode:.surroundCompatencodes any source of two channels or fewer to FLAC, so a stereo TrueHD file reproduces it on the default setting.The fix
Each arm is counted in the unit that bounds it:
samplesEnqueued >= frame_size * 4. Four frames because the first is when output becomes possible and the second covers an encoder that holds it; four is still inside the first half second of source audio on every arm (128 ms on E-AC-3, 384 ms on FLAC at 48 kHz), which is sooner in wall clock than the packet threshold it replaces.silenceIsStructural(stats:encoderFrameSize:)is pure and static so the boundary is pinned against the frame sizes the bridge really opens rather than whichever one a fixture happens to reach. The ERROR line now also names the encoder it is talking about (it said "AC-3/E-AC-3 sample entry" on a FLAC session) and the frame boundary it judged.Measured
Fixture, reproducible from scratch:
ffmpeg -f lavfi -i testsrc=size=1280x720:rate=25:duration=90 -f lavfi -i sine=frequency=440:duration=90 \ -map 0:v -map 1:a -c:v libx264 -preset ultrafast -g 50 -pix_fmt yuv420p \ -c:a truehd -strict -2 -ac 2 -ar 48000 truehd2.mkv aetherctl play --seconds 20 file://$PWD/truehd2.mkvbefore
after: same session, same counters reached, no ERROR line,
final t=20.30s state=playing.The counters in the before arm are identical to the reporter's device log, on the default mode.
Tests
Four new tests in
Issue396SilentAudioBridgeTests, all four failing against the old rule and passing against the new one, with the four pre-existing tests passing in both arms:enqueued=2560 emitted=0and must not reportFull suite green on both runners: XCTest 606 executed / 0 failures, swift-testing 2600 tests in 355 suites.
Limit
The encoder arm is measured on media. The decoder arm is pinned through the real bridge in tests rather than in a session, because no corruption that could be built here (
noisebsf at every byte, on MP3, AC-3 and TrueHD) makes libavcodec stop producing frames for a whole session; each of those sources decoded and played.Blast radius
None beyond the line. Both sites that classify a silent bridge are gated on an actual failure (
HLSVideoEngine+LiveReopen.swift:206on a pump death withmuxerFailed,:632on the exhausted revive), so a healthy start-up never reached them, and$audioDelivery(#462) is derived independently and readbridgedcorrectly throughout.