blob: c5f3cb694316223727c8426370097ef66181619b [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>
Jonas Olssona4d87372019-07-05 19:08:33 +020015
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000016#include <string>
Yves Gerey665174f2018-06-19 15:03:05 +020017#include <vector>
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000018
Mirko Bonadeid9708072019-01-25 20:26:48 +010019#include "api/scoped_refptr.h"
Yves Gerey3e707812018-11-28 16:47:49 +010020#include "api/video/video_frame_buffer.h"
Magnus Jedvert10e829a2018-09-05 10:46:18 +020021#include "rtc_tools/video_file_reader.h"
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000022
23namespace webrtc {
24namespace test {
25
26struct AnalysisResult {
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000027 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.orgfd800702012-08-16 14:07:02 +000032 int frame_number;
33 double psnr_value;
34 double ssim_value;
35};
36
37struct ResultsContainer {
Henrik Kjellander67bcb602015-10-07 08:42:52 +020038 ResultsContainer();
39 ~ResultsContainer();
40
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000041 std::vector<AnalysisResult> frames;
Yves Gerey9931ddb2018-09-21 16:19:17 +020042 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.orgfd800702012-08-16 14:07:02 +000047};
48
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000049// 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 Jedvertb468ace2018-09-05 16:11:48 +020052// position in the original video. We also need to provide a map from test frame
53// indices to reference frame indices.
54std::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.orgfd800702012-08-16 14:07:02 +000058
Magnus Jedvert10e829a2018-09-05 10:46:18 +020059// 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.
61double 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.
66double Ssim(const rtc::scoped_refptr<I420BufferInterface>& ref_buffer,
67 const rtc::scoped_refptr<I420BufferInterface>& test_buffer);
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000068
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000069// 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.
72void PrintAnalysisResults(const std::string& label, ResultsContainer* results);
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000073
kjellander@webrtc.orge2df8b72013-11-03 18:34:51 +000074// Similar to the above, but will print to the specified file handle.
Yves Gerey665174f2018-06-19 15:03:05 +020075void PrintAnalysisResults(FILE* output,
76 const std::string& label,
kjellander@webrtc.orge2df8b72013-11-03 18:34:51 +000077 ResultsContainer* results);
78
Magnus Jedvertb468ace2018-09-05 16:11:48 +020079struct 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};
mandermo7cebe782017-02-16 01:36:43 -080086
Magnus Jedvertb468ace2018-09-05 16:11:48 +020087// Clusters sequentially repeated frames. For example, the sequence {100, 102,
88// 102, 103} will be mapped to {{100, 1}, {102, 2}, {103, 1}}.
89std::vector<Cluster> CalculateFrameClusters(const std::vector<size_t>& indices);
mandermo7cebe782017-02-16 01:36:43 -080090
Magnus Jedvertb468ace2018-09-05 16:11:48 +020091// 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.
93int GetMaxRepeatedFrames(const std::vector<Cluster>& clusters);
kjellander@webrtc.orge2df8b72013-11-03 18:34:51 +000094
Magnus Jedvertb468ace2018-09-05 16:11:48 +020095// Get the longest sequence of skipped reference frames. This corresponds to the
96// longest freeze in the test video.
97int GetMaxSkippedFrames(const std::vector<Cluster>& clusters);
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000098
Magnus Jedvertb468ace2018-09-05 16:11:48 +020099// Get total number of skipped frames in the test video.
100int GetTotalNumberOfSkippedFrames(const std::vector<Cluster>& clusters);
Sami Kalliomäki0673bc92018-08-27 17:58:13 +0200101
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +0000102} // namespace test
103} // namespace webrtc
104
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200105#endif // RTC_TOOLS_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_