From 8771cf470da8bfaeffba2496eb578695eb4fe7c6 Mon Sep 17 00:00:00 2001 From: Fan Zhou Date: Thu, 22 Aug 2024 14:55:19 -0700 Subject: [PATCH] Allow gap on packet buffer fix with GFD The current solution does not work for GFD since GFD is only parsed from the first packet of the frame. As a result, to access the generic information, we have to check every packet when traversing the packet buffer to find the first packet of frame. This fix is necessary to ensure temporal scaling works correctly with GFD. Bug: webrtc:42225186 Change-Id: Iadda4ec690deab62c32eb6101583e6a6d75cfeaf Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/344840 Commit-Queue: Danil Chapovalov Reviewed-by: Sergey Silkin Reviewed-by: Danil Chapovalov Cr-Commit-Position: refs/heads/main@{#42836} --- modules/video_coding/packet_buffer.cc | 8 ++++++++ modules/video_coding/packet_buffer_unittest.cc | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/modules/video_coding/packet_buffer.cc b/modules/video_coding/packet_buffer.cc index b30e84078c..9d7b6e550c 100644 --- a/modules/video_coding/packet_buffer.cc +++ b/modules/video_coding/packet_buffer.cc @@ -279,6 +279,14 @@ std::vector> PacketBuffer::FindFrames( int idr_height = -1; bool full_frame_found = false; while (true) { + // GFD is only attached to first packet of frame, so update check on + // every packet. + if (buffer_[start_index] != nullptr) { + is_generic = buffer_[start_index]->video_header.generic.has_value(); + if (is_generic) { + is_h264_descriptor = false; + } + } ++tested_packets; if (!is_h264_descriptor) { diff --git a/modules/video_coding/packet_buffer_unittest.cc b/modules/video_coding/packet_buffer_unittest.cc index 39b9eea6cd..925d8f2876 100644 --- a/modules/video_coding/packet_buffer_unittest.cc +++ b/modules/video_coding/packet_buffer_unittest.cc @@ -827,6 +827,18 @@ TEST_F(PacketBufferH264FrameGap, DisallowFrameGapForH264NoGeneric) { IsEmpty()); } +TEST_F(PacketBufferH264FrameGap, + AllowFrameGapForH264WithGenericOnFirstPacketOnly) { + bool generic = true; + InsertH264(1, kKeyFrame, kFirst, kLast, 1001, {}, 0, 0, generic); + InsertH264(3, kDeltaFrame, kFirst, kNotLast, 1003, {}, 0, 0, generic); + // Second packet is not generic, but we can still output frame with 2 packets. + EXPECT_THAT( + InsertH264(4, kDeltaFrame, kNotFirst, kLast, 1003, {}, 0, 0, !generic) + .packets, + SizeIs(2)); +} + } // namespace } // namespace video_coding } // namespace webrtc