Skip to content

Commit

Permalink
feat: add hvc1 and sdtp support
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyoucao577 committed Nov 18, 2023
1 parent d338f85 commit 6c29aad
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
4 changes: 4 additions & 0 deletions container/mp4/box/box_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (
TypeStsz = "stsz"
TypeStco = "stco"
TypeCtts = "ctts"
TypeSdtp = "sdtp"
TypeDref = "dref"
TypeUrl = "url "
TypeUrn = "urn"
Expand All @@ -69,6 +70,7 @@ const (
TypeAvc1 = "avc1"
TypeAvcC = "avcC"
TypeHev1 = "hev1"
TypeHvc1 = "hvc1"
TypehvcC = "hvcC"
TypeAv01 = "av01"
TypeAv1C = "av1C"
Expand Down Expand Up @@ -108,6 +110,7 @@ var boxTypes = map[string]BasicInfo{
TypeStsz: {Name: "Sample Size Box"},
TypeStco: {Name: "Chunk Offset Box"},
TypeCtts: {Name: "Composition Time to Sample Box"},
TypeSdtp: {Name: "Independent and Disposable Samples Box"},
TypeDref: {Name: "Data Reference Box"},
TypeUrl: {Name: "Data Entry Url Box"},
TypeUrn: {Name: "Data Entry Urn Box"},
Expand All @@ -132,6 +135,7 @@ var boxTypes = map[string]BasicInfo{
TypeAvc1: {Name: "AVC Sample Entry"},
TypeAvcC: {Name: "AVC Configuration Box"},
TypeHev1: {Name: "HEVC Sample Entry"},
TypeHvc1: {Name: "HEVC Sample Entry"},
TypehvcC: {Name: "HEVC Configuration Box"},
TypeAv01: {Name: "AV1 Sample Entry"},
TypeAv1C: {Name: "AV1 Configuration Box"},
Expand Down
49 changes: 49 additions & 0 deletions container/mp4/box/sdtp/sdtp_box.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Package sdtp represents Independent and Disposable Samples Box.
package sdtp

import (
"io"

"github.com/golang/glog"
"github.com/wangyoucao577/medialib/container/mp4/box"
"github.com/wangyoucao577/medialib/util"
)

// Box represents a sdtp box.
type Box struct {
box.FullHeader `json:"full_header"`

//TODO: payloads
}

// New creates a new Box.
func New(h box.Header) box.Box {
return &Box{
FullHeader: box.FullHeader{
Header: h,
},
}
}

// ParsePayload parse payload which requires basic box already exist.
func (b *Box) ParsePayload(r io.Reader) error {
if err := b.Validate(); err != nil {
glog.Warningf("box %s invalid, err %v", b.Type, err)
return nil
}

// parse full header additional information first
if err := b.FullHeader.ParseVersionFlag(r); err != nil {
return err
}

if b.PayloadSize() > 0 {
//TODO: parse payload
glog.Warningf("sdtp payload size %d but ignoring", b.PayloadSize())
if err := util.ReadOrError(r, make([]byte, b.PayloadSize())); err != nil {
return err
}
}

return nil
}
5 changes: 5 additions & 0 deletions container/mp4/box/stbl/stbl_box.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/wangyoucao577/medialib/container/mp4/box"
"github.com/wangyoucao577/medialib/container/mp4/box/ctts"
"github.com/wangyoucao577/medialib/container/mp4/box/hdlr"
"github.com/wangyoucao577/medialib/container/mp4/box/sdtp"
"github.com/wangyoucao577/medialib/container/mp4/box/stco"
"github.com/wangyoucao577/medialib/container/mp4/box/stsc"
"github.com/wangyoucao577/medialib/container/mp4/box/stsd"
Expand All @@ -27,6 +28,7 @@ type Box struct {
Stsz *stsz.Box `json:"stsz,omitempty"`
Stco *stco.Box `json:"stco,omitempty"`
Ctts *ctts.Box `json:"ctts,omitempty"`
Sdtp *sdtp.Box `json:"sdtp,omitempty"`

// passed from parent for later use
hdlr *hdlr.Box `json:"-"`
Expand All @@ -52,6 +54,7 @@ func New(h box.Header) box.Box {
box.TypeStsz: stsz.New,
box.TypeStco: stco.New,
box.TypeCtts: ctts.New,
box.TypeSdtp: sdtp.New,
},
}
}
Expand Down Expand Up @@ -87,6 +90,8 @@ func (b *Box) CreateSubBox(h box.Header) (box.Box, error) {
b.Stco = createdBox.(*stco.Box)
case box.TypeCtts:
b.Ctts = createdBox.(*ctts.Box)
case box.TypeSdtp:
b.Sdtp = createdBox.(*sdtp.Box)
}

return createdBox, nil
Expand Down
5 changes: 5 additions & 0 deletions container/mp4/box/stsd/stsd_box.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Box struct {
EntryCount uint32 `json:"entry_connt"`
AVC1SampleEntries []avc1.AVCSampleEntry `json:"avc1,omitempty"`
HEV1SampleEntries []hev1.HEVCSampleEntry `json:"hev1,omitempty"`
HVC1SampleEntries []hev1.HEVCSampleEntry `json:"hvc1,omitempty"`
AV01SampleEntries []av01.AV1SampleEntry `json:"av01,omitempty"`
MP4VisualSampleEntries []mp4a.MP4VisualSampleEntry `json:"mp4a,omitempty"`

Expand All @@ -42,6 +43,7 @@ func New(h box.Header) box.Box {
boxesCreator: map[string]box.NewFunc{
box.TypeAvc1: avc1.New,
box.TypeHev1: hev1.New,
box.TypeHvc1: hev1.New,
box.TypeAv01: av01.New,
box.TypeMp4a: mp4a.New,
},
Expand Down Expand Up @@ -70,6 +72,9 @@ func (b *Box) CreateSubBox(h box.Header) (box.Box, error) {
case box.TypeHev1:
b.HEV1SampleEntries = append(b.HEV1SampleEntries, *createdBox.(*hev1.HEVCSampleEntry))
createdBox = &b.HEV1SampleEntries[len(b.HEV1SampleEntries)-1]
case box.TypeHvc1:
b.HVC1SampleEntries = append(b.HVC1SampleEntries, *createdBox.(*hev1.HEVCSampleEntry))
createdBox = &b.HVC1SampleEntries[len(b.HVC1SampleEntries)-1]
case box.TypeAv01:
b.AV01SampleEntries = append(b.AV01SampleEntries, *createdBox.(*av01.AV1SampleEntry))
createdBox = &b.AV01SampleEntries[len(b.AV01SampleEntries)-1]
Expand Down

0 comments on commit 6c29aad

Please sign in to comment.