From 775514444e3705bf2970f7691952ae48dc947321 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbjo=CC=88rn=20Einarsson?= Date: Sat, 9 Nov 2024 17:43:18 +0100 Subject: [PATCH] change: remove ReplaceChild method of StsdBox --- CHANGELOG.md | 1 + mp4/stsd.go | 24 ------------------------ mp4/stsd_test.go | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4010c5b..401db8cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/mp4/stsd.go b/mp4/stsd.go index 7b588348..573991ad 100644 --- a/mp4/stsd.go +++ b/mp4/stsd.go @@ -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) { diff --git a/mp4/stsd_test.go b/mp4/stsd_test.go index db8fad53..b552f52c 100644 --- a/mp4/stsd_test.go +++ b/mp4/stsd_test.go @@ -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) + } +}