• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2012 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 <math.h>
12 
13 #include <algorithm>
14 
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "webrtc/video/stream_synchronization.h"
17 
18 namespace webrtc {
19 
20 // These correspond to the same constants defined in vie_sync_module.cc.
21 enum { kMaxVideoDiffMs = 80 };
22 enum { kMaxAudioDiffMs = 80 };
23 enum { kMaxDelay = 1500 };
24 
25 // Test constants.
26 enum { kDefaultAudioFrequency = 8000 };
27 enum { kDefaultVideoFrequency = 90000 };
28 const double kNtpFracPerMs = 4.294967296E6;
29 static const int kSmoothingFilter = 4 * 2;
30 
31 class Time {
32  public:
Time(int64_t offset)33   explicit Time(int64_t offset)
34       : kNtpJan1970(2208988800UL),
35         time_now_ms_(offset) {}
36 
GenerateRtcp(int frequency,uint32_t offset) const37   RtcpMeasurement GenerateRtcp(int frequency, uint32_t offset) const {
38     RtcpMeasurement rtcp;
39     NowNtp(&rtcp.ntp_secs, &rtcp.ntp_frac);
40     rtcp.rtp_timestamp = NowRtp(frequency, offset);
41     return rtcp;
42   }
43 
NowNtp(uint32_t * ntp_secs,uint32_t * ntp_frac) const44   void NowNtp(uint32_t* ntp_secs, uint32_t* ntp_frac) const {
45     *ntp_secs = time_now_ms_ / 1000 + kNtpJan1970;
46     int64_t remainder_ms = time_now_ms_ % 1000;
47     *ntp_frac = static_cast<uint32_t>(
48         static_cast<double>(remainder_ms) * kNtpFracPerMs + 0.5);
49   }
50 
NowRtp(int frequency,uint32_t offset) const51   uint32_t NowRtp(int frequency, uint32_t offset) const {
52     return frequency * time_now_ms_ / 1000 + offset;
53   }
54 
IncreaseTimeMs(int64_t inc)55   void IncreaseTimeMs(int64_t inc) {
56     time_now_ms_ += inc;
57   }
58 
time_now_ms() const59   int64_t time_now_ms() const {
60     return time_now_ms_;
61   }
62 
63  private:
64   // January 1970, in NTP seconds.
65   const uint32_t kNtpJan1970;
66   int64_t time_now_ms_;
67 };
68 
69 class StreamSynchronizationTest : public ::testing::Test {
70  protected:
SetUp()71   virtual void SetUp() {
72     sync_ = new StreamSynchronization(0, 0);
73     send_time_ = new Time(kSendTimeOffsetMs);
74     receive_time_ = new Time(kReceiveTimeOffsetMs);
75     audio_clock_drift_ = 1.0;
76     video_clock_drift_ = 1.0;
77   }
78 
TearDown()79   virtual void TearDown() {
80     delete sync_;
81     delete send_time_;
82     delete receive_time_;
83   }
84 
85   // Generates the necessary RTCP measurements and RTP timestamps and computes
86   // the audio and video delays needed to get the two streams in sync.
87   // |audio_delay_ms| and |video_delay_ms| are the number of milliseconds after
88   // capture which the frames are rendered.
89   // |current_audio_delay_ms| is the number of milliseconds which audio is
90   // currently being delayed by the receiver.
DelayedStreams(int audio_delay_ms,int video_delay_ms,int current_audio_delay_ms,int * extra_audio_delay_ms,int * total_video_delay_ms)91   bool DelayedStreams(int audio_delay_ms,
92                       int video_delay_ms,
93                       int current_audio_delay_ms,
94                       int* extra_audio_delay_ms,
95                       int* total_video_delay_ms) {
96     int audio_frequency = static_cast<int>(kDefaultAudioFrequency *
97                                            audio_clock_drift_ + 0.5);
98     int audio_offset = 0;
99     int video_frequency = static_cast<int>(kDefaultVideoFrequency *
100                                            video_clock_drift_ + 0.5);
101     int video_offset = 0;
102     StreamSynchronization::Measurements audio;
103     StreamSynchronization::Measurements video;
104     // Generate NTP/RTP timestamp pair for both streams corresponding to RTCP.
105     audio.rtcp.push_front(send_time_->GenerateRtcp(audio_frequency,
106                                                    audio_offset));
107     send_time_->IncreaseTimeMs(100);
108     receive_time_->IncreaseTimeMs(100);
109     video.rtcp.push_front(send_time_->GenerateRtcp(video_frequency,
110                                                    video_offset));
111     send_time_->IncreaseTimeMs(900);
112     receive_time_->IncreaseTimeMs(900);
113     audio.rtcp.push_front(send_time_->GenerateRtcp(audio_frequency,
114                                                    audio_offset));
115     send_time_->IncreaseTimeMs(100);
116     receive_time_->IncreaseTimeMs(100);
117     video.rtcp.push_front(send_time_->GenerateRtcp(video_frequency,
118                                                    video_offset));
119     send_time_->IncreaseTimeMs(900);
120     receive_time_->IncreaseTimeMs(900);
121 
122     // Capture an audio and a video frame at the same time.
123     audio.latest_timestamp = send_time_->NowRtp(audio_frequency,
124                                                 audio_offset);
125     video.latest_timestamp = send_time_->NowRtp(video_frequency,
126                                                 video_offset);
127 
128     if (audio_delay_ms > video_delay_ms) {
129       // Audio later than video.
130       receive_time_->IncreaseTimeMs(video_delay_ms);
131       video.latest_receive_time_ms = receive_time_->time_now_ms();
132       receive_time_->IncreaseTimeMs(audio_delay_ms - video_delay_ms);
133       audio.latest_receive_time_ms = receive_time_->time_now_ms();
134     } else {
135       // Video later than audio.
136       receive_time_->IncreaseTimeMs(audio_delay_ms);
137       audio.latest_receive_time_ms = receive_time_->time_now_ms();
138       receive_time_->IncreaseTimeMs(video_delay_ms - audio_delay_ms);
139       video.latest_receive_time_ms = receive_time_->time_now_ms();
140     }
141     int relative_delay_ms;
142     StreamSynchronization::ComputeRelativeDelay(audio, video,
143                                                 &relative_delay_ms);
144     EXPECT_EQ(video_delay_ms - audio_delay_ms, relative_delay_ms);
145     return sync_->ComputeDelays(relative_delay_ms,
146                                 current_audio_delay_ms,
147                                 extra_audio_delay_ms,
148                                 total_video_delay_ms);
149   }
150 
151   // Simulate audio playback 300 ms after capture and video rendering 100 ms
152   // after capture. Verify that the correct extra delays are calculated for
153   // audio and video, and that they change correctly when we simulate that
154   // NetEQ or the VCM adds more delay to the streams.
155   // TODO(holmer): This is currently wrong! We should simply change
156   // audio_delay_ms or video_delay_ms since those now include VCM and NetEQ
157   // delays.
BothDelayedAudioLaterTest(int base_target_delay)158   void BothDelayedAudioLaterTest(int base_target_delay) {
159     int current_audio_delay_ms = base_target_delay;
160     int audio_delay_ms = base_target_delay + 300;
161     int video_delay_ms = base_target_delay + 100;
162     int extra_audio_delay_ms = 0;
163     int total_video_delay_ms = base_target_delay;
164     int filtered_move = (audio_delay_ms - video_delay_ms) / kSmoothingFilter;
165     const int kNeteqDelayIncrease = 50;
166     const int kNeteqDelayDecrease = 10;
167 
168     EXPECT_TRUE(DelayedStreams(audio_delay_ms,
169                                video_delay_ms,
170                                current_audio_delay_ms,
171                                &extra_audio_delay_ms,
172                                &total_video_delay_ms));
173     EXPECT_EQ(base_target_delay + filtered_move, total_video_delay_ms);
174     EXPECT_EQ(base_target_delay, extra_audio_delay_ms);
175     current_audio_delay_ms = extra_audio_delay_ms;
176 
177     send_time_->IncreaseTimeMs(1000);
178     receive_time_->IncreaseTimeMs(1000 - std::max(audio_delay_ms,
179                                                   video_delay_ms));
180     // Simulate base_target_delay minimum delay in the VCM.
181     total_video_delay_ms = base_target_delay;
182     EXPECT_TRUE(DelayedStreams(audio_delay_ms,
183                                video_delay_ms,
184                                current_audio_delay_ms,
185                                &extra_audio_delay_ms,
186                                &total_video_delay_ms));
187     EXPECT_EQ(base_target_delay + 2 * filtered_move, total_video_delay_ms);
188     EXPECT_EQ(base_target_delay, extra_audio_delay_ms);
189     current_audio_delay_ms = extra_audio_delay_ms;
190 
191     send_time_->IncreaseTimeMs(1000);
192     receive_time_->IncreaseTimeMs(1000 - std::max(audio_delay_ms,
193                                                   video_delay_ms));
194     // Simulate base_target_delay minimum delay in the VCM.
195     total_video_delay_ms = base_target_delay;
196     EXPECT_TRUE(DelayedStreams(audio_delay_ms,
197                                video_delay_ms,
198                                current_audio_delay_ms,
199                                &extra_audio_delay_ms,
200                                &total_video_delay_ms));
201     EXPECT_EQ(base_target_delay + 3 * filtered_move, total_video_delay_ms);
202     EXPECT_EQ(base_target_delay, extra_audio_delay_ms);
203 
204     // Simulate that NetEQ introduces some audio delay.
205     current_audio_delay_ms = base_target_delay + kNeteqDelayIncrease;
206     send_time_->IncreaseTimeMs(1000);
207     receive_time_->IncreaseTimeMs(1000 - std::max(audio_delay_ms,
208                                                   video_delay_ms));
209     // Simulate base_target_delay minimum delay in the VCM.
210     total_video_delay_ms = base_target_delay;
211     EXPECT_TRUE(DelayedStreams(audio_delay_ms,
212                                video_delay_ms,
213                                current_audio_delay_ms,
214                                &extra_audio_delay_ms,
215                                &total_video_delay_ms));
216     filtered_move = 3 * filtered_move +
217         (kNeteqDelayIncrease + audio_delay_ms - video_delay_ms) /
218         kSmoothingFilter;
219     EXPECT_EQ(base_target_delay + filtered_move, total_video_delay_ms);
220     EXPECT_EQ(base_target_delay, extra_audio_delay_ms);
221 
222     // Simulate that NetEQ reduces its delay.
223     current_audio_delay_ms = base_target_delay + kNeteqDelayDecrease;
224     send_time_->IncreaseTimeMs(1000);
225     receive_time_->IncreaseTimeMs(1000 - std::max(audio_delay_ms,
226                                                   video_delay_ms));
227     // Simulate base_target_delay minimum delay in the VCM.
228     total_video_delay_ms = base_target_delay;
229     EXPECT_TRUE(DelayedStreams(audio_delay_ms,
230                                video_delay_ms,
231                                current_audio_delay_ms,
232                                &extra_audio_delay_ms,
233                                &total_video_delay_ms));
234 
235     filtered_move = filtered_move +
236         (kNeteqDelayDecrease + audio_delay_ms - video_delay_ms) /
237         kSmoothingFilter;
238 
239     EXPECT_EQ(base_target_delay + filtered_move, total_video_delay_ms);
240     EXPECT_EQ(base_target_delay, extra_audio_delay_ms);
241   }
242 
BothDelayedVideoLaterTest(int base_target_delay)243   void BothDelayedVideoLaterTest(int base_target_delay) {
244     int current_audio_delay_ms = base_target_delay;
245     int audio_delay_ms = base_target_delay + 100;
246     int video_delay_ms = base_target_delay + 300;
247     int extra_audio_delay_ms = 0;
248     int total_video_delay_ms = base_target_delay;
249 
250     EXPECT_TRUE(DelayedStreams(audio_delay_ms,
251                                video_delay_ms,
252                                current_audio_delay_ms,
253                                &extra_audio_delay_ms,
254                                &total_video_delay_ms));
255     EXPECT_EQ(base_target_delay, total_video_delay_ms);
256     // The audio delay is not allowed to change more than this in 1 second.
257     EXPECT_GE(base_target_delay + kMaxAudioDiffMs, extra_audio_delay_ms);
258     current_audio_delay_ms = extra_audio_delay_ms;
259     int current_extra_delay_ms = extra_audio_delay_ms;
260 
261     send_time_->IncreaseTimeMs(1000);
262     receive_time_->IncreaseTimeMs(800);
263     EXPECT_TRUE(DelayedStreams(audio_delay_ms,
264                                video_delay_ms,
265                                current_audio_delay_ms,
266                                &extra_audio_delay_ms,
267                                &total_video_delay_ms));
268     EXPECT_EQ(base_target_delay, total_video_delay_ms);
269     // The audio delay is not allowed to change more than the half of the
270     // required change in delay.
271     EXPECT_EQ(current_extra_delay_ms + MaxAudioDelayIncrease(
272         current_audio_delay_ms,
273         base_target_delay + video_delay_ms - audio_delay_ms),
274         extra_audio_delay_ms);
275     current_audio_delay_ms = extra_audio_delay_ms;
276     current_extra_delay_ms = extra_audio_delay_ms;
277 
278     send_time_->IncreaseTimeMs(1000);
279     receive_time_->IncreaseTimeMs(800);
280     EXPECT_TRUE(DelayedStreams(audio_delay_ms,
281                                video_delay_ms,
282                                current_audio_delay_ms,
283                                &extra_audio_delay_ms,
284                                &total_video_delay_ms));
285     EXPECT_EQ(base_target_delay, total_video_delay_ms);
286     // The audio delay is not allowed to change more than the half of the
287     // required change in delay.
288     EXPECT_EQ(current_extra_delay_ms + MaxAudioDelayIncrease(
289         current_audio_delay_ms,
290         base_target_delay + video_delay_ms - audio_delay_ms),
291         extra_audio_delay_ms);
292     current_extra_delay_ms = extra_audio_delay_ms;
293 
294     // Simulate that NetEQ for some reason reduced the delay.
295     current_audio_delay_ms = base_target_delay + 10;
296     send_time_->IncreaseTimeMs(1000);
297     receive_time_->IncreaseTimeMs(800);
298     EXPECT_TRUE(DelayedStreams(audio_delay_ms,
299                                video_delay_ms,
300                                current_audio_delay_ms,
301                                &extra_audio_delay_ms,
302                                &total_video_delay_ms));
303     EXPECT_EQ(base_target_delay, total_video_delay_ms);
304     // Since we only can ask NetEQ for a certain amount of extra delay, and
305     // we only measure the total NetEQ delay, we will ask for additional delay
306     // here to try to stay in sync.
307     EXPECT_EQ(current_extra_delay_ms + MaxAudioDelayIncrease(
308         current_audio_delay_ms,
309         base_target_delay + video_delay_ms - audio_delay_ms),
310         extra_audio_delay_ms);
311     current_extra_delay_ms = extra_audio_delay_ms;
312 
313     // Simulate that NetEQ for some reason significantly increased the delay.
314     current_audio_delay_ms = base_target_delay + 350;
315     send_time_->IncreaseTimeMs(1000);
316     receive_time_->IncreaseTimeMs(800);
317     EXPECT_TRUE(DelayedStreams(audio_delay_ms,
318                                video_delay_ms,
319                                current_audio_delay_ms,
320                                &extra_audio_delay_ms,
321                                &total_video_delay_ms));
322     EXPECT_EQ(base_target_delay, total_video_delay_ms);
323     // The audio delay is not allowed to change more than the half of the
324     // required change in delay.
325     EXPECT_EQ(current_extra_delay_ms + MaxAudioDelayIncrease(
326         current_audio_delay_ms,
327         base_target_delay + video_delay_ms - audio_delay_ms),
328         extra_audio_delay_ms);
329   }
330 
MaxAudioDelayIncrease(int current_audio_delay_ms,int delay_ms)331   int MaxAudioDelayIncrease(int current_audio_delay_ms, int delay_ms) {
332     return std::min((delay_ms - current_audio_delay_ms) / kSmoothingFilter,
333                      static_cast<int>(kMaxAudioDiffMs));
334   }
335 
MaxAudioDelayDecrease(int current_audio_delay_ms,int delay_ms)336   int MaxAudioDelayDecrease(int current_audio_delay_ms, int delay_ms) {
337     return std::max((delay_ms - current_audio_delay_ms) / kSmoothingFilter,
338                     -kMaxAudioDiffMs);
339   }
340 
341   enum { kSendTimeOffsetMs = 98765 };
342   enum { kReceiveTimeOffsetMs = 43210 };
343 
344   StreamSynchronization* sync_;
345   Time* send_time_;  // The simulated clock at the sender.
346   Time* receive_time_;  // The simulated clock at the receiver.
347   double audio_clock_drift_;
348   double video_clock_drift_;
349 };
350 
TEST_F(StreamSynchronizationTest,NoDelay)351 TEST_F(StreamSynchronizationTest, NoDelay) {
352   uint32_t current_audio_delay_ms = 0;
353   int extra_audio_delay_ms = 0;
354   int total_video_delay_ms = 0;
355 
356   EXPECT_FALSE(DelayedStreams(0, 0, current_audio_delay_ms,
357                               &extra_audio_delay_ms, &total_video_delay_ms));
358   EXPECT_EQ(0, extra_audio_delay_ms);
359   EXPECT_EQ(0, total_video_delay_ms);
360 }
361 
TEST_F(StreamSynchronizationTest,VideoDelay)362 TEST_F(StreamSynchronizationTest, VideoDelay) {
363   uint32_t current_audio_delay_ms = 0;
364   int delay_ms = 200;
365   int extra_audio_delay_ms = 0;
366   int total_video_delay_ms = 0;
367 
368   EXPECT_TRUE(DelayedStreams(delay_ms, 0, current_audio_delay_ms,
369                              &extra_audio_delay_ms, &total_video_delay_ms));
370   EXPECT_EQ(0, extra_audio_delay_ms);
371   // The video delay is not allowed to change more than this in 1 second.
372   EXPECT_EQ(delay_ms / kSmoothingFilter, total_video_delay_ms);
373 
374   send_time_->IncreaseTimeMs(1000);
375   receive_time_->IncreaseTimeMs(800);
376   // Simulate 0 minimum delay in the VCM.
377   total_video_delay_ms = 0;
378   EXPECT_TRUE(DelayedStreams(delay_ms, 0, current_audio_delay_ms,
379                              &extra_audio_delay_ms, &total_video_delay_ms));
380   EXPECT_EQ(0, extra_audio_delay_ms);
381   // The video delay is not allowed to change more than this in 1 second.
382   EXPECT_EQ(2 * delay_ms / kSmoothingFilter, total_video_delay_ms);
383 
384   send_time_->IncreaseTimeMs(1000);
385   receive_time_->IncreaseTimeMs(800);
386   // Simulate 0 minimum delay in the VCM.
387   total_video_delay_ms = 0;
388   EXPECT_TRUE(DelayedStreams(delay_ms, 0, current_audio_delay_ms,
389                              &extra_audio_delay_ms, &total_video_delay_ms));
390   EXPECT_EQ(0, extra_audio_delay_ms);
391   EXPECT_EQ(3 * delay_ms / kSmoothingFilter, total_video_delay_ms);
392 }
393 
TEST_F(StreamSynchronizationTest,AudioDelay)394 TEST_F(StreamSynchronizationTest, AudioDelay) {
395   int current_audio_delay_ms = 0;
396   int delay_ms = 200;
397   int extra_audio_delay_ms = 0;
398   int total_video_delay_ms = 0;
399 
400   EXPECT_TRUE(DelayedStreams(0, delay_ms, current_audio_delay_ms,
401                              &extra_audio_delay_ms, &total_video_delay_ms));
402   EXPECT_EQ(0, total_video_delay_ms);
403   // The audio delay is not allowed to change more than this in 1 second.
404   EXPECT_EQ(delay_ms / kSmoothingFilter, extra_audio_delay_ms);
405   current_audio_delay_ms = extra_audio_delay_ms;
406   int current_extra_delay_ms = extra_audio_delay_ms;
407 
408   send_time_->IncreaseTimeMs(1000);
409   receive_time_->IncreaseTimeMs(800);
410   EXPECT_TRUE(DelayedStreams(0, delay_ms, current_audio_delay_ms,
411                              &extra_audio_delay_ms, &total_video_delay_ms));
412   EXPECT_EQ(0, total_video_delay_ms);
413   // The audio delay is not allowed to change more than the half of the required
414   // change in delay.
415   EXPECT_EQ(current_extra_delay_ms +
416             MaxAudioDelayIncrease(current_audio_delay_ms, delay_ms),
417             extra_audio_delay_ms);
418   current_audio_delay_ms = extra_audio_delay_ms;
419   current_extra_delay_ms = extra_audio_delay_ms;
420 
421   send_time_->IncreaseTimeMs(1000);
422   receive_time_->IncreaseTimeMs(800);
423   EXPECT_TRUE(DelayedStreams(0, delay_ms, current_audio_delay_ms,
424                              &extra_audio_delay_ms, &total_video_delay_ms));
425   EXPECT_EQ(0, total_video_delay_ms);
426   // The audio delay is not allowed to change more than the half of the required
427   // change in delay.
428   EXPECT_EQ(current_extra_delay_ms +
429             MaxAudioDelayIncrease(current_audio_delay_ms, delay_ms),
430             extra_audio_delay_ms);
431   current_extra_delay_ms = extra_audio_delay_ms;
432 
433   // Simulate that NetEQ for some reason reduced the delay.
434   current_audio_delay_ms = 10;
435   send_time_->IncreaseTimeMs(1000);
436   receive_time_->IncreaseTimeMs(800);
437   EXPECT_TRUE(DelayedStreams(0, delay_ms, current_audio_delay_ms,
438                              &extra_audio_delay_ms, &total_video_delay_ms));
439   EXPECT_EQ(0, total_video_delay_ms);
440   // Since we only can ask NetEQ for a certain amount of extra delay, and
441   // we only measure the total NetEQ delay, we will ask for additional delay
442   // here to try to
443   EXPECT_EQ(current_extra_delay_ms +
444             MaxAudioDelayIncrease(current_audio_delay_ms, delay_ms),
445             extra_audio_delay_ms);
446   current_extra_delay_ms = extra_audio_delay_ms;
447 
448   // Simulate that NetEQ for some reason significantly increased the delay.
449   current_audio_delay_ms = 350;
450   send_time_->IncreaseTimeMs(1000);
451   receive_time_->IncreaseTimeMs(800);
452   EXPECT_TRUE(DelayedStreams(0, delay_ms, current_audio_delay_ms,
453                              &extra_audio_delay_ms, &total_video_delay_ms));
454   EXPECT_EQ(0, total_video_delay_ms);
455   // The audio delay is not allowed to change more than the half of the required
456   // change in delay.
457   EXPECT_EQ(current_extra_delay_ms +
458             MaxAudioDelayDecrease(current_audio_delay_ms, delay_ms),
459             extra_audio_delay_ms);
460 }
461 
TEST_F(StreamSynchronizationTest,BothDelayedVideoLater)462 TEST_F(StreamSynchronizationTest, BothDelayedVideoLater) {
463   BothDelayedVideoLaterTest(0);
464 }
465 
TEST_F(StreamSynchronizationTest,BothDelayedVideoLaterAudioClockDrift)466 TEST_F(StreamSynchronizationTest, BothDelayedVideoLaterAudioClockDrift) {
467   audio_clock_drift_ = 1.05;
468   BothDelayedVideoLaterTest(0);
469 }
470 
TEST_F(StreamSynchronizationTest,BothDelayedVideoLaterVideoClockDrift)471 TEST_F(StreamSynchronizationTest, BothDelayedVideoLaterVideoClockDrift) {
472   video_clock_drift_ = 1.05;
473   BothDelayedVideoLaterTest(0);
474 }
475 
TEST_F(StreamSynchronizationTest,BothDelayedAudioLater)476 TEST_F(StreamSynchronizationTest, BothDelayedAudioLater) {
477   BothDelayedAudioLaterTest(0);
478 }
479 
TEST_F(StreamSynchronizationTest,BothDelayedAudioClockDrift)480 TEST_F(StreamSynchronizationTest, BothDelayedAudioClockDrift) {
481   audio_clock_drift_ = 1.05;
482   BothDelayedAudioLaterTest(0);
483 }
484 
TEST_F(StreamSynchronizationTest,BothDelayedVideoClockDrift)485 TEST_F(StreamSynchronizationTest, BothDelayedVideoClockDrift) {
486   video_clock_drift_ = 1.05;
487   BothDelayedAudioLaterTest(0);
488 }
489 
TEST_F(StreamSynchronizationTest,BaseDelay)490 TEST_F(StreamSynchronizationTest, BaseDelay) {
491   int base_target_delay_ms = 2000;
492   int current_audio_delay_ms = 2000;
493   int extra_audio_delay_ms = 0;
494   int total_video_delay_ms = base_target_delay_ms;
495   sync_->SetTargetBufferingDelay(base_target_delay_ms);
496   // We are in sync don't change.
497   EXPECT_FALSE(DelayedStreams(base_target_delay_ms, base_target_delay_ms,
498                               current_audio_delay_ms,
499                               &extra_audio_delay_ms, &total_video_delay_ms));
500   // Triggering another call with the same values. Delay should not be modified.
501   base_target_delay_ms = 2000;
502   current_audio_delay_ms = base_target_delay_ms;
503   total_video_delay_ms = base_target_delay_ms;
504   sync_->SetTargetBufferingDelay(base_target_delay_ms);
505   // We are in sync don't change.
506   EXPECT_FALSE(DelayedStreams(base_target_delay_ms, base_target_delay_ms,
507                               current_audio_delay_ms,
508                               &extra_audio_delay_ms, &total_video_delay_ms));
509   // Changing delay value - intended to test this module only. In practice it
510   // would take VoE time to adapt.
511   base_target_delay_ms = 5000;
512   current_audio_delay_ms = base_target_delay_ms;
513   total_video_delay_ms = base_target_delay_ms;
514   sync_->SetTargetBufferingDelay(base_target_delay_ms);
515   // We are in sync don't change.
516   EXPECT_FALSE(DelayedStreams(base_target_delay_ms, base_target_delay_ms,
517                               current_audio_delay_ms,
518                               &extra_audio_delay_ms, &total_video_delay_ms));
519 }
520 
TEST_F(StreamSynchronizationTest,BothDelayedAudioLaterWithBaseDelay)521 TEST_F(StreamSynchronizationTest, BothDelayedAudioLaterWithBaseDelay) {
522   int base_target_delay_ms = 3000;
523   sync_->SetTargetBufferingDelay(base_target_delay_ms);
524   BothDelayedAudioLaterTest(base_target_delay_ms);
525 }
526 
TEST_F(StreamSynchronizationTest,BothDelayedAudioClockDriftWithBaseDelay)527 TEST_F(StreamSynchronizationTest, BothDelayedAudioClockDriftWithBaseDelay) {
528   int base_target_delay_ms = 3000;
529   sync_->SetTargetBufferingDelay(base_target_delay_ms);
530   audio_clock_drift_ = 1.05;
531   BothDelayedAudioLaterTest(base_target_delay_ms);
532 }
533 
TEST_F(StreamSynchronizationTest,BothDelayedVideoClockDriftWithBaseDelay)534 TEST_F(StreamSynchronizationTest, BothDelayedVideoClockDriftWithBaseDelay) {
535   int base_target_delay_ms = 3000;
536   sync_->SetTargetBufferingDelay(base_target_delay_ms);
537   video_clock_drift_ = 1.05;
538   BothDelayedAudioLaterTest(base_target_delay_ms);
539 }
540 
TEST_F(StreamSynchronizationTest,BothDelayedVideoLaterWithBaseDelay)541 TEST_F(StreamSynchronizationTest, BothDelayedVideoLaterWithBaseDelay) {
542   int base_target_delay_ms = 2000;
543   sync_->SetTargetBufferingDelay(base_target_delay_ms);
544   BothDelayedVideoLaterTest(base_target_delay_ms);
545 }
546 
TEST_F(StreamSynchronizationTest,BothDelayedVideoLaterAudioClockDriftWithBaseDelay)547 TEST_F(StreamSynchronizationTest,
548        BothDelayedVideoLaterAudioClockDriftWithBaseDelay) {
549   int base_target_delay_ms = 2000;
550   audio_clock_drift_ = 1.05;
551   sync_->SetTargetBufferingDelay(base_target_delay_ms);
552   BothDelayedVideoLaterTest(base_target_delay_ms);
553 }
554 
TEST_F(StreamSynchronizationTest,BothDelayedVideoLaterVideoClockDriftWithBaseDelay)555 TEST_F(StreamSynchronizationTest,
556        BothDelayedVideoLaterVideoClockDriftWithBaseDelay) {
557   int base_target_delay_ms = 2000;
558   video_clock_drift_ = 1.05;
559   sync_->SetTargetBufferingDelay(base_target_delay_ms);
560   BothDelayedVideoLaterTest(base_target_delay_ms);
561 }
562 
563 }  // namespace webrtc
564