blob: 8448ccfd247562b93ba2ef226899e212a49e0945 [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:231/*
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
17namespace webrtc {
18namespace test {
19
phoglund@webrtc.org5600f6e2012-11-29 10:08:1620// The highest PSNR value our algorithms will return.
phoglund@webrtc.orgecf6f812012-12-13 10:15:0621extern double kMetricsPerfectPSNR;
phoglund@webrtc.org5600f6e2012-11-29 10:08:1622
andrew@webrtc.orgb015cbe2012-10-22 18:19:2323// Contains video quality metrics result for a single frame.
24struct 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.
31struct QualityMetricsResult {
32 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
phoglund@webrtc.org5600f6e2012-11-29 10:08:1649// QualityMetricsResult structs.
50//
andrew@webrtc.orgb015cbe2012-10-22 18:19:2351// PSNR values have the unit decibel (dB) where a high value means the test file
phoglund@webrtc.org5600f6e2012-11-29 10:08:1652// 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//
andrew@webrtc.orgb015cbe2012-10-22 18:19:2356// 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.
66int 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.
phoglund@webrtc.org5600f6e2012-11-29 10:08:1676//
andrew@webrtc.orgb015cbe2012-10-22 18:19:2377// PSNR values have the unit decibel (dB) where a high value means the test file
phoglund@webrtc.org5600f6e2012-11-29 10:08:1678// 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//
andrew@webrtc.orgb015cbe2012-10-22 18:19:2382// This function only compares video frames up to the point when the shortest
83// video ends.
andrew@webrtc.orgb015cbe2012-10-22 18:19:2384//
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.
91int 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.
112int 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_