blob: a05985a6650d1002382e9728a06ede5d859c648f [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>
Jonas Olssona4d87372019-07-05 19:08:33 +020016
Sergey Silkin706ef1b2021-07-07 14:23:07 +020017#include <map>
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020018#include <string>
19#include <vector>
20
Niels Möller8f7ce222019-03-21 15:43:58 +010021#include "api/video/video_frame_type.h"
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020022
23namespace webrtc {
24namespace test {
25
26// Statistics for a sequence of processed frames. This class is not thread safe.
27class VideoCodecTestStats {
28 public:
29 // Statistics for one processed frame.
30 struct FrameStatistics {
Sergey Silkin02fed022018-09-25 13:48:19 +020031 FrameStatistics(size_t frame_number,
32 size_t rtp_timestamp,
33 size_t spatial_idx);
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020034
35 std::string ToString() const;
36
Sergey Silkin706ef1b2021-07-07 14:23:07 +020037 // Returns name -> value text map of frame statistics.
38 std::map<std::string, std::string> ToMap() const;
39
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020040 size_t frame_number = 0;
41 size_t rtp_timestamp = 0;
42
43 // Encoding.
44 int64_t encode_start_ns = 0;
45 int encode_return_code = 0;
46 bool encoding_successful = false;
47 size_t encode_time_us = 0;
48 size_t target_bitrate_kbps = 0;
Sergey Silkin44cec0b2019-07-11 14:20:38 +020049 double target_framerate_fps = 0.0;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020050 size_t length_bytes = 0;
Niels Möller8f7ce222019-03-21 15:43:58 +010051 VideoFrameType frame_type = VideoFrameType::kVideoFrameDelta;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020052
53 // Layering.
54 size_t spatial_idx = 0;
55 size_t temporal_idx = 0;
56 bool inter_layer_predicted = false;
57 bool non_ref_for_inter_layer_pred = true;
58
59 // H264 specific.
60 size_t max_nalu_size_bytes = 0;
61
62 // Decoding.
63 int64_t decode_start_ns = 0;
64 int decode_return_code = 0;
65 bool decoding_successful = false;
66 size_t decode_time_us = 0;
67 size_t decoded_width = 0;
68 size_t decoded_height = 0;
69
70 // Quantization.
71 int qp = -1;
72
73 // Quality.
Sergey Silkinb72cc6d2020-10-29 08:29:26 +010074 bool quality_analysis_successful = false;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020075 float psnr_y = 0.0f;
76 float psnr_u = 0.0f;
77 float psnr_v = 0.0f;
78 float psnr = 0.0f; // 10 * log10(255^2 / (mse_y + mse_u + mse_v)).
79 float ssim = 0.0f; // 0.8 * ssim_y + 0.1 * (ssim_u + ssim_v).
80 };
81
82 struct VideoStatistics {
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020083 std::string ToString(std::string prefix) const;
84
Sergey Silkin706ef1b2021-07-07 14:23:07 +020085 // Returns name -> value text map of video statistics.
86 std::map<std::string, std::string> ToMap() const;
87
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020088 size_t target_bitrate_kbps = 0;
89 float input_framerate_fps = 0.0f;
90
91 size_t spatial_idx = 0;
92 size_t temporal_idx = 0;
93
94 size_t width = 0;
95 size_t height = 0;
96
97 size_t length_bytes = 0;
98 size_t bitrate_kbps = 0;
99 float framerate_fps = 0;
100
101 float enc_speed_fps = 0.0f;
102 float dec_speed_fps = 0.0f;
103
Sergey Silkin0b02d632022-02-15 10:39:05 +0100104 float avg_encode_latency_sec = 0.0f;
105 float max_encode_latency_sec = 0.0f;
106 float avg_decode_latency_sec = 0.0f;
107 float max_decode_latency_sec = 0.0f;
108
Kári Tristan Helgason169005d2018-05-22 13:34:14 +0200109 float avg_delay_sec = 0.0f;
110 float max_key_frame_delay_sec = 0.0f;
111 float max_delta_frame_delay_sec = 0.0f;
112 float time_to_reach_target_bitrate_sec = 0.0f;
Sergey Silkin1fdafae2021-08-17 11:39:37 +0200113 float avg_bitrate_mismatch_pct = 0.0f;
114 float avg_framerate_mismatch_pct = 0.0f;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +0200115
116 float avg_key_frame_size_bytes = 0.0f;
117 float avg_delta_frame_size_bytes = 0.0f;
118 float avg_qp = 0.0f;
119
120 float avg_psnr_y = 0.0f;
121 float avg_psnr_u = 0.0f;
122 float avg_psnr_v = 0.0f;
123 float avg_psnr = 0.0f;
124 float min_psnr = 0.0f;
125 float avg_ssim = 0.0f;
126 float min_ssim = 0.0f;
127
128 size_t num_input_frames = 0;
129 size_t num_encoded_frames = 0;
130 size_t num_decoded_frames = 0;
131 size_t num_key_frames = 0;
132 size_t num_spatial_resizes = 0;
133 size_t max_nalu_size_bytes = 0;
134 };
135
136 virtual ~VideoCodecTestStats() = default;
137
Rasmus Brandt7d72d0f2019-03-26 16:56:14 +0100138 virtual std::vector<FrameStatistics> GetFrameStatistics() = 0;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +0200139
140 virtual std::vector<VideoStatistics> SliceAndCalcLayerVideoStatistic(
141 size_t first_frame_num,
142 size_t last_frame_num) = 0;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +0200143};
144
145} // namespace test
146} // namespace webrtc
147
148#endif // API_TEST_VIDEOCODEC_TEST_STATS_H_