feat(mp4): elst media rate as one signed 16.16 fixed-point number - #552
Merged
Conversation
ElstEntry splits the media rate over MediaRateInteger and MediaRateFraction, so reading or writing the actual rate required callers to know the split int16/int16 bit layout, including the sign-extension trap when combining a negative fraction half. Add MediaRateFixed32 and SetMediaRateFixed32 to combine and split the halves, handling negative rates correctly.
nchitkara-xai
marked this pull request as ready for review
August 18, 2026 16:25
Collaborator
|
@nchitkara-xai This is an improved API. Thanks! |
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.
Problem
The elst media rate is split across
MediaRateIntegerandMediaRateFraction,two int16 halves of one signed 16.16 number, so reading or writing a rate means
knowing the bit layout, including the trap that sign-extending the fraction
corrupts the integer half when recombining.
Fix
ElstEntry.MediaRateFixed32()andSetMediaRateFixed32()combine and splitthe halves as one signed
int32. The raw fields are unchanged, so decode andencode round-trips are untouched. The getter returns a plain
int32ratherthan
mp4.Fixed32, which is unsigned; the media rate is signed.Tests
Table-driven round-trips in both directions for 1.0, 0.25, 2.5, -1.0, -0.5,
-1.5 and the 0x7fff/-1 extreme; the negative-fraction cases pin the sign
handling.
go test ./...,go vet,gofmt,golangci-lintpass.