@@ -36,7 +36,7 @@ TEST(ReceiverTimingTest, JitterDelay) {
3636 timing.set_render_delay (0 );
3737 uint32_t wait_time_ms = timing.MaxWaitingTime (
3838 timing.RenderTimeMs (timestamp, clock.TimeInMilliseconds ()),
39- clock.TimeInMilliseconds ());
39+ clock.TimeInMilliseconds (), /* too_many_frames_queued= */ false );
4040 // First update initializes the render time. Since we have no decode delay
4141 // we get wait_time_ms = renderTime - now - renderDelay = jitter.
4242 EXPECT_EQ (jitter_delay_ms, wait_time_ms);
@@ -48,7 +48,7 @@ TEST(ReceiverTimingTest, JitterDelay) {
4848 timing.UpdateCurrentDelay (timestamp);
4949 wait_time_ms = timing.MaxWaitingTime (
5050 timing.RenderTimeMs (timestamp, clock.TimeInMilliseconds ()),
51- clock.TimeInMilliseconds ());
51+ clock.TimeInMilliseconds (), /* too_many_frames_queued= */ false );
5252 // Since we gradually increase the delay we only get 100 ms every second.
5353 EXPECT_EQ (jitter_delay_ms - 10 , wait_time_ms);
5454
@@ -57,7 +57,7 @@ TEST(ReceiverTimingTest, JitterDelay) {
5757 timing.UpdateCurrentDelay (timestamp);
5858 wait_time_ms = timing.MaxWaitingTime (
5959 timing.RenderTimeMs (timestamp, clock.TimeInMilliseconds ()),
60- clock.TimeInMilliseconds ());
60+ clock.TimeInMilliseconds (), /* too_many_frames_queued= */ false );
6161 EXPECT_EQ (jitter_delay_ms, wait_time_ms);
6262
6363 // Insert frames without jitter, verify that this gives the exact wait time.
@@ -70,7 +70,7 @@ TEST(ReceiverTimingTest, JitterDelay) {
7070 timing.UpdateCurrentDelay (timestamp);
7171 wait_time_ms = timing.MaxWaitingTime (
7272 timing.RenderTimeMs (timestamp, clock.TimeInMilliseconds ()),
73- clock.TimeInMilliseconds ());
73+ clock.TimeInMilliseconds (), /* too_many_frames_queued= */ false );
7474 EXPECT_EQ (jitter_delay_ms, wait_time_ms);
7575
7676 // Add decode time estimates for 1 second.
@@ -85,7 +85,7 @@ TEST(ReceiverTimingTest, JitterDelay) {
8585 timing.UpdateCurrentDelay (timestamp);
8686 wait_time_ms = timing.MaxWaitingTime (
8787 timing.RenderTimeMs (timestamp, clock.TimeInMilliseconds ()),
88- clock.TimeInMilliseconds ());
88+ clock.TimeInMilliseconds (), /* too_many_frames_queued= */ false );
8989 EXPECT_EQ (jitter_delay_ms, wait_time_ms);
9090
9191 const int kMinTotalDelayMs = 200 ;
@@ -97,7 +97,7 @@ TEST(ReceiverTimingTest, JitterDelay) {
9797 timing.set_render_delay (kRenderDelayMs );
9898 wait_time_ms = timing.MaxWaitingTime (
9999 timing.RenderTimeMs (timestamp, clock.TimeInMilliseconds ()),
100- clock.TimeInMilliseconds ());
100+ clock.TimeInMilliseconds (), /* too_many_frames_queued= */ false );
101101 // We should at least have kMinTotalDelayMs - decodeTime (10) - renderTime
102102 // (10) to wait.
103103 EXPECT_EQ (kMinTotalDelayMs - kDecodeTimeMs - kRenderDelayMs , wait_time_ms);
@@ -140,16 +140,26 @@ TEST(ReceiverTimingTest, MaxWaitingTimeIsZeroForZeroRenderTime) {
140140 for (int i = 0 ; i < 10 ; ++i) {
141141 clock.AdvanceTimeMilliseconds (kTimeDeltaMs );
142142 int64_t now_ms = clock.TimeInMilliseconds ();
143- EXPECT_LT (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms), 0 );
143+ EXPECT_LT (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms,
144+ /* too_many_frames_queued=*/ false ),
145+ 0 );
144146 }
145147 // Another frame submitted at the same time also returns a negative max
146148 // waiting time.
147149 int64_t now_ms = clock.TimeInMilliseconds ();
148- EXPECT_LT (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms), 0 );
150+ EXPECT_LT (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms,
151+ /* too_many_frames_queued=*/ false ),
152+ 0 );
149153 // MaxWaitingTime should be less than zero even if there's a burst of frames.
150- EXPECT_LT (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms), 0 );
151- EXPECT_LT (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms), 0 );
152- EXPECT_LT (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms), 0 );
154+ EXPECT_LT (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms,
155+ /* too_many_frames_queued=*/ false ),
156+ 0 );
157+ EXPECT_LT (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms,
158+ /* too_many_frames_queued=*/ false ),
159+ 0 );
160+ EXPECT_LT (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms,
161+ /* too_many_frames_queued=*/ false ),
162+ 0 );
153163}
154164
155165TEST (ReceiverTimingTest, MaxWaitingTimeZeroDelayPacingExperiment) {
@@ -168,27 +178,38 @@ TEST(ReceiverTimingTest, MaxWaitingTimeZeroDelayPacingExperiment) {
168178 for (int i = 0 ; i < 10 ; ++i) {
169179 clock.AdvanceTimeMilliseconds (kTimeDeltaMs );
170180 int64_t now_ms = clock.TimeInMilliseconds ();
171- EXPECT_EQ (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms), 0 );
181+ EXPECT_EQ (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms,
182+ /* too_many_frames_queued=*/ false ),
183+ 0 );
172184 timing.SetLastDecodeScheduledTimestamp (now_ms);
173185 }
174186 // Another frame submitted at the same time is paced according to the field
175187 // trial setting.
176188 int64_t now_ms = clock.TimeInMilliseconds ();
177- EXPECT_EQ (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms), kMinPacingMs );
189+ EXPECT_EQ (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms,
190+ /* too_many_frames_queued=*/ false ),
191+ kMinPacingMs );
178192 // If there's a burst of frames, the wait time is calculated based on next
179193 // decode time.
180- EXPECT_EQ (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms), kMinPacingMs );
181- EXPECT_EQ (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms), kMinPacingMs );
194+ EXPECT_EQ (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms,
195+ /* too_many_frames_queued=*/ false ),
196+ kMinPacingMs );
197+ EXPECT_EQ (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms,
198+ /* too_many_frames_queued=*/ false ),
199+ kMinPacingMs );
182200 // Allow a few ms to pass, this should be subtracted from the MaxWaitingTime.
183201 constexpr int64_t kTwoMs = 2 ;
184202 clock.AdvanceTimeMilliseconds (kTwoMs );
185203 now_ms = clock.TimeInMilliseconds ();
186- EXPECT_EQ (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms),
204+ EXPECT_EQ (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms,
205+ /* too_many_frames_queued=*/ false ),
187206 kMinPacingMs - kTwoMs );
188207 // A frame is decoded at the current time, the wait time should be restored to
189208 // pacing delay.
190209 timing.SetLastDecodeScheduledTimestamp (now_ms);
191- EXPECT_EQ (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms), kMinPacingMs );
210+ EXPECT_EQ (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms,
211+ /* too_many_frames_queued=*/ false ),
212+ kMinPacingMs );
192213}
193214
194215TEST (ReceiverTimingTest, DefaultMaxWaitingTimeUnaffectedByPacingExperiment) {
@@ -206,16 +227,56 @@ TEST(ReceiverTimingTest, DefaultMaxWaitingTimeUnaffectedByPacingExperiment) {
206227 int64_t render_time_ms = now_ms + 30 ;
207228 // Estimate the internal processing delay from the first frame.
208229 int64_t estimated_processing_delay =
209- (render_time_ms - now_ms) - timing.MaxWaitingTime (render_time_ms, now_ms);
230+ (render_time_ms - now_ms) -
231+ timing.MaxWaitingTime (render_time_ms, now_ms,
232+ /* too_many_frames_queued=*/ false );
210233 EXPECT_GT (estimated_processing_delay, 0 );
211234
212235 // Any other frame submitted at the same time should be scheduled according to
213236 // its render time.
214237 for (int i = 0 ; i < 5 ; ++i) {
215238 render_time_ms += kTimeDeltaMs ;
216- EXPECT_EQ (timing.MaxWaitingTime (render_time_ms, now_ms),
239+ EXPECT_EQ (timing.MaxWaitingTime (render_time_ms, now_ms,
240+ /* too_many_frames_queued=*/ false ),
217241 render_time_ms - now_ms - estimated_processing_delay);
218242 }
219243}
220244
245+ TEST (ReceiverTiminTest, MaxWaitingTimeReturnsZeroIfTooManyFramesQueuedIsTrue) {
246+ // The minimum pacing is enabled by a field trial and active if the RTP
247+ // playout delay header extension is set to min==0.
248+ constexpr int64_t kMinPacingMs = 3 ;
249+ test::ScopedFieldTrials override_field_trials (
250+ " WebRTC-ZeroPlayoutDelay/min_pacing:3ms/" );
251+ constexpr int64_t kStartTimeUs = 3.15e13 ; // About one year in us.
252+ constexpr int64_t kTimeDeltaMs = 1000.0 / 60.0 ;
253+ constexpr int64_t kZeroRenderTimeMs = 0 ;
254+ SimulatedClock clock (kStartTimeUs );
255+ VCMTiming timing (&clock);
256+ timing.Reset ();
257+ // MaxWaitingTime() returns zero for evenly spaced video frames.
258+ for (int i = 0 ; i < 10 ; ++i) {
259+ clock.AdvanceTimeMilliseconds (kTimeDeltaMs );
260+ int64_t now_ms = clock.TimeInMilliseconds ();
261+ EXPECT_EQ (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms,
262+ /* too_many_frames_queued=*/ false ),
263+ 0 );
264+ timing.SetLastDecodeScheduledTimestamp (now_ms);
265+ }
266+ // Another frame submitted at the same time is paced according to the field
267+ // trial setting.
268+ int64_t now_ms = clock.TimeInMilliseconds ();
269+ EXPECT_EQ (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms,
270+ /* too_many_frames_queued=*/ false ),
271+ kMinPacingMs );
272+ // MaxWaitingTime returns 0 even if there's a burst of frames if
273+ // too_many_frames_queued is set to true.
274+ EXPECT_EQ (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms,
275+ /* too_many_frames_queued=*/ true ),
276+ 0 );
277+ EXPECT_EQ (timing.MaxWaitingTime (kZeroRenderTimeMs , now_ms,
278+ /* too_many_frames_queued=*/ true ),
279+ 0 );
280+ }
281+
221282} // namespace webrtc
0 commit comments