Fix wrong media values in SDP for some cameras #1278

This commit is contained in:
Alex X
2024-07-26 17:00:16 +03:00
parent ed99025bd6
commit d559ec0208
2 changed files with 50 additions and 2 deletions

View File

@@ -38,8 +38,14 @@ func UnmarshalSDP(rawSDP []byte) ([]*core.Media, error) {
// Fix invalid media type (errSDPInvalidValue) caused by
// some TP-LINK IP camera, e.g. TL-IPC44GW
m := regexp.MustCompile("m=application/[^ ]+")
rawSDP = m.ReplaceAll(rawSDP, []byte("m=application"))
m := regexp.MustCompile("m=[^ ]+ ")
for _, i := range m.FindAll(rawSDP, -1) {
switch string(i[2 : len(i)-1]) {
case "audio", "video", "application":
default:
rawSDP = bytes.Replace(rawSDP, i, []byte("m=application "), 1)
}
}
if err == io.EOF {
rawSDP = append(rawSDP, '\n')

View File

@@ -161,6 +161,48 @@ a=control:trackID=2
assert.Equal(t, "recvonly", medias[1].Direction)
}
func TestBugSDP6(t *testing.T) {
// https://github.com/AlexxIT/go2rtc/issues/1278
s := `v=0
o=- 3730506281693 1 IN IP4 172.20.0.215
s=IP camera Live streaming
i=stream1
t=0 0
a=tool:LIVE555 Streaming Media v2014.02.04
a=type:broadcast
a=control:*
a=range:npt=0-
a=x-qt-text-nam:IP camera Live streaming
a=x-qt-text-inf:stream1
m=video 0 RTP/AVP 26
c=IN IP4 172.20.0.215
b=AS:1500
a=x-bufferdelay:0.55000
a=x-dimensions:1280,960
a=control:track1
m=audio 0 RTP/AVP 0
c=IN IP4 172.20.0.215
b=AS:64
a=x-bufferdelay:0.55000
a=control:track2
m=application 0 RTP/AVP 107
c=IN IP4 172.20.0.215
b=AS:1
a=x-bufferdelay:0.55000
a=rtpmap:107 vnd.onvif.metadata/90000/500
a=control:track4
m=vana 0 RTP/AVP 108
c=IN IP4 172.20.0.215
b=AS:1
a=x-bufferdelay:0.55000
a=rtpmap:108 video.analysis/90000/500
a=control:track5
`
medias, err := UnmarshalSDP([]byte(s))
assert.Nil(t, err)
assert.Len(t, medias, 4)
}
func TestHikvisionPCM(t *testing.T) {
s := `v=0
o=- 1721969533379665 1721969533379665 IN IP4 192.168.1.12