mirror of
https://github.com/aler9/gortsplib
synced 2025-10-26 08:40:35 +08:00
aac: rename Encode / Decode into Marshal / Unmarshal
This commit is contained in:
@@ -16,8 +16,8 @@ type MPEG4AudioConfig struct {
|
||||
AOTSpecificConfig []byte
|
||||
}
|
||||
|
||||
// Decode decodes an MPEG4AudioConfig.
|
||||
func (c *MPEG4AudioConfig) Decode(byts []byte) error {
|
||||
// Unmarshal decodes an MPEG4AudioConfig.
|
||||
func (c *MPEG4AudioConfig) Unmarshal(byts []byte) error {
|
||||
// ref: https://wiki.multimedia.cx/index.php/MPEG-4_Audio
|
||||
|
||||
r := bitio.NewReader(bytes.NewBuffer(byts))
|
||||
@@ -88,7 +88,7 @@ func (c *MPEG4AudioConfig) Decode(byts []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c MPEG4AudioConfig) encodeSize() int {
|
||||
func (c MPEG4AudioConfig) marshalSize() int {
|
||||
n := 5 + 4 + len(c.AOTSpecificConfig)*8
|
||||
_, ok := reverseSampleRates[c.SampleRate]
|
||||
if !ok {
|
||||
@@ -104,9 +104,9 @@ func (c MPEG4AudioConfig) encodeSize() int {
|
||||
return ret
|
||||
}
|
||||
|
||||
// Encode encodes an MPEG4AudioConfig.
|
||||
func (c MPEG4AudioConfig) Encode() ([]byte, error) {
|
||||
buf := make([]byte, c.encodeSize())
|
||||
// Marshal encodes an MPEG4AudioConfig.
|
||||
func (c MPEG4AudioConfig) Marshal() ([]byte, error) {
|
||||
buf := make([]byte, c.marshalSize())
|
||||
w := bitio.NewWriter(bytes.NewBuffer(buf[:0]))
|
||||
|
||||
w.WriteBits(uint64(c.Type), 5)
|
||||
|
||||
@@ -69,18 +69,18 @@ var configCases = []struct {
|
||||
},
|
||||
}
|
||||
|
||||
func TestConfigDecode(t *testing.T) {
|
||||
func TestConfigUnmarshal(t *testing.T) {
|
||||
for _, ca := range configCases {
|
||||
t.Run(ca.name, func(t *testing.T) {
|
||||
var dec MPEG4AudioConfig
|
||||
err := dec.Decode(ca.enc)
|
||||
err := dec.Unmarshal(ca.enc)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, ca.dec, dec)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigDecodeErrors(t *testing.T) {
|
||||
func TestConfigUnmarshalErrors(t *testing.T) {
|
||||
for _, ca := range []struct {
|
||||
name string
|
||||
byts []byte
|
||||
@@ -124,23 +124,23 @@ func TestConfigDecodeErrors(t *testing.T) {
|
||||
} {
|
||||
t.Run(ca.name, func(t *testing.T) {
|
||||
var dec MPEG4AudioConfig
|
||||
err := dec.Decode(ca.byts)
|
||||
err := dec.Unmarshal(ca.byts)
|
||||
require.EqualError(t, err, ca.err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigEncode(t *testing.T) {
|
||||
func TestConfigMarshal(t *testing.T) {
|
||||
for _, ca := range configCases {
|
||||
t.Run(ca.name, func(t *testing.T) {
|
||||
enc, err := ca.dec.Encode()
|
||||
enc, err := ca.dec.Marshal()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, ca.enc, enc)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigEncodeErrors(t *testing.T) {
|
||||
func TestConfigMarshalErrors(t *testing.T) {
|
||||
for _, ca := range []struct {
|
||||
name string
|
||||
conf MPEG4AudioConfig
|
||||
@@ -157,7 +157,7 @@ func TestConfigEncodeErrors(t *testing.T) {
|
||||
},
|
||||
} {
|
||||
t.Run(ca.name, func(t *testing.T) {
|
||||
_, err := ca.conf.Encode()
|
||||
_, err := ca.conf.Marshal()
|
||||
require.EqualError(t, err, ca.err)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ func newTrackAACFromMediaDescription(
|
||||
}
|
||||
|
||||
t.Config = &aac.MPEG4AudioConfig{}
|
||||
err = t.Config.Decode(enc)
|
||||
err = t.Config.Unmarshal(enc)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid AAC config (%v)", tmp[1])
|
||||
}
|
||||
@@ -121,7 +121,7 @@ func (t *TrackAAC) clone() Track {
|
||||
|
||||
// MediaDescription returns the track media description in SDP format.
|
||||
func (t *TrackAAC) MediaDescription() *psdp.MediaDescription {
|
||||
enc, err := t.Config.Encode()
|
||||
enc, err := t.Config.Marshal()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user