/* * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ #include "rtc_tools/frame_analyzer/video_quality_analysis.h" #include #include #include "rtc_base/logging.h" #include "rtc_base/strings/string_builder.h" #include "rtc_tools/frame_analyzer/video_color_aligner.h" #include "rtc_tools/frame_analyzer/video_temporal_aligner.h" #include "test/testsupport/perf_test.h" #include "third_party/libyuv/include/libyuv/compare.h" #include "third_party/libyuv/include/libyuv/convert.h" namespace webrtc { namespace test { ResultsContainer::ResultsContainer() {} ResultsContainer::~ResultsContainer() {} template static double CalculateMetric( const FrameMetricFunction& frame_metric_function, const rtc::scoped_refptr& ref_buffer, const rtc::scoped_refptr& test_buffer) { RTC_CHECK_EQ(ref_buffer->width(), test_buffer->width()); RTC_CHECK_EQ(ref_buffer->height(), test_buffer->height()); return frame_metric_function( ref_buffer->DataY(), ref_buffer->StrideY(), ref_buffer->DataU(), ref_buffer->StrideU(), ref_buffer->DataV(), ref_buffer->StrideV(), test_buffer->DataY(), test_buffer->StrideY(), test_buffer->DataU(), test_buffer->StrideU(), test_buffer->DataV(), test_buffer->StrideV(), test_buffer->width(), test_buffer->height()); } double Psnr(const rtc::scoped_refptr& ref_buffer, const rtc::scoped_refptr& test_buffer) { // LibYuv sets the max psnr value to 128, we restrict it to 48. // In case of 0 mse in one frame, 128 can skew the results significantly. return std::min(48.0, CalculateMetric(&libyuv::I420Psnr, ref_buffer, test_buffer)); } double Ssim(const rtc::scoped_refptr& ref_buffer, const rtc::scoped_refptr& test_buffer) { return CalculateMetric(&libyuv::I420Ssim, ref_buffer, test_buffer); } std::vector RunAnalysis( const rtc::scoped_refptr& reference_video, const rtc::scoped_refptr& test_video, const std::vector& test_frame_indices) { const rtc::scoped_refptr