Fit the TOC byte inside the bitrate budget - #199
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #199 +/- ##
==========================================
- Coverage 93.10% 93.07% -0.03%
==========================================
Files 58 58
Lines 10263 10263
==========================================
- Hits 9555 9552 -3
- Misses 500 502 +2
- Partials 208 209 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
FrantaBOT
approved these changes
Aug 12, 2026
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.
Description
frameBytes()returns the amount of bitrate available to the frame, and that value is used as the CELT payload budget — but the packet also has the TOC byte at the front:So each packet was actually frameBytes+1 bytes instead of frameBytes.
Measured over 200 frames at each bitrate, before the change:
It's exactly one extra byte per frame, or 400 bps at 20 ms: 1.7% above the target at 24 kbps and 0.4% at 96 kbps. So a CBR 24 kbps stream was actually sending 24.4 kbps.
libopus passes CELT the payload size without the TOC byte. I verified this by instrumenting run_prefilter at 24 kbps: nbAvailableBytes is 59 in libopus where pion was using 60.
The fix is to subtract the TOC byte from the payload budget. After the change, the packet sizes match the target exactly at all six bitrates.
Side effect
frameBytes is also the budget used by the allocator, so this shifts some of the rate-dependent decisions as well. That's expected — they should now match libopus at the same bitrate.
In particular, the equiv_rate used by the intensity-band and trim decisions now matches the reference.
Reference issue
Part of #34.