Populate generic descriptor based on GenericFrameInfo when available.

Bug: webrtc:10342
Change-Id: Iff769d2604fd79784bcb09874d2803793d20bde5
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/167000
Reviewed-by: Philip Eliasson <philipel@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30505}
diff --git a/call/rtp_payload_params_unittest.cc b/call/rtp_payload_params_unittest.cc
index ad5d8e1..b8fd4a5 100644
--- a/call/rtp_payload_params_unittest.cc
+++ b/call/rtp_payload_params_unittest.cc
@@ -371,6 +371,50 @@
   EXPECT_THAT(header.generic->dependencies, ElementsAre(0));
 }
 
+TEST(RtpPayloadParamsTest, SetsGenericFromGenericFrameInfo) {
+  test::ScopedFieldTrials generic_picture_id(
+      "WebRTC-GenericDescriptor/Enabled/");
+  RtpPayloadState state;
+  EncodedImage encoded_image;
+  CodecSpecificInfo codec_info;
+
+  RtpPayloadParams params(kSsrc1, &state);
+
+  encoded_image._frameType = VideoFrameType::kVideoFrameKey;
+  codec_info.generic_frame_info =
+      GenericFrameInfo::Builder().S(1).T(0).Dtis("S").Build();
+  codec_info.generic_frame_info->encoder_buffers = {
+      {/*id=*/0, /*referenced=*/false, /*updated=*/true}};
+  RTPVideoHeader key_header =
+      params.GetRtpVideoHeader(encoded_image, &codec_info, /*frame_id=*/1);
+
+  ASSERT_TRUE(key_header.generic);
+  EXPECT_EQ(key_header.generic->spatial_index, 1);
+  EXPECT_EQ(key_header.generic->temporal_index, 0);
+  EXPECT_EQ(key_header.generic->frame_id, 1);
+  EXPECT_THAT(key_header.generic->dependencies, IsEmpty());
+  EXPECT_THAT(key_header.generic->decode_target_indications,
+              ElementsAre(DecodeTargetIndication::kSwitch));
+  EXPECT_FALSE(key_header.generic->discardable);
+
+  encoded_image._frameType = VideoFrameType::kVideoFrameDelta;
+  codec_info.generic_frame_info =
+      GenericFrameInfo::Builder().S(2).T(3).Dtis("D").Build();
+  codec_info.generic_frame_info->encoder_buffers = {
+      {/*id=*/0, /*referenced=*/true, /*updated=*/false}};
+  RTPVideoHeader delta_header =
+      params.GetRtpVideoHeader(encoded_image, &codec_info, /*frame_id=*/3);
+
+  ASSERT_TRUE(delta_header.generic);
+  EXPECT_EQ(delta_header.generic->spatial_index, 2);
+  EXPECT_EQ(delta_header.generic->temporal_index, 3);
+  EXPECT_EQ(delta_header.generic->frame_id, 3);
+  EXPECT_THAT(delta_header.generic->dependencies, ElementsAre(1));
+  EXPECT_THAT(delta_header.generic->decode_target_indications,
+              ElementsAre(DecodeTargetIndication::kDiscardable));
+  EXPECT_TRUE(delta_header.generic->discardable);
+}
+
 class RtpPayloadParamsVp8ToGenericTest : public ::testing::Test {
  public:
   enum LayerSync { kNoSync, kSync };