Bug Summary

File:root/firefox-clang/third_party/aom/av1/common/av1_common_int.h
Warning:line 766, column 16
Excessive padding in 'struct AV1Common' (39 padding bytes, where 7 is optimal). Optimal fields order: lf_info, error, prev_frame, cur_frame, last_frame_seg_map, rst_tmpbuf, rlbs, seq_params, fc, default_frame_context, buffer_pool, tpl_mvs, above_contexts, ref_frame_map, mi_params, rst_info, rst_frame, cdef_info, quant_params, width, height, render_width, render_height, superres_upscaled_width, superres_upscaled_height, frame_presentation_time, show_frame, showable_frame, show_existing_frame, current_frame_id, tpl_mvs_mem_size, temporal_layer_id, spatial_layer_id, sf_identity, delta_q_info, features, remapped_ref_idx, ref_frame_id, ref_frame_sign_bias, current_frame, lf, ref_scale_factors, buffer_removal_times, seg, global_motion, tiles, film_grain_params, superres_scale_denominator, ref_frame_side, consider reordering the fields or adding explicit padding members

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name pyramid.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/media/libaom -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/media/libaom -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D MOZ_HAS_MOZGLUE -I /root/firefox-clang/media/libaom -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/media/libaom -I /root/firefox-clang/media/libaom/config/linux/x64 -I /root/firefox-clang/media/libaom/config -I /root/firefox-clang/third_party/aom -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=tautological-type-limit-compare -Wno-range-loop-analysis -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-unknown-warning-option -Wno-character-conversion -Wno-sign-compare -Wno-unused-function -Wno-unreachable-code -Wno-unneeded-internal-declaration -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-09-01-224014-2642839-1 -x c /root/firefox-clang/third_party/aom/aom_dsp/pyramid.c
1/*
2 * Copyright (c) 2016, 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_COMMON_AV1_COMMON_INT_H_
13#define AOM_AV1_COMMON_AV1_COMMON_INT_H_
14
15#include <stdbool.h>
16
17#include "config/aom_config.h"
18#include "config/av1_rtcd.h"
19
20#include "aom/internal/aom_codec_internal.h"
21#include "aom_dsp/flow_estimation/corner_detect.h"
22#include "aom_util/aom_pthread.h"
23#include "av1/common/alloccommon.h"
24#include "av1/common/av1_loopfilter.h"
25#include "av1/common/entropy.h"
26#include "av1/common/entropymode.h"
27#include "av1/common/entropymv.h"
28#include "av1/common/enums.h"
29#include "av1/common/frame_buffers.h"
30#include "av1/common/mv.h"
31#include "av1/common/quant_common.h"
32#include "av1/common/restoration.h"
33#include "av1/common/tile_common.h"
34#include "av1/common/timing.h"
35#include "aom_dsp/grain_params.h"
36#include "aom_dsp/grain_table.h"
37#include "aom_dsp/odintrin.h"
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42#if defined(__clang__1) && defined(__has_warning)0
43#if __has_feature(cxx_attributes)0 && __has_warning("-Wimplicit-fallthrough")1
44#define AOM_FALLTHROUGH_INTENDEDdo { } while (0) [[clang::fallthrough]] // NOLINT
45#endif
46#elif defined(__GNUC__4) && __GNUC__4 >= 7
47#define AOM_FALLTHROUGH_INTENDEDdo { } while (0) __attribute__((fallthrough)) // NOLINT
48#endif
49
50#ifndef AOM_FALLTHROUGH_INTENDEDdo { } while (0)
51#define AOM_FALLTHROUGH_INTENDEDdo { } while (0) \
52 do { \
53 } while (0)
54#endif
55
56#define CDEF_MAX_STRENGTHS16 16
57
58/* Constant values while waiting for the sequence header */
59#define FRAME_ID_LENGTH15 15
60#define DELTA_FRAME_ID_LENGTH14 14
61
62#define FRAME_CONTEXTS((REF_FRAMES + 1 + INTER_REFS_PER_FRAME) + 1) (FRAME_BUFFERS(REF_FRAMES + 1 + INTER_REFS_PER_FRAME) + 1)
63// Extra frame context which is always kept at default values
64#define FRAME_CONTEXT_DEFAULTS(((REF_FRAMES + 1 + INTER_REFS_PER_FRAME) + 1) - 1) (FRAME_CONTEXTS((REF_FRAMES + 1 + INTER_REFS_PER_FRAME) + 1) - 1)
65#define PRIMARY_REF_BITS3 3
66#define PRIMARY_REF_NONE7 7
67
68#define NUM_PING_PONG_BUFFERS2 2
69
70#define MAX_NUM_TEMPORAL_LAYERS8 8
71#define MAX_NUM_SPATIAL_LAYERS4 4
72/* clang-format off */
73// clang-format seems to think this is a pointer dereference and not a
74// multiplication.
75#define MAX_NUM_OPERATING_POINTS(8 * 4) \
76 (MAX_NUM_TEMPORAL_LAYERS8 * MAX_NUM_SPATIAL_LAYERS4)
77/* clang-format on */
78
79// TODO(jingning): Turning this on to set up transform coefficient
80// processing timer.
81#define TXCOEFF_TIMER0 0
82#define TXCOEFF_COST_TIMER0 0
83
84/*!\cond */
85
86enum {
87 SINGLE_REFERENCE = 0,
88 COMPOUND_REFERENCE = 1,
89 REFERENCE_MODE_SELECT = 2,
90 REFERENCE_MODES = 3,
91} UENUM1BYTE(REFERENCE_MODE); typedef uint8_t REFERENCE_MODE;
92
93enum {
94 /**
95 * Frame context updates are disabled
96 */
97 REFRESH_FRAME_CONTEXT_DISABLED,
98 /**
99 * Update frame context to values resulting from backward probability
100 * updates based on entropy/counts in the decoded frame
101 */
102 REFRESH_FRAME_CONTEXT_BACKWARD,
103} UENUM1BYTE(REFRESH_FRAME_CONTEXT_MODE); typedef uint8_t REFRESH_FRAME_CONTEXT_MODE;
104
105#define MFMV_STACK_SIZE3 3
106typedef struct {
107 int_mv mfmv0;
108 uint8_t ref_frame_offset;
109} TPL_MV_REF;
110
111typedef struct {
112 int_mv mv;
113 MV_REFERENCE_FRAME ref_frame;
114} MV_REF;
115
116typedef struct RefCntBuffer {
117 // For a RefCntBuffer, the following are reference-holding variables:
118 // - cm->ref_frame_map[]
119 // - cm->cur_frame
120 // - cm->scaled_ref_buf[] (encoder only)
121 // - pbi->output_frame_index[] (decoder only)
122 // With that definition, 'ref_count' is the number of reference-holding
123 // variables that are currently referencing this buffer.
124 // For example:
125 // - suppose this buffer is at index 'k' in the buffer pool, and
126 // - Total 'n' of the variables / array elements above have value 'k' (that
127 // is, they are pointing to buffer at index 'k').
128 // Then, pool->frame_bufs[k].ref_count = n.
129 int ref_count;
130
131 unsigned int order_hint;
132 unsigned int ref_order_hints[INTER_REFS_PER_FRAME];
133
134 // These variables are used only in encoder and compare the absolute
135 // display order hint to compute the relative distance and overcome
136 // the limitation of get_relative_dist() which returns incorrect
137 // distance when a very old frame is used as a reference.
138 unsigned int display_order_hint;
139 unsigned int ref_display_order_hint[INTER_REFS_PER_FRAME];
140 // Frame's level within the hierarchical structure.
141 unsigned int pyramid_level;
142 int base_qindex;
143 MV_REF *mvs;
144 uint8_t *seg_map;
145 struct segmentation seg;
146 int mi_rows;
147 int mi_cols;
148 // Width and height give the size of the buffer (before any upscaling, unlike
149 // the sizes that can be derived from the buf structure)
150 int width;
151 int height;
152 WarpedMotionParams global_motion[REF_FRAMES];
153 int showable_frame; // frame can be used as show existing frame in future
154 uint8_t film_grain_params_present;
155 aom_film_grain_t film_grain_params;
156 aom_codec_frame_buffer_t raw_frame_buffer;
157 YV12_BUFFER_CONFIG buf;
158 int temporal_id; // Temporal layer ID of the frame
159 int spatial_id; // Spatial layer ID of the frame
160 FRAME_TYPE frame_type;
161
162 // This is only used in the encoder but needs to be indexed per ref frame
163 // so it's extremely convenient to keep it here.
164 int interp_filter_selected[SWITCHABLE];
165
166 // Inter frame reference frame delta for loop filter
167 int8_t ref_deltas[REF_FRAMES];
168
169 // 0 = ZERO_MV, MV
170 int8_t mode_deltas[MAX_MODE_LF_DELTAS2];
171
172 FRAME_CONTEXT frame_context;
173
174 int filter_level[2];
175} RefCntBuffer;
176
177typedef struct BufferPool {
178// Protect BufferPool from being accessed by several FrameWorkers at
179// the same time during frame parallel decode.
180// TODO(hkuang): Try to use atomic variable instead of locking the whole pool.
181// TODO(wtc): Remove this. See
182// https://chromium-review.googlesource.com/c/webm/libvpx/+/560630.
183#if CONFIG_MULTITHREAD1
184 pthread_mutex_t pool_mutex;
185#endif
186
187 // Private data associated with the frame buffer callbacks.
188 void *cb_priv;
189
190 aom_get_frame_buffer_cb_fn_t get_fb_cb;
191 aom_release_frame_buffer_cb_fn_t release_fb_cb;
192
193 RefCntBuffer *frame_bufs;
194 uint8_t num_frame_bufs;
195
196 // Frame buffers allocated internally by the codec.
197 InternalFrameBufferList int_frame_buffers;
198} BufferPool;
199
200/*!\endcond */
201
202/*!\brief Parameters related to CDEF */
203typedef struct {
204 //! CDEF column line buffer
205 uint16_t *colbuf[MAX_MB_PLANE3];
206 //! CDEF top & bottom line buffer
207 uint16_t *linebuf[MAX_MB_PLANE3];
208 //! CDEF intermediate buffer
209 uint16_t *srcbuf;
210 //! CDEF column line buffer sizes
211 size_t allocated_colbuf_size[MAX_MB_PLANE3];
212 //! CDEF top and bottom line buffer sizes
213 size_t allocated_linebuf_size[MAX_MB_PLANE3];
214 //! CDEF intermediate buffer size
215 size_t allocated_srcbuf_size;
216 //! CDEF damping factor
217 int cdef_damping;
218 //! Number of CDEF strength values
219 int nb_cdef_strengths;
220 //! CDEF strength values for luma
221 int cdef_strengths[CDEF_MAX_STRENGTHS16];
222 //! CDEF strength values for chroma
223 int cdef_uv_strengths[CDEF_MAX_STRENGTHS16];
224 //! Number of CDEF strength values in bits
225 int cdef_bits;
226 //! Number of rows in the frame in 4 pixel
227 int allocated_mi_rows;
228 //! Number of CDEF workers
229 int allocated_num_workers;
230} CdefInfo;
231
232/*!\cond */
233
234typedef struct {
235 int delta_q_present_flag;
236 // Resolution of delta quant
237 int delta_q_res;
238 int delta_lf_present_flag;
239 // Resolution of delta lf level
240 int delta_lf_res;
241 // This is a flag for number of deltas of loop filter level
242 // 0: use 1 delta, for y_vertical, y_horizontal, u, and v
243 // 1: use separate deltas for each filter level
244 int delta_lf_multi;
245} DeltaQInfo;
246
247typedef struct {
248 int enable_order_hint; // 0 - disable order hint, and related tools
249 int order_hint_bits_minus_1; // dist_wtd_comp, ref_frame_mvs,
250 // frame_sign_bias
251 // if 0, enable_dist_wtd_comp and
252 // enable_ref_frame_mvs must be set as 0.
253 int enable_dist_wtd_comp; // 0 - disable dist-wtd compound modes
254 // 1 - enable it
255 int enable_ref_frame_mvs; // 0 - disable ref frame mvs
256 // 1 - enable it
257} OrderHintInfo;
258
259// Sequence header structure.
260// Note: All syntax elements of sequence_header_obu that need to be
261// bit-identical across multiple sequence headers must be part of this struct,
262// so that consistency is checked by are_seq_headers_consistent() function.
263// One exception is the last member 'op_params' that is ignored by
264// are_seq_headers_consistent() function.
265typedef struct SequenceHeader {
266 int num_bits_width;
267 int num_bits_height;
268 int max_frame_width;
269 int max_frame_height;
270 // Whether current and reference frame IDs are signaled in the bitstream.
271 // Frame id numbers are additional information that do not affect the
272 // decoding process, but provide decoders with a way of detecting missing
273 // reference frames so that appropriate action can be taken.
274 uint8_t frame_id_numbers_present_flag;
275 int frame_id_length;
276 int delta_frame_id_length;
277 BLOCK_SIZE sb_size; // Size of the superblock used for this frame
278 int mib_size; // Size of the superblock in units of MI blocks
279 int mib_size_log2; // Log 2 of above.
280
281 OrderHintInfo order_hint_info;
282
283 uint8_t force_screen_content_tools; // 0 - force off
284 // 1 - force on
285 // 2 - adaptive
286 uint8_t still_picture; // Video is a single frame still picture
287 uint8_t reduced_still_picture_hdr; // Use reduced header for still picture
288 uint8_t force_integer_mv; // 0 - Don't force. MV can use subpel
289 // 1 - force to integer
290 // 2 - adaptive
291 uint8_t enable_filter_intra; // enables/disables filterintra
292 uint8_t enable_intra_edge_filter; // enables/disables edge upsampling
293 uint8_t enable_interintra_compound; // enables/disables interintra_compound
294 uint8_t enable_masked_compound; // enables/disables masked compound
295 uint8_t enable_dual_filter; // 0 - disable dual interpolation filter
296 // 1 - enable vert/horz filter selection
297 uint8_t enable_warped_motion; // 0 - disable warp for the sequence
298 // 1 - enable warp for the sequence
299 uint8_t enable_superres; // 0 - Disable superres for the sequence
300 // and no frame level superres flag
301 // 1 - Enable superres for the sequence
302 // enable per-frame superres flag
303 uint8_t enable_cdef; // To turn on/off CDEF
304 uint8_t enable_restoration; // To turn on/off loop restoration
305 BITSTREAM_PROFILE profile;
306
307 // Color config.
308 aom_bit_depth_t bit_depth; // AOM_BITS_8 in profile 0 or 1,
309 // AOM_BITS_10 or AOM_BITS_12 in profile 2 or 3.
310 uint8_t use_highbitdepth; // If true, we need to use 16bit frame buffers.
311 uint8_t monochrome; // Monochrome video
312 aom_color_primaries_t color_primaries;
313 aom_transfer_characteristics_t transfer_characteristics;
314 aom_matrix_coefficients_t matrix_coefficients;
315 int color_range;
316 int subsampling_x; // Chroma subsampling for x
317 int subsampling_y; // Chroma subsampling for y
318 aom_chroma_sample_position_t chroma_sample_position;
319 uint8_t separate_uv_delta_q;
320 uint8_t film_grain_params_present;
321
322 // Operating point info.
323 int operating_points_cnt_minus_1;
324 int operating_point_idc[MAX_NUM_OPERATING_POINTS(8 * 4)];
325 // True if operating_point_idc[op] is not equal to 0 for any value of op from
326 // 0 to operating_points_cnt_minus_1.
327 bool_Bool has_nonzero_operating_point_idc;
328 int timing_info_present;
329 aom_timing_info_t timing_info;
330 uint8_t decoder_model_info_present_flag;
331 aom_dec_model_info_t decoder_model_info;
332 uint8_t display_model_info_present_flag;
333 AV1_LEVEL seq_level_idx[MAX_NUM_OPERATING_POINTS(8 * 4)];
334 uint8_t tier[MAX_NUM_OPERATING_POINTS(8 * 4)]; // seq_tier in spec. One bit: 0 or 1.
335
336 // IMPORTANT: the op_params member must be at the end of the struct so that
337 // are_seq_headers_consistent() can be implemented with a memcmp() call.
338 // TODO(urvang): We probably don't need the +1 here.
339 aom_dec_model_op_parameters_t op_params[MAX_NUM_OPERATING_POINTS(8 * 4) + 1];
340} SequenceHeader;
341
342typedef struct {
343 int skip_mode_allowed;
344 int skip_mode_flag;
345 int ref_frame_idx_0;
346 int ref_frame_idx_1;
347} SkipModeInfo;
348
349typedef struct {
350 FRAME_TYPE frame_type;
351 REFERENCE_MODE reference_mode;
352
353 unsigned int order_hint;
354 unsigned int display_order_hint;
355 // Frame's level within the hierarchical structure.
356 unsigned int pyramid_level;
357 unsigned int frame_number;
358 SkipModeInfo skip_mode_info;
359 int refresh_frame_flags; // Which ref frames are overwritten by this frame
360 int frame_refs_short_signaling;
361} CurrentFrame;
362
363/*!\endcond */
364
365/*!
366 * \brief Frame level features.
367 */
368typedef struct {
369 /*!
370 * If true, CDF update in the symbol encoding/decoding process is disabled.
371 */
372 bool_Bool disable_cdf_update;
373 /*!
374 * If true, motion vectors are specified to eighth pel precision; and
375 * if false, motion vectors are specified to quarter pel precision.
376 */
377 bool_Bool allow_high_precision_mv;
378 /*!
379 * If true, force integer motion vectors; if false, use the default.
380 */
381 bool_Bool cur_frame_force_integer_mv;
382 /*!
383 * If true, palette tool and/or intra block copy tools may be used.
384 */
385 bool_Bool allow_screen_content_tools;
386 bool_Bool allow_intrabc; /*!< If true, intra block copy tool may be used. */
387 bool_Bool allow_warped_motion; /*!< If true, frame may use warped motion mode. */
388 /*!
389 * If true, using previous frames' motion vectors for prediction is allowed.
390 */
391 bool_Bool allow_ref_frame_mvs;
392 /*!
393 * If true, frame is fully lossless at coded resolution.
394 * */
395 bool_Bool coded_lossless;
396 /*!
397 * If true, frame is fully lossless at upscaled resolution.
398 */
399 bool_Bool all_lossless;
400 /*!
401 * If true, the frame is restricted to a reduced subset of the full set of
402 * transform types.
403 */
404 bool_Bool reduced_tx_set_used;
405 /*!
406 * If true, error resilient mode is enabled.
407 * Note: Error resilient mode allows the syntax of a frame to be parsed
408 * independently of previously decoded frames.
409 */
410 bool_Bool error_resilient_mode;
411 /*!
412 * If false, only MOTION_MODE that may be used is SIMPLE_TRANSLATION;
413 * if true, all MOTION_MODES may be used.
414 */
415 bool_Bool switchable_motion_mode;
416 TX_MODE tx_mode; /*!< Transform mode at frame level. */
417 InterpFilter interp_filter; /*!< Interpolation filter at frame level. */
418 /*!
419 * The reference frame that contains the CDF values and other state that
420 * should be loaded at the start of the frame.
421 */
422 int primary_ref_frame;
423 /*!
424 * Byte alignment of the planes in the reference buffers.
425 */
426 int byte_alignment;
427 /*!
428 * Flag signaling how frame contexts should be updated at the end of
429 * a frame decode.
430 */
431 REFRESH_FRAME_CONTEXT_MODE refresh_frame_context;
432} FeatureFlags;
433
434/*!
435 * \brief Params related to tiles.
436 */
437typedef struct CommonTileParams {
438 int cols; /*!< number of tile columns that frame is divided into */
439 int rows; /*!< number of tile rows that frame is divided into */
440 int max_width_sb; /*!< maximum tile width in superblock units. */
441 int max_height_sb; /*!< maximum tile height in superblock units. */
442
443 /*!
444 * Min width of non-rightmost tile in MI units. Only valid if cols > 1.
445 */
446 int min_inner_width;
447
448 /*!
449 * If true, tiles are uniformly spaced with power-of-two number of rows and
450 * columns.
451 * If false, tiles have explicitly configured widths and heights.
452 */
453 int uniform_spacing;
454
455 /**
456 * \name Members only valid when uniform_spacing == 1
457 */
458 /**@{*/
459 int log2_cols; /*!< log2 of 'cols'. */
460 int log2_rows; /*!< log2 of 'rows'. */
461 int width; /*!< tile width in MI units */
462 int height; /*!< tile height in MI units */
463 /**@}*/
464
465 /*!
466 * Min num of tile columns possible based on 'max_width_sb' and frame width.
467 */
468 int min_log2_cols;
469 /*!
470 * Min num of tile rows possible based on 'max_height_sb' and frame height.
471 */
472 int min_log2_rows;
473 /*!
474 * Max num of tile columns possible based on frame width.
475 */
476 int max_log2_cols;
477 /*!
478 * Max num of tile rows possible based on frame height.
479 */
480 int max_log2_rows;
481 /*!
482 * log2 of min number of tiles (same as min_log2_cols + min_log2_rows).
483 */
484 int min_log2;
485 /*!
486 * col_start_sb[i] is the start position of tile column i in superblock units.
487 * valid for 0 <= i <= cols
488 */
489 int col_start_sb[MAX_TILE_COLS64 + 1];
490 /*!
491 * row_start_sb[i] is the start position of tile row i in superblock units.
492 * valid for 0 <= i <= rows
493 */
494 int row_start_sb[MAX_TILE_ROWS64 + 1];
495 /*!
496 * If true, we are using large scale tile mode.
497 */
498 unsigned int large_scale;
499 /*!
500 * Only relevant when large_scale == 1.
501 * If true, the independent decoding of a single tile or a section of a frame
502 * is allowed.
503 */
504 unsigned int single_tile_decoding;
505} CommonTileParams;
506
507typedef struct CommonModeInfoParams CommonModeInfoParams;
508/*!
509 * \brief Params related to MB_MODE_INFO arrays and related info.
510 */
511struct CommonModeInfoParams {
512 /*!
513 * Number of rows in the frame in 16 pixel units.
514 * This is computed from frame height aligned to a multiple of 8.
515 */
516 int mb_rows;
517 /*!
518 * Number of cols in the frame in 16 pixel units.
519 * This is computed from frame width aligned to a multiple of 8.
520 */
521 int mb_cols;
522
523 /*!
524 * Total MBs = mb_rows * mb_cols.
525 */
526 int MBs;
527
528 /*!
529 * Number of rows in the frame in 4 pixel (MB_MODE_INFO) units.
530 * This is computed from frame height aligned to a multiple of 8.
531 */
532 int mi_rows;
533 /*!
534 * Number of cols in the frame in 4 pixel (MB_MODE_INFO) units.
535 * This is computed from frame width aligned to a multiple of 8.
536 */
537 int mi_cols;
538
539 /*!
540 * An array of MB_MODE_INFO structs for every 'mi_alloc_bsize' sized block
541 * in the frame.
542 * Note: This array should be treated like a scratch memory, and should NOT be
543 * accessed directly, in most cases. Please use 'mi_grid_base' array instead.
544 */
545 MB_MODE_INFO *mi_alloc;
546 /*!
547 * Number of allocated elements in 'mi_alloc'.
548 */
549 int mi_alloc_size;
550 /*!
551 * Stride for 'mi_alloc' array.
552 */
553 int mi_alloc_stride;
554 /*!
555 * The minimum block size that each element in 'mi_alloc' can correspond to.
556 * For decoder, this is always BLOCK_4X4.
557 * For encoder, this is BLOCK_8X8 for resolution >= 4k case or REALTIME mode
558 * case. Otherwise, this is BLOCK_4X4.
559 */
560 BLOCK_SIZE mi_alloc_bsize;
561
562 /*!
563 * Grid of pointers to 4x4 MB_MODE_INFO structs allocated in 'mi_alloc'.
564 * It's possible that:
565 * - Multiple pointers in the grid point to the same element in 'mi_alloc'
566 * (for example, for all 4x4 blocks that belong to the same partition block).
567 * - Some pointers can be NULL (for example, for blocks outside visible area).
568 */
569 MB_MODE_INFO **mi_grid_base;
570 /*!
571 * Number of allocated elements in 'mi_grid_base' (and 'tx_type_map' also).
572 */
573 int mi_grid_size;
574 /*!
575 * Stride for 'mi_grid_base' (and 'tx_type_map' also).
576 */
577 int mi_stride;
578
579 /*!
580 * An array of tx types for each 4x4 block in the frame.
581 * Number of allocated elements is same as 'mi_grid_size', and stride is
582 * same as 'mi_grid_size'. So, indexing into 'tx_type_map' is same as that of
583 * 'mi_grid_base'.
584 */
585 TX_TYPE *tx_type_map;
586
587 /**
588 * \name Function pointers to allow separate logic for encoder and decoder.
589 */
590 /**@{*/
591 /*!
592 * Free the memory allocated to arrays in 'mi_params'.
593 * \param[in,out] mi_params object containing common mode info parameters
594 */
595 void (*free_mi)(struct CommonModeInfoParams *mi_params);
596 /*!
597 * Initialize / reset appropriate arrays in 'mi_params'.
598 * \param[in,out] mi_params object containing common mode info parameters
599 */
600 void (*setup_mi)(struct CommonModeInfoParams *mi_params);
601 /*!
602 * Allocate required memory for arrays in 'mi_params'.
603 * \param[in,out] mi_params object containing common mode info
604 * parameters
605 * \param width frame width
606 * \param height frame height
607 * \param min_partition_size minimum partition size allowed while
608 * encoding
609 */
610 void (*set_mb_mi)(struct CommonModeInfoParams *mi_params, int width,
611 int height, BLOCK_SIZE min_partition_size);
612 /**@}*/
613};
614
615typedef struct CommonQuantParams CommonQuantParams;
616/*!
617 * \brief Parameters related to quantization at the frame level.
618 */
619struct CommonQuantParams {
620 /*!
621 * Base qindex of the frame in the range 0 to 255.
622 */
623 int base_qindex;
624
625 /*!
626 * Sharpness adjustment in the quantization process.
627 */
628 int sharpness;
629
630 /*!
631 * Delta of qindex (from base_qindex) for Y plane DC coefficient.
632 * Note: y_ac_delta_q is implicitly 0.
633 */
634 int y_dc_delta_q;
635
636 /*!
637 * Delta of qindex (from base_qindex) for U plane DC coefficients.
638 */
639 int u_dc_delta_q;
640 /*!
641 * Delta of qindex (from base_qindex) for U plane AC coefficients.
642 */
643 int v_dc_delta_q;
644
645 /*!
646 * Delta of qindex (from base_qindex) for V plane DC coefficients.
647 * Same as those for U plane if cm->seq_params->separate_uv_delta_q == 0.
648 */
649 int u_ac_delta_q;
650 /*!
651 * Delta of qindex (from base_qindex) for V plane AC coefficients.
652 * Same as those for U plane if cm->seq_params->separate_uv_delta_q == 0.
653 */
654 int v_ac_delta_q;
655
656 /*
657 * Note: The qindex per superblock may have a delta from the qindex obtained
658 * at frame level from parameters above, based on 'cm->delta_q_info'.
659 */
660
661 /**
662 * \name True dequantizers.
663 * The dequantizers below are true dequantizers used only in the
664 * dequantization process. They have the same coefficient
665 * shift/scale as TX.
666 */
667 /**@{*/
668 int16_t y_dequant_QTX[MAX_SEGMENTS8][2]; /*!< Dequant for Y plane */
669 int16_t u_dequant_QTX[MAX_SEGMENTS8][2]; /*!< Dequant for U plane */
670 int16_t v_dequant_QTX[MAX_SEGMENTS8][2]; /*!< Dequant for V plane */
671 /**@}*/
672
673 /**
674 * \name Global quantization matrix tables.
675 */
676 /**@{*/
677 /*!
678 * Global dequantization matrix table.
679 */
680 const qm_val_t *giqmatrix[NUM_QM_LEVELS(1 << 4)][3][TX_SIZES_ALL];
681 /*!
682 * Global quantization matrix table.
683 */
684 const qm_val_t *gqmatrix[NUM_QM_LEVELS(1 << 4)][3][TX_SIZES_ALL];
685 /**@}*/
686
687 /**
688 * \name Local dequantization matrix tables for each frame.
689 */
690 /**@{*/
691 /*!
692 * Local dequant matrix for Y plane.
693 */
694 const qm_val_t *y_iqmatrix[MAX_SEGMENTS8][TX_SIZES_ALL];
695 /*!
696 * Local dequant matrix for U plane.
697 */
698 const qm_val_t *u_iqmatrix[MAX_SEGMENTS8][TX_SIZES_ALL];
699 /*!
700 * Local dequant matrix for V plane.
701 */
702 const qm_val_t *v_iqmatrix[MAX_SEGMENTS8][TX_SIZES_ALL];
703 /**@}*/
704
705 /*!
706 * Flag indicating whether quantization matrices are being used:
707 * - If true, qmatrix_level_y, qmatrix_level_u and qmatrix_level_v indicate
708 * the level indices to be used to access appropriate global quant matrix
709 * tables.
710 * - If false, we implicitly use level index 'NUM_QM_LEVELS - 1'.
711 */
712 bool_Bool using_qmatrix;
713 /**
714 * \name Valid only when using_qmatrix == true
715 * Indicate the level indices to be used to access appropriate global quant
716 * matrix tables.
717 */
718 /**@{*/
719 int qmatrix_level_y; /*!< Level index for Y plane */
720 int qmatrix_level_u; /*!< Level index for U plane */
721 int qmatrix_level_v; /*!< Level index for V plane */
722 /**@}*/
723};
724
725typedef struct CommonContexts CommonContexts;
726/*!
727 * \brief Contexts used for transmitting various symbols in the bitstream.
728 */
729struct CommonContexts {
730 /*!
731 * Context used by 'FRAME_CONTEXT.partition_cdf' to transmit partition type.
732 * partition[i][j] is the context for ith tile row, jth mi_col.
733 */
734 PARTITION_CONTEXT **partition;
735
736 /*!
737 * Context used to derive context for multiple symbols:
738 * - 'TXB_CTX.txb_skip_ctx' used by 'FRAME_CONTEXT.txb_skip_cdf' to transmit
739 * to transmit skip_txfm flag.
740 * - 'TXB_CTX.dc_sign_ctx' used by 'FRAME_CONTEXT.dc_sign_cdf' to transmit
741 * sign.
742 * entropy[i][j][k] is the context for ith plane, jth tile row, kth mi_col.
743 */
744 ENTROPY_CONTEXT **entropy[MAX_MB_PLANE3];
745
746 /*!
747 * Context used to derive context for 'FRAME_CONTEXT.txfm_partition_cdf' to
748 * transmit 'is_split' flag to indicate if this transform block should be
749 * split into smaller sub-blocks.
750 * txfm[i][j] is the context for ith tile row, jth mi_col.
751 */
752 TXFM_CONTEXT **txfm;
753
754 /*!
755 * Dimensions that were used to allocate the arrays above.
756 * If these dimensions change, the arrays may have to be re-allocated.
757 */
758 int num_planes; /*!< Corresponds to av1_num_planes(cm) */
759 int num_tile_rows; /*!< Corresponds to cm->tiles.row */
760 int num_mi_cols; /*!< Corresponds to cm->mi_params.mi_cols */
761};
762
763/*!
764 * \brief Top level common structure used by both encoder and decoder.
765 */
766typedef struct AV1Common {
Excessive padding in 'struct AV1Common' (39 padding bytes, where 7 is optimal). Optimal fields order: lf_info, error, prev_frame, cur_frame, last_frame_seg_map, rst_tmpbuf, rlbs, seq_params, fc, default_frame_context, buffer_pool, tpl_mvs, above_contexts, ref_frame_map, mi_params, rst_info, rst_frame, cdef_info, quant_params, width, height, render_width, render_height, superres_upscaled_width, superres_upscaled_height, frame_presentation_time, show_frame, showable_frame, show_existing_frame, current_frame_id, tpl_mvs_mem_size, temporal_layer_id, spatial_layer_id, sf_identity, delta_q_info, features, remapped_ref_idx, ref_frame_id, ref_frame_sign_bias, current_frame, lf, ref_scale_factors, buffer_removal_times, seg, global_motion, tiles, film_grain_params, superres_scale_denominator, ref_frame_side, consider reordering the fields or adding explicit padding members
767 /*!
768 * Information about the current frame that is being coded.
769 */
770 CurrentFrame current_frame;
771 /*!
772 * Code and details about current error status.
773 */
774 struct aom_internal_error_info *error;
775
776 /*!
777 * AV1 allows two types of frame scaling operations:
778 * 1. Frame super-resolution: that allows coding a frame at lower resolution
779 * and after decoding the frame, normatively scales and restores the frame --
780 * inside the coding loop.
781 * 2. Frame resize: that allows coding frame at lower/higher resolution, and
782 * then non-normatively upscale the frame at the time of rendering -- outside
783 * the coding loop.
784 * Hence, the need for 3 types of dimensions.
785 */
786
787 /**
788 * \name Coded frame dimensions.
789 */
790 /**@{*/
791 int width; /*!< Coded frame width */
792 int height; /*!< Coded frame height */
793 /**@}*/
794
795 /**
796 * \name Rendered frame dimensions.
797 * Dimensions after applying both super-resolution and resize to the coded
798 * frame. Different from coded dimensions if super-resolution and/or resize
799 * are being used for this frame.
800 */
801 /**@{*/
802 int render_width; /*!< Rendered frame width */
803 int render_height; /*!< Rendered frame height */
804 /**@}*/
805
806 /**
807 * \name Super-resolved frame dimensions.
808 * Frame dimensions after applying super-resolution to the coded frame (if
809 * present), but before applying resize.
810 * Larger than the coded dimensions if super-resolution is being used for
811 * this frame.
812 * Different from rendered dimensions if resize is being used for this frame.
813 */
814 /**@{*/
815 int superres_upscaled_width; /*!< Super-resolved frame width */
816 int superres_upscaled_height; /*!< Super-resolved frame height */
817 /**@}*/
818
819 /*!
820 * The denominator of the superres scale used by this frame.
821 * Note: The numerator is fixed to be SCALE_NUMERATOR.
822 */
823 uint8_t superres_scale_denominator;
824
825 /*!
826 * buffer_removal_times[op_num] specifies the frame removal time in units of
827 * DecCT clock ticks counted from the removal time of the last random access
828 * point for operating point op_num.
829 * TODO(urvang): We probably don't need the +1 here.
830 */
831 uint32_t buffer_removal_times[MAX_NUM_OPERATING_POINTS(8 * 4) + 1];
832 /*!
833 * Presentation time of the frame in clock ticks DispCT counted from the
834 * removal time of the last random access point for the operating point that
835 * is being decoded.
836 */
837 uint32_t frame_presentation_time;
838
839 /*!
840 * Buffer where previous frame is stored.
841 */
842 RefCntBuffer *prev_frame;
843
844 /*!
845 * Buffer into which the current frame will be stored and other related info.
846 * TODO(hkuang): Combine this with cur_buf in macroblockd.
847 */
848 RefCntBuffer *cur_frame;
849
850 /*!
851 * For encoder, we have a two-level mapping from reference frame type to the
852 * corresponding buffer in the buffer pool:
853 * * 'remapped_ref_idx[i - 1]' maps reference type 'i' (range: LAST_FRAME ...
854 * EXTREF_FRAME) to a remapped index 'j' (in range: 0 ... REF_FRAMES - 1)
855 * * Later, 'cm->ref_frame_map[j]' maps the remapped index 'j' to a pointer to
856 * the reference counted buffer structure RefCntBuffer, taken from the buffer
857 * pool cm->buffer_pool->frame_bufs.
858 *
859 * LAST_FRAME, ..., EXTREF_FRAME
860 * | |
861 * v v
862 * remapped_ref_idx[LAST_FRAME - 1], ..., remapped_ref_idx[EXTREF_FRAME - 1]
863 * | |
864 * v v
865 * ref_frame_map[], ..., ref_frame_map[]
866 *
867 * Note: INTRA_FRAME always refers to the current frame, so there's no need to
868 * have a remapped index for the same.
869 */
870 int remapped_ref_idx[REF_FRAMES];
871
872 /*!
873 * Scale of the current frame with respect to itself.
874 * This is currently used for intra block copy, which behaves like an inter
875 * prediction mode, where the reference frame is the current frame itself.
876 */
877 struct scale_factors sf_identity;
878
879 /*!
880 * Scale factors of the reference frame with respect to the current frame.
881 * This is required for generating inter prediction and will be non-identity
882 * for a reference frame, if it has different dimensions than the coded
883 * dimensions of the current frame.
884 */
885 struct scale_factors ref_scale_factors[REF_FRAMES];
886
887 /*!
888 * For decoder, ref_frame_map[i] maps reference type 'i' to a pointer to
889 * the buffer in the buffer pool 'cm->buffer_pool.frame_bufs'.
890 * For encoder, ref_frame_map[j] (where j = remapped_ref_idx[i]) maps
891 * remapped reference index 'j' (that is, original reference type 'i') to
892 * a pointer to the buffer in the buffer pool 'cm->buffer_pool.frame_bufs'.
893 */
894 RefCntBuffer *ref_frame_map[REF_FRAMES];
895
896 /*!
897 * If true, this frame is actually shown after decoding.
898 * If false, this frame is coded in the bitstream, but not shown. It is only
899 * used as a reference for other frames coded later.
900 */
901 int show_frame;
902
903 /*!
904 * If true, this frame can be used as a show-existing frame for other frames
905 * coded later.
906 * When 'show_frame' is true, this is always true for all non-keyframes.
907 * When 'show_frame' is false, this value is transmitted in the bitstream.
908 */
909 int showable_frame;
910
911 /*!
912 * If true, show an existing frame coded before, instead of actually coding a
913 * frame. The existing frame comes from one of the existing reference buffers,
914 * as signaled in the bitstream.
915 */
916 int show_existing_frame;
917
918 /*!
919 * Whether some features are allowed or not.
920 */
921 FeatureFlags features;
922
923 /*!
924 * Params related to MB_MODE_INFO arrays and related info.
925 */
926 CommonModeInfoParams mi_params;
927
928#if CONFIG_ENTROPY_STATS0
929 /*!
930 * Context type used by token CDFs, in the range 0 .. (TOKEN_CDF_Q_CTXS - 1).
931 */
932 int coef_cdf_category;
933#endif // CONFIG_ENTROPY_STATS
934
935 /*!
936 * Quantization params.
937 */
938 CommonQuantParams quant_params;
939
940 /*!
941 * Segmentation info for current frame.
942 */
943 struct segmentation seg;
944
945 /*!
946 * Segmentation map for previous frame.
947 */
948 uint8_t *last_frame_seg_map;
949
950 /**
951 * \name Deblocking filter parameters.
952 */
953 /**@{*/
954 loop_filter_info_n lf_info; /*!< Loop filter info */
955 struct loopfilter lf; /*!< Loop filter parameters */
956 /**@}*/
957
958 /**
959 * \name Loop Restoration filter parameters.
960 */
961 /**@{*/
962 RestorationInfo rst_info[MAX_MB_PLANE3]; /*!< Loop Restoration filter info */
963 int32_t *rst_tmpbuf; /*!< Scratch buffer for self-guided restoration */
964 RestorationLineBuffers *rlbs; /*!< Line buffers needed by loop restoration */
965 YV12_BUFFER_CONFIG rst_frame; /*!< Stores the output of loop restoration */
966 /**@}*/
967
968 /*!
969 * CDEF (Constrained Directional Enhancement Filter) parameters.
970 */
971 CdefInfo cdef_info;
972
973 /*!
974 * Parameters for film grain synthesis.
975 */
976 aom_film_grain_t film_grain_params;
977
978 /*!
979 * Parameters for delta quantization and delta loop filter level.
980 */
981 DeltaQInfo delta_q_info;
982
983 /*!
984 * Global motion parameters for each reference frame.
985 */
986 WarpedMotionParams global_motion[REF_FRAMES];
987
988 /*!
989 * Elements part of the sequence header, that are applicable for all the
990 * frames in the video.
991 */
992 SequenceHeader *seq_params;
993
994 /*!
995 * Current CDFs of all the symbols for the current frame.
996 */
997 FRAME_CONTEXT *fc;
998 /*!
999 * Default CDFs used when features.primary_ref_frame = PRIMARY_REF_NONE
1000 * (e.g. for a keyframe). These default CDFs are defined by the bitstream and
1001 * copied from default CDF tables for each symbol.
1002 */
1003 FRAME_CONTEXT *default_frame_context;
1004
1005 /*!
1006 * Parameters related to tiling.
1007 */
1008 CommonTileParams tiles;
1009
1010 /*!
1011 * External BufferPool passed from outside.
1012 */
1013 BufferPool *buffer_pool;
1014
1015 /*!
1016 * Above context buffers and their sizes.
1017 * Note: above contexts are allocated in this struct, as their size is
1018 * dependent on frame width, while left contexts are declared and allocated in
1019 * MACROBLOCKD struct, as they have a fixed size.
1020 */
1021 CommonContexts above_contexts;
1022
1023 /**
1024 * \name Signaled when cm->seq_params->frame_id_numbers_present_flag == 1
1025 */
1026 /**@{*/
1027 int current_frame_id; /*!< frame ID for the current frame. */
1028 int ref_frame_id[REF_FRAMES]; /*!< frame IDs for the reference frames. */
1029 /**@}*/
1030
1031 /*!
1032 * Motion vectors provided by motion field estimation.
1033 * tpl_mvs[row * stride + col] stores MV for block at [mi_row, mi_col] where:
1034 * mi_row = 2 * row,
1035 * mi_col = 2 * col, and
1036 * stride = cm->mi_params.mi_stride / 2
1037 */
1038 TPL_MV_REF *tpl_mvs;
1039 /*!
1040 * Allocated size of 'tpl_mvs' array. Refer to 'ensure_mv_buffer()' function.
1041 */
1042 int tpl_mvs_mem_size;
1043 /*!
1044 * ref_frame_sign_bias[k] is 1 if relative distance between reference 'k' and
1045 * current frame is positive; and 0 otherwise.
1046 */
1047 int ref_frame_sign_bias[REF_FRAMES];
1048 /*!
1049 * ref_frame_side[k] is 1 if relative distance between reference 'k' and
1050 * current frame is positive, -1 if relative distance is 0; and 0 otherwise.
1051 * TODO(jingning): This can be combined with sign_bias later.
1052 */
1053 int8_t ref_frame_side[REF_FRAMES];
1054
1055 /*!
1056 * Temporal layer ID of this frame
1057 * (in the range 0 ... (number_temporal_layers - 1)).
1058 */
1059 int temporal_layer_id;
1060
1061 /*!
1062 * Spatial layer ID of this frame
1063 * (in the range 0 ... (number_spatial_layers - 1)).
1064 */
1065 int spatial_layer_id;
1066
1067#if TXCOEFF_TIMER0
1068 int64_t cum_txcoeff_timer;
1069 int64_t txcoeff_timer;
1070 int txb_count;
1071#endif // TXCOEFF_TIMER
1072
1073#if TXCOEFF_COST_TIMER0
1074 int64_t cum_txcoeff_cost_timer;
1075 int64_t txcoeff_cost_timer;
1076 int64_t txcoeff_cost_count;
1077#endif // TXCOEFF_COST_TIMER
1078} AV1_COMMON;
1079
1080/*!\cond */
1081
1082// TODO(hkuang): Don't need to lock the whole pool after implementing atomic
1083// frame reference count.
1084static void lock_buffer_pool(BufferPool *const pool) {
1085#if CONFIG_MULTITHREAD1
1086 pthread_mutex_lock(&pool->pool_mutex);
1087#else
1088 (void)pool;
1089#endif
1090}
1091
1092static void unlock_buffer_pool(BufferPool *const pool) {
1093#if CONFIG_MULTITHREAD1
1094 pthread_mutex_unlock(&pool->pool_mutex);
1095#else
1096 (void)pool;
1097#endif
1098}
1099
1100static inline YV12_BUFFER_CONFIG *get_ref_frame(AV1_COMMON *cm, int index) {
1101 if (index < 0 || index >= REF_FRAMES) return NULL((void*)0);
1102 if (cm->ref_frame_map[index] == NULL((void*)0)) return NULL((void*)0);
1103 return &cm->ref_frame_map[index]->buf;
1104}
1105
1106static inline int get_free_fb(AV1_COMMON *cm) {
1107 RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs;
1108 int i;
1109
1110 lock_buffer_pool(cm->buffer_pool);
1111 const int num_frame_bufs = cm->buffer_pool->num_frame_bufs;
1112 for (i = 0; i < num_frame_bufs; ++i)
1113 if (frame_bufs[i].ref_count == 0) break;
1114
1115 if (i != num_frame_bufs) {
1116 if (frame_bufs[i].buf.use_external_reference_buffers) {
1117 // If this frame buffer's y_buffer, u_buffer, and v_buffer point to the
1118 // external reference buffers. Restore the buffer pointers to point to the
1119 // internally allocated memory.
1120 YV12_BUFFER_CONFIG *ybf = &frame_bufs[i].buf;
1121 ybf->y_buffer = ybf->store_buf_adr[0];
1122 ybf->u_buffer = ybf->store_buf_adr[1];
1123 ybf->v_buffer = ybf->store_buf_adr[2];
1124 ybf->use_external_reference_buffers = 0;
1125 }
1126
1127 frame_bufs[i].ref_count = 1;
1128 } else {
1129 // We should never run out of free buffers. If this assertion fails, there
1130 // is a reference leak.
1131 assert(0 && "Ran out of free frame buffers. Likely a reference leak.")((void) sizeof ((0 && "Ran out of free frame buffers. Likely a reference leak."
) ? 1 : 0), __extension__ ({ if (0 && "Ran out of free frame buffers. Likely a reference leak."
) ; else __assert_fail ("0 && \"Ran out of free frame buffers. Likely a reference leak.\""
, "/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1131, __extension__ __PRETTY_FUNCTION__); }))
;
1132 // Reset i to be INVALID_IDX to indicate no free buffer found.
1133 i = INVALID_IDX-1;
1134 }
1135
1136 unlock_buffer_pool(cm->buffer_pool);
1137 return i;
1138}
1139
1140static inline RefCntBuffer *assign_cur_frame_new_fb(AV1_COMMON *const cm) {
1141 // Release the previously-used frame-buffer
1142 if (cm->cur_frame != NULL((void*)0)) {
1143 --cm->cur_frame->ref_count;
1144 cm->cur_frame = NULL((void*)0);
1145 }
1146
1147 // Assign a new framebuffer
1148 const int new_fb_idx = get_free_fb(cm);
1149 if (new_fb_idx == INVALID_IDX-1) return NULL((void*)0);
1150
1151 cm->cur_frame = &cm->buffer_pool->frame_bufs[new_fb_idx];
1152#if CONFIG_AV1_ENCODER1 && !CONFIG_REALTIME_ONLY0
1153 aom_invalidate_pyramid(cm->cur_frame->buf.y_pyramid);
1154 av1_invalidate_corner_list(cm->cur_frame->buf.corners);
1155#endif // CONFIG_AV1_ENCODER && !CONFIG_REALTIME_ONLY
1156 av1_zero(cm->cur_frame->interp_filter_selected)memset(&(cm->cur_frame->interp_filter_selected), 0,
sizeof(cm->cur_frame->interp_filter_selected))
;
1157 return cm->cur_frame;
1158}
1159
1160// Modify 'lhs_ptr' to reference the buffer at 'rhs_ptr', and update the ref
1161// counts accordingly.
1162static inline void assign_frame_buffer_p(RefCntBuffer **lhs_ptr,
1163 RefCntBuffer *rhs_ptr) {
1164 RefCntBuffer *const old_ptr = *lhs_ptr;
1165 if (old_ptr != NULL((void*)0)) {
1166 assert(old_ptr->ref_count > 0)((void) sizeof ((old_ptr->ref_count > 0) ? 1 : 0), __extension__
({ if (old_ptr->ref_count > 0) ; else __assert_fail ("old_ptr->ref_count > 0"
, "/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1166, __extension__ __PRETTY_FUNCTION__); }))
;
1167 // One less reference to the buffer at 'old_ptr', so decrease ref count.
1168 --old_ptr->ref_count;
1169 }
1170
1171 *lhs_ptr = rhs_ptr;
1172 // One more reference to the buffer at 'rhs_ptr', so increase ref count.
1173 ++rhs_ptr->ref_count;
1174}
1175
1176static inline int frame_is_intra_only(const AV1_COMMON *const cm) {
1177 return cm->current_frame.frame_type == KEY_FRAME ||
1178 cm->current_frame.frame_type == INTRA_ONLY_FRAME;
1179}
1180
1181static inline int frame_is_sframe(const AV1_COMMON *cm) {
1182 return cm->current_frame.frame_type == S_FRAME;
1183}
1184
1185// These functions take a reference frame label between LAST_FRAME and
1186// EXTREF_FRAME inclusive. Note that this is different to the indexing
1187// previously used by the frame_refs[] array.
1188static inline int get_ref_frame_map_idx(const AV1_COMMON *const cm,
1189 const MV_REFERENCE_FRAME ref_frame) {
1190 return (ref_frame >= LAST_FRAME && ref_frame <= EXTREF_FRAME)
1191 ? cm->remapped_ref_idx[ref_frame - LAST_FRAME]
1192 : INVALID_IDX-1;
1193}
1194
1195static inline RefCntBuffer *get_ref_frame_buf(
1196 const AV1_COMMON *const cm, const MV_REFERENCE_FRAME ref_frame) {
1197 const int map_idx = get_ref_frame_map_idx(cm, ref_frame);
1198 return (map_idx != INVALID_IDX-1) ? cm->ref_frame_map[map_idx] : NULL((void*)0);
1199}
1200
1201// Both const and non-const versions of this function are provided so that it
1202// can be used with a const AV1_COMMON if needed.
1203static inline const struct scale_factors *get_ref_scale_factors_const(
1204 const AV1_COMMON *const cm, const MV_REFERENCE_FRAME ref_frame) {
1205 const int map_idx = get_ref_frame_map_idx(cm, ref_frame);
1206 return (map_idx != INVALID_IDX-1) ? &cm->ref_scale_factors[map_idx] : NULL((void*)0);
1207}
1208
1209static inline struct scale_factors *get_ref_scale_factors(
1210 AV1_COMMON *const cm, const MV_REFERENCE_FRAME ref_frame) {
1211 const int map_idx = get_ref_frame_map_idx(cm, ref_frame);
1212 return (map_idx != INVALID_IDX-1) ? &cm->ref_scale_factors[map_idx] : NULL((void*)0);
1213}
1214
1215static inline RefCntBuffer *get_primary_ref_frame_buf(
1216 const AV1_COMMON *const cm) {
1217 const int primary_ref_frame = cm->features.primary_ref_frame;
1218 if (primary_ref_frame == PRIMARY_REF_NONE7) return NULL((void*)0);
1219 const int map_idx = get_ref_frame_map_idx(cm, primary_ref_frame + 1);
1220 return (map_idx != INVALID_IDX-1) ? cm->ref_frame_map[map_idx] : NULL((void*)0);
1221}
1222
1223// Returns 1 if this frame might allow mvs from some reference frame.
1224static inline int frame_might_allow_ref_frame_mvs(const AV1_COMMON *cm) {
1225 return !cm->features.error_resilient_mode &&
1226 cm->seq_params->order_hint_info.enable_ref_frame_mvs &&
1227 cm->seq_params->order_hint_info.enable_order_hint &&
1228 !frame_is_intra_only(cm);
1229}
1230
1231// Returns 1 if this frame might use warped_motion
1232static inline int frame_might_allow_warped_motion(const AV1_COMMON *cm) {
1233 return !cm->features.error_resilient_mode && !frame_is_intra_only(cm) &&
1234 cm->seq_params->enable_warped_motion;
1235}
1236
1237static inline void ensure_mv_buffer(RefCntBuffer *buf, AV1_COMMON *cm) {
1238 const int buf_rows = buf->mi_rows;
1239 const int buf_cols = buf->mi_cols;
1240 const CommonModeInfoParams *const mi_params = &cm->mi_params;
1241
1242 if (buf->mvs == NULL((void*)0) || buf_rows != mi_params->mi_rows ||
1243 buf_cols != mi_params->mi_cols) {
1244 aom_free(buf->mvs);
1245 buf->mi_rows = mi_params->mi_rows;
1246 buf->mi_cols = mi_params->mi_cols;
1247 CHECK_MEM_ERROR(cm, buf->mvs,do { ((void) sizeof ((((cm)->error)->setjmp) ? 1 : 0), __extension__
({ if (((cm)->error)->setjmp) ; else __assert_fail ("((cm)->error)->setjmp"
, "/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1250, __extension__ __PRETTY_FUNCTION__); })); buf->mvs =
((MV_REF *)aom_calloc(((mi_params->mi_rows + 1) >> 1
) * ((mi_params->mi_cols + 1) >> 1), sizeof(*buf->
mvs))); if (!buf->mvs) aom_internal_error((cm)->error, AOM_CODEC_MEM_ERROR
, "Failed to allocate " "buf->mvs"); } while (0)
1248 (MV_REF *)aom_calloc(((mi_params->mi_rows + 1) >> 1) *do { ((void) sizeof ((((cm)->error)->setjmp) ? 1 : 0), __extension__
({ if (((cm)->error)->setjmp) ; else __assert_fail ("((cm)->error)->setjmp"
, "/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1250, __extension__ __PRETTY_FUNCTION__); })); buf->mvs =
((MV_REF *)aom_calloc(((mi_params->mi_rows + 1) >> 1
) * ((mi_params->mi_cols + 1) >> 1), sizeof(*buf->
mvs))); if (!buf->mvs) aom_internal_error((cm)->error, AOM_CODEC_MEM_ERROR
, "Failed to allocate " "buf->mvs"); } while (0)
1249 ((mi_params->mi_cols + 1) >> 1),do { ((void) sizeof ((((cm)->error)->setjmp) ? 1 : 0), __extension__
({ if (((cm)->error)->setjmp) ; else __assert_fail ("((cm)->error)->setjmp"
, "/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1250, __extension__ __PRETTY_FUNCTION__); })); buf->mvs =
((MV_REF *)aom_calloc(((mi_params->mi_rows + 1) >> 1
) * ((mi_params->mi_cols + 1) >> 1), sizeof(*buf->
mvs))); if (!buf->mvs) aom_internal_error((cm)->error, AOM_CODEC_MEM_ERROR
, "Failed to allocate " "buf->mvs"); } while (0)
1250 sizeof(*buf->mvs)))do { ((void) sizeof ((((cm)->error)->setjmp) ? 1 : 0), __extension__
({ if (((cm)->error)->setjmp) ; else __assert_fail ("((cm)->error)->setjmp"
, "/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1250, __extension__ __PRETTY_FUNCTION__); })); buf->mvs =
((MV_REF *)aom_calloc(((mi_params->mi_rows + 1) >> 1
) * ((mi_params->mi_cols + 1) >> 1), sizeof(*buf->
mvs))); if (!buf->mvs) aom_internal_error((cm)->error, AOM_CODEC_MEM_ERROR
, "Failed to allocate " "buf->mvs"); } while (0)
;
1251 aom_free(buf->seg_map);
1252 CHECK_MEM_ERROR(do { ((void) sizeof ((((cm)->error)->setjmp) ? 1 : 0), __extension__
({ if (((cm)->error)->setjmp) ; else __assert_fail ("((cm)->error)->setjmp"
, "/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1255, __extension__ __PRETTY_FUNCTION__); })); buf->seg_map
= ((uint8_t *)aom_calloc(mi_params->mi_rows * mi_params->
mi_cols, sizeof(*buf->seg_map))); if (!buf->seg_map) aom_internal_error
((cm)->error, AOM_CODEC_MEM_ERROR, "Failed to allocate " "buf->seg_map"
); } while (0)
1253 cm, buf->seg_map,do { ((void) sizeof ((((cm)->error)->setjmp) ? 1 : 0), __extension__
({ if (((cm)->error)->setjmp) ; else __assert_fail ("((cm)->error)->setjmp"
, "/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1255, __extension__ __PRETTY_FUNCTION__); })); buf->seg_map
= ((uint8_t *)aom_calloc(mi_params->mi_rows * mi_params->
mi_cols, sizeof(*buf->seg_map))); if (!buf->seg_map) aom_internal_error
((cm)->error, AOM_CODEC_MEM_ERROR, "Failed to allocate " "buf->seg_map"
); } while (0)
1254 (uint8_t *)aom_calloc(mi_params->mi_rows * mi_params->mi_cols,do { ((void) sizeof ((((cm)->error)->setjmp) ? 1 : 0), __extension__
({ if (((cm)->error)->setjmp) ; else __assert_fail ("((cm)->error)->setjmp"
, "/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1255, __extension__ __PRETTY_FUNCTION__); })); buf->seg_map
= ((uint8_t *)aom_calloc(mi_params->mi_rows * mi_params->
mi_cols, sizeof(*buf->seg_map))); if (!buf->seg_map) aom_internal_error
((cm)->error, AOM_CODEC_MEM_ERROR, "Failed to allocate " "buf->seg_map"
); } while (0)
1255 sizeof(*buf->seg_map)))do { ((void) sizeof ((((cm)->error)->setjmp) ? 1 : 0), __extension__
({ if (((cm)->error)->setjmp) ; else __assert_fail ("((cm)->error)->setjmp"
, "/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1255, __extension__ __PRETTY_FUNCTION__); })); buf->seg_map
= ((uint8_t *)aom_calloc(mi_params->mi_rows * mi_params->
mi_cols, sizeof(*buf->seg_map))); if (!buf->seg_map) aom_internal_error
((cm)->error, AOM_CODEC_MEM_ERROR, "Failed to allocate " "buf->seg_map"
); } while (0)
;
1256 }
1257
1258 const int mem_size =
1259 ((mi_params->mi_rows + MAX_MIB_SIZE(1 << (7 - 2))) >> 1) * (mi_params->mi_stride >> 1);
1260
1261 if (cm->tpl_mvs == NULL((void*)0) || cm->tpl_mvs_mem_size < mem_size) {
1262 aom_free(cm->tpl_mvs);
1263 CHECK_MEM_ERROR(cm, cm->tpl_mvs,do { ((void) sizeof ((((cm)->error)->setjmp) ? 1 : 0), __extension__
({ if (((cm)->error)->setjmp) ; else __assert_fail ("((cm)->error)->setjmp"
, "/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1264, __extension__ __PRETTY_FUNCTION__); })); cm->tpl_mvs
= ((TPL_MV_REF *)aom_calloc(mem_size, sizeof(*cm->tpl_mvs
))); if (!cm->tpl_mvs) aom_internal_error((cm)->error, AOM_CODEC_MEM_ERROR
, "Failed to allocate " "cm->tpl_mvs"); } while (0)
1264 (TPL_MV_REF *)aom_calloc(mem_size, sizeof(*cm->tpl_mvs)))do { ((void) sizeof ((((cm)->error)->setjmp) ? 1 : 0), __extension__
({ if (((cm)->error)->setjmp) ; else __assert_fail ("((cm)->error)->setjmp"
, "/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1264, __extension__ __PRETTY_FUNCTION__); })); cm->tpl_mvs
= ((TPL_MV_REF *)aom_calloc(mem_size, sizeof(*cm->tpl_mvs
))); if (!cm->tpl_mvs) aom_internal_error((cm)->error, AOM_CODEC_MEM_ERROR
, "Failed to allocate " "cm->tpl_mvs"); } while (0)
;
1265 cm->tpl_mvs_mem_size = mem_size;
1266 }
1267}
1268
1269#if !CONFIG_REALTIME_ONLY0 || CONFIG_AV1_DECODER1
1270void cfl_init(CFL_CTX *cfl, const SequenceHeader *seq_params);
1271#endif
1272
1273static inline int av1_num_planes(const AV1_COMMON *cm) {
1274 return cm->seq_params->monochrome ? 1 : MAX_MB_PLANE3;
1275}
1276
1277static inline void av1_init_above_context(CommonContexts *above_contexts,
1278 int num_planes, int tile_row,
1279 MACROBLOCKD *xd) {
1280 for (int i = 0; i < num_planes; ++i) {
1281 xd->above_entropy_context[i] = above_contexts->entropy[i][tile_row];
1282 }
1283 xd->above_partition_context = above_contexts->partition[tile_row];
1284 xd->above_txfm_context = above_contexts->txfm[tile_row];
1285}
1286
1287static inline void av1_init_macroblockd(AV1_COMMON *cm, MACROBLOCKD *xd) {
1288 const int num_planes = av1_num_planes(cm);
1289 const CommonQuantParams *const quant_params = &cm->quant_params;
1290
1291 for (int i = 0; i < num_planes; ++i) {
1292 if (xd->plane[i].plane_type == PLANE_TYPE_Y) {
1293 memcpy(xd->plane[i].seg_dequant_QTX, quant_params->y_dequant_QTX,
1294 sizeof(quant_params->y_dequant_QTX));
1295 memcpy(xd->plane[i].seg_iqmatrix, quant_params->y_iqmatrix,
1296 sizeof(quant_params->y_iqmatrix));
1297
1298 } else {
1299 if (i == AOM_PLANE_U1) {
1300 memcpy(xd->plane[i].seg_dequant_QTX, quant_params->u_dequant_QTX,
1301 sizeof(quant_params->u_dequant_QTX));
1302 memcpy(xd->plane[i].seg_iqmatrix, quant_params->u_iqmatrix,
1303 sizeof(quant_params->u_iqmatrix));
1304 } else {
1305 memcpy(xd->plane[i].seg_dequant_QTX, quant_params->v_dequant_QTX,
1306 sizeof(quant_params->v_dequant_QTX));
1307 memcpy(xd->plane[i].seg_iqmatrix, quant_params->v_iqmatrix,
1308 sizeof(quant_params->v_iqmatrix));
1309 }
1310 }
1311 }
1312 xd->mi_stride = cm->mi_params.mi_stride;
1313 xd->error_info = cm->error;
1314#if !CONFIG_REALTIME_ONLY0 || CONFIG_AV1_DECODER1
1315 cfl_init(&xd->cfl, cm->seq_params);
1316#endif
1317}
1318
1319static inline void set_entropy_context(MACROBLOCKD *xd, int mi_row, int mi_col,
1320 const int num_planes) {
1321 int i;
1322 int row_offset = mi_row;
1323 int col_offset = mi_col;
1324 for (i = 0; i < num_planes; ++i) {
1325 struct macroblockd_plane *const pd = &xd->plane[i];
1326 // Offset the buffer pointer
1327 const BLOCK_SIZE bsize = xd->mi[0]->bsize;
1328 if (pd->subsampling_y && (mi_row & 0x01) && (mi_size_high[bsize] == 1))
1329 row_offset = mi_row - 1;
1330 if (pd->subsampling_x && (mi_col & 0x01) && (mi_size_wide[bsize] == 1))
1331 col_offset = mi_col - 1;
1332 int above_idx = col_offset;
1333 int left_idx = row_offset & MAX_MIB_MASK((1 << (7 - 2)) - 1);
1334 pd->above_entropy_context =
1335 &xd->above_entropy_context[i][above_idx >> pd->subsampling_x];
1336 pd->left_entropy_context =
1337 &xd->left_entropy_context[i][left_idx >> pd->subsampling_y];
1338 }
1339}
1340
1341static inline int calc_mi_size(int len) {
1342 // len is in mi units. Align to a multiple of SBs.
1343 return ALIGN_POWER_OF_TWO(len, MAX_MIB_SIZE_LOG2)(((len) + ((1 << ((7 - 2))) - 1)) & ~((1 << (
(7 - 2))) - 1))
;
1344}
1345
1346static inline void set_plane_n4(MACROBLOCKD *const xd, int bw, int bh,
1347 const int num_planes) {
1348 int i;
1349 for (i = 0; i < num_planes; i++) {
1350 xd->plane[i].width = (bw * MI_SIZE(1 << 2)) >> xd->plane[i].subsampling_x;
1351 xd->plane[i].height = (bh * MI_SIZE(1 << 2)) >> xd->plane[i].subsampling_y;
1352
1353 xd->plane[i].width = AOMMAX(xd->plane[i].width, 4)(((xd->plane[i].width) > (4)) ? (xd->plane[i].width)
: (4))
;
1354 xd->plane[i].height = AOMMAX(xd->plane[i].height, 4)(((xd->plane[i].height) > (4)) ? (xd->plane[i].height
) : (4))
;
1355 }
1356}
1357
1358static inline void set_mi_row_col(MACROBLOCKD *xd, const TileInfo *const tile,
1359 int mi_row, int bh, int mi_col, int bw,
1360 int mi_rows, int mi_cols) {
1361 xd->mb_to_top_edge = -GET_MV_SUBPEL(mi_row * MI_SIZE)((mi_row * (1 << 2)) * 8);
1362 xd->mb_to_bottom_edge = GET_MV_SUBPEL((mi_rows - bh - mi_row) * MI_SIZE)(((mi_rows - bh - mi_row) * (1 << 2)) * 8);
1363 xd->mb_to_left_edge = -GET_MV_SUBPEL((mi_col * MI_SIZE))(((mi_col * (1 << 2))) * 8);
1364 xd->mb_to_right_edge = GET_MV_SUBPEL((mi_cols - bw - mi_col) * MI_SIZE)(((mi_cols - bw - mi_col) * (1 << 2)) * 8);
1365
1366 xd->mi_row = mi_row;
1367 xd->mi_col = mi_col;
1368
1369 // Are edges available for intra prediction?
1370 xd->up_available = (mi_row > tile->mi_row_start);
1371
1372 const int ss_x = xd->plane[1].subsampling_x;
1373 const int ss_y = xd->plane[1].subsampling_y;
1374
1375 xd->left_available = (mi_col > tile->mi_col_start);
1376 xd->chroma_up_available = xd->up_available;
1377 xd->chroma_left_available = xd->left_available;
1378 if (ss_x && bw < mi_size_wide[BLOCK_8X8])
1379 xd->chroma_left_available = (mi_col - 1) > tile->mi_col_start;
1380 if (ss_y && bh < mi_size_high[BLOCK_8X8])
1381 xd->chroma_up_available = (mi_row - 1) > tile->mi_row_start;
1382 if (xd->up_available) {
1383 xd->above_mbmi = xd->mi[-xd->mi_stride];
1384 } else {
1385 xd->above_mbmi = NULL((void*)0);
1386 }
1387
1388 if (xd->left_available) {
1389 xd->left_mbmi = xd->mi[-1];
1390 } else {
1391 xd->left_mbmi = NULL((void*)0);
1392 }
1393
1394 const int chroma_ref = ((mi_row & 0x01) || !(bh & 0x01) || !ss_y) &&
1395 ((mi_col & 0x01) || !(bw & 0x01) || !ss_x);
1396 xd->is_chroma_ref = chroma_ref;
1397 if (chroma_ref) {
1398 // To help calculate the "above" and "left" chroma blocks, note that the
1399 // current block may cover multiple luma blocks (e.g., if partitioned into
1400 // 4x4 luma blocks).
1401 // First, find the top-left-most luma block covered by this chroma block
1402 MB_MODE_INFO **base_mi =
1403 &xd->mi[-(mi_row & ss_y) * xd->mi_stride - (mi_col & ss_x)];
1404
1405 // Then, we consider the luma region covered by the left or above 4x4 chroma
1406 // prediction. We want to point to the chroma reference block in that
1407 // region, which is the bottom-right-most mi unit.
1408 // This leads to the following offsets:
1409 MB_MODE_INFO *chroma_above_mi =
1410 xd->chroma_up_available ? base_mi[-xd->mi_stride + ss_x] : NULL((void*)0);
1411 xd->chroma_above_mbmi = chroma_above_mi;
1412
1413 MB_MODE_INFO *chroma_left_mi =
1414 xd->chroma_left_available ? base_mi[ss_y * xd->mi_stride - 1] : NULL((void*)0);
1415 xd->chroma_left_mbmi = chroma_left_mi;
1416 }
1417
1418 xd->height = bh;
1419 xd->width = bw;
1420
1421 xd->is_last_vertical_rect = 0;
1422 if (xd->width < xd->height) {
1423 if (!((mi_col + xd->width) & (xd->height - 1))) {
1424 xd->is_last_vertical_rect = 1;
1425 }
1426 }
1427
1428 xd->is_first_horizontal_rect = 0;
1429 if (xd->width > xd->height)
1430 if (!(mi_row & (xd->width - 1))) xd->is_first_horizontal_rect = 1;
1431}
1432
1433static inline aom_cdf_prob *get_y_mode_cdf(FRAME_CONTEXT *tile_ctx,
1434 const MB_MODE_INFO *above_mi,
1435 const MB_MODE_INFO *left_mi) {
1436 const PREDICTION_MODE above = av1_above_block_mode(above_mi);
1437 const PREDICTION_MODE left = av1_left_block_mode(left_mi);
1438 const int above_ctx = intra_mode_context[above];
1439 const int left_ctx = intra_mode_context[left];
1440 return tile_ctx->kf_y_cdf[above_ctx][left_ctx];
1441}
1442
1443static inline void update_partition_context(MACROBLOCKD *xd, int mi_row,
1444 int mi_col, BLOCK_SIZE subsize,
1445 BLOCK_SIZE bsize) {
1446 PARTITION_CONTEXT *const above_ctx = xd->above_partition_context + mi_col;
1447 PARTITION_CONTEXT *const left_ctx =
1448 xd->left_partition_context + (mi_row & MAX_MIB_MASK((1 << (7 - 2)) - 1));
1449
1450 const int bw = mi_size_wide[bsize];
1451 const int bh = mi_size_high[bsize];
1452 memset(above_ctx, partition_context_lookup[subsize].above, bw);
1453 memset(left_ctx, partition_context_lookup[subsize].left, bh);
1454}
1455
1456static inline int is_chroma_reference(int mi_row, int mi_col, BLOCK_SIZE bsize,
1457 int subsampling_x, int subsampling_y) {
1458 assert(bsize < BLOCK_SIZES_ALL)((void) sizeof ((bsize < BLOCK_SIZES_ALL) ? 1 : 0), __extension__
({ if (bsize < BLOCK_SIZES_ALL) ; else __assert_fail ("bsize < BLOCK_SIZES_ALL"
, "/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1458, __extension__ __PRETTY_FUNCTION__); }))
;
1459 const int bw = mi_size_wide[bsize];
1460 const int bh = mi_size_high[bsize];
1461 int ref_pos = ((mi_row & 0x01) || !(bh & 0x01) || !subsampling_y) &&
1462 ((mi_col & 0x01) || !(bw & 0x01) || !subsampling_x);
1463 return ref_pos;
1464}
1465
1466static inline aom_cdf_prob cdf_element_prob(const aom_cdf_prob *cdf,
1467 size_t element) {
1468 assert(cdf != NULL)((void) sizeof ((cdf != ((void*)0)) ? 1 : 0), __extension__ (
{ if (cdf != ((void*)0)) ; else __assert_fail ("cdf != NULL",
"/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1468, __extension__ __PRETTY_FUNCTION__); }))
;
1469 return (element > 0 ? cdf[element - 1] : CDF_PROB_TOP(1 << 15)) - cdf[element];
1470}
1471
1472static inline void partition_gather_horz_alike(aom_cdf_prob *out,
1473 const aom_cdf_prob *const in,
1474 BLOCK_SIZE bsize) {
1475 (void)bsize;
1476 out[0] = CDF_PROB_TOP(1 << 15);
1477 out[0] -= cdf_element_prob(in, PARTITION_HORZ);
1478 out[0] -= cdf_element_prob(in, PARTITION_SPLIT);
1479 out[0] -= cdf_element_prob(in, PARTITION_HORZ_A);
1480 out[0] -= cdf_element_prob(in, PARTITION_HORZ_B);
1481 out[0] -= cdf_element_prob(in, PARTITION_VERT_A);
1482 if (bsize != BLOCK_128X128) out[0] -= cdf_element_prob(in, PARTITION_HORZ_4);
1483 out[0] = AOM_ICDF(out[0])((1 << 15) - (out[0]));
1484 out[1] = AOM_ICDF(CDF_PROB_TOP)((1 << 15) - ((1 << 15)));
1485}
1486
1487static inline void partition_gather_vert_alike(aom_cdf_prob *out,
1488 const aom_cdf_prob *const in,
1489 BLOCK_SIZE bsize) {
1490 (void)bsize;
1491 out[0] = CDF_PROB_TOP(1 << 15);
1492 out[0] -= cdf_element_prob(in, PARTITION_VERT);
1493 out[0] -= cdf_element_prob(in, PARTITION_SPLIT);
1494 out[0] -= cdf_element_prob(in, PARTITION_HORZ_A);
1495 out[0] -= cdf_element_prob(in, PARTITION_VERT_A);
1496 out[0] -= cdf_element_prob(in, PARTITION_VERT_B);
1497 if (bsize != BLOCK_128X128) out[0] -= cdf_element_prob(in, PARTITION_VERT_4);
1498 out[0] = AOM_ICDF(out[0])((1 << 15) - (out[0]));
1499 out[1] = AOM_ICDF(CDF_PROB_TOP)((1 << 15) - ((1 << 15)));
1500}
1501
1502static inline void update_ext_partition_context(MACROBLOCKD *xd, int mi_row,
1503 int mi_col, BLOCK_SIZE subsize,
1504 BLOCK_SIZE bsize,
1505 PARTITION_TYPE partition) {
1506 if (bsize >= BLOCK_8X8) {
1507 const int hbs = mi_size_wide[bsize] / 2;
1508 BLOCK_SIZE bsize2 = get_partition_subsize(bsize, PARTITION_SPLIT);
1509 switch (partition) {
1510 case PARTITION_SPLIT:
1511 if (bsize != BLOCK_8X8) break;
1512 AOM_FALLTHROUGH_INTENDEDdo { } while (0);
1513 case PARTITION_NONE:
1514 case PARTITION_HORZ:
1515 case PARTITION_VERT:
1516 case PARTITION_HORZ_4:
1517 case PARTITION_VERT_4:
1518 update_partition_context(xd, mi_row, mi_col, subsize, bsize);
1519 break;
1520 case PARTITION_HORZ_A:
1521 update_partition_context(xd, mi_row, mi_col, bsize2, subsize);
1522 update_partition_context(xd, mi_row + hbs, mi_col, subsize, subsize);
1523 break;
1524 case PARTITION_HORZ_B:
1525 update_partition_context(xd, mi_row, mi_col, subsize, subsize);
1526 update_partition_context(xd, mi_row + hbs, mi_col, bsize2, subsize);
1527 break;
1528 case PARTITION_VERT_A:
1529 update_partition_context(xd, mi_row, mi_col, bsize2, subsize);
1530 update_partition_context(xd, mi_row, mi_col + hbs, subsize, subsize);
1531 break;
1532 case PARTITION_VERT_B:
1533 update_partition_context(xd, mi_row, mi_col, subsize, subsize);
1534 update_partition_context(xd, mi_row, mi_col + hbs, bsize2, subsize);
1535 break;
1536 default: assert(0 && "Invalid partition type")((void) sizeof ((0 && "Invalid partition type") ? 1 :
0), __extension__ ({ if (0 && "Invalid partition type"
) ; else __assert_fail ("0 && \"Invalid partition type\""
, "/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1536, __extension__ __PRETTY_FUNCTION__); }))
;
1537 }
1538 }
1539}
1540
1541static inline int partition_plane_context(const MACROBLOCKD *xd, int mi_row,
1542 int mi_col, BLOCK_SIZE bsize) {
1543 const PARTITION_CONTEXT *above_ctx = xd->above_partition_context + mi_col;
1544 const PARTITION_CONTEXT *left_ctx =
1545 xd->left_partition_context + (mi_row & MAX_MIB_MASK((1 << (7 - 2)) - 1));
1546 // Minimum partition point is 8x8. Offset the bsl accordingly.
1547 const int bsl = mi_size_wide_log2[bsize] - mi_size_wide_log2[BLOCK_8X8];
1548 int above = (*above_ctx >> bsl) & 1, left = (*left_ctx >> bsl) & 1;
1549
1550 assert(mi_size_wide_log2[bsize] == mi_size_high_log2[bsize])((void) sizeof ((mi_size_wide_log2[bsize] == mi_size_high_log2
[bsize]) ? 1 : 0), __extension__ ({ if (mi_size_wide_log2[bsize
] == mi_size_high_log2[bsize]) ; else __assert_fail ("mi_size_wide_log2[bsize] == mi_size_high_log2[bsize]"
, "/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1550, __extension__ __PRETTY_FUNCTION__); }))
;
1551 assert(bsl >= 0)((void) sizeof ((bsl >= 0) ? 1 : 0), __extension__ ({ if (
bsl >= 0) ; else __assert_fail ("bsl >= 0", "/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1551, __extension__ __PRETTY_FUNCTION__); }))
;
1552
1553 return (left * 2 + above) + bsl * PARTITION_PLOFFSET4;
1554}
1555
1556// Return the number of elements in the partition CDF when
1557// partitioning the (square) block with luma block size of bsize.
1558static inline int partition_cdf_length(BLOCK_SIZE bsize) {
1559 if (bsize <= BLOCK_8X8)
1560 return PARTITION_TYPES;
1561 else if (bsize == BLOCK_128X128)
1562 return EXT_PARTITION_TYPES - 2;
1563 else
1564 return EXT_PARTITION_TYPES;
1565}
1566
1567static inline int max_block_wide(const MACROBLOCKD *xd, BLOCK_SIZE bsize,
1568 int plane) {
1569 assert(bsize < BLOCK_SIZES_ALL)((void) sizeof ((bsize < BLOCK_SIZES_ALL) ? 1 : 0), __extension__
({ if (bsize < BLOCK_SIZES_ALL) ; else __assert_fail ("bsize < BLOCK_SIZES_ALL"
, "/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1569, __extension__ __PRETTY_FUNCTION__); }))
;
1570 int max_blocks_wide = block_size_wide[bsize];
1571
1572 if (xd->mb_to_right_edge < 0) {
1573 const struct macroblockd_plane *const pd = &xd->plane[plane];
1574 max_blocks_wide += xd->mb_to_right_edge >> (3 + pd->subsampling_x);
1575 }
1576
1577 // Scale the width in the transform block unit.
1578 return max_blocks_wide >> MI_SIZE_LOG22;
1579}
1580
1581static inline int max_block_high(const MACROBLOCKD *xd, BLOCK_SIZE bsize,
1582 int plane) {
1583 int max_blocks_high = block_size_high[bsize];
1584
1585 if (xd->mb_to_bottom_edge < 0) {
1586 const struct macroblockd_plane *const pd = &xd->plane[plane];
1587 max_blocks_high += xd->mb_to_bottom_edge >> (3 + pd->subsampling_y);
1588 }
1589
1590 // Scale the height in the transform block unit.
1591 return max_blocks_high >> MI_SIZE_LOG22;
1592}
1593
1594static inline void av1_zero_above_context(AV1_COMMON *const cm,
1595 const MACROBLOCKD *xd,
1596 int mi_col_start, int mi_col_end,
1597 const int tile_row) {
1598 const SequenceHeader *const seq_params = cm->seq_params;
1599 const int num_planes = av1_num_planes(cm);
1600 const int width = mi_col_end - mi_col_start;
1601 const int aligned_width =
1602 ALIGN_POWER_OF_TWO(width, seq_params->mib_size_log2)(((width) + ((1 << (seq_params->mib_size_log2)) - 1)
) & ~((1 << (seq_params->mib_size_log2)) - 1))
;
1603 const int offset_y = mi_col_start;
1604 const int width_y = aligned_width;
1605 const int offset_uv = offset_y >> seq_params->subsampling_x;
1606 const int width_uv = width_y >> seq_params->subsampling_x;
1607 CommonContexts *const above_contexts = &cm->above_contexts;
1608
1609 av1_zero_array(above_contexts->entropy[0][tile_row] + offset_y, width_y)memset(above_contexts->entropy[0][tile_row] + offset_y, 0,
width_y * sizeof(*(above_contexts->entropy[0][tile_row] +
offset_y)))
;
1610 if (num_planes > 1) {
1611 if (above_contexts->entropy[1][tile_row] &&
1612 above_contexts->entropy[2][tile_row]) {
1613 av1_zero_array(above_contexts->entropy[1][tile_row] + offset_uv,memset(above_contexts->entropy[1][tile_row] + offset_uv, 0
, width_uv * sizeof(*(above_contexts->entropy[1][tile_row]
+ offset_uv)))
1614 width_uv)memset(above_contexts->entropy[1][tile_row] + offset_uv, 0
, width_uv * sizeof(*(above_contexts->entropy[1][tile_row]
+ offset_uv)))
;
1615 av1_zero_array(above_contexts->entropy[2][tile_row] + offset_uv,memset(above_contexts->entropy[2][tile_row] + offset_uv, 0
, width_uv * sizeof(*(above_contexts->entropy[2][tile_row]
+ offset_uv)))
1616 width_uv)memset(above_contexts->entropy[2][tile_row] + offset_uv, 0
, width_uv * sizeof(*(above_contexts->entropy[2][tile_row]
+ offset_uv)))
;
1617 } else {
1618 aom_internal_error(xd->error_info, AOM_CODEC_CORRUPT_FRAME,
1619 "Invalid value of planes");
1620 }
1621 }
1622
1623 av1_zero_array(above_contexts->partition[tile_row] + mi_col_start,memset(above_contexts->partition[tile_row] + mi_col_start,
0, aligned_width * sizeof(*(above_contexts->partition[tile_row
] + mi_col_start)))
1624 aligned_width)memset(above_contexts->partition[tile_row] + mi_col_start,
0, aligned_width * sizeof(*(above_contexts->partition[tile_row
] + mi_col_start)))
;
1625
1626 memset(above_contexts->txfm[tile_row] + mi_col_start,
1627 tx_size_wide[TX_SIZES_LARGEST], aligned_width * sizeof(TXFM_CONTEXT));
1628}
1629
1630static inline void av1_zero_left_context(MACROBLOCKD *const xd) {
1631 av1_zero(xd->left_entropy_context)memset(&(xd->left_entropy_context), 0, sizeof(xd->left_entropy_context
))
;
1632 av1_zero(xd->left_partition_context)memset(&(xd->left_partition_context), 0, sizeof(xd->
left_partition_context))
;
1633
1634 memset(xd->left_txfm_context_buffer, tx_size_high[TX_SIZES_LARGEST],
1635 sizeof(xd->left_txfm_context_buffer));
1636}
1637
1638static inline void set_txfm_ctx(TXFM_CONTEXT *txfm_ctx, uint8_t txs, int len) {
1639 int i;
1640 for (i = 0; i < len; ++i) txfm_ctx[i] = txs;
1641}
1642
1643static inline void set_txfm_ctxs(TX_SIZE tx_size, int n4_w, int n4_h, int skip,
1644 const MACROBLOCKD *xd) {
1645 uint8_t bw = tx_size_wide[tx_size];
1646 uint8_t bh = tx_size_high[tx_size];
1647
1648 if (skip) {
1649 bw = n4_w * MI_SIZE(1 << 2);
1650 bh = n4_h * MI_SIZE(1 << 2);
1651 }
1652
1653 set_txfm_ctx(xd->above_txfm_context, bw, n4_w);
1654 set_txfm_ctx(xd->left_txfm_context, bh, n4_h);
1655}
1656
1657static inline int get_mi_grid_idx(const CommonModeInfoParams *const mi_params,
1658 int mi_row, int mi_col) {
1659 return mi_row * mi_params->mi_stride + mi_col;
1660}
1661
1662static inline int get_alloc_mi_idx(const CommonModeInfoParams *const mi_params,
1663 int mi_row, int mi_col) {
1664 const int mi_alloc_size_1d = mi_size_wide[mi_params->mi_alloc_bsize];
1665 const int mi_alloc_row = mi_row / mi_alloc_size_1d;
1666 const int mi_alloc_col = mi_col / mi_alloc_size_1d;
1667
1668 return mi_alloc_row * mi_params->mi_alloc_stride + mi_alloc_col;
1669}
1670
1671// For this partition block, set pointers in mi_params->mi_grid_base and xd->mi.
1672static inline void set_mi_offsets(const CommonModeInfoParams *const mi_params,
1673 MACROBLOCKD *const xd, int mi_row,
1674 int mi_col) {
1675 // 'mi_grid_base' should point to appropriate memory in 'mi'.
1676 const int mi_grid_idx = get_mi_grid_idx(mi_params, mi_row, mi_col);
1677 const int mi_alloc_idx = get_alloc_mi_idx(mi_params, mi_row, mi_col);
1678 mi_params->mi_grid_base[mi_grid_idx] = &mi_params->mi_alloc[mi_alloc_idx];
1679 // 'xd->mi' should point to an offset in 'mi_grid_base';
1680 xd->mi = mi_params->mi_grid_base + mi_grid_idx;
1681 // 'xd->tx_type_map' should point to an offset in 'mi_params->tx_type_map'.
1682 xd->tx_type_map = mi_params->tx_type_map + mi_grid_idx;
1683 xd->tx_type_map_stride = mi_params->mi_stride;
1684}
1685
1686static inline void txfm_partition_update(TXFM_CONTEXT *above_ctx,
1687 TXFM_CONTEXT *left_ctx,
1688 TX_SIZE tx_size, TX_SIZE txb_size) {
1689 BLOCK_SIZE bsize = txsize_to_bsize[txb_size];
1690 int bh = mi_size_high[bsize];
1691 int bw = mi_size_wide[bsize];
1692 uint8_t txw = tx_size_wide[tx_size];
1693 uint8_t txh = tx_size_high[tx_size];
1694 int i;
1695 for (i = 0; i < bh; ++i) left_ctx[i] = txh;
1696 for (i = 0; i < bw; ++i) above_ctx[i] = txw;
1697}
1698
1699static inline TX_SIZE get_sqr_tx_size(int tx_dim) {
1700 switch (tx_dim) {
1701 case 128:
1702 case 64: return TX_64X64; break;
1703 case 32: return TX_32X32; break;
1704 case 16: return TX_16X16; break;
1705 case 8: return TX_8X8; break;
1706 default: return TX_4X4;
1707 }
1708}
1709
1710static inline TX_SIZE get_tx_size(int width, int height) {
1711 if (width == height) {
1712 return get_sqr_tx_size(width);
1713 }
1714 if (width < height) {
1715 if (width + width == height) {
1716 switch (width) {
1717 case 4: return TX_4X8; break;
1718 case 8: return TX_8X16; break;
1719 case 16: return TX_16X32; break;
1720 case 32: return TX_32X64; break;
1721 }
1722 } else {
1723 switch (width) {
1724 case 4: return TX_4X16; break;
1725 case 8: return TX_8X32; break;
1726 case 16: return TX_16X64; break;
1727 }
1728 }
1729 } else {
1730 if (height + height == width) {
1731 switch (height) {
1732 case 4: return TX_8X4; break;
1733 case 8: return TX_16X8; break;
1734 case 16: return TX_32X16; break;
1735 case 32: return TX_64X32; break;
1736 }
1737 } else {
1738 switch (height) {
1739 case 4: return TX_16X4; break;
1740 case 8: return TX_32X8; break;
1741 case 16: return TX_64X16; break;
1742 }
1743 }
1744 }
1745 assert(0)((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail
("0", "/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1745, __extension__ __PRETTY_FUNCTION__); }))
;
1746 return TX_4X4;
1747}
1748
1749static inline int txfm_partition_context(const TXFM_CONTEXT *const above_ctx,
1750 const TXFM_CONTEXT *const left_ctx,
1751 BLOCK_SIZE bsize, TX_SIZE tx_size) {
1752 const uint8_t txw = tx_size_wide[tx_size];
1753 const uint8_t txh = tx_size_high[tx_size];
1754 const int above = *above_ctx < txw;
1755 const int left = *left_ctx < txh;
1756 int category = TXFM_PARTITION_CONTEXTS((TX_SIZES - TX_8X8) * 6 - 3);
1757
1758 // dummy return, not used by others.
1759 if (tx_size <= TX_4X4) return 0;
1760
1761 TX_SIZE max_tx_size =
1762 get_sqr_tx_size(AOMMAX(block_size_wide[bsize], block_size_high[bsize])(((block_size_wide[bsize]) > (block_size_high[bsize])) ? (
block_size_wide[bsize]) : (block_size_high[bsize]))
);
1763
1764 if (max_tx_size >= TX_8X8) {
1765 category =
1766 (txsize_sqr_up_map[tx_size] != max_tx_size && max_tx_size > TX_8X8) +
1767 (TX_SIZES - 1 - max_tx_size) * 2;
1768 }
1769 assert(category != TXFM_PARTITION_CONTEXTS)((void) sizeof ((category != ((TX_SIZES - TX_8X8) * 6 - 3)) ?
1 : 0), __extension__ ({ if (category != ((TX_SIZES - TX_8X8
) * 6 - 3)) ; else __assert_fail ("category != TXFM_PARTITION_CONTEXTS"
, "/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1769, __extension__ __PRETTY_FUNCTION__); }))
;
1770 return category * 3 + above + left;
1771}
1772
1773// Compute the next partition in the direction of the sb_type stored in the mi
1774// array, starting with bsize.
1775static inline PARTITION_TYPE get_partition(const AV1_COMMON *const cm,
1776 int mi_row, int mi_col,
1777 BLOCK_SIZE bsize) {
1778 const CommonModeInfoParams *const mi_params = &cm->mi_params;
1779 if (mi_row >= mi_params->mi_rows || mi_col >= mi_params->mi_cols)
1780 return PARTITION_INVALID;
1781
1782 const int offset = mi_row * mi_params->mi_stride + mi_col;
1783 MB_MODE_INFO **mi = mi_params->mi_grid_base + offset;
1784 const BLOCK_SIZE subsize = mi[0]->bsize;
1785
1786 assert(bsize < BLOCK_SIZES_ALL)((void) sizeof ((bsize < BLOCK_SIZES_ALL) ? 1 : 0), __extension__
({ if (bsize < BLOCK_SIZES_ALL) ; else __assert_fail ("bsize < BLOCK_SIZES_ALL"
, "/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1786, __extension__ __PRETTY_FUNCTION__); }))
;
1787
1788 if (subsize == bsize) return PARTITION_NONE;
1789
1790 const int bhigh = mi_size_high[bsize];
1791 const int bwide = mi_size_wide[bsize];
1792 const int sshigh = mi_size_high[subsize];
1793 const int sswide = mi_size_wide[subsize];
1794
1795 if (bsize > BLOCK_8X8 && mi_row + bwide / 2 < mi_params->mi_rows &&
1796 mi_col + bhigh / 2 < mi_params->mi_cols) {
1797 // In this case, the block might be using an extended partition
1798 // type.
1799 const MB_MODE_INFO *const mbmi_right = mi[bwide / 2];
1800 const MB_MODE_INFO *const mbmi_below = mi[bhigh / 2 * mi_params->mi_stride];
1801
1802 if (sswide == bwide) {
1803 // Smaller height but same width. Is PARTITION_HORZ_4, PARTITION_HORZ or
1804 // PARTITION_HORZ_B. To distinguish the latter two, check if the lower
1805 // half was split.
1806 if (sshigh * 4 == bhigh) return PARTITION_HORZ_4;
1807 assert(sshigh * 2 == bhigh)((void) sizeof ((sshigh * 2 == bhigh) ? 1 : 0), __extension__
({ if (sshigh * 2 == bhigh) ; else __assert_fail ("sshigh * 2 == bhigh"
, "/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1807, __extension__ __PRETTY_FUNCTION__); }))
;
1808
1809 if (mbmi_below->bsize == subsize)
1810 return PARTITION_HORZ;
1811 else
1812 return PARTITION_HORZ_B;
1813 } else if (sshigh == bhigh) {
1814 // Smaller width but same height. Is PARTITION_VERT_4, PARTITION_VERT or
1815 // PARTITION_VERT_B. To distinguish the latter two, check if the right
1816 // half was split.
1817 if (sswide * 4 == bwide) return PARTITION_VERT_4;
1818 assert(sswide * 2 == bwide)((void) sizeof ((sswide * 2 == bwide) ? 1 : 0), __extension__
({ if (sswide * 2 == bwide) ; else __assert_fail ("sswide * 2 == bwide"
, "/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1818, __extension__ __PRETTY_FUNCTION__); }))
;
1819
1820 if (mbmi_right->bsize == subsize)
1821 return PARTITION_VERT;
1822 else
1823 return PARTITION_VERT_B;
1824 } else {
1825 // Smaller width and smaller height. Might be PARTITION_SPLIT or could be
1826 // PARTITION_HORZ_A or PARTITION_VERT_A. If subsize isn't halved in both
1827 // dimensions, we immediately know this is a split (which will recurse to
1828 // get to subsize). Otherwise look down and to the right. With
1829 // PARTITION_VERT_A, the right block will have height bhigh; with
1830 // PARTITION_HORZ_A, the lower block with have width bwide. Otherwise
1831 // it's PARTITION_SPLIT.
1832 if (sswide * 2 != bwide || sshigh * 2 != bhigh) return PARTITION_SPLIT;
1833
1834 if (mi_size_wide[mbmi_below->bsize] == bwide) return PARTITION_HORZ_A;
1835 if (mi_size_high[mbmi_right->bsize] == bhigh) return PARTITION_VERT_A;
1836
1837 return PARTITION_SPLIT;
1838 }
1839 }
1840 const int vert_split = sswide < bwide;
1841 const int horz_split = sshigh < bhigh;
1842 const int split_idx = (vert_split << 1) | horz_split;
1843 assert(split_idx != 0)((void) sizeof ((split_idx != 0) ? 1 : 0), __extension__ ({ if
(split_idx != 0) ; else __assert_fail ("split_idx != 0", "/root/firefox-clang/third_party/aom/av1/common/av1_common_int.h"
, 1843, __extension__ __PRETTY_FUNCTION__); }))
;
1844
1845 static const PARTITION_TYPE base_partitions[4] = {
1846 PARTITION_INVALID, PARTITION_HORZ, PARTITION_VERT, PARTITION_SPLIT
1847 };
1848
1849 return base_partitions[split_idx];
1850}
1851
1852static inline void set_sb_size(SequenceHeader *const seq_params,
1853 BLOCK_SIZE sb_size) {
1854 seq_params->sb_size = sb_size;
1855 seq_params->mib_size = mi_size_wide[seq_params->sb_size];
1856 seq_params->mib_size_log2 = mi_size_wide_log2[seq_params->sb_size];
1857}
1858
1859// Returns true if the frame is fully lossless at the coded resolution.
1860// Note: If super-resolution is used, such a frame will still NOT be lossless at
1861// the upscaled resolution.
1862static inline int is_coded_lossless(const AV1_COMMON *cm,
1863 const MACROBLOCKD *xd) {
1864 int coded_lossless = 1;
1865 if (cm->seg.enabled) {
1866 for (int i = 0; i < MAX_SEGMENTS8; ++i) {
1867 if (!xd->lossless[i]) {
1868 coded_lossless = 0;
1869 break;
1870 }
1871 }
1872 } else {
1873 coded_lossless = xd->lossless[0];
1874 }
1875 return coded_lossless;
1876}
1877
1878static inline int is_valid_seq_level_idx(AV1_LEVEL seq_level_idx) {
1879 return seq_level_idx == SEQ_LEVEL_MAX ||
1880 (seq_level_idx < SEQ_LEVELS &&
1881 // The following levels are currently undefined.
1882 seq_level_idx != SEQ_LEVEL_2_2 && seq_level_idx != SEQ_LEVEL_2_3 &&
1883 seq_level_idx != SEQ_LEVEL_3_2 && seq_level_idx != SEQ_LEVEL_3_3 &&
1884 seq_level_idx != SEQ_LEVEL_4_2 && seq_level_idx != SEQ_LEVEL_4_3
1885#if !CONFIG_CWG_C0130
1886 && seq_level_idx != SEQ_LEVEL_7_0 && seq_level_idx != SEQ_LEVEL_7_1 &&
1887 seq_level_idx != SEQ_LEVEL_7_2 && seq_level_idx != SEQ_LEVEL_7_3 &&
1888 seq_level_idx != SEQ_LEVEL_8_0 && seq_level_idx != SEQ_LEVEL_8_1 &&
1889 seq_level_idx != SEQ_LEVEL_8_2 && seq_level_idx != SEQ_LEVEL_8_3
1890#endif
1891 );
1892}
1893
1894/*!\endcond */
1895
1896#ifdef __cplusplus
1897} // extern "C"
1898#endif
1899
1900#endif // AOM_AV1_COMMON_AV1_COMMON_INT_H_