mpeg4audio: fix regression due to #219 (#223)

This commit is contained in:
Alessandro Ros
2025-07-20 10:59:46 +02:00
committed by GitHub
parent db1f43505f
commit 8bb48d4469
2 changed files with 30 additions and 11 deletions

View File

@@ -22,6 +22,7 @@ type AudioSpecificConfig struct {
ExtensionType ObjectType
ExtensionSampleRate int
// GASpecificConfig
FrameLengthFlag bool
DependsOnCoreCoder bool
CoreCoderDelay uint16
@@ -35,15 +36,6 @@ func (c *AudioSpecificConfig) Unmarshal(buf []byte) error {
return err
}
n := pos / 8
if pos%8 != 0 {
n++
}
if n != len(buf) {
return fmt.Errorf("detected unread bytes")
}
return nil
}
@@ -121,7 +113,7 @@ func (c *AudioSpecificConfig) UnmarshalFromPos(buf []byte, pos *int) error {
c.ExtensionSampleRate = int(tmp)
default:
return fmt.Errorf("invalid extension sample rate index (%d)", extensionSamplingFrequencyIndex)
return fmt.Errorf("invalid extension sample rate index: %d", extensionSamplingFrequencyIndex)
}
tmp, err = bits.ReadBits(buf, pos, 5)
@@ -135,6 +127,8 @@ func (c *AudioSpecificConfig) UnmarshalFromPos(buf []byte, pos *int) error {
}
}
// GASpecificConfig
c.FrameLengthFlag, err = bits.ReadFlag(buf, pos)
if err != nil {
return err
@@ -159,7 +153,7 @@ func (c *AudioSpecificConfig) UnmarshalFromPos(buf []byte, pos *int) error {
}
if extensionFlag {
return fmt.Errorf("unsupported")
return fmt.Errorf("extensionFlag is unsupported")
}
return nil

View File

@@ -122,6 +122,31 @@ func TestAudioSpecificConfigUnmarshal(t *testing.T) {
}
}
func TestAudioSpecificConfigUnmarshalAdditional(t *testing.T) {
for _, ca := range []struct {
name string
enc []byte
dec AudioSpecificConfig
}{
{
"additional bytes",
[]byte{0x11, 0x90, 0x08, 0x10},
AudioSpecificConfig{
Type: ObjectTypeAACLC,
SampleRate: 48000,
ChannelCount: 2,
},
},
} {
t.Run(ca.name, func(t *testing.T) {
var dec AudioSpecificConfig
err := dec.Unmarshal(ca.enc)
require.NoError(t, err)
require.Equal(t, ca.dec, dec)
})
}
}
func TestAudioSpecificConfigMarshal(t *testing.T) {
for _, ca := range audioSpecificConfigCases {
t.Run(ca.name, func(t *testing.T) {