mikhal@webrtc.org | 552f173 | 2011-08-26 17:38:09 +0000 | [diff] [blame] | 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 | |
mikhal@webrtc.org | 552f173 | 2011-08-26 17:38:09 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_MODULES_VIDEO_CODING_TEST_VIDEO_METRICS_H_ |
| 12 | #define WEBRTC_MODULES_VIDEO_CODING_TEST_VIDEO_METRICS_H_ |
| 13 | |
kjellander@webrtc.org | f0a8464 | 2011-09-12 13:45:39 +0000 | [diff] [blame] | 14 | #include <limits> |
| 15 | #include <vector> |
| 16 | |
kjellander@webrtc.org | 82d91ae | 2011-12-05 13:03:38 +0000 | [diff] [blame^] | 17 | #include "typedefs.h" |
kjellander@webrtc.org | f0a8464 | 2011-09-12 13:45:39 +0000 | [diff] [blame] | 18 | |
| 19 | // Contains video quality metrics result for a single frame. |
| 20 | struct 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. |
| 27 | struct 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.org | 552f173 | 2011-08-26 17:38:09 +0000 | [diff] [blame] | 42 | |
| 43 | // PSNR & SSIM calculations |
phoglund@webrtc.org | 1144ba2 | 2011-11-11 09:01:03 +0000 | [diff] [blame] | 44 | |
| 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.org | 82d91ae | 2011-12-05 13:03:38 +0000 | [diff] [blame^] | 49 | // 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 |
| 57 | int PsnrFromFiles(const WebRtc_Word8 *refFileName, |
| 58 | const WebRtc_Word8 *testFileName, WebRtc_Word32 width, |
| 59 | WebRtc_Word32 height, QualityMetricsResult *result); |
phoglund@webrtc.org | 1144ba2 | 2011-11-11 09:01:03 +0000 | [diff] [blame] | 60 | |
| 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.org | 82d91ae | 2011-12-05 13:03:38 +0000 | [diff] [blame^] | 64 | // 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 |
| 72 | int SsimFromFiles(const WebRtc_Word8 *refFileName, |
| 73 | const WebRtc_Word8 *testFileName, WebRtc_Word32 width, |
| 74 | WebRtc_Word32 height, QualityMetricsResult *result); |
mikhal@webrtc.org | 552f173 | 2011-08-26 17:38:09 +0000 | [diff] [blame] | 75 | |
kjellander@webrtc.org | 82d91ae | 2011-12-05 13:03:38 +0000 | [diff] [blame^] | 76 | double 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.org | 552f173 | 2011-08-26 17:38:09 +0000 | [diff] [blame] | 79 | |
| 80 | #endif // WEBRTC_MODULES_VIDEO_CODING_TEST_VIDEO_METRICS_H_ |