Skip to content

Commit

Permalink
strictly follow the specification when generating SDP of AAC tracks (#35
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed May 13, 2021
1 parent 8be64d9 commit 4ef801b
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 11 deletions.
6 changes: 3 additions & 3 deletions track.go
Expand Up @@ -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),
},
{
Expand All @@ -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
Expand All @@ -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.
Expand Down
106 changes: 98 additions & 8 deletions track_test.go
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
},
},
},
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 4ef801b

Please sign in to comment.