Skip to content

Commit

Permalink
change: remove ReplaceChild method of StsdBox
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbee committed Nov 9, 2024
1 parent 7bf352b commit 7755144
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 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

- CreatePrftBox now takes flags parameter
- PrftBox Info output
- Removed ReplaceChild method of StsdBox

### Added

Expand Down
24 changes: 0 additions & 24 deletions mp4/stsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,30 +76,6 @@ func (s *StsdBox) AddChild(box Box) {
s.SampleCount++
}

// ReplaceChild - Replace a child box with one of the same type
func (s *StsdBox) ReplaceChild(box Box) {
switch box.(type) {
case *VisualSampleEntryBox:
for i, b := range s.Children {
switch b.(type) {
case *VisualSampleEntryBox:
s.Children[i] = box.(*VisualSampleEntryBox)
s.AvcX = box.(*VisualSampleEntryBox)
}
}
case *AudioSampleEntryBox:
for i, b := range s.Children {
switch b.(type) {
case *AudioSampleEntryBox:
s.Children[i] = box.(*AudioSampleEntryBox)
s.Mp4a = box.(*AudioSampleEntryBox)
}
}
default:
panic("Cannot handle box type")
}
}

// GetSampleDescription - get one of multiple descriptions
func (s *StsdBox) GetSampleDescription(index int) (Box, error) {
if index >= len(s.Children) {
Expand Down
18 changes: 18 additions & 0 deletions mp4/stsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,21 @@ func TestStsd(t *testing.T) {
}
}
}

func TestStsdEncodeDecode(t *testing.T) {
stsd := &StsdBox{}
evte := &EvteBox{}
stsd.AddChild(evte)
boxDiffAfterEncodeAndDecode(t, stsd)
b, err := stsd.GetSampleDescription(0)
if err != nil {
t.Error(err)
}
if b != evte {
t.Errorf("Expected %v, got %v", evte, b)
}
b, err = stsd.GetSampleDescription(1)
if err == nil {
t.Errorf("Expected error, got %v", b)
}
}

0 comments on commit 7755144

Please sign in to comment.