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