blob: ae2a19b9c4a74300cef04e6ec35ae488cdfe0800 [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
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <stdio.h>
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000015#include <string>
Yves Gerey665174f2018-06-19 15:03:05 +020016#include <vector>
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000017
Yves Gerey3e707812018-11-28 16:47:49 +010018#include "api/video/video_frame_buffer.h"
19#include "rtc_base/scoped_ref_ptr.h"
Magnus Jedvert10e829a2018-09-05 10:46:18 +020020#include "rtc_tools/video_file_reader.h"
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000021
22namespace webrtc {
23namespace test {
24
25struct AnalysisResult {
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000026 AnalysisResult() {}
27 AnalysisResult(int frame_number, double psnr_value, double ssim_value)
28 : frame_number(frame_number),
29 psnr_value(psnr_value),
30 ssim_value(ssim_value) {}
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000031 int frame_number;
32 double psnr_value;
33 double ssim_value;
34};
35
36struct ResultsContainer {
Henrik Kjellander67bcb602015-10-07 08:42:52 +020037 ResultsContainer();
38 ~ResultsContainer();
39
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000040 std::vector<AnalysisResult> frames;
Yves Gerey9931ddb2018-09-21 16:19:17 +020041 int max_repeated_frames = 0;
42 int max_skipped_frames = 0;
43 int total_skipped_frames = 0;
44 int decode_errors_ref = 0;
45 int decode_errors_test = 0;
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000046};
47
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000048// A function to run the PSNR and SSIM analysis on the test file. The test file
49// comprises the frames that were captured during the quality measurement test.
50// There may be missing or duplicate frames. Also the frames start at a random
Magnus Jedvertb468ace2018-09-05 16:11:48 +020051// position in the original video. We also need to provide a map from test frame
52// indices to reference frame indices.
53std::vector<AnalysisResult> RunAnalysis(
54 const rtc::scoped_refptr<webrtc::test::Video>& reference_video,
55 const rtc::scoped_refptr<webrtc::test::Video>& test_video,
56 const std::vector<size_t>& test_frame_indices);
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000057
Magnus Jedvert10e829a2018-09-05 10:46:18 +020058// Compute PSNR for an I420 buffer (all planes). The max return value (in the
59// case where the test and reference frames are exactly the same) will be 48.
60double Psnr(const rtc::scoped_refptr<I420BufferInterface>& ref_buffer,
61 const rtc::scoped_refptr<I420BufferInterface>& test_buffer);
62
63// Compute SSIM for an I420 buffer (all planes). The max return value (in the
64// case where the test and reference frames are exactly the same) will be 1.
65double Ssim(const rtc::scoped_refptr<I420BufferInterface>& ref_buffer,
66 const rtc::scoped_refptr<I420BufferInterface>& test_buffer);
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000067
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000068// Prints the result from the analysis in Chromium performance
69// numbers compatible format to stdout. If the results object contains no frames
70// no output will be written.
71void PrintAnalysisResults(const std::string& label, ResultsContainer* results);
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000072
kjellander@webrtc.orge2df8b72013-11-03 18:34:51 +000073// Similar to the above, but will print to the specified file handle.
Yves Gerey665174f2018-06-19 15:03:05 +020074void PrintAnalysisResults(FILE* output,
75 const std::string& label,
kjellander@webrtc.orge2df8b72013-11-03 18:34:51 +000076 ResultsContainer* results);
77
Magnus Jedvertb468ace2018-09-05 16:11:48 +020078struct Cluster {
79 // Corresponding reference frame index for this cluster.
80 size_t index;
81 // The number of sequential frames that mapped to the same reference frame
82 // index.
83 int number_of_repeated_frames;
84};
mandermo7cebe782017-02-16 01:36:43 -080085
Magnus Jedvertb468ace2018-09-05 16:11:48 +020086// Clusters sequentially repeated frames. For example, the sequence {100, 102,
87// 102, 103} will be mapped to {{100, 1}, {102, 2}, {103, 1}}.
88std::vector<Cluster> CalculateFrameClusters(const std::vector<size_t>& indices);
mandermo7cebe782017-02-16 01:36:43 -080089
Magnus Jedvertb468ace2018-09-05 16:11:48 +020090// Get number of max sequentially repeated frames in the test video. This number
91// will be one if we only store unique frames in the test video.
92int GetMaxRepeatedFrames(const std::vector<Cluster>& clusters);
kjellander@webrtc.orge2df8b72013-11-03 18:34:51 +000093
Magnus Jedvertb468ace2018-09-05 16:11:48 +020094// Get the longest sequence of skipped reference frames. This corresponds to the
95// longest freeze in the test video.
96int GetMaxSkippedFrames(const std::vector<Cluster>& clusters);
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000097
Magnus Jedvertb468ace2018-09-05 16:11:48 +020098// Get total number of skipped frames in the test video.
99int GetTotalNumberOfSkippedFrames(const std::vector<Cluster>& clusters);
Sami Kalliomäki0673bc92018-08-27 17:58:13 +0200100
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +0000101} // namespace test
102} // namespace webrtc
103
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200104#endif // RTC_TOOLS_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_