1 /* 2 * Copyright (c) 2011 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 WEBRTC_TESTSUPPORT_METRICS_VIDEO_METRICS_H_ 12 #define WEBRTC_TESTSUPPORT_METRICS_VIDEO_METRICS_H_ 13 14 #include <limits> 15 #include <vector> 16 17 namespace webrtc { 18 namespace test { 19 20 // Contains video quality metrics result for a single frame. 21 struct FrameResult { 22 int frame_number; 23 double value; 24 }; 25 26 // Result from a PSNR/SSIM calculation operation. 27 // The frames in this data structure are 0-indexed. 28 struct QualityMetricsResult { 29 QualityMetricsResult() : 30 average(0.0), 31 min(std::numeric_limits<double>::max()), 32 max(std::numeric_limits<double>::min()), 33 min_frame_number(-1), 34 max_frame_number(-1) 35 {}; 36 double average; 37 double min; 38 double max; 39 int min_frame_number; 40 int max_frame_number; 41 std::vector<FrameResult> frames; 42 }; 43 44 // Calculates PSNR and SSIM values for the reference and test video files 45 // (must be in I420 format). All calculated values are filled into the 46 // QualityMetricsResult stucts. 47 // PSNR values have the unit decibel (dB) where a high value means the test file 48 // is similar to the reference file. The higher value, the more similar. 49 // For more info about PSNR, see http://en.wikipedia.org/wiki/PSNR 50 // SSIM values range between -1.0 and 1.0, where 1.0 means the files are 51 // identical. For more info about SSIM, see http://en.wikipedia.org/wiki/SSIM 52 // This function only compares video frames up to the point when the shortest 53 // video ends. 54 // Return value: 55 // 0 if successful, negative on errors: 56 // -1 if the source file cannot be opened 57 // -2 if the test file cannot be opened 58 // -3 if any of the files are empty 59 // -4 if any arguments are invalid. 60 int I420MetricsFromFiles(const char* ref_filename, 61 const char* test_filename, 62 int width, 63 int height, 64 QualityMetricsResult* psnr_result, 65 QualityMetricsResult* ssim_result); 66 67 // Calculates PSNR values for the reference and test video files (must be in 68 // I420 format). All calculated values are filled into the QualityMetricsResult 69 // struct. 70 // PSNR values have the unit decibel (dB) where a high value means the test file 71 // is similar to the reference file. The higher value, the more similar. 72 // This function only compares video frames up to the point when the shortest 73 // video ends. 74 // For more info about PSNR, see http://en.wikipedia.org/wiki/PSNR 75 // 76 // Return value: 77 // 0 if successful, negative on errors: 78 // -1 if the source file cannot be opened 79 // -2 if the test file cannot be opened 80 // -3 if any of the files are empty 81 // -4 if any arguments are invalid. 82 int I420PSNRFromFiles(const char* ref_filename, 83 const char* test_filename, 84 int width, 85 int height, 86 QualityMetricsResult* result); 87 88 // Calculates SSIM values for the reference and test video files (must be in 89 // I420 format). All calculated values are filled into the QualityMetricsResult 90 // struct. 91 // SSIM values range between -1.0 and 1.0, where 1.0 means the files are 92 // identical. 93 // This function only compares video frames up to the point when the shortest 94 // video ends. 95 // For more info about SSIM, see http://en.wikipedia.org/wiki/SSIM 96 // 97 // Return value: 98 // 0 if successful, negative on errors: 99 // -1 if the source file cannot be opened 100 // -2 if the test file cannot be opened 101 // -3 if any of the files are empty 102 // -4 if any arguments are invalid. 103 int I420SSIMFromFiles(const char* ref_filename, 104 const char* test_filename, 105 int width, 106 int height, 107 QualityMetricsResult* result); 108 109 } // namespace test 110 } // namespace webrtc 111 112 #endif // WEBRTC_TESTSUPPORT_METRICS_VIDEO_METRICS_H_ 113