Signaling for low-latency renderer algorithm

This feature is active if and only if the RTP header extension
playout-delay is used with min playout delay=0 and max playout delay>0.

In this case, a maximum composition delay will be calculated and attached
to the video frame as a signal to use the low-latency renderer algorithm,
which is landed in a separate CL in Chromium.

The maximum composition delay is specified in number of frames and is
calculated based on the max playout delay.

The feature can be completetly disabled by specifying the field trial
WebRTC-LowLatencyRenderer/enabled:false/

Bug: chromium:1138888
Change-Id: I05f461982d0632bd6e09e5d7ec1a8985dccdc61b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/190141
Reviewed-by: Niels Moller <nisse@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Johannes Kron <kron@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32493}
diff --git a/modules/video_coding/generic_decoder_unittest.cc b/modules/video_coding/generic_decoder_unittest.cc
index dbceb18..a4cc5b0 100644
--- a/modules/video_coding/generic_decoder_unittest.cc
+++ b/modules/video_coding/generic_decoder_unittest.cc
@@ -115,5 +115,29 @@
   EXPECT_EQ(decoded_frame->packet_infos().size(), 3U);
 }
 
+TEST_F(GenericDecoderTest, MaxCompositionDelayNotSetByDefault) {
+  VCMEncodedFrame encoded_frame;
+  generic_decoder_.Decode(encoded_frame, clock_.CurrentTime());
+  absl::optional<VideoFrame> decoded_frame = user_callback_.WaitForFrame(10);
+  ASSERT_TRUE(decoded_frame.has_value());
+  EXPECT_FALSE(decoded_frame->max_composition_delay_in_frames());
+}
+
+TEST_F(GenericDecoderTest, MaxCompositionDelayActivatedByPlayoutDelay) {
+  VCMEncodedFrame encoded_frame;
+  // VideoReceiveStream2 would set MaxCompositionDelayInFrames if playout delay
+  // is specified as X,Y, where X=0, Y>0.
+  const VideoPlayoutDelay kPlayoutDelay = {0, 50};
+  constexpr int kMaxCompositionDelayInFrames = 3;  // ~50 ms at 60 fps.
+  encoded_frame.SetPlayoutDelay(kPlayoutDelay);
+  timing_.SetMaxCompositionDelayInFrames(
+      absl::make_optional(kMaxCompositionDelayInFrames));
+  generic_decoder_.Decode(encoded_frame, clock_.CurrentTime());
+  absl::optional<VideoFrame> decoded_frame = user_callback_.WaitForFrame(10);
+  ASSERT_TRUE(decoded_frame.has_value());
+  EXPECT_EQ(kMaxCompositionDelayInFrames,
+            decoded_frame->max_composition_delay_in_frames());
+}
+
 }  // namespace video_coding
 }  // namespace webrtc