Files
gortsplib/pkg/formatdecenc/rtpmpeg4audio/decoder_test.go
2022-12-11 22:56:59 +01:00

805 lines
20 KiB
Go

package rtpmpeg4audio
import (
"bytes"
"testing"
"time"
"github.com/pion/rtp"
"github.com/stretchr/testify/require"
"github.com/aler9/gortsplib/v2/pkg/mpeg4audio"
)
func mergeBytes(vals ...[]byte) []byte {
size := 0
for _, v := range vals {
size += len(v)
}
res := make([]byte, size)
pos := 0
for _, v := range vals {
n := copy(res[pos:], v)
pos += n
}
return res
}
var cases = []struct {
name string
sizeLength int
indexLength int
indexDeltaLength int
aus [][]byte
pts time.Duration
pkts []*rtp.Packet
}{
{
"single",
13,
3,
3,
[][]byte{
{
0x21, 0x1a, 0xd4, 0xf5, 0x9e, 0x20, 0xc5, 0x42,
0x89, 0x40, 0xa2, 0x9b, 0x3c, 0x94, 0xdd, 0x28,
0x94, 0x48, 0xd5, 0x8b, 0xb0, 0x2, 0xdb, 0x1b,
0xeb, 0xe0, 0xfa, 0x9f, 0xea, 0x91, 0xa7, 0x3,
0xe8, 0x6b, 0xe5, 0x5, 0x95, 0x6, 0x62, 0x88,
0x13, 0xa, 0x15, 0xa0, 0xeb, 0xef, 0x40, 0x82,
0xdf, 0x49, 0xf2, 0xe0, 0x26, 0xfc, 0x52, 0x5b,
0x6c, 0x2a, 0x2d, 0xe8, 0xa5, 0x70, 0xc5, 0xaf,
0xfc, 0x98, 0x9a, 0x2f, 0x1f, 0xbb, 0xa2, 0xcb,
0xb8, 0x26, 0xb6, 0x6e, 0x4c, 0x15, 0x6c, 0x21,
0x3d, 0x35, 0xf6, 0xcf, 0xa4, 0x3b, 0x72, 0x26,
0xe1, 0x3a, 0x3a, 0x99, 0xd8, 0x2d, 0x6a, 0x22,
0xcd, 0x97, 0xa, 0xef, 0x52, 0x9c, 0x5f, 0xcd,
0x5c, 0xd9, 0xd3, 0x12, 0x7e, 0x45, 0x45, 0xb3,
0x24, 0xef, 0xd3, 0x4f, 0x2f, 0x96, 0xd9, 0x8b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0xd, 0xc0, 0x15, 0xf, 0xd2, 0xc3, 0x72, 0x4d,
0x6e, 0x4f, 0x8e, 0x6d, 0x64, 0xdc, 0x64, 0x1f,
0x33, 0x53, 0x4e, 0xd8, 0xa4, 0x74, 0xf3, 0x33,
0x4, 0x68, 0xd9, 0x92, 0xf3, 0x6e, 0xb7, 0x5b,
0xe6, 0xf6, 0xc3, 0x55, 0x14, 0x54, 0x87, 0x0,
0xaf, 0x7,
},
},
20 * time.Millisecond,
[]*rtp.Packet{
{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 96,
SequenceNumber: 17645,
Timestamp: 2289527317,
SSRC: 0x9dbb7812,
},
Payload: []byte{
0x00, 0x10, 0x0a, 0xd8,
0x21, 0x1a, 0xd4, 0xf5, 0x9e, 0x20, 0xc5, 0x42,
0x89, 0x40, 0xa2, 0x9b, 0x3c, 0x94, 0xdd, 0x28,
0x94, 0x48, 0xd5, 0x8b, 0xb0, 0x02, 0xdb, 0x1b,
0xeb, 0xe0, 0xfa, 0x9f, 0xea, 0x91, 0xa7, 0x03,
0xe8, 0x6b, 0xe5, 0x05, 0x95, 0x06, 0x62, 0x88,
0x13, 0x0a, 0x15, 0xa0, 0xeb, 0xef, 0x40, 0x82,
0xdf, 0x49, 0xf2, 0xe0, 0x26, 0xfc, 0x52, 0x5b,
0x6c, 0x2a, 0x2d, 0xe8, 0xa5, 0x70, 0xc5, 0xaf,
0xfc, 0x98, 0x9a, 0x2f, 0x1f, 0xbb, 0xa2, 0xcb,
0xb8, 0x26, 0xb6, 0x6e, 0x4c, 0x15, 0x6c, 0x21,
0x3d, 0x35, 0xf6, 0xcf, 0xa4, 0x3b, 0x72, 0x26,
0xe1, 0x3a, 0x3a, 0x99, 0xd8, 0x2d, 0x6a, 0x22,
0xcd, 0x97, 0x0a, 0xef, 0x52, 0x9c, 0x5f, 0xcd,
0x5c, 0xd9, 0xd3, 0x12, 0x7e, 0x45, 0x45, 0xb3,
0x24, 0xef, 0xd3, 0x4f,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, 0x50, 0xb6, 0x95, 0x44,
0x1a, 0x0d, 0xc0, 0x15, 0x0f, 0xd2, 0xc3, 0x72,
0x4d, 0x6e, 0x4f, 0x8e, 0x6d, 0x64, 0xdc, 0x64,
0x1f, 0x33, 0x53, 0x4e, 0xd8, 0xa4, 0x74, 0xf3,
0x33, 0x04, 0x68, 0xd9, 0x92, 0xf3, 0x6e, 0xb7,
0x5b, 0xe6, 0xf6, 0xc3, 0x55, 0x14, 0x54, 0x87,
0x00, 0xaf, 0x07,
},
},
},
},
{
"aggregated",
13,
3,
3,
[][]byte{
{0x00, 0x01, 0x02, 0x03},
{0x04, 0x05, 0x06, 0x07},
{0x08, 0x09, 0x0A, 0x0B},
},
0,
[]*rtp.Packet{
{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 96,
SequenceNumber: 17645,
Timestamp: 2289526357,
SSRC: 0x9dbb7812,
},
Payload: []byte{
0x0, 0x30, 0x0, 0x20,
0x0, 0x20, 0x0, 0x20, 0x0, 0x1, 0x2, 0x3,
0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb,
},
},
},
},
{
"fragmented",
13,
3,
3,
[][]byte{
bytes.Repeat([]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, 512),
},
0,
[]*rtp.Packet{ //nolint:dupl
{
Header: rtp.Header{
Version: 2,
Marker: false,
PayloadType: 96,
SequenceNumber: 17645,
Timestamp: 2289526357,
SSRC: 0x9dbb7812,
},
Payload: mergeBytes(
[]byte{0x0, 0x10, 0x2d, 0x80},
bytes.Repeat([]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, 182),
),
},
{
Header: rtp.Header{
Version: 2,
Marker: false,
PayloadType: 96,
SequenceNumber: 17646,
Timestamp: 2289526357,
SSRC: 0x9dbb7812,
},
Payload: mergeBytes(
[]byte{0x00, 0x10, 0x2d, 0x80},
bytes.Repeat([]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, 182),
),
},
{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 96,
SequenceNumber: 17647,
Timestamp: 2289526357,
SSRC: 0x9dbb7812,
},
Payload: mergeBytes(
[]byte{0x00, 0x10, 0x25, 0x00},
bytes.Repeat([]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, 148),
),
},
},
},
{
"aggregated followed by fragmented",
13,
3,
3,
[][]byte{
{0x00, 0x01, 0x02, 0x03},
{0x04, 0x05, 0x06, 0x07},
{0x08, 0x09, 0x0A, 0x0B},
bytes.Repeat([]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, 256),
},
0,
[]*rtp.Packet{
{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 96,
SequenceNumber: 17645,
Timestamp: 2289526357,
SSRC: 0x9dbb7812,
},
Payload: []byte{
0x0, 0x30, 0x0, 0x20,
0x0, 0x20, 0x0, 0x20, 0x0, 0x1, 0x2, 0x3,
0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb,
},
},
{
Header: rtp.Header{
Version: 2,
Marker: false,
PayloadType: 96,
SequenceNumber: 17646,
Timestamp: 2289529429,
SSRC: 0x9dbb7812,
},
Payload: mergeBytes(
[]byte{0x0, 0x10, 0x2d, 0x80},
bytes.Repeat([]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, 182),
),
},
{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 96,
SequenceNumber: 17647,
Timestamp: 2289529429,
SSRC: 0x9dbb7812,
},
Payload: mergeBytes(
[]byte{0x00, 0x10, 0x12, 0x80},
bytes.Repeat([]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, 74),
),
},
},
},
{
"single, custom sized",
6,
2,
2,
[][]byte{
{0x01, 0x02, 0x03, 0x04},
},
20 * time.Millisecond,
[]*rtp.Packet{
{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 96,
SequenceNumber: 17645,
Timestamp: 2289527317,
SSRC: 0x9dbb7812,
},
Payload: []byte{
0x00, 0x08, 0x10,
0x01, 0x02, 0x03, 0x04,
},
},
},
},
{
"single, custom sized, padded",
13,
0,
0,
[][]byte{
{0x01, 0x02, 0x03, 0x04},
},
20 * time.Millisecond,
[]*rtp.Packet{
{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 96,
SequenceNumber: 17645,
Timestamp: 2289527317,
SSRC: 0x9dbb7812,
},
Payload: []byte{
0x00, 0x0d, 0x00, 0x20,
0x01, 0x02, 0x03, 0x04,
},
},
},
},
{
"aggregated, custom sized, padded",
13,
0,
0,
[][]byte{
{0x01, 0x02, 0x03, 0x04},
{0x05, 0x06, 0x07, 0x08},
},
20 * time.Millisecond,
[]*rtp.Packet{
{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 96,
SequenceNumber: 17645,
Timestamp: 2289527317,
SSRC: 0x9dbb7812,
},
Payload: []byte{
0x00, 0x1a, 0x00, 0x20, 0x01, 0x00,
0x01, 0x02, 0x03, 0x04,
0x05, 0x06, 0x07, 0x08,
},
},
},
},
{
"fragmented, custom sized",
21,
3,
3,
[][]byte{
bytes.Repeat([]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, 512),
},
20 * time.Millisecond,
[]*rtp.Packet{
{
Header: rtp.Header{
Version: 2,
Marker: false,
PayloadType: 96,
SequenceNumber: 17645,
Timestamp: 2289527317,
SSRC: 0x9dbb7812,
},
Payload: mergeBytes(
[]byte{0x0, 0x18, 0x00, 0x2d, 0x78},
bytes.Repeat([]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, 181),
[]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06},
),
},
{
Header: rtp.Header{
Version: 2,
Marker: false,
PayloadType: 96,
SequenceNumber: 17646,
Timestamp: 2289527317,
SSRC: 0x9dbb7812,
},
Payload: mergeBytes(
[]byte{0x00, 0x18, 0x00, 0x2d, 0x78, 0x07},
bytes.Repeat([]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, 181),
[]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05},
),
},
{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 96,
SequenceNumber: 17647,
Timestamp: 2289527317,
SSRC: 0x9dbb7812,
},
Payload: mergeBytes(
[]byte{0x00, 0x18, 0x00, 0x25, 0x10, 0x06, 0x07},
bytes.Repeat([]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, 148),
),
},
},
},
{
"fragmented, custom sized, padded",
13,
0,
0,
[][]byte{
bytes.Repeat([]byte{0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, 512),
},
20 * time.Millisecond,
[]*rtp.Packet{ //nolint:dupl
{
Header: rtp.Header{
Version: 2,
Marker: false,
PayloadType: 96,
SequenceNumber: 17645,
Timestamp: 2289527317,
SSRC: 0x9dbb7812,
},
Payload: mergeBytes(
[]byte{0x0, 0x0d, 0x2d, 0x80},
bytes.Repeat([]byte{0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, 182),
),
},
{
Header: rtp.Header{
Version: 2,
Marker: false,
PayloadType: 96,
SequenceNumber: 17646,
Timestamp: 2289527317,
SSRC: 0x9dbb7812,
},
Payload: mergeBytes(
[]byte{0x0, 0x0d, 0x2d, 0x80},
bytes.Repeat([]byte{0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, 182),
),
},
{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 96,
SequenceNumber: 17647,
Timestamp: 2289527317,
SSRC: 0x9dbb7812,
},
Payload: mergeBytes(
[]byte{0x00, 0x0d, 0x25, 0x00},
bytes.Repeat([]byte{0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, 148),
),
},
},
},
}
func TestDecode(t *testing.T) {
for _, ca := range cases {
t.Run(ca.name, func(t *testing.T) {
d := &Decoder{
SampleRate: 48000,
SizeLength: ca.sizeLength,
IndexLength: ca.indexLength,
IndexDeltaLength: ca.indexDeltaLength,
}
d.Init()
// send an initial packet downstream
// in order to compute the right timestamp,
// that is relative to the initial packet
pkt := rtp.Packet{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 96,
SequenceNumber: 17645,
Timestamp: 2289526357,
SSRC: 0x9dbb7812,
},
}
switch {
case ca.sizeLength == 13 && ca.indexLength == 3:
pkt.Payload = []byte{0x00, 0x10, 0x00, 0x08, 0x0}
case ca.sizeLength == 13 && ca.indexLength == 0:
pkt.Payload = []byte{0x00, 0x0d, 0x00, 0x08, 0x0}
case ca.sizeLength == 6:
pkt.Payload = []byte{0x00, 0x08, 0x04, 0x0}
case ca.sizeLength == 21:
pkt.Payload = []byte{0x00, 0x18, 0x00, 0x0, 0x08, 0x00}
}
_, _, err := d.Decode(&pkt)
require.NoError(t, err)
var aus [][]byte
expPTS := ca.pts
for _, pkt := range ca.pkts {
clone := pkt.Clone()
addAUs, pts, err := d.Decode(pkt)
if err == ErrMorePacketsNeeded {
continue
}
require.NoError(t, err)
require.Equal(t, expPTS, pts)
aus = append(aus, addAUs...)
expPTS += time.Duration(len(aus)) * mpeg4audio.SamplesPerAccessUnit * time.Second / 48000
// test input integrity
require.Equal(t, clone, pkt)
}
require.Equal(t, ca.aus, aus)
})
}
}
func TestDecodeADTS(t *testing.T) {
d := &Decoder{
SampleRate: 16000,
SizeLength: 13,
IndexLength: 3,
IndexDeltaLength: 3,
}
d.Init()
for i := 0; i < 2; i++ {
aus, _, err := d.Decode(&rtp.Packet{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 96,
SequenceNumber: 17645,
Timestamp: 2289526357,
SSRC: 0x9dbb7812,
},
Payload: []byte{
0x00, 0x10, 0x00, 0x09 << 3,
0xff, 0xf1, 0x4c, 0x80, 0x1, 0x3f, 0xfc, 0xaa, 0xbb,
},
})
require.NoError(t, err)
require.Equal(t, [][]byte{{0xaa, 0xbb}}, aus)
}
}
func TestDecodeErrors(t *testing.T) {
for _, ca := range []struct {
name string
pkts []*rtp.Packet
err string
}{
{
"missing payload",
[]*rtp.Packet{
{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 0x60,
SequenceNumber: 0x44ed,
Timestamp: 0x88776a15,
SSRC: 0x9dbb7812,
},
},
},
"payload is too short",
},
{
"missing au header",
[]*rtp.Packet{
{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 0x60,
SequenceNumber: 0x44ed,
Timestamp: 0x88776a15,
SSRC: 0x9dbb7812,
},
Payload: []byte{0x00, 0x10},
},
},
"not enough bits",
},
{
"missing au",
[]*rtp.Packet{
{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 0x60,
SequenceNumber: 0x44ed,
Timestamp: 0x88776a15,
SSRC: 0x9dbb7812,
},
Payload: []byte{0x00, 0x10, 0x0a, 0xd8},
},
},
"payload is too short",
},
{
"invalid au headers length",
[]*rtp.Packet{
{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 0x60,
SequenceNumber: 0x44ed,
Timestamp: 0x88776a15,
SSRC: 0x9dbb7812,
},
Payload: []byte{0x00, 0x00},
},
},
"invalid AU-headers-length",
},
{
"au index not zero",
[]*rtp.Packet{
{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 0x60,
SequenceNumber: 0x44ed,
Timestamp: 0x88776a15,
SSRC: 0x9dbb7812,
},
Payload: []byte{0x00, 0x10, 0x0a, 0xd9},
},
},
"AU-index different than zero is not supported",
},
{
"au index delta not zero",
[]*rtp.Packet{
{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 0x60,
SequenceNumber: 0x44ed,
Timestamp: 0x88776a15,
SSRC: 0x9dbb7812,
},
Payload: []byte{0x00, 0x20, 0x00, 0x08, 0x0a, 0xd9},
},
},
"AU-index-delta different than zero is not supported",
},
{
"fragmented with multiple AUs in 1st packet",
[]*rtp.Packet{
{
Header: rtp.Header{
Version: 2,
Marker: false,
PayloadType: 0x60,
SequenceNumber: 0xea2,
Timestamp: 0x88776a15,
SSRC: 0x9dbb7812,
},
Payload: []byte{0x00, 0x20, 0x00, 0x08, 0x00, 0x08},
},
},
"a fragmented packet can only contain one AU",
},
{
"fragmented with no payload in 1st packet",
[]*rtp.Packet{
{
Header: rtp.Header{
Version: 2,
Marker: false,
PayloadType: 0x60,
SequenceNumber: 0x44ed,
Timestamp: 0x88776a15,
SSRC: 0x9dbb7812,
},
Payload: []byte{0x00, 0x10, 0x0a, 0xd8},
},
},
"payload is too short",
},
{
"fragmented with multiple AUs in 2nd packet",
[]*rtp.Packet{
{
Header: rtp.Header{
Version: 2,
Marker: false,
PayloadType: 0x60,
SequenceNumber: 0x44ed,
Timestamp: 0x88776a15,
SSRC: 0x9dbb7812,
},
Payload: mergeBytes(
[]byte{0x0, 0x10, 0x2d, 0x80},
bytes.Repeat([]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, 182),
),
},
{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 0x60,
SequenceNumber: 0x44ee,
Timestamp: 0x88776a15,
SSRC: 0x9dbb7812,
},
Payload: mergeBytes(
[]byte{0x0, 0x20, 0x00, 0x08, 0x00, 0x08},
),
},
},
"a fragmented packet can only contain one AU",
},
{
"fragmented with no payload in 2nd packet",
[]*rtp.Packet{
{
Header: rtp.Header{
Version: 2,
Marker: false,
PayloadType: 0x60,
SequenceNumber: 0x44ed,
Timestamp: 0x88776a15,
SSRC: 0x9dbb7812,
},
Payload: mergeBytes(
[]byte{0x0, 0x10, 0x2d, 0x80},
bytes.Repeat([]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, 182),
),
},
{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 0x60,
SequenceNumber: 0x44ee,
Timestamp: 0x88776a15,
SSRC: 0x9dbb7812,
},
Payload: []byte{0x00, 0x10, 0x0a, 0xd8},
},
},
"payload is too short",
},
} {
t.Run(ca.name, func(t *testing.T) {
d := &Decoder{
SampleRate: 48000,
SizeLength: 13,
IndexLength: 3,
IndexDeltaLength: 3,
}
d.Init()
var lastErr error
for _, pkt := range ca.pkts {
_, _, lastErr = d.Decode(pkt)
}
require.EqualError(t, lastErr, ca.err)
})
}
}