blob: 36e62a07690c28b52ad3cb6ef26f717efac4c95f [file] [log] [blame]
mikhal@webrtc.org552f1732011-08-26 17:38:09 +00001/*
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
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +000011#ifndef WEBRTC_TESTSUPPORT_METRICS_VIDEO_METRICS_H_
12#define WEBRTC_TESTSUPPORT_METRICS_VIDEO_METRICS_H_
mikhal@webrtc.org552f1732011-08-26 17:38:09 +000013
kjellander@webrtc.orgf0a84642011-09-12 13:45:39 +000014#include <limits>
15#include <vector>
16
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +000017namespace webrtc {
18namespace test {
kjellander@webrtc.orgf0a84642011-09-12 13:45:39 +000019
phoglund@webrtc.org273ccad2012-11-29 10:08:16 +000020// The highest PSNR value our algorithms will return.
andrew@webrtc.orgd8aeb302012-12-12 20:58:32 +000021extern double kMetricsInfinitePSNR;
phoglund@webrtc.org273ccad2012-11-29 10:08:16 +000022
kjellander@webrtc.orgf0a84642011-09-12 13:45:39 +000023// Contains video quality metrics result for a single frame.
24struct FrameResult {
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +000025 int frame_number;
kjellander@webrtc.orgf0a84642011-09-12 13:45:39 +000026 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;
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +000042 int min_frame_number;
43 int max_frame_number;
kjellander@webrtc.orgf0a84642011-09-12 13:45:39 +000044 std::vector<FrameResult> frames;
45};
mikhal@webrtc.org552f1732011-08-26 17:38:09 +000046
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +000047// 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.org273ccad2012-11-29 10:08:16 +000049// QualityMetricsResult structs.
50//
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +000051// PSNR values have the unit decibel (dB) where a high value means the test file
phoglund@webrtc.org273ccad2012-11-29 10:08:16 +000052// 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//
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +000056// 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:
kjellander@webrtc.org82d91ae2011-12-05 13:03:38 +000062// -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
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +000065// -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);
phoglund@webrtc.org1144ba22011-11-11 09:01:03 +000072
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +000073// 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.org273ccad2012-11-29 10:08:16 +000076//
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +000077// PSNR values have the unit decibel (dB) where a high value means the test file
phoglund@webrtc.org273ccad2012-11-29 10:08:16 +000078// 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//
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +000082// This function only compares video frames up to the point when the shortest
83// video ends.
kjellander@webrtc.org82d91ae2011-12-05 13:03:38 +000084//
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +000085// Return value:
86// 0 if successful, negative on errors:
kjellander@webrtc.org82d91ae2011-12-05 13:03:38 +000087// -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
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +000090// -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);
mikhal@webrtc.org552f1732011-08-26 17:38:09 +000096
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +000097// 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);
mikhal@webrtc.org552f1732011-08-26 17:38:09 +0000117
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +0000118} // namespace test
119} // namespace webrtc
120
121#endif // WEBRTC_TESTSUPPORT_METRICS_VIDEO_METRICS_H_