/src/avm/av2/common/level.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2021, Alliance for Open Media. All rights reserved |
3 | | * |
4 | | * This source code is subject to the terms of the BSD 3-Clause Clear License |
5 | | * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear |
6 | | * License was not distributed with this source code in the LICENSE file, you |
7 | | * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/. If the |
8 | | * Alliance for Open Media Patent License 1.0 was not distributed with this |
9 | | * source code in the PATENTS file, you can obtain it at |
10 | | * aomedia.org/license/patent-license/. |
11 | | */ |
12 | | |
13 | | #ifndef AVM_AV2_ENCODER_LEVEL_H_ |
14 | | #define AVM_AV2_ENCODER_LEVEL_H_ |
15 | | |
16 | | #include "av2/common/av2_common_int.h" |
17 | | |
18 | | struct AV2_COMP; |
19 | | |
20 | | // AV2 Level Specifications |
21 | | typedef struct { |
22 | | AV2_LEVEL level; |
23 | | int max_picture_size; |
24 | | int max_h_size; |
25 | | int max_v_size; |
26 | | int max_header_rate; |
27 | | int max_tile_rate; |
28 | | int max_tiles; |
29 | | int max_tile_cols; |
30 | | int64_t max_display_rate; |
31 | | int64_t max_decode_rate; |
32 | | double main_mbps; |
33 | | double high_mbps; |
34 | | double main_cr; |
35 | | double high_cr; |
36 | | } AV2LevelSpec; |
37 | | |
38 | | extern const AV2LevelSpec av2_level_defs[SEQ_LEVELS]; |
39 | | |
40 | | // AV2 Substream Level Specifications |
41 | | typedef struct { |
42 | | int max_picture_size; |
43 | | int max_picture_size_x; |
44 | | double scale_factor_x; // This is present here to align with the table in |
45 | | // Specification text. This one is derived from the |
46 | | // bitstream |
47 | | int max_v_size_x; |
48 | | int max_h_size_x; |
49 | | int max_tile_cols_x; |
50 | | int max_header_rate_x; |
51 | | } AV2SubstreamLevelSpec; |
52 | | |
53 | | typedef struct { |
54 | | int64_t ts_start; |
55 | | int64_t ts_end; |
56 | | size_t encoded_size_in_bytes; |
57 | | int pic_size; |
58 | | int frame_header_count; |
59 | | int tiles; |
60 | | int immediate_output_picture; |
61 | | int show_existing_frame; |
62 | | } FrameRecord; |
63 | | |
64 | | // Record frame info. in a rolling window. |
65 | 0 | #define FRAME_WINDOW_SIZE 256 |
66 | | typedef struct { |
67 | | FrameRecord buf[FRAME_WINDOW_SIZE]; |
68 | | int num; // Number of FrameRecord stored in the buffer. |
69 | | int start; // Buffer index of the first FrameRecord. |
70 | | } FrameWindowBuffer; |
71 | | |
72 | | typedef struct { |
73 | | int max_bitrate; // Max bitrate in any 1-second window, in bps. |
74 | | int max_tile_size; |
75 | | int max_tile_width; |
76 | | int min_cropped_tile_width; |
77 | | int min_cropped_tile_height; |
78 | | int tile_width_is_valid; |
79 | | int min_frame_width; |
80 | | int min_frame_height; |
81 | | double total_compressed_size; // In bytes. |
82 | | double total_time_encoded; // In seconds. |
83 | | double min_cr; |
84 | | } AV2LevelStats; |
85 | | |
86 | | // The following data structures are for the decoder model. |
87 | | typedef struct { |
88 | | int decoder_ref_count; |
89 | | int player_ref_count; |
90 | | int display_index; |
91 | | FRAME_TYPE frame_type; |
92 | | double presentation_time; |
93 | | } FRAME_BUFFER; |
94 | | |
95 | | // Interval of bits transmission for a DFG(Decodable Frame Group). |
96 | | typedef struct { |
97 | | double first_bit_arrival_time; // Time when the first bit arrives. |
98 | | double last_bit_arrival_time; // Time when the last bit arrives. |
99 | | // Removal time means the time when the bits to be decoded are removed from |
100 | | // the smoothing buffer. Removal time is essentially the time when the |
101 | | // decoding of the frame starts. |
102 | | double removal_time; |
103 | | } DFG_INTERVAL; |
104 | | |
105 | 0 | #define DFG_INTERVAL_QUEUE_SIZE 64 |
106 | | typedef struct { |
107 | | int head; |
108 | | int size; |
109 | | double total_interval; |
110 | | DFG_INTERVAL buf[DFG_INTERVAL_QUEUE_SIZE]; |
111 | | } DFG_INTERVAL_QUEUE; |
112 | | |
113 | | enum { |
114 | | RESOURCE_MODE = 0, // Resource availability mode. |
115 | | SCHEDULE_MODE // Decoding schedule mode. |
116 | | } UENUM1BYTE(DECODER_MODEL_MODE); |
117 | | |
118 | | enum { |
119 | | DECODER_MODEL_OK = 0, |
120 | | DECODE_FRAME_BUF_UNAVAILABLE, |
121 | | DECODE_EXISTING_FRAME_BUF_EMPTY, |
122 | | DISPLAY_FRAME_LATE, |
123 | | SMOOTHING_BUFFER_UNDERFLOW, |
124 | | SMOOTHING_BUFFER_OVERFLOW, |
125 | | DECODER_MODEL_DISABLED, |
126 | | DECODER_MODEL_MULTIPLE_XLAYERS, |
127 | | } UENUM1BYTE(DECODER_MODEL_STATUS); |
128 | | |
129 | | typedef struct { |
130 | | DECODER_MODEL_STATUS status; |
131 | | DECODER_MODEL_MODE mode; |
132 | | bool is_low_delay_mode; |
133 | | AV2_LEVEL level; |
134 | | int encoder_buffer_delay; // In units of 1/90000 seconds. |
135 | | int decoder_buffer_delay; // In units of 1/90000 seconds. |
136 | | int num_ticks_per_picture; |
137 | | int initial_display_delay; // In units of frames. |
138 | | int64_t decode_rate; |
139 | | double display_clock_tick; // In units of seconds. |
140 | | double current_time; // In units of seconds. |
141 | | double initial_presentation_delay; // In units of seconds. |
142 | | double bit_rate; // Bits per second. |
143 | | |
144 | | int num_frame; |
145 | | int num_decoded_frame; |
146 | | int num_shown_frame; |
147 | | int vbi[REF_FRAMES]; // Virtual buffer index. |
148 | | FRAME_BUFFER frame_buffer_pool[BUFFER_POOL_MAX_SIZE]; |
149 | | DFG_INTERVAL_QUEUE dfg_interval_queue; |
150 | | |
151 | | // Information for the DFG(Decodable Frame Group) being processed. |
152 | | double first_bit_arrival_time; |
153 | | double last_bit_arrival_time; |
154 | | size_t coded_bits; |
155 | | |
156 | | // Information for the frame being processed. |
157 | | double removal_time; |
158 | | double presentation_time; |
159 | | int decode_samples; |
160 | | int display_samples; |
161 | | |
162 | | int64_t max_display_rate; |
163 | | int64_t max_decode_rate; |
164 | | bool max_tile_rate_satisfy; |
165 | | bool compressed_size_satisfy; |
166 | | bool frame_symbol_count_satisfy; |
167 | | |
168 | | // Number of reference frames signaled in the sequence header. Determines |
169 | | // the active buffer pool size (num_ref_frames + 2), matching the spec's |
170 | | // NumRefFrames + 2. The backing array is sized at BUFFER_POOL_MAX_SIZE. |
171 | | int num_ref_frames; |
172 | | |
173 | | // Number of shown frames that share the current presentation time (i.e. |
174 | | // belong to the same temporal unit). Reset to 0 when the presentation time |
175 | | // advances to a new temporal unit. |
176 | | int num_frames_current_tu; |
177 | | |
178 | | // Tracks whether every inter-TU presentation interval satisfies the minimum |
179 | | // required by the spec (§E.3.2). |
180 | | bool min_presentation_interval_satisfy; |
181 | | |
182 | | // Index of the currently decoded frame |
183 | | int cfbi; |
184 | | |
185 | | int last_output_mlayer; |
186 | | int last_output_xlayer; |
187 | | int last_display_index; |
188 | | } DECODER_MODEL; |
189 | | |
190 | | typedef struct { |
191 | | AV2LevelStats level_stats; |
192 | | AV2LevelSpec level_spec; |
193 | | FrameWindowBuffer frame_window_buffer; |
194 | | DECODER_MODEL decoder_models[SEQ_LEVELS]; |
195 | | } AV2LevelInfo; |
196 | | |
197 | | typedef struct AV2LevelParams { |
198 | | // Specifies the level that the coded video sequence conforms to for each |
199 | | // operating point. |
200 | | AV2_LEVEL target_seq_level_idx[MAX_NUM_OPERATING_POINTS]; |
201 | | // Bit mask to indicate whether to keep level stats for corresponding |
202 | | // operating points. |
203 | | uint32_t keep_level_stats; |
204 | | // Level information for each operating point. |
205 | | AV2LevelInfo *level_info[MAX_NUM_OPERATING_POINTS]; |
206 | | // Count the number of OBU_FRAME and OBU_FRAME_HEADER for level calculation. |
207 | | int frame_header_count; |
208 | | double multi_stream_scaling_x; |
209 | | } AV2LevelParams; |
210 | | |
211 | | static INLINE int is_in_operating_point(int operating_point, int tlayer_id, |
212 | 0 | int mlayer_id) { |
213 | 0 | if (!operating_point) return 1; |
214 | | |
215 | 0 | return ((operating_point >> tlayer_id) & 1) && |
216 | 0 | ((operating_point >> (mlayer_id + MAX_NUM_TLAYERS)) & 1); |
217 | 0 | } Unexecuted instantiation: decodeframe.c:is_in_operating_point Unexecuted instantiation: obu.c:is_in_operating_point Unexecuted instantiation: level.c:is_in_operating_point |
218 | | int level_to_sub_stream_level_index(AV2_LEVEL level, double scaling_factor_x); |
219 | | |
220 | | void av2_init_level_info(struct AV2_COMP *cpi); |
221 | | |
222 | | bool is_filter_enabled_frame(const AV2_COMMON *const cm); |
223 | | |
224 | | void av2_update_level_info(struct AV2_COMP *cpi, size_t size, int64_t ts_start, |
225 | | int64_t ts_end, int decode_frame); |
226 | | |
227 | | // Compression ratio of current frame. |
228 | | double av2_get_compression_ratio(const AV2_COMMON *const cm, |
229 | | size_t encoded_frame_size); |
230 | | |
231 | | // Return sequence level indices in seq_level_idx[MAX_NUM_OPERATING_POINTS]. |
232 | | avm_codec_err_t av2_get_seq_level_idx(const struct AV2_COMP *cpi, |
233 | | const SequenceHeader *seq_params, |
234 | | const AV2LevelParams *level_params, |
235 | | int *seq_level_idx); |
236 | | |
237 | | void av2_decoder_model_init(const struct AV2_COMP *const cpi, AV2_LEVEL level, |
238 | | int op_index, DECODER_MODEL *const decoder_model); |
239 | | |
240 | | void av2_decoder_model_update_buffer_and_finish_frame_decode_for_operating_points( |
241 | | const struct AV2_COMP *const cpi); |
242 | | |
243 | | void av2_decoder_model_check_output_frame_for_operating_points( |
244 | | const struct AV2_COMP *const cpi, int ref_idx, |
245 | | RefCntBuffer *output_frame_ptr); |
246 | | |
247 | | // Return max bitrate(bps) for given level. |
248 | | double av2_get_max_bitrate_for_level(AV2_LEVEL level_index, int tier, |
249 | | BITSTREAM_PROFILE profile, |
250 | | double multi_stream_scaling_x); |
251 | | |
252 | | // Get max number of tiles and tile columns for given level. |
253 | | void av2_get_max_tiles_for_level(AV2_LEVEL level_index, int *const max_tiles, |
254 | | int *const max_tile_cols); |
255 | | |
256 | | // Return maximum legal DPB size defined by the level. |
257 | | int av2_get_max_level_ref_frames(const AV2_COMMON *const cm, OBU_TYPE obu_type, |
258 | | AV2_LEVEL level_index); |
259 | | |
260 | | #endif // AVM_AV2_ENCODER_LEVEL_H_ |