strictly follow the specification when generating SDP of AAC tracks (#35) (https://github.com/aler9/rtsp-simple-server/issues/112)

This commit is contained in:
aler9
2021-05-13 09:48:41 +02:00
parent 8be64d9cf6
commit 4ef801b9e0
2 changed files with 101 additions and 11 deletions

View File

@@ -149,7 +149,7 @@ func NewTrackAAC(payloadType uint8, config []byte) (*Track, error) {
Attributes: []psdp.Attribute{ Attributes: []psdp.Attribute{
{ {
Key: "rtpmap", 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), "/" + strconv.FormatInt(int64(conf.ChannelCount), 10),
}, },
{ {
@@ -166,7 +166,7 @@ func NewTrackAAC(payloadType uint8, config []byte) (*Track, error) {
}, nil }, nil
} }
// IsAAC checks whether the track is a AAC track. // IsAAC checks whether the track is an AAC track.
func (t *Track) IsAAC() bool { func (t *Track) IsAAC() bool {
if t.Media.MediaName.Media != "audio" { if t.Media.MediaName.Media != "audio" {
return false return false
@@ -182,7 +182,7 @@ func (t *Track) IsAAC() bool {
return false 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. // ExtractDataAAC extracts the config from an AAC track.

View File

@@ -228,6 +228,40 @@ func TestTrackH264New(t *testing.T) {
}, tr) }, 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) { func TestTrackH264Extract(t *testing.T) {
for _, ca := range []struct { for _, ca := range []struct {
name string name string
@@ -490,7 +524,7 @@ func TestTrackAACNew(t *testing.T) {
Attributes: []psdp.Attribute{ Attributes: []psdp.Attribute{
{ {
Key: "rtpmap", Key: "rtpmap",
Value: "96 MPEG4-GENERIC/48000/2", Value: "96 mpeg4-generic/48000/2",
}, },
{ {
Key: "fmtp", Key: "fmtp",
@@ -501,6 +535,62 @@ func TestTrackAACNew(t *testing.T) {
}, tr) }, 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) { func TestTrackAACExtract(t *testing.T) {
for _, ca := range []struct { for _, ca := range []struct {
name string name string
@@ -519,7 +609,7 @@ func TestTrackAACExtract(t *testing.T) {
Attributes: []psdp.Attribute{ Attributes: []psdp.Attribute{
{ {
Key: "rtpmap", Key: "rtpmap",
Value: "96 MPEG4-GENERIC/48000/2", Value: "96 mpeg4-generic/48000/2",
}, },
{ {
Key: "fmtp", Key: "fmtp",
@@ -542,7 +632,7 @@ func TestTrackAACExtract(t *testing.T) {
Attributes: []psdp.Attribute{ Attributes: []psdp.Attribute{
{ {
Key: "rtpmap", Key: "rtpmap",
Value: "96 MPEG4-GENERIC/48000/2", Value: "96 mpeg4-generic/48000/2",
}, },
{ {
Key: "fmtp", Key: "fmtp",
@@ -580,7 +670,7 @@ func TestTrackAACExtractError(t *testing.T) {
Attributes: []psdp.Attribute{ Attributes: []psdp.Attribute{
{ {
Key: "rtpmap", 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{ Attributes: []psdp.Attribute{
{ {
Key: "rtpmap", Key: "rtpmap",
Value: "96 MPEG4-GENERIC/48000/2", Value: "96 mpeg4-generic/48000/2",
}, },
{ {
Key: "fmtp", Key: "fmtp",
@@ -622,7 +712,7 @@ func TestTrackAACExtractError(t *testing.T) {
Attributes: []psdp.Attribute{ Attributes: []psdp.Attribute{
{ {
Key: "rtpmap", Key: "rtpmap",
Value: "96 MPEG4-GENERIC/48000/2", Value: "96 mpeg4-generic/48000/2",
}, },
{ {
Key: "fmtp", Key: "fmtp",
@@ -645,7 +735,7 @@ func TestTrackAACExtractError(t *testing.T) {
Attributes: []psdp.Attribute{ Attributes: []psdp.Attribute{
{ {
Key: "rtpmap", Key: "rtpmap",
Value: "96 MPEG4-GENERIC/48000/2", Value: "96 mpeg4-generic/48000/2",
}, },
{ {
Key: "fmtp", Key: "fmtp",
@@ -668,7 +758,7 @@ func TestTrackAACExtractError(t *testing.T) {
Attributes: []psdp.Attribute{ Attributes: []psdp.Attribute{
{ {
Key: "rtpmap", Key: "rtpmap",
Value: "96 MPEG4-GENERIC/48000/2", Value: "96 mpeg4-generic/48000/2",
}, },
{ {
Key: "fmtp", Key: "fmtp",