Skip to content

Commit

Permalink
Fix wrong SDP for MERCURY camera #708
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Oct 27, 2023
1 parent 8bc65e4 commit c27e735
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
5 changes: 2 additions & 3 deletions pkg/rtsp/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ func UnmarshalSDP(rawSDP []byte) ([]*core.Media, error) {

// Fix invalid media type (errSDPInvalidValue) caused by
// some TP-LINK IP camera, e.g. TL-IPC44GW
rawSDP = bytes.ReplaceAll(rawSDP, []byte("m=application/TP-LINK "), []byte("m=application "))
// more tplink ipcams
rawSDP = bytes.ReplaceAll(rawSDP, []byte("m=application/tp-link "), []byte("m=application "))
m := regexp.MustCompile("m=application/[^ ]+")
rawSDP = m.ReplaceAll(rawSDP, []byte("m=application"))

if err == io.EOF {
rawSDP = append(rawSDP, '\n')
Expand Down
27 changes: 26 additions & 1 deletion pkg/rtsp/rtsp_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package rtsp

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestURLParse(t *testing.T) {
Expand Down Expand Up @@ -107,3 +108,27 @@ a=sendonly`
assert.Nil(t, err)
assert.Len(t, medias, 3)
}

func TestBugSDP4(t *testing.T) {
s := `v=0
o=- 14665860 31787219 1 IN IP4 10.0.0.94
s=Session streamed by "MERCURY RTSP Server"
t=0 0
m=video 0 RTP/AVP 96
c=IN IP4 0.0.0.0
b=AS:4096
a=range:npt=0-
a=control:track1
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1; profile-level-id=640016; sprop-parameter-sets=Z2QAFqzGoCgPaEAAAAMAQAAAB6E=,aOqPLA==
m=audio 0 RTP/AVP 8
a=rtpmap:8 PCMA/8000
a=control:track2
m=application/MERCURY 0 RTP/AVP smart/1/90000
a=rtpmap:95 MERCURY/90000
a=control:track3
`
medias, err := UnmarshalSDP([]byte(s))
assert.Nil(t, err)
assert.Len(t, medias, 3)
}

0 comments on commit c27e735

Please sign in to comment.