mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
improve tests
This commit is contained in:
@@ -26,7 +26,7 @@ type Output struct {
|
||||
|
||||
// Cleaner is used to clean incoming RTP packets, in order to:
|
||||
// - remove padding
|
||||
// - re-encode packets if they are bigger than maximum allowed.
|
||||
// - re-encode them if they are bigger than maximum allowed
|
||||
type Cleaner struct {
|
||||
isH264 bool
|
||||
isTCP bool
|
||||
|
@@ -37,6 +37,21 @@ func TestRemovePadding(t *testing.T) {
|
||||
}}, out)
|
||||
}
|
||||
|
||||
func TestGenericOversized(t *testing.T) {
|
||||
cleaner := NewCleaner(false, true)
|
||||
|
||||
_, err := cleaner.Clear(&rtp.Packet{
|
||||
Header: rtp.Header{
|
||||
Version: 2,
|
||||
PayloadType: 96,
|
||||
Marker: false,
|
||||
SequenceNumber: 34572,
|
||||
},
|
||||
Payload: bytes.Repeat([]byte{0x01, 0x02, 0x03, 0x04, 0x05}, 2050/5),
|
||||
})
|
||||
require.EqualError(t, err, "payload size (2062) greater than maximum allowed (1472)")
|
||||
}
|
||||
|
||||
func TestH264Oversized(t *testing.T) {
|
||||
cleaner := NewCleaner(true, true)
|
||||
|
||||
|
@@ -158,7 +158,8 @@ func TestTrackH264GetSPSPPSErrors(t *testing.T) {
|
||||
},
|
||||
} {
|
||||
t.Run(ca.name, func(t *testing.T) {
|
||||
_, _, err := trackH264GetSPSPPS(ca.md)
|
||||
tr := &TrackH264{}
|
||||
err := tr.fillParamsFromMediaDescription(ca.md)
|
||||
require.EqualError(t, err, ca.err)
|
||||
})
|
||||
}
|
||||
|
51
track_h265_test.go
Normal file
51
track_h265_test.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package gortsplib
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
psdp "github.com/pion/sdp/v3"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestTrackH265New(t *testing.T) {
|
||||
track := NewTrackH265(96,
|
||||
[]byte{0x01, 0x02}, []byte{0x03, 0x04}, []byte{0x05, 0x06})
|
||||
require.Equal(t, "", track.GetControl())
|
||||
require.Equal(t, []byte{0x01, 0x02}, track.VPS())
|
||||
require.Equal(t, []byte{0x03, 0x04}, track.SPS())
|
||||
require.Equal(t, []byte{0x05, 0x06}, track.PPS())
|
||||
}
|
||||
|
||||
func TestTrackH265Clone(t *testing.T) {
|
||||
track := NewTrackH265(96, []byte{0x01, 0x02}, []byte{0x03, 0x04}, []byte{0x05, 0x06})
|
||||
|
||||
clone := track.clone()
|
||||
require.NotSame(t, track, clone)
|
||||
require.Equal(t, track, clone)
|
||||
}
|
||||
|
||||
func TestTrackH265MediaDescription(t *testing.T) {
|
||||
track := NewTrackH265(96, []byte{0x01, 0x02}, []byte{0x03, 0x04}, []byte{0x05, 0x06})
|
||||
|
||||
require.Equal(t, &psdp.MediaDescription{
|
||||
MediaName: psdp.MediaName{
|
||||
Media: "video",
|
||||
Protos: []string{"RTP", "AVP"},
|
||||
Formats: []string{"96"},
|
||||
},
|
||||
Attributes: []psdp.Attribute{
|
||||
{
|
||||
Key: "rtpmap",
|
||||
Value: "96 H265/90000",
|
||||
},
|
||||
{
|
||||
Key: "fmtp",
|
||||
Value: "96 sprop-vps=AQI=; sprop-sps=AwQ=; sprop-pps=BQY=",
|
||||
},
|
||||
{
|
||||
Key: "control",
|
||||
Value: "",
|
||||
},
|
||||
},
|
||||
}, track.MediaDescription())
|
||||
}
|
@@ -39,7 +39,7 @@ func (t *TrackJPEG) clone() Track {
|
||||
func (t *TrackJPEG) MediaDescription() *psdp.MediaDescription {
|
||||
return &psdp.MediaDescription{
|
||||
MediaName: psdp.MediaName{
|
||||
Media: "audio",
|
||||
Media: "video",
|
||||
Protos: []string{"RTP", "AVP"},
|
||||
Formats: []string{"26"},
|
||||
},
|
||||
|
43
track_jpeg_test.go
Normal file
43
track_jpeg_test.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package gortsplib
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
psdp "github.com/pion/sdp/v3"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestTrackJPEGNew(t *testing.T) {
|
||||
track := NewTrackJPEG()
|
||||
require.Equal(t, "", track.GetControl())
|
||||
}
|
||||
|
||||
func TestTrackJPEGClone(t *testing.T) {
|
||||
track := NewTrackJPEG()
|
||||
|
||||
clone := track.clone()
|
||||
require.NotSame(t, track, clone)
|
||||
require.Equal(t, track, clone)
|
||||
}
|
||||
|
||||
func TestTrackJPEGMediaDescription(t *testing.T) {
|
||||
track := NewTrackJPEG()
|
||||
|
||||
require.Equal(t, &psdp.MediaDescription{
|
||||
MediaName: psdp.MediaName{
|
||||
Media: "video",
|
||||
Protos: []string{"RTP", "AVP"},
|
||||
Formats: []string{"26"},
|
||||
},
|
||||
Attributes: []psdp.Attribute{
|
||||
{
|
||||
Key: "rtpmap",
|
||||
Value: "26 JPEG/90000",
|
||||
},
|
||||
{
|
||||
Key: "control",
|
||||
Value: "",
|
||||
},
|
||||
},
|
||||
}, track.MediaDescription())
|
||||
}
|
43
track_pcma_test.go
Normal file
43
track_pcma_test.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package gortsplib
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
psdp "github.com/pion/sdp/v3"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestTrackPCMANew(t *testing.T) {
|
||||
track := NewTrackPCMA()
|
||||
require.Equal(t, "", track.GetControl())
|
||||
}
|
||||
|
||||
func TestTrackPCMAClone(t *testing.T) {
|
||||
track := NewTrackPCMA()
|
||||
|
||||
clone := track.clone()
|
||||
require.NotSame(t, track, clone)
|
||||
require.Equal(t, track, clone)
|
||||
}
|
||||
|
||||
func TestTrackPCMAMediaDescription(t *testing.T) {
|
||||
track := NewTrackPCMA()
|
||||
|
||||
require.Equal(t, &psdp.MediaDescription{
|
||||
MediaName: psdp.MediaName{
|
||||
Media: "audio",
|
||||
Protos: []string{"RTP", "AVP"},
|
||||
Formats: []string{"8"},
|
||||
},
|
||||
Attributes: []psdp.Attribute{
|
||||
{
|
||||
Key: "rtpmap",
|
||||
Value: "8 PCMA/8000",
|
||||
},
|
||||
{
|
||||
Key: "control",
|
||||
Value: "",
|
||||
},
|
||||
},
|
||||
}, track.MediaDescription())
|
||||
}
|
43
track_pcmu_test.go
Normal file
43
track_pcmu_test.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package gortsplib
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
psdp "github.com/pion/sdp/v3"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestTrackPCMUNew(t *testing.T) {
|
||||
track := NewTrackPCMU()
|
||||
require.Equal(t, "", track.GetControl())
|
||||
}
|
||||
|
||||
func TestTrackPCMUClone(t *testing.T) {
|
||||
track := NewTrackPCMU()
|
||||
|
||||
clone := track.clone()
|
||||
require.NotSame(t, track, clone)
|
||||
require.Equal(t, track, clone)
|
||||
}
|
||||
|
||||
func TestTrackPCMUMediaDescription(t *testing.T) {
|
||||
track := NewTrackPCMU()
|
||||
|
||||
require.Equal(t, &psdp.MediaDescription{
|
||||
MediaName: psdp.MediaName{
|
||||
Media: "audio",
|
||||
Protos: []string{"RTP", "AVP"},
|
||||
Formats: []string{"0"},
|
||||
},
|
||||
Attributes: []psdp.Attribute{
|
||||
{
|
||||
Key: "rtpmap",
|
||||
Value: "0 PCMU/8000",
|
||||
},
|
||||
{
|
||||
Key: "control",
|
||||
Value: "",
|
||||
},
|
||||
},
|
||||
}, track.MediaDescription())
|
||||
}
|
@@ -339,13 +339,24 @@ func TestTrackNewFromMediaDescription(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
&TrackGeneric{
|
||||
clockRate: 90000,
|
||||
media: "video",
|
||||
formats: []string{"96"},
|
||||
rtpmap: "96 H265/90000",
|
||||
fmtp: "96 sprop-vps=QAEMAf//AWAAAAMAkAAAAwAAAwB4mZgJ; " +
|
||||
"sprop-sps=QgEBAWAAAAMAkAAAAwAAAwB4oAPAgBDllmZpJMrgEAAAAwAQAAADAeCA; sprop-pps=RAHBcrRiQA==",
|
||||
&TrackH265{
|
||||
payloadType: 96,
|
||||
vps: []byte{
|
||||
0x40, 0x1, 0xc, 0x1, 0xff, 0xff, 0x1, 0x60,
|
||||
0x0, 0x0, 0x3, 0x0, 0x90, 0x0, 0x0, 0x3,
|
||||
0x0, 0x0, 0x3, 0x0, 0x78, 0x99, 0x98, 0x9,
|
||||
},
|
||||
sps: []byte{
|
||||
0x42, 0x1, 0x1, 0x1, 0x60, 0x0, 0x0, 0x3,
|
||||
0x0, 0x90, 0x0, 0x0, 0x3, 0x0, 0x0, 0x3,
|
||||
0x0, 0x78, 0xa0, 0x3, 0xc0, 0x80, 0x10, 0xe5,
|
||||
0x96, 0x66, 0x69, 0x24, 0xca, 0xe0, 0x10, 0x0,
|
||||
0x0, 0x3, 0x0, 0x10, 0x0, 0x0, 0x3, 0x1,
|
||||
0xe0, 0x80,
|
||||
},
|
||||
pps: []byte{
|
||||
0x44, 0x1, 0xc1, 0x72, 0xb4, 0x62, 0x40,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
|
Reference in New Issue
Block a user