From 06c7095bc7dbd4d14652eeb7ab448cac337c6f1c Mon Sep 17 00:00:00 2001 From: Ilya Nikolaevskiy Date: Mon, 16 Mar 2020 13:01:25 +0100 Subject: [PATCH] Make video quality tests to always take a fixed duration It was possible before if an input fps dropped due to cpu adaptation Also, this CL removes occasional test failure (it could've happened if input framerate got very low) Bug: webrtc:11432,webrtc:11426 Change-Id: Id1a4df23302f7b8ab6781f1e7cca5112bfcfe9ea Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/170469 Reviewed-by: Artem Titov Commit-Queue: Ilya Nikolaevskiy Cr-Commit-Position: refs/heads/master@{#30802} --- video/video_analyzer.cc | 27 ++++++++++++++++----------- video/video_analyzer.h | 8 ++++++-- video/video_quality_test.cc | 3 +++ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/video/video_analyzer.cc b/video/video_analyzer.cc index e5181126ce..f4a1c96d74 100644 --- a/video/video_analyzer.cc +++ b/video/video_analyzer.cc @@ -57,6 +57,7 @@ VideoAnalyzer::VideoAnalyzer(test::LayerFilteringTransport* transport, double avg_psnr_threshold, double avg_ssim_threshold, int duration_frames, + TimeDelta test_duration, FILE* graph_data_output_file, const std::string& graph_title, uint32_t ssrc_to_analyze, @@ -74,7 +75,7 @@ VideoAnalyzer::VideoAnalyzer(test::LayerFilteringTransport* transport, send_stream_(nullptr), receive_stream_(nullptr), audio_receive_stream_(nullptr), - captured_frame_forwarder_(this, clock, duration_frames), + captured_frame_forwarder_(this, clock, duration_frames, test_duration), test_label_(test_label), graph_data_output_file_(graph_data_output_file), graph_title_(graph_title), @@ -92,6 +93,7 @@ VideoAnalyzer::VideoAnalyzer(test::LayerFilteringTransport* transport, render_frame_rate_(0), last_fec_bytes_(0), frames_to_process_(duration_frames), + test_end_(clock->CurrentTime() + test_duration), frames_recorded_(0), frames_processed_(0), captured_frames_(0), @@ -379,11 +381,8 @@ void VideoAnalyzer::Wait() { continue; } if (frames_processed == last_frames_processed && - last_frames_captured == frames_captured) { - if (frames_captured < frames_to_process_) { - EXPECT_GT(frames_processed, last_frames_processed) - << "Analyzer stalled while waiting for test to finish."; - } + last_frames_captured == frames_captured && + clock_->CurrentTime() > test_end_) { done_.Set(); break; } @@ -589,14 +588,16 @@ void VideoAnalyzer::FrameRecorded() { bool VideoAnalyzer::AllFramesRecorded() { rtc::CritScope crit(&comparison_lock_); RTC_DCHECK(frames_recorded_ <= frames_to_process_); - return frames_recorded_ == frames_to_process_ || quit_; + return frames_recorded_ == frames_to_process_ || + (clock_->CurrentTime() > test_end_ && comparisons_.empty()) || quit_; } bool VideoAnalyzer::FrameProcessed() { rtc::CritScope crit(&comparison_lock_); ++frames_processed_; assert(frames_processed_ <= frames_to_process_); - return frames_processed_ == frames_to_process_; + return frames_processed_ == frames_to_process_ || + (clock_->CurrentTime() > test_end_ && comparisons_.empty()); } void VideoAnalyzer::PrintResults() { @@ -973,13 +974,15 @@ VideoAnalyzer::Sample::Sample(int dropped, VideoAnalyzer::CapturedFrameForwarder::CapturedFrameForwarder( VideoAnalyzer* analyzer, Clock* clock, - int frames_to_process) + int frames_to_capture, + TimeDelta test_duration) : analyzer_(analyzer), send_stream_input_(nullptr), video_source_(nullptr), clock_(clock), captured_frames_(0), - frames_to_process_(frames_to_process) {} + frames_to_capture_(frames_to_capture), + test_end_(clock->CurrentTime() + test_duration) {} void VideoAnalyzer::CapturedFrameForwarder::SetSource( VideoSourceInterface* video_source) { @@ -998,8 +1001,10 @@ void VideoAnalyzer::CapturedFrameForwarder::OnFrame( analyzer_->AddCapturedFrameForComparison(copy); rtc::CritScope lock(&crit_); ++captured_frames_; - if (send_stream_input_ && captured_frames_ <= frames_to_process_) + if (send_stream_input_ && clock_->CurrentTime() <= test_end_ && + captured_frames_ <= frames_to_capture_) { send_stream_input_->OnFrame(copy); + } } void VideoAnalyzer::CapturedFrameForwarder::AddOrUpdateSink( diff --git a/video/video_analyzer.h b/video/video_analyzer.h index 7d60e7c8fa..14f77ac53c 100644 --- a/video/video_analyzer.h +++ b/video/video_analyzer.h @@ -41,6 +41,7 @@ class VideoAnalyzer : public PacketReceiver, double avg_psnr_threshold, double avg_ssim_threshold, int duration_frames, + TimeDelta test_duration, FILE* graph_data_output_file, const std::string& graph_title, uint32_t ssrc_to_analyze, @@ -147,7 +148,8 @@ class VideoAnalyzer : public PacketReceiver, public: CapturedFrameForwarder(VideoAnalyzer* analyzer, Clock* clock, - int frames_to_process); + int frames_to_capture, + TimeDelta test_duration); void SetSource(rtc::VideoSourceInterface* video_source); private: @@ -167,7 +169,8 @@ class VideoAnalyzer : public PacketReceiver, VideoSourceInterface* video_source_; Clock* clock_; int captured_frames_ RTC_GUARDED_BY(crit_); - const int frames_to_process_; + const int frames_to_capture_; + const Timestamp test_end_; }; struct FrameWithPsnr { @@ -263,6 +266,7 @@ class VideoAnalyzer : public PacketReceiver, rtc::CriticalSection crit_; const int frames_to_process_; + const Timestamp test_end_; int frames_recorded_ RTC_GUARDED_BY(comparison_lock_); int frames_processed_ RTC_GUARDED_BY(comparison_lock_); int captured_frames_ RTC_GUARDED_BY(comparison_lock_); diff --git a/video/video_quality_test.cc b/video/video_quality_test.cc index 826567c21f..42d502a688 100644 --- a/video/video_quality_test.cc +++ b/video/video_quality_test.cc @@ -1287,6 +1287,9 @@ void VideoQualityTest::RunWithAnalyzer(const Params& params) { is_quick_test_enabled ? kFramesSentInQuickTest : params_.analyzer.test_durations_secs * params_.video[0].fps, + is_quick_test_enabled + ? TimeDelta::Millis(1) + : TimeDelta::Seconds(params_.analyzer.test_durations_secs), graph_data_output_file, graph_title, kVideoSendSsrcs[params_.ss[0].selected_stream], kSendRtxSsrcs[params_.ss[0].selected_stream],