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