Coverage Report

Created: 2025-06-22 08:04

/src/aom/av1/encoder/level.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2019, Alliance for Open Media. All rights reserved.
3
 *
4
 * This source code is subject to the terms of the BSD 2 Clause License and
5
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6
 * was not distributed with this source code in the LICENSE file, you can
7
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8
 * Media Patent License 1.0 was not distributed with this source code in the
9
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10
 */
11
12
#ifndef AOM_AV1_ENCODER_LEVEL_H_
13
#define AOM_AV1_ENCODER_LEVEL_H_
14
15
#include "av1/common/enums.h"
16
17
struct AV1_COMP;
18
19
// AV1 Level Specifications
20
typedef struct {
21
  AV1_LEVEL level;
22
  int max_picture_size;
23
  int max_h_size;
24
  int max_v_size;
25
  int max_header_rate;
26
  int max_tile_rate;
27
  int max_tiles;
28
  int max_tile_cols;
29
  int64_t max_display_rate;
30
  int64_t max_decode_rate;
31
  double main_mbps;
32
  double high_mbps;
33
  double main_cr;
34
  double high_cr;
35
} AV1LevelSpec;
36
37
typedef struct {
38
  int64_t ts_start;
39
  int64_t ts_end;
40
  size_t encoded_size_in_bytes;
41
  int pic_size;
42
  int frame_header_count;
43
  int tiles;
44
  int show_frame;
45
  int show_existing_frame;
46
} FrameRecord;
47
48
// Record frame info. in a rolling window.
49
0
#define FRAME_WINDOW_SIZE 256
50
typedef struct {
51
  FrameRecord buf[FRAME_WINDOW_SIZE];
52
  int num;    // Number of FrameRecord stored in the buffer.
53
  int start;  // Buffer index of the first FrameRecord.
54
} FrameWindowBuffer;
55
56
typedef struct {
57
  int max_bitrate;  // Max bitrate in any 1-second window, in bps.
58
  int max_tile_size;
59
  int max_superres_tile_width;
60
  int min_cropped_tile_width;
61
  int min_cropped_tile_height;
62
  int tile_width_is_valid;
63
  int min_frame_width;
64
  int min_frame_height;
65
  double total_compressed_size;  // In bytes.
66
  double total_time_encoded;     // In seconds.
67
  double min_cr;
68
} AV1LevelStats;
69
70
// The following data structures are for the decoder model.
71
typedef struct {
72
  int decoder_ref_count;
73
  int player_ref_count;
74
  int display_index;
75
  FRAME_TYPE frame_type;
76
  double presentation_time;
77
} FRAME_BUFFER;
78
79
// Interval of bits transmission for a DFG(Decodable Frame Group).
80
typedef struct {
81
  double first_bit_arrival_time;  // Time when the first bit arrives.
82
  double last_bit_arrival_time;   // Time when the last bit arrives.
83
  // Removal time means the time when the bits to be decoded are removed from
84
  // the smoothing buffer. Removal time is essentially the time when the
85
  // decoding of the frame starts.
86
  double removal_time;
87
} DFG_INTERVAL;
88
89
0
#define DFG_INTERVAL_QUEUE_SIZE 64
90
typedef struct {
91
  int head;
92
  int size;
93
  double total_interval;
94
  DFG_INTERVAL buf[DFG_INTERVAL_QUEUE_SIZE];
95
} DFG_INTERVAL_QUEUE;
96
97
enum {
98
  RESOURCE_MODE = 0,  // Resource availability mode.
99
  SCHEDULE_MODE       // Decoding schedule mode.
100
} UENUM1BYTE(DECODER_MODEL_MODE);
101
102
enum {
103
  DECODER_MODEL_OK = 0,
104
  DECODE_BUFFER_AVAILABLE_LATE,
105
  DECODE_FRAME_BUF_UNAVAILABLE,
106
  DECODE_EXISTING_FRAME_BUF_EMPTY,
107
  DISPLAY_FRAME_LATE,
108
  SMOOTHING_BUFFER_UNDERFLOW,
109
  SMOOTHING_BUFFER_OVERFLOW,
110
  DECODER_MODEL_DISABLED
111
} UENUM1BYTE(DECODER_MODEL_STATUS);
112
113
0
#define BUFFER_POOL_MAX_SIZE 10
114
typedef struct {
115
  DECODER_MODEL_STATUS status;
116
  DECODER_MODEL_MODE mode;
117
  bool is_low_delay_mode;
118
  AV1_LEVEL level;
119
  int encoder_buffer_delay;  // In units of 1/90000 seconds.
120
  int decoder_buffer_delay;  // In units of 1/90000 seconds.
121
  int num_ticks_per_picture;
122
  int initial_display_delay;  // In units of frames.
123
  int64_t decode_rate;
124
  double display_clock_tick;          // In units of seconds.
125
  double current_time;                // In units of seconds.
126
  double initial_presentation_delay;  // In units of seconds.
127
  double bit_rate;                    // Bits per second.
128
129
  int num_frame;
130
  int num_decoded_frame;
131
  int num_shown_frame;
132
  int vbi[REF_FRAMES];  // Virtual buffer index.
133
  FRAME_BUFFER frame_buffer_pool[BUFFER_POOL_MAX_SIZE];
134
  DFG_INTERVAL_QUEUE dfg_interval_queue;
135
136
  // Information for the DFG(Decodable Frame Group) being processed.
137
  double first_bit_arrival_time;
138
  double last_bit_arrival_time;
139
  size_t coded_bits;
140
141
  // Information for the frame being processed.
142
  double removal_time;
143
  double presentation_time;
144
  int decode_samples;
145
  int display_samples;
146
147
  double max_display_rate;
148
  double max_decode_rate;
149
} DECODER_MODEL;
150
151
typedef struct {
152
  AV1LevelStats level_stats;
153
  AV1LevelSpec level_spec;
154
  FrameWindowBuffer frame_window_buffer;
155
  DECODER_MODEL decoder_models[SEQ_LEVELS];
156
} AV1LevelInfo;
157
158
typedef struct AV1LevelParams {
159
  // Specifies the level that the coded video sequence conforms to for each
160
  // operating point.
161
  AV1_LEVEL target_seq_level_idx[MAX_NUM_OPERATING_POINTS];
162
  // Bit mask to indicate whether to keep level stats for corresponding
163
  // operating points.
164
  uint32_t keep_level_stats;
165
  // Level information for each operating point.
166
  AV1LevelInfo *level_info[MAX_NUM_OPERATING_POINTS];
167
} AV1LevelParams;
168
169
static inline int is_in_operating_point(int operating_point,
170
                                        int temporal_layer_id,
171
0
                                        int spatial_layer_id) {
172
0
  if (!operating_point) return 1;
173
174
0
  return ((operating_point >> temporal_layer_id) & 1) &&
175
0
         ((operating_point >> (spatial_layer_id + 8)) & 1);
176
0
}
Unexecuted instantiation: av1_cx_iface.c:is_in_operating_point
Unexecuted instantiation: allintra_vis.c:is_in_operating_point
Unexecuted instantiation: av1_quantize.c:is_in_operating_point
Unexecuted instantiation: bitstream.c:is_in_operating_point
Unexecuted instantiation: context_tree.c:is_in_operating_point
Unexecuted instantiation: encodeframe.c:is_in_operating_point
Unexecuted instantiation: encodeframe_utils.c:is_in_operating_point
Unexecuted instantiation: encodemb.c:is_in_operating_point
Unexecuted instantiation: encodemv.c:is_in_operating_point
Unexecuted instantiation: encoder.c:is_in_operating_point
Unexecuted instantiation: encoder_utils.c:is_in_operating_point
Unexecuted instantiation: encodetxb.c:is_in_operating_point
Unexecuted instantiation: ethread.c:is_in_operating_point
Unexecuted instantiation: firstpass.c:is_in_operating_point
Unexecuted instantiation: global_motion_facade.c:is_in_operating_point
Unexecuted instantiation: level.c:is_in_operating_point
Unexecuted instantiation: lookahead.c:is_in_operating_point
Unexecuted instantiation: mcomp.c:is_in_operating_point
Unexecuted instantiation: mv_prec.c:is_in_operating_point
Unexecuted instantiation: palette.c:is_in_operating_point
Unexecuted instantiation: partition_search.c:is_in_operating_point
Unexecuted instantiation: partition_strategy.c:is_in_operating_point
Unexecuted instantiation: pass2_strategy.c:is_in_operating_point
Unexecuted instantiation: pickcdef.c:is_in_operating_point
Unexecuted instantiation: picklpf.c:is_in_operating_point
Unexecuted instantiation: pickrst.c:is_in_operating_point
Unexecuted instantiation: ratectrl.c:is_in_operating_point
Unexecuted instantiation: rd.c:is_in_operating_point
Unexecuted instantiation: rdopt.c:is_in_operating_point
Unexecuted instantiation: nonrd_pickmode.c:is_in_operating_point
Unexecuted instantiation: nonrd_opt.c:is_in_operating_point
Unexecuted instantiation: segmentation.c:is_in_operating_point
Unexecuted instantiation: speed_features.c:is_in_operating_point
Unexecuted instantiation: superres_scale.c:is_in_operating_point
Unexecuted instantiation: svc_layercontext.c:is_in_operating_point
Unexecuted instantiation: temporal_filter.c:is_in_operating_point
Unexecuted instantiation: tokenize.c:is_in_operating_point
Unexecuted instantiation: tpl_model.c:is_in_operating_point
Unexecuted instantiation: tx_search.c:is_in_operating_point
Unexecuted instantiation: txb_rdopt.c:is_in_operating_point
Unexecuted instantiation: intra_mode_search.c:is_in_operating_point
Unexecuted instantiation: var_based_part.c:is_in_operating_point
Unexecuted instantiation: av1_noise_estimate.c:is_in_operating_point
Unexecuted instantiation: aq_complexity.c:is_in_operating_point
Unexecuted instantiation: aq_cyclicrefresh.c:is_in_operating_point
Unexecuted instantiation: aq_variance.c:is_in_operating_point
Unexecuted instantiation: compound_type.c:is_in_operating_point
Unexecuted instantiation: encode_strategy.c:is_in_operating_point
Unexecuted instantiation: global_motion.c:is_in_operating_point
Unexecuted instantiation: gop_structure.c:is_in_operating_point
Unexecuted instantiation: interp_search.c:is_in_operating_point
Unexecuted instantiation: motion_search_facade.c:is_in_operating_point
177
178
void av1_init_level_info(struct AV1_COMP *cpi);
179
180
void av1_update_level_info(struct AV1_COMP *cpi, size_t size, int64_t ts_start,
181
                           int64_t ts_end);
182
183
// Return sequence level indices in seq_level_idx[MAX_NUM_OPERATING_POINTS].
184
aom_codec_err_t av1_get_seq_level_idx(const SequenceHeader *seq_params,
185
                                      const AV1LevelParams *level_params,
186
                                      int *seq_level_idx);
187
188
aom_codec_err_t av1_get_target_seq_level_idx(const SequenceHeader *seq_params,
189
                                             const AV1LevelParams *level_params,
190
                                             int *target_seq_level_idx);
191
192
// This function uses the decoder model to check whether there could be
193
// SMOOTHING_BUFFER_UNDERFLOW or SMOOTHING_BUFFER_OVERFLOW. It does not
194
// update the content of decoder_model, and can be used to target certain
195
// encoding level in the recode loop.
196
DECODER_MODEL_STATUS av1_decoder_model_try_smooth_buf(
197
    const struct AV1_COMP *const cpi, size_t coded_bits,
198
    const DECODER_MODEL *const decoder_model);
199
200
// Return max bitrate(bps) for given level.
201
double av1_get_max_bitrate_for_level(AV1_LEVEL level_index, int tier,
202
                                     BITSTREAM_PROFILE profile);
203
204
// Get max number of tiles and tile columns for given level.
205
void av1_get_max_tiles_for_level(AV1_LEVEL level_index, int *const max_tiles,
206
                                 int *const max_tile_cols);
207
208
// Return minimum compression ratio for given level.
209
double av1_get_min_cr_for_level(AV1_LEVEL level_index, int tier,
210
                                int is_still_picture);
211
#endif  // AOM_AV1_ENCODER_LEVEL_H_