blob: b1dfee8b75aec2783046a47f4cbd3707bd8d5fab [file] [log] [blame]
Sergey Silkin6c60f722023-02-02 11:49:13 +01001/*
2 * Copyright (c) 2023 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_VIDEO_CODEC_STATS_H_
12#define API_TEST_VIDEO_CODEC_STATS_H_
13
14#include <string>
15#include <vector>
16
17#include "absl/types/optional.h"
18#include "api/numerics/samples_stats_counter.h"
19#include "api/test/metrics/metric.h"
20#include "api/test/metrics/metrics_logger.h"
21#include "api/units/data_rate.h"
22#include "api/units/frequency.h"
23
24namespace webrtc {
25namespace test {
26
27// Interface for encoded and/or decoded video frame and stream statistics.
28class VideoCodecStats {
29 public:
30 // Filter for slicing frames.
31 struct Filter {
32 absl::optional<int> first_frame;
33 absl::optional<int> last_frame;
34 absl::optional<int> spatial_idx;
35 absl::optional<int> temporal_idx;
36 };
37
38 struct Frame {
39 int frame_num = 0;
40 uint32_t timestamp_rtp = 0;
41
42 int spatial_idx = 0;
43 int temporal_idx = 0;
44
45 int width = 0;
46 int height = 0;
47 int size_bytes = 0;
48 bool keyframe = false;
49 absl::optional<int> qp = absl::nullopt;
50 absl::optional<int> base_spatial_idx = absl::nullopt;
51
52 Timestamp encode_start = Timestamp::Zero();
53 TimeDelta encode_time = TimeDelta::Zero();
54 Timestamp decode_start = Timestamp::Zero();
55 TimeDelta decode_time = TimeDelta::Zero();
56
57 struct Psnr {
58 double y = 0.0;
59 double u = 0.0;
60 double v = 0.0;
61 };
62 absl::optional<Psnr> psnr = absl::nullopt;
63
64 bool encoded = false;
65 bool decoded = false;
66 };
67
68 struct Stream {
69 int num_frames = 0;
70 int num_keyframes = 0;
71
72 SamplesStatsCounter width;
73 SamplesStatsCounter height;
74 SamplesStatsCounter size_bytes;
75 SamplesStatsCounter qp;
76
77 SamplesStatsCounter encode_time_us;
78 SamplesStatsCounter decode_time_us;
79
80 DataRate bitrate = DataRate::Zero();
81 Frequency framerate = Frequency::Zero();
82 int bitrate_mismatch_pct = 0;
83 int framerate_mismatch_pct = 0;
84 SamplesStatsCounter transmission_time_us;
85
86 struct Psnr {
87 SamplesStatsCounter y;
88 SamplesStatsCounter u;
89 SamplesStatsCounter v;
90 } psnr;
91 };
92
93 virtual ~VideoCodecStats() = default;
94
95 // Returns frames from interval, spatial and temporal layer specified by given
96 // `filter`.
97 virtual std::vector<Frame> Slice(
98 absl::optional<Filter> filter = absl::nullopt) const = 0;
99
100 // Returns video statistics aggregated for given `frames`. If `bitrate` is
101 // provided, also performs rate control analysis. If `framerate` is provided,
102 // also calculates frame rate mismatch.
103 virtual Stream Aggregate(
104 const std::vector<Frame>& frames,
105 absl::optional<DataRate> bitrate = absl::nullopt,
106 absl::optional<Frequency> framerate = absl::nullopt) const = 0;
107
108 // Logs `Stream` metrics to provided `MetricsLogger`.
109 virtual void LogMetrics(MetricsLogger* logger,
110 const Stream& stream,
111 std::string test_case_name) const = 0;
112};
113
114} // namespace test
115} // namespace webrtc
116
117#endif // API_TEST_VIDEO_CODEC_STATS_H_