blob: 85384ef26476bb5a9aa55d09f2245d3373f28367 [file] [log] [blame]
Kári Tristan Helgason169005d2018-05-22 13:34:14 +02001/*
2 * Copyright (c) 2018 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
11#ifndef API_TEST_VIDEOCODEC_TEST_STATS_H_
12#define API_TEST_VIDEOCODEC_TEST_STATS_H_
13
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <stddef.h>
15#include <stdint.h>
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020016#include <string>
17#include <vector>
18
Niels Möller8f7ce222019-03-21 15:43:58 +010019#include "api/video/video_frame_type.h"
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020020
21namespace webrtc {
22namespace test {
23
24// Statistics for a sequence of processed frames. This class is not thread safe.
25class VideoCodecTestStats {
26 public:
27 // Statistics for one processed frame.
28 struct FrameStatistics {
Sergey Silkin02fed022018-09-25 13:48:19 +020029 FrameStatistics(size_t frame_number,
30 size_t rtp_timestamp,
31 size_t spatial_idx);
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020032 FrameStatistics(const FrameStatistics& rhs);
33
34 std::string ToString() const;
35
36 size_t frame_number = 0;
37 size_t rtp_timestamp = 0;
38
39 // Encoding.
40 int64_t encode_start_ns = 0;
41 int encode_return_code = 0;
42 bool encoding_successful = false;
43 size_t encode_time_us = 0;
44 size_t target_bitrate_kbps = 0;
45 size_t length_bytes = 0;
Niels Möller8f7ce222019-03-21 15:43:58 +010046 VideoFrameType frame_type = VideoFrameType::kVideoFrameDelta;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020047
48 // Layering.
49 size_t spatial_idx = 0;
50 size_t temporal_idx = 0;
51 bool inter_layer_predicted = false;
52 bool non_ref_for_inter_layer_pred = true;
53
54 // H264 specific.
55 size_t max_nalu_size_bytes = 0;
56
57 // Decoding.
58 int64_t decode_start_ns = 0;
59 int decode_return_code = 0;
60 bool decoding_successful = false;
61 size_t decode_time_us = 0;
62 size_t decoded_width = 0;
63 size_t decoded_height = 0;
64
65 // Quantization.
66 int qp = -1;
67
68 // Quality.
69 float psnr_y = 0.0f;
70 float psnr_u = 0.0f;
71 float psnr_v = 0.0f;
72 float psnr = 0.0f; // 10 * log10(255^2 / (mse_y + mse_u + mse_v)).
73 float ssim = 0.0f; // 0.8 * ssim_y + 0.1 * (ssim_u + ssim_v).
74 };
75
76 struct VideoStatistics {
77 VideoStatistics();
78 VideoStatistics(const VideoStatistics&);
79
80 std::string ToString(std::string prefix) const;
81
82 size_t target_bitrate_kbps = 0;
83 float input_framerate_fps = 0.0f;
84
85 size_t spatial_idx = 0;
86 size_t temporal_idx = 0;
87
88 size_t width = 0;
89 size_t height = 0;
90
91 size_t length_bytes = 0;
92 size_t bitrate_kbps = 0;
93 float framerate_fps = 0;
94
95 float enc_speed_fps = 0.0f;
96 float dec_speed_fps = 0.0f;
97
98 float avg_delay_sec = 0.0f;
99 float max_key_frame_delay_sec = 0.0f;
100 float max_delta_frame_delay_sec = 0.0f;
101 float time_to_reach_target_bitrate_sec = 0.0f;
102
103 float avg_key_frame_size_bytes = 0.0f;
104 float avg_delta_frame_size_bytes = 0.0f;
105 float avg_qp = 0.0f;
106
107 float avg_psnr_y = 0.0f;
108 float avg_psnr_u = 0.0f;
109 float avg_psnr_v = 0.0f;
110 float avg_psnr = 0.0f;
111 float min_psnr = 0.0f;
112 float avg_ssim = 0.0f;
113 float min_ssim = 0.0f;
114
115 size_t num_input_frames = 0;
116 size_t num_encoded_frames = 0;
117 size_t num_decoded_frames = 0;
118 size_t num_key_frames = 0;
119 size_t num_spatial_resizes = 0;
120 size_t max_nalu_size_bytes = 0;
121 };
122
123 virtual ~VideoCodecTestStats() = default;
124
125 // Creates a FrameStatistics for the next frame to be processed.
Sergey Silkin02fed022018-09-25 13:48:19 +0200126 virtual void AddFrame(const FrameStatistics& frame_stat) = 0;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +0200127
128 // Returns the FrameStatistics corresponding to |frame_number| or |timestamp|.
129 virtual FrameStatistics* GetFrame(size_t frame_number,
130 size_t spatial_idx) = 0;
131 virtual FrameStatistics* GetFrameWithTimestamp(size_t timestamp,
132 size_t spatial_idx) = 0;
133
134 virtual std::vector<VideoStatistics> SliceAndCalcLayerVideoStatistic(
135 size_t first_frame_num,
136 size_t last_frame_num) = 0;
137
138 virtual VideoStatistics SliceAndCalcAggregatedVideoStatistic(
139 size_t first_frame_num,
140 size_t last_frame_num) = 0;
141
142 virtual void PrintFrameStatistics() = 0;
143
144 virtual size_t Size(size_t spatial_idx) = 0;
145
146 virtual void Clear() = 0;
147};
148
149} // namespace test
150} // namespace webrtc
151
152#endif // API_TEST_VIDEOCODEC_TEST_STATS_H_