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