blob: df11a49db2dd0c7b80449d30adbb73c01ee843fa [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
20// Contains video quality metrics result for a single frame.
21struct FrameResult {
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +000022 int frame_number;
kjellander@webrtc.orgf0a84642011-09-12 13:45:39 +000023 double value;
24};
25
26// Result from a PSNR/SSIM calculation operation.
27// The frames in this data structure are 0-indexed.
28struct 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;
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +000039 int min_frame_number;
40 int max_frame_number;
kjellander@webrtc.orgf0a84642011-09-12 13:45:39 +000041 std::vector<FrameResult> frames;
42};
mikhal@webrtc.org552f1732011-08-26 17:38:09 +000043
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +000044// 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:
kjellander@webrtc.org82d91ae2011-12-05 13:03:38 +000056// -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
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +000059// -4 if any arguments are invalid.
60int I420MetricsFromFiles(const char* ref_filename,
61 const char* test_filename,
62 int width,
63 int height,
64 QualityMetricsResult* psnr_result,
65 QualityMetricsResult* ssim_result);
phoglund@webrtc.org1144ba22011-11-11 09:01:03 +000066
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +000067// 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
kjellander@webrtc.org82d91ae2011-12-05 13:03:38 +000075//
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +000076// Return value:
77// 0 if successful, negative on errors:
kjellander@webrtc.org82d91ae2011-12-05 13:03:38 +000078// -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
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +000081// -4 if any arguments are invalid.
82int I420PSNRFromFiles(const char* ref_filename,
83 const char* test_filename,
84 int width,
85 int height,
86 QualityMetricsResult* result);
mikhal@webrtc.org552f1732011-08-26 17:38:09 +000087
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +000088// 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.
103int I420SSIMFromFiles(const char* ref_filename,
104 const char* test_filename,
105 int width,
106 int height,
107 QualityMetricsResult* result);
mikhal@webrtc.org552f1732011-08-26 17:38:09 +0000108
kjellander@webrtc.orgcc337372012-01-04 08:09:32 +0000109} // namespace test
110} // namespace webrtc
111
112#endif // WEBRTC_TESTSUPPORT_METRICS_VIDEO_METRICS_H_