mirror of
https://github.com/bluenviron/mediacommon.git
synced 2025-12-24 13:17:52 +08:00
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:
@@ -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)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user