Skip to content

Commit

Permalink
Fix wrong media values in SDP for some cameras #1278
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Jul 26, 2024
1 parent ed99025 commit d559ec0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/rtsp/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
42 changes: 42 additions & 0 deletions pkg/rtsp/rtsp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d559ec0

Please sign in to comment.