add aac utilities

This commit is contained in:
aler9
2021-09-23 20:19:11 +02:00
parent 13c6b69d30
commit 321fe06c6d
7 changed files with 213 additions and 7 deletions

68
pkg/aac/adts_test.go Normal file
View File

@@ -0,0 +1,68 @@
package aac
import (
"testing"
"github.com/stretchr/testify/require"
)
var casesADTS = []struct {
name string
byts []byte
pkts []*ADTSPacket
}{
{
"single",
[]byte{0xff, 0xf1, 0x4c, 0x80, 0x1, 0x3f, 0xfc, 0xaa, 0xbb},
[]*ADTSPacket{
{
Type: 2,
SampleRate: 48000,
ChannelCount: 2,
AU: []byte{0xaa, 0xbb},
},
},
},
{
"multiple",
[]byte{
0xff, 0xf1, 0x50, 0x40, 0x1, 0x3f, 0xfc, 0xaa,
0xbb, 0xff, 0xf1, 0x4c, 0x80, 0x1, 0x3f, 0xfc,
0xcc, 0xdd,
},
[]*ADTSPacket{
{
Type: 2,
SampleRate: 44100,
ChannelCount: 1,
AU: []byte{0xaa, 0xbb},
},
{
Type: 2,
SampleRate: 48000,
ChannelCount: 2,
AU: []byte{0xcc, 0xdd},
},
},
},
}
func TestDecodeADTS(t *testing.T) {
for _, ca := range casesADTS {
t.Run(ca.name, func(t *testing.T) {
pkts, err := DecodeADTS(ca.byts)
require.NoError(t, err)
require.Equal(t, ca.pkts, pkts)
})
}
}
func TestEncodeADTS(t *testing.T) {
for _, ca := range casesADTS {
t.Run(ca.name, func(t *testing.T) {
byts, err := EncodeADTS(ca.pkts)
require.NoError(t, err)
require.Equal(t, ca.byts, byts)
})
}
}