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