mirror of
https://github.com/bluenviron/mediacommon.git
synced 2025-09-26 21:01:14 +08:00
mpeg4audio: deprecate Config (#216)
This commit is contained in:
@@ -434,15 +434,15 @@ func WriteCodecBoxes(w *Writer, codec mp4.Codec, trackID int, info *CodecInfo, a
|
|||||||
},
|
},
|
||||||
DataReferenceIndex: 1,
|
DataReferenceIndex: 1,
|
||||||
},
|
},
|
||||||
ChannelCount: uint16(codec.ChannelCount),
|
ChannelCount: uint16(codec.Config.ChannelCount),
|
||||||
SampleSize: 16,
|
SampleSize: 16,
|
||||||
SampleRate: uint32(codec.SampleRate * 65536),
|
SampleRate: uint32(codec.Config.SampleRate * 65536),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
enc, _ := codec.Marshal()
|
enc, _ := codec.Config.Marshal()
|
||||||
|
|
||||||
_, err = w.WriteBox(&4.Esds{ // <esds/>
|
_, err = w.WriteBox(&4.Esds{ // <esds/>
|
||||||
Descriptors: []amp4.Descriptor{
|
Descriptors: []amp4.Descriptor{
|
||||||
|
@@ -7,6 +7,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Config is an alias for AudioSpecificConfig.
|
// Config is an alias for AudioSpecificConfig.
|
||||||
|
//
|
||||||
|
// Deprecated: replaced by AudioSpecificConfig.
|
||||||
type Config = AudioSpecificConfig
|
type Config = AudioSpecificConfig
|
||||||
|
|
||||||
// AudioSpecificConfig is an AudioSpecificConfig.
|
// AudioSpecificConfig is an AudioSpecificConfig.
|
||||||
@@ -25,13 +27,13 @@ type AudioSpecificConfig struct {
|
|||||||
CoreCoderDelay uint16
|
CoreCoderDelay uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmarshal decodes a Config.
|
// Unmarshal decodes a AudioSpecificConfig.
|
||||||
func (c *AudioSpecificConfig) Unmarshal(buf []byte) error {
|
func (c *AudioSpecificConfig) Unmarshal(buf []byte) error {
|
||||||
pos := 0
|
pos := 0
|
||||||
return c.UnmarshalFromPos(buf, &pos)
|
return c.UnmarshalFromPos(buf, &pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalFromPos decodes a Config.
|
// UnmarshalFromPos decodes a AudioSpecificConfig.
|
||||||
func (c *AudioSpecificConfig) UnmarshalFromPos(buf []byte, pos *int) error {
|
func (c *AudioSpecificConfig) UnmarshalFromPos(buf []byte, pos *int) error {
|
||||||
tmp, err := bits.ReadBits(buf, pos, 5)
|
tmp, err := bits.ReadBits(buf, pos, 5)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -187,7 +189,7 @@ func (c AudioSpecificConfig) marshalSize() int {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// Marshal encodes a Config.
|
// Marshal encodes a AudioSpecificConfig.
|
||||||
func (c AudioSpecificConfig) Marshal() ([]byte, error) {
|
func (c AudioSpecificConfig) Marshal() ([]byte, error) {
|
||||||
buf := make([]byte, c.marshalSize())
|
buf := make([]byte, c.marshalSize())
|
||||||
pos := 0
|
pos := 0
|
||||||
|
@@ -471,7 +471,7 @@ func (i *Init) Unmarshal(r io.ReadSeeker) error {
|
|||||||
return nil, fmt.Errorf("unable to find decoder specific info")
|
return nil, fmt.Errorf("unable to find decoder specific info")
|
||||||
}
|
}
|
||||||
|
|
||||||
var c mpeg4audio.Config
|
var c mpeg4audio.AudioSpecificConfig
|
||||||
err := c.Unmarshal(spec)
|
err := c.Unmarshal(spec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("invalid MPEG-4 Audio configuration: %w", err)
|
return nil, fmt.Errorf("invalid MPEG-4 Audio configuration: %w", err)
|
||||||
|
@@ -24,7 +24,7 @@ var testVideoTrack = &mp4.CodecH264{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var testAudioTrack = &mp4.CodecMPEG4Audio{
|
var testAudioTrack = &mp4.CodecMPEG4Audio{
|
||||||
Config: mpeg4audio.Config{
|
Config: mpeg4audio.AudioSpecificConfig{
|
||||||
Type: 2,
|
Type: 2,
|
||||||
SampleRate: 44100,
|
SampleRate: 44100,
|
||||||
ChannelCount: 2,
|
ChannelCount: 2,
|
||||||
@@ -994,7 +994,7 @@ var casesInit = []struct {
|
|||||||
Tracks: []*InitTrack{
|
Tracks: []*InitTrack{
|
||||||
{
|
{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
TimeScale: uint32(testAudioTrack.SampleRate),
|
TimeScale: uint32(testAudioTrack.Config.SampleRate),
|
||||||
Codec: testAudioTrack,
|
Codec: testAudioTrack,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -1461,7 +1461,7 @@ var casesInit = []struct {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: 2,
|
ID: 2,
|
||||||
TimeScale: uint32(testAudioTrack.SampleRate),
|
TimeScale: uint32(testAudioTrack.Config.SampleRate),
|
||||||
Codec: testAudioTrack,
|
Codec: testAudioTrack,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -1886,7 +1886,7 @@ func TestInitUnmarshalExternal(t *testing.T) {
|
|||||||
ID: 257,
|
ID: 257,
|
||||||
TimeScale: 10000000,
|
TimeScale: 10000000,
|
||||||
Codec: &mp4.CodecMPEG4Audio{
|
Codec: &mp4.CodecMPEG4Audio{
|
||||||
Config: mpeg4audio.Config{
|
Config: mpeg4audio.AudioSpecificConfig{
|
||||||
Type: mpeg4audio.ObjectTypeAACLC,
|
Type: mpeg4audio.ObjectTypeAACLC,
|
||||||
SampleRate: 48000,
|
SampleRate: 48000,
|
||||||
ChannelCount: 2,
|
ChannelCount: 2,
|
||||||
|
@@ -6,7 +6,7 @@ import (
|
|||||||
|
|
||||||
// CodecMPEG4Audio is a MPEG-4 Audio codec.
|
// CodecMPEG4Audio is a MPEG-4 Audio codec.
|
||||||
type CodecMPEG4Audio struct {
|
type CodecMPEG4Audio struct {
|
||||||
mpeg4audio.Config
|
Config mpeg4audio.AudioSpecificConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsVideo implements Codec.
|
// IsVideo implements Codec.
|
||||||
|
@@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/bluenviron/mediacommon/v2/pkg/codecs/mpeg4audio"
|
"github.com/bluenviron/mediacommon/v2/pkg/codecs/mpeg4audio"
|
||||||
)
|
)
|
||||||
|
|
||||||
func findMPEG4AudioConfig(dem *astits.Demuxer, pid uint16) (*mpeg4audio.Config, error) {
|
func findMPEG4AudioConfig(dem *astits.Demuxer, pid uint16) (*mpeg4audio.AudioSpecificConfig, error) {
|
||||||
for {
|
for {
|
||||||
data, err := dem.NextData()
|
data, err := dem.NextData()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -26,7 +26,7 @@ func findMPEG4AudioConfig(dem *astits.Demuxer, pid uint16) (*mpeg4audio.Config,
|
|||||||
}
|
}
|
||||||
|
|
||||||
pkt := adtsPkts[0]
|
pkt := adtsPkts[0]
|
||||||
return &mpeg4audio.Config{
|
return &mpeg4audio.AudioSpecificConfig{
|
||||||
Type: pkt.Type,
|
Type: pkt.Type,
|
||||||
SampleRate: pkt.SampleRate,
|
SampleRate: pkt.SampleRate,
|
||||||
ChannelCount: pkt.ChannelCount,
|
ChannelCount: pkt.ChannelCount,
|
||||||
|
@@ -523,7 +523,7 @@ func (p *Presentation) Unmarshal(r io.ReadSeeker) error {
|
|||||||
return nil, fmt.Errorf("unable to find decoder specific info")
|
return nil, fmt.Errorf("unable to find decoder specific info")
|
||||||
}
|
}
|
||||||
|
|
||||||
var c mpeg4audio.Config
|
var c mpeg4audio.AudioSpecificConfig
|
||||||
err := c.Unmarshal(spec)
|
err := c.Unmarshal(spec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("invalid MPEG-4 Audio configuration: %w", err)
|
return nil, fmt.Errorf("invalid MPEG-4 Audio configuration: %w", err)
|
||||||
|
@@ -188,7 +188,7 @@ var casesPresentation = []struct {
|
|||||||
ID: 8,
|
ID: 8,
|
||||||
TimeScale: 90000,
|
TimeScale: 90000,
|
||||||
Codec: &mp4.CodecMPEG4Audio{
|
Codec: &mp4.CodecMPEG4Audio{
|
||||||
Config: mpeg4audio.Config{
|
Config: mpeg4audio.AudioSpecificConfig{
|
||||||
Type: 2,
|
Type: 2,
|
||||||
SampleRate: 44100,
|
SampleRate: 44100,
|
||||||
ChannelCount: 2,
|
ChannelCount: 2,
|
||||||
|
Reference in New Issue
Block a user