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