diff --git a/test/pc/e2e/BUILD.gn b/test/pc/e2e/BUILD.gn index 396552e88f..13d061dee3 100644 --- a/test/pc/e2e/BUILD.gn +++ b/test/pc/e2e/BUILD.gn @@ -648,6 +648,7 @@ if (!build_with_chromium) { "../../../rtc_base:rtc_numerics", "../../../rtc_base:timeutils", "../../../rtc_base/synchronization:mutex", + "../../../rtc_tools:video_quality_analysis", "../../../system_wrappers", ] } diff --git a/test/pc/e2e/analyzer/video/default_video_quality_analyzer.cc b/test/pc/e2e/analyzer/video/default_video_quality_analyzer.cc index e9d2dabe1a..66d9c276bd 100644 --- a/test/pc/e2e/analyzer/video/default_video_quality_analyzer.cc +++ b/test/pc/e2e/analyzer/video/default_video_quality_analyzer.cc @@ -22,6 +22,7 @@ #include "rtc_base/logging.h" #include "rtc_base/strings/string_builder.h" #include "rtc_base/time_utils.h" +#include "rtc_tools/frame_analyzer/video_geometry_aligner.h" namespace webrtc { namespace webrtc_pc_e2e { @@ -671,8 +672,18 @@ void DefaultVideoQualityAnalyzer::ProcessComparison( double ssim = -1.0; if (options_.heavy_metrics_computation_enabled && comparison.captured && !comparison.dropped) { - psnr = I420PSNR(&*comparison.captured, &*comparison.rendered); - ssim = I420SSIM(&*comparison.captured, &*comparison.rendered); + rtc::scoped_refptr reference_buffer = + comparison.captured->video_frame_buffer()->ToI420(); + rtc::scoped_refptr test_buffer = + comparison.rendered->video_frame_buffer()->ToI420(); + if (options_.adjust_cropping_before_comparing_frames) { + test_buffer = + ScaleVideoFrameBuffer(*test_buffer.get(), reference_buffer->width(), + reference_buffer->height()); + reference_buffer = test::AdjustCropping(reference_buffer, test_buffer); + } + psnr = I420PSNR(*reference_buffer.get(), *test_buffer.get()); + ssim = I420SSIM(*reference_buffer.get(), *test_buffer.get()); } const FrameStats& frame_stats = comparison.frame_stats; diff --git a/test/pc/e2e/analyzer/video/default_video_quality_analyzer.h b/test/pc/e2e/analyzer/video/default_video_quality_analyzer.h index ed40d095b1..db17ced72a 100644 --- a/test/pc/e2e/analyzer/video/default_video_quality_analyzer.h +++ b/test/pc/e2e/analyzer/video/default_video_quality_analyzer.h @@ -170,6 +170,14 @@ struct DefaultVideoQualityAnalyzerOptions { // Tells DefaultVideoQualityAnalyzer if heavy metrics like PSNR and SSIM have // to be computed or not. bool heavy_metrics_computation_enabled = true; + // If true DefaultVideoQualityAnalyzer will try to adjust frames before + // computing PSNR and SSIM for them. In some cases picture may be shifted by + // a few pixels after the encode/decode step. Those difference is invisible + // for a human eye, but it affects the metrics. So the adjustment is used to + // get metrics that are closer to how human persepts the video. This feature + // significantly slows down the comparison, so turn it on only when it is + // needed. + bool adjust_cropping_before_comparing_frames = false; // Amount of frames that are queued in the DefaultVideoQualityAnalyzer from // the point they were captured to the point they were rendered on all // receivers per stream.