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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 if (!complete) { | 66 if (!complete) { |
67 // Drop the second packet. | 67 // Drop the second packet. |
68 VCMPacket packet; | 68 VCMPacket packet; |
69 stream_generator_->PopPacket(&packet, 0); | 69 stream_generator_->PopPacket(&packet, 0); |
70 } | 70 } |
71 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs); | 71 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs); |
72 return ret; | 72 return ret; |
73 } | 73 } |
74 | 74 |
75 bool DecodeNextFrame() { | 75 bool DecodeNextFrame() { |
76 int64_t render_time_ms = 0; | 76 VCMEncodedFrame* frame = receiver_.FrameForDecoding(0, false); |
77 VCMEncodedFrame* frame = | |
78 receiver_.FrameForDecoding(0, &render_time_ms, false); | |
79 if (!frame) | 77 if (!frame) |
80 return false; | 78 return false; |
81 receiver_.ReleaseFrame(frame); | 79 receiver_.ReleaseFrame(frame); |
82 return true; | 80 return true; |
83 } | 81 } |
84 | 82 |
85 std::unique_ptr<SimulatedClock> clock_; | 83 std::unique_ptr<SimulatedClock> clock_; |
86 VCMTiming timing_; | 84 VCMTiming timing_; |
87 NullEventFactory event_factory_; | 85 NullEventFactory event_factory_; |
88 VCMReceiver receiver_; | 86 VCMReceiver receiver_; |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 // Test whether VCMReceiver::FrameForDecoding handles parameter | 400 // Test whether VCMReceiver::FrameForDecoding handles parameter |
403 // |max_wait_time_ms| correctly: | 401 // |max_wait_time_ms| correctly: |
404 // 1. The function execution should never take more than |max_wait_time_ms|. | 402 // 1. The function execution should never take more than |max_wait_time_ms|. |
405 // 2. If the function exit before now + |max_wait_time_ms|, a frame must be | 403 // 2. If the function exit before now + |max_wait_time_ms|, a frame must be |
406 // returned. | 404 // returned. |
407 TEST_F(VCMReceiverTimingTest, FrameForDecoding) { | 405 TEST_F(VCMReceiverTimingTest, FrameForDecoding) { |
408 const size_t kNumFrames = 100; | 406 const size_t kNumFrames = 100; |
409 const int kFramePeriod = 40; | 407 const int kFramePeriod = 40; |
410 int64_t arrive_timestamps[kNumFrames]; | 408 int64_t arrive_timestamps[kNumFrames]; |
411 int64_t render_timestamps[kNumFrames]; | 409 int64_t render_timestamps[kNumFrames]; |
412 int64_t next_render_time; | |
413 | 410 |
414 // Construct test samples. | 411 // Construct test samples. |
415 // render_timestamps are the timestamps stored in the Frame; | 412 // render_timestamps are the timestamps stored in the Frame; |
416 // arrive_timestamps controls when the Frame packet got received. | 413 // arrive_timestamps controls when the Frame packet got received. |
417 for (size_t i = 0; i < kNumFrames; i++) { | 414 for (size_t i = 0; i < kNumFrames; i++) { |
418 // Preset frame rate to 25Hz. | 415 // Preset frame rate to 25Hz. |
419 // But we add a reasonable deviation to arrive_timestamps to mimic Internet | 416 // But we add a reasonable deviation to arrive_timestamps to mimic Internet |
420 // fluctuation. | 417 // fluctuation. |
421 arrive_timestamps[i] = | 418 arrive_timestamps[i] = |
422 (i + 1) * kFramePeriod + (i % 10) * ((i % 2) ? 1 : -1); | 419 (i + 1) * kFramePeriod + (i % 10) * ((i % 2) ? 1 : -1); |
423 render_timestamps[i] = (i + 1) * kFramePeriod; | 420 render_timestamps[i] = (i + 1) * kFramePeriod; |
424 } | 421 } |
425 | 422 |
426 clock_.SetFrames(arrive_timestamps, render_timestamps, kNumFrames); | 423 clock_.SetFrames(arrive_timestamps, render_timestamps, kNumFrames); |
427 | 424 |
428 // Record how many frames we finally get out of the receiver. | 425 // Record how many frames we finally get out of the receiver. |
429 size_t num_frames_return = 0; | 426 size_t num_frames_return = 0; |
430 | 427 |
431 const int64_t kMaxWaitTime = 30; | 428 const int64_t kMaxWaitTime = 30; |
432 | 429 |
433 // Ideally, we should get all frames that we input in InitializeFrames. | 430 // Ideally, we should get all frames that we input in InitializeFrames. |
434 // In the case that FrameForDecoding kills frames by error, we rely on the | 431 // In the case that FrameForDecoding kills frames by error, we rely on the |
435 // build bot to kill the test. | 432 // build bot to kill the test. |
436 while (num_frames_return < kNumFrames) { | 433 while (num_frames_return < kNumFrames) { |
437 int64_t start_time = clock_.TimeInMilliseconds(); | 434 int64_t start_time = clock_.TimeInMilliseconds(); |
438 VCMEncodedFrame* frame = | 435 VCMEncodedFrame* frame = receiver_.FrameForDecoding(kMaxWaitTime, false); |
439 receiver_.FrameForDecoding(kMaxWaitTime, &next_render_time, false); | |
440 int64_t end_time = clock_.TimeInMilliseconds(); | 436 int64_t end_time = clock_.TimeInMilliseconds(); |
441 | 437 |
442 // In any case the FrameForDecoding should not wait longer than | 438 // In any case the FrameForDecoding should not wait longer than |
443 // max_wait_time. | 439 // max_wait_time. |
444 // In the case that we did not get a frame, it should have been waiting for | 440 // In the case that we did not get a frame, it should have been waiting for |
445 // exactly max_wait_time. (By the testing samples we constructed above, we | 441 // exactly max_wait_time. (By the testing samples we constructed above, we |
446 // are sure there is no timing error, so the only case it returns with NULL | 442 // are sure there is no timing error, so the only case it returns with NULL |
447 // is that it runs out of time.) | 443 // is that it runs out of time.) |
448 if (frame) { | 444 if (frame) { |
449 receiver_.ReleaseFrame(frame); | 445 receiver_.ReleaseFrame(frame); |
(...skipping 10 matching lines...) Expand all Loading... |
460 // 1. The function execution should never take more than |max_wait_time_ms|. | 456 // 1. The function execution should never take more than |max_wait_time_ms|. |
461 // 2. If the function exit before now + |max_wait_time_ms|, a frame must be | 457 // 2. If the function exit before now + |max_wait_time_ms|, a frame must be |
462 // returned and the end time must be equal to the render timestamp - delay | 458 // returned and the end time must be equal to the render timestamp - delay |
463 // for decoding and rendering. | 459 // for decoding and rendering. |
464 TEST_F(VCMReceiverTimingTest, FrameForDecodingPreferLateDecoding) { | 460 TEST_F(VCMReceiverTimingTest, FrameForDecodingPreferLateDecoding) { |
465 const size_t kNumFrames = 100; | 461 const size_t kNumFrames = 100; |
466 const int kFramePeriod = 40; | 462 const int kFramePeriod = 40; |
467 | 463 |
468 int64_t arrive_timestamps[kNumFrames]; | 464 int64_t arrive_timestamps[kNumFrames]; |
469 int64_t render_timestamps[kNumFrames]; | 465 int64_t render_timestamps[kNumFrames]; |
470 int64_t next_render_time; | |
471 | 466 |
472 int render_delay_ms; | 467 int render_delay_ms; |
473 int max_decode_ms; | 468 int max_decode_ms; |
474 int dummy; | 469 int dummy; |
475 timing_.GetTimings(&dummy, &max_decode_ms, &dummy, &dummy, &dummy, &dummy, | 470 timing_.GetTimings(&dummy, &max_decode_ms, &dummy, &dummy, &dummy, &dummy, |
476 &render_delay_ms); | 471 &render_delay_ms); |
477 | 472 |
478 // Construct test samples. | 473 // Construct test samples. |
479 // render_timestamps are the timestamps stored in the Frame; | 474 // render_timestamps are the timestamps stored in the Frame; |
480 // arrive_timestamps controls when the Frame packet got received. | 475 // arrive_timestamps controls when the Frame packet got received. |
481 for (size_t i = 0; i < kNumFrames; i++) { | 476 for (size_t i = 0; i < kNumFrames; i++) { |
482 // Preset frame rate to 25Hz. | 477 // Preset frame rate to 25Hz. |
483 // But we add a reasonable deviation to arrive_timestamps to mimic Internet | 478 // But we add a reasonable deviation to arrive_timestamps to mimic Internet |
484 // fluctuation. | 479 // fluctuation. |
485 arrive_timestamps[i] = | 480 arrive_timestamps[i] = |
486 (i + 1) * kFramePeriod + (i % 10) * ((i % 2) ? 1 : -1); | 481 (i + 1) * kFramePeriod + (i % 10) * ((i % 2) ? 1 : -1); |
487 render_timestamps[i] = (i + 1) * kFramePeriod; | 482 render_timestamps[i] = (i + 1) * kFramePeriod; |
488 } | 483 } |
489 | 484 |
490 clock_.SetFrames(arrive_timestamps, render_timestamps, kNumFrames); | 485 clock_.SetFrames(arrive_timestamps, render_timestamps, kNumFrames); |
491 | 486 |
492 // Record how many frames we finally get out of the receiver. | 487 // Record how many frames we finally get out of the receiver. |
493 size_t num_frames_return = 0; | 488 size_t num_frames_return = 0; |
494 const int64_t kMaxWaitTime = 30; | 489 const int64_t kMaxWaitTime = 30; |
495 bool prefer_late_decoding = true; | 490 bool prefer_late_decoding = true; |
496 while (num_frames_return < kNumFrames) { | 491 while (num_frames_return < kNumFrames) { |
497 int64_t start_time = clock_.TimeInMilliseconds(); | 492 int64_t start_time = clock_.TimeInMilliseconds(); |
498 | 493 |
499 VCMEncodedFrame* frame = receiver_.FrameForDecoding( | 494 VCMEncodedFrame* frame = |
500 kMaxWaitTime, &next_render_time, prefer_late_decoding); | 495 receiver_.FrameForDecoding(kMaxWaitTime, prefer_late_decoding); |
501 int64_t end_time = clock_.TimeInMilliseconds(); | 496 int64_t end_time = clock_.TimeInMilliseconds(); |
502 if (frame) { | 497 if (frame) { |
503 EXPECT_EQ(frame->RenderTimeMs() - max_decode_ms - render_delay_ms, | 498 EXPECT_EQ(frame->RenderTimeMs() - max_decode_ms - render_delay_ms, |
504 end_time); | 499 end_time); |
505 receiver_.ReleaseFrame(frame); | 500 receiver_.ReleaseFrame(frame); |
506 ++num_frames_return; | 501 ++num_frames_return; |
507 } else { | 502 } else { |
508 EXPECT_EQ(kMaxWaitTime, end_time - start_time); | 503 EXPECT_EQ(kMaxWaitTime, end_time - start_time); |
509 } | 504 } |
510 } | 505 } |
511 } | 506 } |
512 | 507 |
513 } // namespace webrtc | 508 } // namespace webrtc |
OLD | NEW |