-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from aler9/patch-av1
add AV1 boxes
- Loading branch information
Showing
2 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package mp4 | ||
|
||
/*************************** av01 ****************************/ | ||
|
||
// https://aomediacodec.github.io/av1-isobmff | ||
|
||
func BoxTypeAv01() BoxType { return StrToBoxType("av01") } | ||
|
||
func init() { | ||
AddAnyTypeBoxDef(&VisualSampleEntry{}, BoxTypeAv01()) | ||
} | ||
|
||
/*************************** av1C ****************************/ | ||
|
||
// https://aomediacodec.github.io/av1-isobmff | ||
|
||
func BoxTypeAv1C() BoxType { return StrToBoxType("av1C") } | ||
|
||
func init() { | ||
AddBoxDef(&Av1C{}) | ||
} | ||
|
||
type Av1C struct { | ||
Box | ||
Marker uint8 `mp4:"0,size=1,const=1"` | ||
Version uint8 `mp4:"1,size=7,const=1"` | ||
SeqProfile uint8 `mp4:"2,size=3"` | ||
SeqLevelIdx0 uint8 `mp4:"3,size=5"` | ||
SeqTier0 uint8 `mp4:"4,size=1"` | ||
HighBitdepth uint8 `mp4:"5,size=1"` | ||
TwelveBit uint8 `mp4:"6,size=1"` | ||
Monochrome uint8 `mp4:"7,size=1"` | ||
ChromaSubsamplingX uint8 `mp4:"8,size=1"` | ||
ChromaSubsamplingY uint8 `mp4:"9,size=1"` | ||
ChromaSamplePosition uint8 `mp4:"10,size=2"` | ||
Reserved uint8 `mp4:"11,size=3,const=0"` | ||
InitialPresentationDelayPresent uint8 `mp4:"12,size=1"` | ||
InitialPresentationDelayMinusOne uint8 `mp4:"13,size=4"` | ||
ConfigOBUs []uint8 `mp4:"14,size=8"` | ||
} | ||
|
||
func (Av1C) GetType() BoxType { | ||
return BoxTypeAv1C() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package mp4 | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestBoxTypesAV1(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
src IImmutableBox | ||
dst IBox | ||
bin []byte | ||
str string | ||
ctx Context | ||
}{ | ||
{ | ||
name: "Av1C", | ||
src: &Av1C{ | ||
Marker: 1, | ||
Version: 1, | ||
SeqProfile: 2, | ||
SeqLevelIdx0: 1, | ||
SeqTier0: 1, | ||
HighBitdepth: 1, | ||
TwelveBit: 0, | ||
Monochrome: 0, | ||
ChromaSubsamplingX: 1, | ||
ChromaSubsamplingY: 1, | ||
ChromaSamplePosition: 0, | ||
ConfigOBUs: []byte{ | ||
0x08, 0x00, 0x00, 0x00, 0x42, 0xa7, 0xbf, 0xe4, | ||
0x60, 0x0d, 0x00, 0x40, | ||
}, | ||
}, | ||
dst: &Av1C{}, | ||
bin: []byte{ | ||
0x81, 0x41, 0xcc, 0x00, 0x08, 0x00, 0x00, 0x00, | ||
0x42, 0xa7, 0xbf, 0xe4, 0x60, 0x0d, 0x00, 0x40, | ||
}, | ||
str: `SeqProfile=0x2 SeqLevelIdx0=0x1 SeqTier0=0x1 HighBitdepth=0x1 TwelveBit=0x0 Monochrome=0x0 ChromaSubsamplingX=0x1 ChromaSubsamplingY=0x1 ChromaSamplePosition=0x0 InitialPresentationDelayPresent=0x0 InitialPresentationDelayMinusOne=0x0 ConfigOBUs=[0x8, 0x0, 0x0, 0x0, 0x42, 0xa7, 0xbf, 0xe4, 0x60, 0xd, 0x0, 0x40]`, | ||
}, | ||
} | ||
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) | ||
}) | ||
} | ||
} |