OLD | NEW |
1 /* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 1 /* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
2 * | 2 * |
3 * Use of this source code is governed by a BSD-style license | 3 * Use of this source code is governed by a BSD-style license |
4 * that can be found in the LICENSE file in the root of the source | 4 * that can be found in the LICENSE file in the root of the source |
5 * tree. An additional intellectual property rights grant can be found | 5 * tree. An additional intellectual property rights grant can be found |
6 * in the file PATENTS. All contributing project authors may | 6 * in the file PATENTS. All contributing project authors may |
7 * be found in the AUTHORS file in the root of the source tree. | 7 * be found in the AUTHORS file in the root of the source tree. |
8 */ | 8 */ |
9 | 9 |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 bool AdvanceTimeMilliseconds(int64_t milliseconds, bool stop_on_frame) { | 341 bool AdvanceTimeMilliseconds(int64_t milliseconds, bool stop_on_frame) { |
342 return AdvanceTimeMicroseconds(milliseconds * 1000, stop_on_frame); | 342 return AdvanceTimeMicroseconds(milliseconds * 1000, stop_on_frame); |
343 }; | 343 }; |
344 | 344 |
345 bool AdvanceTimeMicroseconds(int64_t microseconds, bool stop_on_frame) { | 345 bool AdvanceTimeMicroseconds(int64_t microseconds, bool stop_on_frame) { |
346 int64_t start_time = TimeInMicroseconds(); | 346 int64_t start_time = TimeInMicroseconds(); |
347 int64_t end_time = start_time + microseconds; | 347 int64_t end_time = start_time + microseconds; |
348 bool frame_injected = false; | 348 bool frame_injected = false; |
349 while (!timestamps_.empty() && | 349 while (!timestamps_.empty() && |
350 timestamps_.front().arrive_time <= end_time) { | 350 timestamps_.front().arrive_time <= end_time) { |
351 DCHECK(timestamps_.front().arrive_time >= start_time); | 351 RTC_DCHECK(timestamps_.front().arrive_time >= start_time); |
352 | 352 |
353 SimulatedClock::AdvanceTimeMicroseconds(timestamps_.front().arrive_time - | 353 SimulatedClock::AdvanceTimeMicroseconds(timestamps_.front().arrive_time - |
354 TimeInMicroseconds()); | 354 TimeInMicroseconds()); |
355 GenerateAndInsertFrame((timestamps_.front().render_time + 500) / 1000); | 355 GenerateAndInsertFrame((timestamps_.front().render_time + 500) / 1000); |
356 timestamps_.pop(); | 356 timestamps_.pop(); |
357 frame_injected = true; | 357 frame_injected = true; |
358 | 358 |
359 if (stop_on_frame) | 359 if (stop_on_frame) |
360 return frame_injected; | 360 return frame_injected; |
361 } | 361 } |
362 | 362 |
363 if (TimeInMicroseconds() < end_time) { | 363 if (TimeInMicroseconds() < end_time) { |
364 SimulatedClock::AdvanceTimeMicroseconds(end_time - TimeInMicroseconds()); | 364 SimulatedClock::AdvanceTimeMicroseconds(end_time - TimeInMicroseconds()); |
365 } | 365 } |
366 return frame_injected; | 366 return frame_injected; |
367 }; | 367 }; |
368 | 368 |
369 // Input timestamps are in unit Milliseconds. | 369 // Input timestamps are in unit Milliseconds. |
370 // And |arrive_timestamps| must be positive and in increasing order. | 370 // And |arrive_timestamps| must be positive and in increasing order. |
371 // |arrive_timestamps| determine when we are going to insert frames into the | 371 // |arrive_timestamps| determine when we are going to insert frames into the |
372 // jitter buffer. | 372 // jitter buffer. |
373 // |render_timestamps| are the timestamps on the frame. | 373 // |render_timestamps| are the timestamps on the frame. |
374 void SetFrames(const int64_t* arrive_timestamps, | 374 void SetFrames(const int64_t* arrive_timestamps, |
375 const int64_t* render_timestamps, | 375 const int64_t* render_timestamps, |
376 size_t size) { | 376 size_t size) { |
377 int64_t previous_arrive_timestamp = 0; | 377 int64_t previous_arrive_timestamp = 0; |
378 for (size_t i = 0; i < size; i++) { | 378 for (size_t i = 0; i < size; i++) { |
379 CHECK(arrive_timestamps[i] >= previous_arrive_timestamp); | 379 RTC_CHECK(arrive_timestamps[i] >= previous_arrive_timestamp); |
380 timestamps_.push(TimestampPair(arrive_timestamps[i] * 1000, | 380 timestamps_.push(TimestampPair(arrive_timestamps[i] * 1000, |
381 render_timestamps[i] * 1000)); | 381 render_timestamps[i] * 1000)); |
382 previous_arrive_timestamp = arrive_timestamps[i]; | 382 previous_arrive_timestamp = arrive_timestamps[i]; |
383 } | 383 } |
384 } | 384 } |
385 | 385 |
386 private: | 386 private: |
387 struct TimestampPair { | 387 struct TimestampPair { |
388 TimestampPair(int64_t arrive_timestamp, int64_t render_timestamp) | 388 TimestampPair(int64_t arrive_timestamp, int64_t render_timestamp) |
389 : arrive_time(arrive_timestamp), render_time(render_timestamp) {} | 389 : arrive_time(arrive_timestamp), render_time(render_timestamp) {} |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 receiver_.ReleaseFrame(frame); | 519 receiver_.ReleaseFrame(frame); |
520 ++num_frames_return; | 520 ++num_frames_return; |
521 EXPECT_GE(kMaxWaitTime, end_time - start_time); | 521 EXPECT_GE(kMaxWaitTime, end_time - start_time); |
522 } else { | 522 } else { |
523 EXPECT_EQ(kMaxWaitTime, end_time - start_time); | 523 EXPECT_EQ(kMaxWaitTime, end_time - start_time); |
524 } | 524 } |
525 } | 525 } |
526 } | 526 } |
527 | 527 |
528 } // namespace webrtc | 528 } // namespace webrtc |
OLD | NEW |