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 | |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_TOOLS_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_ |
| 12 | #define WEBRTC_TOOLS_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_ |
vspasova@webrtc.org | fd80070 | 2012-08-16 14:07:02 +0000 | [diff] [blame] | 13 | |
| 14 | #include <string> |
| 15 | #include <vector> |
| 16 | |
pbos@webrtc.org | ba7f6a8 | 2013-06-04 08:14:10 +0000 | [diff] [blame] | 17 | #include "third_party/libyuv/include/libyuv/compare.h" |
| 18 | #include "third_party/libyuv/include/libyuv/convert.h" |
vspasova@webrtc.org | fd80070 | 2012-08-16 14:07:02 +0000 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | namespace test { |
| 22 | |
| 23 | struct AnalysisResult { |
| 24 | int frame_number; |
| 25 | double psnr_value; |
| 26 | double ssim_value; |
| 27 | }; |
| 28 | |
| 29 | struct ResultsContainer { |
| 30 | std::vector<AnalysisResult> frames; |
| 31 | }; |
| 32 | |
| 33 | enum VideoAnalysisMetricsType {kPSNR, kSSIM}; |
| 34 | |
| 35 | // A function to run the PSNR and SSIM analysis on the test file. The test file |
| 36 | // comprises the frames that were captured during the quality measurement test. |
| 37 | // There may be missing or duplicate frames. Also the frames start at a random |
| 38 | // position in the original video. We should provide a statistics file along |
| 39 | // with the test video. The stats file contains the connection between the |
| 40 | // actual frames in the test file and their position in the reference video, so |
| 41 | // that the analysis could run with the right frames from both videos. The stats |
| 42 | // file should be in the form 'frame_xxxx yyyy', where xxxx is the consecutive |
| 43 | // number of the frame in the test video, and yyyy is the equivalent frame in |
| 44 | // the reference video. The stats file could be produced by |
| 45 | // tools/barcode_tools/barcode_decoder.py. This script decodes the barcodes |
| 46 | // integrated in every video and generates the stats file. If three was some |
| 47 | // problem with the decoding there would be 'Barcode error' instead of yyyy. |
| 48 | void RunAnalysis(const char* reference_file_name, const char* test_file_name, |
| 49 | const char* stats_file_name, int width, int height, |
| 50 | ResultsContainer* results); |
| 51 | |
| 52 | // Compute PSNR or SSIM for an I420 frame (all planes). When we are calculating |
| 53 | // PSNR values, the max return value (in the case where the test and reference |
| 54 | // frames are exactly the same) will be 48. In the case of SSIM the max return |
| 55 | // value will be 1. |
| 56 | double CalculateMetrics(VideoAnalysisMetricsType video_metrics_type, |
| 57 | const uint8* ref_frame, const uint8* test_frame, |
| 58 | int width, int height); |
| 59 | |
| 60 | // Function to print the result from the analysis. |
| 61 | void PrintAnalysisResults(ResultsContainer* results); |
| 62 | |
| 63 | // Calculates max repeated and skipped frames. |
| 64 | void PrintMaxRepeatedAndSkippedFrames(const char* stats_file_name); |
| 65 | |
| 66 | // Gets the next line from an open stats file. |
| 67 | bool GetNextStatsLine(FILE* stats_file, char* line); |
| 68 | |
| 69 | // Calculates the size of a I420 frame if given the width and height. |
vspasova@webrtc.org | ac410e2 | 2012-08-27 14:57:19 +0000 | [diff] [blame] | 70 | int GetI420FrameSize(int width, int height); |
vspasova@webrtc.org | fd80070 | 2012-08-16 14:07:02 +0000 | [diff] [blame] | 71 | |
vspasova@webrtc.org | fd80070 | 2012-08-16 14:07:02 +0000 | [diff] [blame] | 72 | // Extract the sequence of the frame in the video. I.e. if line is |
| 73 | // frame_0023 0284, we will get 23. |
| 74 | int ExtractFrameSequenceNumber(std::string line); |
| 75 | |
| 76 | // Checks if there is 'Barcode error' for the given line. |
| 77 | bool IsThereBarcodeError(std::string line); |
| 78 | |
| 79 | // Extract the frame number in the reference video. I.e. if line is |
| 80 | // frame_0023 0284, we will get 284. |
| 81 | int ExtractDecodedFrameNumber(std::string line); |
| 82 | |
| 83 | // Gets the next frame from an open I420 file. |
| 84 | bool GetNextI420Frame(FILE* input_file, int width, int height, |
| 85 | uint8* result_frame); |
| 86 | |
| 87 | // Extracts an I420 frame at position frame_number from the file. |
| 88 | bool ExtractFrameFromI420(const char* i420_file_name, int width, int height, |
| 89 | int frame_number, uint8* result_frame); |
| 90 | |
| 91 | |
| 92 | } // namespace test |
| 93 | } // namespace webrtc |
| 94 | |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 95 | #endif // WEBRTC_TOOLS_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_ |