mpeg4audio: support all ADTS profiles (#275)

ADTS supports profiles 0-3 per ISO 14496-3, mapping to ObjectType 1-4.
Previously only ObjectType 2 (AAC-LC) was accepted, rejecting valid
streams with AAC Main (1), AAC SSR (3), or AAC LTP (4).

---------

Co-authored-by: aler9 <46489434+aler9@users.noreply.github.com>
This commit is contained in:
John Mylchreest
2025-12-21 15:45:39 +00:00
committed by GitHub
parent f3d78c9dc8
commit f84899af51
2 changed files with 19 additions and 5 deletions

View File

@@ -38,12 +38,9 @@ func (ps *ADTSPackets) Unmarshal(buf []byte) error {
pkt := &ADTSPacket{}
// ADTS profile (2 bits) maps to ObjectType = profile + 1
// All profiles 0-3 are valid per ISO 14496-3
pkt.Type = ObjectType((buf[pos+2] >> 6) + 1)
switch pkt.Type {
case ObjectTypeAACLC:
default:
return fmt.Errorf("unsupported audio type: %d", pkt.Type)
}
sampleRateIndex := (buf[pos+2] >> 2) & 0x0F
switch {
@@ -114,6 +111,11 @@ func (ps ADTSPackets) Marshal() ([]byte, error) {
pos := 0
for _, pkt := range ps {
// ADTS only supports ObjectType 1-4 (profile 0-3)
if pkt.Type < 1 || pkt.Type > 4 {
return nil, fmt.Errorf("ADTS only supports ObjectType 1-4, got %d", pkt.Type)
}
sampleRateIndex, ok := reverseSampleRates[pkt.SampleRate]
if !ok {
return nil, fmt.Errorf("invalid sample rate: %d", pkt.SampleRate)

View File

@@ -45,6 +45,18 @@ var casesADTS = []struct {
},
},
},
{
"aac-ssr",
[]byte{0xff, 0xf1, 0x8c, 0x80, 0x1, 0x3f, 0xfc, 0xaa, 0xbb},
ADTSPackets{
{
Type: 3,
SampleRate: 48000,
ChannelCount: 2,
AU: []byte{0xaa, 0xbb},
},
},
},
}
func TestADTSUnmarshal(t *testing.T) {