From fb803de683585ebadb0137f1cbbc54e36a50fc77 Mon Sep 17 00:00:00 2001 From: Sergio Garcia Murillo Date: Thu, 3 Oct 2024 16:07:51 +0200 Subject: [PATCH] Fix is_first_packet_in_frame for SEI and PPS NALUs PacketBuffer will ignore any non-idr frame which is firs packet has not is_first_packet_in_frame set to true if there was a packet loss in the previous frame even if the cseqs are continous: https://issues.webrtc.org/issues/368335257#comment14 This CL sets this flag to true to SEI and PPS nal units that would have caused the delta frames after an idr frame to be dropped in case of loss. Bug: webrtc:368335257 Change-Id: Ic7150297d7fb4ed274c7d99175ff367100b5cf75 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/364241 Reviewed-by: Sergey Silkin Commit-Queue: Danil Chapovalov Reviewed-by: Danil Chapovalov Cr-Commit-Position: refs/heads/main@{#43168} --- .../source/video_rtp_depacketizer_h264.cc | 6 +++-- .../video_rtp_depacketizer_h264_unittest.cc | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/modules/rtp_rtcp/source/video_rtp_depacketizer_h264.cc b/modules/rtp_rtcp/source/video_rtp_depacketizer_h264.cc index 19ada0fa6f..49cc1af7d4 100644 --- a/modules/rtp_rtcp/source/video_rtp_depacketizer_h264.cc +++ b/modules/rtp_rtcp/source/video_rtp_depacketizer_h264.cc @@ -188,6 +188,7 @@ std::optional ProcessStapAOrSingleNalu( << "Failed to parse PPS id and SPS id from PPS slice."; return std::nullopt; } + parsed_payload->video_header.is_first_packet_in_frame = true; break; } case H264::NaluType::kIdr: @@ -212,12 +213,13 @@ std::optional ProcessStapAOrSingleNalu( case H264::NaluType::kAud: parsed_payload->video_header.is_first_packet_in_frame = true; break; + case H264::NaluType::kSei: + parsed_payload->video_header.is_first_packet_in_frame = true; + break; // Slices below don't contain SPS or PPS ids. case H264::NaluType::kEndOfSequence: case H264::NaluType::kEndOfStream: case H264::NaluType::kFiller: - case H264::NaluType::kSei: - break; case H264::NaluType::kStapA: case H264::NaluType::kFuA: RTC_LOG(LS_WARNING) << "Unexpected STAP-A or FU-A received."; diff --git a/modules/rtp_rtcp/source/video_rtp_depacketizer_h264_unittest.cc b/modules/rtp_rtcp/source/video_rtp_depacketizer_h264_unittest.cc index d73d10f415..8f1d272b77 100644 --- a/modules/rtp_rtcp/source/video_rtp_depacketizer_h264_unittest.cc +++ b/modules/rtp_rtcp/source/video_rtp_depacketizer_h264_unittest.cc @@ -517,5 +517,30 @@ TEST(VideoRtpDepacketizerH264Test, AudSetsFirstPacketInFrame) { EXPECT_TRUE(parsed->video_header.is_first_packet_in_frame); } +TEST(VideoRtpDepacketizerH264Test, PpsSetsFirstPacketInFrame) { + const uint8_t kPayload[] = { + 0x08, 0x69, 0xFC, 0x0, 0x0, 0x3, 0x0, + 0x7, 0xFF, 0xFF, 0xFF, 0xF6, 0x40 // PPS. + }; + + VideoRtpDepacketizerH264 depacketizer; + std::optional parsed = + depacketizer.Parse(rtc::CopyOnWriteBuffer(kPayload)); + ASSERT_TRUE(parsed); + EXPECT_TRUE(parsed->video_header.is_first_packet_in_frame); +} + +TEST(VideoRtpDepacketizerH264Test, SeiSetsFirstPacketInFrame) { + const uint8_t kPayload[] = { + 0x06, 0x05, 0x04, 0xDE, 0xAD, 0xBE, 0xEF, 0x80 // SEI. + }; + + VideoRtpDepacketizerH264 depacketizer; + std::optional parsed = + depacketizer.Parse(rtc::CopyOnWriteBuffer(kPayload)); + ASSERT_TRUE(parsed); + EXPECT_TRUE(parsed->video_header.is_first_packet_in_frame); +} + } // namespace } // namespace webrtc