diff --git a/box.go b/box.go index 8fd1288..beac0fd 100644 --- a/box.go +++ b/box.go @@ -12,62 +12,62 @@ const LengthUnlimited = math.MaxUint32 type ICustomFieldObject interface { // GetFieldSize returns size of dynamic field - GetFieldSize(name string, bss *BoxStructureStatus) uint + GetFieldSize(name string, bss BoxStructureStatus) uint // GetFieldLength returns length of dynamic field - GetFieldLength(name string, bss *BoxStructureStatus) uint + GetFieldLength(name string, bss BoxStructureStatus) uint // IsOptFieldEnabled check whether if the optional field is enabled - IsOptFieldEnabled(name string, bss *BoxStructureStatus) bool + IsOptFieldEnabled(name string, bss BoxStructureStatus) bool // StringifyField returns field value as string - StringifyField(name string, indent string, depth int, bss *BoxStructureStatus) (string, bool) + StringifyField(name string, indent string, depth int, bss BoxStructureStatus) (string, bool) - IsPString(name string, bytes []byte, remainingSize uint64, bss *BoxStructureStatus) bool + IsPString(name string, bytes []byte, remainingSize uint64, bss BoxStructureStatus) bool - BeforeUnmarshal(r io.ReadSeeker, size uint64, bss *BoxStructureStatus) (n uint64, override bool, err error) + BeforeUnmarshal(r io.ReadSeeker, size uint64, bss BoxStructureStatus) (n uint64, override bool, err error) - OnReadField(name string, r bitio.ReadSeeker, leftBits uint64, bss *BoxStructureStatus) (rbits uint64, override bool, err error) + OnReadField(name string, r bitio.ReadSeeker, leftBits uint64, bss BoxStructureStatus) (rbits uint64, override bool, err error) - OnWriteField(name string, w bitio.Writer, bss *BoxStructureStatus) (wbits uint64, override bool, err error) + OnWriteField(name string, w bitio.Writer, bss BoxStructureStatus) (wbits uint64, override bool, err error) } type BaseCustomFieldObject struct { } // GetFieldSize returns size of dynamic field -func (box *BaseCustomFieldObject) GetFieldSize(string, *BoxStructureStatus) uint { +func (box *BaseCustomFieldObject) GetFieldSize(string, BoxStructureStatus) uint { panic(errors.New("GetFieldSize not implemented")) } // GetFieldLength returns length of dynamic field -func (box *BaseCustomFieldObject) GetFieldLength(string, *BoxStructureStatus) uint { +func (box *BaseCustomFieldObject) GetFieldLength(string, BoxStructureStatus) uint { panic(errors.New("GetFieldLength not implemented")) } // IsOptFieldEnabled check whether if the optional field is enabled -func (box *BaseCustomFieldObject) IsOptFieldEnabled(string, *BoxStructureStatus) bool { +func (box *BaseCustomFieldObject) IsOptFieldEnabled(string, BoxStructureStatus) bool { return false } // StringifyField returns field value as string -func (box *BaseCustomFieldObject) StringifyField(string, string, int, *BoxStructureStatus) (string, bool) { +func (box *BaseCustomFieldObject) StringifyField(string, string, int, BoxStructureStatus) (string, bool) { return "", false } -func (*BaseCustomFieldObject) IsPString(name string, bytes []byte, remainingSize uint64, bss *BoxStructureStatus) bool { +func (*BaseCustomFieldObject) IsPString(name string, bytes []byte, remainingSize uint64, bss BoxStructureStatus) bool { return true } -func (*BaseCustomFieldObject) BeforeUnmarshal(io.ReadSeeker, uint64, *BoxStructureStatus) (uint64, bool, error) { +func (*BaseCustomFieldObject) BeforeUnmarshal(io.ReadSeeker, uint64, BoxStructureStatus) (uint64, bool, error) { return 0, false, nil } -func (*BaseCustomFieldObject) OnReadField(string, bitio.ReadSeeker, uint64, *BoxStructureStatus) (uint64, bool, error) { +func (*BaseCustomFieldObject) OnReadField(string, bitio.ReadSeeker, uint64, BoxStructureStatus) (uint64, bool, error) { return 0, false, nil } -func (*BaseCustomFieldObject) OnWriteField(string, bitio.Writer, *BoxStructureStatus) (uint64, bool, error) { +func (*BaseCustomFieldObject) OnWriteField(string, bitio.Writer, BoxStructureStatus) (uint64, bool, error) { return 0, false, nil } diff --git a/box_types.go b/box_types.go index 2df2262..e4d8d9e 100644 --- a/box_types.go +++ b/box_types.go @@ -31,7 +31,7 @@ func (*Co64) GetType() BoxType { } // GetFieldLength returns length of dynamic field -func (co64 *Co64) GetFieldLength(name string, bss *BoxStructureStatus) uint { +func (co64 *Co64) GetFieldLength(name string, bss BoxStructureStatus) uint { switch name { case "ChunkOffset": return uint(co64.EntryCount) @@ -59,7 +59,7 @@ type Colr struct { Unknown []byte `mp4:"size=8,opt=dynamic"` } -func (colr *Colr) IsOptFieldEnabled(name string, bss *BoxStructureStatus) bool { +func (colr *Colr) IsOptFieldEnabled(name string, bss BoxStructureStatus) bool { switch colr.ColourType { case [4]byte{'n', 'c', 'l', 'x'}: switch name { @@ -111,7 +111,7 @@ func (*Ctts) GetType() BoxType { } // GetFieldLength returns length of dynamic field -func (ctts *Ctts) GetFieldLength(name string, bss *BoxStructureStatus) uint { +func (ctts *Ctts) GetFieldLength(name string, bss BoxStructureStatus) uint { switch name { case "Entries": return uint(ctts.EntryCount) @@ -231,7 +231,7 @@ func (*Elst) GetType() BoxType { } // GetFieldSize returns size of dynamic field -func (elst *Elst) GetFieldSize(name string, bss *BoxStructureStatus) uint { +func (elst *Elst) GetFieldSize(name string, bss BoxStructureStatus) uint { switch name { case "Entries": switch elst.GetVersion() { @@ -253,7 +253,7 @@ func (elst *Elst) GetFieldSize(name string, bss *BoxStructureStatus) uint { } // GetFieldLength returns length of dynamic field -func (elst *Elst) GetFieldLength(name string, bss *BoxStructureStatus) uint { +func (elst *Elst) GetFieldLength(name string, bss BoxStructureStatus) uint { switch name { case "Entries": return uint(elst.EntryCount) @@ -282,7 +282,7 @@ type Emsg struct { MessageData []byte `mp4:"size=8,string"` } -func (emsg *Emsg) OnReadField(name string, r bitio.ReadSeeker, leftBits uint64, bss *BoxStructureStatus) (rbits uint64, override bool, err error) { +func (emsg *Emsg) OnReadField(name string, r bitio.ReadSeeker, leftBits uint64, bss BoxStructureStatus) (rbits uint64, override bool, err error) { if emsg.GetVersion() == 0 { return } @@ -306,7 +306,7 @@ func (emsg *Emsg) OnReadField(name string, r bitio.ReadSeeker, leftBits uint64, } } -func (emsg *Emsg) OnWriteField(name string, w bitio.Writer, bss *BoxStructureStatus) (wbits uint64, override bool, err error) { +func (emsg *Emsg) OnWriteField(name string, w bitio.Writer, bss BoxStructureStatus) (wbits uint64, override bool, err error) { if emsg.GetVersion() == 0 { return } @@ -371,7 +371,7 @@ type Descriptor struct { } // GetFieldLength returns length of dynamic field -func (ds *Descriptor) GetFieldLength(name string, bss *BoxStructureStatus) uint { +func (ds *Descriptor) GetFieldLength(name string, bss BoxStructureStatus) uint { switch name { case "Data": return uint(ds.Size) @@ -379,7 +379,7 @@ func (ds *Descriptor) GetFieldLength(name string, bss *BoxStructureStatus) uint panic(fmt.Errorf("invalid name of dynamic-length field: boxType=esds fieldName=%s", name)) } -func (ds *Descriptor) IsOptFieldEnabled(name string, bss *BoxStructureStatus) bool { +func (ds *Descriptor) IsOptFieldEnabled(name string, bss BoxStructureStatus) bool { switch ds.Tag { case ESDescrTag: return name == "ESDescriptor" @@ -391,7 +391,7 @@ func (ds *Descriptor) IsOptFieldEnabled(name string, bss *BoxStructureStatus) bo } // StringifyField returns field value as string -func (ds *Descriptor) StringifyField(name string, indent string, depth int, bss *BoxStructureStatus) (string, bool) { +func (ds *Descriptor) StringifyField(name string, indent string, depth int, bss BoxStructureStatus) (string, bool) { switch name { case "Tag": switch ds.Tag { @@ -424,7 +424,7 @@ type ESDescriptor struct { OCRESID uint16 `mp4:"size=16,opt=dynamic"` } -func (esds *ESDescriptor) GetFieldLength(name string, bss *BoxStructureStatus) uint { +func (esds *ESDescriptor) GetFieldLength(name string, bss BoxStructureStatus) uint { switch name { case "URLString": return uint(esds.URLLength) @@ -432,7 +432,7 @@ func (esds *ESDescriptor) GetFieldLength(name string, bss *BoxStructureStatus) u panic(fmt.Errorf("invalid name of dynamic-length field: boxType=ESDescriptor fieldName=%s", name)) } -func (esds *ESDescriptor) IsOptFieldEnabled(name string, bss *BoxStructureStatus) bool { +func (esds *ESDescriptor) IsOptFieldEnabled(name string, bss BoxStructureStatus) bool { switch name { case "DependsOnESID": return esds.StreamDependenceFlag @@ -536,7 +536,7 @@ func (*Hdlr) GetType() BoxType { return BoxTypeHdlr() } -func (hdlr *Hdlr) IsPString(name string, bytes []byte, remainingSize uint64, bss *BoxStructureStatus) bool { +func (hdlr *Hdlr) IsPString(name string, bytes []byte, remainingSize uint64, bss BoxStructureStatus) bool { switch name { case "Name": return remainingSize == 0 && hdlr.PreDefined != 0 @@ -666,7 +666,7 @@ func (*Meta) GetType() BoxType { return BoxTypeMeta() } -func (meta *Meta) BeforeUnmarshal(r io.ReadSeeker, size uint64, bss *BoxStructureStatus) (n uint64, override bool, err error) { +func (meta *Meta) BeforeUnmarshal(r io.ReadSeeker, size uint64, bss BoxStructureStatus) (n uint64, override bool, err error) { // for Apple Quick Time buf := make([]byte, 4) if _, err := io.ReadFull(r, buf); err != nil { @@ -844,7 +844,7 @@ func (*Mvhd) GetType() BoxType { } // StringifyField returns field value as string -func (mvhd *Mvhd) StringifyField(name string, indent string, depth int, bss *BoxStructureStatus) (string, bool) { +func (mvhd *Mvhd) StringifyField(name string, indent string, depth int, bss BoxStructureStatus) (string, bool) { switch name { case "Rate": return strconv.FormatFloat(mvhd.GetRate(), 'f', -1, 32), true @@ -886,7 +886,7 @@ type PsshKID struct { } // GetFieldLength returns length of dynamic field -func (pssh *Pssh) GetFieldLength(name string, bss *BoxStructureStatus) uint { +func (pssh *Pssh) GetFieldLength(name string, bss BoxStructureStatus) uint { switch name { case "KIDs": return uint(pssh.KIDCount) @@ -897,7 +897,7 @@ func (pssh *Pssh) GetFieldLength(name string, bss *BoxStructureStatus) uint { } // StringifyField returns field value as string -func (pssh *Pssh) StringifyField(name string, indent string, depth int, bss *BoxStructureStatus) (string, bool) { +func (pssh *Pssh) StringifyField(name string, indent string, depth int, bss BoxStructureStatus) (string, bool) { switch name { case "SystemID": buf := bytes.NewBuffer(nil) @@ -969,7 +969,7 @@ type VisualSampleEntry struct { } // StringifyField returns field value as string -func (vse *VisualSampleEntry) StringifyField(name string, indent string, depth int, bss *BoxStructureStatus) (string, bool) { +func (vse *VisualSampleEntry) StringifyField(name string, indent string, depth int, bss BoxStructureStatus) (string, bool) { switch name { case "Compressorname": if vse.Compressorname[0] <= 31 { @@ -993,18 +993,18 @@ type AudioSampleEntry struct { QuickTimeData []byte `mp4:"size=8,opt=dynamic,len=dynamic"` } -func (ase *AudioSampleEntry) IsOptFieldEnabled(name string, bss *BoxStructureStatus) bool { +func (ase *AudioSampleEntry) IsOptFieldEnabled(name string, bss BoxStructureStatus) bool { if name == "QuickTimeData" { - return bss != nil && bss.IsQuickTimeCompatible && (bss.UnderWave || ase.EntryVersion == 1 || ase.EntryVersion == 2) + return bss.IsQuickTimeCompatible && (bss.UnderWave || ase.EntryVersion == 1 || ase.EntryVersion == 2) } - if bss != nil && bss.IsQuickTimeCompatible && bss.UnderWave { + if bss.IsQuickTimeCompatible && bss.UnderWave { return false } return true } -func (ase *AudioSampleEntry) GetFieldLength(name string, bss *BoxStructureStatus) uint { - if name == "QuickTimeData" && bss != nil && bss.IsQuickTimeCompatible { +func (ase *AudioSampleEntry) GetFieldLength(name string, bss BoxStructureStatus) uint { + if name == "QuickTimeData" && bss.IsQuickTimeCompatible { if bss.UnderWave { return LengthUnlimited } else if ase.EntryVersion == 1 { @@ -1049,7 +1049,7 @@ type AVCDecoderConfiguration struct { SequenceParameterSetsExt []AVCParameterSet `mp4:"len=dynamic,opt=dynamic"` } -func (avcc *AVCDecoderConfiguration) GetFieldLength(name string, bss *BoxStructureStatus) uint { +func (avcc *AVCDecoderConfiguration) GetFieldLength(name string, bss BoxStructureStatus) uint { switch name { case "SequenceParameterSets": return uint(avcc.NumOfSequenceParameterSets) @@ -1061,7 +1061,7 @@ func (avcc *AVCDecoderConfiguration) GetFieldLength(name string, bss *BoxStructu return 0 } -func (avcc *AVCDecoderConfiguration) IsOptFieldEnabled(name string, bss *BoxStructureStatus) bool { +func (avcc *AVCDecoderConfiguration) IsOptFieldEnabled(name string, bss BoxStructureStatus) bool { switch name { case "Reserved3", "ChromaFormat", @@ -1076,7 +1076,7 @@ func (avcc *AVCDecoderConfiguration) IsOptFieldEnabled(name string, bss *BoxStru return false } -func (avcc *AVCDecoderConfiguration) OnReadField(name string, r bitio.ReadSeeker, leftBits uint64, bss *BoxStructureStatus) (rbits uint64, override bool, err error) { +func (avcc *AVCDecoderConfiguration) OnReadField(name string, r bitio.ReadSeeker, leftBits uint64, bss BoxStructureStatus) (rbits uint64, override bool, err error) { if name == "HighProfileFieldsEnabled" { avcc.HighProfileFieldsEnabled = leftBits >= 32 && (avcc.Profile == AVCHighProfile || @@ -1088,7 +1088,7 @@ func (avcc *AVCDecoderConfiguration) OnReadField(name string, r bitio.ReadSeeker return 0, false, nil } -func (avcc *AVCDecoderConfiguration) OnWriteField(name string, w bitio.Writer, bss *BoxStructureStatus) (wbits uint64, override bool, err error) { +func (avcc *AVCDecoderConfiguration) OnWriteField(name string, w bitio.Writer, bss BoxStructureStatus) (wbits uint64, override bool, err error) { if name == "HighProfileFieldsEnabled" { if avcc.HighProfileFieldsEnabled && avcc.Profile != AVCHighProfile && @@ -1108,7 +1108,7 @@ type AVCParameterSet struct { NALUnit []byte `mp4:"size=8,len=dynamic"` } -func (s *AVCParameterSet) GetFieldLength(name string, bss *BoxStructureStatus) uint { +func (s *AVCParameterSet) GetFieldLength(name string, bss BoxStructureStatus) uint { switch name { case "NALUnit": return uint(s.Length) @@ -1143,7 +1143,7 @@ type SbgpEntry struct { GroupDescriptionIndex uint32 `mp4:"size=32"` } -func (sbgp *Sbgp) GetFieldLength(name string, bss *BoxStructureStatus) uint { +func (sbgp *Sbgp) GetFieldLength(name string, bss BoxStructureStatus) uint { switch name { case "Entries": return uint(sbgp.EntryCount) @@ -1239,7 +1239,7 @@ type TemporalLevelEntryL struct { TemporalLevelEntry `mp4:"extend"` } -func (sgpd *Sgpd) GetFieldSize(name string, bss *BoxStructureStatus) uint { +func (sgpd *Sgpd) GetFieldSize(name string, bss BoxStructureStatus) uint { switch name { case "AlternativeStartupEntries": return uint(sgpd.DefaultLength * 8) @@ -1247,7 +1247,7 @@ func (sgpd *Sgpd) GetFieldSize(name string, bss *BoxStructureStatus) uint { return 0 } -func (sgpd *Sgpd) GetFieldLength(name string, bss *BoxStructureStatus) uint { +func (sgpd *Sgpd) GetFieldLength(name string, bss BoxStructureStatus) uint { switch name { case "RollDistances", "RollDistancesL", "AlternativeStartupEntries", "AlternativeStartupEntriesL", @@ -1258,7 +1258,7 @@ func (sgpd *Sgpd) GetFieldLength(name string, bss *BoxStructureStatus) uint { return 0 } -func (sgpd *Sgpd) IsOptFieldEnabled(name string, bss *BoxStructureStatus) bool { +func (sgpd *Sgpd) IsOptFieldEnabled(name string, bss BoxStructureStatus) bool { noDefaultLength := sgpd.Version == 1 && sgpd.DefaultLength == 0 rollDistances := sgpd.GroupingType == [4]byte{'r', 'o', 'l', 'l'} || sgpd.GroupingType == [4]byte{'p', 'r', 'o', 'l'} @@ -1296,7 +1296,7 @@ func (*Sgpd) GetType() BoxType { return BoxTypeSgpd() } -func (entry *AlternativeStartupEntry) GetFieldLength(name string, bss *BoxStructureStatus) uint { +func (entry *AlternativeStartupEntry) GetFieldLength(name string, bss BoxStructureStatus) uint { switch name { case "SampleOffset": return uint(entry.RollCount) @@ -1304,7 +1304,7 @@ func (entry *AlternativeStartupEntry) GetFieldLength(name string, bss *BoxStruct return 0 } -func (entry *AlternativeStartupEntryL) GetFieldSize(name string, bss *BoxStructureStatus) uint { +func (entry *AlternativeStartupEntryL) GetFieldSize(name string, bss BoxStructureStatus) uint { switch name { case "AlternativeStartupEntry": return uint(entry.DescriptionLength * 8) @@ -1346,7 +1346,7 @@ func (*Sidx) GetType() BoxType { return BoxTypeSidx() } -func (sidx *Sidx) GetFieldLength(name string, bss *BoxStructureStatus) uint { +func (sidx *Sidx) GetFieldLength(name string, bss BoxStructureStatus) uint { switch name { case "References": return uint(sidx.ReferenceCount) @@ -1389,7 +1389,7 @@ func (*Smhd) GetType() BoxType { } // StringifyField returns field value as string -func (smhd *Smhd) StringifyField(name string, indent string, depth int, bss *BoxStructureStatus) (string, bool) { +func (smhd *Smhd) StringifyField(name string, indent string, depth int, bss BoxStructureStatus) (string, bool) { switch name { case "Balance": return strconv.FormatFloat(float64(smhd.GetBalance()), 'f', -1, 32), true @@ -1447,7 +1447,7 @@ func (*Stco) GetType() BoxType { } // GetFieldLength returns length of dynamic field -func (stco *Stco) GetFieldLength(name string, bss *BoxStructureStatus) uint { +func (stco *Stco) GetFieldLength(name string, bss BoxStructureStatus) uint { switch name { case "ChunkOffset": return uint(stco.EntryCount) @@ -1482,7 +1482,7 @@ func (*Stsc) GetType() BoxType { } // GetFieldLength returns length of dynamic field -func (stsc *Stsc) GetFieldLength(name string, bss *BoxStructureStatus) uint { +func (stsc *Stsc) GetFieldLength(name string, bss BoxStructureStatus) uint { switch name { case "Entries": return uint(stsc.EntryCount) @@ -1529,7 +1529,7 @@ func (*Stss) GetType() BoxType { } // GetFieldLength returns length of dynamic field -func (stss *Stss) GetFieldLength(name string, bss *BoxStructureStatus) uint { +func (stss *Stss) GetFieldLength(name string, bss BoxStructureStatus) uint { switch name { case "SampleNumber": return uint(stss.EntryCount) @@ -1559,7 +1559,7 @@ func (*Stsz) GetType() BoxType { } // GetFieldLength returns length of dynamic field -func (stsz *Stsz) GetFieldLength(name string, bss *BoxStructureStatus) uint { +func (stsz *Stsz) GetFieldLength(name string, bss BoxStructureStatus) uint { switch name { case "EntrySize": if stsz.SampleSize == 0 { @@ -1597,7 +1597,7 @@ func (*Stts) GetType() BoxType { } // GetFieldLength returns length of dynamic field -func (stts *Stts) GetFieldLength(name string, bss *BoxStructureStatus) uint { +func (stts *Stts) GetFieldLength(name string, bss BoxStructureStatus) uint { switch name { case "Entries": return uint(stts.EntryCount) @@ -1716,7 +1716,7 @@ func (*Tfra) GetType() BoxType { } // GetFieldSize returns size of dynamic field -func (tfra *Tfra) GetFieldSize(name string, bss *BoxStructureStatus) uint { +func (tfra *Tfra) GetFieldSize(name string, bss BoxStructureStatus) uint { switch name { case "TrafNumber": return (uint(tfra.LengthSizeOfTrafNum) + 1) * 8 @@ -1746,7 +1746,7 @@ func (tfra *Tfra) GetFieldSize(name string, bss *BoxStructureStatus) uint { } // GetFieldLength returns length of dynamic field -func (tfra *Tfra) GetFieldLength(name string, bss *BoxStructureStatus) uint { +func (tfra *Tfra) GetFieldLength(name string, bss BoxStructureStatus) uint { switch name { case "Entries": return uint(tfra.NumberOfEntry) @@ -1794,7 +1794,7 @@ func (*Tkhd) GetType() BoxType { } // StringifyField returns field value as string -func (tkhd *Tkhd) StringifyField(name string, indent string, depth int, bss *BoxStructureStatus) (string, bool) { +func (tkhd *Tkhd) StringifyField(name string, indent string, depth int, bss BoxStructureStatus) (string, bool) { switch name { case "Width": return strconv.FormatFloat(tkhd.GetWidth(), 'f', -1, 32), true @@ -1917,7 +1917,7 @@ func (*Trun) GetType() BoxType { } // GetFieldSize returns size of dynamic field -func (trun *Trun) GetFieldSize(name string, bss *BoxStructureStatus) uint { +func (trun *Trun) GetFieldSize(name string, bss BoxStructureStatus) uint { switch name { case "Entries": var size uint @@ -1940,7 +1940,7 @@ func (trun *Trun) GetFieldSize(name string, bss *BoxStructureStatus) uint { } // GetFieldLength returns length of dynamic field -func (trun *Trun) GetFieldLength(name string, bss *BoxStructureStatus) uint { +func (trun *Trun) GetFieldLength(name string, bss BoxStructureStatus) uint { switch name { case "Entries": return uint(trun.SampleCount) diff --git a/box_types_test.go b/box_types_test.go index db36e62..0836e2e 100644 --- a/box_types_test.go +++ b/box_types_test.go @@ -2437,14 +2437,14 @@ func TestBoxTypes(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Marshal buf := bytes.NewBuffer(nil) - n, err := Marshal(buf, tc.src, &tc.bss) + n, err := Marshal(buf, tc.src, tc.bss) require.NoError(t, err) assert.Equal(t, uint64(len(tc.bin)), n) assert.Equal(t, tc.bin, buf.Bytes()) // Unmarshal r := bytes.NewReader(tc.bin) - n, err = Unmarshal(r, uint64(len(tc.bin)), tc.dst, &tc.bss) + n, err = Unmarshal(r, uint64(len(tc.bin)), tc.dst, tc.bss) require.NoError(t, err) assert.Equal(t, uint64(buf.Len()), n) assert.Equal(t, tc.src, tc.dst) @@ -2453,7 +2453,7 @@ func TestBoxTypes(t *testing.T) { assert.Equal(t, int64(buf.Len()), s) // UnmarshalAny - dst, n, err := UnmarshalAny(bytes.NewReader(tc.bin), tc.src.GetType(), uint64(len(tc.bin)), &tc.bss) + dst, n, err := UnmarshalAny(bytes.NewReader(tc.bin), tc.src.GetType(), uint64(len(tc.bin)), tc.bss) require.NoError(t, err) assert.Equal(t, uint64(buf.Len()), n) assert.Equal(t, tc.src, dst) @@ -2462,7 +2462,7 @@ func TestBoxTypes(t *testing.T) { assert.Equal(t, int64(buf.Len()), s) // Stringify - str, err := Stringify(tc.src, &tc.bss) + str, err := Stringify(tc.src, tc.bss) require.NoError(t, err) assert.Equal(t, tc.str, str) }) @@ -2534,7 +2534,7 @@ func TestHdlrUnmarshalHandlerName(t *testing.T) { // unmarshal dst := Hdlr{} r := bytes.NewReader(bin) - n, err := Unmarshal(r, uint64(len(bin)), &dst, nil) + n, err := Unmarshal(r, uint64(len(bin)), &dst, BoxStructureStatus{}) assert.NoError(t, err) assert.Equal(t, uint64(len(bin)), n) assert.Equal(t, [4]byte{'v', 'i', 'd', 'e'}, dst.HandlerType) @@ -2555,7 +2555,7 @@ func TestMetaMarshalAppleQuickTime(t *testing.T) { // unmarshal dst := Meta{} r := bytes.NewReader(bin) - n, err := Unmarshal(r, uint64(len(bin)), &dst, nil) + n, err := Unmarshal(r, uint64(len(bin)), &dst, BoxStructureStatus{}) assert.NoError(t, err) assert.Equal(t, uint64(0), n) s, _ := r.Seek(0, io.SeekCurrent) @@ -2598,7 +2598,7 @@ func TestAvcCInconsistentError(t *testing.T) { }, } buf := bytes.NewBuffer(nil) - _, err := Marshal(buf, avcc, nil) + _, err := Marshal(buf, avcc, BoxStructureStatus{}) require.Error(t, err) assert.Equal(t, "each values of Profile and HighProfileFieldsEnabled are inconsistent", err.Error()) } diff --git a/extract.go b/extract.go index 5dcadc6..5e3001b 100644 --- a/extract.go +++ b/extract.go @@ -26,9 +26,9 @@ func ExtractBoxesWithPayload(r io.ReadSeeker, parent *BoxInfo, paths []BoxPath) return nil, err } - var bss *BoxStructureStatus + var bss BoxStructureStatus if parent != nil { - bss = &parent.BoxStructureStatus + bss = parent.BoxStructureStatus } box, _, err := UnmarshalAny(r, bi.Type, bi.Size-bi.HeaderSize, bss) if err != nil { diff --git a/marshaller.go b/marshaller.go index ed3551e..1045bd6 100644 --- a/marshaller.go +++ b/marshaller.go @@ -23,10 +23,10 @@ type marshaller struct { writer bitio.Writer wbits uint64 src IImmutableBox - bss *BoxStructureStatus + bss BoxStructureStatus } -func Marshal(w io.Writer, src IImmutableBox, bss *BoxStructureStatus) (n uint64, err error) { +func Marshal(w io.Writer, src IImmutableBox, bss BoxStructureStatus) (n uint64, err error) { t := reflect.TypeOf(src).Elem() v := reflect.ValueOf(src).Elem() @@ -259,10 +259,10 @@ type unmarshaller struct { dst IBox size uint64 rbits uint64 - bss *BoxStructureStatus + bss BoxStructureStatus } -func UnmarshalAny(r io.ReadSeeker, boxType BoxType, payloadSize uint64, bss *BoxStructureStatus) (box IBox, n uint64, err error) { +func UnmarshalAny(r io.ReadSeeker, boxType BoxType, payloadSize uint64, bss BoxStructureStatus) (box IBox, n uint64, err error) { if dst, err := boxType.New(); err != nil { return nil, 0, err } else { @@ -271,7 +271,7 @@ func UnmarshalAny(r io.ReadSeeker, boxType BoxType, payloadSize uint64, bss *Box } } -func Unmarshal(r io.ReadSeeker, payloadSize uint64, dst IBox, bss *BoxStructureStatus) (n uint64, err error) { +func Unmarshal(r io.ReadSeeker, payloadSize uint64, dst IBox, bss BoxStructureStatus) (n uint64, err error) { t := reflect.TypeOf(dst).Elem() v := reflect.ValueOf(dst).Elem() @@ -687,7 +687,7 @@ type fieldConfig struct { hidden bool } -func readFieldConfig(box IImmutableBox, parent reflect.Value, fieldName string, tag fieldTag, bss *BoxStructureStatus) (config fieldConfig, err error) { +func readFieldConfig(box IImmutableBox, parent reflect.Value, fieldName string, tag fieldTag, bss BoxStructureStatus) (config fieldConfig, err error) { config.name = fieldName cfo, ok := parent.Addr().Interface().(ICustomFieldObject) if ok { @@ -825,7 +825,7 @@ func parseFieldTag(str string) fieldTag { return tag } -func isTargetField(box IImmutableBox, config fieldConfig, bss *BoxStructureStatus) bool { +func isTargetField(box IImmutableBox, config fieldConfig, bss BoxStructureStatus) bool { if box.GetVersion() != anyVersion { if config.version != anyVersion && box.GetVersion() != config.version { return false diff --git a/marshaller_test.go b/marshaller_test.go index dda266d..7d04bee 100644 --- a/marshaller_test.go +++ b/marshaller_test.go @@ -21,7 +21,7 @@ func (m *mockBox) GetType() BoxType { return m.Type } -func (m *mockBox) GetFieldSize(n string, bss *BoxStructureStatus) uint { +func (m *mockBox) GetFieldSize(n string, bss BoxStructureStatus) uint { if s, ok := m.DynSizeMap[n]; !ok { panic(fmt.Errorf("invalid name of dynamic-size field: %s", n)) } else { @@ -29,7 +29,7 @@ func (m *mockBox) GetFieldSize(n string, bss *BoxStructureStatus) uint { } } -func (m *mockBox) GetFieldLength(n string, bss *BoxStructureStatus) uint { +func (m *mockBox) GetFieldLength(n string, bss BoxStructureStatus) uint { if l, ok := m.DynLenMap[n]; !ok { panic(fmt.Errorf("invalid name of dynamic-length field: %s", n)) } else { @@ -180,14 +180,14 @@ func TestMarshal(t *testing.T) { // marshal buf := &bytes.Buffer{} - n, err := Marshal(buf, &src, nil) + n, err := Marshal(buf, &src, BoxStructureStatus{}) require.NoError(t, err) assert.Equal(t, uint64(len(bin)), n) assert.Equal(t, bin, buf.Bytes()) // unmarshal dst := testBox{mockBox: mb} - n, err = Unmarshal(bytes.NewReader(bin), uint64(len(bin)+8), &dst, nil) + n, err = Unmarshal(bytes.NewReader(bin), uint64(len(bin)+8), &dst, BoxStructureStatus{}) assert.NoError(t, err) assert.Equal(t, uint64(len(bin)), n) assert.Equal(t, src, dst) @@ -229,7 +229,7 @@ func TestUnsupportedBoxVersionErr(t *testing.T) { } dst := testBox{mockBox: mb} - n, err := Unmarshal(bytes.NewReader(bin), uint64(len(bin)+8), &dst, nil) + n, err := Unmarshal(bytes.NewReader(bin), uint64(len(bin)+8), &dst, BoxStructureStatus{}) if e.enabled { assert.NoError(t, err, "version=%d", e.version) @@ -631,7 +631,7 @@ func TestReadFieldConfig(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { v := reflect.ValueOf(tc.box).Elem() - config, err := readFieldConfig(tc.box, v, tc.fieldName, tc.fieldTag, nil) + config, err := readFieldConfig(tc.box, v, tc.fieldName, tc.fieldTag, BoxStructureStatus{}) if tc.err { assert.Error(t, err) return diff --git a/probe.go b/probe.go index d639838..51cf297 100644 --- a/probe.go +++ b/probe.go @@ -106,7 +106,7 @@ func probeTkhd(r io.ReadSeeker, bi *BoxInfo, info *TrackInfo) error { } tkhd := Tkhd{} - _, err := Unmarshal(r, bi.Size-bi.HeaderSize, &tkhd, &bi.BoxStructureStatus) + _, err := Unmarshal(r, bi.Size-bi.HeaderSize, &tkhd, bi.BoxStructureStatus) if err != nil { return err } @@ -126,7 +126,7 @@ func probeMdhd(r io.ReadSeeker, bi *BoxInfo, info *TrackInfo) error { } mdhd := Mdhd{} - _, err := Unmarshal(r, bi.Size-bi.HeaderSize, &mdhd, &bi.BoxStructureStatus) + _, err := Unmarshal(r, bi.Size-bi.HeaderSize, &mdhd, bi.BoxStructureStatus) if err != nil { return err } @@ -183,7 +183,7 @@ func probeTfhd(r io.ReadSeeker, bi *BoxInfo, segment *SegmentInfo) error { } tfhd := Tfhd{} - _, err := Unmarshal(r, bi.Size-bi.HeaderSize, &tfhd, &bi.BoxStructureStatus) + _, err := Unmarshal(r, bi.Size-bi.HeaderSize, &tfhd, bi.BoxStructureStatus) if err != nil { return err } @@ -200,7 +200,7 @@ func probeTfdt(r io.ReadSeeker, bi *BoxInfo, segment *SegmentInfo) error { } tfdt := Tfdt{} - _, err := Unmarshal(r, bi.Size-bi.HeaderSize, &tfdt, &bi.BoxStructureStatus) + _, err := Unmarshal(r, bi.Size-bi.HeaderSize, &tfdt, bi.BoxStructureStatus) if err != nil { return err } @@ -220,7 +220,7 @@ func probeTrun(r io.ReadSeeker, bi *BoxInfo, segment *SegmentInfo) error { } trun := Trun{} - _, err := Unmarshal(r, bi.Size-bi.HeaderSize, &trun, &bi.BoxStructureStatus) + _, err := Unmarshal(r, bi.Size-bi.HeaderSize, &trun, bi.BoxStructureStatus) if err != nil { return err } @@ -263,7 +263,7 @@ func probeTfra(r io.ReadSeeker, bi *BoxInfo, info *FraProbeInfo) error { } tfra := Tfra{} - _, err := Unmarshal(r, bi.Size-bi.HeaderSize, &tfra, &bi.BoxStructureStatus) + _, err := Unmarshal(r, bi.Size-bi.HeaderSize, &tfra, bi.BoxStructureStatus) if err != nil { return err } diff --git a/read.go b/read.go index 15e582b..0065691 100644 --- a/read.go +++ b/read.go @@ -54,7 +54,7 @@ func readBoxStructureFromInternal(r io.ReadSeeker, bi *BoxInfo, path BoxPath, ha // check comatible-brands if len(path) == 0 && bi.Type == BoxTypeFtyp() { var ftyp Ftyp - if _, err := Unmarshal(r, bi.Size-bi.HeaderSize, &ftyp, &bi.BoxStructureStatus); err != nil { + if _, err := Unmarshal(r, bi.Size-bi.HeaderSize, &ftyp, bi.BoxStructureStatus); err != nil { return nil, err } for _, cb := range ftyp.CompatibleBrands { @@ -88,7 +88,7 @@ func readBoxStructureFromInternal(r io.ReadSeeker, bi *BoxInfo, path BoxPath, ha return nil, 0, err } - if box, n, err := UnmarshalAny(r, bi.Type, bi.Size-bi.HeaderSize, &bi.BoxStructureStatus); err != nil { + if box, n, err := UnmarshalAny(r, bi.Type, bi.Size-bi.HeaderSize, bi.BoxStructureStatus); err != nil { return nil, 0, err } else { childrenOffset = bi.Offset + bi.HeaderSize + n @@ -114,7 +114,7 @@ func readBoxStructureFromInternal(r io.ReadSeeker, bi *BoxInfo, path BoxPath, ha return nil, err } - if _, n, err := UnmarshalAny(r, bi.Type, bi.Size-bi.HeaderSize, &bi.BoxStructureStatus); err != nil { + if _, n, err := UnmarshalAny(r, bi.Type, bi.Size-bi.HeaderSize, bi.BoxStructureStatus); err != nil { return nil, err } else { childrenOffset = bi.Offset + bi.HeaderSize + n diff --git a/string.go b/string.go index 69f89e1..0370ce0 100644 --- a/string.go +++ b/string.go @@ -12,14 +12,14 @@ type stringfier struct { buf *bytes.Buffer src IImmutableBox indent string - bss *BoxStructureStatus + bss BoxStructureStatus } -func Stringify(src IImmutableBox, bss *BoxStructureStatus) (string, error) { +func Stringify(src IImmutableBox, bss BoxStructureStatus) (string, error) { return StringifyWithIndent(src, "", bss) } -func StringifyWithIndent(src IImmutableBox, indent string, bss *BoxStructureStatus) (string, error) { +func StringifyWithIndent(src IImmutableBox, indent string, bss BoxStructureStatus) (string, error) { t := reflect.TypeOf(src).Elem() v := reflect.ValueOf(src).Elem() diff --git a/string_test.go b/string_test.go index 0e86da2..01ee5eb 100644 --- a/string_test.go +++ b/string_test.go @@ -54,7 +54,7 @@ func TestEmsgStringify(t *testing.T) { Bool: true, } - str, err := StringifyWithIndent(&box, " ", nil) + str, err := StringifyWithIndent(&box, " ", BoxStructureStatus{}) require.NoError(t, err) assert.Equal(t, ` Version=0`+"\n"+ ` Flags=0x000000`+"\n"+ @@ -74,7 +74,7 @@ func TestEmsgStringify(t *testing.T) { ` Array="hoge"`+"\n"+ ` Bool=true`+"\n", str) - str, err = Stringify(&box, nil) + str, err = Stringify(&box, BoxStructureStatus{}) require.NoError(t, err) assert.Equal(t, `Version=0 Flags=0x000000 String="abema.tv" Int32=-1234567890 Int32Hex=0x12345678 Uint32=1234567890 Bytes="abema" Ptr={Uint64=0x1234567890} Uint64=0x1234567890 Struct={Uint64=0x1234567890} Uint64=0x1234567890 Array="hoge" Bool=true`, str) }