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