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