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_synthesis.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]]
43 #elif defined(__GNUC__) && __GNUC__ >= 7
44 #define AOM_FALLTHROUGH_INTENDED __attribute__((fallthrough))
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];
137 #if CONFIG_FRAME_PARALLEL_ENCODE
139 unsigned int pyramid_level;
143 struct segmentation seg;
150 WarpedMotionParams global_motion[REF_FRAMES];
152 uint8_t film_grain_params_present;
153 aom_film_grain_t film_grain_params;
158 FRAME_TYPE frame_type;
162 int interp_filter_selected[SWITCHABLE];
165 int8_t ref_deltas[REF_FRAMES];
168 int8_t mode_deltas[MAX_MODE_LF_DELTAS];
170 FRAME_CONTEXT frame_context;
173 typedef struct BufferPool {
179 #if CONFIG_MULTITHREAD
180 pthread_mutex_t pool_mutex;
189 RefCntBuffer frame_bufs[FRAME_BUFFERS];
192 InternalFrameBufferList int_frame_buffers;
200 uint16_t *colbuf[MAX_MB_PLANE];
202 uint16_t *linebuf[MAX_MB_PLANE];
206 size_t allocated_colbuf_size[MAX_MB_PLANE];
208 size_t allocated_linebuf_size[MAX_MB_PLANE];
216 int cdef_strengths[CDEF_MAX_STRENGTHS];
218 int cdef_uv_strengths[CDEF_MAX_STRENGTHS];
230 int delta_q_present_flag;
233 int delta_lf_present_flag;
243 int enable_order_hint;
244 int order_hint_bits_minus_1;
248 int enable_dist_wtd_comp;
250 int enable_ref_frame_mvs;
260 typedef struct SequenceHeader {
264 int max_frame_height;
269 uint8_t frame_id_numbers_present_flag;
271 int delta_frame_id_length;
276 OrderHintInfo order_hint_info;
278 uint8_t force_screen_content_tools;
281 uint8_t still_picture;
282 uint8_t reduced_still_picture_hdr;
283 uint8_t force_integer_mv;
286 uint8_t enable_filter_intra;
287 uint8_t enable_intra_edge_filter;
288 uint8_t enable_interintra_compound;
289 uint8_t enable_masked_compound;
290 uint8_t enable_dual_filter;
292 uint8_t enable_warped_motion;
294 uint8_t enable_superres;
299 uint8_t enable_restoration;
300 BITSTREAM_PROFILE profile;
305 uint8_t use_highbitdepth;
314 uint8_t separate_uv_delta_q;
315 uint8_t film_grain_params_present;
318 int operating_points_cnt_minus_1;
319 int operating_point_idc[MAX_NUM_OPERATING_POINTS];
320 int timing_info_present;
321 aom_timing_info_t timing_info;
322 uint8_t decoder_model_info_present_flag;
323 aom_dec_model_info_t decoder_model_info;
324 uint8_t display_model_info_present_flag;
325 AV1_LEVEL seq_level_idx[MAX_NUM_OPERATING_POINTS];
326 uint8_t tier[MAX_NUM_OPERATING_POINTS];
331 aom_dec_model_op_parameters_t op_params[MAX_NUM_OPERATING_POINTS + 1];
335 int skip_mode_allowed;
342 FRAME_TYPE frame_type;
343 REFERENCE_MODE reference_mode;
345 unsigned int order_hint;
346 unsigned int display_order_hint;
347 #if CONFIG_FRAME_PARALLEL_ENCODE
349 unsigned int pyramid_level;
351 unsigned int frame_number;
352 SkipModeInfo skip_mode_info;
353 int refresh_frame_flags;
354 int frame_refs_short_signaling;
666 const qm_val_t *
giqmatrix[NUM_QM_LEVELS][3][TX_SIZES_ALL];
670 const qm_val_t *
gqmatrix[NUM_QM_LEVELS][3][TX_SIZES_ALL];
759 struct aom_internal_error_info *
error;
913 #if CONFIG_ENTROPY_STATS
917 int coef_cdf_category;
928 struct segmentation
seg;
940 struct loopfilter
lf;
1053 int64_t cum_txcoeff_timer;
1054 int64_t txcoeff_timer;
1058 #if TXCOEFF_COST_TIMER
1059 int64_t cum_txcoeff_cost_timer;
1060 int64_t txcoeff_cost_timer;
1061 int64_t txcoeff_cost_count;
1069 static void lock_buffer_pool(BufferPool *
const pool) {
1070 #if CONFIG_MULTITHREAD
1071 pthread_mutex_lock(&pool->pool_mutex);
1077 static void unlock_buffer_pool(BufferPool *
const pool) {
1078 #if CONFIG_MULTITHREAD
1079 pthread_mutex_unlock(&pool->pool_mutex);
1086 if (index < 0 || index >= REF_FRAMES)
return NULL;
1091 static INLINE
int get_free_fb(
AV1_COMMON *cm) {
1092 RefCntBuffer *
const frame_bufs = cm->
buffer_pool->frame_bufs;
1096 for (i = 0; i < FRAME_BUFFERS; ++i)
1097 if (frame_bufs[i].ref_count == 0)
break;
1099 if (i != FRAME_BUFFERS) {
1100 if (frame_bufs[i].buf.use_external_reference_buffers) {
1105 ybf->y_buffer = ybf->store_buf_adr[0];
1106 ybf->u_buffer = ybf->store_buf_adr[1];
1107 ybf->v_buffer = ybf->store_buf_adr[2];
1108 ybf->use_external_reference_buffers = 0;
1111 frame_bufs[i].ref_count = 1;
1115 assert(0 &&
"Ran out of free frame buffers. Likely a reference leak.");
1124 static INLINE RefCntBuffer *assign_cur_frame_new_fb(
AV1_COMMON *
const cm) {
1132 const int new_fb_idx = get_free_fb(cm);
1133 if (new_fb_idx == INVALID_IDX)
return NULL;
1137 av1_zero(cm->
cur_frame->interp_filter_selected);
1143 static INLINE
void assign_frame_buffer_p(RefCntBuffer **lhs_ptr,
1144 RefCntBuffer *rhs_ptr) {
1145 RefCntBuffer *
const old_ptr = *lhs_ptr;
1146 if (old_ptr != NULL) {
1147 assert(old_ptr->ref_count > 0);
1149 --old_ptr->ref_count;
1154 ++rhs_ptr->ref_count;
1157 static INLINE
int frame_is_intra_only(
const AV1_COMMON *
const cm) {
1162 static INLINE
int frame_is_sframe(
const AV1_COMMON *cm) {
1169 static INLINE
int get_ref_frame_map_idx(
const AV1_COMMON *
const cm,
1170 const MV_REFERENCE_FRAME ref_frame) {
1171 return (ref_frame >= LAST_FRAME && ref_frame <= EXTREF_FRAME)
1176 static INLINE RefCntBuffer *get_ref_frame_buf(
1177 const AV1_COMMON *
const cm,
const MV_REFERENCE_FRAME ref_frame) {
1178 const int map_idx = get_ref_frame_map_idx(cm, ref_frame);
1179 return (map_idx != INVALID_IDX) ? cm->
ref_frame_map[map_idx] : NULL;
1184 static INLINE
const struct scale_factors *get_ref_scale_factors_const(
1185 const AV1_COMMON *
const cm,
const MV_REFERENCE_FRAME ref_frame) {
1186 const int map_idx = get_ref_frame_map_idx(cm, ref_frame);
1190 static INLINE
struct scale_factors *get_ref_scale_factors(
1191 AV1_COMMON *
const cm,
const MV_REFERENCE_FRAME ref_frame) {
1192 const int map_idx = get_ref_frame_map_idx(cm, ref_frame);
1196 static INLINE RefCntBuffer *get_primary_ref_frame_buf(
1199 if (primary_ref_frame == PRIMARY_REF_NONE)
return NULL;
1200 const int map_idx = get_ref_frame_map_idx(cm, primary_ref_frame + 1);
1201 return (map_idx != INVALID_IDX) ? cm->
ref_frame_map[map_idx] : NULL;
1205 static INLINE
int frame_might_allow_ref_frame_mvs(
const AV1_COMMON *cm) {
1207 cm->
seq_params->order_hint_info.enable_ref_frame_mvs &&
1208 cm->
seq_params->order_hint_info.enable_order_hint &&
1209 !frame_is_intra_only(cm);
1213 static INLINE
int frame_might_allow_warped_motion(
const AV1_COMMON *cm) {
1218 static INLINE
void ensure_mv_buffer(RefCntBuffer *buf,
AV1_COMMON *cm) {
1219 const int buf_rows = buf->mi_rows;
1220 const int buf_cols = buf->mi_cols;
1223 if (buf->mvs == NULL || buf_rows != mi_params->
mi_rows ||
1224 buf_cols != mi_params->
mi_cols) {
1226 buf->mi_rows = mi_params->
mi_rows;
1227 buf->mi_cols = mi_params->
mi_cols;
1228 CHECK_MEM_ERROR(cm, buf->mvs,
1229 (MV_REF *)aom_calloc(((mi_params->
mi_rows + 1) >> 1) *
1230 ((mi_params->
mi_cols + 1) >> 1),
1231 sizeof(*buf->mvs)));
1232 aom_free(buf->seg_map);
1236 sizeof(*buf->seg_map)));
1239 const int mem_size =
1241 int realloc = cm->
tpl_mvs == NULL;
1246 CHECK_MEM_ERROR(cm, cm->
tpl_mvs,
1247 (TPL_MV_REF *)aom_calloc(mem_size,
sizeof(*cm->
tpl_mvs)));
1252 void cfl_init(CFL_CTX *cfl,
const SequenceHeader *seq_params);
1254 static INLINE
int av1_num_planes(
const AV1_COMMON *cm) {
1255 return cm->
seq_params->monochrome ? 1 : MAX_MB_PLANE;
1258 static INLINE
void av1_init_above_context(
CommonContexts *above_contexts,
1259 int num_planes,
int tile_row,
1261 for (
int i = 0; i < num_planes; ++i) {
1269 const int num_planes = av1_num_planes(cm);
1272 for (
int i = 0; i < num_planes; ++i) {
1273 if (xd->
plane[i].plane_type == PLANE_TYPE_Y) {
1298 static INLINE
void set_entropy_context(
MACROBLOCKD *xd,
int mi_row,
int mi_col,
1299 const int num_planes) {
1301 int row_offset = mi_row;
1302 int col_offset = mi_col;
1303 for (i = 0; i < num_planes; ++i) {
1304 struct macroblockd_plane *
const pd = &xd->
plane[i];
1306 const BLOCK_SIZE bsize = xd->
mi[0]->
bsize;
1307 if (pd->subsampling_y && (mi_row & 0x01) && (mi_size_high[bsize] == 1))
1308 row_offset = mi_row - 1;
1309 if (pd->subsampling_x && (mi_col & 0x01) && (mi_size_wide[bsize] == 1))
1310 col_offset = mi_col - 1;
1311 int above_idx = col_offset;
1312 int left_idx = row_offset & MAX_MIB_MASK;
1313 pd->above_entropy_context =
1315 pd->left_entropy_context =
1320 static INLINE
int calc_mi_size(
int len) {
1322 return ALIGN_POWER_OF_TWO(len, MAX_MIB_SIZE_LOG2);
1325 static INLINE
void set_plane_n4(
MACROBLOCKD *
const xd,
int bw,
int bh,
1326 const int num_planes) {
1328 for (i = 0; i < num_planes; i++) {
1329 xd->
plane[i].width = (bw * MI_SIZE) >> xd->
plane[i].subsampling_x;
1330 xd->
plane[i].height = (bh * MI_SIZE) >> xd->
plane[i].subsampling_y;
1332 xd->
plane[i].width = AOMMAX(xd->
plane[i].width, 4);
1333 xd->
plane[i].height = AOMMAX(xd->
plane[i].height, 4);
1337 static INLINE
void set_mi_row_col(
MACROBLOCKD *xd,
const TileInfo *
const tile,
1338 int mi_row,
int bh,
int mi_col,
int bw,
1339 int mi_rows,
int mi_cols) {
1351 const int ss_x = xd->
plane[1].subsampling_x;
1352 const int ss_y = xd->
plane[1].subsampling_y;
1357 if (ss_x && bw < mi_size_wide[BLOCK_8X8])
1359 if (ss_y && bh < mi_size_high[BLOCK_8X8])
1373 const int chroma_ref = ((mi_row & 0x01) || !(bh & 0x01) || !ss_y) &&
1374 ((mi_col & 0x01) || !(bw & 0x01) || !ss_x);
1382 &xd->
mi[-(mi_row & ss_y) * xd->
mi_stride - (mi_col & ss_x)];
1412 static INLINE aom_cdf_prob *get_y_mode_cdf(FRAME_CONTEXT *tile_ctx,
1415 const PREDICTION_MODE above = av1_above_block_mode(above_mi);
1416 const PREDICTION_MODE left = av1_left_block_mode(left_mi);
1417 const int above_ctx = intra_mode_context[above];
1418 const int left_ctx = intra_mode_context[left];
1419 return tile_ctx->kf_y_cdf[above_ctx][left_ctx];
1422 static INLINE
void update_partition_context(
MACROBLOCKD *xd,
int mi_row,
1423 int mi_col, BLOCK_SIZE subsize,
1426 PARTITION_CONTEXT *
const left_ctx =
1429 const int bw = mi_size_wide[bsize];
1430 const int bh = mi_size_high[bsize];
1431 memset(above_ctx, partition_context_lookup[subsize].above, bw);
1432 memset(left_ctx, partition_context_lookup[subsize].left, bh);
1435 static INLINE
int is_chroma_reference(
int mi_row,
int mi_col, BLOCK_SIZE bsize,
1436 int subsampling_x,
int subsampling_y) {
1437 assert(bsize < BLOCK_SIZES_ALL);
1438 const int bw = mi_size_wide[bsize];
1439 const int bh = mi_size_high[bsize];
1440 int ref_pos = ((mi_row & 0x01) || !(bh & 0x01) || !subsampling_y) &&
1441 ((mi_col & 0x01) || !(bw & 0x01) || !subsampling_x);
1445 static INLINE aom_cdf_prob cdf_element_prob(
const aom_cdf_prob *cdf,
1447 assert(cdf != NULL);
1448 return (element > 0 ? cdf[element - 1] : CDF_PROB_TOP) - cdf[element];
1451 static INLINE
void partition_gather_horz_alike(aom_cdf_prob *out,
1452 const aom_cdf_prob *
const in,
1455 out[0] = CDF_PROB_TOP;
1456 out[0] -= cdf_element_prob(in, PARTITION_HORZ);
1457 out[0] -= cdf_element_prob(in, PARTITION_SPLIT);
1458 out[0] -= cdf_element_prob(in, PARTITION_HORZ_A);
1459 out[0] -= cdf_element_prob(in, PARTITION_HORZ_B);
1460 out[0] -= cdf_element_prob(in, PARTITION_VERT_A);
1461 if (bsize != BLOCK_128X128) out[0] -= cdf_element_prob(in, PARTITION_HORZ_4);
1462 out[0] = AOM_ICDF(out[0]);
1463 out[1] = AOM_ICDF(CDF_PROB_TOP);
1466 static INLINE
void partition_gather_vert_alike(aom_cdf_prob *out,
1467 const aom_cdf_prob *
const in,
1470 out[0] = CDF_PROB_TOP;
1471 out[0] -= cdf_element_prob(in, PARTITION_VERT);
1472 out[0] -= cdf_element_prob(in, PARTITION_SPLIT);
1473 out[0] -= cdf_element_prob(in, PARTITION_HORZ_A);
1474 out[0] -= cdf_element_prob(in, PARTITION_VERT_A);
1475 out[0] -= cdf_element_prob(in, PARTITION_VERT_B);
1476 if (bsize != BLOCK_128X128) out[0] -= cdf_element_prob(in, PARTITION_VERT_4);
1477 out[0] = AOM_ICDF(out[0]);
1478 out[1] = AOM_ICDF(CDF_PROB_TOP);
1481 static INLINE
void update_ext_partition_context(
MACROBLOCKD *xd,
int mi_row,
1482 int mi_col, BLOCK_SIZE subsize,
1484 PARTITION_TYPE partition) {
1485 if (bsize >= BLOCK_8X8) {
1486 const int hbs = mi_size_wide[bsize] / 2;
1487 BLOCK_SIZE bsize2 = get_partition_subsize(bsize, PARTITION_SPLIT);
1488 switch (partition) {
1489 case PARTITION_SPLIT:
1490 if (bsize != BLOCK_8X8)
break;
1491 AOM_FALLTHROUGH_INTENDED;
1492 case PARTITION_NONE:
1493 case PARTITION_HORZ:
1494 case PARTITION_VERT:
1495 case PARTITION_HORZ_4:
1496 case PARTITION_VERT_4:
1497 update_partition_context(xd, mi_row, mi_col, subsize, bsize);
1499 case PARTITION_HORZ_A:
1500 update_partition_context(xd, mi_row, mi_col, bsize2, subsize);
1501 update_partition_context(xd, mi_row + hbs, mi_col, subsize, subsize);
1503 case PARTITION_HORZ_B:
1504 update_partition_context(xd, mi_row, mi_col, subsize, subsize);
1505 update_partition_context(xd, mi_row + hbs, mi_col, bsize2, subsize);
1507 case PARTITION_VERT_A:
1508 update_partition_context(xd, mi_row, mi_col, bsize2, subsize);
1509 update_partition_context(xd, mi_row, mi_col + hbs, subsize, subsize);
1511 case PARTITION_VERT_B:
1512 update_partition_context(xd, mi_row, mi_col, subsize, subsize);
1513 update_partition_context(xd, mi_row, mi_col + hbs, bsize2, subsize);
1515 default: assert(0 &&
"Invalid partition type");
1520 static INLINE
int partition_plane_context(
const MACROBLOCKD *xd,
int mi_row,
1521 int mi_col, BLOCK_SIZE bsize) {
1523 const PARTITION_CONTEXT *left_ctx =
1526 const int bsl = mi_size_wide_log2[bsize] - mi_size_wide_log2[BLOCK_8X8];
1527 int above = (*above_ctx >> bsl) & 1, left = (*left_ctx >> bsl) & 1;
1529 assert(mi_size_wide_log2[bsize] == mi_size_high_log2[bsize]);
1532 return (left * 2 + above) + bsl * PARTITION_PLOFFSET;
1537 static INLINE
int partition_cdf_length(BLOCK_SIZE bsize) {
1538 if (bsize <= BLOCK_8X8)
1539 return PARTITION_TYPES;
1540 else if (bsize == BLOCK_128X128)
1541 return EXT_PARTITION_TYPES - 2;
1543 return EXT_PARTITION_TYPES;
1546 static INLINE
int max_block_wide(
const MACROBLOCKD *xd, BLOCK_SIZE bsize,
1548 assert(bsize < BLOCK_SIZES_ALL);
1549 int max_blocks_wide = block_size_wide[bsize];
1552 const struct macroblockd_plane *
const pd = &xd->
plane[plane];
1557 return max_blocks_wide >> MI_SIZE_LOG2;
1560 static INLINE
int max_block_high(
const MACROBLOCKD *xd, BLOCK_SIZE bsize,
1562 int max_blocks_high = block_size_high[bsize];
1565 const struct macroblockd_plane *
const pd = &xd->
plane[plane];
1570 return max_blocks_high >> MI_SIZE_LOG2;
1573 static INLINE
void av1_zero_above_context(
AV1_COMMON *
const cm,
1575 int mi_col_start,
int mi_col_end,
1576 const int tile_row) {
1577 const SequenceHeader *
const seq_params = cm->
seq_params;
1578 const int num_planes = av1_num_planes(cm);
1579 const int width = mi_col_end - mi_col_start;
1580 const int aligned_width =
1581 ALIGN_POWER_OF_TWO(width, seq_params->mib_size_log2);
1582 const int offset_y = mi_col_start;
1583 const int width_y = aligned_width;
1584 const int offset_uv = offset_y >> seq_params->subsampling_x;
1585 const int width_uv = width_y >> seq_params->subsampling_x;
1588 av1_zero_array(above_contexts->
entropy[0][tile_row] + offset_y, width_y);
1589 if (num_planes > 1) {
1590 if (above_contexts->
entropy[1][tile_row] &&
1591 above_contexts->
entropy[2][tile_row]) {
1592 av1_zero_array(above_contexts->
entropy[1][tile_row] + offset_uv,
1594 av1_zero_array(above_contexts->
entropy[2][tile_row] + offset_uv,
1598 "Invalid value of planes");
1602 av1_zero_array(above_contexts->
partition[tile_row] + mi_col_start,
1605 memset(above_contexts->
txfm[tile_row] + mi_col_start,
1606 tx_size_wide[TX_SIZES_LARGEST], aligned_width *
sizeof(TXFM_CONTEXT));
1609 static INLINE
void av1_zero_left_context(
MACROBLOCKD *
const xd) {
1621 #if defined(__GNUC__) && __GNUC__ >= 4
1622 #pragma GCC diagnostic ignored "-Warray-bounds"
1625 #if defined(__GNUC__) && __GNUC__ >= 4
1626 #pragma GCC diagnostic warning "-Warray-bounds"
1629 static INLINE
void set_txfm_ctx(TXFM_CONTEXT *txfm_ctx, uint8_t txs,
int len) {
1631 for (i = 0; i < len; ++i) txfm_ctx[i] = txs;
1634 static INLINE
void set_txfm_ctxs(TX_SIZE tx_size,
int n4_w,
int n4_h,
int skip,
1636 uint8_t bw = tx_size_wide[tx_size];
1637 uint8_t bh = tx_size_high[tx_size];
1640 bw = n4_w * MI_SIZE;
1641 bh = n4_h * MI_SIZE;
1649 int mi_row,
int mi_col) {
1650 return mi_row * mi_params->
mi_stride + mi_col;
1654 int mi_row,
int mi_col) {
1655 const int mi_alloc_size_1d = mi_size_wide[mi_params->
mi_alloc_bsize];
1656 const int mi_alloc_row = mi_row / mi_alloc_size_1d;
1657 const int mi_alloc_col = mi_col / mi_alloc_size_1d;
1667 const int mi_grid_idx = get_mi_grid_idx(mi_params, mi_row, mi_col);
1668 const int mi_alloc_idx = get_alloc_mi_idx(mi_params, mi_row, mi_col);
1677 static INLINE
void txfm_partition_update(TXFM_CONTEXT *above_ctx,
1678 TXFM_CONTEXT *left_ctx,
1679 TX_SIZE tx_size, TX_SIZE txb_size) {
1680 BLOCK_SIZE bsize = txsize_to_bsize[txb_size];
1681 int bh = mi_size_high[bsize];
1682 int bw = mi_size_wide[bsize];
1683 uint8_t txw = tx_size_wide[tx_size];
1684 uint8_t txh = tx_size_high[tx_size];
1686 for (i = 0; i < bh; ++i) left_ctx[i] = txh;
1687 for (i = 0; i < bw; ++i) above_ctx[i] = txw;
1690 static INLINE TX_SIZE get_sqr_tx_size(
int tx_dim) {
1693 case 64:
return TX_64X64;
break;
1694 case 32:
return TX_32X32;
break;
1695 case 16:
return TX_16X16;
break;
1696 case 8:
return TX_8X8;
break;
1697 default:
return TX_4X4;
1701 static INLINE TX_SIZE get_tx_size(
int width,
int height) {
1702 if (width == height) {
1703 return get_sqr_tx_size(width);
1705 if (width < height) {
1706 if (width + width == height) {
1708 case 4:
return TX_4X8;
break;
1709 case 8:
return TX_8X16;
break;
1710 case 16:
return TX_16X32;
break;
1711 case 32:
return TX_32X64;
break;
1715 case 4:
return TX_4X16;
break;
1716 case 8:
return TX_8X32;
break;
1717 case 16:
return TX_16X64;
break;
1721 if (height + height == width) {
1723 case 4:
return TX_8X4;
break;
1724 case 8:
return TX_16X8;
break;
1725 case 16:
return TX_32X16;
break;
1726 case 32:
return TX_64X32;
break;
1730 case 4:
return TX_16X4;
break;
1731 case 8:
return TX_32X8;
break;
1732 case 16:
return TX_64X16;
break;
1740 static INLINE
int txfm_partition_context(
const TXFM_CONTEXT *
const above_ctx,
1741 const TXFM_CONTEXT *
const left_ctx,
1742 BLOCK_SIZE bsize, TX_SIZE tx_size) {
1743 const uint8_t txw = tx_size_wide[tx_size];
1744 const uint8_t txh = tx_size_high[tx_size];
1745 const int above = *above_ctx < txw;
1746 const int left = *left_ctx < txh;
1747 int category = TXFM_PARTITION_CONTEXTS;
1750 if (tx_size <= TX_4X4)
return 0;
1752 TX_SIZE max_tx_size =
1753 get_sqr_tx_size(AOMMAX(block_size_wide[bsize], block_size_high[bsize]));
1755 if (max_tx_size >= TX_8X8) {
1757 (txsize_sqr_up_map[tx_size] != max_tx_size && max_tx_size > TX_8X8) +
1758 (TX_SIZES - 1 - max_tx_size) * 2;
1760 assert(category != TXFM_PARTITION_CONTEXTS);
1761 return category * 3 + above + left;
1766 static INLINE PARTITION_TYPE get_partition(
const AV1_COMMON *
const cm,
1767 int mi_row,
int mi_col,
1770 if (mi_row >= mi_params->
mi_rows || mi_col >= mi_params->
mi_cols)
1771 return PARTITION_INVALID;
1773 const int offset = mi_row * mi_params->
mi_stride + mi_col;
1775 const BLOCK_SIZE subsize = mi[0]->
bsize;
1777 assert(bsize < BLOCK_SIZES_ALL);
1779 if (subsize == bsize)
return PARTITION_NONE;
1781 const int bhigh = mi_size_high[bsize];
1782 const int bwide = mi_size_wide[bsize];
1783 const int sshigh = mi_size_high[subsize];
1784 const int sswide = mi_size_wide[subsize];
1786 if (bsize > BLOCK_8X8 && mi_row + bwide / 2 < mi_params->
mi_rows &&
1787 mi_col + bhigh / 2 < mi_params->
mi_cols) {
1793 if (sswide == bwide) {
1797 if (sshigh * 4 == bhigh)
return PARTITION_HORZ_4;
1798 assert(sshigh * 2 == bhigh);
1800 if (mbmi_below->
bsize == subsize)
1801 return PARTITION_HORZ;
1803 return PARTITION_HORZ_B;
1804 }
else if (sshigh == bhigh) {
1808 if (sswide * 4 == bwide)
return PARTITION_VERT_4;
1809 assert(sswide * 2 == bhigh);
1811 if (mbmi_right->
bsize == subsize)
1812 return PARTITION_VERT;
1814 return PARTITION_VERT_B;
1823 if (sswide * 2 != bwide || sshigh * 2 != bhigh)
return PARTITION_SPLIT;
1825 if (mi_size_wide[mbmi_below->
bsize] == bwide)
return PARTITION_HORZ_A;
1826 if (mi_size_high[mbmi_right->
bsize] == bhigh)
return PARTITION_VERT_A;
1828 return PARTITION_SPLIT;
1831 const int vert_split = sswide < bwide;
1832 const int horz_split = sshigh < bhigh;
1833 const int split_idx = (vert_split << 1) | horz_split;
1834 assert(split_idx != 0);
1836 static const PARTITION_TYPE base_partitions[4] = {
1837 PARTITION_INVALID, PARTITION_HORZ, PARTITION_VERT, PARTITION_SPLIT
1840 return base_partitions[split_idx];
1843 static INLINE
void set_sb_size(SequenceHeader *
const seq_params,
1844 BLOCK_SIZE sb_size) {
1845 seq_params->sb_size = sb_size;
1846 seq_params->mib_size = mi_size_wide[seq_params->sb_size];
1847 seq_params->mib_size_log2 = mi_size_wide_log2[seq_params->sb_size];
1853 static INLINE
int is_coded_lossless(
const AV1_COMMON *cm,
1855 int coded_lossless = 1;
1856 if (cm->
seg.enabled) {
1857 for (
int i = 0; i < MAX_SEGMENTS; ++i) {
1866 return coded_lossless;
1869 static INLINE
int is_valid_seq_level_idx(AV1_LEVEL seq_level_idx) {
1870 return seq_level_idx == SEQ_LEVEL_MAX ||
1871 (seq_level_idx < SEQ_LEVELS &&
1873 seq_level_idx != SEQ_LEVEL_2_2 && seq_level_idx != SEQ_LEVEL_2_3 &&
1874 seq_level_idx != SEQ_LEVEL_3_2 && seq_level_idx != SEQ_LEVEL_3_3 &&
1875 seq_level_idx != SEQ_LEVEL_4_2 && seq_level_idx != SEQ_LEVEL_4_3 &&
1876 seq_level_idx != SEQ_LEVEL_7_0 && seq_level_idx != SEQ_LEVEL_7_1 &&
1877 seq_level_idx != SEQ_LEVEL_7_2 && seq_level_idx != SEQ_LEVEL_7_3);
int(* aom_get_frame_buffer_cb_fn_t)(void *priv, size_t min_size, aom_codec_frame_buffer_t *fb)
get frame buffer callback prototype
Definition: aom_frame_buffer.h:64
int(* aom_release_frame_buffer_cb_fn_t)(void *priv, aom_codec_frame_buffer_t *fb)
release frame buffer callback prototype
Definition: aom_frame_buffer.h:77
#define AOM_PLANE_U
Definition: aom_image.h:200
enum aom_chroma_sample_position aom_chroma_sample_position_t
List of chroma sample positions.
enum aom_transfer_characteristics aom_transfer_characteristics_t
List of supported transfer functions.
enum aom_color_primaries aom_color_primaries_t
List of supported color primaries.
enum aom_matrix_coefficients aom_matrix_coefficients_t
List of supported matrix coefficients.
enum aom_bit_depth aom_bit_depth_t
Bit depth for codecThis enumeration determines the bit depth of the codec.
@ AOM_CODEC_CORRUPT_FRAME
The coded data for this stream is corrupt or incomplete.
Definition: aom_codec.h:195
Top level common structure used by both encoder and decoder.
Definition: av1_common_int.h:751
uint8_t * last_frame_seg_map
Definition: av1_common_int.h:933
RestorationInfo rst_info[3]
Definition: av1_common_int.h:947
WarpedMotionParams global_motion[REF_FRAMES]
Definition: av1_common_int.h:971
int superres_upscaled_width
Definition: av1_common_int.h:800
int8_t ref_frame_side[REF_FRAMES]
Definition: av1_common_int.h:1038
struct scale_factors ref_scale_factors[REF_FRAMES]
Definition: av1_common_int.h:870
RefCntBuffer * prev_frame
Definition: av1_common_int.h:827
FRAME_CONTEXT * default_frame_context
Definition: av1_common_int.h:988
int ref_frame_id[REF_FRAMES]
Definition: av1_common_int.h:1013
int superres_upscaled_height
Definition: av1_common_int.h:801
DeltaQInfo delta_q_info
Definition: av1_common_int.h:966
SequenceHeader * seq_params
Definition: av1_common_int.h:977
int width
Definition: av1_common_int.h:776
RefCntBuffer * cur_frame
Definition: av1_common_int.h:833
CdefInfo cdef_info
Definition: av1_common_int.h:956
loop_filter_info_n lf_info
Definition: av1_common_int.h:939
CurrentFrame current_frame
Definition: av1_common_int.h:755
int remapped_ref_idx[REF_FRAMES]
Definition: av1_common_int.h:855
RestorationLineBuffers * rlbs
Definition: av1_common_int.h:949
aom_film_grain_t film_grain_params
Definition: av1_common_int.h:961
int show_existing_frame
Definition: av1_common_int.h:901
uint32_t buffer_removal_times[(8 *4)+1]
Definition: av1_common_int.h:816
int temporal_layer_id
Definition: av1_common_int.h:1044
struct aom_internal_error_info * error
Definition: av1_common_int.h:759
int showable_frame
Definition: av1_common_int.h:894
int tpl_mvs_mem_size
Definition: av1_common_int.h:1027
uint32_t frame_presentation_time
Definition: av1_common_int.h:822
struct loopfilter lf
Definition: av1_common_int.h:940
int spatial_layer_id
Definition: av1_common_int.h:1050
FeatureFlags features
Definition: av1_common_int.h:906
struct scale_factors sf_identity
Definition: av1_common_int.h:862
YV12_BUFFER_CONFIG rst_frame
Definition: av1_common_int.h:950
CommonModeInfoParams mi_params
Definition: av1_common_int.h:911
uint8_t superres_scale_denominator
Definition: av1_common_int.h:808
int show_frame
Definition: av1_common_int.h:886
struct segmentation seg
Definition: av1_common_int.h:928
CommonQuantParams quant_params
Definition: av1_common_int.h:923
TPL_MV_REF * tpl_mvs
Definition: av1_common_int.h:1023
int current_frame_id
Definition: av1_common_int.h:1012
int32_t * rst_tmpbuf
Definition: av1_common_int.h:948
RefCntBuffer * ref_frame_map[REF_FRAMES]
Definition: av1_common_int.h:879
CommonContexts above_contexts
Definition: av1_common_int.h:1006
CommonTileParams tiles
Definition: av1_common_int.h:993
BufferPool * buffer_pool
Definition: av1_common_int.h:998
int ref_frame_sign_bias[REF_FRAMES]
Definition: av1_common_int.h:1032
FRAME_CONTEXT * fc
Definition: av1_common_int.h:982
int height
Definition: av1_common_int.h:777
int render_width
Definition: av1_common_int.h:787
int render_height
Definition: av1_common_int.h:788
Parameters related to CDEF.
Definition: av1_common_int.h:198
int cdef_bits
Number of CDEF strength values in bits.
Definition: av1_common_int.h:220
int allocated_mi_rows
Number of rows in the frame in 4 pixel.
Definition: av1_common_int.h:222
int allocated_num_workers
Number of CDEF workers.
Definition: av1_common_int.h:224
size_t allocated_srcbuf_size
CDEF intermediate buffer size.
Definition: av1_common_int.h:210
int nb_cdef_strengths
Number of CDEF strength values.
Definition: av1_common_int.h:214
int cdef_damping
CDEF damping factor.
Definition: av1_common_int.h:212
uint16_t * srcbuf
CDEF intermediate buffer.
Definition: av1_common_int.h:204
Contexts used for transmitting various symbols in the bitstream.
Definition: av1_common_int.h:714
PARTITION_CONTEXT ** partition
Definition: av1_common_int.h:719
int num_planes
Definition: av1_common_int.h:743
ENTROPY_CONTEXT ** entropy[3]
Definition: av1_common_int.h:729
int num_tile_rows
Definition: av1_common_int.h:744
int num_mi_cols
Definition: av1_common_int.h:745
TXFM_CONTEXT ** txfm
Definition: av1_common_int.h:737
Params related to MB_MODE_INFO arrays and related info.
Definition: av1_common_int.h:505
int mb_cols
Definition: av1_common_int.h:515
MB_MODE_INFO * mi_alloc
Definition: av1_common_int.h:539
int mi_rows
Definition: av1_common_int.h:526
void(* setup_mi)(struct CommonModeInfoParams *mi_params)
Definition: av1_common_int.h:594
void(* free_mi)(struct CommonModeInfoParams *mi_params)
Definition: av1_common_int.h:589
int mi_cols
Definition: av1_common_int.h:531
int mi_alloc_size
Definition: av1_common_int.h:543
int MBs
Definition: av1_common_int.h:520
TX_TYPE * tx_type_map
Definition: av1_common_int.h:579
void(* set_mb_mi)(struct CommonModeInfoParams *mi_params, int width, int height)
Definition: av1_common_int.h:601
int mi_alloc_stride
Definition: av1_common_int.h:547
int mi_grid_size
Definition: av1_common_int.h:567
int mi_stride
Definition: av1_common_int.h:571
int mb_rows
Definition: av1_common_int.h:510
MB_MODE_INFO ** mi_grid_base
Definition: av1_common_int.h:563
BLOCK_SIZE mi_alloc_bsize
Definition: av1_common_int.h:554
Parameters related to quantization at the frame level.
Definition: av1_common_int.h:610
int u_ac_delta_q
Definition: av1_common_int.h:635
const qm_val_t * u_iqmatrix[8][TX_SIZES_ALL]
Definition: av1_common_int.h:684
int qmatrix_level_v
Definition: av1_common_int.h:706
const qm_val_t * giqmatrix[(1<< 4)][3][TX_SIZES_ALL]
Definition: av1_common_int.h:666
int16_t u_dequant_QTX[8][2]
Definition: av1_common_int.h:655
const qm_val_t * y_iqmatrix[8][TX_SIZES_ALL]
Definition: av1_common_int.h:680
int qmatrix_level_y
Definition: av1_common_int.h:704
int v_ac_delta_q
Definition: av1_common_int.h:640
bool using_qmatrix
Definition: av1_common_int.h:697
int u_dc_delta_q
Definition: av1_common_int.h:625
int qmatrix_level_u
Definition: av1_common_int.h:705
int base_qindex
Definition: av1_common_int.h:614
int16_t v_dequant_QTX[8][2]
Definition: av1_common_int.h:656
const qm_val_t * v_iqmatrix[8][TX_SIZES_ALL]
Definition: av1_common_int.h:688
int16_t y_dequant_QTX[8][2]
Definition: av1_common_int.h:654
int v_dc_delta_q
Definition: av1_common_int.h:629
int y_dc_delta_q
Definition: av1_common_int.h:620
const qm_val_t * gqmatrix[(1<< 4)][3][TX_SIZES_ALL]
Definition: av1_common_int.h:670
Params related to tiles.
Definition: av1_common_int.h:431
int uniform_spacing
Definition: av1_common_int.h:447
int max_width_sb
Definition: av1_common_int.h:434
int log2_rows
Definition: av1_common_int.h:454
int min_log2_rows
Definition: av1_common_int.h:466
int width
Definition: av1_common_int.h:455
int max_log2_rows
Definition: av1_common_int.h:474
int row_start_sb[MAX_TILE_ROWS+1]
Definition: av1_common_int.h:488
int cols
Definition: av1_common_int.h:432
int max_height_sb
Definition: av1_common_int.h:435
unsigned int large_scale
Definition: av1_common_int.h:492
unsigned int single_tile_decoding
Definition: av1_common_int.h:498
int max_log2_cols
Definition: av1_common_int.h:470
int log2_cols
Definition: av1_common_int.h:453
int min_log2
Definition: av1_common_int.h:478
int rows
Definition: av1_common_int.h:433
int min_inner_width
Definition: av1_common_int.h:440
int min_log2_cols
Definition: av1_common_int.h:462
int col_start_sb[MAX_TILE_COLS+1]
Definition: av1_common_int.h:483
int height
Definition: av1_common_int.h:456
Frame level features.
Definition: av1_common_int.h:362
InterpFilter interp_filter
Definition: av1_common_int.h:411
bool allow_ref_frame_mvs
Definition: av1_common_int.h:385
bool allow_warped_motion
Definition: av1_common_int.h:381
bool allow_screen_content_tools
Definition: av1_common_int.h:379
bool switchable_motion_mode
Definition: av1_common_int.h:409
TX_MODE tx_mode
Definition: av1_common_int.h:410
bool reduced_tx_set_used
Definition: av1_common_int.h:398
bool allow_intrabc
Definition: av1_common_int.h:380
int byte_alignment
Definition: av1_common_int.h:420
bool coded_lossless
Definition: av1_common_int.h:389
REFRESH_FRAME_CONTEXT_MODE refresh_frame_context
Definition: av1_common_int.h:425
bool error_resilient_mode
Definition: av1_common_int.h:404
int primary_ref_frame
Definition: av1_common_int.h:416
bool disable_cdf_update
Definition: av1_common_int.h:366
bool allow_high_precision_mv
Definition: av1_common_int.h:371
bool cur_frame_force_integer_mv
Definition: av1_common_int.h:375
bool all_lossless
Definition: av1_common_int.h:393
Stores the prediction/txfm mode of the current coding block.
Definition: blockd.h:222
BLOCK_SIZE bsize
The block size of the current coding block.
Definition: blockd.h:228
Parameters related to Restoration Info.
Definition: restoration.h:255
External frame buffer.
Definition: aom_frame_buffer.h:40
Variables related to current coding block.
Definition: blockd.h:577
bool left_available
Definition: blockd.h:633
uint8_t * tx_type_map
Definition: blockd.h:673
int mb_to_bottom_edge
Definition: blockd.h:687
TXFM_CONTEXT * left_txfm_context
Definition: blockd.h:747
struct macroblockd_plane plane[3]
Definition: blockd.h:613
int mb_to_top_edge
Definition: blockd.h:686
int mb_to_right_edge
Definition: blockd.h:685
bool up_available
Definition: blockd.h:629
MB_MODE_INFO * above_mbmi
Definition: blockd.h:652
bool chroma_up_available
Definition: blockd.h:637
TXFM_CONTEXT * above_txfm_context
Definition: blockd.h:740
bool chroma_left_available
Definition: blockd.h:641
PARTITION_CONTEXT * above_partition_context
Definition: blockd.h:725
MB_MODE_INFO * chroma_left_mbmi
Definition: blockd.h:659
TXFM_CONTEXT left_txfm_context_buffer[MAX_MIB_SIZE]
Definition: blockd.h:754
int tx_type_map_stride
Definition: blockd.h:678
MB_MODE_INFO * chroma_above_mbmi
Definition: blockd.h:666
int mi_row
Definition: blockd.h:582
int mi_stride
Definition: blockd.h:589
bool is_last_vertical_rect
Definition: blockd.h:794
bool is_first_horizontal_rect
Definition: blockd.h:799
uint8_t width
Definition: blockd.h:772
struct aom_internal_error_info * error_info
Definition: blockd.h:845
CFL_CTX cfl
Definition: blockd.h:901
int lossless[8]
Definition: blockd.h:824
ENTROPY_CONTEXT left_entropy_context[3][MAX_MIB_SIZE]
Definition: blockd.h:717
ENTROPY_CONTEXT * above_entropy_context[3]
Definition: blockd.h:710
MB_MODE_INFO ** mi
Definition: blockd.h:624
uint8_t height
Definition: blockd.h:773
MB_MODE_INFO * left_mbmi
Definition: blockd.h:647
PARTITION_CONTEXT left_partition_context[MAX_MIB_SIZE]
Definition: blockd.h:732
bool is_chroma_ref
Definition: blockd.h:608
int mi_col
Definition: blockd.h:583
int mb_to_left_edge
Definition: blockd.h:684
YV12 frame buffer data structure.
Definition: yv12config.h:38