Skip to content

Commit

Permalink
Merge pull request #309 from Eyevinn/fix-bad-senc-size
Browse files Browse the repository at this point in the history
fix: set senc.perSampleIVSize properly
  • Loading branch information
tobbee authored Dec 28, 2023
2 parents fd7b140 + 5312913 commit 4929bac
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Parsing of AVCDecoderConfigurationRecord
- Parsing of time offset in AVC PicTiming SEI
- Set senc.perSampleIVSize properly

## [0.40.2] - 2023-11-17

Expand Down
1 change: 1 addition & 0 deletions mp4/senc.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func (s *SencBox) ParseReadBox(perSampleIVSize byte, saiz *SaizBox) error {
// No subsamples
if perSampleIVSize == 0 { // Infer the size
perSampleIVSize = byte(nrBytesLeft / s.SampleCount)
s.perSampleIVSize = perSampleIVSize
}

s.IVs = make([]InitializationVector, 0, s.SampleCount)
Expand Down
23 changes: 23 additions & 0 deletions mp4/senc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,26 @@ func TestAddSamples(t *testing.T) {
err = senc.AddSample(SencSample{iv8, []SubSamplePattern{{20, 2000}}})
assertError(t, err, "Should have got error due to different iv size")
}

// TestImplicitIVSize tests that the implicit IV size is correctly calculated (perSampleIVSize != 0)
func TestImplicitIVSize(t *testing.T) {
testCases := []struct {
inputFile string
expectedSencSize int
}{
{inputFile: "testdata/2xSencNoMdat.mp4", expectedSencSize: 2248},
}

for _, tc := range testCases {
// Read the file
m, err := ReadMP4File(tc.inputFile)
if err != nil {
t.Error(err)
}
frag := m.Segments[0].Fragments[0]
senc := frag.Moof.Traf.Senc
if int(senc.Size()) != tc.expectedSencSize {
t.Errorf("Expected senc size %d, got %d", tc.expectedSencSize, senc.Size())
}
}
}
Binary file added mp4/testdata/2xSencNoMdat.mp4
Binary file not shown.

0 comments on commit 4929bac

Please sign in to comment.