From 91399d3194aeb451a90b86a4c5434abc95a10087 Mon Sep 17 00:00:00 2001 From: Alexey Khit Date: Fri, 17 Feb 2023 12:38:41 +0300 Subject: [PATCH] Fix SDP parsing for Ezviz C6N --- pkg/rtsp/helpers.go | 5 +++++ pkg/rtsp/rtsp_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/pkg/rtsp/helpers.go b/pkg/rtsp/helpers.go index c43dcea5..fd7aa487 100644 --- a/pkg/rtsp/helpers.go +++ b/pkg/rtsp/helpers.go @@ -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 diff --git a/pkg/rtsp/rtsp_test.go b/pkg/rtsp/rtsp_test.go index 471dc271..d618fdc6 100644 --- a/pkg/rtsp/rtsp_test.go +++ b/pkg/rtsp/rtsp_test.go @@ -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" ) @@ -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) +}