Skip to content

Commit

Permalink
Fix buggy SDP from D-Link cameras #771
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Nov 22, 2023
1 parent a87dafb commit 051c5ff
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/rtsp/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ func UnmarshalSDP(rawSDP []byte) ([]*core.Media, error) {
}
}

// fix buggy camera https://github.com/AlexxIT/go2rtc/issues/771
forceDirection := sd.Origin.Username == "CV-RTSPHandler"

var medias []*core.Media

for _, md := range sd.MediaDescriptions {
Expand All @@ -65,7 +68,7 @@ func UnmarshalSDP(rawSDP []byte) ([]*core.Media, error) {
}
}

if media.Direction == "" {
if media.Direction == "" || forceDirection {
media.Direction = core.DirectionRecvonly
}

Expand Down
27 changes: 27 additions & 0 deletions pkg/rtsp/rtsp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,30 @@ a=control:track3
assert.Nil(t, err)
assert.Len(t, medias, 3)
}

func TestBugSDP5(t *testing.T) {
s := `v=0
o=CV-RTSPHandler 1123412 0 IN IP4 192.168.1.22
s=Camera
c=IN IP4 192.168.1.22
t=0 0
a=charset:Shift_JIS
a=range:npt=0-
a=control:*
a=etag:1234567890
m=video 0 RTP/AVP 99
a=rtpmap:99 H264/90000
a=fmtp:99 profile-level-id=42A01E;packetization-mode=1;sprop-parameter-sets=Z0KgKedAPAET8uAIEAABd2AAK/IGAAADAC+vCAAAHc1lP//jAAADABfXhAAADuayn//wIA==,aN48gA==
a=control:trackID=1
a=sendonly
m=audio 0 RTP/AVP 127
a=rtpmap:127 mpeg4-generic/8000/1
a=fmtp:127 streamtype=5; profile-level-id=15; mode=AAC-hbr; sizeLength=13; indexLength=3; indexDeltalength=3; config=1588; CTSDeltaLength=0; DTSDeltaLength=0;
a=control:trackID=2
`
medias, err := UnmarshalSDP([]byte(s))
assert.Nil(t, err)
assert.Len(t, medias, 2)
assert.Equal(t, "recvonly", medias[0].Direction)
assert.Equal(t, "recvonly", medias[1].Direction)
}

0 comments on commit 051c5ff

Please sign in to comment.