diff --git a/atom/ctts.go b/atom/ctts.go new file mode 100644 index 0000000..24eb2e6 --- /dev/null +++ b/atom/ctts.go @@ -0,0 +1,24 @@ +package atom + +import "encoding/binary" + +// CttsBox - Composition offset atom Box +// Box Type: ctts +// Container: Composition offset atom Box (ctts) +// Mandatory: Yes +// Quantity: Exactly one. +type CttsBox struct { + *Box + Version byte + Flags uint32 + EntryCount uint32 +} + +func (b *CttsBox) parse() error { + data := b.ReadBoxData() + + b.Version = data[0] + b.Flags = binary.BigEndian.Uint32(data[0:4]) + b.EntryCount = binary.BigEndian.Uint32(data[4:8]) + return nil +} diff --git a/atom/stbl.go b/atom/stbl.go index d839b75..565bdae 100644 --- a/atom/stbl.go +++ b/atom/stbl.go @@ -9,6 +9,11 @@ type StblBox struct { *Box Stts *SttsBox Stsd *StsdBox + Stss *StssBox + Ctts *CttsBox + Stsc *StscBox + Stsz *StszBox + Stco *StcoBox } func (b *StblBox) parse() error { @@ -23,6 +28,22 @@ func (b *StblBox) parse() error { case "stsd": b.Stsd = &StsdBox{Box: box} b.Stsd.parse() + + case "stss": + b.Stss = &StssBox{Box: box} + b.Stss.parse() + case "ctts": + b.Ctts = &CttsBox{Box: box} + b.Ctts.parse() + case "stsc": + b.Stsc = &StscBox{Box: box} + b.Stsc.parse() + case "stsz": + b.Stsz = &StszBox{Box: box} + b.Stsz.parse() + case "stco": + b.Stco = &StcoBox{Box: box} + b.Stco.parse() } } return nil diff --git a/atom/stco.go b/atom/stco.go new file mode 100644 index 0000000..ac2aa42 --- /dev/null +++ b/atom/stco.go @@ -0,0 +1,28 @@ +package atom + +import "encoding/binary" + +// StcoBox - Chunk offset atom Box +// Box Type: stco +// Container: Chunk offset atom Box (stco) +// Mandatory: Yes +// Quantity: Exactly one. +type StcoBox struct { + *Box + Version byte + Flags uint32 + EntryCount uint32 + ChunkOffsetTable []uint32 +} + +func (b *StcoBox) parse() error { + data := b.ReadBoxData() + b.Version = data[0] + b.Flags = binary.BigEndian.Uint32(data[0:4]) + b.EntryCount = binary.BigEndian.Uint32(data[4:8]) + + for i := 0; i < int(b.EntryCount); i++ { + b.ChunkOffsetTable = append(b.ChunkOffsetTable, binary.BigEndian.Uint32(data[i*4+8:i*4+12])) + } + return nil +} diff --git a/atom/stsc.go b/atom/stsc.go new file mode 100644 index 0000000..b2e2fe3 --- /dev/null +++ b/atom/stsc.go @@ -0,0 +1,32 @@ +package atom + +import "encoding/binary" + +// StscBox - Sample-to-chunk atom Box +// Box Type: stsc +// Container: Sample-to-chunk atom Box (stsc) +// Mandatory: Yes +// Quantity: Exactly one. +type StscBox struct { + *Box + Version byte + Flags uint32 + EntryCount uint32 + SampletoChunkData SampletoChunk +} +type SampletoChunk struct { + Firstchunk uint32 + SamplesPerChunk uint32 + SampleDescriptionID uint32 +} + +func (b *StscBox) parse() error { + data := b.ReadBoxData() + b.Version = data[0] + b.Flags = binary.BigEndian.Uint32(data[0:4]) + b.EntryCount = binary.BigEndian.Uint32(data[4:8]) + b.SampletoChunkData.Firstchunk = binary.BigEndian.Uint32(data[8:12]) + b.SampletoChunkData.SamplesPerChunk = binary.BigEndian.Uint32(data[12:16]) + b.SampletoChunkData.SampleDescriptionID = binary.BigEndian.Uint32(data[16:20]) + return nil +} diff --git a/atom/stss.go b/atom/stss.go new file mode 100644 index 0000000..55ebea2 --- /dev/null +++ b/atom/stss.go @@ -0,0 +1,30 @@ +package atom + +import ( + "encoding/binary" +) + +// StssBox - Sync sample atom Box +// Box Type: stss +// Container: Sync sample atom Box (stss) +// Mandatory: Yes +// Quantity: Exactly one. +type StssBox struct { + *Box + Version byte + Flags uint32 + EntriesNumber uint32 + SyncSampleTable []uint32 +} + +func (b *StssBox) parse() error { + data := b.ReadBoxData() + b.Version = data[0] + b.Flags = binary.BigEndian.Uint32(data[0:4]) + b.EntriesNumber = binary.BigEndian.Uint32(data[4:8]) + for i := 8; i < len(data); i += 4 { + b.SyncSampleTable = append(b.SyncSampleTable, uint32(binary.BigEndian.Uint32(data[i:i+4]))) + } + + return nil +} diff --git a/atom/stsz.go b/atom/stsz.go new file mode 100644 index 0000000..63b3b68 --- /dev/null +++ b/atom/stsz.go @@ -0,0 +1,31 @@ +package atom + +import "encoding/binary" + +// StszBox - Sample size atom Box +// Box Type: sttz +// Container: Sample Size Table Box (stsz) +// Mandatory: Yes +// Quantity: Exactly one. +type StszBox struct { + *Box + Version byte + Flags uint32 + SampleSize uint32 + EntryCount uint32 + SampleSizeTable []uint32 +} + +func (b *StszBox) parse() error { + data := b.ReadBoxData() + b.Version = data[0] + b.Flags = binary.BigEndian.Uint32(data[0:4]) + b.SampleSize = binary.BigEndian.Uint32(data[4:8]) + b.EntryCount = binary.BigEndian.Uint32(data[8:12]) + if b.SampleSize == 0 { + for i := 0; i < int(b.EntryCount); i++ { + b.SampleSizeTable = append(b.SampleSizeTable, binary.BigEndian.Uint32(data[i*4+12:i*4+16])) + } + } + return nil +}