blob: 93d360541089862a1be22ec8649aa118c5347338 [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
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000011#ifndef WEBRTC_TOOLS_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_
12#define WEBRTC_TOOLS_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000013
14#include <string>
15#include <vector>
16
kjellander@webrtc.orgd7e34e12015-01-26 19:17:26 +000017#include "libyuv/compare.h" // NOLINT
18#include "libyuv/convert.h" // NOLINT
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000019
20namespace webrtc {
21namespace test {
22
23struct AnalysisResult {
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000024 AnalysisResult() {}
25 AnalysisResult(int frame_number, double psnr_value, double ssim_value)
26 : frame_number(frame_number),
27 psnr_value(psnr_value),
28 ssim_value(ssim_value) {}
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000029 int frame_number;
30 double psnr_value;
31 double ssim_value;
32};
33
34struct ResultsContainer {
Henrik Kjellander67bcb602015-10-07 08:42:52 +020035 ResultsContainer();
36 ~ResultsContainer();
37
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000038 std::vector<AnalysisResult> frames;
39};
40
41enum VideoAnalysisMetricsType {kPSNR, kSSIM};
42
43// A function to run the PSNR and SSIM analysis on the test file. The test file
44// comprises the frames that were captured during the quality measurement test.
45// There may be missing or duplicate frames. Also the frames start at a random
46// position in the original video. We should provide a statistics file along
47// with the test video. The stats file contains the connection between the
mandermo74568172017-01-17 03:24:57 -080048// actual frames in the test file and their bar code number. There is one file
49// for the reference video and one for the test video. The stats file should
50// be in the form 'frame_xxxx yyyy', where xxxx is the consecutive
51// number of the frame in the test video, and yyyy is the barcode number.
52// The stats file could be produced by
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000053// tools/barcode_tools/barcode_decoder.py. This script decodes the barcodes
54// integrated in every video and generates the stats file. If three was some
55// problem with the decoding there would be 'Barcode error' instead of yyyy.
mandermo74568172017-01-17 03:24:57 -080056// The stat files are used to compare the right frames with each other and
57// to calculate statistics.
58void RunAnalysis(const char* reference_file_name,
59 const char* test_file_name,
60 const char* stats_file_reference_name,
61 const char* stats_file_test_name,
62 int width,
63 int height,
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000064 ResultsContainer* results);
65
66// Compute PSNR or SSIM for an I420 frame (all planes). When we are calculating
67// PSNR values, the max return value (in the case where the test and reference
68// frames are exactly the same) will be 48. In the case of SSIM the max return
69// value will be 1.
70double CalculateMetrics(VideoAnalysisMetricsType video_metrics_type,
Peter Boström0c4e06b2015-10-07 12:23:21 +020071 const uint8_t* ref_frame,
72 const uint8_t* test_frame,
73 int width,
74 int height);
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000075
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000076// Prints the result from the analysis in Chromium performance
77// numbers compatible format to stdout. If the results object contains no frames
78// no output will be written.
79void PrintAnalysisResults(const std::string& label, ResultsContainer* results);
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000080
kjellander@webrtc.orge2df8b72013-11-03 18:34:51 +000081// Similar to the above, but will print to the specified file handle.
82void PrintAnalysisResults(FILE* output, const std::string& label,
83 ResultsContainer* results);
84
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000085// Calculates max repeated and skipped frames and prints them to stdout in a
86// format that is compatible with Chromium performance numbers.
87void PrintMaxRepeatedAndSkippedFrames(const std::string& label,
mandermo74568172017-01-17 03:24:57 -080088 const std::string& stats_file_ref_name,
89 const std::string& stats_file_test_name);
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000090
kjellander@webrtc.orge2df8b72013-11-03 18:34:51 +000091// Similar to the above, but will print to the specified file handle.
mandermo74568172017-01-17 03:24:57 -080092void PrintMaxRepeatedAndSkippedFrames(FILE* output,
93 const std::string& label,
94 const std::string& stats_file_ref_name,
95 const std::string& stats_file_test_name);
kjellander@webrtc.orge2df8b72013-11-03 18:34:51 +000096
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +000097// Gets the next line from an open stats file.
98bool GetNextStatsLine(FILE* stats_file, char* line);
99
100// Calculates the size of a I420 frame if given the width and height.
vspasova@webrtc.orgac410e22012-08-27 14:57:19 +0000101int GetI420FrameSize(int width, int height);
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +0000102
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +0000103// Extract the sequence of the frame in the video. I.e. if line is
104// frame_0023 0284, we will get 23.
105int ExtractFrameSequenceNumber(std::string line);
106
107// Checks if there is 'Barcode error' for the given line.
108bool IsThereBarcodeError(std::string line);
109
110// Extract the frame number in the reference video. I.e. if line is
111// frame_0023 0284, we will get 284.
112int ExtractDecodedFrameNumber(std::string line);
113
mcasas@webrtc.org6e2d0122014-03-14 12:45:45 +0000114// Extracts an I420 frame at position frame_number from the raw YUV file.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200115bool ExtractFrameFromYuvFile(const char* i420_file_name,
116 int width,
117 int height,
118 int frame_number,
119 uint8_t* result_frame);
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +0000120
mcasas@webrtc.org6e2d0122014-03-14 12:45:45 +0000121// Extracts an I420 frame at position frame_number from the Y4M file. The first
122// frame has corresponded |frame_number| 0.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200123bool ExtractFrameFromY4mFile(const char* i420_file_name,
124 int width,
125 int height,
126 int frame_number,
127 uint8_t* result_frame);
vspasova@webrtc.orgfd800702012-08-16 14:07:02 +0000128
129} // namespace test
130} // namespace webrtc
131
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +0000132#endif // WEBRTC_TOOLS_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_