Send keyframe request if the DependencyDescriptor fail to parse due to missing video structure.

Bug: b/233610247
Change-Id: If471d9b81906c04f50a5f63e26408968adc8c275
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/265392
Reviewed-by: Erik Språng <sprang@webrtc.org>
Commit-Queue: Philip Eliasson <philipel@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37196}
diff --git a/video/rtp_video_stream_receiver2.cc b/video/rtp_video_stream_receiver2.cc
index 1463244..207da62 100644
--- a/video/rtp_video_stream_receiver2.cc
+++ b/video/rtp_video_stream_receiver2.cc
@@ -526,8 +526,18 @@
         rtp_packet, video_header.frame_type == VideoFrameType::kVideoFrameKey);
   }
 
-  if (generic_descriptor_state == kDropPacket)
+  if (generic_descriptor_state == kDropPacket) {
+    Timestamp now = clock_->CurrentTime();
+    if (video_structure_ == nullptr &&
+        next_keyframe_request_for_missing_video_structure_ < now) {
+      // No video structure received yet, most likely part of the initial
+      // keyframe was lost.
+      RequestKeyFrame();
+      next_keyframe_request_for_missing_video_structure_ =
+          now + TimeDelta::Seconds(1);
+    }
     return;
+  }
 
   // Color space should only be transmitted in the last packet of a frame,
   // therefore, neglect it otherwise so that last_color_space_ is not reset by
diff --git a/video/rtp_video_stream_receiver2.h b/video/rtp_video_stream_receiver2.h
index cb43b2c..8ed6ea0 100644
--- a/video/rtp_video_stream_receiver2.h
+++ b/video/rtp_video_stream_receiver2.h
@@ -404,6 +404,9 @@
       RTC_GUARDED_BY(packet_sequence_checker_);
   std::map<int64_t, RtpPacketInfo> packet_infos_
       RTC_GUARDED_BY(packet_sequence_checker_);
+
+  Timestamp next_keyframe_request_for_missing_video_structure_ =
+      Timestamp::MinusInfinity();
 };
 
 }  // namespace webrtc
diff --git a/video/rtp_video_stream_receiver2_unittest.cc b/video/rtp_video_stream_receiver2_unittest.cc
index 71cc1a7..0507da9 100644
--- a/video/rtp_video_stream_receiver2_unittest.cc
+++ b/video/rtp_video_stream_receiver2_unittest.cc
@@ -1109,6 +1109,26 @@
   InjectPacketWith(stream_structure2, deltaframe_descriptor);
 }
 
+TEST_F(RtpVideoStreamReceiver2DependencyDescriptorTest,
+       RequestKeyframeIfInitialKeyframePacketIsLost) {
+  FrameDependencyStructure stream_structure = CreateStreamStructure();
+
+  DependencyDescriptor keyframe_descriptor_without_structure;
+  keyframe_descriptor_without_structure.frame_dependencies =
+      stream_structure.templates[0];
+  keyframe_descriptor_without_structure.frame_number = 0;
+
+  EXPECT_CALL(mock_key_frame_request_sender_, RequestKeyFrame).Times(2);
+  InjectPacketWith(stream_structure, keyframe_descriptor_without_structure);
+
+  // Not enough time since last keyframe request
+  time_controller_.AdvanceTime(TimeDelta::Millis(500));
+  InjectPacketWith(stream_structure, keyframe_descriptor_without_structure);
+
+  time_controller_.AdvanceTime(TimeDelta::Millis(501));
+  InjectPacketWith(stream_structure, keyframe_descriptor_without_structure);
+}
+
 TEST_F(RtpVideoStreamReceiver2Test, TransformFrame) {
   rtc::scoped_refptr<MockFrameTransformer> mock_frame_transformer =
       rtc::make_ref_counted<testing::NiceMock<MockFrameTransformer>>();