mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 07:06:58 +08:00
improve coverage
This commit is contained in:
@@ -610,7 +610,46 @@ func TestNewFromMediaDescription(t *testing.T) {
|
|||||||
},
|
},
|
||||||
&Generic{
|
&Generic{
|
||||||
PayloadTyp: 107,
|
PayloadTyp: 107,
|
||||||
ClockRat: 0,
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"generic invalid rtpmap",
|
||||||
|
&psdp.MediaDescription{
|
||||||
|
MediaName: psdp.MediaName{
|
||||||
|
Media: "application",
|
||||||
|
Protos: []string{"RTP", "AVP"},
|
||||||
|
Formats: []string{"98"},
|
||||||
|
},
|
||||||
|
Attributes: []psdp.Attribute{
|
||||||
|
{
|
||||||
|
Key: "rtpmap",
|
||||||
|
Value: "98 custom",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
&Generic{
|
||||||
|
PayloadTyp: 98,
|
||||||
|
RTPMap: "custom",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"generic invalid rtpmap 2",
|
||||||
|
&psdp.MediaDescription{
|
||||||
|
MediaName: psdp.MediaName{
|
||||||
|
Media: "application",
|
||||||
|
Protos: []string{"RTP", "AVP"},
|
||||||
|
Formats: []string{"98"},
|
||||||
|
},
|
||||||
|
Attributes: []psdp.Attribute{
|
||||||
|
{
|
||||||
|
Key: "rtpmap",
|
||||||
|
Value: "98 custom/aaa",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
&Generic{
|
||||||
|
PayloadTyp: 98,
|
||||||
|
RTPMap: "custom/aaa",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
@@ -662,44 +701,6 @@ func TestNewFromMediaDescriptionErrors(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"strconv.ParseInt: parsing \"\": invalid syntax",
|
"strconv.ParseInt: parsing \"\": invalid syntax",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"audio aac missing fmtp",
|
|
||||||
&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",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"fmtp attribute is missing",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"audio aac invalid fmtp",
|
|
||||||
&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",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"fmtp attribute is missing",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"audio aac fmtp without key",
|
"audio aac fmtp without key",
|
||||||
&psdp.MediaDescription{
|
&psdp.MediaDescription{
|
||||||
@@ -868,6 +869,27 @@ func TestNewFromMediaDescriptionErrors(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"invalid AAC IndexDeltaLength (aaa)",
|
"invalid AAC IndexDeltaLength (aaa)",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"audio vorbis missing configuration",
|
||||||
|
&psdp.MediaDescription{
|
||||||
|
MediaName: psdp.MediaName{
|
||||||
|
Media: "audio",
|
||||||
|
Protos: []string{"RTP", "AVP"},
|
||||||
|
Formats: []string{"96"},
|
||||||
|
},
|
||||||
|
Attributes: []psdp.Attribute{
|
||||||
|
{
|
||||||
|
Key: "rtpmap",
|
||||||
|
Value: "96 VORBIS/44100/2",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: "fmtp",
|
||||||
|
Value: "96 aa=bb",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"config is missing (aa=bb)",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"audio opus invalid 1",
|
"audio opus invalid 1",
|
||||||
&psdp.MediaDescription{
|
&psdp.MediaDescription{
|
||||||
@@ -919,6 +941,90 @@ func TestNewFromMediaDescriptionErrors(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"strconv.ParseInt: parsing \"aa\": invalid syntax",
|
"strconv.ParseInt: parsing \"aa\": invalid syntax",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"video h264 invalid fmtp",
|
||||||
|
&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 aaa",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"invalid fmtp attribute (aaa)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"video h264 invalid sps",
|
||||||
|
&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 sprop-parameter-sets=kkk,vvv",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"invalid sprop-parameter-sets (kkk,vvv)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"video h264 invalid pps",
|
||||||
|
&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 sprop-parameter-sets=Z2QADKw7ULBLQgAAAwACAAADAD0I,vvv",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"invalid sprop-parameter-sets (Z2QADKw7ULBLQgAAAwACAAADAD0I,vvv)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"video h264 invalid packetization-mode",
|
||||||
|
&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=aaa",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"invalid packetization-mode (aaa)",
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(ca.name, func(t *testing.T) {
|
t.Run(ca.name, func(t *testing.T) {
|
||||||
_, err := Unmarshal(ca.md, ca.md.MediaName.Formats[0])
|
_, err := Unmarshal(ca.md, ca.md.MediaName.Formats[0])
|
||||||
|
@@ -98,10 +98,7 @@ func (t *H264) PayloadType() uint8 {
|
|||||||
func (t *H264) unmarshal(payloadType uint8, clock string, codec string, rtpmap string, fmtp string) error {
|
func (t *H264) unmarshal(payloadType uint8, clock string, codec string, rtpmap string, fmtp string) error {
|
||||||
t.PayloadTyp = payloadType
|
t.PayloadTyp = payloadType
|
||||||
|
|
||||||
if fmtp == "" {
|
if fmtp != "" {
|
||||||
return nil // do not return any error
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, kv := range strings.Split(fmtp, ";") {
|
for _, kv := range strings.Split(fmtp, ";") {
|
||||||
kv = strings.Trim(kv, " ")
|
kv = strings.Trim(kv, " ")
|
||||||
|
|
||||||
@@ -116,16 +113,16 @@ func (t *H264) unmarshal(payloadType uint8, clock string, codec string, rtpmap s
|
|||||||
|
|
||||||
switch tmp[0] {
|
switch tmp[0] {
|
||||||
case "sprop-parameter-sets":
|
case "sprop-parameter-sets":
|
||||||
tmp := strings.Split(tmp[1], ",")
|
tmp2 := strings.Split(tmp[1], ",")
|
||||||
if len(tmp) >= 2 {
|
if len(tmp2) >= 2 {
|
||||||
sps, err := base64.StdEncoding.DecodeString(tmp[0])
|
sps, err := base64.StdEncoding.DecodeString(tmp2[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid sprop-parameter-sets (%v)", fmtp)
|
return fmt.Errorf("invalid sprop-parameter-sets (%v)", tmp[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
pps, err := base64.StdEncoding.DecodeString(tmp[1])
|
pps, err := base64.StdEncoding.DecodeString(tmp2[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid sprop-parameter-sets (%v)", fmtp)
|
return fmt.Errorf("invalid sprop-parameter-sets (%v)", tmp[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
t.SPS = sps
|
t.SPS = sps
|
||||||
@@ -133,12 +130,13 @@ func (t *H264) unmarshal(payloadType uint8, clock string, codec string, rtpmap s
|
|||||||
}
|
}
|
||||||
|
|
||||||
case "packetization-mode":
|
case "packetization-mode":
|
||||||
tmp, err := strconv.ParseInt(tmp[1], 10, 64)
|
tmp2, err := strconv.ParseInt(tmp[1], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid packetization-mode (%v)", fmtp)
|
return fmt.Errorf("invalid packetization-mode (%v)", tmp[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
t.PacketizationMode = int(tmp)
|
t.PacketizationMode = int(tmp2)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -41,10 +41,7 @@ func (t *H265) PayloadType() uint8 {
|
|||||||
func (t *H265) unmarshal(payloadType uint8, clock string, codec string, rtpmap string, fmtp string) error {
|
func (t *H265) unmarshal(payloadType uint8, clock string, codec string, rtpmap string, fmtp string) error {
|
||||||
t.PayloadTyp = payloadType
|
t.PayloadTyp = payloadType
|
||||||
|
|
||||||
if fmtp == "" {
|
if fmtp != "" {
|
||||||
return nil // do not return any error
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, kv := range strings.Split(fmtp, ";") {
|
for _, kv := range strings.Split(fmtp, ";") {
|
||||||
kv = strings.Trim(kv, " ")
|
kv = strings.Trim(kv, " ")
|
||||||
|
|
||||||
@@ -87,6 +84,7 @@ func (t *H265) unmarshal(payloadType uint8, clock string, codec string, rtpmap s
|
|||||||
t.MaxDONDiff = int(tmp)
|
t.MaxDONDiff = int(tmp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -39,10 +39,7 @@ func (t *MPEG4Audio) PayloadType() uint8 {
|
|||||||
func (t *MPEG4Audio) unmarshal(payloadType uint8, clock string, codec string, rtpmap string, fmtp string) error {
|
func (t *MPEG4Audio) unmarshal(payloadType uint8, clock string, codec string, rtpmap string, fmtp string) error {
|
||||||
t.PayloadTyp = payloadType
|
t.PayloadTyp = payloadType
|
||||||
|
|
||||||
if fmtp == "" {
|
if fmtp != "" {
|
||||||
return fmt.Errorf("fmtp attribute is missing")
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, kv := range strings.Split(fmtp, ";") {
|
for _, kv := range strings.Split(fmtp, ";") {
|
||||||
kv = strings.Trim(kv, " ")
|
kv = strings.Trim(kv, " ")
|
||||||
|
|
||||||
@@ -90,6 +87,7 @@ func (t *MPEG4Audio) unmarshal(payloadType uint8, clock string, codec string, rt
|
|||||||
t.IndexDeltaLength = int(val)
|
t.IndexDeltaLength = int(val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if t.Config == nil {
|
if t.Config == nil {
|
||||||
return fmt.Errorf("config is missing (%v)", fmtp)
|
return fmt.Errorf("config is missing (%v)", fmtp)
|
||||||
|
@@ -45,3 +45,27 @@ func TestMPEG4AudioMediaDescription(t *testing.T) {
|
|||||||
require.Equal(t, "profile-level-id=1; mode=AAC-hbr; sizelength=13;"+
|
require.Equal(t, "profile-level-id=1; mode=AAC-hbr; sizelength=13;"+
|
||||||
" indexlength=3; indexdeltalength=3; config=1190", fmtp)
|
" indexlength=3; indexdeltalength=3; config=1190", fmtp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMPEG4AudioDecEncoder(t *testing.T) {
|
||||||
|
format := &MPEG4Audio{
|
||||||
|
PayloadTyp: 96,
|
||||||
|
Config: &mpeg4audio.Config{
|
||||||
|
Type: mpeg4audio.ObjectTypeAACLC,
|
||||||
|
SampleRate: 48000,
|
||||||
|
ChannelCount: 2,
|
||||||
|
},
|
||||||
|
SizeLength: 13,
|
||||||
|
IndexLength: 3,
|
||||||
|
IndexDeltaLength: 3,
|
||||||
|
}
|
||||||
|
|
||||||
|
enc := format.CreateEncoder()
|
||||||
|
pkts, err := enc.Encode([][]byte{{0x01, 0x02, 0x03, 0x04}}, 0)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, format.PayloadType(), pkts[0].PayloadType)
|
||||||
|
|
||||||
|
dec := format.CreateDecoder()
|
||||||
|
byts, _, err := dec.Decode(pkts[0])
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, [][]byte{{0x01, 0x02, 0x03, 0x04}}, byts)
|
||||||
|
}
|
||||||
|
@@ -52,10 +52,7 @@ func (t *Vorbis) unmarshal(payloadType uint8, clock string, codec string, rtpmap
|
|||||||
}
|
}
|
||||||
t.ChannelCount = int(channelCount)
|
t.ChannelCount = int(channelCount)
|
||||||
|
|
||||||
if fmtp == "" {
|
if fmtp != "" {
|
||||||
return fmt.Errorf("fmtp attribute is missing")
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, kv := range strings.Split(fmtp, ";") {
|
for _, kv := range strings.Split(fmtp, ";") {
|
||||||
kv = strings.Trim(kv, " ")
|
kv = strings.Trim(kv, " ")
|
||||||
|
|
||||||
@@ -77,6 +74,7 @@ func (t *Vorbis) unmarshal(payloadType uint8, clock string, codec string, rtpmap
|
|||||||
t.Configuration = conf
|
t.Configuration = conf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if t.Configuration == nil {
|
if t.Configuration == nil {
|
||||||
return fmt.Errorf("config is missing (%v)", fmtp)
|
return fmt.Errorf("config is missing (%v)", fmtp)
|
||||||
|
@@ -1001,9 +1001,9 @@ func TestServerRecordRTCPReport(t *testing.T) {
|
|||||||
buf = make([]byte, 2048)
|
buf = make([]byte, 2048)
|
||||||
n, _, err := l2.ReadFrom(buf)
|
n, _, err := l2.ReadFrom(buf)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
pkt, err := rtcp.Unmarshal(buf[:n])
|
pkts, err := rtcp.Unmarshal(buf[:n])
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
rr, ok := pkt[0].(*rtcp.ReceiverReport)
|
rr, ok := pkts[0].(*rtcp.ReceiverReport)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
require.Equal(t, &rtcp.ReceiverReport{
|
require.Equal(t, &rtcp.ReceiverReport{
|
||||||
SSRC: rr.SSRC,
|
SSRC: rr.SSRC,
|
||||||
|
Reference in New Issue
Block a user