1 /* 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef RTC_TOOLS_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_ 12 #define RTC_TOOLS_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_ 13 14 #include <stdio.h> 15 16 #include <string> 17 #include <vector> 18 19 #include "api/scoped_refptr.h" 20 #include "api/test/metrics/metrics_logger.h" 21 #include "api/video/video_frame_buffer.h" 22 #include "rtc_tools/video_file_reader.h" 23 24 namespace webrtc { 25 namespace test { 26 27 struct AnalysisResult { AnalysisResultAnalysisResult28 AnalysisResult() {} AnalysisResultAnalysisResult29 AnalysisResult(int frame_number, double psnr_value, double ssim_value) 30 : frame_number(frame_number), 31 psnr_value(psnr_value), 32 ssim_value(ssim_value) {} 33 int frame_number; 34 double psnr_value; 35 double ssim_value; 36 }; 37 38 struct ResultsContainer { 39 ResultsContainer(); 40 ~ResultsContainer(); 41 42 std::vector<AnalysisResult> frames; 43 int max_repeated_frames = 0; 44 int max_skipped_frames = 0; 45 int total_skipped_frames = 0; 46 int decode_errors_ref = 0; 47 int decode_errors_test = 0; 48 }; 49 50 // A function to run the PSNR and SSIM analysis on the test file. The test file 51 // comprises the frames that were captured during the quality measurement test. 52 // There may be missing or duplicate frames. Also the frames start at a random 53 // position in the original video. We also need to provide a map from test frame 54 // indices to reference frame indices. 55 std::vector<AnalysisResult> RunAnalysis( 56 const rtc::scoped_refptr<webrtc::test::Video>& reference_video, 57 const rtc::scoped_refptr<webrtc::test::Video>& test_video, 58 const std::vector<size_t>& test_frame_indices); 59 60 // Compute PSNR for an I420 buffer (all planes). The max return value (in the 61 // case where the test and reference frames are exactly the same) will be 48. 62 double Psnr(const rtc::scoped_refptr<I420BufferInterface>& ref_buffer, 63 const rtc::scoped_refptr<I420BufferInterface>& test_buffer); 64 65 // Compute SSIM for an I420 buffer (all planes). The max return value (in the 66 // case where the test and reference frames are exactly the same) will be 1. 67 double Ssim(const rtc::scoped_refptr<I420BufferInterface>& ref_buffer, 68 const rtc::scoped_refptr<I420BufferInterface>& test_buffer); 69 70 // Prints the result from the analysis in Chromium performance 71 // numbers compatible format to stdout. If the results object contains no frames 72 // no output will be written. 73 void PrintAnalysisResults(const std::string& label, 74 ResultsContainer& results, 75 MetricsLogger& logger); 76 77 struct Cluster { 78 // Corresponding reference frame index for this cluster. 79 size_t index; 80 // The number of sequential frames that mapped to the same reference frame 81 // index. 82 int number_of_repeated_frames; 83 }; 84 85 // Clusters sequentially repeated frames. For example, the sequence {100, 102, 86 // 102, 103} will be mapped to {{100, 1}, {102, 2}, {103, 1}}. 87 std::vector<Cluster> CalculateFrameClusters(const std::vector<size_t>& indices); 88 89 // Get number of max sequentially repeated frames in the test video. This number 90 // will be one if we only store unique frames in the test video. 91 int GetMaxRepeatedFrames(const std::vector<Cluster>& clusters); 92 93 // Get the longest sequence of skipped reference frames. This corresponds to the 94 // longest freeze in the test video. 95 int GetMaxSkippedFrames(const std::vector<Cluster>& clusters); 96 97 // Get total number of skipped frames in the test video. 98 int GetTotalNumberOfSkippedFrames(const std::vector<Cluster>& clusters); 99 100 } // namespace test 101 } // namespace webrtc 102 103 #endif // RTC_TOOLS_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_ 104