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