12 #ifndef AOM_AV1_COMMON_AV1_COMMON_INT_H_
13 #define AOM_AV1_COMMON_AV1_COMMON_INT_H_
15 #include "config/aom_config.h"
16 #include "config/av1_rtcd.h"
18 #include "aom/internal/aom_codec_internal.h"
19 #include "aom_util/aom_thread.h"
20 #include "av1/common/alloccommon.h"
21 #include "av1/common/av1_loopfilter.h"
22 #include "av1/common/entropy.h"
23 #include "av1/common/entropymode.h"
24 #include "av1/common/entropymv.h"
26 #include "av1/common/frame_buffers.h"
27 #include "av1/common/mv.h"
28 #include "av1/common/quant_common.h"
30 #include "av1/common/tile_common.h"
31 #include "av1/common/timing.h"
32 #include "aom_dsp/grain_params.h"
33 #include "aom_dsp/grain_table.h"
34 #include "aom_dsp/odintrin.h"
39 #if defined(__clang__) && defined(__has_warning)
40 #if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
41 #define AOM_FALLTHROUGH_INTENDED [[clang::fallthrough]] // NOLINT
43 #elif defined(__GNUC__) && __GNUC__ >= 7
44 #define AOM_FALLTHROUGH_INTENDED __attribute__((fallthrough)) // NOLINT
47 #ifndef AOM_FALLTHROUGH_INTENDED
48 #define AOM_FALLTHROUGH_INTENDED \
53 #define CDEF_MAX_STRENGTHS 16
56 #define FRAME_ID_LENGTH 15
57 #define DELTA_FRAME_ID_LENGTH 14
59 #define FRAME_CONTEXTS (FRAME_BUFFERS + 1)
61 #define FRAME_CONTEXT_DEFAULTS (FRAME_CONTEXTS - 1)
62 #define PRIMARY_REF_BITS 3
63 #define PRIMARY_REF_NONE 7
65 #define NUM_PING_PONG_BUFFERS 2
67 #define MAX_NUM_TEMPORAL_LAYERS 8
68 #define MAX_NUM_SPATIAL_LAYERS 4
72 #define MAX_NUM_OPERATING_POINTS \
73 (MAX_NUM_TEMPORAL_LAYERS * MAX_NUM_SPATIAL_LAYERS)
78 #define TXCOEFF_TIMER 0
79 #define TXCOEFF_COST_TIMER 0
85 COMPOUND_REFERENCE = 1,
86 REFERENCE_MODE_SELECT = 2,
88 } UENUM1BYTE(REFERENCE_MODE);
94 REFRESH_FRAME_CONTEXT_DISABLED,
99 REFRESH_FRAME_CONTEXT_BACKWARD,
100 } UENUM1BYTE(REFRESH_FRAME_CONTEXT_MODE);
102 #define MFMV_STACK_SIZE 3
105 uint8_t ref_frame_offset;
110 MV_REFERENCE_FRAME ref_frame;
113 typedef struct RefCntBuffer {
128 unsigned int order_hint;
129 unsigned int ref_order_hints[INTER_REFS_PER_FRAME];
135 unsigned int display_order_hint;
136 unsigned int ref_display_order_hint[INTER_REFS_PER_FRAME];
138 unsigned int pyramid_level;
141 struct segmentation seg;
148 WarpedMotionParams global_motion[REF_FRAMES];
150 uint8_t film_grain_params_present;
151 aom_film_grain_t film_grain_params;
156 FRAME_TYPE frame_type;
160 int interp_filter_selected[SWITCHABLE];
163 int8_t ref_deltas[REF_FRAMES];
166 int8_t mode_deltas[MAX_MODE_LF_DELTAS];
168 FRAME_CONTEXT frame_context;
171 typedef struct BufferPool {
177 #if CONFIG_MULTITHREAD
178 pthread_mutex_t pool_mutex;
187 RefCntBuffer frame_bufs[FRAME_BUFFERS];
190 InternalFrameBufferList int_frame_buffers;
198 uint16_t *colbuf[MAX_MB_PLANE];
200 uint16_t *linebuf[MAX_MB_PLANE];
204 size_t allocated_colbuf_size[MAX_MB_PLANE];
206 size_t allocated_linebuf_size[MAX_MB_PLANE];
214 int cdef_strengths[CDEF_MAX_STRENGTHS];
216 int cdef_uv_strengths[CDEF_MAX_STRENGTHS];
228 int delta_q_present_flag;
231 int delta_lf_present_flag;
241 int enable_order_hint;
242 int order_hint_bits_minus_1;
246 int enable_dist_wtd_comp;
248 int enable_ref_frame_mvs;
258 typedef struct SequenceHeader {
262 int max_frame_height;
267 uint8_t frame_id_numbers_present_flag;
269 int delta_frame_id_length;
274 OrderHintInfo order_hint_info;
276 uint8_t force_screen_content_tools;
279 uint8_t still_picture;
280 uint8_t reduced_still_picture_hdr;
281 uint8_t force_integer_mv;
284 uint8_t enable_filter_intra;
285 uint8_t enable_intra_edge_filter;
286 uint8_t enable_interintra_compound;
287 uint8_t enable_masked_compound;
288 uint8_t enable_dual_filter;
290 uint8_t enable_warped_motion;
292 uint8_t enable_superres;
297 uint8_t enable_restoration;
298 BITSTREAM_PROFILE profile;
303 uint8_t use_highbitdepth;
312 uint8_t separate_uv_delta_q;
313 uint8_t film_grain_params_present;
316 int operating_points_cnt_minus_1;
317 int operating_point_idc[MAX_NUM_OPERATING_POINTS];
318 int timing_info_present;
319 aom_timing_info_t timing_info;
320 uint8_t decoder_model_info_present_flag;
321 aom_dec_model_info_t decoder_model_info;
322 uint8_t display_model_info_present_flag;
323 AV1_LEVEL seq_level_idx[MAX_NUM_OPERATING_POINTS];
324 uint8_t tier[MAX_NUM_OPERATING_POINTS];
329 aom_dec_model_op_parameters_t op_params[MAX_NUM_OPERATING_POINTS + 1];
333 int skip_mode_allowed;
340 FRAME_TYPE frame_type;
341 REFERENCE_MODE reference_mode;
343 unsigned int order_hint;
344 unsigned int display_order_hint;
346 unsigned int pyramid_level;
347 unsigned int frame_number;
348 SkipModeInfo skip_mode_info;
349 int refresh_frame_flags;
350 int frame_refs_short_signaling;
601 int height, BLOCK_SIZE min_partition_size);
665 const qm_val_t *
giqmatrix[NUM_QM_LEVELS][3][TX_SIZES_ALL];
669 const qm_val_t *
gqmatrix[NUM_QM_LEVELS][3][TX_SIZES_ALL];
758 struct aom_internal_error_info *
error;
912 #if CONFIG_ENTROPY_STATS
916 int coef_cdf_category;
917 #endif // CONFIG_ENTROPY_STATS
927 struct segmentation
seg;
939 struct loopfilter
lf;
1052 int64_t cum_txcoeff_timer;
1053 int64_t txcoeff_timer;
1055 #endif // TXCOEFF_TIMER
1057 #if TXCOEFF_COST_TIMER
1058 int64_t cum_txcoeff_cost_timer;
1059 int64_t txcoeff_cost_timer;
1060 int64_t txcoeff_cost_count;
1061 #endif // TXCOEFF_COST_TIMER
1068 static void lock_buffer_pool(BufferPool *
const pool) {
1069 #if CONFIG_MULTITHREAD
1070 pthread_mutex_lock(&pool->pool_mutex);
1076 static void unlock_buffer_pool(BufferPool *
const pool) {
1077 #if CONFIG_MULTITHREAD
1078 pthread_mutex_unlock(&pool->pool_mutex);
1085 if (index < 0 || index >= REF_FRAMES)
return NULL;
1090 static INLINE
int get_free_fb(
AV1_COMMON *cm) {
1091 RefCntBuffer *
const frame_bufs = cm->
buffer_pool->frame_bufs;
1095 for (i = 0; i < FRAME_BUFFERS; ++i)
1096 if (frame_bufs[i].ref_count == 0)
break;
1098 if (i != FRAME_BUFFERS) {
1099 if (frame_bufs[i].buf.use_external_reference_buffers) {
1104 ybf->y_buffer = ybf->store_buf_adr[0];
1105 ybf->u_buffer = ybf->store_buf_adr[1];
1106 ybf->v_buffer = ybf->store_buf_adr[2];
1107 ybf->use_external_reference_buffers = 0;
1110 frame_bufs[i].ref_count = 1;
1114 assert(0 &&
"Ran out of free frame buffers. Likely a reference leak.");
1123 static INLINE RefCntBuffer *assign_cur_frame_new_fb(
AV1_COMMON *
const cm) {
1131 const int new_fb_idx = get_free_fb(cm);
1132 if (new_fb_idx == INVALID_IDX)
return NULL;
1136 av1_zero(cm->
cur_frame->interp_filter_selected);
1142 static INLINE
void assign_frame_buffer_p(RefCntBuffer **lhs_ptr,
1143 RefCntBuffer *rhs_ptr) {
1144 RefCntBuffer *
const old_ptr = *lhs_ptr;
1145 if (old_ptr != NULL) {
1146 assert(old_ptr->ref_count > 0);
1148 --old_ptr->ref_count;
1153 ++rhs_ptr->ref_count;
1156 static INLINE
int frame_is_intra_only(
const AV1_COMMON *
const cm) {
1161 static INLINE
int frame_is_sframe(
const AV1_COMMON *cm) {
1168 static INLINE
int get_ref_frame_map_idx(
const AV1_COMMON *
const cm,
1169 const MV_REFERENCE_FRAME ref_frame) {
1170 return (ref_frame >= LAST_FRAME && ref_frame <= EXTREF_FRAME)
1175 static INLINE RefCntBuffer *get_ref_frame_buf(
1176 const AV1_COMMON *
const cm,
const MV_REFERENCE_FRAME ref_frame) {
1177 const int map_idx = get_ref_frame_map_idx(cm, ref_frame);
1178 return (map_idx != INVALID_IDX) ? cm->
ref_frame_map[map_idx] : NULL;
1183 static INLINE
const struct scale_factors *get_ref_scale_factors_const(
1184 const AV1_COMMON *
const cm,
const MV_REFERENCE_FRAME ref_frame) {
1185 const int map_idx = get_ref_frame_map_idx(cm, ref_frame);
1189 static INLINE
struct scale_factors *get_ref_scale_factors(
1190 AV1_COMMON *
const cm,
const MV_REFERENCE_FRAME ref_frame) {
1191 const int map_idx = get_ref_frame_map_idx(cm, ref_frame);
1195 static INLINE RefCntBuffer *get_primary_ref_frame_buf(
1198 if (primary_ref_frame == PRIMARY_REF_NONE)
return NULL;
1199 const int map_idx = get_ref_frame_map_idx(cm, primary_ref_frame + 1);
1200 return (map_idx != INVALID_IDX) ? cm->
ref_frame_map[map_idx] : NULL;
1204 static INLINE
int frame_might_allow_ref_frame_mvs(
const AV1_COMMON *cm) {
1206 cm->
seq_params->order_hint_info.enable_ref_frame_mvs &&
1207 cm->
seq_params->order_hint_info.enable_order_hint &&
1208 !frame_is_intra_only(cm);
1212 static INLINE
int frame_might_allow_warped_motion(
const AV1_COMMON *cm) {
1217 static INLINE
void ensure_mv_buffer(RefCntBuffer *buf,
AV1_COMMON *cm) {
1218 const int buf_rows = buf->mi_rows;
1219 const int buf_cols = buf->mi_cols;
1222 if (buf->mvs == NULL || buf_rows != mi_params->
mi_rows ||
1223 buf_cols != mi_params->
mi_cols) {
1225 buf->mi_rows = mi_params->
mi_rows;
1226 buf->mi_cols = mi_params->
mi_cols;
1227 CHECK_MEM_ERROR(cm, buf->mvs,
1228 (MV_REF *)aom_calloc(((mi_params->
mi_rows + 1) >> 1) *
1229 ((mi_params->
mi_cols + 1) >> 1),
1230 sizeof(*buf->mvs)));
1231 aom_free(buf->seg_map);
1235 sizeof(*buf->seg_map)));
1238 const int mem_size =
1240 int realloc = cm->
tpl_mvs == NULL;
1245 CHECK_MEM_ERROR(cm, cm->
tpl_mvs,
1246 (TPL_MV_REF *)aom_calloc(mem_size,
sizeof(*cm->
tpl_mvs)));
1251 void cfl_init(CFL_CTX *cfl,
const SequenceHeader *seq_params);
1253 static INLINE
int av1_num_planes(
const AV1_COMMON *cm) {
1254 return cm->
seq_params->monochrome ? 1 : MAX_MB_PLANE;
1257 static INLINE
void av1_init_above_context(
CommonContexts *above_contexts,
1258 int num_planes,
int tile_row,
1260 for (
int i = 0; i < num_planes; ++i) {
1268 const int num_planes = av1_num_planes(cm);
1271 for (
int i = 0; i < num_planes; ++i) {
1272 if (xd->
plane[i].plane_type == PLANE_TYPE_Y) {
1297 static INLINE
void set_entropy_context(
MACROBLOCKD *xd,
int mi_row,
int mi_col,
1298 const int num_planes) {
1300 int row_offset = mi_row;
1301 int col_offset = mi_col;
1302 for (i = 0; i < num_planes; ++i) {
1303 struct macroblockd_plane *
const pd = &xd->
plane[i];
1305 const BLOCK_SIZE bsize = xd->
mi[0]->
bsize;
1306 if (pd->subsampling_y && (mi_row & 0x01) && (mi_size_high[bsize] == 1))
1307 row_offset = mi_row - 1;
1308 if (pd->subsampling_x && (mi_col & 0x01) && (mi_size_wide[bsize] == 1))
1309 col_offset = mi_col - 1;
1310 int above_idx = col_offset;
1311 int left_idx = row_offset & MAX_MIB_MASK;
1312 pd->above_entropy_context =
1314 pd->left_entropy_context =
1319 static INLINE
int calc_mi_size(
int len) {
1321 return ALIGN_POWER_OF_TWO(len, MAX_MIB_SIZE_LOG2);
1324 static INLINE
void set_plane_n4(
MACROBLOCKD *
const xd,
int bw,
int bh,
1325 const int num_planes) {
1327 for (i = 0; i < num_planes; i++) {
1328 xd->
plane[i].width = (bw * MI_SIZE) >> xd->
plane[i].subsampling_x;
1329 xd->
plane[i].height = (bh * MI_SIZE) >> xd->
plane[i].subsampling_y;
1331 xd->
plane[i].width = AOMMAX(xd->
plane[i].width, 4);
1332 xd->
plane[i].height = AOMMAX(xd->
plane[i].height, 4);
1336 static INLINE
void set_mi_row_col(
MACROBLOCKD *xd,
const TileInfo *
const tile,
1337 int mi_row,
int bh,
int mi_col,
int bw,
1338 int mi_rows,
int mi_cols) {
1350 const int ss_x = xd->
plane[1].subsampling_x;
1351 const int ss_y = xd->
plane[1].subsampling_y;
1356 if (ss_x && bw < mi_size_wide[BLOCK_8X8])
1358 if (ss_y && bh < mi_size_high[BLOCK_8X8])
1372 const int chroma_ref = ((mi_row & 0x01) || !(bh & 0x01) || !ss_y) &&
1373 ((mi_col & 0x01) || !(bw & 0x01) || !ss_x);
1381 &xd->
mi[-(mi_row & ss_y) * xd->
mi_stride - (mi_col & ss_x)];
1411 static INLINE aom_cdf_prob *get_y_mode_cdf(FRAME_CONTEXT *tile_ctx,
1414 const PREDICTION_MODE above = av1_above_block_mode(above_mi);
1415 const PREDICTION_MODE left = av1_left_block_mode(left_mi);
1416 const int above_ctx = intra_mode_context[above];
1417 const int left_ctx = intra_mode_context[left];
1418 return tile_ctx->kf_y_cdf[above_ctx][left_ctx];
1421 static INLINE
void update_partition_context(
MACROBLOCKD *xd,
int mi_row,
1422 int mi_col, BLOCK_SIZE subsize,
1425 PARTITION_CONTEXT *
const left_ctx =
1428 const int bw = mi_size_wide[bsize];
1429 const int bh = mi_size_high[bsize];
1430 memset(above_ctx, partition_context_lookup[subsize].above, bw);
1431 memset(left_ctx, partition_context_lookup[subsize].left, bh);
1434 static INLINE
int is_chroma_reference(
int mi_row,
int mi_col, BLOCK_SIZE bsize,
1435 int subsampling_x,
int subsampling_y) {
1436 assert(bsize < BLOCK_SIZES_ALL);
1437 const int bw = mi_size_wide[bsize];
1438 const int bh = mi_size_high[bsize];
1439 int ref_pos = ((mi_row & 0x01) || !(bh & 0x01) || !subsampling_y) &&
1440 ((mi_col & 0x01) || !(bw & 0x01) || !subsampling_x);
1444 static INLINE aom_cdf_prob cdf_element_prob(
const aom_cdf_prob *cdf,
1446 assert(cdf != NULL);
1447 return (element > 0 ? cdf[element - 1] : CDF_PROB_TOP) - cdf[element];
1450 static INLINE
void partition_gather_horz_alike(aom_cdf_prob *out,
1451 const aom_cdf_prob *
const in,
1454 out[0] = CDF_PROB_TOP;
1455 out[0] -= cdf_element_prob(in, PARTITION_HORZ);
1456 out[0] -= cdf_element_prob(in, PARTITION_SPLIT);
1457 out[0] -= cdf_element_prob(in, PARTITION_HORZ_A);
1458 out[0] -= cdf_element_prob(in, PARTITION_HORZ_B);
1459 out[0] -= cdf_element_prob(in, PARTITION_VERT_A);
1460 if (bsize != BLOCK_128X128) out[0] -= cdf_element_prob(in, PARTITION_HORZ_4);
1461 out[0] = AOM_ICDF(out[0]);
1462 out[1] = AOM_ICDF(CDF_PROB_TOP);
1465 static INLINE
void partition_gather_vert_alike(aom_cdf_prob *out,
1466 const aom_cdf_prob *
const in,
1469 out[0] = CDF_PROB_TOP;
1470 out[0] -= cdf_element_prob(in, PARTITION_VERT);
1471 out[0] -= cdf_element_prob(in, PARTITION_SPLIT);
1472 out[0] -= cdf_element_prob(in, PARTITION_HORZ_A);
1473 out[0] -= cdf_element_prob(in, PARTITION_VERT_A);
1474 out[0] -= cdf_element_prob(in, PARTITION_VERT_B);
1475 if (bsize != BLOCK_128X128) out[0] -= cdf_element_prob(in, PARTITION_VERT_4);
1476 out[0] = AOM_ICDF(out[0]);
1477 out[1] = AOM_ICDF(CDF_PROB_TOP);
1480 static INLINE
void update_ext_partition_context(
MACROBLOCKD *xd,
int mi_row,
1481 int mi_col, BLOCK_SIZE subsize,
1483 PARTITION_TYPE partition) {
1484 if (bsize >= BLOCK_8X8) {
1485 const int hbs = mi_size_wide[bsize] / 2;
1486 BLOCK_SIZE bsize2 = get_partition_subsize(bsize, PARTITION_SPLIT);
1487 switch (partition) {
1488 case PARTITION_SPLIT:
1489 if (bsize != BLOCK_8X8)
break;
1490 AOM_FALLTHROUGH_INTENDED;
1491 case PARTITION_NONE:
1492 case PARTITION_HORZ:
1493 case PARTITION_VERT:
1494 case PARTITION_HORZ_4:
1495 case PARTITION_VERT_4:
1496 update_partition_context(xd, mi_row, mi_col, subsize, bsize);
1498 case PARTITION_HORZ_A:
1499 update_partition_context(xd, mi_row, mi_col, bsize2, subsize);
1500 update_partition_context(xd, mi_row + hbs, mi_col, subsize, subsize);
1502 case PARTITION_HORZ_B:
1503 update_partition_context(xd, mi_row, mi_col, subsize, subsize);
1504 update_partition_context(xd, mi_row + hbs, mi_col, bsize2, subsize);
1506 case PARTITION_VERT_A:
1507 update_partition_context(xd, mi_row, mi_col, bsize2, subsize);
1508 update_partition_context(xd, mi_row, mi_col + hbs, subsize, subsize);
1510 case PARTITION_VERT_B:
1511 update_partition_context(xd, mi_row, mi_col, subsize, subsize);
1512 update_partition_context(xd, mi_row, mi_col + hbs, bsize2, subsize);
1514 default: assert(0 &&
"Invalid partition type");
1519 static INLINE
int partition_plane_context(
const MACROBLOCKD *xd,
int mi_row,
1520 int mi_col, BLOCK_SIZE bsize) {
1522 const PARTITION_CONTEXT *left_ctx =
1525 const int bsl = mi_size_wide_log2[bsize] - mi_size_wide_log2[BLOCK_8X8];
1526 int above = (*above_ctx >> bsl) & 1, left = (*left_ctx >> bsl) & 1;
1528 assert(mi_size_wide_log2[bsize] == mi_size_high_log2[bsize]);
1531 return (left * 2 + above) + bsl * PARTITION_PLOFFSET;
1536 static INLINE
int partition_cdf_length(BLOCK_SIZE bsize) {
1537 if (bsize <= BLOCK_8X8)
1538 return PARTITION_TYPES;
1539 else if (bsize == BLOCK_128X128)
1540 return EXT_PARTITION_TYPES - 2;
1542 return EXT_PARTITION_TYPES;
1545 static INLINE
int max_block_wide(
const MACROBLOCKD *xd, BLOCK_SIZE bsize,
1547 assert(bsize < BLOCK_SIZES_ALL);
1548 int max_blocks_wide = block_size_wide[bsize];
1551 const struct macroblockd_plane *
const pd = &xd->
plane[plane];
1556 return max_blocks_wide >> MI_SIZE_LOG2;
1559 static INLINE
int max_block_high(
const MACROBLOCKD *xd, BLOCK_SIZE bsize,
1561 int max_blocks_high = block_size_high[bsize];
1564 const struct macroblockd_plane *
const pd = &xd->
plane[plane];
1569 return max_blocks_high >> MI_SIZE_LOG2;
1572 static INLINE
void av1_zero_above_context(
AV1_COMMON *
const cm,
1574 int mi_col_start,
int mi_col_end,
1575 const int tile_row) {
1576 const SequenceHeader *
const seq_params = cm->
seq_params;
1577 const int num_planes = av1_num_planes(cm);
1578 const int width = mi_col_end - mi_col_start;
1579 const int aligned_width =
1580 ALIGN_POWER_OF_TWO(width, seq_params->mib_size_log2);
1581 const int offset_y = mi_col_start;
1582 const int width_y = aligned_width;
1583 const int offset_uv = offset_y >> seq_params->subsampling_x;
1584 const int width_uv = width_y >> seq_params->subsampling_x;
1587 av1_zero_array(above_contexts->
entropy[0][tile_row] + offset_y, width_y);
1588 if (num_planes > 1) {
1589 if (above_contexts->
entropy[1][tile_row] &&
1590 above_contexts->
entropy[2][tile_row]) {
1591 av1_zero_array(above_contexts->
entropy[1][tile_row] + offset_uv,
1593 av1_zero_array(above_contexts->
entropy[2][tile_row] + offset_uv,
1597 "Invalid value of planes");
1601 av1_zero_array(above_contexts->
partition[tile_row] + mi_col_start,
1604 memset(above_contexts->
txfm[tile_row] + mi_col_start,
1605 tx_size_wide[TX_SIZES_LARGEST], aligned_width *
sizeof(TXFM_CONTEXT));
1608 static INLINE
void av1_zero_left_context(
MACROBLOCKD *
const xd) {
1620 #if defined(__GNUC__) && __GNUC__ >= 4
1621 #pragma GCC diagnostic ignored "-Warray-bounds"
1624 #if defined(__GNUC__) && __GNUC__ >= 4
1625 #pragma GCC diagnostic warning "-Warray-bounds"
1628 static INLINE
void set_txfm_ctx(TXFM_CONTEXT *txfm_ctx, uint8_t txs,
int len) {
1630 for (i = 0; i < len; ++i) txfm_ctx[i] = txs;
1633 static INLINE
void set_txfm_ctxs(TX_SIZE tx_size,
int n4_w,
int n4_h,
int skip,
1635 uint8_t bw = tx_size_wide[tx_size];
1636 uint8_t bh = tx_size_high[tx_size];
1639 bw = n4_w * MI_SIZE;
1640 bh = n4_h * MI_SIZE;
1648 int mi_row,
int mi_col) {
1649 return mi_row * mi_params->
mi_stride + mi_col;
1653 int mi_row,
int mi_col) {
1654 const int mi_alloc_size_1d = mi_size_wide[mi_params->
mi_alloc_bsize];
1655 const int mi_alloc_row = mi_row / mi_alloc_size_1d;
1656 const int mi_alloc_col = mi_col / mi_alloc_size_1d;
1666 const int mi_grid_idx = get_mi_grid_idx(mi_params, mi_row, mi_col);
1667 const int mi_alloc_idx = get_alloc_mi_idx(mi_params, mi_row, mi_col);
1676 static INLINE
void txfm_partition_update(TXFM_CONTEXT *above_ctx,
1677 TXFM_CONTEXT *left_ctx,
1678 TX_SIZE tx_size, TX_SIZE txb_size) {
1679 BLOCK_SIZE bsize = txsize_to_bsize[txb_size];
1680 int bh = mi_size_high[bsize];
1681 int bw = mi_size_wide[bsize];
1682 uint8_t txw = tx_size_wide[tx_size];
1683 uint8_t txh = tx_size_high[tx_size];
1685 for (i = 0; i < bh; ++i) left_ctx[i] = txh;
1686 for (i = 0; i < bw; ++i) above_ctx[i] = txw;
1689 static INLINE TX_SIZE get_sqr_tx_size(
int tx_dim) {
1692 case 64:
return TX_64X64;
break;
1693 case 32:
return TX_32X32;
break;
1694 case 16:
return TX_16X16;
break;
1695 case 8:
return TX_8X8;
break;
1696 default:
return TX_4X4;
1700 static INLINE TX_SIZE get_tx_size(
int width,
int height) {
1701 if (width == height) {
1702 return get_sqr_tx_size(width);
1704 if (width < height) {
1705 if (width + width == height) {
1707 case 4:
return TX_4X8;
break;
1708 case 8:
return TX_8X16;
break;
1709 case 16:
return TX_16X32;
break;
1710 case 32:
return TX_32X64;
break;
1714 case 4:
return TX_4X16;
break;
1715 case 8:
return TX_8X32;
break;
1716 case 16:
return TX_16X64;
break;
1720 if (height + height == width) {
1722 case 4:
return TX_8X4;
break;
1723 case 8:
return TX_16X8;
break;
1724 case 16:
return TX_32X16;
break;
1725 case 32:
return TX_64X32;
break;
1729 case 4:
return TX_16X4;
break;
1730 case 8:
return TX_32X8;
break;
1731 case 16:
return TX_64X16;
break;
1739 static INLINE
int txfm_partition_context(
const TXFM_CONTEXT *
const above_ctx,
1740 const TXFM_CONTEXT *
const left_ctx,
1741 BLOCK_SIZE bsize, TX_SIZE tx_size) {
1742 const uint8_t txw = tx_size_wide[tx_size];
1743 const uint8_t txh = tx_size_high[tx_size];
1744 const int above = *above_ctx < txw;
1745 const int left = *left_ctx < txh;
1746 int category = TXFM_PARTITION_CONTEXTS;
1749 if (tx_size <= TX_4X4)
return 0;
1751 TX_SIZE max_tx_size =
1752 get_sqr_tx_size(AOMMAX(block_size_wide[bsize], block_size_high[bsize]));
1754 if (max_tx_size >= TX_8X8) {
1756 (txsize_sqr_up_map[tx_size] != max_tx_size && max_tx_size > TX_8X8) +
1757 (TX_SIZES - 1 - max_tx_size) * 2;
1759 assert(category != TXFM_PARTITION_CONTEXTS);
1760 return category * 3 + above + left;
1765 static INLINE PARTITION_TYPE get_partition(
const AV1_COMMON *
const cm,
1766 int mi_row,
int mi_col,
1769 if (mi_row >= mi_params->
mi_rows || mi_col >= mi_params->
mi_cols)
1770 return PARTITION_INVALID;
1772 const int offset = mi_row * mi_params->
mi_stride + mi_col;
1774 const BLOCK_SIZE subsize = mi[0]->
bsize;
1776 assert(bsize < BLOCK_SIZES_ALL);
1778 if (subsize == bsize)
return PARTITION_NONE;
1780 const int bhigh = mi_size_high[bsize];
1781 const int bwide = mi_size_wide[bsize];
1782 const int sshigh = mi_size_high[subsize];
1783 const int sswide = mi_size_wide[subsize];
1785 if (bsize > BLOCK_8X8 && mi_row + bwide / 2 < mi_params->
mi_rows &&
1786 mi_col + bhigh / 2 < mi_params->
mi_cols) {
1792 if (sswide == bwide) {
1796 if (sshigh * 4 == bhigh)
return PARTITION_HORZ_4;
1797 assert(sshigh * 2 == bhigh);
1799 if (mbmi_below->
bsize == subsize)
1800 return PARTITION_HORZ;
1802 return PARTITION_HORZ_B;
1803 }
else if (sshigh == bhigh) {
1807 if (sswide * 4 == bwide)
return PARTITION_VERT_4;
1808 assert(sswide * 2 == bhigh);
1810 if (mbmi_right->
bsize == subsize)
1811 return PARTITION_VERT;
1813 return PARTITION_VERT_B;
1822 if (sswide * 2 != bwide || sshigh * 2 != bhigh)
return PARTITION_SPLIT;
1824 if (mi_size_wide[mbmi_below->
bsize] == bwide)
return PARTITION_HORZ_A;
1825 if (mi_size_high[mbmi_right->
bsize] == bhigh)
return PARTITION_VERT_A;
1827 return PARTITION_SPLIT;
1830 const int vert_split = sswide < bwide;
1831 const int horz_split = sshigh < bhigh;
1832 const int split_idx = (vert_split << 1) | horz_split;
1833 assert(split_idx != 0);
1835 static const PARTITION_TYPE base_partitions[4] = {
1836 PARTITION_INVALID, PARTITION_HORZ, PARTITION_VERT, PARTITION_SPLIT
1839 return base_partitions[split_idx];
1842 static INLINE
void set_sb_size(SequenceHeader *
const seq_params,
1843 BLOCK_SIZE sb_size) {
1844 seq_params->sb_size = sb_size;
1845 seq_params->mib_size = mi_size_wide[seq_params->sb_size];
1846 seq_params->mib_size_log2 = mi_size_wide_log2[seq_params->sb_size];
1852 static INLINE
int is_coded_lossless(
const AV1_COMMON *cm,
1854 int coded_lossless = 1;
1855 if (cm->
seg.enabled) {
1856 for (
int i = 0; i < MAX_SEGMENTS; ++i) {
1865 return coded_lossless;
1868 static INLINE
int is_valid_seq_level_idx(AV1_LEVEL seq_level_idx) {
1869 return seq_level_idx == SEQ_LEVEL_MAX ||
1870 (seq_level_idx < SEQ_LEVELS &&
1872 seq_level_idx != SEQ_LEVEL_2_2 && seq_level_idx != SEQ_LEVEL_2_3 &&
1873 seq_level_idx != SEQ_LEVEL_3_2 && seq_level_idx != SEQ_LEVEL_3_3 &&
1874 seq_level_idx != SEQ_LEVEL_4_2 && seq_level_idx != SEQ_LEVEL_4_3 &&
1875 seq_level_idx != SEQ_LEVEL_7_0 && seq_level_idx != SEQ_LEVEL_7_1 &&
1876 seq_level_idx != SEQ_LEVEL_7_2 && seq_level_idx != SEQ_LEVEL_7_3);
1885 #endif // AOM_AV1_COMMON_AV1_COMMON_INT_H_