blob: 81e0111e503a86d42203f1ce30899d4eb441ad72 [file] [log] [blame]
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +00001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef RTC_TOOLS_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_
12#define RTC_TOOLS_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000013
14#include <string>
mandermo7cebe782017-02-16 01:36:43 -080015#include <utility>
Yves Gerey665174f2018-06-19 15:03:05 +020016#include <vector>
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000017
Magnus Jedvert404be7f2018-08-22 19:23:34 +020018#include "api/video/i420_buffer.h"
19#include "rtc_tools/y4m_file_reader.h"
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000020
21namespace webrtc {
22namespace test {
23
24struct AnalysisResult {
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000025 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.orgfd800702012-08-16 14:07:02 +000030 int frame_number;
31 double psnr_value;
32 double ssim_value;
33};
34
35struct ResultsContainer {
Henrik Kjellander67bcb602015-10-07 08:42:52 +020036 ResultsContainer();
37 ~ResultsContainer();
38
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000039 std::vector<AnalysisResult> frames;
Edward Lemur2e5966b2018-01-30 15:33:02 +010040 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.orgfd800702012-08-16 14:07:02 +000045};
46
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000047// 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 Jedvert9bb55fc2018-08-24 14:56:03 +020050// position in the original video. We also need to provide a map from test frame
51// indices to reference frame indices.
52std::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.orgfd800702012-08-16 14:07:02 +000056
Magnus Jedvert404be7f2018-08-22 19:23:34 +020057// 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.
59double 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.
64double Ssim(const rtc::scoped_refptr<I420BufferInterface>& ref_buffer,
65 const rtc::scoped_refptr<I420BufferInterface>& test_buffer);
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000066
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000067// 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.
70void PrintAnalysisResults(const std::string& label, ResultsContainer* results);
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000071
kjellander@webrtc.orge2df8b72013-11-03 18:34:51 +000072// Similar to the above, but will print to the specified file handle.
Yves Gerey665174f2018-06-19 15:03:05 +020073void PrintAnalysisResults(FILE* output,
74 const std::string& label,
kjellander@webrtc.orge2df8b72013-11-03 18:34:51 +000075 ResultsContainer* results);
76
Magnus Jedvert9bb55fc2018-08-24 14:56:03 +020077struct 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};
mandermo7cebe782017-02-16 01:36:43 -080084
Magnus Jedvert9bb55fc2018-08-24 14:56:03 +020085// Clusters sequentially repeated frames. For example, the sequence {100, 102,
86// 102, 103} will be mapped to {{100, 1}, {102, 2}, {103, 1}}.
87std::vector<Cluster> CalculateFrameClusters(const std::vector<size_t>& indices);
mandermo7cebe782017-02-16 01:36:43 -080088
Magnus Jedvert9bb55fc2018-08-24 14:56:03 +020089// 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.
91int GetMaxRepeatedFrames(const std::vector<Cluster>& clusters);
kjellander@webrtc.orge2df8b72013-11-03 18:34:51 +000092
Magnus Jedvert9bb55fc2018-08-24 14:56:03 +020093// Get the longest sequence of skipped reference frames. This corresponds to the
94// longest freeze in the test video.
95int GetMaxSkippedFrames(const std::vector<Cluster>& clusters);
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000096
Magnus Jedvert9bb55fc2018-08-24 14:56:03 +020097// Get total number of skipped frames in the test video.
98int GetTotalNumberOfSkippedFrames(const std::vector<Cluster>& clusters);
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000099
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +0000100} // namespace test
101} // namespace webrtc
102
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200103#endif // RTC_TOOLS_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_