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" |
11 | 11 |
12 #include <stdio.h> | 12 #include <stdio.h> |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <deque> | 14 #include <deque> |
15 #include <map> | 15 #include <map> |
16 #include <sstream> | 16 #include <sstream> |
17 #include <string> | 17 #include <string> |
18 #include <vector> | 18 #include <vector> |
19 | 19 |
20 #include "webrtc/base/checks.h" | 20 #include "webrtc/base/checks.h" |
21 #include "webrtc/base/cpu_time.h" | |
21 #include "webrtc/base/event.h" | 22 #include "webrtc/base/event.h" |
22 #include "webrtc/base/format_macros.h" | 23 #include "webrtc/base/format_macros.h" |
23 #include "webrtc/base/optional.h" | 24 #include "webrtc/base/optional.h" |
24 #include "webrtc/base/platform_file.h" | 25 #include "webrtc/base/platform_file.h" |
25 #include "webrtc/base/timeutils.h" | 26 #include "webrtc/base/timeutils.h" |
26 #include "webrtc/call/call.h" | 27 #include "webrtc/call/call.h" |
27 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 28 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
28 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" | 29 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
29 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" | 30 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" |
30 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" | 31 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 pre_encode_proxy_(this), | 156 pre_encode_proxy_(this), |
156 encode_timing_proxy_(this), | 157 encode_timing_proxy_(this), |
157 frames_to_process_(duration_frames), | 158 frames_to_process_(duration_frames), |
158 frames_recorded_(0), | 159 frames_recorded_(0), |
159 frames_processed_(0), | 160 frames_processed_(0), |
160 dropped_frames_(0), | 161 dropped_frames_(0), |
161 dropped_frames_before_first_encode_(0), | 162 dropped_frames_before_first_encode_(0), |
162 dropped_frames_before_rendering_(0), | 163 dropped_frames_before_rendering_(0), |
163 last_render_time_(0), | 164 last_render_time_(0), |
164 rtp_timestamp_delta_(0), | 165 rtp_timestamp_delta_(0), |
166 cpu_time_(0), | |
167 wallclock_time_(0), | |
165 avg_psnr_threshold_(avg_psnr_threshold), | 168 avg_psnr_threshold_(avg_psnr_threshold), |
166 avg_ssim_threshold_(avg_ssim_threshold), | 169 avg_ssim_threshold_(avg_ssim_threshold), |
167 is_quick_test_enabled_(is_quick_test_enabled), | 170 is_quick_test_enabled_(is_quick_test_enabled), |
168 stats_polling_thread_(&PollStatsThread, this, "StatsPoller"), | 171 stats_polling_thread_(&PollStatsThread, this, "StatsPoller"), |
169 comparison_available_event_(false, false), | 172 comparison_available_event_(false, false), |
170 done_(true, false) { | 173 done_(true, false) { |
171 // Create thread pool for CPU-expensive PSNR/SSIM calculations. | 174 // Create thread pool for CPU-expensive PSNR/SSIM calculations. |
172 | 175 |
173 // Try to use about as many threads as cores, but leave kMinCoresLeft alone, | 176 // Try to use about as many threads as cores, but leave kMinCoresLeft alone, |
174 // so that we don't accidentally starve "real" worker threads (codec etc). | 177 // so that we don't accidentally starve "real" worker threads (codec etc). |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 rtc::CritScope lock(&comparison_lock_); | 326 rtc::CritScope lock(&comparison_lock_); |
324 if (frames_recorded_ < frames_to_process_) | 327 if (frames_recorded_ < frames_to_process_) |
325 encoded_frame_size_.AddSample(frame.length_); | 328 encoded_frame_size_.AddSample(frame.length_); |
326 } | 329 } |
327 | 330 |
328 void OnFrame(const VideoFrame& video_frame) override { | 331 void OnFrame(const VideoFrame& video_frame) override { |
329 int64_t render_time_ms = | 332 int64_t render_time_ms = |
330 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds(); | 333 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds(); |
331 | 334 |
332 rtc::CritScope lock(&crit_); | 335 rtc::CritScope lock(&crit_); |
336 | |
337 StartExcludingCpuThreadTime(); | |
338 | |
333 int64_t send_timestamp = | 339 int64_t send_timestamp = |
334 wrap_handler_.Unwrap(video_frame.timestamp() - rtp_timestamp_delta_); | 340 wrap_handler_.Unwrap(video_frame.timestamp() - rtp_timestamp_delta_); |
335 | 341 |
336 while (wrap_handler_.Unwrap(frames_.front().timestamp()) < send_timestamp) { | 342 while (wrap_handler_.Unwrap(frames_.front().timestamp()) < send_timestamp) { |
337 if (!last_rendered_frame_) { | 343 if (!last_rendered_frame_) { |
338 // No previous frame rendered, this one was dropped after sending but | 344 // No previous frame rendered, this one was dropped after sending but |
339 // before rendering. | 345 // before rendering. |
340 ++dropped_frames_before_rendering_; | 346 ++dropped_frames_before_rendering_; |
341 } else { | 347 } else { |
342 AddFrameComparison(frames_.front(), *last_rendered_frame_, true, | 348 AddFrameComparison(frames_.front(), *last_rendered_frame_, true, |
(...skipping 10 matching lines...) Expand all Loading... | |
353 if (send_timestamp == reference_timestamp - 1) { | 359 if (send_timestamp == reference_timestamp - 1) { |
354 // TODO(ivica): Make this work for > 2 streams. | 360 // TODO(ivica): Make this work for > 2 streams. |
355 // Look at RTPSender::BuildRTPHeader. | 361 // Look at RTPSender::BuildRTPHeader. |
356 ++send_timestamp; | 362 ++send_timestamp; |
357 } | 363 } |
358 ASSERT_EQ(reference_timestamp, send_timestamp); | 364 ASSERT_EQ(reference_timestamp, send_timestamp); |
359 | 365 |
360 AddFrameComparison(reference_frame, video_frame, false, render_time_ms); | 366 AddFrameComparison(reference_frame, video_frame, false, render_time_ms); |
361 | 367 |
362 last_rendered_frame_ = rtc::Optional<VideoFrame>(video_frame); | 368 last_rendered_frame_ = rtc::Optional<VideoFrame>(video_frame); |
369 | |
370 StopExcludingCpuThreadTime(); | |
363 } | 371 } |
364 | 372 |
365 void Wait() { | 373 void Wait() { |
366 // Frame comparisons can be very expensive. Wait for test to be done, but | 374 // Frame comparisons can be very expensive. Wait for test to be done, but |
367 // at time-out check if frames_processed is going up. If so, give it more | 375 // at time-out check if frames_processed is going up. If so, give it more |
368 // time, otherwise fail. Hopefully this will reduce test flakiness. | 376 // time, otherwise fail. Hopefully this will reduce test flakiness. |
369 | 377 |
370 stats_polling_thread_.Start(); | 378 stats_polling_thread_.Start(); |
371 | 379 |
372 int last_frames_processed = -1; | 380 int last_frames_processed = -1; |
(...skipping 29 matching lines...) Expand all Loading... | |
402 printf("- Farewell, sweet Concorde!\n"); | 410 printf("- Farewell, sweet Concorde!\n"); |
403 | 411 |
404 stats_polling_thread_.Stop(); | 412 stats_polling_thread_.Stop(); |
405 } | 413 } |
406 | 414 |
407 rtc::VideoSinkInterface<VideoFrame>* pre_encode_proxy() { | 415 rtc::VideoSinkInterface<VideoFrame>* pre_encode_proxy() { |
408 return &pre_encode_proxy_; | 416 return &pre_encode_proxy_; |
409 } | 417 } |
410 EncodedFrameObserver* encode_timing_proxy() { return &encode_timing_proxy_; } | 418 EncodedFrameObserver* encode_timing_proxy() { return &encode_timing_proxy_; } |
411 | 419 |
420 void StartMeasuringCpuProcessTime() { | |
421 rtc::CritScope lock(&cpu_measurement_lock_); | |
422 cpu_time_ -= rtc::GetProcessCpuTimeNanos(); | |
423 wallclock_time_ -= rtc::SystemTimeNanos(); | |
424 } | |
425 | |
426 void StopMeasuringCpuProcessTime() { | |
427 rtc::CritScope lock(&cpu_measurement_lock_); | |
428 cpu_time_ += rtc::GetProcessCpuTimeNanos(); | |
429 wallclock_time_ += rtc::SystemTimeNanos(); | |
430 } | |
431 | |
432 void StartExcludingCpuThreadTime() { | |
433 rtc::CritScope lock(&cpu_measurement_lock_); | |
434 cpu_time_ += rtc::GetThreadCpuTimeNanos(); | |
435 } | |
436 | |
437 void StopExcludingCpuThreadTime() { | |
438 rtc::CritScope lock(&cpu_measurement_lock_); | |
439 cpu_time_ -= rtc::GetThreadCpuTimeNanos(); | |
440 } | |
441 | |
442 double GetCpuUsage() { | |
sprang_webrtc
2017/02/22 16:44:03
nit: GetCpuUsagePercent()
ilnik
2017/02/23 09:00:59
Done.
| |
443 rtc::CritScope lock(&cpu_measurement_lock_); | |
444 return static_cast<double>(cpu_time_) / wallclock_time_ * 100.0; | |
445 } | |
446 | |
412 test::LayerFilteringTransport* const transport_; | 447 test::LayerFilteringTransport* const transport_; |
413 PacketReceiver* receiver_; | 448 PacketReceiver* receiver_; |
414 | 449 |
415 private: | 450 private: |
416 struct FrameComparison { | 451 struct FrameComparison { |
417 FrameComparison() | 452 FrameComparison() |
418 : dropped(false), | 453 : dropped(false), |
419 input_time_ms(0), | 454 input_time_ms(0), |
420 send_time_ms(0), | 455 send_time_ms(0), |
421 recv_time_ms(0), | 456 recv_time_ms(0), |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
602 // Wait until new comparison task is available, or test is done. | 637 // Wait until new comparison task is available, or test is done. |
603 // If done, wake up remaining threads waiting. | 638 // If done, wake up remaining threads waiting. |
604 comparison_available_event_.Wait(1000); | 639 comparison_available_event_.Wait(1000); |
605 if (AllFramesRecorded()) { | 640 if (AllFramesRecorded()) { |
606 comparison_available_event_.Set(); | 641 comparison_available_event_.Set(); |
607 return false; | 642 return false; |
608 } | 643 } |
609 return true; // Try again. | 644 return true; // Try again. |
610 } | 645 } |
611 | 646 |
647 StartExcludingCpuThreadTime(); | |
648 | |
612 PerformFrameComparison(comparison); | 649 PerformFrameComparison(comparison); |
613 | 650 |
651 StopExcludingCpuThreadTime(); | |
652 | |
614 if (FrameProcessed()) { | 653 if (FrameProcessed()) { |
615 PrintResults(); | 654 PrintResults(); |
616 if (graph_data_output_file_) | 655 if (graph_data_output_file_) |
617 PrintSamplesToFile(); | 656 PrintSamplesToFile(); |
618 done_.Set(); | 657 done_.Set(); |
619 comparison_available_event_.Set(); | 658 comparison_available_event_.Set(); |
620 return false; | 659 return false; |
621 } | 660 } |
622 | 661 |
623 return true; | 662 return true; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
656 // Increase count of number of frames processed. Returns true if this was the | 695 // Increase count of number of frames processed. Returns true if this was the |
657 // last frame to be processed. | 696 // last frame to be processed. |
658 bool FrameProcessed() { | 697 bool FrameProcessed() { |
659 rtc::CritScope crit(&comparison_lock_); | 698 rtc::CritScope crit(&comparison_lock_); |
660 ++frames_processed_; | 699 ++frames_processed_; |
661 assert(frames_processed_ <= frames_to_process_); | 700 assert(frames_processed_ <= frames_to_process_); |
662 return frames_processed_ == frames_to_process_; | 701 return frames_processed_ == frames_to_process_; |
663 } | 702 } |
664 | 703 |
665 void PrintResults() { | 704 void PrintResults() { |
705 StopMeasuringCpuProcessTime(); | |
666 rtc::CritScope crit(&comparison_lock_); | 706 rtc::CritScope crit(&comparison_lock_); |
667 PrintResult("psnr", psnr_, " dB"); | 707 PrintResult("psnr", psnr_, " dB"); |
668 PrintResult("ssim", ssim_, " score"); | 708 PrintResult("ssim", ssim_, " score"); |
669 PrintResult("sender_time", sender_time_, " ms"); | 709 PrintResult("sender_time", sender_time_, " ms"); |
670 PrintResult("receiver_time", receiver_time_, " ms"); | 710 PrintResult("receiver_time", receiver_time_, " ms"); |
671 PrintResult("total_delay_incl_network", end_to_end_, " ms"); | 711 PrintResult("total_delay_incl_network", end_to_end_, " ms"); |
672 PrintResult("time_between_rendered_frames", rendered_delta_, " ms"); | 712 PrintResult("time_between_rendered_frames", rendered_delta_, " ms"); |
673 PrintResult("encoded_frame_size", encoded_frame_size_, " bytes"); | 713 PrintResult("encoded_frame_size", encoded_frame_size_, " bytes"); |
674 PrintResult("encode_frame_rate", encode_frame_rate_, " fps"); | 714 PrintResult("encode_frame_rate", encode_frame_rate_, " fps"); |
675 PrintResult("encode_time", encode_time_ms_, " ms"); | 715 PrintResult("encode_time", encode_time_ms_, " ms"); |
676 PrintResult("encode_usage_percent", encode_usage_percent_, " percent"); | 716 PrintResult("encode_usage_percent", encode_usage_percent_, " percent"); |
677 PrintResult("media_bitrate", media_bitrate_bps_, " bps"); | 717 PrintResult("media_bitrate", media_bitrate_bps_, " bps"); |
678 | 718 |
679 if (receive_stream_ != nullptr) { | 719 if (receive_stream_ != nullptr) { |
680 PrintResult("decode_time", decode_time_ms_, " ms"); | 720 PrintResult("decode_time", decode_time_ms_, " ms"); |
681 PrintResult("decode_time_max", decode_time_max_ms_, " ms"); | 721 PrintResult("decode_time_max", decode_time_max_ms_, " ms"); |
682 } | 722 } |
683 | 723 |
684 printf("RESULT dropped_frames: %s = %d frames\n", test_label_.c_str(), | 724 printf("RESULT dropped_frames: %s = %d frames\n", test_label_.c_str(), |
685 dropped_frames_); | 725 dropped_frames_); |
686 printf("RESULT dropped_frames_before_first_encode: %s = %d frames\n", | 726 printf("RESULT dropped_frames_before_first_encode: %s = %d frames\n", |
687 test_label_.c_str(), dropped_frames_before_first_encode_); | 727 test_label_.c_str(), dropped_frames_before_first_encode_); |
688 printf("RESULT dropped_frames_before_rendering: %s = %d frames\n", | 728 printf("RESULT dropped_frames_before_rendering: %s = %d frames\n", |
689 test_label_.c_str(), dropped_frames_before_rendering_); | 729 test_label_.c_str(), dropped_frames_before_rendering_); |
730 printf("RESULT cpu_usage: %s = %lf %%\n", test_label_.c_str(), | |
731 GetCpuUsage()); | |
690 // Disable quality check for quick test, as quality checks may fail | 732 // Disable quality check for quick test, as quality checks may fail |
691 // because too few samples were collected. | 733 // because too few samples were collected. |
692 if (!is_quick_test_enabled_) { | 734 if (!is_quick_test_enabled_) { |
693 EXPECT_GT(psnr_.Mean(), avg_psnr_threshold_); | 735 EXPECT_GT(psnr_.Mean(), avg_psnr_threshold_); |
694 EXPECT_GT(ssim_.Mean(), avg_ssim_threshold_); | 736 EXPECT_GT(ssim_.Mean(), avg_ssim_threshold_); |
695 } | 737 } |
696 } | 738 } |
697 | 739 |
698 void PerformFrameComparison(const FrameComparison& comparison) { | 740 void PerformFrameComparison(const FrameComparison& comparison) { |
699 // Perform expensive psnr and ssim calculations while not holding lock. | 741 // Perform expensive psnr and ssim calculations while not holding lock. |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
879 | 921 |
880 const int frames_to_process_; | 922 const int frames_to_process_; |
881 int frames_recorded_; | 923 int frames_recorded_; |
882 int frames_processed_; | 924 int frames_processed_; |
883 int dropped_frames_; | 925 int dropped_frames_; |
884 int dropped_frames_before_first_encode_; | 926 int dropped_frames_before_first_encode_; |
885 int dropped_frames_before_rendering_; | 927 int dropped_frames_before_rendering_; |
886 int64_t last_render_time_; | 928 int64_t last_render_time_; |
887 uint32_t rtp_timestamp_delta_; | 929 uint32_t rtp_timestamp_delta_; |
888 | 930 |
931 int64_t cpu_time_ GUARDED_BY(cpu_measurement_lock_); | |
932 int64_t wallclock_time_ GUARDED_BY(cpu_measurement_lock_); | |
933 rtc::CriticalSection cpu_measurement_lock_; | |
934 | |
889 rtc::CriticalSection crit_; | 935 rtc::CriticalSection crit_; |
890 std::deque<VideoFrame> frames_ GUARDED_BY(crit_); | 936 std::deque<VideoFrame> frames_ GUARDED_BY(crit_); |
891 rtc::Optional<VideoFrame> last_rendered_frame_ GUARDED_BY(crit_); | 937 rtc::Optional<VideoFrame> last_rendered_frame_ GUARDED_BY(crit_); |
892 rtc::TimestampWrapAroundHandler wrap_handler_ GUARDED_BY(crit_); | 938 rtc::TimestampWrapAroundHandler wrap_handler_ GUARDED_BY(crit_); |
893 std::map<int64_t, int64_t> send_times_ GUARDED_BY(crit_); | 939 std::map<int64_t, int64_t> send_times_ GUARDED_BY(crit_); |
894 std::map<int64_t, int64_t> recv_times_ GUARDED_BY(crit_); | 940 std::map<int64_t, int64_t> recv_times_ GUARDED_BY(crit_); |
895 std::map<int64_t, size_t> encoded_frame_sizes_ GUARDED_BY(crit_); | 941 std::map<int64_t, size_t> encoded_frame_sizes_ GUARDED_BY(crit_); |
896 rtc::Optional<uint32_t> first_encoded_timestamp_ GUARDED_BY(crit_); | 942 rtc::Optional<uint32_t> first_encoded_timestamp_ GUARDED_BY(crit_); |
897 rtc::Optional<uint32_t> first_sent_timestamp_ GUARDED_BY(crit_); | 943 rtc::Optional<uint32_t> first_sent_timestamp_ GUARDED_BY(crit_); |
898 const double avg_psnr_threshold_; | 944 const double avg_psnr_threshold_; |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1378 if (video_receive_streams_.size() == 1) | 1424 if (video_receive_streams_.size() == 1) |
1379 analyzer.SetReceiveStream(video_receive_streams_[0]); | 1425 analyzer.SetReceiveStream(video_receive_streams_[0]); |
1380 | 1426 |
1381 video_send_stream_->SetSource(analyzer.OutputInterface(), | 1427 video_send_stream_->SetSource(analyzer.OutputInterface(), |
1382 degradation_preference_); | 1428 degradation_preference_); |
1383 | 1429 |
1384 CreateCapturer(); | 1430 CreateCapturer(); |
1385 rtc::VideoSinkWants wants; | 1431 rtc::VideoSinkWants wants; |
1386 video_capturer_->AddOrUpdateSink(analyzer.InputInterface(), wants); | 1432 video_capturer_->AddOrUpdateSink(analyzer.InputInterface(), wants); |
1387 | 1433 |
1434 analyzer.StartMeasuringCpuProcessTime(); | |
sprang_webrtc
2017/02/22 16:44:03
I think you can move this down even further. Defin
ilnik
2017/02/23 09:00:59
Done.
| |
1435 | |
1388 StartEncodedFrameLogs(video_send_stream_); | 1436 StartEncodedFrameLogs(video_send_stream_); |
1389 StartEncodedFrameLogs(video_receive_streams_[0]); | 1437 StartEncodedFrameLogs(video_receive_streams_[0]); |
1390 video_send_stream_->Start(); | 1438 video_send_stream_->Start(); |
1391 for (VideoReceiveStream* receive_stream : video_receive_streams_) | 1439 for (VideoReceiveStream* receive_stream : video_receive_streams_) |
1392 receive_stream->Start(); | 1440 receive_stream->Start(); |
1393 for (FlexfecReceiveStream* receive_stream : flexfec_receive_streams_) | 1441 for (FlexfecReceiveStream* receive_stream : flexfec_receive_streams_) |
1394 receive_stream->Start(); | 1442 receive_stream->Start(); |
1395 video_capturer_->Start(); | 1443 video_capturer_->Start(); |
1396 | 1444 |
1397 analyzer.Wait(); | 1445 analyzer.Wait(); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1604 std::ostringstream str; | 1652 std::ostringstream str; |
1605 str << receive_logs_++; | 1653 str << receive_logs_++; |
1606 std::string path = | 1654 std::string path = |
1607 params_.video.encoded_frame_base_path + "." + str.str() + ".recv.ivf"; | 1655 params_.video.encoded_frame_base_path + "." + str.str() + ".recv.ivf"; |
1608 stream->EnableEncodedFrameRecording(rtc::CreatePlatformFile(path), | 1656 stream->EnableEncodedFrameRecording(rtc::CreatePlatformFile(path), |
1609 10000000); | 1657 10000000); |
1610 } | 1658 } |
1611 } | 1659 } |
1612 | 1660 |
1613 } // namespace webrtc | 1661 } // namespace webrtc |
OLD | NEW |