fix(packet_pool): reduce latency for single-packet PES by flushing immediately when complete #72
+77
−0
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.
Motivation / Problem
Currently, the demuxer buffers a PES packet and only emits it when it encounters the
PayloadUnitStartIndicatorof the next packet.While this works well for high-frequency streams (like Video/Audio), it causes significant issues for sparse streams, such as DVB Teletext subtitles. These packets may arrive minutes apart.
Consequence: A subtitle frame arriving at
T=0is held in the buffer untilT=4min(when the next subtitle arrives). This results in severe timestamp handling issues during transcoding, often causing the subtitles to be dropped or desynchronized because they effectively arrive "from the past."Solution
This PR introduces a heuristic to reduce latency without breaking existing buffer logic:
PayloadUnitStartIndicator, we check the PES header length.b.q) after being sent.sameAsPrevious) continue to work correctly when the next packet eventually arrives.Re-produce example
We have source with following dvb_teletext sequence: source_dvb.txt.
Current upstream version will delay the last packet until there are no more packets, and instead send the previous one with a timestamp from 4 minutes ago.