vspasova@webrtc.org | fd80070 | 2012-08-16 14:07:02 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef RTC_TOOLS_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_ |
| 12 | #define RTC_TOOLS_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_ |
vspasova@webrtc.org | fd80070 | 2012-08-16 14:07:02 +0000 | [diff] [blame] | 13 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 14 | #include <stdio.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 15 | |
vspasova@webrtc.org | fd80070 | 2012-08-16 14:07:02 +0000 | [diff] [blame] | 16 | #include <string> |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 17 | #include <vector> |
vspasova@webrtc.org | fd80070 | 2012-08-16 14:07:02 +0000 | [diff] [blame] | 18 | |
Mirko Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 19 | #include "api/scoped_refptr.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 20 | #include "api/video/video_frame_buffer.h" |
Magnus Jedvert | 10e829a | 2018-09-05 10:46:18 +0200 | [diff] [blame] | 21 | #include "rtc_tools/video_file_reader.h" |
vspasova@webrtc.org | fd80070 | 2012-08-16 14:07:02 +0000 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
| 24 | namespace test { |
| 25 | |
| 26 | struct AnalysisResult { |
kjellander@webrtc.org | f880f86 | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 27 | AnalysisResult() {} |
| 28 | AnalysisResult(int frame_number, double psnr_value, double ssim_value) |
| 29 | : frame_number(frame_number), |
| 30 | psnr_value(psnr_value), |
| 31 | ssim_value(ssim_value) {} |
vspasova@webrtc.org | fd80070 | 2012-08-16 14:07:02 +0000 | [diff] [blame] | 32 | int frame_number; |
| 33 | double psnr_value; |
| 34 | double ssim_value; |
| 35 | }; |
| 36 | |
| 37 | struct ResultsContainer { |
Henrik Kjellander | 67bcb60 | 2015-10-07 08:42:52 +0200 | [diff] [blame] | 38 | ResultsContainer(); |
| 39 | ~ResultsContainer(); |
| 40 | |
vspasova@webrtc.org | fd80070 | 2012-08-16 14:07:02 +0000 | [diff] [blame] | 41 | std::vector<AnalysisResult> frames; |
Yves Gerey | 9931ddb | 2018-09-21 16:19:17 +0200 | [diff] [blame] | 42 | int max_repeated_frames = 0; |
| 43 | int max_skipped_frames = 0; |
| 44 | int total_skipped_frames = 0; |
| 45 | int decode_errors_ref = 0; |
| 46 | int decode_errors_test = 0; |
vspasova@webrtc.org | fd80070 | 2012-08-16 14:07:02 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
vspasova@webrtc.org | fd80070 | 2012-08-16 14:07:02 +0000 | [diff] [blame] | 49 | // A function to run the PSNR and SSIM analysis on the test file. The test file |
| 50 | // comprises the frames that were captured during the quality measurement test. |
| 51 | // There may be missing or duplicate frames. Also the frames start at a random |
Magnus Jedvert | b468ace | 2018-09-05 16:11:48 +0200 | [diff] [blame] | 52 | // position in the original video. We also need to provide a map from test frame |
| 53 | // indices to reference frame indices. |
| 54 | std::vector<AnalysisResult> RunAnalysis( |
| 55 | const rtc::scoped_refptr<webrtc::test::Video>& reference_video, |
| 56 | const rtc::scoped_refptr<webrtc::test::Video>& test_video, |
| 57 | const std::vector<size_t>& test_frame_indices); |
vspasova@webrtc.org | fd80070 | 2012-08-16 14:07:02 +0000 | [diff] [blame] | 58 | |
Magnus Jedvert | 10e829a | 2018-09-05 10:46:18 +0200 | [diff] [blame] | 59 | // Compute PSNR for an I420 buffer (all planes). The max return value (in the |
| 60 | // case where the test and reference frames are exactly the same) will be 48. |
| 61 | double Psnr(const rtc::scoped_refptr<I420BufferInterface>& ref_buffer, |
| 62 | const rtc::scoped_refptr<I420BufferInterface>& test_buffer); |
| 63 | |
| 64 | // Compute SSIM for an I420 buffer (all planes). The max return value (in the |
| 65 | // case where the test and reference frames are exactly the same) will be 1. |
| 66 | double Ssim(const rtc::scoped_refptr<I420BufferInterface>& ref_buffer, |
| 67 | const rtc::scoped_refptr<I420BufferInterface>& test_buffer); |
vspasova@webrtc.org | fd80070 | 2012-08-16 14:07:02 +0000 | [diff] [blame] | 68 | |
kjellander@webrtc.org | f880f86 | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 69 | // Prints the result from the analysis in Chromium performance |
| 70 | // numbers compatible format to stdout. If the results object contains no frames |
| 71 | // no output will be written. |
| 72 | void PrintAnalysisResults(const std::string& label, ResultsContainer* results); |
vspasova@webrtc.org | fd80070 | 2012-08-16 14:07:02 +0000 | [diff] [blame] | 73 | |
kjellander@webrtc.org | e2df8b7 | 2013-11-03 18:34:51 +0000 | [diff] [blame] | 74 | // Similar to the above, but will print to the specified file handle. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 75 | void PrintAnalysisResults(FILE* output, |
| 76 | const std::string& label, |
kjellander@webrtc.org | e2df8b7 | 2013-11-03 18:34:51 +0000 | [diff] [blame] | 77 | ResultsContainer* results); |
| 78 | |
Magnus Jedvert | b468ace | 2018-09-05 16:11:48 +0200 | [diff] [blame] | 79 | struct Cluster { |
| 80 | // Corresponding reference frame index for this cluster. |
| 81 | size_t index; |
| 82 | // The number of sequential frames that mapped to the same reference frame |
| 83 | // index. |
| 84 | int number_of_repeated_frames; |
| 85 | }; |
mandermo | 7cebe78 | 2017-02-16 01:36:43 -0800 | [diff] [blame] | 86 | |
Magnus Jedvert | b468ace | 2018-09-05 16:11:48 +0200 | [diff] [blame] | 87 | // Clusters sequentially repeated frames. For example, the sequence {100, 102, |
| 88 | // 102, 103} will be mapped to {{100, 1}, {102, 2}, {103, 1}}. |
| 89 | std::vector<Cluster> CalculateFrameClusters(const std::vector<size_t>& indices); |
mandermo | 7cebe78 | 2017-02-16 01:36:43 -0800 | [diff] [blame] | 90 | |
Magnus Jedvert | b468ace | 2018-09-05 16:11:48 +0200 | [diff] [blame] | 91 | // Get number of max sequentially repeated frames in the test video. This number |
| 92 | // will be one if we only store unique frames in the test video. |
| 93 | int GetMaxRepeatedFrames(const std::vector<Cluster>& clusters); |
kjellander@webrtc.org | e2df8b7 | 2013-11-03 18:34:51 +0000 | [diff] [blame] | 94 | |
Magnus Jedvert | b468ace | 2018-09-05 16:11:48 +0200 | [diff] [blame] | 95 | // Get the longest sequence of skipped reference frames. This corresponds to the |
| 96 | // longest freeze in the test video. |
| 97 | int GetMaxSkippedFrames(const std::vector<Cluster>& clusters); |
vspasova@webrtc.org | fd80070 | 2012-08-16 14:07:02 +0000 | [diff] [blame] | 98 | |
Magnus Jedvert | b468ace | 2018-09-05 16:11:48 +0200 | [diff] [blame] | 99 | // Get total number of skipped frames in the test video. |
| 100 | int GetTotalNumberOfSkippedFrames(const std::vector<Cluster>& clusters); |
Sami Kalliomäki | 0673bc9 | 2018-08-27 17:58:13 +0200 | [diff] [blame] | 101 | |
vspasova@webrtc.org | fd80070 | 2012-08-16 14:07:02 +0000 | [diff] [blame] | 102 | } // namespace test |
| 103 | } // namespace webrtc |
| 104 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 105 | #endif // RTC_TOOLS_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_ |