From 8cee4179f2c71bee7d214ca1235b7866b038b45b Mon Sep 17 00:00:00 2001 From: Alexey Khit Date: Fri, 3 Feb 2023 12:54:42 +0300 Subject: [PATCH] Fix another buggy Chinese cameras --- pkg/h264/rtp.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/h264/rtp.go b/pkg/h264/rtp.go index 6044caae..024ccf74 100644 --- a/pkg/h264/rtp.go +++ b/pkg/h264/rtp.go @@ -10,6 +10,8 @@ import ( const RTPPacketVersionAVC = 0 +const PSMaxSize = 128 // the biggest SPS I've seen is 48 (EZVIZ CS-CV210) + func RTPDepay(track *streamer.Track) streamer.WrapperFunc { depack := &codecs.H264Packet{IsAVC: true} @@ -29,7 +31,7 @@ func RTPDepay(track *streamer.Track) streamer.WrapperFunc { // Fix TP-Link Tapo TC70: sends SPS and PPS with packet.Marker = true // Reolink Duo 2: sends SPS with Marker and PPS without - if packet.Marker && len(payload) < 128 { + if packet.Marker && len(payload) < PSMaxSize { switch NALUType(payload) { case NALUTypeSPS, NALUTypePPS: buf = append(buf, payload...) @@ -70,7 +72,10 @@ func RTPDepay(track *streamer.Track) streamer.WrapperFunc { if len(buf) > 0 { payload = append(buf, payload...) buf = buf[:0] - } else { + } + + // should not be that huge SPS + if NALUType(payload) == NALUTypeSPS && binary.BigEndian.Uint32(payload) >= PSMaxSize { // some Chinese buggy cameras has single packet with SPS+PPS+IFrame separated by 00 00 00 01 // https://github.com/AlexxIT/WebRTC/issues/391 // https://github.com/AlexxIT/WebRTC/issues/392