blob: 20667c9db1164c8ad280229fe9e763c8d2bdaa51 [file] [log] [blame]
stefan@webrtc.org9f557c12013-05-17 12:55:07 +00001/*
2 * Copyright (c) 2011 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/video_coding/timing.h"
Jonas Olssona4d87372019-07-05 19:08:33 +020012
Evan Shrubsoled6cdf802022-03-02 15:13:55 +010013#include "api/units/frequency.h"
14#include "api/units/time_delta.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "system_wrappers/include/clock.h"
16#include "test/gtest.h"
Jonas Orelande02f9ee2022-03-25 12:43:14 +010017#include "test/scoped_key_value_config.h"
stefan@webrtc.org9f557c12013-05-17 12:55:07 +000018
19namespace webrtc {
Åsa Persson8368d1a2018-01-05 12:44:45 +010020namespace {
Evan Shrubsoled6cdf802022-03-02 15:13:55 +010021
22constexpr Frequency k25Fps = Frequency::Hertz(25);
23constexpr Frequency k90kHz = Frequency::KiloHertz(90);
24
Åsa Persson8368d1a2018-01-05 12:44:45 +010025} // namespace
stefan@webrtc.org9f557c12013-05-17 12:55:07 +000026
Johannes Kron985905d2021-06-29 11:37:06 +020027TEST(ReceiverTimingTest, JitterDelay) {
Jonas Orelande02f9ee2022-03-25 12:43:14 +010028 test::ScopedKeyValueConfig field_trials;
stefan@webrtc.org9f557c12013-05-17 12:55:07 +000029 SimulatedClock clock(0);
Jonas Orelande02f9ee2022-03-25 12:43:14 +010030 VCMTiming timing(&clock, field_trials);
Åsa Persson8368d1a2018-01-05 12:44:45 +010031 timing.Reset();
32
33 uint32_t timestamp = 0;
34 timing.UpdateCurrentDelay(timestamp);
stefan@webrtc.org9f557c12013-05-17 12:55:07 +000035
36 timing.Reset();
37
Evan Shrubsoled6cdf802022-03-02 15:13:55 +010038 timing.IncomingTimestamp(timestamp, clock.CurrentTime());
39 TimeDelta jitter_delay = TimeDelta::Millis(20);
40 timing.SetJitterDelay(jitter_delay);
Åsa Persson8368d1a2018-01-05 12:44:45 +010041 timing.UpdateCurrentDelay(timestamp);
Evan Shrubsoled6cdf802022-03-02 15:13:55 +010042 timing.set_render_delay(TimeDelta::Zero());
43 auto wait_time = timing.MaxWaitingTime(
44 timing.RenderTime(timestamp, clock.CurrentTime()), clock.CurrentTime(),
45 /*too_many_frames_queued=*/false);
stefan@webrtc.org9f557c12013-05-17 12:55:07 +000046 // First update initializes the render time. Since we have no decode delay
Evan Shrubsoled6cdf802022-03-02 15:13:55 +010047 // we get wait_time = renderTime - now - renderDelay = jitter.
48 EXPECT_EQ(jitter_delay, wait_time);
stefan@webrtc.org9f557c12013-05-17 12:55:07 +000049
Evan Shrubsoled6cdf802022-03-02 15:13:55 +010050 jitter_delay += TimeDelta::Millis(VCMTiming::kDelayMaxChangeMsPerS + 10);
Åsa Persson8368d1a2018-01-05 12:44:45 +010051 timestamp += 90000;
stefan@webrtc.org9f557c12013-05-17 12:55:07 +000052 clock.AdvanceTimeMilliseconds(1000);
Evan Shrubsoled6cdf802022-03-02 15:13:55 +010053 timing.SetJitterDelay(jitter_delay);
Åsa Persson8368d1a2018-01-05 12:44:45 +010054 timing.UpdateCurrentDelay(timestamp);
Evan Shrubsoled6cdf802022-03-02 15:13:55 +010055 wait_time = timing.MaxWaitingTime(
56 timing.RenderTime(timestamp, clock.CurrentTime()), clock.CurrentTime(),
57 /*too_many_frames_queued=*/false);
stefan@webrtc.org9f557c12013-05-17 12:55:07 +000058 // Since we gradually increase the delay we only get 100 ms every second.
Evan Shrubsoled6cdf802022-03-02 15:13:55 +010059 EXPECT_EQ(jitter_delay - TimeDelta::Millis(10), wait_time);
stefan@webrtc.org9f557c12013-05-17 12:55:07 +000060
Åsa Persson8368d1a2018-01-05 12:44:45 +010061 timestamp += 90000;
stefan@webrtc.org9f557c12013-05-17 12:55:07 +000062 clock.AdvanceTimeMilliseconds(1000);
Åsa Persson8368d1a2018-01-05 12:44:45 +010063 timing.UpdateCurrentDelay(timestamp);
Evan Shrubsoled6cdf802022-03-02 15:13:55 +010064 wait_time = timing.MaxWaitingTime(
65 timing.RenderTime(timestamp, clock.CurrentTime()), clock.CurrentTime(),
66 /*too_many_frames_queued=*/false);
67 EXPECT_EQ(jitter_delay, wait_time);
stefan@webrtc.org9f557c12013-05-17 12:55:07 +000068
Åsa Persson8368d1a2018-01-05 12:44:45 +010069 // Insert frames without jitter, verify that this gives the exact wait time.
70 const int kNumFrames = 300;
71 for (int i = 0; i < kNumFrames; i++) {
Evan Shrubsoled6cdf802022-03-02 15:13:55 +010072 clock.AdvanceTime(1 / k25Fps);
73 timestamp += k90kHz / k25Fps;
74 timing.IncomingTimestamp(timestamp, clock.CurrentTime());
stefan@webrtc.org9f557c12013-05-17 12:55:07 +000075 }
Åsa Persson8368d1a2018-01-05 12:44:45 +010076 timing.UpdateCurrentDelay(timestamp);
Evan Shrubsoled6cdf802022-03-02 15:13:55 +010077 wait_time = timing.MaxWaitingTime(
78 timing.RenderTime(timestamp, clock.CurrentTime()), clock.CurrentTime(),
79 /*too_many_frames_queued=*/false);
80 EXPECT_EQ(jitter_delay, wait_time);
stefan@webrtc.org9f557c12013-05-17 12:55:07 +000081
Åsa Persson8368d1a2018-01-05 12:44:45 +010082 // Add decode time estimates for 1 second.
Evan Shrubsoled6cdf802022-03-02 15:13:55 +010083 const TimeDelta kDecodeTime = TimeDelta::Millis(10);
84 for (int i = 0; i < k25Fps.hertz(); i++) {
85 clock.AdvanceTime(kDecodeTime);
86 timing.StopDecodeTimer(kDecodeTime, clock.CurrentTime());
87 timestamp += k90kHz / k25Fps;
88 clock.AdvanceTime(1 / k25Fps - kDecodeTime);
89 timing.IncomingTimestamp(timestamp, clock.CurrentTime());
stefan@webrtc.org9f557c12013-05-17 12:55:07 +000090 }
Åsa Persson8368d1a2018-01-05 12:44:45 +010091 timing.UpdateCurrentDelay(timestamp);
Evan Shrubsoled6cdf802022-03-02 15:13:55 +010092 wait_time = timing.MaxWaitingTime(
93 timing.RenderTime(timestamp, clock.CurrentTime()), clock.CurrentTime(),
94 /*too_many_frames_queued=*/false);
95 EXPECT_EQ(jitter_delay, wait_time);
stefan@webrtc.org9f557c12013-05-17 12:55:07 +000096
Evan Shrubsoled6cdf802022-03-02 15:13:55 +010097 const TimeDelta kMinTotalDelay = TimeDelta::Millis(200);
98 timing.set_min_playout_delay(kMinTotalDelay);
stefan@webrtc.org9f557c12013-05-17 12:55:07 +000099 clock.AdvanceTimeMilliseconds(5000);
Åsa Persson8368d1a2018-01-05 12:44:45 +0100100 timestamp += 5 * 90000;
101 timing.UpdateCurrentDelay(timestamp);
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100102 const TimeDelta kRenderDelay = TimeDelta::Millis(10);
103 timing.set_render_delay(kRenderDelay);
104 wait_time = timing.MaxWaitingTime(
105 timing.RenderTime(timestamp, clock.CurrentTime()), clock.CurrentTime(),
106 /*too_many_frames_queued=*/false);
Åsa Persson8368d1a2018-01-05 12:44:45 +0100107 // We should at least have kMinTotalDelayMs - decodeTime (10) - renderTime
stefan@webrtc.org9f557c12013-05-17 12:55:07 +0000108 // (10) to wait.
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100109 EXPECT_EQ(kMinTotalDelay - kDecodeTime - kRenderDelay, wait_time);
stefan@webrtc.org9f557c12013-05-17 12:55:07 +0000110 // The total video delay should be equal to the min total delay.
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100111 EXPECT_EQ(kMinTotalDelay, timing.TargetVideoDelay());
stefan@webrtc.org9f557c12013-05-17 12:55:07 +0000112
mikhal@webrtc.orgadc64a72013-05-30 16:20:18 +0000113 // Reset playout delay.
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100114 timing.set_min_playout_delay(TimeDelta::Zero());
stefan@webrtc.org9f557c12013-05-17 12:55:07 +0000115 clock.AdvanceTimeMilliseconds(5000);
Åsa Persson8368d1a2018-01-05 12:44:45 +0100116 timestamp += 5 * 90000;
117 timing.UpdateCurrentDelay(timestamp);
stefan@webrtc.org9f557c12013-05-17 12:55:07 +0000118}
119
Johannes Kron985905d2021-06-29 11:37:06 +0200120TEST(ReceiverTimingTest, TimestampWrapAround) {
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100121 constexpr auto kStartTime = Timestamp::Millis(1337);
Jonas Orelande02f9ee2022-03-25 12:43:14 +0100122 test::ScopedKeyValueConfig field_trials;
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100123 SimulatedClock clock(kStartTime);
Jonas Orelande02f9ee2022-03-25 12:43:14 +0100124 VCMTiming timing(&clock, field_trials);
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100125
Åsa Persson8368d1a2018-01-05 12:44:45 +0100126 // Provoke a wrap-around. The fifth frame will have wrapped at 25 fps.
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100127 constexpr uint32_t kRtpTicksPerFrame = k90kHz / k25Fps;
128 uint32_t timestamp = 0xFFFFFFFFu - 3 * kRtpTicksPerFrame;
Åsa Persson8368d1a2018-01-05 12:44:45 +0100129 for (int i = 0; i < 5; ++i) {
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100130 timing.IncomingTimestamp(timestamp, clock.CurrentTime());
131 clock.AdvanceTime(1 / k25Fps);
132 timestamp += kRtpTicksPerFrame;
133 EXPECT_EQ(kStartTime + 3 / k25Fps,
134 timing.RenderTime(0xFFFFFFFFu, clock.CurrentTime()));
135 // One ms later in 90 kHz.
136 EXPECT_EQ(kStartTime + 3 / k25Fps + TimeDelta::Millis(1),
137 timing.RenderTime(89u, clock.CurrentTime()));
stefan@webrtc.org9f557c12013-05-17 12:55:07 +0000138 }
139}
140
Johannes Kron985905d2021-06-29 11:37:06 +0200141TEST(ReceiverTimingTest, MaxWaitingTimeIsZeroForZeroRenderTime) {
142 // This is the default path when the RTP playout delay header extension is set
Johannes Kron23bfff32021-09-28 21:31:46 +0200143 // to min==0 and max==0.
Johannes Kron985905d2021-06-29 11:37:06 +0200144 constexpr int64_t kStartTimeUs = 3.15e13; // About one year in us.
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100145 constexpr TimeDelta kTimeDelta = 1 / Frequency::Hertz(60);
146 constexpr Timestamp kZeroRenderTime = Timestamp::Zero();
Johannes Kron985905d2021-06-29 11:37:06 +0200147 SimulatedClock clock(kStartTimeUs);
Jonas Orelande02f9ee2022-03-25 12:43:14 +0100148 test::ScopedKeyValueConfig field_trials;
149 VCMTiming timing(&clock, field_trials);
Johannes Kron985905d2021-06-29 11:37:06 +0200150 timing.Reset();
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100151 timing.set_max_playout_delay(TimeDelta::Zero());
Johannes Kron985905d2021-06-29 11:37:06 +0200152 for (int i = 0; i < 10; ++i) {
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100153 clock.AdvanceTime(kTimeDelta);
154 Timestamp now = clock.CurrentTime();
155 EXPECT_LT(timing.MaxWaitingTime(kZeroRenderTime, now,
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200156 /*too_many_frames_queued=*/false),
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100157 TimeDelta::Zero());
Johannes Kron985905d2021-06-29 11:37:06 +0200158 }
159 // Another frame submitted at the same time also returns a negative max
160 // waiting time.
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100161 Timestamp now = clock.CurrentTime();
162 EXPECT_LT(timing.MaxWaitingTime(kZeroRenderTime, now,
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200163 /*too_many_frames_queued=*/false),
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100164 TimeDelta::Zero());
Johannes Kron985905d2021-06-29 11:37:06 +0200165 // MaxWaitingTime should be less than zero even if there's a burst of frames.
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100166 EXPECT_LT(timing.MaxWaitingTime(kZeroRenderTime, now,
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200167 /*too_many_frames_queued=*/false),
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100168 TimeDelta::Zero());
169 EXPECT_LT(timing.MaxWaitingTime(kZeroRenderTime, now,
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200170 /*too_many_frames_queued=*/false),
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100171 TimeDelta::Zero());
172 EXPECT_LT(timing.MaxWaitingTime(kZeroRenderTime, now,
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200173 /*too_many_frames_queued=*/false),
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100174 TimeDelta::Zero());
Johannes Kron985905d2021-06-29 11:37:06 +0200175}
176
177TEST(ReceiverTimingTest, MaxWaitingTimeZeroDelayPacingExperiment) {
178 // The minimum pacing is enabled by a field trial and active if the RTP
179 // playout delay header extension is set to min==0.
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100180 constexpr TimeDelta kMinPacing = TimeDelta::Millis(3);
Jonas Orelande02f9ee2022-03-25 12:43:14 +0100181 test::ScopedKeyValueConfig field_trials(
Johannes Kron985905d2021-06-29 11:37:06 +0200182 "WebRTC-ZeroPlayoutDelay/min_pacing:3ms/");
183 constexpr int64_t kStartTimeUs = 3.15e13; // About one year in us.
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100184 constexpr TimeDelta kTimeDelta = 1 / Frequency::Hertz(60);
185 constexpr auto kZeroRenderTime = Timestamp::Zero();
Johannes Kron985905d2021-06-29 11:37:06 +0200186 SimulatedClock clock(kStartTimeUs);
Jonas Orelande02f9ee2022-03-25 12:43:14 +0100187 VCMTiming timing(&clock, field_trials);
Johannes Kron985905d2021-06-29 11:37:06 +0200188 timing.Reset();
189 // MaxWaitingTime() returns zero for evenly spaced video frames.
190 for (int i = 0; i < 10; ++i) {
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100191 clock.AdvanceTime(kTimeDelta);
192 Timestamp now = clock.CurrentTime();
193 EXPECT_EQ(timing.MaxWaitingTime(kZeroRenderTime, now,
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200194 /*too_many_frames_queued=*/false),
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100195 TimeDelta::Zero());
196 timing.SetLastDecodeScheduledTimestamp(now);
Johannes Kron985905d2021-06-29 11:37:06 +0200197 }
198 // Another frame submitted at the same time is paced according to the field
199 // trial setting.
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100200 auto now = clock.CurrentTime();
201 EXPECT_EQ(timing.MaxWaitingTime(kZeroRenderTime, now,
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200202 /*too_many_frames_queued=*/false),
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100203 kMinPacing);
Rezaul Barbhuiya82c22482021-08-05 17:54:11 -0700204 // If there's a burst of frames, the wait time is calculated based on next
205 // decode time.
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100206 EXPECT_EQ(timing.MaxWaitingTime(kZeroRenderTime, now,
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200207 /*too_many_frames_queued=*/false),
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100208 kMinPacing);
209 EXPECT_EQ(timing.MaxWaitingTime(kZeroRenderTime, now,
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200210 /*too_many_frames_queued=*/false),
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100211 kMinPacing);
Johannes Kron985905d2021-06-29 11:37:06 +0200212 // Allow a few ms to pass, this should be subtracted from the MaxWaitingTime.
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100213 constexpr TimeDelta kTwoMs = TimeDelta::Millis(2);
214 clock.AdvanceTime(kTwoMs);
215 now = clock.CurrentTime();
216 EXPECT_EQ(timing.MaxWaitingTime(kZeroRenderTime, now,
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200217 /*too_many_frames_queued=*/false),
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100218 kMinPacing - kTwoMs);
Rezaul Barbhuiya82c22482021-08-05 17:54:11 -0700219 // A frame is decoded at the current time, the wait time should be restored to
220 // pacing delay.
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100221 timing.SetLastDecodeScheduledTimestamp(now);
222 EXPECT_EQ(timing.MaxWaitingTime(kZeroRenderTime, now,
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200223 /*too_many_frames_queued=*/false),
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100224 kMinPacing);
Johannes Kron985905d2021-06-29 11:37:06 +0200225}
226
227TEST(ReceiverTimingTest, DefaultMaxWaitingTimeUnaffectedByPacingExperiment) {
228 // The minimum pacing is enabled by a field trial but should not have any
229 // effect if render_time_ms is greater than 0;
Jonas Orelande02f9ee2022-03-25 12:43:14 +0100230 test::ScopedKeyValueConfig field_trials(
Johannes Kron985905d2021-06-29 11:37:06 +0200231 "WebRTC-ZeroPlayoutDelay/min_pacing:3ms/");
232 constexpr int64_t kStartTimeUs = 3.15e13; // About one year in us.
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100233 const TimeDelta kTimeDelta = TimeDelta::Millis(1000.0 / 60.0);
Johannes Kron985905d2021-06-29 11:37:06 +0200234 SimulatedClock clock(kStartTimeUs);
Jonas Orelande02f9ee2022-03-25 12:43:14 +0100235 VCMTiming timing(&clock, field_trials);
Johannes Kron985905d2021-06-29 11:37:06 +0200236 timing.Reset();
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100237 clock.AdvanceTime(kTimeDelta);
238 auto now = clock.CurrentTime();
239 Timestamp render_time = now + TimeDelta::Millis(30);
Johannes Kron985905d2021-06-29 11:37:06 +0200240 // Estimate the internal processing delay from the first frame.
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100241 TimeDelta estimated_processing_delay =
242 (render_time - now) -
243 timing.MaxWaitingTime(render_time, now,
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200244 /*too_many_frames_queued=*/false);
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100245 EXPECT_GT(estimated_processing_delay, TimeDelta::Zero());
Johannes Kron985905d2021-06-29 11:37:06 +0200246
247 // Any other frame submitted at the same time should be scheduled according to
248 // its render time.
249 for (int i = 0; i < 5; ++i) {
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100250 render_time += kTimeDelta;
251 EXPECT_EQ(timing.MaxWaitingTime(render_time, now,
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200252 /*too_many_frames_queued=*/false),
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100253 render_time - now - estimated_processing_delay);
Johannes Kron985905d2021-06-29 11:37:06 +0200254 }
255}
256
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100257TEST(ReceiverTimingTest, MaxWaitingTimeReturnsZeroIfTooManyFramesQueuedIsTrue) {
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200258 // The minimum pacing is enabled by a field trial and active if the RTP
259 // playout delay header extension is set to min==0.
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100260 constexpr TimeDelta kMinPacing = TimeDelta::Millis(3);
Jonas Orelande02f9ee2022-03-25 12:43:14 +0100261 test::ScopedKeyValueConfig field_trials(
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200262 "WebRTC-ZeroPlayoutDelay/min_pacing:3ms/");
263 constexpr int64_t kStartTimeUs = 3.15e13; // About one year in us.
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100264 const TimeDelta kTimeDelta = TimeDelta::Millis(1000.0 / 60.0);
265 constexpr auto kZeroRenderTime = Timestamp::Zero();
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200266 SimulatedClock clock(kStartTimeUs);
Jonas Orelande02f9ee2022-03-25 12:43:14 +0100267 VCMTiming timing(&clock, field_trials);
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200268 timing.Reset();
269 // MaxWaitingTime() returns zero for evenly spaced video frames.
270 for (int i = 0; i < 10; ++i) {
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100271 clock.AdvanceTime(kTimeDelta);
272 auto now = clock.CurrentTime();
273 EXPECT_EQ(timing.MaxWaitingTime(kZeroRenderTime, now,
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200274 /*too_many_frames_queued=*/false),
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100275 TimeDelta::Zero());
276 timing.SetLastDecodeScheduledTimestamp(now);
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200277 }
278 // Another frame submitted at the same time is paced according to the field
279 // trial setting.
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100280 auto now_ms = clock.CurrentTime();
281 EXPECT_EQ(timing.MaxWaitingTime(kZeroRenderTime, now_ms,
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200282 /*too_many_frames_queued=*/false),
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100283 kMinPacing);
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200284 // MaxWaitingTime returns 0 even if there's a burst of frames if
285 // too_many_frames_queued is set to true.
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100286 EXPECT_EQ(timing.MaxWaitingTime(kZeroRenderTime, now_ms,
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200287 /*too_many_frames_queued=*/true),
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100288 TimeDelta::Zero());
289 EXPECT_EQ(timing.MaxWaitingTime(kZeroRenderTime, now_ms,
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200290 /*too_many_frames_queued=*/true),
Evan Shrubsoled6cdf802022-03-02 15:13:55 +0100291 TimeDelta::Zero());
Johannes Kron2ddc39e2021-08-10 16:56:12 +0200292}
293
stefan@webrtc.org9f557c12013-05-17 12:55:07 +0000294} // namespace webrtc