Browse Source

improve tests

pull/1364/head
aler9 3 years ago
parent
commit
3fd2a25dc1
  1. 10
      internal/hls/client_downloader_primary.go
  2. 123
      internal/hls/fmp4/init.go
  3. 549
      internal/hls/fmp4/init_test.go

10
internal/hls/client_downloader_primary.go

@ -271,19 +271,17 @@ func (d *clientDownloaderPrimary) run(ctx context.Context) error {
for _, track := range tracks { for _, track := range tracks {
switch ttrack := track.(type) { switch ttrack := track.(type) {
case *format.H264: case *format.H264:
if videoTrack != nil {
return fmt.Errorf("multiple video tracks are not supported")
}
videoTrack = ttrack videoTrack = ttrack
case *format.MPEG4Audio: case *format.MPEG4Audio:
if audioTrack != nil {
return fmt.Errorf("multiple audio tracks are not supported")
}
audioTrack = ttrack audioTrack = ttrack
} }
} }
if videoTrack == nil && audioTrack == nil {
return fmt.Errorf("no supported tracks found")
}
err = d.onTracks(videoTrack, audioTrack) err = d.onTracks(videoTrack, audioTrack)
if err != nil { if err != nil {
return err return err

123
internal/hls/fmp4/init.go

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
gomp4 "github.com/abema/go-mp4" gomp4 "github.com/abema/go-mp4"
"github.com/aler9/gortsplib/v2/pkg/codecs/h265"
"github.com/aler9/gortsplib/v2/pkg/codecs/mpeg4audio" "github.com/aler9/gortsplib/v2/pkg/codecs/mpeg4audio"
"github.com/aler9/gortsplib/v2/pkg/format" "github.com/aler9/gortsplib/v2/pkg/format"
) )
@ -23,8 +24,10 @@ func (i *Init) Unmarshal(byts []byte) error {
waitingTkhd waitingTkhd
waitingMdhd waitingMdhd
waitingCodec waitingCodec
waitingAvcc waitingAvcC
waitingHvcC
waitingEsds waitingEsds
waitingDOps
) )
state := waitingTrak state := waitingTrak
@ -34,7 +37,7 @@ func (i *Init) Unmarshal(byts []byte) error {
switch h.BoxInfo.Type.String() { switch h.BoxInfo.Type.String() {
case "trak": case "trak":
if state != waitingTrak { if state != waitingTrak {
return nil, fmt.Errorf("parse error") return nil, fmt.Errorf("unexpected box 'trak'")
} }
curTrack = &InitTrack{} curTrack = &InitTrack{}
@ -43,7 +46,7 @@ func (i *Init) Unmarshal(byts []byte) error {
case "tkhd": case "tkhd":
if state != waitingTkhd { if state != waitingTkhd {
return nil, fmt.Errorf("parse error") return nil, fmt.Errorf("unexpected box 'tkhd'")
} }
box, _, err := h.ReadPayload() box, _, err := h.ReadPayload()
@ -57,7 +60,7 @@ func (i *Init) Unmarshal(byts []byte) error {
case "mdhd": case "mdhd":
if state != waitingMdhd { if state != waitingMdhd {
return nil, fmt.Errorf("parse error") return nil, fmt.Errorf("unexpected box 'mdhd'")
} }
box, _, err := h.ReadPayload() box, _, err := h.ReadPayload()
@ -71,38 +74,38 @@ func (i *Init) Unmarshal(byts []byte) error {
case "avc1": case "avc1":
if state != waitingCodec { if state != waitingCodec {
return nil, fmt.Errorf("parse error") return nil, fmt.Errorf("unexpected box 'avc1'")
} }
state = waitingAvcc state = waitingAvcC
case "avcC": case "avcC":
if state != waitingAvcc { if state != waitingAvcC {
return nil, fmt.Errorf("parse error") return nil, fmt.Errorf("unexpected box 'avcC'")
} }
box, _, err := h.ReadPayload() box, _, err := h.ReadPayload()
if err != nil { if err != nil {
return nil, err return nil, err
} }
conf := box.(*gomp4.AVCDecoderConfiguration) avcc := box.(*gomp4.AVCDecoderConfiguration)
if len(conf.SequenceParameterSets) > 1 { if len(avcc.SequenceParameterSets) > 1 {
return nil, fmt.Errorf("multiple SPS are not supported") return nil, fmt.Errorf("multiple SPS are not supported")
} }
var sps []byte var sps []byte
if len(conf.SequenceParameterSets) == 1 { if len(avcc.SequenceParameterSets) == 1 {
sps = conf.SequenceParameterSets[0].NALUnit sps = avcc.SequenceParameterSets[0].NALUnit
} }
if len(conf.PictureParameterSets) > 1 { if len(avcc.PictureParameterSets) > 1 {
return nil, fmt.Errorf("multiple PPS are not supported") return nil, fmt.Errorf("multiple PPS are not supported")
} }
var pps []byte var pps []byte
if len(conf.PictureParameterSets) == 1 { if len(avcc.PictureParameterSets) == 1 {
pps = conf.PictureParameterSets[0].NALUnit pps = avcc.PictureParameterSets[0].NALUnit
} }
curTrack.Format = &format.H264{ curTrack.Format = &format.H264{
@ -113,16 +116,76 @@ func (i *Init) Unmarshal(byts []byte) error {
} }
state = waitingTrak state = waitingTrak
case "mp4a": case "hev1":
if state != waitingCodec { if state != waitingCodec {
return nil, fmt.Errorf("parse error") return nil, fmt.Errorf("unexpected box 'hev1'")
}
state = waitingHvcC
case "hvcC":
if state != waitingHvcC {
return nil, fmt.Errorf("unexpected box 'hvcC'")
}
box, _, err := h.ReadPayload()
if err != nil {
return nil, err
}
hvcc := box.(*gomp4.HvcC)
var vps []byte
var sps []byte
var pps []byte
for _, arr := range hvcc.NaluArrays {
switch h265.NALUType(arr.NaluType) {
case h265.NALUType_VPS_NUT, h265.NALUType_SPS_NUT, h265.NALUType_PPS_NUT:
if arr.NumNalus != 1 {
return nil, fmt.Errorf("multiple VPS/SPS/PPS are not supported")
}
}
switch h265.NALUType(arr.NaluType) {
case h265.NALUType_VPS_NUT:
vps = arr.Nalus[0].NALUnit
case h265.NALUType_SPS_NUT:
sps = arr.Nalus[0].NALUnit
case h265.NALUType_PPS_NUT:
pps = arr.Nalus[0].NALUnit
}
}
if vps == nil {
return nil, fmt.Errorf("VPS not provided")
}
if sps == nil {
return nil, fmt.Errorf("SPS not provided")
}
if pps == nil {
return nil, fmt.Errorf("PPS not provided")
}
curTrack.Format = &format.H265{
PayloadTyp: 96,
VPS: vps,
SPS: sps,
PPS: pps,
} }
state = waitingTrak
case "mp4a":
if state != waitingCodec {
return nil, fmt.Errorf("unexpected box 'mp4a'")
}
state = waitingEsds state = waitingEsds
case "esds": case "esds":
if state != waitingEsds { if state != waitingEsds {
return nil, fmt.Errorf("parse error") return nil, fmt.Errorf("unexpected box 'esds'")
} }
box, _, err := h.ReadPayload() box, _, err := h.ReadPayload()
@ -160,6 +223,30 @@ func (i *Init) Unmarshal(byts []byte) error {
case "ac-3": case "ac-3":
return nil, fmt.Errorf("AC-3 codec is not supported (yet)") return nil, fmt.Errorf("AC-3 codec is not supported (yet)")
case "Opus":
if state != waitingCodec {
return nil, fmt.Errorf("unexpected box 'Opus'")
}
state = waitingDOps
case "dOps":
if state != waitingDOps {
return nil, fmt.Errorf("unexpected box 'dOps'")
}
box, _, err := h.ReadPayload()
if err != nil {
return nil, err
}
dops := box.(*DOps)
curTrack.Format = &format.Opus{
PayloadTyp: 96,
SampleRate: int(dops.InputSampleRate),
ChannelCount: int(dops.OutputChannelCount),
}
state = waitingTrak
} }
return h.Expand() return h.Expand()

549
internal/hls/fmp4/init_test.go

@ -1,4 +1,3 @@
//nolint:dupl
package fmp4 package fmp4
import ( import (
@ -24,7 +23,7 @@ var testVideoTrack = &format.H264{
} }
var testAudioTrack = &format.MPEG4Audio{ var testAudioTrack = &format.MPEG4Audio{
PayloadTyp: 97, PayloadTyp: 96,
Config: &mpeg4audio.Config{ Config: &mpeg4audio.Config{
Type: 2, Type: 2,
SampleRate: 44100, SampleRate: 44100,
@ -35,33 +34,20 @@ var testAudioTrack = &format.MPEG4Audio{
IndexDeltaLength: 3, IndexDeltaLength: 3,
} }
func TestInitMarshal(t *testing.T) { var casesInit = []struct {
t.Run("video + audio", func(t *testing.T) { name string
init := Init{ enc []byte
Tracks: []*InitTrack{ dec Init
{ }{
ID: 1,
TimeScale: 90000,
Format: testVideoTrack,
},
{ {
ID: 2, "h264",
TimeScale: uint32(testAudioTrack.ClockRate()), []byte{
Format: testAudioTrack,
},
},
}
byts, err := init.Marshal()
require.NoError(t, err)
require.Equal(t, []byte{
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20,
'f', 't', 'y', 'p', 'f', 't', 'y', 'p',
0x6d, 0x70, 0x34, 0x32, 0x00, 0x00, 0x00, 0x01, 0x6d, 0x70, 0x34, 0x32, 0x00, 0x00, 0x00, 0x01,
0x6d, 0x70, 0x34, 0x31, 0x6d, 0x70, 0x34, 0x32, 0x6d, 0x70, 0x34, 0x31, 0x6d, 0x70, 0x34, 0x32,
0x69, 0x73, 0x6f, 0x6d, 0x68, 0x6c, 0x73, 0x66, 0x69, 0x73, 0x6f, 0x6d, 0x68, 0x6c, 0x73, 0x66,
0x00, 0x00, 0x04, 0x64, 0x00, 0x00, 0x02, 0x88,
'm', 'o', 'o', 'v', 'm', 'o', 'o', 'v',
0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x6c,
'm', 'v', 'h', 'd', 'm', 'v', 'h', 'd',
@ -92,13 +78,15 @@ func TestInitMarshal(t *testing.T) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x07, 0x80, 0x00, 0x00, 0x04, 0x38, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x04, 0x38, 0x00, 0x00,
0x00, 0x00, 0x01, 0x88, 0x6d, 0x64, 0x69, 0x61, 0x00, 0x00, 0x01, 0x88,
'm', 'd', 'i', 'a',
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20,
'm', 'd', 'h', 'd', 'm', 'd', 'h', 'd',
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x5f, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x5f, 0x90,
0x00, 0x00, 0x00, 0x00, 0x55, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xc4, 0x00, 0x00,
0x00, 0x00, 0x00, 0x2d, 0x68, 0x64, 0x6c, 0x72, 0x00, 0x00, 0x00, 0x2d,
'h', 'd', 'l', 'r',
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x76, 0x69, 0x64, 0x65, 0x00, 0x00, 0x00, 0x00, 0x76, 0x69, 0x64, 0x65, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -106,12 +94,14 @@ func TestInitMarshal(t *testing.T) {
0x64, 0x6c, 0x65, 0x72, 0x00, 0x00, 0x00, 0x01, 0x64, 0x6c, 0x65, 0x72, 0x00, 0x00, 0x00, 0x01,
0x33, 0x33,
'm', 'i', 'n', 'f', 'm', 'i', 'n', 'f',
0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
0x14,
'v', 'm', 'h', 'd', 'v', 'm', 'h', 'd',
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x24, 0x64, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x24,
0x66, 0x00, 0x00, 0x00, 0x1c, 0x64, 0x72, 0x65, 'd', 'i', 'n', 'f',
0x00, 0x00, 0x00, 0x1c, 0x64, 0x72, 0x65,
0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x0c, 0x75, 0x72, 0x6c, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x75, 0x72, 0x6c,
0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
@ -145,80 +135,13 @@ func TestInitMarshal(t *testing.T) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x10, 0x73, 0x74, 0x63, 0x6f, 0x00, 0x00, 0x00, 0x10, 0x73, 0x74, 0x63, 0x6f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0xbc, 0x00, 0x00, 0x00, 0x28, 0x6d, 0x76, 0x65, 0x78,
't', 'r', 'a', 'k', 0x00, 0x00, 0x00, 0x20, 0x74, 0x72, 0x65, 0x78,
0x00, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
't', 'k', 'h', 'd', 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x58,
0x6d, 0x64, 0x69, 0x61, 0x00, 0x00, 0x00, 0x20,
'm', 'd', 'h', 'd',
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xac, 0x44, 0x00, 0x00, 0x00, 0x00,
0x55, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d,
0x68, 0x64, 0x6c, 0x72, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x73, 0x6f, 0x75, 0x6e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x53, 0x6f, 0x75, 0x6e,
0x64, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72,
0x00, 0x00, 0x00, 0x01, 0x03, 0x6d, 0x69, 0x6e,
0x66, 0x00, 0x00, 0x00, 0x10,
's', 'm', 'h', 'd',
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x24, 0x64, 0x69, 0x6e,
0x66, 0x00, 0x00, 0x00, 0x1c, 0x64, 0x72, 0x65,
0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x0c, 0x75, 0x72, 0x6c,
0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0xc7, 0x73, 0x74, 0x62, 0x6c, 0x00, 0x00, 0x00,
0x7b, 0x73, 0x74, 0x73, 0x64, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x6b, 0x6d, 0x70, 0x34, 0x61, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
0x10, 0x00, 0x00, 0x00, 0x00, 0xac, 0x44, 0x00,
0x00, 0x00, 0x00, 0x00, 0x33, 0x65, 0x73, 0x64,
0x73, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x80,
0x80, 0x22, 0x00, 0x02, 0x00, 0x04, 0x80, 0x80,
0x80, 0x14, 0x40, 0x15, 0x00, 0x00, 0x00, 0x00,
0x01, 0xf7, 0x39, 0x00, 0x01, 0xf7, 0x39, 0x05,
0x80, 0x80, 0x80, 0x02, 0x12, 0x10, 0x06, 0x80,
0x80, 0x80, 0x01, 0x02, 0x00, 0x00, 0x00, 0x14,
0x62, 0x74, 0x72, 0x74, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xf7, 0x39, 0x00, 0x01, 0xf7, 0x39,
0x00, 0x00, 0x00, 0x10, 0x73, 0x74, 0x74, 0x73,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x10, 0x73, 0x74, 0x73, 0x63,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x14, 0x73, 0x74, 0x73, 0x7a,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
0x73, 0x74, 0x63, 0x6f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48,
0x6d, 0x76, 0x65, 0x78, 0x00, 0x00, 0x00, 0x20,
0x74, 0x72, 0x65, 0x78, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
0x74, 0x72, 0x65, 0x78, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, },
}, byts) Init{
})
t.Run("video only", func(t *testing.T) {
init := Init{
Tracks: []*InitTrack{ Tracks: []*InitTrack{
{ {
ID: 1, ID: 1,
@ -226,18 +149,17 @@ func TestInitMarshal(t *testing.T) {
Format: testVideoTrack, Format: testVideoTrack,
}, },
}, },
} },
},
byts, err := init.Marshal() {
require.NoError(t, err) "h265",
[]byte{
require.Equal(t, []byte{
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20,
'f', 't', 'y', 'p', 'f', 't', 'y', 'p',
0x6d, 0x70, 0x34, 0x32, 0x00, 0x00, 0x00, 0x01, 0x6d, 0x70, 0x34, 0x32, 0x00, 0x00, 0x00, 0x01,
0x6d, 0x70, 0x34, 0x31, 0x6d, 0x70, 0x34, 0x32, 0x6d, 0x70, 0x34, 0x31, 0x6d, 0x70, 0x34, 0x32,
0x69, 0x73, 0x6f, 0x6d, 0x68, 0x6c, 0x73, 0x66, 0x69, 0x73, 0x6f, 0x6d, 0x68, 0x6c, 0x73, 0x66,
0x00, 0x00, 0x02, 0x88, 0x00, 0x00, 0x02, 0xb8,
'm', 'o', 'o', 'v', 'm', 'o', 'o', 'v',
0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x6c,
'm', 'v', 'h', 'd', 'm', 'v', 'h', 'd',
@ -253,11 +175,9 @@ func TestInitMarshal(t *testing.T) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x01, 0xec, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x02, 0x1c,
't', 'r', 'a', 'k', 0x74, 0x72, 0x61, 0x6b, 0x00, 0x00, 0x00, 0x5c,
0x00, 0x00, 0x00, 0x5c, 0x74, 0x6b, 0x68, 0x64, 0x00, 0x00, 0x00, 0x03,
't', 'k', 'h', 'd',
0x00, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -268,9 +188,8 @@ func TestInitMarshal(t *testing.T) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x07, 0x80, 0x00, 0x00, 0x04, 0x38, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x04, 0x38, 0x00, 0x00,
0x00, 0x00, 0x01, 0x88, 0x6d, 0x64, 0x69, 0x61, 0x00, 0x00, 0x01, 0xb8, 0x6d, 0x64, 0x69, 0x61,
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x6d, 0x64, 0x68, 0x64,
'm', 'd', 'h', 'd',
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x5f, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x5f, 0x90,
0x00, 0x00, 0x00, 0x00, 0x55, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xc4, 0x00, 0x00,
@ -280,23 +199,18 @@ func TestInitMarshal(t *testing.T) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x56, 0x69, 0x64, 0x65, 0x6f, 0x48, 0x61, 0x6e, 0x56, 0x69, 0x64, 0x65, 0x6f, 0x48, 0x61, 0x6e,
0x64, 0x6c, 0x65, 0x72, 0x00, 0x00, 0x00, 0x01, 0x64, 0x6c, 0x65, 0x72, 0x00, 0x00, 0x00, 0x01,
0x33, 0x63, 0x6d, 0x69, 0x6e, 0x66, 0x00, 0x00, 0x00,
'm', 'i', 'n', 'f', 0x14, 0x76, 0x6d, 0x68, 0x64, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00,
0x14,
'v', 'm', 'h', 'd',
0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x24, 0x64, 0x69, 0x6e,
'd', 'i', 'n', 'f', 0x66, 0x00, 0x00, 0x00, 0x1c, 0x64, 0x72, 0x65,
0x00, 0x00, 0x00, 0x1c, 0x64, 0x72, 0x65,
0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x0c, 0x75, 0x72, 0x6c, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x75, 0x72, 0x6c,
0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01,
0xf3, 0x73, 0x74, 0x62, 0x6c, 0x00, 0x00, 0x00, 0x23, 0x73, 0x74, 0x62, 0x6c, 0x00, 0x00, 0x00,
0xa7, 0x73, 0x74, 0x73, 0x64, 0x00, 0x00, 0x00, 0xd7, 0x73, 0x74, 0x73, 0x64, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x97, 0x61, 0x76, 0x63, 0x31, 0x00, 0x00, 0x00, 0xc7, 0x68, 0x65, 0x76, 0x31, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x04,
@ -306,12 +220,18 @@ func TestInitMarshal(t *testing.T) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x18, 0xff, 0xff, 0x00, 0x00, 0x00, 0x2d, 0x61, 0x18, 0xff, 0xff, 0x00, 0x00, 0x00, 0x5d, 0x68,
0x76, 0x63, 0x43, 0x01, 0x42, 0xc0, 0x28, 0x03, 0x76, 0x63, 0x43, 0x01, 0x01, 0x60, 0x00, 0x00,
0x01, 0x00, 0x19, 0x67, 0x42, 0xc0, 0x28, 0xd9, 0x00, 0x03, 0x00, 0x90, 0x00, 0x00, 0x03, 0x78,
0x00, 0x78, 0x02, 0x27, 0xe5, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0xf0, 0x13, 0x03, 0x20, 0x00, 0x01, 0x00, 0x04, 0x01,
0x3c, 0x60, 0xc9, 0x20, 0x01, 0x00, 0x01, 0x08, 0x02, 0x03, 0x04, 0x21, 0x00, 0x01, 0x00, 0x2a,
0x42, 0x01, 0x01, 0x01, 0x60, 0x00, 0x00, 0x03,
0x00, 0x90, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03,
0x00, 0x78, 0xa0, 0x03, 0xc0, 0x80, 0x10, 0xe5,
0x96, 0x66, 0x69, 0x24, 0xca, 0xe0, 0x10, 0x00,
0x00, 0x03, 0x00, 0x10, 0x00, 0x00, 0x03, 0x01,
0xe0, 0x80, 0x22, 0x00, 0x01, 0x00, 0x01, 0x08,
0x00, 0x00, 0x00, 0x14, 0x62, 0x74, 0x72, 0x74, 0x00, 0x00, 0x00, 0x14, 0x62, 0x74, 0x72, 0x74,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x42, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x42, 0x40,
0x00, 0x0f, 0x42, 0x40, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0f, 0x42, 0x40, 0x00, 0x00, 0x00, 0x10,
@ -328,24 +248,32 @@ func TestInitMarshal(t *testing.T) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
}, byts) },
}) Init{
t.Run("audio only", func(t *testing.T) {
init := &Init{
Tracks: []*InitTrack{ Tracks: []*InitTrack{
{ {
ID: 1, ID: 1,
TimeScale: uint32(testAudioTrack.ClockRate()), TimeScale: 90000,
Format: testAudioTrack, Format: &format.H265{
PayloadTyp: 96,
VPS: []byte{0x01, 0x02, 0x03, 0x04},
SPS: []byte{
0x42, 0x01, 0x01, 0x01, 0x60, 0x00, 0x00, 0x03,
0x00, 0x90, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03,
0x00, 0x78, 0xa0, 0x03, 0xc0, 0x80, 0x10, 0xe5,
0x96, 0x66, 0x69, 0x24, 0xca, 0xe0, 0x10, 0x00,
0x00, 0x03, 0x00, 0x10, 0x00, 0x00, 0x03, 0x01,
0xe0, 0x80,
}, },
PPS: []byte{0x08},
}, },
} },
},
byts, err := init.Marshal() },
require.NoError(t, err) },
{
require.Equal(t, []byte{ "mpeg4audio",
[]byte{
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20,
'f', 't', 'y', 'p', 'f', 't', 'y', 'p',
0x6d, 0x70, 0x34, 0x32, 0x00, 0x00, 0x00, 0x01, 0x6d, 0x70, 0x34, 0x32, 0x00, 0x00, 0x00, 0x01,
@ -444,12 +372,319 @@ func TestInitMarshal(t *testing.T) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
}, byts) },
Init{
Tracks: []*InitTrack{
{
ID: 1,
TimeScale: uint32(testAudioTrack.ClockRate()),
Format: testAudioTrack,
},
},
},
},
{
"opus",
[]byte{
0x00, 0x00, 0x00, 0x20,
'f', 't', 'y', 'p',
0x6d, 0x70, 0x34, 0x32, 0x00, 0x00, 0x00, 0x01,
0x6d, 0x70, 0x34, 0x31, 0x6d, 0x70, 0x34, 0x32,
0x69, 0x73, 0x6f, 0x6d, 0x68, 0x6c, 0x73, 0x66,
0x00, 0x00, 0x02, 0x38,
'm', 'o', 'o', 'v',
0x00, 0x00, 0x00, 0x6c,
'm', 'v', 'h', 'd',
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe8,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x01, 0x9c,
0x74, 0x72, 0x61, 0x6b, 0x00, 0x00, 0x00, 0x5c,
0x74, 0x6b, 0x68, 0x64, 0x00, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x38, 0x6d, 0x64, 0x69, 0x61,
0x00, 0x00, 0x00, 0x20, 0x6d, 0x64, 0x68, 0x64,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbb, 0x80,
0x00, 0x00, 0x00, 0x00, 0x55, 0xc4, 0x00, 0x00,
0x00, 0x00, 0x00, 0x2d, 0x68, 0x64, 0x6c, 0x72,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x73, 0x6f, 0x75, 0x6e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x53, 0x6f, 0x75, 0x6e, 0x64, 0x48, 0x61, 0x6e,
0x64, 0x6c, 0x65, 0x72, 0x00, 0x00, 0x00, 0x00,
0xe3, 0x6d, 0x69, 0x6e, 0x66, 0x00, 0x00, 0x00,
0x10, 0x73, 0x6d, 0x68, 0x64, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x24, 0x64, 0x69, 0x6e, 0x66, 0x00, 0x00, 0x00,
0x1c, 0x64, 0x72, 0x65, 0x66, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x0c, 0x75, 0x72, 0x6c, 0x20, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0xa7, 0x73, 0x74, 0x62,
0x6c, 0x00, 0x00, 0x00, 0x5b, 0x73, 0x74, 0x73,
0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x4b, 0x4f, 0x70, 0x75,
0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x02, 0x00, 0x10, 0x00, 0x00, 0x00,
0x00, 0xbb, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x13, 0x64, 0x4f, 0x70, 0x73, 0x00, 0x02, 0x01,
0x38, 0x00, 0x00, 0xbb, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x14, 0x62, 0x74, 0x72, 0x74,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf7, 0x39,
0x00, 0x01, 0xf7, 0x39, 0x00, 0x00, 0x00, 0x10,
0x73, 0x74, 0x74, 0x73, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
0x73, 0x74, 0x73, 0x63, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14,
0x73, 0x74, 0x73, 0x7a, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x10, 0x73, 0x74, 0x63, 0x6f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x28, 0x6d, 0x76, 0x65, 0x78,
0x00, 0x00, 0x00, 0x20, 0x74, 0x72, 0x65, 0x78,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
Init{
Tracks: []*InitTrack{
{
ID: 1,
TimeScale: 48000,
Format: &format.Opus{
PayloadTyp: 96,
SampleRate: 48000,
ChannelCount: 2,
},
},
},
},
},
{
"h264 + mpeg4audio",
[]byte{
0x00, 0x00, 0x00, 0x20,
'f', 't', 'y', 'p',
0x6d, 0x70, 0x34, 0x32, 0x00, 0x00, 0x00, 0x01,
0x6d, 0x70, 0x34, 0x31, 0x6d, 0x70, 0x34, 0x32,
0x69, 0x73, 0x6f, 0x6d, 0x68, 0x6c, 0x73, 0x66,
0x00, 0x00, 0x04, 0x64,
'm', 'o', 'o', 'v',
0x00, 0x00, 0x00, 0x6c,
'm', 'v', 'h', 'd',
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe8,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x01, 0xec,
't', 'r', 'a', 'k',
0x00, 0x00, 0x00, 0x5c,
't', 'k', 'h', 'd',
0x00, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x07, 0x80, 0x00, 0x00, 0x04, 0x38, 0x00, 0x00,
0x00, 0x00, 0x01, 0x88,
'm', 'd', 'i', 'a',
0x00, 0x00, 0x00, 0x20,
'm', 'd', 'h', 'd',
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x5f, 0x90,
0x00, 0x00, 0x00, 0x00, 0x55, 0xc4, 0x00, 0x00,
0x00, 0x00, 0x00, 0x2d,
'h', 'd', 'l', 'r',
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x76, 0x69, 0x64, 0x65, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x56, 0x69, 0x64, 0x65, 0x6f, 0x48, 0x61, 0x6e,
0x64, 0x6c, 0x65, 0x72, 0x00, 0x00, 0x00, 0x01,
0x33,
'm', 'i', 'n', 'f',
0x00, 0x00, 0x00, 0x14,
'v', 'm', 'h', 'd',
0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x24, 0x64, 0x69, 0x6e,
0x66, 0x00, 0x00, 0x00, 0x1c, 0x64, 0x72, 0x65,
0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x0c, 0x75, 0x72, 0x6c,
0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0xf3, 0x73, 0x74, 0x62, 0x6c, 0x00, 0x00, 0x00,
0xa7, 0x73, 0x74, 0x73, 0x64, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x97, 0x61, 0x76, 0x63, 0x31, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x04,
0x38, 0x00, 0x48, 0x00, 0x00, 0x00, 0x48, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x18, 0xff, 0xff, 0x00, 0x00, 0x00, 0x2d, 0x61,
0x76, 0x63, 0x43, 0x01, 0x42, 0xc0, 0x28, 0x03,
0x01, 0x00, 0x19, 0x67, 0x42, 0xc0, 0x28, 0xd9,
0x00, 0x78, 0x02, 0x27, 0xe5, 0x84, 0x00, 0x00,
0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0xf0,
0x3c, 0x60, 0xc9, 0x20, 0x01, 0x00, 0x01, 0x08,
0x00, 0x00, 0x00, 0x14, 0x62, 0x74, 0x72, 0x74,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x42, 0x40,
0x00, 0x0f, 0x42, 0x40, 0x00, 0x00, 0x00, 0x10,
0x73, 0x74, 0x74, 0x73, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
0x73, 0x74, 0x73, 0x63, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14,
0x73, 0x74, 0x73, 0x7a, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x10, 0x73, 0x74, 0x63, 0x6f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0xbc,
't', 'r', 'a', 'k',
0x00, 0x00, 0x00, 0x5c,
't', 'k', 'h', 'd',
0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x58,
'm', 'd', 'i', 'a',
0x00, 0x00, 0x00, 0x20,
'm', 'd', 'h', 'd',
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xac, 0x44, 0x00, 0x00, 0x00, 0x00,
0x55, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d,
'h', 'd', 'l', 'r',
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x73, 0x6f, 0x75, 0x6e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x53, 0x6f, 0x75, 0x6e,
0x64, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72,
0x00, 0x00, 0x00, 0x01, 0x03, 0x6d, 0x69, 0x6e,
0x66, 0x00, 0x00, 0x00, 0x10,
's', 'm', 'h', 'd',
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x24, 0x64, 0x69, 0x6e,
0x66, 0x00, 0x00, 0x00, 0x1c, 0x64, 0x72, 0x65,
0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x0c, 0x75, 0x72, 0x6c,
0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0xc7, 0x73, 0x74, 0x62, 0x6c, 0x00, 0x00, 0x00,
0x7b, 0x73, 0x74, 0x73, 0x64, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x6b, 0x6d, 0x70, 0x34, 0x61, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
0x10, 0x00, 0x00, 0x00, 0x00, 0xac, 0x44, 0x00,
0x00, 0x00, 0x00, 0x00, 0x33, 0x65, 0x73, 0x64,
0x73, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x80,
0x80, 0x22, 0x00, 0x02, 0x00, 0x04, 0x80, 0x80,
0x80, 0x14, 0x40, 0x15, 0x00, 0x00, 0x00, 0x00,
0x01, 0xf7, 0x39, 0x00, 0x01, 0xf7, 0x39, 0x05,
0x80, 0x80, 0x80, 0x02, 0x12, 0x10, 0x06, 0x80,
0x80, 0x80, 0x01, 0x02, 0x00, 0x00, 0x00, 0x14,
0x62, 0x74, 0x72, 0x74, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xf7, 0x39, 0x00, 0x01, 0xf7, 0x39,
0x00, 0x00, 0x00, 0x10, 0x73, 0x74, 0x74, 0x73,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x10, 0x73, 0x74, 0x73, 0x63,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x14, 0x73, 0x74, 0x73, 0x7a,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
0x73, 0x74, 0x63, 0x6f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48,
0x6d, 0x76, 0x65, 0x78, 0x00, 0x00, 0x00, 0x20,
0x74, 0x72, 0x65, 0x78, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
0x74, 0x72, 0x65, 0x78, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
},
Init{
Tracks: []*InitTrack{
{
ID: 1,
TimeScale: 90000,
Format: testVideoTrack,
},
{
ID: 2,
TimeScale: uint32(testAudioTrack.ClockRate()),
Format: testAudioTrack,
},
},
},
},
}
func TestInitMarshal(t *testing.T) {
for _, ca := range casesInit {
t.Run(ca.name, func(t *testing.T) {
byts, err := ca.dec.Marshal()
require.NoError(t, err)
require.Equal(t, ca.enc, byts)
}) })
}
} }
func TestInitUnmarshal(t *testing.T) { func TestInitUnmarshal(t *testing.T) {
t.Run("video", func(t *testing.T) { for _, ca := range casesInit {
t.Run(ca.name, func(t *testing.T) {
var init Init
err := init.Unmarshal(ca.enc)
require.NoError(t, err)
require.Equal(t, ca.dec, init)
})
}
}
func TestInitUnmarshalExternal(t *testing.T) {
t.Run("h264", func(t *testing.T) {
byts := []byte{ byts := []byte{
0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x1c,
'f', 't', 'y', 'p', 'f', 't', 'y', 'p',
@ -487,13 +722,15 @@ func TestInitUnmarshal(t *testing.T) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x40, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00,
0x02, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x01, 0x92, 0x02, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x01, 0x92,
0x6d, 0x64, 0x69, 0x61, 0x00, 0x00, 0x00, 0x20, 'm', 'd', 'i', 'a',
0x00, 0x00, 0x00, 0x20,
'm', 'd', 'h', 'd', 'm', 'd', 'h', 'd',
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x98, 0x96, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x98, 0x96, 0x80, 0x00, 0x00, 0x00, 0x00,
0x55, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x55, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38,
0x68, 0x64, 0x6c, 0x72, 0x00, 0x00, 0x00, 0x00, 'h', 'd', 'l', 'r',
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x76, 0x69, 0x64, 0x65, 0x00, 0x00, 0x00, 0x00, 0x76, 0x69, 0x64, 0x65,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x42, 0x72, 0x6f, 0x61, 0x00, 0x00, 0x00, 0x00, 0x42, 0x72, 0x6f, 0x61,
@ -575,7 +812,7 @@ func TestInitUnmarshal(t *testing.T) {
}, init) }, init)
}) })
t.Run("audio", func(t *testing.T) { t.Run("mpeg4audio", func(t *testing.T) {
byts := []byte{ byts := []byte{
0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x18,
'f', 't', 'y', 'p', 'f', 't', 'y', 'p',
@ -612,13 +849,15 @@ func TestInitUnmarshal(t *testing.T) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x43, 0x6d, 0x64, 0x69, 0x61, 0x00, 0x00, 0x01, 0x43,
'm', 'd', 'i', 'a',
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20,
'm', 'd', 'h', 'd', 'm', 'd', 'h', 'd',
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x98, 0x96, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x98, 0x96, 0x80,
0x00, 0x00, 0x00, 0x00, 0x55, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xc4, 0x00, 0x00,
0x00, 0x00, 0x00, 0x38, 0x68, 0x64, 0x6c, 0x72, 0x00, 0x00, 0x00, 0x38,
'h', 'd', 'l', 'r',
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x73, 0x6f, 0x75, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x73, 0x6f, 0x75, 0x6e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

Loading…
Cancel
Save