blob: 43663d6e87a6516c2afaec2877924dd716f941b0 [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
mikhal@webrtc.org552f1732011-08-26 17:38:09 +000011#ifndef WEBRTC_MODULES_VIDEO_CODING_TEST_VIDEO_METRICS_H_
12#define WEBRTC_MODULES_VIDEO_CODING_TEST_VIDEO_METRICS_H_
13
kjellander@webrtc.orgf0a84642011-09-12 13:45:39 +000014#include <limits>
15#include <vector>
16
kjellander@webrtc.org82d91ae2011-12-05 13:03:38 +000017#include "typedefs.h"
kjellander@webrtc.orgf0a84642011-09-12 13:45:39 +000018
19// Contains video quality metrics result for a single frame.
20struct FrameResult {
21 WebRtc_Word32 frame_number;
22 double value;
23};
24
25// Result from a PSNR/SSIM calculation operation.
26// The frames in this data structure are 0-indexed.
27struct QualityMetricsResult {
28 QualityMetricsResult() :
29 average(0.0),
30 min(std::numeric_limits<double>::max()),
31 max(std::numeric_limits<double>::min()),
32 min_frame_number(-1),
33 max_frame_number(-1)
34 {};
35 double average;
36 double min;
37 double max;
38 WebRtc_Word32 min_frame_number;
39 WebRtc_Word32 max_frame_number;
40 std::vector<FrameResult> frames;
41};
mikhal@webrtc.org552f1732011-08-26 17:38:09 +000042
43// PSNR & SSIM calculations
phoglund@webrtc.org1144ba22011-11-11 09:01:03 +000044
45// PSNR values are filled into the QualityMetricsResult struct.
46// If the result is std::numerical_limits<double>::max() the videos were
47// equal. Otherwise, PSNR values are in decibel (higher is better). This
48// algorithm only compares up to the point when the shortest video ends.
kjellander@webrtc.org82d91ae2011-12-05 13:03:38 +000049// By definition of PSNR, the result value is undefined if the reference file
50// and the test file are identical. In that case the max value for double
51// will be set in the result struct.
52//
53// Returns 0 if successful, negative on errors:
54// -1 if the source file cannot be opened
55// -2 if the test file cannot be opened
56// -3 if any of the files are empty
57int PsnrFromFiles(const WebRtc_Word8 *refFileName,
58 const WebRtc_Word8 *testFileName, WebRtc_Word32 width,
59 WebRtc_Word32 height, QualityMetricsResult *result);
phoglund@webrtc.org1144ba22011-11-11 09:01:03 +000060
61// SSIM values are filled into the QualityMetricsResult struct.
62// Values range between -1 and 1, where 1 means the files were identical. This
63// algorithm only compares up to the point when the shortest video ends.
kjellander@webrtc.org82d91ae2011-12-05 13:03:38 +000064// By definition, SSIM values varies from -1.0, when everything is different
65// between the reference file and the test file, up to 1.0 for two identical
66// files.
67//
68// Returns 0 if successful, negative on errors:
69// -1 if the source file cannot be opened
70// -2 if the test file cannot be opened
71// -3 if any of the files are empty
72int SsimFromFiles(const WebRtc_Word8 *refFileName,
73 const WebRtc_Word8 *testFileName, WebRtc_Word32 width,
74 WebRtc_Word32 height, QualityMetricsResult *result);
mikhal@webrtc.org552f1732011-08-26 17:38:09 +000075
kjellander@webrtc.org82d91ae2011-12-05 13:03:38 +000076double SsimFrame(WebRtc_UWord8 *img1, WebRtc_UWord8 *img2,
77 WebRtc_Word32 stride_img1, WebRtc_Word32 stride_img2,
78 WebRtc_Word32 width, WebRtc_Word32 height);
mikhal@webrtc.org552f1732011-08-26 17:38:09 +000079
80#endif // WEBRTC_MODULES_VIDEO_CODING_TEST_VIDEO_METRICS_H_