| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 #include "webrtc/video/video_quality_test.h" | 10 #include "webrtc/video/video_quality_test.h" |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 } | 364 } |
| 365 EncodedFrameObserver* encode_timing_proxy() { return &encode_timing_proxy_; } | 365 EncodedFrameObserver* encode_timing_proxy() { return &encode_timing_proxy_; } |
| 366 | 366 |
| 367 test::LayerFilteringTransport* const transport_; | 367 test::LayerFilteringTransport* const transport_; |
| 368 PacketReceiver* receiver_; | 368 PacketReceiver* receiver_; |
| 369 | 369 |
| 370 private: | 370 private: |
| 371 struct FrameComparison { | 371 struct FrameComparison { |
| 372 FrameComparison() | 372 FrameComparison() |
| 373 : dropped(false), | 373 : dropped(false), |
| 374 input_time_ms(0), | |
| 375 send_time_ms(0), | 374 send_time_ms(0), |
| 376 recv_time_ms(0), | 375 recv_time_ms(0), |
| 377 render_time_ms(0), | 376 render_time_ms(0), |
| 378 encoded_frame_size(0) {} | 377 encoded_frame_size(0) {} |
| 379 | 378 |
| 380 FrameComparison(const VideoFrame& reference, | 379 FrameComparison(const VideoFrame& reference, |
| 381 const VideoFrame& render, | 380 const VideoFrame& render, |
| 382 bool dropped, | 381 bool dropped, |
| 383 int64_t input_time_ms, | |
| 384 int64_t send_time_ms, | 382 int64_t send_time_ms, |
| 385 int64_t recv_time_ms, | 383 int64_t recv_time_ms, |
| 386 int64_t render_time_ms, | 384 int64_t render_time_ms, |
| 387 size_t encoded_frame_size) | 385 size_t encoded_frame_size) |
| 388 : reference(reference), | 386 : reference(reference), |
| 389 render(render), | 387 render(render), |
| 390 dropped(dropped), | 388 dropped(dropped), |
| 391 input_time_ms(input_time_ms), | |
| 392 send_time_ms(send_time_ms), | 389 send_time_ms(send_time_ms), |
| 393 recv_time_ms(recv_time_ms), | 390 recv_time_ms(recv_time_ms), |
| 394 render_time_ms(render_time_ms), | 391 render_time_ms(render_time_ms), |
| 395 encoded_frame_size(encoded_frame_size) {} | 392 encoded_frame_size(encoded_frame_size) {} |
| 396 | 393 |
| 397 FrameComparison(bool dropped, | 394 VideoFrame reference; |
| 398 int64_t input_time_ms, | 395 VideoFrame render; |
| 399 int64_t send_time_ms, | |
| 400 int64_t recv_time_ms, | |
| 401 int64_t render_time_ms, | |
| 402 size_t encoded_frame_size) | |
| 403 : dropped(dropped), | |
| 404 input_time_ms(input_time_ms), | |
| 405 send_time_ms(send_time_ms), | |
| 406 recv_time_ms(recv_time_ms), | |
| 407 render_time_ms(render_time_ms), | |
| 408 encoded_frame_size(encoded_frame_size) {} | |
| 409 | |
| 410 rtc::Optional<VideoFrame> reference; | |
| 411 rtc::Optional<VideoFrame> render; | |
| 412 bool dropped; | 396 bool dropped; |
| 413 int64_t input_time_ms; | |
| 414 int64_t send_time_ms; | 397 int64_t send_time_ms; |
| 415 int64_t recv_time_ms; | 398 int64_t recv_time_ms; |
| 416 int64_t render_time_ms; | 399 int64_t render_time_ms; |
| 417 size_t encoded_frame_size; | 400 size_t encoded_frame_size; |
| 418 }; | 401 }; |
| 419 | 402 |
| 420 struct Sample { | 403 struct Sample { |
| 421 Sample(int dropped, | 404 Sample(int dropped, |
| 422 int64_t input_time_ms, | 405 int64_t input_time_ms, |
| 423 int64_t send_time_ms, | 406 int64_t send_time_ms, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 recv_times_.erase(reference_timestamp); | 469 recv_times_.erase(reference_timestamp); |
| 487 | 470 |
| 488 // TODO(ivica): Make this work for > 2 streams. | 471 // TODO(ivica): Make this work for > 2 streams. |
| 489 auto it = encoded_frame_sizes_.find(reference_timestamp); | 472 auto it = encoded_frame_sizes_.find(reference_timestamp); |
| 490 if (it == encoded_frame_sizes_.end()) | 473 if (it == encoded_frame_sizes_.end()) |
| 491 it = encoded_frame_sizes_.find(reference_timestamp - 1); | 474 it = encoded_frame_sizes_.find(reference_timestamp - 1); |
| 492 size_t encoded_size = it == encoded_frame_sizes_.end() ? 0 : it->second; | 475 size_t encoded_size = it == encoded_frame_sizes_.end() ? 0 : it->second; |
| 493 if (it != encoded_frame_sizes_.end()) | 476 if (it != encoded_frame_sizes_.end()) |
| 494 encoded_frame_sizes_.erase(it); | 477 encoded_frame_sizes_.erase(it); |
| 495 | 478 |
| 479 VideoFrame reference_copy; |
| 480 VideoFrame render_copy; |
| 481 |
| 496 rtc::CritScope crit(&comparison_lock_); | 482 rtc::CritScope crit(&comparison_lock_); |
| 497 if (comparisons_.size() < kMaxComparisons) { | 483 if (comparisons_.size() < kMaxComparisons) { |
| 498 comparisons_.push_back(FrameComparison(reference, render, dropped, | 484 reference_copy = reference; |
| 499 reference.ntp_time_ms(), | 485 render_copy = render; |
| 500 send_time_ms, recv_time_ms, | |
| 501 render_time_ms, encoded_size)); | |
| 502 } else { | 486 } else { |
| 503 comparisons_.push_back(FrameComparison(dropped, | 487 // Copy the time to ensure that delay calculations can still be made. |
| 504 reference.ntp_time_ms(), | 488 reference_copy.set_ntp_time_ms(reference.ntp_time_ms()); |
| 505 send_time_ms, recv_time_ms, | 489 render_copy.set_ntp_time_ms(render.ntp_time_ms()); |
| 506 render_time_ms, encoded_size)); | |
| 507 } | 490 } |
| 491 comparisons_.push_back(FrameComparison(reference_copy, render_copy, dropped, |
| 492 send_time_ms, recv_time_ms, |
| 493 render_time_ms, encoded_size)); |
| 508 comparison_available_event_.Set(); | 494 comparison_available_event_.Set(); |
| 509 } | 495 } |
| 510 | 496 |
| 511 static bool PollStatsThread(void* obj) { | 497 static bool PollStatsThread(void* obj) { |
| 512 return static_cast<VideoAnalyzer*>(obj)->PollStats(); | 498 return static_cast<VideoAnalyzer*>(obj)->PollStats(); |
| 513 } | 499 } |
| 514 | 500 |
| 515 bool PollStats() { | 501 bool PollStats() { |
| 516 if (done_.Wait(kSendStatsPollingIntervalMs)) | 502 if (done_.Wait(kSendStatsPollingIntervalMs)) |
| 517 return false; | 503 return false; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 534 } | 520 } |
| 535 | 521 |
| 536 static bool FrameComparisonThread(void* obj) { | 522 static bool FrameComparisonThread(void* obj) { |
| 537 return static_cast<VideoAnalyzer*>(obj)->CompareFrames(); | 523 return static_cast<VideoAnalyzer*>(obj)->CompareFrames(); |
| 538 } | 524 } |
| 539 | 525 |
| 540 bool CompareFrames() { | 526 bool CompareFrames() { |
| 541 if (AllFramesRecorded()) | 527 if (AllFramesRecorded()) |
| 542 return false; | 528 return false; |
| 543 | 529 |
| 530 VideoFrame reference; |
| 531 VideoFrame render; |
| 544 FrameComparison comparison; | 532 FrameComparison comparison; |
| 545 | 533 |
| 546 if (!PopComparison(&comparison)) { | 534 if (!PopComparison(&comparison)) { |
| 547 // Wait until new comparison task is available, or test is done. | 535 // Wait until new comparison task is available, or test is done. |
| 548 // If done, wake up remaining threads waiting. | 536 // If done, wake up remaining threads waiting. |
| 549 comparison_available_event_.Wait(1000); | 537 comparison_available_event_.Wait(1000); |
| 550 if (AllFramesRecorded()) { | 538 if (AllFramesRecorded()) { |
| 551 comparison_available_event_.Set(); | 539 comparison_available_event_.Set(); |
| 552 return false; | 540 return false; |
| 553 } | 541 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 test_label_.c_str(), dropped_frames_before_rendering_); | 617 test_label_.c_str(), dropped_frames_before_rendering_); |
| 630 | 618 |
| 631 EXPECT_GT(psnr_.Mean(), avg_psnr_threshold_); | 619 EXPECT_GT(psnr_.Mean(), avg_psnr_threshold_); |
| 632 EXPECT_GT(ssim_.Mean(), avg_ssim_threshold_); | 620 EXPECT_GT(ssim_.Mean(), avg_ssim_threshold_); |
| 633 } | 621 } |
| 634 | 622 |
| 635 void PerformFrameComparison(const FrameComparison& comparison) { | 623 void PerformFrameComparison(const FrameComparison& comparison) { |
| 636 // Perform expensive psnr and ssim calculations while not holding lock. | 624 // Perform expensive psnr and ssim calculations while not holding lock. |
| 637 double psnr = -1.0; | 625 double psnr = -1.0; |
| 638 double ssim = -1.0; | 626 double ssim = -1.0; |
| 639 if (comparison.reference) { | 627 if (!comparison.reference.IsZeroSize()) { |
| 640 psnr = I420PSNR(&*comparison.reference, &*comparison.render); | 628 psnr = I420PSNR(&comparison.reference, &comparison.render); |
| 641 ssim = I420SSIM(&*comparison.reference, &*comparison.render); | 629 ssim = I420SSIM(&comparison.reference, &comparison.render); |
| 642 } | 630 } |
| 643 | 631 |
| 644 int64_t input_time_ms = comparison.reference->ntp_time_ms(); | 632 int64_t input_time_ms = comparison.reference.ntp_time_ms(); |
| 645 | 633 |
| 646 rtc::CritScope crit(&comparison_lock_); | 634 rtc::CritScope crit(&comparison_lock_); |
| 647 if (graph_data_output_file_) { | 635 if (graph_data_output_file_) { |
| 648 samples_.push_back( | 636 samples_.push_back( |
| 649 Sample(comparison.dropped, input_time_ms, comparison.send_time_ms, | 637 Sample(comparison.dropped, input_time_ms, comparison.send_time_ms, |
| 650 comparison.recv_time_ms, comparison.render_time_ms, | 638 comparison.recv_time_ms, comparison.render_time_ms, |
| 651 comparison.encoded_frame_size, psnr, ssim)); | 639 comparison.encoded_frame_size, psnr, ssim)); |
| 652 } | 640 } |
| 653 if (psnr >= 0.0) | 641 if (psnr >= 0.0) |
| 654 psnr_.AddSample(psnr); | 642 psnr_.AddSample(psnr); |
| (...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1497 std::ostringstream str; | 1485 std::ostringstream str; |
| 1498 str << receive_logs_++; | 1486 str << receive_logs_++; |
| 1499 std::string path = | 1487 std::string path = |
| 1500 params_.video.encoded_frame_base_path + "." + str.str() + ".recv.ivf"; | 1488 params_.video.encoded_frame_base_path + "." + str.str() + ".recv.ivf"; |
| 1501 stream->EnableEncodedFrameRecording(rtc::CreatePlatformFile(path), | 1489 stream->EnableEncodedFrameRecording(rtc::CreatePlatformFile(path), |
| 1502 10000000); | 1490 10000000); |
| 1503 } | 1491 } |
| 1504 } | 1492 } |
| 1505 | 1493 |
| 1506 } // namespace webrtc | 1494 } // namespace webrtc |
| OLD | NEW |