Request key frame on all layers.

Explicitly request key frame on all layers until proper mapping is
implemented (webrtc:10615).

Bug: webrtc:10585
Change-Id: I9722610920a753c50700d925ff6a1babf0011e2f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/136682
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Sergey Silkin <ssilkin@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27934}
diff --git a/modules/video_coding/codecs/h264/h264_encoder_impl.cc b/modules/video_coding/codecs/h264/h264_encoder_impl.cc
index 495c11a..a8135bc 100644
--- a/modules/video_coding/codecs/h264/h264_encoder_impl.cc
+++ b/modules/video_coding/codecs/h264/h264_encoder_impl.cc
@@ -409,11 +409,13 @@
       break;
     }
   }
+
   if (!send_key_frame && frame_types) {
-    for (size_t i = 0; i < frame_types->size() && i < configurations_.size();
-         ++i) {
-      if ((*frame_types)[i] == VideoFrameType::kVideoFrameKey &&
-          configurations_[i].sending) {
+    for (size_t i = 0; i < configurations_.size(); ++i) {
+      const size_t simulcast_idx =
+          static_cast<size_t>(configurations_[i].simulcast_idx);
+      if (configurations_[i].sending && simulcast_idx < frame_types->size() &&
+          (*frame_types)[simulcast_idx] == VideoFrameType::kVideoFrameKey) {
         send_key_frame = true;
         break;
       }
diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc
index 289a7b9..579c144 100644
--- a/video/video_stream_encoder.cc
+++ b/video/video_stream_encoder.cc
@@ -1358,7 +1358,11 @@
   RTC_DCHECK_RUN_ON(&encoder_queue_);
   TRACE_EVENT0("webrtc", "OnKeyFrameRequest");
   RTC_DCHECK(!next_frame_types_.empty());
-  next_frame_types_[0] = VideoFrameType::kVideoFrameKey;
+
+  // TODO(webrtc:10615): Map keyframe request to spatial layer.
+  std::fill(next_frame_types_.begin(), next_frame_types_.end(),
+            VideoFrameType::kVideoFrameKey);
+
   if (HasInternalSource()) {
     // Try to request the frame if we have an external encoder with
     // internal source since AddVideoFrame never will be called.
@@ -1377,7 +1381,8 @@
                              .build(),
                          &next_frame_types_) == WEBRTC_VIDEO_CODEC_OK) {
       // Try to remove just-performed keyframe request, if stream still exists.
-      next_frame_types_[0] = VideoFrameType::kVideoFrameDelta;
+      std::fill(next_frame_types_.begin(), next_frame_types_.end(),
+                VideoFrameType::kVideoFrameDelta);
     }
   }
 }
diff --git a/video/video_stream_encoder_unittest.cc b/video/video_stream_encoder_unittest.cc
index 18ab5b9..19451ec 100644
--- a/video/video_stream_encoder_unittest.cc
+++ b/video/video_stream_encoder_unittest.cc
@@ -3752,10 +3752,13 @@
   video_stream_encoder_->SendKeyFrame();
   video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr));
   WaitForEncodedFrame(3);
+
+  // TODO(webrtc:10615): Map keyframe request to spatial layer. Currently
+  // keyframe request on any layer triggers keyframe on all layers.
   EXPECT_THAT(fake_encoder_.LastFrameTypes(),
               ::testing::ElementsAreArray({VideoFrameType::kVideoFrameKey,
-                                           VideoFrameType::kVideoFrameDelta,
-                                           VideoFrameType::kVideoFrameDelta}));
+                                           VideoFrameType::kVideoFrameKey,
+                                           VideoFrameType::kVideoFrameKey}));
 
   video_stream_encoder_->Stop();
 }