From 58146b7e7e8ee6b52a54d6c233c3ef23946ea6c3 Mon Sep 17 00:00:00 2001 From: Alexey Khit Date: Thu, 9 Feb 2023 06:43:08 +0300 Subject: [PATCH] Fix H265 processing for RtspServer project #244 --- pkg/h265/helper.go | 18 ++++++++++-------- pkg/h265/rtp.go | 10 ++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/pkg/h265/helper.go b/pkg/h265/helper.go index 937cb2f7..345b9687 100644 --- a/pkg/h265/helper.go +++ b/pkg/h265/helper.go @@ -7,14 +7,16 @@ import ( ) const ( - NALUTypePFrame = 1 - NALUTypeIFrame = 19 - NALUTypeIFrame2 = 20 - NALUTypeIFrame3 = 21 - NALUTypeVPS = 32 - NALUTypeSPS = 33 - NALUTypePPS = 34 - NALUTypeFU = 49 + NALUTypePFrame = 1 + NALUTypeIFrame = 19 + NALUTypeIFrame2 = 20 + NALUTypeIFrame3 = 21 + NALUTypeVPS = 32 + NALUTypeSPS = 33 + NALUTypePPS = 34 + NALUTypePrefixSEI = 39 + NALUTypeSuffixSEI = 40 + NALUTypeFU = 49 ) func NALUType(b []byte) byte { diff --git a/pkg/h265/rtp.go b/pkg/h265/rtp.go index e9dfa1c1..9fae2546 100644 --- a/pkg/h265/rtp.go +++ b/pkg/h265/rtp.go @@ -20,6 +20,16 @@ func RTPDepay(track *streamer.Track) streamer.WrapperFunc { nuType := (data[0] >> 1) & 0x3F //log.Printf("[RTP] codec: %s, nalu: %2d, size: %6d, ts: %10d, pt: %2d, ssrc: %d, seq: %d, %v", track.Codec.Name, nuType, len(packet.Payload), packet.Timestamp, packet.PayloadType, packet.SSRC, packet.SequenceNumber, packet.Marker) + // Fix for RtspServer https://github.com/AlexxIT/go2rtc/issues/244 + if packet.Marker && len(data) < h264.PSMaxSize { + switch nuType { + case NALUTypeVPS, NALUTypeSPS, NALUTypePPS: + packet.Marker = false + case NALUTypePrefixSEI, NALUTypeSuffixSEI: + return nil + } + } + if nuType == NALUTypeFU { switch data[2] >> 6 { case 2: // begin