diff --git a/track.go b/track.go index 48499d10..217651ab 100644 --- a/track.go +++ b/track.go @@ -149,7 +149,7 @@ func NewTrackAAC(payloadType uint8, config []byte) (*Track, error) { Attributes: []psdp.Attribute{ { Key: "rtpmap", - Value: typ + " MPEG4-GENERIC/" + strconv.FormatInt(int64(conf.SampleRate), 10) + + Value: typ + " mpeg4-generic/" + strconv.FormatInt(int64(conf.SampleRate), 10) + "/" + strconv.FormatInt(int64(conf.ChannelCount), 10), }, { @@ -166,7 +166,7 @@ func NewTrackAAC(payloadType uint8, config []byte) (*Track, error) { }, nil } -// IsAAC checks whether the track is a AAC track. +// IsAAC checks whether the track is an AAC track. func (t *Track) IsAAC() bool { if t.Media.MediaName.Media != "audio" { return false @@ -182,7 +182,7 @@ func (t *Track) IsAAC() bool { return false } - return strings.HasPrefix(vals[1], "MPEG4-GENERIC/") + return strings.HasPrefix(strings.ToLower(vals[1]), "mpeg4-generic/") } // ExtractDataAAC extracts the config from an AAC track. diff --git a/track_test.go b/track_test.go index e406ae20..524986d3 100644 --- a/track_test.go +++ b/track_test.go @@ -228,6 +228,40 @@ func TestTrackH264New(t *testing.T) { }, tr) } +func TestTrackIsH264(t *testing.T) { + for _, ca := range []struct { + name string + track *Track + }{ + { + "standard", + &Track{ + Media: &psdp.MediaDescription{ + MediaName: psdp.MediaName{ + Media: "video", + Protos: []string{"RTP", "AVP"}, + Formats: []string{"96"}, + }, + Attributes: []psdp.Attribute{ + { + Key: "rtpmap", + Value: "96 H264/90000", + }, + { + Key: "fmtp", + Value: "96 packetization-mode=1; sprop-parameter-sets=Z2QADKw7ULBLQgAAAwACAAADAD0I,aO48gA==; profile-level-id=64000C", + }, + }, + }, + }, + }, + } { + t.Run(ca.name, func(t *testing.T) { + require.Equal(t, true, ca.track.IsH264()) + }) + } +} + func TestTrackH264Extract(t *testing.T) { for _, ca := range []struct { name string @@ -490,7 +524,7 @@ func TestTrackAACNew(t *testing.T) { Attributes: []psdp.Attribute{ { Key: "rtpmap", - Value: "96 MPEG4-GENERIC/48000/2", + Value: "96 mpeg4-generic/48000/2", }, { Key: "fmtp", @@ -501,6 +535,62 @@ func TestTrackAACNew(t *testing.T) { }, tr) } +func TestTrackIsAAC(t *testing.T) { + for _, ca := range []struct { + name string + track *Track + }{ + { + "standard", + &Track{ + Media: &psdp.MediaDescription{ + MediaName: psdp.MediaName{ + Media: "audio", + Protos: []string{"RTP", "AVP"}, + Formats: []string{"96"}, + }, + Attributes: []psdp.Attribute{ + { + Key: "rtpmap", + Value: "96 mpeg4-generic/48000/2", + }, + { + Key: "fmtp", + Value: "96 profile-level-id=1; mode=AAC-hbr; sizelength=13; indexlength=3; indexdeltalength=3; config=1190", + }, + }, + }, + }, + }, + { + "uppercase", + &Track{ + Media: &psdp.MediaDescription{ + MediaName: psdp.MediaName{ + Media: "audio", + Protos: []string{"RTP", "AVP"}, + Formats: []string{"96"}, + }, + Attributes: []psdp.Attribute{ + { + Key: "rtpmap", + Value: "96 MPEG4-GENERIC/48000/2", + }, + { + Key: "fmtp", + Value: "96 profile-level-id=1; mode=AAC-hbr; sizelength=13; indexlength=3; indexdeltalength=3; config=1190", + }, + }, + }, + }, + }, + } { + t.Run(ca.name, func(t *testing.T) { + require.Equal(t, true, ca.track.IsAAC()) + }) + } +} + func TestTrackAACExtract(t *testing.T) { for _, ca := range []struct { name string @@ -519,7 +609,7 @@ func TestTrackAACExtract(t *testing.T) { Attributes: []psdp.Attribute{ { Key: "rtpmap", - Value: "96 MPEG4-GENERIC/48000/2", + Value: "96 mpeg4-generic/48000/2", }, { Key: "fmtp", @@ -542,7 +632,7 @@ func TestTrackAACExtract(t *testing.T) { Attributes: []psdp.Attribute{ { Key: "rtpmap", - Value: "96 MPEG4-GENERIC/48000/2", + Value: "96 mpeg4-generic/48000/2", }, { Key: "fmtp", @@ -580,7 +670,7 @@ func TestTrackAACExtractError(t *testing.T) { Attributes: []psdp.Attribute{ { Key: "rtpmap", - Value: "96 MPEG4-GENERIC/48000/2", + Value: "96 mpeg4-generic/48000/2", }, }, }, @@ -599,7 +689,7 @@ func TestTrackAACExtractError(t *testing.T) { Attributes: []psdp.Attribute{ { Key: "rtpmap", - Value: "96 MPEG4-GENERIC/48000/2", + Value: "96 mpeg4-generic/48000/2", }, { Key: "fmtp", @@ -622,7 +712,7 @@ func TestTrackAACExtractError(t *testing.T) { Attributes: []psdp.Attribute{ { Key: "rtpmap", - Value: "96 MPEG4-GENERIC/48000/2", + Value: "96 mpeg4-generic/48000/2", }, { Key: "fmtp", @@ -645,7 +735,7 @@ func TestTrackAACExtractError(t *testing.T) { Attributes: []psdp.Attribute{ { Key: "rtpmap", - Value: "96 MPEG4-GENERIC/48000/2", + Value: "96 mpeg4-generic/48000/2", }, { Key: "fmtp", @@ -668,7 +758,7 @@ func TestTrackAACExtractError(t *testing.T) { Attributes: []psdp.Attribute{ { Key: "rtpmap", - Value: "96 MPEG4-GENERIC/48000/2", + Value: "96 mpeg4-generic/48000/2", }, { Key: "fmtp",