← All issues

MSE: B-frame tail PTS overshoot in coded-frame processing

93e7a14

MSE Coded Frame Processing is the spec algorithm that determines how incoming encoded frames interact with already-buffered content. Steps 1.14/1.15 handle overlap removal: when a new frame's presentation range overlaps existing buffered content, the overlapping content is erased. B-frames (bidirectional predictive frames) have PTS > DTS because they decode before they display; at the tail of an fMP4 segment, the last sample's trun.sample_duration is a decode-grid placeholder rather than a real presentation duration, so frameEndTime = pts + duration can slightly exceed the next buffered sample's PTS without representing a true editorial overlap. This commit adds a per-track "B-frame tail + within-timeFudgeFactor" heuristic that redirects to a forward-shift path, atomically mutating three coupled structures: the SampleMap's presentation-order submap, its decode-order submap, and TrackBuffer::m_decodeQueue. New helpers createCopyWithAdjustedStartTime, adjustSampleStartTime, and replaceSample implement the shift.

fMP4 tail B-frame: dts=50 pts=80 dur=30 => frameEnd=110
Next buffered content sync: pts=100

Before: erase [50,110) removes pts=100 sync => buffered gap, playback stalls
After:  overshoot=10ms < fudge, B-frame tail => shift sync pts 100->110, no gap

The fix prevents live-stream stalls at ad splice points, but the new code atomically mutates three coupled sample-bookkeeping structures — each a potential source of subtle state and lifetime bugs.

🔒

New timing-mutation paths across three coupled MSE bookkeeping structures — edge cases in the heuristic guard and map operations are worth careful investigation.

더 확인하려면 구독해 주세요