Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include "video/video_receive_stream2.h" |
| 12 | |
| 13 | #include <algorithm> |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 14 | #include <cstddef> |
Philipp Hancke | 80859bc | 2025-04-10 18:04:54 | [diff] [blame] | 15 | #include <cstdint> |
| 16 | #include <cstring> |
Evan Shrubsole | 7cbd8de | 2022-08-16 08:08:53 | [diff] [blame] | 17 | #include <deque> |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 18 | #include <limits> |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 19 | #include <memory> |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 20 | #include <optional> |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 21 | #include <utility> |
| 22 | #include <vector> |
| 23 | |
Evan Shrubsole | 6dbc172 | 2022-03-22 11:20:11 | [diff] [blame] | 24 | #include "absl/memory/memory.h" |
Philipp Hancke | ce6aa1f | 2025-04-28 18:59:22 | [diff] [blame] | 25 | #include "api/array_view.h" |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 26 | #include "api/environment/environment.h" |
| 27 | #include "api/environment/environment_factory.h" |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 28 | #include "api/metronome/test/fake_metronome.h" |
Philipp Hancke | 80859bc | 2025-04-10 18:04:54 | [diff] [blame] | 29 | #include "api/rtp_packet_info.h" |
| 30 | #include "api/rtp_packet_infos.h" |
Danil Chapovalov | 9cd4d49 | 2021-08-03 12:59:00 | [diff] [blame] | 31 | #include "api/test/mock_video_decoder.h" |
| 32 | #include "api/test/mock_video_decoder_factory.h" |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 33 | #include "api/test/time_controller.h" |
Philipp Hancke | 80859bc | 2025-04-10 18:04:54 | [diff] [blame] | 34 | #include "api/transport/rtp/rtp_source.h" |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 35 | #include "api/units/frequency.h" |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 36 | #include "api/units/time_delta.h" |
Philipp Hancke | 80859bc | 2025-04-10 18:04:54 | [diff] [blame] | 37 | #include "api/units/timestamp.h" |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 38 | #include "api/video/recordable_encoded_frame.h" |
| 39 | #include "api/video/test/video_frame_matchers.h" |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 40 | #include "api/video/video_frame.h" |
Philipp Hancke | 80859bc | 2025-04-10 18:04:54 | [diff] [blame] | 41 | #include "api/video/video_frame_type.h" |
| 42 | #include "api/video/video_rotation.h" |
| 43 | #include "api/video/video_sink_interface.h" |
| 44 | #include "api/video/video_timing.h" |
Evan Shrubsole | 1c18477 | 2022-04-26 07:47:49 | [diff] [blame] | 45 | #include "api/video_codecs/sdp_video_format.h" |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 46 | #include "call/rtp_stream_receiver_controller.h" |
Evan Shrubsole | 1c18477 | 2022-04-26 07:47:49 | [diff] [blame] | 47 | #include "call/video_receive_stream.h" |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 48 | #include "common_video/test/utilities.h" |
Tommi | 90738dd | 2021-05-31 15:36:47 | [diff] [blame] | 49 | #include "media/engine/fake_webrtc_call.h" |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 50 | #include "modules/pacing/packet_router.h" |
| 51 | #include "modules/rtp_rtcp/source/rtp_packet_to_send.h" |
Philipp Hancke | 80859bc | 2025-04-10 18:04:54 | [diff] [blame] | 52 | #include "modules/video_coding/nack_requester.h" |
Evan Shrubsole | dcb9c5d | 2022-06-13 15:39:53 | [diff] [blame] | 53 | #include "rtc_base/logging.h" |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 54 | #include "system_wrappers/include/clock.h" |
| 55 | #include "test/fake_decoder.h" |
Evan Shrubsole | a0ee64c | 2022-04-26 08:09:04 | [diff] [blame] | 56 | #include "test/fake_encoded_frame.h" |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 57 | #include "test/gmock.h" |
| 58 | #include "test/gtest.h" |
Danil Chapovalov | 9cd4d49 | 2021-08-03 12:59:00 | [diff] [blame] | 59 | #include "test/mock_transport.h" |
philipel | 27b35a7 | 2022-07-05 07:59:55 | [diff] [blame] | 60 | #include "test/rtcp_packet_parser.h" |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 61 | #include "test/time_controller/simulated_time_controller.h" |
| 62 | #include "test/video_decoder_proxy_factory.h" |
| 63 | #include "video/call_stats2.h" |
Philipp Hancke | 80859bc | 2025-04-10 18:04:54 | [diff] [blame] | 64 | #include "video/decode_synchronizer.h" |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 65 | |
| 66 | namespace webrtc { |
Evan Shrubsole | 1c18477 | 2022-04-26 07:47:49 | [diff] [blame] | 67 | |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 68 | namespace { |
| 69 | |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 70 | using test::video_frame_matchers::NtpTimestamp; |
| 71 | using test::video_frame_matchers::PacketInfos; |
| 72 | using test::video_frame_matchers::Rotation; |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 73 | using ::testing::_; |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 74 | using ::testing::AllOf; |
Evan Shrubsole | dcb9c5d | 2022-06-13 15:39:53 | [diff] [blame] | 75 | using ::testing::AnyNumber; |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 76 | using ::testing::ElementsAreArray; |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 77 | using ::testing::Eq; |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 78 | using ::testing::Field; |
| 79 | using ::testing::InSequence; |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 80 | using ::testing::Invoke; |
| 81 | using ::testing::IsEmpty; |
Johannes Kron | bbf639e | 2022-06-15 10:27:23 | [diff] [blame] | 82 | using ::testing::Optional; |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 83 | using ::testing::Pointee; |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 84 | using ::testing::Property; |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 85 | using ::testing::Return; |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 86 | using ::testing::SizeIs; |
Danil Chapovalov | d08930d | 2021-08-12 11:26:55 | [diff] [blame] | 87 | using ::testing::WithoutArgs; |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 88 | |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 89 | auto RenderedFrameWith(::testing::Matcher<VideoFrame> m) { |
| 90 | return Optional(m); |
| 91 | } |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 92 | auto RenderedFrame() { |
| 93 | return RenderedFrameWith(_); |
| 94 | } |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 95 | testing::Matcher<std::optional<VideoFrame>> DidNotReceiveFrame() { |
| 96 | return Eq(std::nullopt); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 97 | } |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 98 | |
| 99 | constexpr TimeDelta kDefaultTimeOut = TimeDelta::Millis(50); |
Evan Shrubsole | 14ee803 | 2022-04-26 14:01:44 | [diff] [blame] | 100 | constexpr int kDefaultNumCpuCores = 2; |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 101 | |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 102 | constexpr Timestamp kStartTime = Timestamp::Millis(1'337'000); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 103 | constexpr Frequency k30Fps = Frequency::Hertz(30); |
| 104 | constexpr TimeDelta k30FpsDelay = 1 / k30Fps; |
| 105 | constexpr Frequency kRtpTimestampHz = Frequency::KiloHertz(90); |
| 106 | constexpr uint32_t k30FpsRtpTimestampDelta = kRtpTimestampHz / k30Fps; |
| 107 | constexpr uint32_t kFirstRtpTimestamp = 90000; |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 108 | constexpr uint8_t kH264PayloadType = 99; |
| 109 | constexpr uint8_t kH265PayloadType = 100; |
| 110 | constexpr uint8_t kAv1PayloadType = 101; |
| 111 | constexpr uint32_t kRemoteSsrc = 1111; |
| 112 | constexpr uint32_t kLocalSsrc = 2222; |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 113 | |
Evan Shrubsole | 8f7678f | 2025-04-01 14:23:55 | [diff] [blame] | 114 | class FakeVideoRenderer : public VideoSinkInterface<VideoFrame> { |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 115 | public: |
Evan Shrubsole | 7cbd8de | 2022-08-16 08:08:53 | [diff] [blame] | 116 | explicit FakeVideoRenderer(TimeController* time_controller) |
| 117 | : time_controller_(time_controller) {} |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 118 | ~FakeVideoRenderer() override = default; |
| 119 | |
Evan Shrubsole | dcb9c5d | 2022-06-13 15:39:53 | [diff] [blame] | 120 | void OnFrame(const VideoFrame& frame) override { |
| 121 | RTC_LOG(LS_VERBOSE) << "Received frame with timestamp=" |
Per K | 0fa9088 | 2024-03-13 08:52:41 | [diff] [blame] | 122 | << frame.rtp_timestamp(); |
Evan Shrubsole | 7cbd8de | 2022-08-16 08:08:53 | [diff] [blame] | 123 | if (!last_frame_.empty()) { |
| 124 | RTC_LOG(LS_INFO) << "Already had frame queue with timestamp=" |
Per K | 0fa9088 | 2024-03-13 08:52:41 | [diff] [blame] | 125 | << last_frame_.back().rtp_timestamp(); |
Evan Shrubsole | dcb9c5d | 2022-06-13 15:39:53 | [diff] [blame] | 126 | } |
Evan Shrubsole | 7cbd8de | 2022-08-16 08:08:53 | [diff] [blame] | 127 | last_frame_.push_back(frame); |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 128 | } |
| 129 | |
Evan Shrubsole | dcb9c5d | 2022-06-13 15:39:53 | [diff] [blame] | 130 | // If `advance_time`, then the clock will always advance by `timeout`. |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 131 | std::optional<VideoFrame> WaitForFrame(TimeDelta timeout, |
| 132 | bool advance_time = false) { |
Evan Shrubsole | dcb9c5d | 2022-06-13 15:39:53 | [diff] [blame] | 133 | auto start = time_controller_->GetClock()->CurrentTime(); |
Evan Shrubsole | 7cbd8de | 2022-08-16 08:08:53 | [diff] [blame] | 134 | if (last_frame_.empty()) { |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 135 | time_controller_->AdvanceTime(TimeDelta::Zero()); |
Evan Shrubsole | 7cbd8de | 2022-08-16 08:08:53 | [diff] [blame] | 136 | time_controller_->Wait([this] { return !last_frame_.empty(); }, timeout); |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 137 | } |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 138 | std::optional<VideoFrame> ret; |
Evan Shrubsole | 7cbd8de | 2022-08-16 08:08:53 | [diff] [blame] | 139 | if (!last_frame_.empty()) { |
| 140 | ret = last_frame_.front(); |
| 141 | last_frame_.pop_front(); |
| 142 | } |
Evan Shrubsole | dcb9c5d | 2022-06-13 15:39:53 | [diff] [blame] | 143 | if (advance_time) { |
| 144 | time_controller_->AdvanceTime( |
| 145 | timeout - (time_controller_->GetClock()->CurrentTime() - start)); |
| 146 | } |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 147 | return ret; |
| 148 | } |
| 149 | |
| 150 | private: |
Evan Shrubsole | 7cbd8de | 2022-08-16 08:08:53 | [diff] [blame] | 151 | std::deque<VideoFrame> last_frame_; |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 152 | TimeController* const time_controller_; |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 153 | }; |
| 154 | |
Jonas Oreland | 0deda15 | 2022-09-23 10:08:57 | [diff] [blame] | 155 | MATCHER_P2(MatchResolution, w, h, "") { |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 156 | return arg.resolution().width == w && arg.resolution().height == h; |
| 157 | } |
| 158 | |
Evan Shrubsole | dcb9c5d | 2022-06-13 15:39:53 | [diff] [blame] | 159 | MATCHER_P(RtpTimestamp, timestamp, "") { |
Per K | 0fa9088 | 2024-03-13 08:52:41 | [diff] [blame] | 160 | if (arg.rtp_timestamp() != timestamp) { |
Evan Shrubsole | 7cbd8de | 2022-08-16 08:08:53 | [diff] [blame] | 161 | *result_listener->stream() |
Per K | 0fa9088 | 2024-03-13 08:52:41 | [diff] [blame] | 162 | << "rtp timestamp was " << arg.rtp_timestamp() << " != " << timestamp; |
Evan Shrubsole | 7cbd8de | 2022-08-16 08:08:53 | [diff] [blame] | 163 | return false; |
| 164 | } |
| 165 | return true; |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | // Rtp timestamp for in order frame at 30fps. |
| 169 | uint32_t RtpTimestampForFrame(int id) { |
| 170 | return kFirstRtpTimestamp + id * k30FpsRtpTimestampDelta; |
| 171 | } |
| 172 | |
| 173 | // Receive time for in order frame at 30fps. |
| 174 | Timestamp ReceiveTimeForFrame(int id) { |
| 175 | return kStartTime + id * k30FpsDelay; |
| 176 | } |
| 177 | |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 178 | } // namespace |
| 179 | |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 180 | class VideoReceiveStream2Test : public ::testing::TestWithParam<bool> { |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 181 | public: |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 182 | auto DefaultDecodeAction() { |
philipel | 27b35a7 | 2022-07-05 07:59:55 | [diff] [blame] | 183 | return Invoke(&fake_decoder_, &test::FakeDecoder::Decode); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | bool UseMetronome() const { return GetParam(); } |
| 187 | |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 188 | VideoReceiveStream2Test() |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 189 | : time_controller_(kStartTime), |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 190 | env_(CreateEnvironment(time_controller_.CreateTaskQueueFactory(), |
| 191 | time_controller_.GetClock())), |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 192 | config_(&mock_transport_, &mock_decoder_factory_), |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 193 | call_stats_(&env_.clock(), time_controller_.GetMainThread()), |
Evan Shrubsole | 7cbd8de | 2022-08-16 08:08:53 | [diff] [blame] | 194 | fake_renderer_(&time_controller_), |
Danil Chapovalov | 8d079be | 2024-04-08 16:35:40 | [diff] [blame] | 195 | fake_call_(env_), |
Markus Handell | be400e4 | 2022-11-08 11:14:23 | [diff] [blame] | 196 | fake_metronome_(TimeDelta::Millis(16)), |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 197 | decode_sync_(&env_.clock(), |
Evan Shrubsole | 7cbd8de | 2022-08-16 08:08:53 | [diff] [blame] | 198 | &fake_metronome_, |
| 199 | time_controller_.GetMainThread()), |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 200 | h264_decoder_factory_(&mock_decoder_) { |
Evan Shrubsole | 1c18477 | 2022-04-26 07:47:49 | [diff] [blame] | 201 | // By default, mock decoder factory is backed by VideoDecoderProxyFactory. |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 202 | ON_CALL(mock_decoder_factory_, Create) |
Danil Chapovalov | 0817380 | 2024-01-23 12:02:46 | [diff] [blame] | 203 | .WillByDefault(Invoke(&h264_decoder_factory_, |
| 204 | &test::VideoDecoderProxyFactory::Create)); |
Evan Shrubsole | 14ee803 | 2022-04-26 14:01:44 | [diff] [blame] | 205 | |
| 206 | // By default, mock decode will wrap the fake decoder. |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 207 | ON_CALL(mock_decoder_, Configure) |
philipel | 27b35a7 | 2022-07-05 07:59:55 | [diff] [blame] | 208 | .WillByDefault(Invoke(&fake_decoder_, &test::FakeDecoder::Configure)); |
Tony Herre | 55b593f | 2023-08-29 14:05:49 | [diff] [blame] | 209 | ON_CALL(mock_decoder_, Decode(_, _)).WillByDefault(DefaultDecodeAction()); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 210 | ON_CALL(mock_decoder_, RegisterDecodeCompleteCallback) |
Evan Shrubsole | 14ee803 | 2022-04-26 14:01:44 | [diff] [blame] | 211 | .WillByDefault( |
philipel | 27b35a7 | 2022-07-05 07:59:55 | [diff] [blame] | 212 | Invoke(&fake_decoder_, |
| 213 | &test::FakeDecoder::RegisterDecodeCompleteCallback)); |
| 214 | ON_CALL(mock_decoder_, Release) |
| 215 | .WillByDefault(Invoke(&fake_decoder_, &test::FakeDecoder::Release)); |
| 216 | ON_CALL(mock_transport_, SendRtcp) |
| 217 | .WillByDefault( |
Philipp Hancke | ce6aa1f | 2025-04-28 18:59:22 | [diff] [blame] | 218 | Invoke([this](ArrayView<const uint8_t> packet, ::testing::Unused) { |
| 219 | return rtcp_packet_parser_.Parse(packet); |
| 220 | })); |
Jonas Oreland | 8ca0613 | 2022-03-14 11:52:48 | [diff] [blame] | 221 | } |
Evan Shrubsole | 7cbd8de | 2022-08-16 08:08:53 | [diff] [blame] | 222 | |
Tommi | 90738dd | 2021-05-31 15:36:47 | [diff] [blame] | 223 | ~VideoReceiveStream2Test() override { |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 224 | if (video_receive_stream_) { |
| 225 | video_receive_stream_->Stop(); |
Tommi | 90738dd | 2021-05-31 15:36:47 | [diff] [blame] | 226 | video_receive_stream_->UnregisterFromTransport(); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 227 | } |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 228 | time_controller_.AdvanceTime(TimeDelta::Zero()); |
Tommi | 90738dd | 2021-05-31 15:36:47 | [diff] [blame] | 229 | } |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 230 | |
Tommi | 90738dd | 2021-05-31 15:36:47 | [diff] [blame] | 231 | void SetUp() override { |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 232 | config_.rtp.remote_ssrc = kRemoteSsrc; |
| 233 | config_.rtp.local_ssrc = kLocalSsrc; |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 234 | config_.renderer = &fake_renderer_; |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 235 | VideoReceiveStreamInterface::Decoder h264_decoder; |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 236 | h264_decoder.payload_type = kH264PayloadType; |
Philipp Hancke | bbff58d | 2024-02-27 11:18:33 | [diff] [blame] | 237 | h264_decoder.video_format = SdpVideoFormat::H264(); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 238 | h264_decoder.video_format.parameters.insert( |
| 239 | {"sprop-parameter-sets", "Z0IACpZTBYmI,aMljiA=="}); |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 240 | VideoReceiveStreamInterface::Decoder h265_decoder; |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 241 | h265_decoder.payload_type = kH265PayloadType; |
Evan Shrubsole | 1c18477 | 2022-04-26 07:47:49 | [diff] [blame] | 242 | h265_decoder.video_format = SdpVideoFormat("H265"); |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 243 | VideoReceiveStreamInterface::Decoder av1_decoder; |
| 244 | av1_decoder.payload_type = kAv1PayloadType; |
| 245 | av1_decoder.video_format = SdpVideoFormat("AV1"); |
Evan Shrubsole | 1c18477 | 2022-04-26 07:47:49 | [diff] [blame] | 246 | |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 247 | config_.decoders = {av1_decoder, h265_decoder, h264_decoder}; |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 248 | |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 249 | RecreateReceiveStream(); |
Evan Shrubsole | 14ee803 | 2022-04-26 14:01:44 | [diff] [blame] | 250 | } |
| 251 | |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 252 | void RecreateReceiveStream( |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 253 | std::optional<VideoReceiveStreamInterface::RecordingState> state = |
| 254 | std::nullopt) { |
Evan Shrubsole | 14ee803 | 2022-04-26 14:01:44 | [diff] [blame] | 255 | if (video_receive_stream_) { |
| 256 | video_receive_stream_->UnregisterFromTransport(); |
| 257 | video_receive_stream_ = nullptr; |
| 258 | } |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 259 | timing_ = new VCMTiming(&env_.clock(), env_.field_trials()); |
Evan Shrubsole | 2b87a42 | 2025-05-09 10:35:38 | [diff] [blame] | 260 | video_receive_stream_ = std::make_unique<internal::VideoReceiveStream2>( |
| 261 | env_, &fake_call_, kDefaultNumCpuCores, &packet_router_, config_.Copy(), |
| 262 | &call_stats_, absl::WrapUnique(timing_), &nack_periodic_processor_, |
| 263 | UseMetronome() ? &decode_sync_ : nullptr); |
Tommi | 90738dd | 2021-05-31 15:36:47 | [diff] [blame] | 264 | video_receive_stream_->RegisterWithTransport( |
| 265 | &rtp_stream_receiver_controller_); |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 266 | if (state) |
| 267 | video_receive_stream_->SetAndGetRecordingState(std::move(*state), false); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | protected: |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 271 | GlobalSimulatedTimeController time_controller_; |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 272 | Environment env_; |
Markus Handell | 0e62f7a | 2021-07-20 11:32:02 | [diff] [blame] | 273 | NackPeriodicProcessor nack_periodic_processor_; |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 274 | testing::NiceMock<MockVideoDecoderFactory> mock_decoder_factory_; |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 275 | VideoReceiveStreamInterface::Config config_; |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 276 | internal::CallStats call_stats_; |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 277 | testing::NiceMock<MockVideoDecoder> mock_decoder_; |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 278 | FakeVideoRenderer fake_renderer_; |
Evan Shrubsole | e4b09d7 | 2025-03-17 13:25:49 | [diff] [blame] | 279 | FakeCall fake_call_; |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 280 | MockTransport mock_transport_; |
philipel | 27b35a7 | 2022-07-05 07:59:55 | [diff] [blame] | 281 | test::RtcpPacketParser rtcp_packet_parser_; |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 282 | PacketRouter packet_router_; |
| 283 | RtpStreamReceiverController rtp_stream_receiver_controller_; |
Evan Shrubsole | 2b87a42 | 2025-05-09 10:35:38 | [diff] [blame] | 284 | std::unique_ptr<internal::VideoReceiveStream2> video_receive_stream_; |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 285 | VCMTiming* timing_; |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 286 | test::FakeMetronome fake_metronome_; |
| 287 | DecodeSynchronizer decode_sync_; |
Evan Shrubsole | 1c18477 | 2022-04-26 07:47:49 | [diff] [blame] | 288 | |
| 289 | private: |
| 290 | test::VideoDecoderProxyFactory h264_decoder_factory_; |
Evan Shrubsole | 14ee803 | 2022-04-26 14:01:44 | [diff] [blame] | 291 | test::FakeDecoder fake_decoder_; |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 292 | }; |
| 293 | |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 294 | TEST_P(VideoReceiveStream2Test, CreateFrameFromH264FmtpSpropAndIdr) { |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 295 | constexpr uint8_t idr_nalu[] = {0x05, 0xFF, 0xFF, 0xFF}; |
| 296 | RtpPacketToSend rtppacket(nullptr); |
Danil Chapovalov | adf7d6e | 2025-07-17 15:20:53 | [diff] [blame] | 297 | rtppacket.SetPayload(idr_nalu); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 298 | rtppacket.SetMarker(true); |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 299 | rtppacket.SetSsrc(kRemoteSsrc); |
| 300 | rtppacket.SetPayloadType(kH264PayloadType); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 301 | rtppacket.SetSequenceNumber(1); |
| 302 | rtppacket.SetTimestamp(0); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 303 | EXPECT_CALL(mock_decoder_, RegisterDecodeCompleteCallback(_)); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 304 | video_receive_stream_->Start(); |
Tony Herre | 55b593f | 2023-08-29 14:05:49 | [diff] [blame] | 305 | EXPECT_CALL(mock_decoder_, Decode(_, _)); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 306 | RtpPacketReceived parsed_packet; |
| 307 | ASSERT_TRUE(parsed_packet.Parse(rtppacket.data(), rtppacket.size())); |
| 308 | rtp_stream_receiver_controller_.OnRtpPacket(parsed_packet); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 309 | EXPECT_CALL(mock_decoder_, Release()); |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 310 | |
| 311 | time_controller_.AdvanceTime(TimeDelta::Zero()); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 312 | } |
| 313 | |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 314 | TEST_P(VideoReceiveStream2Test, PlayoutDelay) { |
Danil Chapovalov | 7084e1b | 2023-08-23 11:16:22 | [diff] [blame] | 315 | const VideoPlayoutDelay kPlayoutDelay(TimeDelta::Millis(123), |
Danil Chapovalov | 87b7c1a | 2025-01-28 09:51:08 | [diff] [blame] | 316 | TimeDelta::Millis(521)); |
Evan Shrubsole | a0ee64c | 2022-04-26 08:09:04 | [diff] [blame] | 317 | std::unique_ptr<test::FakeEncodedFrame> test_frame = |
Danil Chapovalov | c146b5f | 2023-08-16 09:42:52 | [diff] [blame] | 318 | test::FakeFrameBuilder() |
| 319 | .Id(0) |
Danil Chapovalov | 7084e1b | 2023-08-23 11:16:22 | [diff] [blame] | 320 | .PlayoutDelay(kPlayoutDelay) |
Danil Chapovalov | c146b5f | 2023-08-16 09:42:52 | [diff] [blame] | 321 | .AsLast() |
| 322 | .Build(); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 323 | |
| 324 | video_receive_stream_->OnCompleteFrame(std::move(test_frame)); |
Evan Shrubsole | 8f1159b | 2022-03-22 11:12:17 | [diff] [blame] | 325 | auto timings = timing_->GetTimings(); |
Danil Chapovalov | 7084e1b | 2023-08-23 11:16:22 | [diff] [blame] | 326 | EXPECT_EQ(kPlayoutDelay.min(), timings.min_playout_delay); |
| 327 | EXPECT_EQ(kPlayoutDelay.max(), timings.max_playout_delay); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 328 | |
| 329 | // Check that the biggest minimum delay is chosen. |
| 330 | video_receive_stream_->SetMinimumPlayoutDelay(400); |
Evan Shrubsole | 8f1159b | 2022-03-22 11:12:17 | [diff] [blame] | 331 | timings = timing_->GetTimings(); |
| 332 | EXPECT_EQ(400, timings.min_playout_delay.ms()); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 333 | |
| 334 | // Check base minimum delay validation. |
| 335 | EXPECT_FALSE(video_receive_stream_->SetBaseMinimumPlayoutDelayMs(12345)); |
| 336 | EXPECT_FALSE(video_receive_stream_->SetBaseMinimumPlayoutDelayMs(-1)); |
| 337 | EXPECT_TRUE(video_receive_stream_->SetBaseMinimumPlayoutDelayMs(500)); |
Evan Shrubsole | 8f1159b | 2022-03-22 11:12:17 | [diff] [blame] | 338 | timings = timing_->GetTimings(); |
| 339 | EXPECT_EQ(500, timings.min_playout_delay.ms()); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 340 | |
| 341 | // Check that intermidiate values are remembered and the biggest remembered |
| 342 | // is chosen. |
| 343 | video_receive_stream_->SetBaseMinimumPlayoutDelayMs(0); |
Evan Shrubsole | 8f1159b | 2022-03-22 11:12:17 | [diff] [blame] | 344 | timings = timing_->GetTimings(); |
| 345 | EXPECT_EQ(400, timings.min_playout_delay.ms()); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 346 | |
| 347 | video_receive_stream_->SetMinimumPlayoutDelay(0); |
Evan Shrubsole | 8f1159b | 2022-03-22 11:12:17 | [diff] [blame] | 348 | timings = timing_->GetTimings(); |
| 349 | EXPECT_EQ(123, timings.min_playout_delay.ms()); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 350 | } |
| 351 | |
Danil Chapovalov | 87b7c1a | 2025-01-28 09:51:08 | [diff] [blame] | 352 | TEST_P(VideoReceiveStream2Test, MinPlayoutDelayIsLimitedByMaxPlayoutDelay) { |
| 353 | const VideoPlayoutDelay kPlayoutDelay(TimeDelta::Millis(123), |
| 354 | TimeDelta::Millis(321)); |
| 355 | video_receive_stream_->OnCompleteFrame(test::FakeFrameBuilder() |
| 356 | .Id(0) |
| 357 | .PlayoutDelay(kPlayoutDelay) |
| 358 | .AsLast() |
| 359 | .Build()); |
| 360 | EXPECT_EQ(timing_->GetTimings().min_playout_delay, kPlayoutDelay.min()); |
| 361 | |
| 362 | // Check that the biggest minimum delay is limited by the max playout delay. |
| 363 | video_receive_stream_->SetMinimumPlayoutDelay(400); |
| 364 | EXPECT_EQ(timing_->GetTimings().min_playout_delay, kPlayoutDelay.max()); |
| 365 | } |
| 366 | |
Johannes Kron | bbf639e | 2022-06-15 10:27:23 | [diff] [blame] | 367 | TEST_P(VideoReceiveStream2Test, RenderParametersSetToDefaultValues) { |
| 368 | // Default render parameters. |
| 369 | const VideoFrame::RenderParameters kDefaultRenderParameters; |
Johannes Kron | 111e981 | 2020-10-26 12:54:40 | [diff] [blame] | 370 | // Default with no playout delay set. |
Evan Shrubsole | a0ee64c | 2022-04-26 08:09:04 | [diff] [blame] | 371 | std::unique_ptr<test::FakeEncodedFrame> test_frame0 = |
| 372 | test::FakeFrameBuilder().Id(0).AsLast().Build(); |
Johannes Kron | 111e981 | 2020-10-26 12:54:40 | [diff] [blame] | 373 | video_receive_stream_->OnCompleteFrame(std::move(test_frame0)); |
Johannes Kron | bbf639e | 2022-06-15 10:27:23 | [diff] [blame] | 374 | EXPECT_EQ(timing_->RenderParameters(), kDefaultRenderParameters); |
| 375 | } |
Johannes Kron | 111e981 | 2020-10-26 12:54:40 | [diff] [blame] | 376 | |
Johannes Kron | bbf639e | 2022-06-15 10:27:23 | [diff] [blame] | 377 | TEST_P(VideoReceiveStream2Test, UseLowLatencyRenderingSetFromPlayoutDelay) { |
Johannes Kron | bbf639e | 2022-06-15 10:27:23 | [diff] [blame] | 378 | std::unique_ptr<test::FakeEncodedFrame> test_frame0 = |
Danil Chapovalov | c146b5f | 2023-08-16 09:42:52 | [diff] [blame] | 379 | test::FakeFrameBuilder() |
| 380 | .Id(0) |
| 381 | .PlayoutDelay(VideoPlayoutDelay::Minimal()) |
| 382 | .AsLast() |
| 383 | .Build(); |
Johannes Kron | bbf639e | 2022-06-15 10:27:23 | [diff] [blame] | 384 | video_receive_stream_->OnCompleteFrame(std::move(test_frame0)); |
| 385 | EXPECT_TRUE(timing_->RenderParameters().use_low_latency_rendering); |
| 386 | |
Evan Shrubsole | a0ee64c | 2022-04-26 08:09:04 | [diff] [blame] | 387 | std::unique_ptr<test::FakeEncodedFrame> test_frame1 = |
Danil Chapovalov | c146b5f | 2023-08-16 09:42:52 | [diff] [blame] | 388 | test::FakeFrameBuilder() |
| 389 | .Id(1) |
Danil Chapovalov | 7084e1b | 2023-08-23 11:16:22 | [diff] [blame] | 390 | .PlayoutDelay({TimeDelta::Zero(), TimeDelta::Millis(500)}) |
Danil Chapovalov | c146b5f | 2023-08-16 09:42:52 | [diff] [blame] | 391 | .AsLast() |
| 392 | .Build(); |
Johannes Kron | 111e981 | 2020-10-26 12:54:40 | [diff] [blame] | 393 | video_receive_stream_->OnCompleteFrame(std::move(test_frame1)); |
Johannes Kron | bbf639e | 2022-06-15 10:27:23 | [diff] [blame] | 394 | EXPECT_TRUE(timing_->RenderParameters().use_low_latency_rendering); |
Johannes Kron | 111e981 | 2020-10-26 12:54:40 | [diff] [blame] | 395 | } |
| 396 | |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 397 | TEST_P(VideoReceiveStream2Test, MaxCompositionDelaySetFromMaxPlayoutDelay) { |
Johannes Kron | bbf639e | 2022-06-15 10:27:23 | [diff] [blame] | 398 | // The max composition delay is dependent on the number of frames in the |
| 399 | // pre-decode queue. It's therefore important to advance the time as the test |
| 400 | // runs to get the correct expectations of max_composition_delay_in_frames. |
| 401 | video_receive_stream_->Start(); |
| 402 | // Max composition delay not set if no playout delay is set. |
| 403 | std::unique_ptr<test::FakeEncodedFrame> test_frame0 = |
| 404 | test::FakeFrameBuilder() |
| 405 | .Id(0) |
| 406 | .Time(RtpTimestampForFrame(0)) |
| 407 | .ReceivedTime(ReceiveTimeForFrame(0)) |
| 408 | .AsLast() |
| 409 | .Build(); |
| 410 | video_receive_stream_->OnCompleteFrame(std::move(test_frame0)); |
| 411 | EXPECT_THAT(timing_->RenderParameters().max_composition_delay_in_frames, |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 412 | Eq(std::nullopt)); |
Johannes Kron | bbf639e | 2022-06-15 10:27:23 | [diff] [blame] | 413 | time_controller_.AdvanceTime(k30FpsDelay); |
Johannes Kron | bbf639e | 2022-06-15 10:27:23 | [diff] [blame] | 414 | |
| 415 | // Max composition delay not set for playout delay 0,0. |
| 416 | std::unique_ptr<test::FakeEncodedFrame> test_frame1 = |
| 417 | test::FakeFrameBuilder() |
| 418 | .Id(1) |
| 419 | .Time(RtpTimestampForFrame(1)) |
| 420 | .ReceivedTime(ReceiveTimeForFrame(1)) |
Danil Chapovalov | 7084e1b | 2023-08-23 11:16:22 | [diff] [blame] | 421 | .PlayoutDelay(VideoPlayoutDelay::Minimal()) |
Johannes Kron | bbf639e | 2022-06-15 10:27:23 | [diff] [blame] | 422 | .AsLast() |
| 423 | .Build(); |
Johannes Kron | bbf639e | 2022-06-15 10:27:23 | [diff] [blame] | 424 | video_receive_stream_->OnCompleteFrame(std::move(test_frame1)); |
| 425 | EXPECT_THAT(timing_->RenderParameters().max_composition_delay_in_frames, |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 426 | Eq(std::nullopt)); |
Johannes Kron | bbf639e | 2022-06-15 10:27:23 | [diff] [blame] | 427 | time_controller_.AdvanceTime(k30FpsDelay); |
Johannes Kron | bbf639e | 2022-06-15 10:27:23 | [diff] [blame] | 428 | |
| 429 | // Max composition delay not set for playout delay X,Y, where X,Y>0. |
| 430 | std::unique_ptr<test::FakeEncodedFrame> test_frame2 = |
| 431 | test::FakeFrameBuilder() |
| 432 | .Id(2) |
| 433 | .Time(RtpTimestampForFrame(2)) |
| 434 | .ReceivedTime(ReceiveTimeForFrame(2)) |
Danil Chapovalov | 7084e1b | 2023-08-23 11:16:22 | [diff] [blame] | 435 | .PlayoutDelay({TimeDelta::Millis(10), TimeDelta::Millis(30)}) |
Johannes Kron | bbf639e | 2022-06-15 10:27:23 | [diff] [blame] | 436 | .AsLast() |
| 437 | .Build(); |
Johannes Kron | bbf639e | 2022-06-15 10:27:23 | [diff] [blame] | 438 | video_receive_stream_->OnCompleteFrame(std::move(test_frame2)); |
| 439 | EXPECT_THAT(timing_->RenderParameters().max_composition_delay_in_frames, |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 440 | Eq(std::nullopt)); |
Johannes Kron | bbf639e | 2022-06-15 10:27:23 | [diff] [blame] | 441 | |
| 442 | time_controller_.AdvanceTime(k30FpsDelay); |
Johannes Kron | bbf639e | 2022-06-15 10:27:23 | [diff] [blame] | 443 | |
Johannes Kron | 111e981 | 2020-10-26 12:54:40 | [diff] [blame] | 444 | // Max composition delay set if playout delay X,Y, where X=0,Y>0. |
Johannes Kron | 111e981 | 2020-10-26 12:54:40 | [diff] [blame] | 445 | const int kExpectedMaxCompositionDelayInFrames = 3; // ~50 ms at 60 fps. |
Johannes Kron | bbf639e | 2022-06-15 10:27:23 | [diff] [blame] | 446 | std::unique_ptr<test::FakeEncodedFrame> test_frame3 = |
| 447 | test::FakeFrameBuilder() |
| 448 | .Id(3) |
| 449 | .Time(RtpTimestampForFrame(3)) |
| 450 | .ReceivedTime(ReceiveTimeForFrame(3)) |
Danil Chapovalov | 7084e1b | 2023-08-23 11:16:22 | [diff] [blame] | 451 | .PlayoutDelay({TimeDelta::Zero(), TimeDelta::Millis(50)}) |
Johannes Kron | bbf639e | 2022-06-15 10:27:23 | [diff] [blame] | 452 | .AsLast() |
| 453 | .Build(); |
Johannes Kron | bbf639e | 2022-06-15 10:27:23 | [diff] [blame] | 454 | video_receive_stream_->OnCompleteFrame(std::move(test_frame3)); |
| 455 | EXPECT_THAT(timing_->RenderParameters().max_composition_delay_in_frames, |
| 456 | Optional(kExpectedMaxCompositionDelayInFrames)); |
Johannes Kron | 111e981 | 2020-10-26 12:54:40 | [diff] [blame] | 457 | } |
| 458 | |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 459 | TEST_P(VideoReceiveStream2Test, LazyDecoderCreation) { |
Evan Shrubsole | 1c18477 | 2022-04-26 07:47:49 | [diff] [blame] | 460 | constexpr uint8_t idr_nalu[] = {0x05, 0xFF, 0xFF, 0xFF}; |
| 461 | RtpPacketToSend rtppacket(nullptr); |
Danil Chapovalov | adf7d6e | 2025-07-17 15:20:53 | [diff] [blame] | 462 | rtppacket.SetPayload(idr_nalu); |
Evan Shrubsole | 1c18477 | 2022-04-26 07:47:49 | [diff] [blame] | 463 | rtppacket.SetMarker(true); |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 464 | rtppacket.SetSsrc(kRemoteSsrc); |
| 465 | rtppacket.SetPayloadType(kH264PayloadType); |
Evan Shrubsole | 1c18477 | 2022-04-26 07:47:49 | [diff] [blame] | 466 | rtppacket.SetSequenceNumber(1); |
| 467 | rtppacket.SetTimestamp(0); |
| 468 | |
Johannes Kron | bb591c4 | 2022-09-28 10:10:25 | [diff] [blame] | 469 | // No decoders are created by default. |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 470 | EXPECT_CALL(mock_decoder_factory_, Create).Times(0); |
Evan Shrubsole | 1c18477 | 2022-04-26 07:47:49 | [diff] [blame] | 471 | video_receive_stream_->Start(); |
Erik Språng | 7aaeb5a | 2022-08-18 11:18:27 | [diff] [blame] | 472 | time_controller_.AdvanceTime(TimeDelta::Zero()); |
Evan Shrubsole | 1c18477 | 2022-04-26 07:47:49 | [diff] [blame] | 473 | |
| 474 | EXPECT_TRUE( |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 475 | testing::Mock::VerifyAndClearExpectations(&mock_decoder_factory_)); |
Johannes Kron | bb591c4 | 2022-09-28 10:10:25 | [diff] [blame] | 476 | // Verify that the decoder is created when we receive payload data and tries |
| 477 | // to decode a frame. |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 478 | EXPECT_CALL(mock_decoder_factory_, |
Danil Chapovalov | 0817380 | 2024-01-23 12:02:46 | [diff] [blame] | 479 | Create(_, Field(&SdpVideoFormat::name, Eq("H264")))); |
Erik Språng | 7aaeb5a | 2022-08-18 11:18:27 | [diff] [blame] | 480 | EXPECT_CALL(mock_decoder_, Configure); |
| 481 | EXPECT_CALL(mock_decoder_, RegisterDecodeCompleteCallback); |
Tony Herre | 55b593f | 2023-08-29 14:05:49 | [diff] [blame] | 482 | EXPECT_CALL(mock_decoder_, Decode(_, _)); |
Evan Shrubsole | 1c18477 | 2022-04-26 07:47:49 | [diff] [blame] | 483 | RtpPacketReceived parsed_packet; |
| 484 | ASSERT_TRUE(parsed_packet.Parse(rtppacket.data(), rtppacket.size())); |
| 485 | rtp_stream_receiver_controller_.OnRtpPacket(parsed_packet); |
Erik Språng | 7aaeb5a | 2022-08-18 11:18:27 | [diff] [blame] | 486 | EXPECT_CALL(mock_decoder_, Release); |
Evan Shrubsole | 1c18477 | 2022-04-26 07:47:49 | [diff] [blame] | 487 | |
| 488 | // Make sure the decoder thread had a chance to run. |
Erik Språng | 7aaeb5a | 2022-08-18 11:18:27 | [diff] [blame] | 489 | time_controller_.AdvanceTime(TimeDelta::Zero()); |
Evan Shrubsole | 1c18477 | 2022-04-26 07:47:49 | [diff] [blame] | 490 | } |
| 491 | |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 492 | TEST_P(VideoReceiveStream2Test, LazyDecoderCreationCodecSwitch) { |
| 493 | constexpr uint8_t idr_nalu[] = {0x05, 0xFF, 0xFF, 0xFF}; |
| 494 | RtpPacketToSend rtppacket(nullptr); |
Danil Chapovalov | adf7d6e | 2025-07-17 15:20:53 | [diff] [blame] | 495 | rtppacket.SetPayload(idr_nalu); |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 496 | rtppacket.SetMarker(true); |
| 497 | rtppacket.SetSsrc(kRemoteSsrc); |
| 498 | rtppacket.SetPayloadType(kH264PayloadType); |
| 499 | rtppacket.SetSequenceNumber(1); |
| 500 | rtppacket.SetTimestamp(0); |
| 501 | |
| 502 | // No decoders are created by default. |
| 503 | EXPECT_CALL(mock_decoder_factory_, Create).Times(0); |
| 504 | video_receive_stream_->Start(); |
| 505 | time_controller_.AdvanceTime(TimeDelta::Zero()); |
| 506 | |
| 507 | EXPECT_TRUE( |
| 508 | testing::Mock::VerifyAndClearExpectations(&mock_decoder_factory_)); |
| 509 | // Verify that the decoder is created when we receive payload data and tries |
| 510 | // to decode a frame. |
| 511 | EXPECT_CALL(mock_decoder_factory_, |
| 512 | Create(_, Field(&SdpVideoFormat::name, Eq("H264")))); |
| 513 | EXPECT_CALL(mock_decoder_, Configure); |
| 514 | EXPECT_CALL(mock_decoder_, RegisterDecodeCompleteCallback); |
| 515 | EXPECT_CALL(mock_decoder_, Decode(_, _)); |
| 516 | RtpPacketReceived parsed_packet; |
| 517 | ASSERT_TRUE(parsed_packet.Parse(rtppacket.data(), rtppacket.size())); |
| 518 | rtp_stream_receiver_controller_.OnRtpPacket(parsed_packet); |
| 519 | // H264 decoder is released after receiving the AV1 packet. |
| 520 | EXPECT_CALL(mock_decoder_, Release).Times(0); |
| 521 | |
| 522 | // Make sure the decoder thread had a chance to run. |
| 523 | time_controller_.AdvanceTime(TimeDelta::Millis(100)); |
| 524 | |
| 525 | // Switch to AV1. |
| 526 | const uint8_t av1_key_obu[] = {0x18, 0x48, 0x01, 0xAA}; // \ OBU |
| 527 | RtpPacketToSend av1_rtppacket(nullptr); |
Danil Chapovalov | adf7d6e | 2025-07-17 15:20:53 | [diff] [blame] | 528 | av1_rtppacket.SetPayload(av1_key_obu); |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 529 | av1_rtppacket.SetMarker(true); |
| 530 | av1_rtppacket.SetSsrc(kRemoteSsrc); |
| 531 | av1_rtppacket.SetPayloadType(kAv1PayloadType); |
| 532 | av1_rtppacket.SetSequenceNumber(2); |
| 533 | av1_rtppacket.SetTimestamp(1); |
| 534 | |
| 535 | EXPECT_TRUE( |
| 536 | testing::Mock::VerifyAndClearExpectations(&mock_decoder_factory_)); |
| 537 | // Release the H264 previous decoder. |
| 538 | EXPECT_CALL(mock_decoder_, Release); |
| 539 | // Verify that the decoder is created when we receive payload data and tries |
| 540 | // to decode a frame. |
| 541 | EXPECT_CALL(mock_decoder_factory_, |
| 542 | Create(_, Field(&SdpVideoFormat::name, Eq("AV1")))); |
| 543 | EXPECT_CALL(mock_decoder_, Configure); |
| 544 | EXPECT_CALL(mock_decoder_, RegisterDecodeCompleteCallback); |
| 545 | EXPECT_CALL(mock_decoder_, Decode(_, _)); |
| 546 | ASSERT_TRUE(parsed_packet.Parse(av1_rtppacket.data(), av1_rtppacket.size())); |
| 547 | rtp_stream_receiver_controller_.OnRtpPacket(parsed_packet); |
| 548 | |
| 549 | // Make sure the decoder thread had a chance to run. |
| 550 | time_controller_.AdvanceTime(TimeDelta::Millis(100)); |
| 551 | |
| 552 | // Switch back to H264. |
| 553 | rtppacket.SetPayloadType(kH264PayloadType); |
| 554 | rtppacket.SetSequenceNumber(3); |
| 555 | rtppacket.SetTimestamp(2); |
| 556 | |
| 557 | EXPECT_TRUE( |
| 558 | testing::Mock::VerifyAndClearExpectations(&mock_decoder_factory_)); |
| 559 | // Release the AV1 previous decoder and the new H264 decoder on test end. |
| 560 | EXPECT_CALL(mock_decoder_, Release).Times(2); |
| 561 | // Verify that the decoder is created when we receive payload data and tries |
| 562 | // to decode a frame. |
| 563 | EXPECT_CALL(mock_decoder_factory_, |
| 564 | Create(_, Field(&SdpVideoFormat::name, Eq("H264")))); |
| 565 | EXPECT_CALL(mock_decoder_, Configure); |
| 566 | EXPECT_CALL(mock_decoder_, RegisterDecodeCompleteCallback); |
| 567 | EXPECT_CALL(mock_decoder_, Decode(_, _)); |
| 568 | ASSERT_TRUE(parsed_packet.Parse(rtppacket.data(), rtppacket.size())); |
| 569 | rtp_stream_receiver_controller_.OnRtpPacket(parsed_packet); |
| 570 | |
| 571 | // Make sure the decoder thread had a chance to run. |
| 572 | time_controller_.AdvanceTime(TimeDelta::Millis(100)); |
| 573 | } |
| 574 | |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 575 | TEST_P(VideoReceiveStream2Test, PassesNtpTime) { |
Evan Shrubsole | a0ee64c | 2022-04-26 08:09:04 | [diff] [blame] | 576 | const Timestamp kNtpTimestamp = Timestamp::Millis(12345); |
| 577 | std::unique_ptr<test::FakeEncodedFrame> test_frame = |
| 578 | test::FakeFrameBuilder() |
| 579 | .Id(0) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 580 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | a0ee64c | 2022-04-26 08:09:04 | [diff] [blame] | 581 | .NtpTime(kNtpTimestamp) |
| 582 | .AsLast() |
| 583 | .Build(); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 584 | |
| 585 | video_receive_stream_->Start(); |
| 586 | video_receive_stream_->OnCompleteFrame(std::move(test_frame)); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 587 | EXPECT_THAT(fake_renderer_.WaitForFrame(kDefaultTimeOut), |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 588 | RenderedFrameWith(NtpTimestamp(kNtpTimestamp))); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 589 | } |
| 590 | |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 591 | TEST_P(VideoReceiveStream2Test, PassesRotation) { |
Evan Shrubsole | 2b87a42 | 2025-05-09 10:35:38 | [diff] [blame] | 592 | const VideoRotation kRotation = kVideoRotation_180; |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 593 | std::unique_ptr<test::FakeEncodedFrame> test_frame = |
| 594 | test::FakeFrameBuilder() |
| 595 | .Id(0) |
| 596 | .PayloadType(kH264PayloadType) |
| 597 | .Rotation(kRotation) |
| 598 | .AsLast() |
| 599 | .Build(); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 600 | |
| 601 | video_receive_stream_->Start(); |
| 602 | video_receive_stream_->OnCompleteFrame(std::move(test_frame)); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 603 | EXPECT_THAT(fake_renderer_.WaitForFrame(kDefaultTimeOut), |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 604 | RenderedFrameWith(Rotation(kRotation))); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 605 | } |
| 606 | |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 607 | TEST_P(VideoReceiveStream2Test, PassesPacketInfos) { |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 608 | RtpPacketInfos packet_infos = CreatePacketInfos(3); |
Evan Shrubsole | a0ee64c | 2022-04-26 08:09:04 | [diff] [blame] | 609 | auto test_frame = test::FakeFrameBuilder() |
| 610 | .Id(0) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 611 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | a0ee64c | 2022-04-26 08:09:04 | [diff] [blame] | 612 | .PacketInfos(packet_infos) |
| 613 | .AsLast() |
| 614 | .Build(); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 615 | |
| 616 | video_receive_stream_->Start(); |
| 617 | video_receive_stream_->OnCompleteFrame(std::move(test_frame)); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 618 | EXPECT_THAT(fake_renderer_.WaitForFrame(kDefaultTimeOut), |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 619 | RenderedFrameWith(PacketInfos(ElementsAreArray(packet_infos)))); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 620 | } |
| 621 | |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 622 | TEST_P(VideoReceiveStream2Test, RenderedFrameUpdatesGetSources) { |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 623 | constexpr uint32_t kSsrc = kRemoteSsrc; |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 624 | constexpr uint32_t kCsrc = 9001; |
| 625 | constexpr uint32_t kRtpTimestamp = 12345; |
| 626 | |
| 627 | // Prepare one video frame with per-packet information. |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 628 | auto test_frame = test::FakeFrameBuilder() |
| 629 | .Id(0) |
| 630 | .PayloadType(kH264PayloadType) |
| 631 | .AsLast() |
| 632 | .Build(); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 633 | RtpPacketInfos packet_infos; |
| 634 | { |
| 635 | RtpPacketInfos::vector_type infos; |
| 636 | |
| 637 | RtpPacketInfo info; |
| 638 | info.set_ssrc(kSsrc); |
| 639 | info.set_csrcs({kCsrc}); |
| 640 | info.set_rtp_timestamp(kRtpTimestamp); |
| 641 | |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 642 | info.set_receive_time(env_.clock().CurrentTime() - TimeDelta::Millis(5000)); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 643 | infos.push_back(info); |
| 644 | |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 645 | info.set_receive_time(env_.clock().CurrentTime() - TimeDelta::Millis(3000)); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 646 | infos.push_back(info); |
| 647 | |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 648 | info.set_receive_time(env_.clock().CurrentTime() - TimeDelta::Millis(2000)); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 649 | infos.push_back(info); |
| 650 | |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 651 | info.set_receive_time(env_.clock().CurrentTime() - TimeDelta::Millis(1000)); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 652 | infos.push_back(info); |
| 653 | |
| 654 | packet_infos = RtpPacketInfos(std::move(infos)); |
| 655 | } |
| 656 | test_frame->SetPacketInfos(packet_infos); |
| 657 | |
| 658 | // Start receive stream. |
| 659 | video_receive_stream_->Start(); |
| 660 | EXPECT_THAT(video_receive_stream_->GetSources(), IsEmpty()); |
| 661 | |
| 662 | // Render one video frame. |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 663 | Timestamp timestamp_min = env_.clock().CurrentTime(); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 664 | video_receive_stream_->OnCompleteFrame(std::move(test_frame)); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 665 | // Verify that the per-packet information is passed to the renderer. |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 666 | EXPECT_THAT(fake_renderer_.WaitForFrame(kDefaultTimeOut), |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 667 | RenderedFrameWith(PacketInfos(ElementsAreArray(packet_infos)))); |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 668 | Timestamp timestamp_max = env_.clock().CurrentTime(); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 669 | |
Artem Titov | ab30d72 | 2021-07-27 14:22:11 | [diff] [blame] | 670 | // Verify that the per-packet information also updates `GetSources()`. |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 671 | std::vector<RtpSource> sources = video_receive_stream_->GetSources(); |
| 672 | ASSERT_THAT(sources, SizeIs(2)); |
| 673 | { |
| 674 | auto it = std::find_if(sources.begin(), sources.end(), |
| 675 | [](const RtpSource& source) { |
| 676 | return source.source_type() == RtpSourceType::SSRC; |
| 677 | }); |
| 678 | ASSERT_NE(it, sources.end()); |
| 679 | |
| 680 | EXPECT_EQ(it->source_id(), kSsrc); |
| 681 | EXPECT_EQ(it->source_type(), RtpSourceType::SSRC); |
| 682 | EXPECT_EQ(it->rtp_timestamp(), kRtpTimestamp); |
Danil Chapovalov | f535971 | 2023-08-28 16:32:25 | [diff] [blame] | 683 | EXPECT_GE(it->timestamp(), timestamp_min); |
| 684 | EXPECT_LE(it->timestamp(), timestamp_max); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 685 | } |
| 686 | { |
| 687 | auto it = std::find_if(sources.begin(), sources.end(), |
| 688 | [](const RtpSource& source) { |
| 689 | return source.source_type() == RtpSourceType::CSRC; |
| 690 | }); |
| 691 | ASSERT_NE(it, sources.end()); |
| 692 | |
| 693 | EXPECT_EQ(it->source_id(), kCsrc); |
| 694 | EXPECT_EQ(it->source_type(), RtpSourceType::CSRC); |
| 695 | EXPECT_EQ(it->rtp_timestamp(), kRtpTimestamp); |
Danil Chapovalov | f535971 | 2023-08-28 16:32:25 | [diff] [blame] | 696 | EXPECT_GE(it->timestamp(), timestamp_min); |
| 697 | EXPECT_LE(it->timestamp(), timestamp_max); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 698 | } |
| 699 | } |
| 700 | |
Evan Shrubsole | a0ee64c | 2022-04-26 08:09:04 | [diff] [blame] | 701 | std::unique_ptr<test::FakeEncodedFrame> MakeFrameWithResolution( |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 702 | VideoFrameType frame_type, |
| 703 | int picture_id, |
| 704 | int width, |
| 705 | int height) { |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 706 | auto frame = test::FakeFrameBuilder() |
| 707 | .Id(picture_id) |
| 708 | .PayloadType(kH264PayloadType) |
| 709 | .AsLast() |
| 710 | .Build(); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 711 | frame->SetFrameType(frame_type); |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 712 | frame->_encodedWidth = width; |
| 713 | frame->_encodedHeight = height; |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 714 | return frame; |
| 715 | } |
| 716 | |
Evan Shrubsole | a0ee64c | 2022-04-26 08:09:04 | [diff] [blame] | 717 | std::unique_ptr<test::FakeEncodedFrame> MakeFrame(VideoFrameType frame_type, |
| 718 | int picture_id) { |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 719 | return MakeFrameWithResolution(frame_type, picture_id, 320, 240); |
| 720 | } |
| 721 | |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 722 | TEST_P(VideoReceiveStream2Test, PassesFrameWhenEncodedFramesCallbackSet) { |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 723 | testing::MockFunction<void(const RecordableEncodedFrame&)> callback; |
| 724 | video_receive_stream_->Start(); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 725 | EXPECT_CALL(callback, Call); |
| 726 | video_receive_stream_->SetAndGetRecordingState( |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 727 | VideoReceiveStreamInterface::RecordingState(callback.AsStdFunction()), |
| 728 | true); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 729 | video_receive_stream_->OnCompleteFrame( |
| 730 | MakeFrame(VideoFrameType::kVideoFrameKey, 0)); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 731 | EXPECT_TRUE(fake_renderer_.WaitForFrame(kDefaultTimeOut)); |
philipel | 27b35a7 | 2022-07-05 07:59:55 | [diff] [blame] | 732 | |
| 733 | EXPECT_THAT(rtcp_packet_parser_.pli()->num_packets(), Eq(1)); |
| 734 | |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 735 | video_receive_stream_->Stop(); |
| 736 | } |
| 737 | |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 738 | TEST_P(VideoReceiveStream2Test, MovesEncodedFrameDispatchStateWhenReCreating) { |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 739 | testing::MockFunction<void(const RecordableEncodedFrame&)> callback; |
| 740 | video_receive_stream_->Start(); |
| 741 | // Expect a key frame request over RTCP. |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 742 | video_receive_stream_->SetAndGetRecordingState( |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 743 | VideoReceiveStreamInterface::RecordingState(callback.AsStdFunction()), |
| 744 | true); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 745 | video_receive_stream_->Stop(); |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 746 | VideoReceiveStreamInterface::RecordingState old_state = |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 747 | video_receive_stream_->SetAndGetRecordingState( |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 748 | VideoReceiveStreamInterface::RecordingState(), false); |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 749 | RecreateReceiveStream(std::move(old_state)); |
philipel | 27b35a7 | 2022-07-05 07:59:55 | [diff] [blame] | 750 | |
| 751 | EXPECT_THAT(rtcp_packet_parser_.pli()->num_packets(), Eq(1)); |
| 752 | |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 753 | video_receive_stream_->Stop(); |
| 754 | } |
| 755 | |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 756 | TEST_P(VideoReceiveStream2Test, RequestsKeyFramesUntilKeyFrameReceived) { |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 757 | // Recreate receive stream with shorter delay to test rtx. |
| 758 | TimeDelta rtx_delay = TimeDelta::Millis(50); |
| 759 | config_.rtp.nack.rtp_history_ms = rtx_delay.ms(); |
| 760 | auto tick = rtx_delay / 2; |
| 761 | RecreateReceiveStream(); |
| 762 | video_receive_stream_->Start(); |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 763 | |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 764 | video_receive_stream_->GenerateKeyFrame(); |
| 765 | video_receive_stream_->OnCompleteFrame( |
| 766 | MakeFrame(VideoFrameType::kVideoFrameDelta, 0)); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 767 | fake_renderer_.WaitForFrame(kDefaultTimeOut); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 768 | time_controller_.AdvanceTime(tick); |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 769 | video_receive_stream_->OnCompleteFrame( |
| 770 | MakeFrame(VideoFrameType::kVideoFrameDelta, 1)); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 771 | fake_renderer_.WaitForFrame(kDefaultTimeOut); |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 772 | time_controller_.AdvanceTime(TimeDelta::Zero()); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 773 | testing::Mock::VerifyAndClearExpectations(&mock_transport_); |
| 774 | |
philipel | 27b35a7 | 2022-07-05 07:59:55 | [diff] [blame] | 775 | EXPECT_THAT(rtcp_packet_parser_.pli()->num_packets(), Eq(1)); |
| 776 | |
Philipp Hancke | 006206d | 2021-03-24 16:49:02 | [diff] [blame] | 777 | // T+keyframetimeout: still no key frame received, expect key frame request |
| 778 | // sent again. |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 779 | time_controller_.AdvanceTime(tick); |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 780 | video_receive_stream_->OnCompleteFrame( |
| 781 | MakeFrame(VideoFrameType::kVideoFrameDelta, 2)); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 782 | EXPECT_THAT(fake_renderer_.WaitForFrame(kDefaultTimeOut), RenderedFrame()); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 783 | testing::Mock::VerifyAndClearExpectations(&mock_transport_); |
| 784 | |
philipel | 27b35a7 | 2022-07-05 07:59:55 | [diff] [blame] | 785 | EXPECT_THAT(rtcp_packet_parser_.pli()->num_packets(), Eq(2)); |
| 786 | |
Philipp Hancke | 006206d | 2021-03-24 16:49:02 | [diff] [blame] | 787 | // T+keyframetimeout: now send a key frame - we should not observe new key |
| 788 | // frame requests after this. |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 789 | video_receive_stream_->OnCompleteFrame( |
| 790 | MakeFrame(VideoFrameType::kVideoFrameKey, 3)); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 791 | EXPECT_THAT(fake_renderer_.WaitForFrame(kDefaultTimeOut), RenderedFrame()); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 792 | time_controller_.AdvanceTime(2 * tick); |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 793 | video_receive_stream_->OnCompleteFrame( |
| 794 | MakeFrame(VideoFrameType::kVideoFrameDelta, 4)); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 795 | EXPECT_THAT(fake_renderer_.WaitForFrame(kDefaultTimeOut), RenderedFrame()); |
philipel | 27b35a7 | 2022-07-05 07:59:55 | [diff] [blame] | 796 | |
| 797 | EXPECT_THAT(rtcp_packet_parser_.pli()->num_packets(), Eq(2)); |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 798 | } |
| 799 | |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 800 | TEST_P(VideoReceiveStream2Test, |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 801 | DispatchesEncodedFrameSequenceStartingWithKeyframeWithoutResolution) { |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 802 | video_receive_stream_->Start(); |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 803 | testing::MockFunction<void(const RecordableEncodedFrame&)> callback; |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 804 | video_receive_stream_->SetAndGetRecordingState( |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 805 | VideoReceiveStreamInterface::RecordingState(callback.AsStdFunction()), |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 806 | /*generate_key_frame=*/false); |
| 807 | |
| 808 | InSequence s; |
Jonas Oreland | 0deda15 | 2022-09-23 10:08:57 | [diff] [blame] | 809 | EXPECT_CALL(callback, |
| 810 | Call(MatchResolution(test::FakeDecoder::kDefaultWidth, |
| 811 | test::FakeDecoder::kDefaultHeight))); |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 812 | EXPECT_CALL(callback, Call); |
| 813 | |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 814 | video_receive_stream_->OnCompleteFrame( |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 815 | MakeFrameWithResolution(VideoFrameType::kVideoFrameKey, 0, 0, 0)); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 816 | EXPECT_THAT(fake_renderer_.WaitForFrame(kDefaultTimeOut), RenderedFrame()); |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 817 | video_receive_stream_->OnCompleteFrame( |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 818 | MakeFrameWithResolution(VideoFrameType::kVideoFrameDelta, 1, 0, 0)); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 819 | EXPECT_THAT(fake_renderer_.WaitForFrame(kDefaultTimeOut), RenderedFrame()); |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 820 | |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 821 | video_receive_stream_->Stop(); |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 822 | } |
| 823 | |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 824 | TEST_P(VideoReceiveStream2Test, |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 825 | DispatchesEncodedFrameSequenceStartingWithKeyframeWithResolution) { |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 826 | video_receive_stream_->Start(); |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 827 | testing::MockFunction<void(const RecordableEncodedFrame&)> callback; |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 828 | video_receive_stream_->SetAndGetRecordingState( |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 829 | VideoReceiveStreamInterface::RecordingState(callback.AsStdFunction()), |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 830 | /*generate_key_frame=*/false); |
| 831 | |
| 832 | InSequence s; |
Jonas Oreland | 0deda15 | 2022-09-23 10:08:57 | [diff] [blame] | 833 | EXPECT_CALL(callback, Call(MatchResolution(1080u, 720u))); |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 834 | EXPECT_CALL(callback, Call); |
| 835 | |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 836 | video_receive_stream_->OnCompleteFrame( |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 837 | MakeFrameWithResolution(VideoFrameType::kVideoFrameKey, 0, 1080, 720)); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 838 | EXPECT_THAT(fake_renderer_.WaitForFrame(kDefaultTimeOut), RenderedFrame()); |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 839 | video_receive_stream_->OnCompleteFrame( |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 840 | MakeFrameWithResolution(VideoFrameType::kVideoFrameDelta, 1, 0, 0)); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 841 | EXPECT_THAT(fake_renderer_.WaitForFrame(kDefaultTimeOut), RenderedFrame()); |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 842 | |
Evan Shrubsole | 44be579 | 2022-04-26 14:24:41 | [diff] [blame] | 843 | video_receive_stream_->Stop(); |
Markus Handell | 588f9b3 | 2021-04-08 17:19:50 | [diff] [blame] | 844 | } |
| 845 | |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 846 | TEST_P(VideoReceiveStream2Test, DependantFramesAreScheduled) { |
| 847 | video_receive_stream_->Start(); |
| 848 | |
| 849 | auto key_frame = test::FakeFrameBuilder() |
| 850 | .Id(0) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 851 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 852 | .Time(kFirstRtpTimestamp) |
| 853 | .ReceivedTime(kStartTime) |
| 854 | .AsLast() |
| 855 | .Build(); |
| 856 | auto delta_frame = test::FakeFrameBuilder() |
| 857 | .Id(1) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 858 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 859 | .Time(RtpTimestampForFrame(1)) |
| 860 | .ReceivedTime(ReceiveTimeForFrame(1)) |
| 861 | .Refs({0}) |
| 862 | .AsLast() |
| 863 | .Build(); |
| 864 | |
| 865 | // Expect frames are decoded in order. |
| 866 | InSequence seq; |
Tony Herre | 55b593f | 2023-08-29 14:05:49 | [diff] [blame] | 867 | EXPECT_CALL(mock_decoder_, Decode(test::RtpTimestamp(kFirstRtpTimestamp), _)); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 868 | EXPECT_CALL(mock_decoder_, Decode(test::RtpTimestamp(kFirstRtpTimestamp + |
| 869 | k30FpsRtpTimestampDelta), |
Tony Herre | 55b593f | 2023-08-29 14:05:49 | [diff] [blame] | 870 | _)) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 871 | .Times(1); |
| 872 | video_receive_stream_->OnCompleteFrame(std::move(key_frame)); |
| 873 | EXPECT_THAT(fake_renderer_.WaitForFrame(TimeDelta::Zero()), RenderedFrame()); |
| 874 | |
| 875 | time_controller_.AdvanceTime(k30FpsDelay); |
| 876 | video_receive_stream_->OnCompleteFrame(std::move(delta_frame)); |
| 877 | EXPECT_THAT(fake_renderer_.WaitForFrame(k30FpsDelay), RenderedFrame()); |
| 878 | |
| 879 | video_receive_stream_->Stop(); |
| 880 | } |
| 881 | |
| 882 | TEST_P(VideoReceiveStream2Test, FramesScheduledInOrder) { |
| 883 | video_receive_stream_->Start(); |
| 884 | |
| 885 | auto key_frame = test::FakeFrameBuilder() |
| 886 | .Id(0) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 887 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 888 | .Time(kFirstRtpTimestamp) |
| 889 | .AsLast() |
| 890 | .Build(); |
| 891 | auto delta_frame1 = test::FakeFrameBuilder() |
| 892 | .Id(1) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 893 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 894 | .Time(RtpTimestampForFrame(1)) |
| 895 | .Refs({0}) |
| 896 | .AsLast() |
| 897 | .Build(); |
| 898 | auto delta_frame2 = test::FakeFrameBuilder() |
| 899 | .Id(2) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 900 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 901 | .Time(RtpTimestampForFrame(2)) |
| 902 | .Refs({1}) |
| 903 | .AsLast() |
| 904 | .Build(); |
| 905 | |
| 906 | // Expect frames are decoded in order despite delta_frame1 arriving first. |
| 907 | InSequence seq; |
Tony Herre | 55b593f | 2023-08-29 14:05:49 | [diff] [blame] | 908 | EXPECT_CALL(mock_decoder_, Decode(test::RtpTimestamp(kFirstRtpTimestamp), _)) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 909 | .Times(1); |
| 910 | EXPECT_CALL(mock_decoder_, |
Tony Herre | 55b593f | 2023-08-29 14:05:49 | [diff] [blame] | 911 | Decode(test::RtpTimestamp(RtpTimestampForFrame(1)), _)) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 912 | .Times(1); |
| 913 | EXPECT_CALL(mock_decoder_, |
Tony Herre | 55b593f | 2023-08-29 14:05:49 | [diff] [blame] | 914 | Decode(test::RtpTimestamp(RtpTimestampForFrame(2)), _)) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 915 | .Times(1); |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 916 | key_frame->SetReceivedTime(env_.clock().CurrentTime().ms()); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 917 | video_receive_stream_->OnCompleteFrame(std::move(key_frame)); |
| 918 | EXPECT_THAT(fake_renderer_.WaitForFrame(TimeDelta::Zero()), RenderedFrame()); |
| 919 | |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 920 | delta_frame2->SetReceivedTime(env_.clock().CurrentTime().ms()); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 921 | video_receive_stream_->OnCompleteFrame(std::move(delta_frame2)); |
| 922 | EXPECT_THAT(fake_renderer_.WaitForFrame(k30FpsDelay), DidNotReceiveFrame()); |
| 923 | // `delta_frame1` arrives late. |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 924 | delta_frame1->SetReceivedTime(env_.clock().CurrentTime().ms()); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 925 | video_receive_stream_->OnCompleteFrame(std::move(delta_frame1)); |
| 926 | EXPECT_THAT(fake_renderer_.WaitForFrame(k30FpsDelay), RenderedFrame()); |
| 927 | EXPECT_THAT(fake_renderer_.WaitForFrame(k30FpsDelay * 2), RenderedFrame()); |
| 928 | video_receive_stream_->Stop(); |
| 929 | } |
| 930 | |
| 931 | TEST_P(VideoReceiveStream2Test, WaitsforAllSpatialLayers) { |
| 932 | video_receive_stream_->Start(); |
| 933 | auto sl0 = test::FakeFrameBuilder() |
| 934 | .Id(0) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 935 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 936 | .Time(kFirstRtpTimestamp) |
| 937 | .ReceivedTime(kStartTime) |
| 938 | .Build(); |
| 939 | auto sl1 = test::FakeFrameBuilder() |
| 940 | .Id(1) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 941 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 942 | .ReceivedTime(kStartTime) |
| 943 | .Time(kFirstRtpTimestamp) |
| 944 | .Refs({0}) |
| 945 | .Build(); |
| 946 | auto sl2 = test::FakeFrameBuilder() |
| 947 | .Id(2) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 948 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 949 | .ReceivedTime(kStartTime) |
| 950 | .Time(kFirstRtpTimestamp) |
| 951 | .Refs({0, 1}) |
| 952 | .AsLast() |
| 953 | .Build(); |
| 954 | |
| 955 | // No decodes should be called until `sl2` is received. |
Tony Herre | 55b593f | 2023-08-29 14:05:49 | [diff] [blame] | 956 | EXPECT_CALL(mock_decoder_, Decode(_, _)).Times(0); |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 957 | sl0->SetReceivedTime(env_.clock().CurrentTime().ms()); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 958 | video_receive_stream_->OnCompleteFrame(std::move(sl0)); |
| 959 | EXPECT_THAT(fake_renderer_.WaitForFrame(TimeDelta::Zero()), |
| 960 | DidNotReceiveFrame()); |
| 961 | video_receive_stream_->OnCompleteFrame(std::move(sl1)); |
| 962 | EXPECT_THAT(fake_renderer_.WaitForFrame(TimeDelta::Zero()), |
| 963 | DidNotReceiveFrame()); |
| 964 | // When `sl2` arrives decode should happen. |
Tony Herre | 55b593f | 2023-08-29 14:05:49 | [diff] [blame] | 965 | EXPECT_CALL(mock_decoder_, Decode(test::RtpTimestamp(kFirstRtpTimestamp), _)) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 966 | .Times(1); |
| 967 | video_receive_stream_->OnCompleteFrame(std::move(sl2)); |
| 968 | EXPECT_THAT(fake_renderer_.WaitForFrame(TimeDelta::Zero()), RenderedFrame()); |
| 969 | video_receive_stream_->Stop(); |
| 970 | } |
| 971 | |
| 972 | TEST_P(VideoReceiveStream2Test, FramesFastForwardOnSystemHalt) { |
| 973 | video_receive_stream_->Start(); |
| 974 | |
| 975 | // The frame structure looks like this, |
| 976 | // F1 |
| 977 | // / |
| 978 | // F0 --> F2 |
| 979 | // |
| 980 | // In this case we will have a system halt simulated. By the time the system |
| 981 | // resumes, F1 will be old and so F2 should be decoded. |
| 982 | auto key_frame = test::FakeFrameBuilder() |
| 983 | .Id(0) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 984 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 985 | .Time(kFirstRtpTimestamp) |
| 986 | .AsLast() |
| 987 | .Build(); |
| 988 | auto ffwd_frame = test::FakeFrameBuilder() |
| 989 | .Id(1) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 990 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 991 | .Time(RtpTimestampForFrame(1)) |
| 992 | .Refs({0}) |
| 993 | .AsLast() |
| 994 | .Build(); |
| 995 | auto rendered_frame = test::FakeFrameBuilder() |
| 996 | .Id(2) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 997 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 998 | .Time(RtpTimestampForFrame(2)) |
| 999 | .Refs({0}) |
| 1000 | .AsLast() |
| 1001 | .Build(); |
| 1002 | InSequence seq; |
Tony Herre | 55b593f | 2023-08-29 14:05:49 | [diff] [blame] | 1003 | EXPECT_CALL(mock_decoder_, Decode(test::RtpTimestamp(kFirstRtpTimestamp), _)) |
philipel | 27b35a7 | 2022-07-05 07:59:55 | [diff] [blame] | 1004 | .WillOnce(testing::DoAll(Invoke([&] { |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 1005 | // System halt will be simulated in the decode. |
| 1006 | time_controller_.AdvanceTime(k30FpsDelay * 2); |
| 1007 | }), |
| 1008 | DefaultDecodeAction())); |
| 1009 | EXPECT_CALL(mock_decoder_, |
Tony Herre | 55b593f | 2023-08-29 14:05:49 | [diff] [blame] | 1010 | Decode(test::RtpTimestamp(RtpTimestampForFrame(2)), _)); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 1011 | video_receive_stream_->OnCompleteFrame(std::move(key_frame)); |
| 1012 | video_receive_stream_->OnCompleteFrame(std::move(ffwd_frame)); |
| 1013 | video_receive_stream_->OnCompleteFrame(std::move(rendered_frame)); |
Evan Shrubsole | 7cbd8de | 2022-08-16 08:08:53 | [diff] [blame] | 1014 | EXPECT_THAT(fake_renderer_.WaitForFrame(TimeDelta::Zero()), |
| 1015 | RenderedFrameWith(RtpTimestamp(RtpTimestampForFrame(0)))); |
| 1016 | EXPECT_THAT(fake_renderer_.WaitForFrame(TimeDelta::Zero()), |
| 1017 | RenderedFrameWith(RtpTimestamp(RtpTimestampForFrame(2)))); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 1018 | |
| 1019 | // Check stats show correct dropped frames. |
| 1020 | auto stats = video_receive_stream_->GetStats(); |
| 1021 | EXPECT_EQ(stats.frames_dropped, 1u); |
| 1022 | |
| 1023 | video_receive_stream_->Stop(); |
| 1024 | } |
| 1025 | |
| 1026 | TEST_P(VideoReceiveStream2Test, BetterFrameInsertedWhileWaitingToDecodeFrame) { |
| 1027 | video_receive_stream_->Start(); |
| 1028 | |
| 1029 | auto key_frame = test::FakeFrameBuilder() |
| 1030 | .Id(0) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 1031 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 1032 | .Time(kFirstRtpTimestamp) |
| 1033 | .ReceivedTime(ReceiveTimeForFrame(0)) |
| 1034 | .AsLast() |
| 1035 | .Build(); |
| 1036 | auto f1 = test::FakeFrameBuilder() |
| 1037 | .Id(1) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 1038 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 1039 | .Time(RtpTimestampForFrame(1)) |
| 1040 | .ReceivedTime(ReceiveTimeForFrame(1)) |
| 1041 | .Refs({0}) |
| 1042 | .AsLast() |
| 1043 | .Build(); |
| 1044 | auto f2 = test::FakeFrameBuilder() |
| 1045 | .Id(2) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 1046 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 1047 | .Time(RtpTimestampForFrame(2)) |
| 1048 | .ReceivedTime(ReceiveTimeForFrame(2)) |
| 1049 | .Refs({0}) |
| 1050 | .AsLast() |
| 1051 | .Build(); |
| 1052 | |
| 1053 | video_receive_stream_->OnCompleteFrame(std::move(key_frame)); |
| 1054 | EXPECT_THAT(fake_renderer_.WaitForFrame(TimeDelta::Zero()), RenderedFrame()); |
| 1055 | |
| 1056 | InSequence seq; |
| 1057 | EXPECT_CALL(mock_decoder_, |
Tony Herre | 55b593f | 2023-08-29 14:05:49 | [diff] [blame] | 1058 | Decode(test::RtpTimestamp(RtpTimestampForFrame(1)), _)) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 1059 | .Times(1); |
| 1060 | EXPECT_CALL(mock_decoder_, |
Tony Herre | 55b593f | 2023-08-29 14:05:49 | [diff] [blame] | 1061 | Decode(test::RtpTimestamp(RtpTimestampForFrame(2)), _)) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 1062 | .Times(1); |
| 1063 | // Simulate f1 arriving after f2 but before f2 is decoded. |
| 1064 | video_receive_stream_->OnCompleteFrame(std::move(f2)); |
| 1065 | EXPECT_THAT(fake_renderer_.WaitForFrame(k30FpsDelay), DidNotReceiveFrame()); |
| 1066 | video_receive_stream_->OnCompleteFrame(std::move(f1)); |
| 1067 | EXPECT_THAT(fake_renderer_.WaitForFrame(k30FpsDelay), RenderedFrame()); |
| 1068 | EXPECT_THAT(fake_renderer_.WaitForFrame(k30FpsDelay), RenderedFrame()); |
| 1069 | |
| 1070 | video_receive_stream_->Stop(); |
| 1071 | } |
| 1072 | |
| 1073 | // Note: This test takes a long time (~10s) to run if the fake metronome is |
| 1074 | // active. Since the test needs to wait for the timestamp to rollover, it has a |
| 1075 | // fake delay of around 6.5 hours. Even though time is simulated, this will be |
| 1076 | // around 1,500,000 metronome tick invocations. |
| 1077 | TEST_P(VideoReceiveStream2Test, RtpTimestampWrapAround) { |
Evan Shrubsole | 7cbd8de | 2022-08-16 08:08:53 | [diff] [blame] | 1078 | EXPECT_CALL(mock_transport_, SendRtcp).Times(AnyNumber()); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 1079 | video_receive_stream_->Start(); |
| 1080 | |
| 1081 | constexpr uint32_t kBaseRtp = std::numeric_limits<uint32_t>::max() / 2; |
| 1082 | video_receive_stream_->OnCompleteFrame( |
| 1083 | test::FakeFrameBuilder() |
| 1084 | .Id(0) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 1085 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 1086 | .Time(kBaseRtp) |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 1087 | .ReceivedTime(env_.clock().CurrentTime()) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 1088 | .AsLast() |
| 1089 | .Build()); |
| 1090 | EXPECT_THAT(fake_renderer_.WaitForFrame(TimeDelta::Zero()), RenderedFrame()); |
| 1091 | time_controller_.AdvanceTime(k30FpsDelay); |
| 1092 | video_receive_stream_->OnCompleteFrame( |
| 1093 | test::FakeFrameBuilder() |
| 1094 | .Id(1) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 1095 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 1096 | .Time(kBaseRtp + k30FpsRtpTimestampDelta) |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 1097 | .ReceivedTime(env_.clock().CurrentTime()) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 1098 | .AsLast() |
| 1099 | .Build()); |
| 1100 | EXPECT_THAT(fake_renderer_.WaitForFrame(k30FpsDelay), RenderedFrame()); |
| 1101 | |
| 1102 | // Pause stream so that RTP timestamp wraps around. |
| 1103 | constexpr uint32_t kLastRtp = kBaseRtp + k30FpsRtpTimestampDelta; |
| 1104 | constexpr uint32_t kWrapAroundRtp = |
| 1105 | kLastRtp + std::numeric_limits<uint32_t>::max() / 2 + 1; |
| 1106 | // Pause for corresponding delay such that RTP timestamp would increase this |
| 1107 | // much at 30fps. |
| 1108 | constexpr TimeDelta kWrapAroundDelay = |
| 1109 | (std::numeric_limits<uint32_t>::max() / 2 + 1) / kRtpTimestampHz; |
| 1110 | |
| 1111 | time_controller_.AdvanceTime(kWrapAroundDelay); |
| 1112 | video_receive_stream_->OnCompleteFrame( |
| 1113 | test::FakeFrameBuilder() |
| 1114 | .Id(2) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 1115 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 1116 | .Time(kWrapAroundRtp) |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 1117 | .ReceivedTime(env_.clock().CurrentTime()) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 1118 | .AsLast() |
| 1119 | .Build()); |
Tony Herre | 55b593f | 2023-08-29 14:05:49 | [diff] [blame] | 1120 | EXPECT_CALL(mock_decoder_, Decode(test::RtpTimestamp(kWrapAroundRtp), _)) |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 1121 | .Times(1); |
philipel | 2f3b75d | 2024-03-13 12:02:15 | [diff] [blame] | 1122 | EXPECT_THAT(fake_renderer_.WaitForFrame(TimeDelta::Seconds(1)), |
| 1123 | RenderedFrame()); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 1124 | |
| 1125 | video_receive_stream_->Stop(); |
| 1126 | } |
| 1127 | |
Evan Shrubsole | dcb9c5d | 2022-06-13 15:39:53 | [diff] [blame] | 1128 | // If a frame was lost causing the stream to become temporarily non-decodable |
| 1129 | // and the sender reduces their framerate during this time, the video stream |
| 1130 | // should start decoding at the new framerate. However, if the connection is |
| 1131 | // poor, a keyframe will take a long time to send. If the timing of the incoming |
| 1132 | // frames was not kept up to date with the new framerate while the stream was |
| 1133 | // decodable, this late frame will have a large delay as the rtp timestamp of |
| 1134 | // this keyframe will look like the frame arrived early if the frame-rate was |
| 1135 | // not updated. |
| 1136 | TEST_P(VideoReceiveStream2Test, PoorConnectionWithFpsChangeDuringLostFrame) { |
| 1137 | video_receive_stream_->Start(); |
| 1138 | |
| 1139 | constexpr Frequency k15Fps = Frequency::Hertz(15); |
| 1140 | constexpr TimeDelta k15FpsDelay = 1 / k15Fps; |
| 1141 | constexpr uint32_t k15FpsRtpTimestampDelta = kRtpTimestampHz / k15Fps; |
| 1142 | |
| 1143 | // Initial keyframe and frames at 30fps. |
| 1144 | video_receive_stream_->OnCompleteFrame( |
| 1145 | test::FakeFrameBuilder() |
| 1146 | .Id(0) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 1147 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | dcb9c5d | 2022-06-13 15:39:53 | [diff] [blame] | 1148 | .Time(RtpTimestampForFrame(0)) |
| 1149 | .ReceivedTime(ReceiveTimeForFrame(0)) |
| 1150 | .AsLast() |
| 1151 | .Build()); |
| 1152 | EXPECT_THAT(fake_renderer_.WaitForFrame(k30FpsDelay, /*advance_time=*/true), |
| 1153 | RenderedFrameWith(RtpTimestamp(RtpTimestampForFrame(0)))); |
| 1154 | |
| 1155 | video_receive_stream_->OnCompleteFrame( |
| 1156 | test::FakeFrameBuilder() |
| 1157 | .Id(1) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 1158 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | dcb9c5d | 2022-06-13 15:39:53 | [diff] [blame] | 1159 | .Time(RtpTimestampForFrame(1)) |
| 1160 | .ReceivedTime(ReceiveTimeForFrame(1)) |
| 1161 | .Refs({0}) |
| 1162 | .AsLast() |
| 1163 | .Build()); |
| 1164 | EXPECT_THAT(fake_renderer_.WaitForFrame(k30FpsDelay, /*advance_time=*/true), |
| 1165 | RenderedFrameWith(RtpTimestamp(RtpTimestampForFrame(1)))); |
| 1166 | |
| 1167 | // Simulate lost frame 2, followed by 2 second of frames at 30fps, followed by |
| 1168 | // 2 second of frames at 15 fps, and then a keyframe. |
| 1169 | time_controller_.AdvanceTime(k30FpsDelay); |
| 1170 | |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 1171 | Timestamp send_30fps_end_time = |
| 1172 | env_.clock().CurrentTime() + TimeDelta::Seconds(2); |
Evan Shrubsole | dcb9c5d | 2022-06-13 15:39:53 | [diff] [blame] | 1173 | int id = 3; |
| 1174 | EXPECT_CALL(mock_transport_, SendRtcp).Times(AnyNumber()); |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 1175 | while (env_.clock().CurrentTime() < send_30fps_end_time) { |
Evan Shrubsole | dcb9c5d | 2022-06-13 15:39:53 | [diff] [blame] | 1176 | ++id; |
| 1177 | video_receive_stream_->OnCompleteFrame( |
| 1178 | test::FakeFrameBuilder() |
| 1179 | .Id(id) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 1180 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | dcb9c5d | 2022-06-13 15:39:53 | [diff] [blame] | 1181 | .Time(RtpTimestampForFrame(id)) |
| 1182 | .ReceivedTime(ReceiveTimeForFrame(id)) |
| 1183 | .Refs({id - 1}) |
| 1184 | .AsLast() |
| 1185 | .Build()); |
| 1186 | EXPECT_THAT(fake_renderer_.WaitForFrame(k30FpsDelay, /*advance_time=*/true), |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 1187 | Eq(std::nullopt)); |
Evan Shrubsole | dcb9c5d | 2022-06-13 15:39:53 | [diff] [blame] | 1188 | } |
| 1189 | uint32_t current_rtp = RtpTimestampForFrame(id); |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 1190 | Timestamp send_15fps_end_time = |
| 1191 | env_.clock().CurrentTime() + TimeDelta::Seconds(2); |
| 1192 | while (env_.clock().CurrentTime() < send_15fps_end_time) { |
Evan Shrubsole | dcb9c5d | 2022-06-13 15:39:53 | [diff] [blame] | 1193 | ++id; |
| 1194 | current_rtp += k15FpsRtpTimestampDelta; |
| 1195 | video_receive_stream_->OnCompleteFrame( |
| 1196 | test::FakeFrameBuilder() |
| 1197 | .Id(id) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 1198 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | dcb9c5d | 2022-06-13 15:39:53 | [diff] [blame] | 1199 | .Time(current_rtp) |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 1200 | .ReceivedTime(env_.clock().CurrentTime()) |
Evan Shrubsole | dcb9c5d | 2022-06-13 15:39:53 | [diff] [blame] | 1201 | .Refs({id - 1}) |
| 1202 | .AsLast() |
| 1203 | .Build()); |
| 1204 | EXPECT_THAT(fake_renderer_.WaitForFrame(k15FpsDelay, /*advance_time=*/true), |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 1205 | Eq(std::nullopt)); |
Evan Shrubsole | dcb9c5d | 2022-06-13 15:39:53 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | ++id; |
| 1209 | current_rtp += k15FpsRtpTimestampDelta; |
| 1210 | // Insert keyframe which will recover the stream. However, on a poor |
| 1211 | // connection the keyframe will take significant time to send. |
| 1212 | constexpr TimeDelta kKeyframeDelay = TimeDelta::Millis(200); |
| 1213 | video_receive_stream_->OnCompleteFrame( |
| 1214 | test::FakeFrameBuilder() |
| 1215 | .Id(id) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 1216 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | dcb9c5d | 2022-06-13 15:39:53 | [diff] [blame] | 1217 | .Time(current_rtp) |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 1218 | .ReceivedTime(env_.clock().CurrentTime() + kKeyframeDelay) |
Evan Shrubsole | dcb9c5d | 2022-06-13 15:39:53 | [diff] [blame] | 1219 | .AsLast() |
| 1220 | .Build()); |
| 1221 | // If the framerate was not updated to be 15fps from the frames that arrived |
| 1222 | // previously, this will fail, as the delay will be longer. |
| 1223 | EXPECT_THAT(fake_renderer_.WaitForFrame(k15FpsDelay, /*advance_time=*/true), |
| 1224 | RenderedFrameWith(RtpTimestamp(current_rtp))); |
| 1225 | |
| 1226 | video_receive_stream_->Stop(); |
| 1227 | } |
| 1228 | |
Evan Shrubsole | 4d3ba77 | 2022-06-22 14:32:36 | [diff] [blame] | 1229 | TEST_P(VideoReceiveStream2Test, StreamShouldNotTimeoutWhileWaitingForFrame) { |
| 1230 | // Disable smoothing since this makes it hard to test frame timing. |
| 1231 | config_.enable_prerenderer_smoothing = false; |
| 1232 | RecreateReceiveStream(); |
| 1233 | |
| 1234 | video_receive_stream_->Start(); |
| 1235 | EXPECT_CALL(mock_transport_, SendRtcp).Times(AnyNumber()); |
| 1236 | |
| 1237 | video_receive_stream_->OnCompleteFrame( |
| 1238 | test::FakeFrameBuilder() |
| 1239 | .Id(0) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 1240 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | 4d3ba77 | 2022-06-22 14:32:36 | [diff] [blame] | 1241 | .Time(RtpTimestampForFrame(0)) |
| 1242 | .ReceivedTime(ReceiveTimeForFrame(0)) |
| 1243 | .AsLast() |
| 1244 | .Build()); |
| 1245 | EXPECT_THAT(fake_renderer_.WaitForFrame(k30FpsDelay, /*advance_time=*/true), |
| 1246 | RenderedFrameWith(RtpTimestamp(RtpTimestampForFrame(0)))); |
| 1247 | |
| 1248 | for (int id = 1; id < 30; ++id) { |
| 1249 | video_receive_stream_->OnCompleteFrame( |
| 1250 | test::FakeFrameBuilder() |
| 1251 | .Id(id) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 1252 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | 4d3ba77 | 2022-06-22 14:32:36 | [diff] [blame] | 1253 | .Time(RtpTimestampForFrame(id)) |
| 1254 | .ReceivedTime(ReceiveTimeForFrame(id)) |
| 1255 | .Refs({0}) |
| 1256 | .AsLast() |
| 1257 | .Build()); |
| 1258 | EXPECT_THAT(fake_renderer_.WaitForFrame(k30FpsDelay, /*advance_time=*/true), |
| 1259 | RenderedFrameWith(RtpTimestamp(RtpTimestampForFrame(id)))); |
| 1260 | } |
| 1261 | |
| 1262 | // Simulate a pause in the stream, followed by a decodable frame that is ready |
| 1263 | // long in the future. The stream should not timeout in this case, but rather |
| 1264 | // decode the frame just before the timeout. |
| 1265 | time_controller_.AdvanceTime(TimeDelta::Millis(2900)); |
| 1266 | uint32_t late_decode_rtp = kFirstRtpTimestamp + 200 * k30FpsRtpTimestampDelta; |
| 1267 | video_receive_stream_->OnCompleteFrame( |
| 1268 | test::FakeFrameBuilder() |
| 1269 | .Id(121) |
Sergio Garcia Murillo | b5289d7 | 2024-10-24 12:10:53 | [diff] [blame] | 1270 | .PayloadType(kH264PayloadType) |
Evan Shrubsole | 4d3ba77 | 2022-06-22 14:32:36 | [diff] [blame] | 1271 | .Time(late_decode_rtp) |
Danil Chapovalov | 2233349 | 2023-12-07 11:10:46 | [diff] [blame] | 1272 | .ReceivedTime(env_.clock().CurrentTime()) |
Evan Shrubsole | 4d3ba77 | 2022-06-22 14:32:36 | [diff] [blame] | 1273 | .AsLast() |
| 1274 | .Build()); |
| 1275 | EXPECT_THAT(fake_renderer_.WaitForFrame(TimeDelta::Millis(100), |
| 1276 | /*advance_time=*/true), |
| 1277 | RenderedFrameWith(RtpTimestamp(late_decode_rtp))); |
| 1278 | |
| 1279 | video_receive_stream_->Stop(); |
| 1280 | } |
| 1281 | |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 1282 | INSTANTIATE_TEST_SUITE_P(VideoReceiveStream2Test, |
| 1283 | VideoReceiveStream2Test, |
| 1284 | testing::Bool(), |
| 1285 | [](const auto& test_param_info) { |
Evan Shrubsole | dcb9c5d | 2022-06-13 15:39:53 | [diff] [blame] | 1286 | return (test_param_info.param |
| 1287 | ? "ScheduleDecodesWithMetronome" |
| 1288 | : "ScheduleDecodesWithPostTask"); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 1289 | }); |
| 1290 | |
Tommi | ae4d097 | 2020-05-18 06:45:38 | [diff] [blame] | 1291 | } // namespace webrtc |