Skip to content

Commit

Permalink
Fix SDP parsing for Ezviz C6N
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Feb 17, 2023
1 parent 338da2a commit 91399d3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/rtsp/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ func UnmarshalSDP(rawSDP []byte) ([]*streamer.Media, error) {
rawSDP[i+10] = '\n'
}

// fix bug from Ezviz C6N
if i := bytes.Index(rawSDP, []byte("H265/90000\r\na=fmtp:96 profile-level-id=420029;")); i > 0 {
rawSDP[i+3] = '4'
}

sd := &sdp.SessionDescription{}
if err := sd.Unmarshal(rawSDP); err != nil {
// fix multiple `s=` https://github.com/AlexxIT/WebRTC/issues/417
Expand Down
33 changes: 33 additions & 0 deletions pkg/rtsp/rtsp_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package rtsp

import (
"github.com/AlexxIT/go2rtc/pkg/h264"
"github.com/AlexxIT/go2rtc/pkg/streamer"
"github.com/stretchr/testify/assert"
"strings"
"testing"
)

Expand Down Expand Up @@ -106,3 +109,33 @@ a=control:track3
assert.Nil(t, err)
assert.Len(t, medias, 3)
}

func TestBugSDP4(t *testing.T) {
s := `v=0
o=- 1676583297494652 1676583297494652 IN IP4 192.168.1.58
s=Media Presentation
e=NONE
b=AS:5050
t=0 0
a=control:rtsp://192.168.1.58:554/h264_stream/
m=video 0 RTP/AVP 96
b=AS:5000
a=control:rtsp://192.168.1.58:554/h264_stream/trackID=1
a=rtpmap:96 H265/90000
a=fmtp:96 profile-level-id=420029; packetization-mode=1; sprop-parameter-sets=
a=Media_header:MEDIAINFO=494D4B48010100000400050000000000000000000000000000000000000000000000000000000000;
a=appversion:1.0
`
s = strings.ReplaceAll(s, "\n", "\r\n")
medias, err := UnmarshalSDP([]byte(s))
assert.Nil(t, err)

codec := medias[0].Codecs[0]
assert.Equal(t, streamer.CodecH264, codec.Name)

sps, _ := h264.GetParameterSet(codec.FmtpLine)
assert.Nil(t, sps)

profile := h264.GetProfileLevelID(codec.FmtpLine)
assert.Equal(t, "420029", profile)
}

0 comments on commit 91399d3

Please # to comment.