mirror of
https://github.com/aler9/gortsplib
synced 2025-10-18 13:10:42 +08:00
rewrite track tests
This commit is contained in:
@@ -7,148 +7,30 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestTrackGenericNewFromMediaDescription(t *testing.T) {
|
||||
for _, ca := range []struct {
|
||||
name string
|
||||
md *psdp.MediaDescription
|
||||
track *TrackGeneric
|
||||
}{
|
||||
{
|
||||
"pcma",
|
||||
&psdp.MediaDescription{
|
||||
MediaName: psdp.MediaName{
|
||||
Media: "audio",
|
||||
Protos: []string{"RTP", "AVP"},
|
||||
Formats: []string{"8"},
|
||||
func TestTrackGenericClone(t *testing.T) {
|
||||
track, err := newTrackGenericFromMediaDescription(
|
||||
&psdp.MediaDescription{
|
||||
MediaName: psdp.MediaName{
|
||||
Media: "video",
|
||||
Port: psdp.RangedPort{Value: 0},
|
||||
Protos: []string{"RTP", "AVP"},
|
||||
Formats: []string{"98", "96"},
|
||||
},
|
||||
Attributes: []psdp.Attribute{
|
||||
{
|
||||
Key: "rtpmap",
|
||||
Value: "98 H265/90000",
|
||||
},
|
||||
{
|
||||
Key: "fmtp",
|
||||
Value: "98 profile-id=1; sprop-vps=QAEMAf//AWAAAAMAAAMAAAMAAAMAlqwJ; " +
|
||||
"sprop-sps=QgEBAWAAAAMAAAMAAAMAAAMAlqADwIAQ5Za5JMmuWcBSSgAAB9AAAHUwgkA=; sprop-pps=RAHgdrAwxmQ=",
|
||||
},
|
||||
},
|
||||
&TrackGeneric{
|
||||
clockRate: 8000,
|
||||
media: "audio",
|
||||
formats: []string{"8"},
|
||||
},
|
||||
},
|
||||
{
|
||||
"pcmu",
|
||||
&psdp.MediaDescription{
|
||||
MediaName: psdp.MediaName{
|
||||
Media: "audio",
|
||||
Port: psdp.RangedPort{Value: 49170},
|
||||
Protos: []string{"RTP", "AVP"},
|
||||
Formats: []string{"0"},
|
||||
},
|
||||
},
|
||||
&TrackGeneric{
|
||||
clockRate: 8000,
|
||||
media: "audio",
|
||||
formats: []string{"0"},
|
||||
},
|
||||
},
|
||||
{
|
||||
"multiple formats",
|
||||
&psdp.MediaDescription{
|
||||
MediaName: psdp.MediaName{
|
||||
Media: "video",
|
||||
Port: psdp.RangedPort{Value: 0},
|
||||
Protos: []string{"RTP", "AVP"},
|
||||
Formats: []string{"98", "96"},
|
||||
},
|
||||
Attributes: []psdp.Attribute{
|
||||
{
|
||||
Key: "rtpmap",
|
||||
Value: "98 H265/90000",
|
||||
},
|
||||
{
|
||||
Key: "fmtp",
|
||||
Value: "98 profile-id=1; sprop-vps=QAEMAf//AWAAAAMAAAMAAAMAAAMAlqwJ; " +
|
||||
"sprop-sps=QgEBAWAAAAMAAAMAAAMAAAMAlqADwIAQ5Za5JMmuWcBSSgAAB9AAAHUwgkA=; sprop-pps=RAHgdrAwxmQ=",
|
||||
},
|
||||
},
|
||||
},
|
||||
&TrackGeneric{
|
||||
clockRate: 90000,
|
||||
media: "video",
|
||||
formats: []string{"98", "96"},
|
||||
rtpmap: "98 H265/90000",
|
||||
fmtp: "98 profile-id=1; sprop-vps=QAEMAf//AWAAAAMAAAMAAAMAAAMAlqwJ; " +
|
||||
"sprop-sps=QgEBAWAAAAMAAAMAAAMAAAMAlqADwIAQ5Za5JMmuWcBSSgAAB9AAAHUwgkA=; sprop-pps=RAHgdrAwxmQ=",
|
||||
},
|
||||
},
|
||||
} {
|
||||
t.Run(ca.name, func(t *testing.T) {
|
||||
track, err := newTrackGenericFromMediaDescription(ca.md)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, ca.track, track)
|
||||
})
|
||||
}
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
func TestTrackGenericNewFromMediaDescriptionErrors(t *testing.T) {
|
||||
for _, ca := range []struct {
|
||||
name string
|
||||
md *psdp.MediaDescription
|
||||
err string
|
||||
}{
|
||||
{
|
||||
"no formats",
|
||||
&psdp.MediaDescription{
|
||||
MediaName: psdp.MediaName{
|
||||
Media: "audio",
|
||||
Protos: []string{"RTP", "AVP"},
|
||||
Formats: []string{},
|
||||
},
|
||||
},
|
||||
"unable to get clock rate: no formats provided",
|
||||
},
|
||||
{
|
||||
"no rtpmap",
|
||||
&psdp.MediaDescription{
|
||||
MediaName: psdp.MediaName{
|
||||
Media: "video",
|
||||
Protos: []string{"RTP", "AVP"},
|
||||
Formats: []string{"90"},
|
||||
},
|
||||
},
|
||||
"unable to get clock rate: attribute 'rtpmap' not found",
|
||||
},
|
||||
{
|
||||
"invalid rtpmap 1",
|
||||
&psdp.MediaDescription{
|
||||
MediaName: psdp.MediaName{
|
||||
Media: "video",
|
||||
Protos: []string{"RTP", "AVP"},
|
||||
Formats: []string{"96"},
|
||||
},
|
||||
Attributes: []psdp.Attribute{
|
||||
{
|
||||
Key: "rtpmap",
|
||||
Value: "96",
|
||||
},
|
||||
},
|
||||
},
|
||||
"unable to get clock rate: invalid rtpmap (96)",
|
||||
},
|
||||
{
|
||||
"invalid rtpmap 2",
|
||||
&psdp.MediaDescription{
|
||||
MediaName: psdp.MediaName{
|
||||
Media: "video",
|
||||
Protos: []string{"RTP", "AVP"},
|
||||
Formats: []string{"96"},
|
||||
},
|
||||
Attributes: []psdp.Attribute{
|
||||
{
|
||||
Key: "rtpmap",
|
||||
Value: "96 mpeg4-generic",
|
||||
},
|
||||
},
|
||||
},
|
||||
"unable to get clock rate: invalid rtpmap (96 mpeg4-generic)",
|
||||
},
|
||||
} {
|
||||
t.Run(ca.name, func(t *testing.T) {
|
||||
_, err := newTrackGenericFromMediaDescription(ca.md)
|
||||
require.EqualError(t, err, ca.err)
|
||||
})
|
||||
}
|
||||
copy := track.clone()
|
||||
require.NotSame(t, track, copy)
|
||||
require.Equal(t, track, copy)
|
||||
}
|
||||
|
Reference in New Issue
Block a user