Skip to content

Commit

Permalink
Merge pull request #148 from aler9/patch/ac3
Browse files Browse the repository at this point in the history
Add AC-3 boxes
  • Loading branch information
sunfish-shogi authored Sep 24, 2023
2 parents 065cad1 + 218c0a1 commit e3b90bd
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
36 changes: 36 additions & 0 deletions box_types_etsi_ts_102_366.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package mp4

/*************************** ac-3 ****************************/

// https://www.etsi.org/deliver/etsi_ts/102300_102399/102366/01.04.01_60/ts_102366v010401p.pdf

func BoxTypeAC3() BoxType { return StrToBoxType("ac-3") }

func init() {
AddAnyTypeBoxDef(&AudioSampleEntry{}, BoxTypeAC3())
}

/*************************** dac3 ****************************/

// https://www.etsi.org/deliver/etsi_ts/102300_102399/102366/01.04.01_60/ts_102366v010401p.pdf

func BoxTypeDAC3() BoxType { return StrToBoxType("dac3") }

func init() {
AddBoxDef(&Dac3{})
}

type Dac3 struct {
Box
Fscod uint8 `mp4:"0,size=2"`
Bsid uint8 `mp4:"1,size=5"`
Bsmod uint8 `mp4:"2,size=3"`
Acmod uint8 `mp4:"3,size=3"`
LfeOn uint8 `mp4:"4,size=1"`
BitRateCode uint8 `mp4:"5,size=5"`
Reserved uint8 `mp4:"6,size=5,const=0"`
}

func (Dac3) GetType() BoxType {
return BoxTypeDAC3()
}
69 changes: 69 additions & 0 deletions box_types_etsi_ts_102_366_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package mp4

import (
"bytes"
"io"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestBoxTypesETSI_TS_102_366(t *testing.T) {
testCases := []struct {
name string
src IImmutableBox
dst IBox
bin []byte
str string
ctx Context
}{
{
name: "dac3",
src: &Dac3{
Fscod: 0,
Bsid: 8,
Acmod: 7,
LfeOn: 1,
BitRateCode: 0x7,
},
dst: &Dac3{},
bin: []byte{0x10, 0x3c, 0xe0},
str: `Fscod=0x0 Bsid=0x8 Bsmod=0x0 Acmod=0x7 LfeOn=0x1 BitRateCode=0x7`,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
// Marshal
buf := bytes.NewBuffer(nil)
n, err := Marshal(buf, tc.src, tc.ctx)
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.ctx)
require.NoError(t, err)
assert.Equal(t, uint64(buf.Len()), n)
assert.Equal(t, tc.src, tc.dst)
s, err := r.Seek(0, io.SeekCurrent)
require.NoError(t, err)
assert.Equal(t, int64(buf.Len()), s)

// UnmarshalAny
dst, n, err := UnmarshalAny(bytes.NewReader(tc.bin), tc.src.GetType(), uint64(len(tc.bin)), tc.ctx)
require.NoError(t, err)
assert.Equal(t, uint64(buf.Len()), n)
assert.Equal(t, tc.src, dst)
s, err = r.Seek(0, io.SeekCurrent)
require.NoError(t, err)
assert.Equal(t, int64(buf.Len()), s)

// Stringify
str, err := Stringify(tc.src, tc.ctx)
require.NoError(t, err)
assert.Equal(t, tc.str, str)
})
}
}

0 comments on commit e3b90bd

Please sign in to comment.