Consolidate temporal layer limit to kMaxTemporalStreams The VP8 and VP9 RTP reference finders defined their own local constant, `kMaxTemporalLayers`, with a value of 5. This was inconsistent with the global constant `kMaxTemporalStreams`, which has a value of 4 and is used for this purpose elsewhere. This patch removes the redundant local `kMaxTemporalLayers` definitions in `rtp_vp8_ref_finder.h` and `rtp_vp9_ref_finder.h`. All usages (array bounds, frame validation checks, and log messages) are updated to use the global `kMaxTemporalStreams` constant instead. This change aligns the validation logic with the rest of the codebase, dropping frames with a temporal index of 4 or greater. Fixed: chromium:456855150 Change-Id: I0de0b2b765ccf9bef30dfbca504b9c9f7179dabe Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/422720 Reviewed-by: Erik Språng <sprang@webrtc.org> Commit-Queue: Johannes Kron <kron@webrtc.org> Cr-Commit-Position: refs/heads/main@{#48002}
diff --git a/modules/video_coding/rtp_vp8_ref_finder.cc b/modules/video_coding/rtp_vp8_ref_finder.cc index c88b08a..fb7e511 100644 --- a/modules/video_coding/rtp_vp8_ref_finder.cc +++ b/modules/video_coding/rtp_vp8_ref_finder.cc
@@ -15,6 +15,7 @@ #include <memory> #include <utility> +#include "api/video/video_codec_constants.h" #include "modules/rtp_rtcp/source/frame_object.h" #include "modules/video_coding/codecs/interface/common_constants.h" #include "modules/video_coding/codecs/vp8/include/vp8_globals.h" @@ -62,7 +63,7 @@ const RTPVideoHeaderVP8& codec_header, int64_t unwrapped_tl0) { // Protect against corrupted packets with arbitrary large temporal idx. - if (codec_header.temporalIdx >= kMaxTemporalLayers) + if (codec_header.temporalIdx >= kMaxTemporalStreams) return kDrop; frame->SetSpatialIndex(0);
diff --git a/modules/video_coding/rtp_vp8_ref_finder.h b/modules/video_coding/rtp_vp8_ref_finder.h index 8f581ca..49b2f77 100644 --- a/modules/video_coding/rtp_vp8_ref_finder.h +++ b/modules/video_coding/rtp_vp8_ref_finder.h
@@ -18,6 +18,7 @@ #include <memory> #include <set> +#include "api/video/video_codec_constants.h" #include "modules/rtp_rtcp/source/frame_object.h" #include "modules/video_coding/codecs/vp8/include/vp8_globals.h" #include "modules/video_coding/rtp_frame_reference_finder.h" @@ -39,7 +40,6 @@ static constexpr int kMaxLayerInfo = 50; static constexpr int kMaxNotYetReceivedFrames = 100; static constexpr int kMaxStashedFrames = 100; - static constexpr int kMaxTemporalLayers = 5; struct UnwrappedTl0Frame { int64_t unwrapped_tl0; @@ -72,7 +72,7 @@ // Holds the information about the last completed frame for a given temporal // layer given an unwrapped Tl0 picture index. - std::map<int64_t, std::array<int64_t, kMaxTemporalLayers>> layer_info_; + std::map<int64_t, std::array<int64_t, kMaxTemporalStreams>> layer_info_; // Unwrapper used to unwrap VP8/VP9 streams which have their picture id // specified.
diff --git a/modules/video_coding/rtp_vp9_ref_finder.cc b/modules/video_coding/rtp_vp9_ref_finder.cc index ab2345f..ccc2d7b 100644 --- a/modules/video_coding/rtp_vp9_ref_finder.cc +++ b/modules/video_coding/rtp_vp9_ref_finder.cc
@@ -33,7 +33,7 @@ const RTPVideoHeaderVP9& codec_header = std::get<RTPVideoHeaderVP9>(frame->GetRtpVideoHeader().video_type_header); - if (codec_header.temporal_idx >= kMaxTemporalLayers || + if (codec_header.temporal_idx >= kMaxTemporalStreams || codec_header.spatial_idx >= kMaxSpatialLayers) { return {}; } @@ -234,8 +234,8 @@ size_t gof_idx = diff % info.gof->num_frames_in_gof; size_t temporal_idx = info.gof->temporal_idx[gof_idx]; - if (temporal_idx >= kMaxTemporalLayers) { - RTC_LOG(LS_WARNING) << "At most " << kMaxTemporalLayers + if (temporal_idx >= kMaxTemporalStreams) { + RTC_LOG(LS_WARNING) << "At most " << kMaxTemporalStreams << " temporal " "layers are supported."; return true; @@ -277,8 +277,8 @@ RTC_CHECK(gof_idx < kMaxVp9FramesInGof); size_t temporal_idx = info->gof->temporal_idx[gof_idx]; - if (temporal_idx >= kMaxTemporalLayers) { - RTC_LOG(LS_WARNING) << "At most " << kMaxTemporalLayers + if (temporal_idx >= kMaxTemporalStreams) { + RTC_LOG(LS_WARNING) << "At most " << kMaxTemporalStreams << " temporal " "layers are supported."; return; @@ -296,8 +296,8 @@ RTC_CHECK(gof_idx < kMaxVp9FramesInGof); size_t temporal_idx = info->gof->temporal_idx[gof_idx]; - if (temporal_idx >= kMaxTemporalLayers) { - RTC_LOG(LS_WARNING) << "At most " << kMaxTemporalLayers + if (temporal_idx >= kMaxTemporalStreams) { + RTC_LOG(LS_WARNING) << "At most " << kMaxTemporalStreams << " temporal " "layers are supported."; return;
diff --git a/modules/video_coding/rtp_vp9_ref_finder.h b/modules/video_coding/rtp_vp9_ref_finder.h index d28a787..c9765fe 100644 --- a/modules/video_coding/rtp_vp9_ref_finder.h +++ b/modules/video_coding/rtp_vp9_ref_finder.h
@@ -18,6 +18,7 @@ #include <memory> #include <set> +#include "api/video/video_codec_constants.h" #include "modules/rtp_rtcp/source/frame_object.h" #include "modules/video_coding/codecs/vp9/include/vp9_globals.h" #include "modules/video_coding/rtp_frame_reference_finder.h" @@ -40,7 +41,6 @@ static constexpr int kMaxLayerInfo = 50; static constexpr int kMaxNotYetReceivedFrames = 100; static constexpr int kMaxStashedFrames = 100; - static constexpr int kMaxTemporalLayers = 5; enum FrameDecision { kStash, kHandOff, kDrop }; @@ -93,7 +93,7 @@ // For every temporal layer, keep a set of which frames that are missing. std::array<std::set<uint16_t, DescendingSeqNumComp<uint16_t, kFrameIdLength>>, - kMaxTemporalLayers> + kMaxTemporalStreams> missing_frames_for_layer_; // Unwrapper used to unwrap VP8/VP9 streams which have their picture id
diff --git a/modules/video_coding/rtp_vp9_ref_finder_unittest.cc b/modules/video_coding/rtp_vp9_ref_finder_unittest.cc index 17ca806..b143290 100644 --- a/modules/video_coding/rtp_vp9_ref_finder_unittest.cc +++ b/modules/video_coding/rtp_vp9_ref_finder_unittest.cc
@@ -612,10 +612,9 @@ } TEST_F(RtpVp9RefFinderTest, GofTidTooHigh) { - const int kMaxTemporalLayers = 5; GofInfoVP9 ss; ss.SetGofInfoVP9(kTemporalStructureMode2); - ss.temporal_idx[1] = kMaxTemporalLayers; + ss.temporal_idx[1] = kMaxTemporalStreams; Insert(Frame().Pid(0).SidAndTid(0, 0).Tl0(0).AsKeyFrame().NotAsInterPic().Gof( &ss)); @@ -666,14 +665,18 @@ } TEST_F(RtpVp9RefFinderTest, TemporalIndexTooHighDropsFrame) { - // kMaxTemporalLayers is 5. - Insert(Frame().Pid(0).SidAndTid(0, 5).AsKeyFrame()); + Insert(Frame().Pid(0).SidAndTid(0, kMaxTemporalStreams).AsKeyFrame()); EXPECT_THAT(frames_, SizeIs(0)); // Using a GoF frame type. GofInfoVP9 ss; ss.SetGofInfoVP9(kTemporalStructureMode1); - Insert(Frame().Pid(1).SidAndTid(0, 5).Tl0(0).AsKeyFrame().Gof(&ss)); + Insert(Frame() + .Pid(1) + .SidAndTid(0, kMaxTemporalStreams) + .Tl0(0) + .AsKeyFrame() + .Gof(&ss)); EXPECT_THAT(frames_, SizeIs(0)); }