Fix parsing SDP from Reolink Doorbell

This commit is contained in:
Alexey Khit
2023-02-07 20:02:23 +03:00
parent b05cbdf3d3
commit 9ed4d4cedb
2 changed files with 41 additions and 2 deletions
+6
View File
@@ -23,6 +23,12 @@ s=-
t=0 0`
func UnmarshalSDP(rawSDP []byte) ([]*streamer.Media, error) {
// fix bug from Reolink Doorbell
if i := bytes.Index(rawSDP, []byte("a=sendonlym=")); i > 0 {
rawSDP = append(rawSDP[:i+11], rawSDP[i+10:]...)
rawSDP[i+10] = '\n'
}
sd := &sdp.SessionDescription{}
if err := sd.Unmarshal(rawSDP); err != nil {
// fix multiple `s=` https://github.com/AlexxIT/WebRTC/issues/417
+35 -2
View File
@@ -19,7 +19,7 @@ func TestURLParse(t *testing.T) {
assert.Equal(t, "turret2-cam.lan:554", u.Host)
}
func TestMultipleSinSDP(t *testing.T) {
func TestBugSDP1(t *testing.T) {
// https://github.com/AlexxIT/WebRTC/issues/417
s := `v=0
o=- 91674849066 1 IN IP4 192.168.1.123
@@ -52,7 +52,7 @@ a=control:track1
assert.NotNil(t, medias)
}
func TestFindFmtp(t *testing.T) {
func TestBugSDP2(t *testing.T) {
// https://github.com/AlexxIT/WebRTC/issues/419
s := `v=0
o=- 1675628282 1675628283 IN IP4 192.168.1.123
@@ -73,3 +73,36 @@ a=fmtp:96 packetization-mode=1;profile-level-id=64001F;sprop-parameter-sets=Z0IA
assert.NotNil(t, medias)
assert.NotEqual(t, "", medias[0].Codecs[0].FmtpLine)
}
func TestBugSDP3(t *testing.T) {
s := `v=0
o=- 1675775048103026 1 IN IP4 192.168.1.123
s=Session streamed by "preview"
t=0 0
a=tool:LIVE555 Streaming Media v2020.08.12
a=type:broadcast
a=control:*
a=range:npt=0-
a=x-qt-text-nam:Session streamed by "preview"
m=video 0 RTP/AVP 96
c=IN IP4 0.0.0.0
b=AS:8192
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;profile-level-id=640033;sprop-parameter-sets=Z2QAM6wVFKAoAPGQ,aO48sA==
a=recvonly
a=control:track1
m=audio 0 RTP/AVP 8
a=control:track2
a=rtpmap:8 PCMA/8000
a=sendonlym=audio 0 RTP/AVP 98
c=IN IP4 0.0.0.0
b=AS:8192
a=rtpmap:98 MPEG4-GENERIC/16000
a=fmtp:98 streamtype=5;profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3;config=1408;
a=recvonly
a=control:track3
`
medias, err := UnmarshalSDP([]byte(s))
assert.Nil(t, err)
assert.Len(t, medias, 3)
}