Skip to content

Commit

Permalink
feat: add pasp
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyoucao577 committed Oct 21, 2023
1 parent b58009c commit 2a991ec
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions container/mp4/box/box_type.go
Expand Up @@ -75,6 +75,7 @@ const (
TypeBtrt = "btrt"
TypeMp4a = "mp4a"
TypeEsds = "esds"
TypePasp = "pasp"
)

var boxTypes = map[string]BasicInfo{
Expand Down Expand Up @@ -137,6 +138,7 @@ var boxTypes = map[string]BasicInfo{
TypeBtrt: {Name: "MPEG4 Bit Rate Box"},
TypeMp4a: {Name: "MP4 Visual Sample Entry"},
TypeEsds: {Name: "ES Descriptor Box"},
TypePasp: {Name: "Pixel Aspect Ratio Box"},
}

// BoxTypes returns box types map.
Expand Down
5 changes: 5 additions & 0 deletions container/mp4/box/sampleentry/av01/av01_sample_entry.go
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/wangyoucao577/medialib/container/mp4/box/sampleentry"
av1c "github.com/wangyoucao577/medialib/container/mp4/box/sampleentry/av1C"
"github.com/wangyoucao577/medialib/container/mp4/box/sampleentry/btrt"
"github.com/wangyoucao577/medialib/container/mp4/box/sampleentry/pasp"
"github.com/wangyoucao577/medialib/container/mp4/box/sampleentry/vide"
)

Expand All @@ -18,6 +19,7 @@ type AV1SampleEntry struct {

AV1Config *av1c.AV1ConfigrationBox `json:"av1C"`
Btrt *btrt.Box `json:"btrt,omitempty"`
Pasp *pasp.Box `json:"pasp,omitempty"`

boxesCreator map[string]box.NewFunc `json:"-"`
}
Expand All @@ -34,6 +36,7 @@ func New(h box.Header) box.Box {
boxesCreator: map[string]box.NewFunc{
box.TypeAv1C: av1c.New,
box.TypeBtrt: btrt.New,
box.TypePasp: pasp.New,
},
}
}
Expand All @@ -56,6 +59,8 @@ func (a *AV1SampleEntry) CreateSubBox(h box.Header) (box.Box, error) {
a.AV1Config = createdBox.(*av1c.AV1ConfigrationBox)
case box.TypeBtrt:
a.Btrt = createdBox.(*btrt.Box)
case box.TypePasp:
a.Pasp = createdBox.(*pasp.Box)
}

return createdBox, nil
Expand Down
48 changes: 48 additions & 0 deletions container/mp4/box/sampleentry/pasp/pasp_box.go
@@ -0,0 +1,48 @@
// Package pasp represents PixelAspectRatio Box.
package pasp

import (
"encoding/binary"
"io"

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

// Box represents a PixelAspectRatio box.
type Box struct {
box.Header `json:"header"`

HSpacing uint32 `json:"hSpacing"`
VSpacing uint32 `json:"vSpacing"`
}

// New creates a new Box.
func New(h box.Header) box.Box {
return &Box{
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.Header.Type, err)
return nil
}

// start to parse payload
var parsedBytes uint64

data := make([]byte, 8)
if err := util.ReadOrError(r, data); err != nil {
return err
} else {
b.HSpacing = binary.BigEndian.Uint32(data[:4])
b.VSpacing = binary.BigEndian.Uint32(data[4:])
parsedBytes += 8

Check failure on line 44 in container/mp4/box/sampleentry/pasp/pasp_box.go

View workflow job for this annotation

GitHub Actions / Lint

ineffectual assignment to parsedBytes (ineffassign)
}

return nil
}

0 comments on commit 2a991ec

Please sign in to comment.