blob: d620d31f1234128c575eee8338e7c59667789da2 [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
Sergey Silkin2e1a9a42022-12-15 10:15:18 +010021#include "absl/types/optional.h"
22#include "api/units/data_rate.h"
23#include "api/units/frequency.h"
Niels Möller8f7ce222019-03-21 15:43:58 +010024#include "api/video/video_frame_type.h"
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020025
26namespace webrtc {
27namespace test {
28
29// Statistics for a sequence of processed frames. This class is not thread safe.
Sergey Silkin6c60f722023-02-02 11:49:13 +010030// TODO(webrtc:14852): Deprecated in favor VideoCodecStats.
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020031class VideoCodecTestStats {
32 public:
33 // Statistics for one processed frame.
34 struct FrameStatistics {
Sergey Silkin02fed022018-09-25 13:48:19 +020035 FrameStatistics(size_t frame_number,
36 size_t rtp_timestamp,
37 size_t spatial_idx);
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020038
39 std::string ToString() const;
40
Sergey Silkin706ef1b2021-07-07 14:23:07 +020041 // Returns name -> value text map of frame statistics.
42 std::map<std::string, std::string> ToMap() const;
43
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020044 size_t frame_number = 0;
45 size_t rtp_timestamp = 0;
46
47 // Encoding.
48 int64_t encode_start_ns = 0;
49 int encode_return_code = 0;
50 bool encoding_successful = false;
51 size_t encode_time_us = 0;
52 size_t target_bitrate_kbps = 0;
Sergey Silkin44cec0b2019-07-11 14:20:38 +020053 double target_framerate_fps = 0.0;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020054 size_t length_bytes = 0;
Niels Möller8f7ce222019-03-21 15:43:58 +010055 VideoFrameType frame_type = VideoFrameType::kVideoFrameDelta;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020056
57 // Layering.
58 size_t spatial_idx = 0;
59 size_t temporal_idx = 0;
60 bool inter_layer_predicted = false;
61 bool non_ref_for_inter_layer_pred = true;
62
63 // H264 specific.
64 size_t max_nalu_size_bytes = 0;
65
66 // Decoding.
67 int64_t decode_start_ns = 0;
68 int decode_return_code = 0;
69 bool decoding_successful = false;
70 size_t decode_time_us = 0;
71 size_t decoded_width = 0;
72 size_t decoded_height = 0;
73
74 // Quantization.
75 int qp = -1;
76
77 // Quality.
Sergey Silkinb72cc6d2020-10-29 08:29:26 +010078 bool quality_analysis_successful = false;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020079 float psnr_y = 0.0f;
80 float psnr_u = 0.0f;
81 float psnr_v = 0.0f;
82 float psnr = 0.0f; // 10 * log10(255^2 / (mse_y + mse_u + mse_v)).
83 float ssim = 0.0f; // 0.8 * ssim_y + 0.1 * (ssim_u + ssim_v).
84 };
85
86 struct VideoStatistics {
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020087 std::string ToString(std::string prefix) const;
88
Sergey Silkin706ef1b2021-07-07 14:23:07 +020089 // Returns name -> value text map of video statistics.
90 std::map<std::string, std::string> ToMap() const;
91
Kári Tristan Helgason169005d2018-05-22 13:34:14 +020092 size_t target_bitrate_kbps = 0;
93 float input_framerate_fps = 0.0f;
94
95 size_t spatial_idx = 0;
96 size_t temporal_idx = 0;
97
98 size_t width = 0;
99 size_t height = 0;
100
101 size_t length_bytes = 0;
102 size_t bitrate_kbps = 0;
103 float framerate_fps = 0;
104
105 float enc_speed_fps = 0.0f;
106 float dec_speed_fps = 0.0f;
107
Sergey Silkin0b02d632022-02-15 10:39:05 +0100108 float avg_encode_latency_sec = 0.0f;
109 float max_encode_latency_sec = 0.0f;
110 float avg_decode_latency_sec = 0.0f;
111 float max_decode_latency_sec = 0.0f;
112
Kári Tristan Helgason169005d2018-05-22 13:34:14 +0200113 float avg_delay_sec = 0.0f;
114 float max_key_frame_delay_sec = 0.0f;
115 float max_delta_frame_delay_sec = 0.0f;
116 float time_to_reach_target_bitrate_sec = 0.0f;
Sergey Silkin1fdafae2021-08-17 11:39:37 +0200117 float avg_bitrate_mismatch_pct = 0.0f;
118 float avg_framerate_mismatch_pct = 0.0f;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +0200119
120 float avg_key_frame_size_bytes = 0.0f;
121 float avg_delta_frame_size_bytes = 0.0f;
122 float avg_qp = 0.0f;
123
124 float avg_psnr_y = 0.0f;
125 float avg_psnr_u = 0.0f;
126 float avg_psnr_v = 0.0f;
127 float avg_psnr = 0.0f;
128 float min_psnr = 0.0f;
129 float avg_ssim = 0.0f;
130 float min_ssim = 0.0f;
131
132 size_t num_input_frames = 0;
133 size_t num_encoded_frames = 0;
134 size_t num_decoded_frames = 0;
135 size_t num_key_frames = 0;
136 size_t num_spatial_resizes = 0;
137 size_t max_nalu_size_bytes = 0;
138 };
139
140 virtual ~VideoCodecTestStats() = default;
141
Sergey Silkin2e1a9a42022-12-15 10:15:18 +0100142 virtual std::vector<FrameStatistics> GetFrameStatistics() const = 0;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +0200143
144 virtual std::vector<VideoStatistics> SliceAndCalcLayerVideoStatistic(
145 size_t first_frame_num,
146 size_t last_frame_num) = 0;
Sergey Silkin2e1a9a42022-12-15 10:15:18 +0100147
148 virtual VideoStatistics CalcVideoStatistic(size_t first_frame,
149 size_t last_frame,
150 DataRate target_bitrate,
151 Frequency target_framerate) = 0;
Kári Tristan Helgason169005d2018-05-22 13:34:14 +0200152};
153
154} // namespace test
155} // namespace webrtc
156
157#endif // API_TEST_VIDEOCODEC_TEST_STATS_H_