Skip to content

Commit

Permalink
test: add more tests to audioSampleEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbee committed Nov 9, 2024
1 parent 0c311b1 commit 90fd800
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 34 deletions.
41 changes: 8 additions & 33 deletions mp4/audiosampleentry_test.go
Original file line number Diff line number Diff line change
@@ -1,42 +1,17 @@
package mp4

import (
"bytes"
"testing"

"github.com/Eyevinn/mp4ff/bits"
)

func TestWriteReadOfAudioSampleEntry(t *testing.T) {
ase := CreateAudioSampleEntryBox("mp4a", 2, 16, 48000, nil)

// Write to a buffer so that we can read and check
var buf bytes.Buffer
err := ase.Encode(&buf)
if err != nil {
t.Fatal(err)
}

// Read back from buffer
encData := buf.Bytes()
encBuf := bytes.NewBuffer(encData)
decodedBox, err := DecodeBox(0, encBuf)
if err != nil {
t.Error("Did not get a box back")
}
outAse := decodedBox.(*AudioSampleEntryBox)
if outAse.SampleRate != ase.SampleRate {
t.Errorf("Out sampled rate %d differs from in %d", outAse.SampleRate, ase.SampleRate)
}

// Read back from buffer
sr := bits.NewFixedSliceReader(encData)
decodedBoxSR, err := DecodeBoxSR(0, sr)
if err != nil {
t.Error("Did not get a box back")
}
outAse = decodedBoxSR.(*AudioSampleEntryBox)
if outAse.SampleRate != ase.SampleRate {
t.Errorf("Out sampled rate %d differs from in %d for SliceReader", outAse.SampleRate, ase.SampleRate)
ascBytes := []byte{0x11, 0x90}
esds := CreateEsdsBox(ascBytes)
ase := CreateAudioSampleEntryBox("mp4a", 2, 16, 48000, esds)
boxDiffAfterEncodeAndDecode(t, ase)
_, err := ase.RemoveEncryption()
expectedErrMsg := "is not encrypted: mp4a"
if err == nil || err.Error() != expectedErrMsg {
t.Errorf("expected error with message: %q", err.Error())
}
}
2 changes: 1 addition & 1 deletion mp4/audiosamplentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func CreateAudioSampleEntryBox(name string, nrChannels, sampleSize, sampleRate u
ChannelCount: nrChannels,
SampleSize: sampleSize,
SampleRate: sampleRate,
Children: []Box{},
Children: nil,
}
if child != nil {
a.AddChild(child)
Expand Down

0 comments on commit 90fd800

Please sign in to comment.