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 "av1/common/odintrin.h"
33 #include "av1/encoder/hash_motion.h"
34 #include "aom_dsp/grain_synthesis.h"
35 #include "aom_dsp/grain_table.h"
40 #if defined(__clang__) && defined(__has_warning)
41 #if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
42 #define AOM_FALLTHROUGH_INTENDED [[clang::fallthrough]]
44 #elif defined(__GNUC__) && __GNUC__ >= 7
45 #define AOM_FALLTHROUGH_INTENDED __attribute__((fallthrough))
48 #ifndef AOM_FALLTHROUGH_INTENDED
49 #define AOM_FALLTHROUGH_INTENDED \
54 #define CDEF_MAX_STRENGTHS 16
57 #define FRAME_ID_LENGTH 15
58 #define DELTA_FRAME_ID_LENGTH 14
60 #define FRAME_CONTEXTS (FRAME_BUFFERS + 1)
62 #define FRAME_CONTEXT_DEFAULTS (FRAME_CONTEXTS - 1)
63 #define PRIMARY_REF_BITS 3
64 #define PRIMARY_REF_NONE 7
66 #define NUM_PING_PONG_BUFFERS 2
68 #define MAX_NUM_TEMPORAL_LAYERS 8
69 #define MAX_NUM_SPATIAL_LAYERS 4
73 #define MAX_NUM_OPERATING_POINTS \
74 (MAX_NUM_TEMPORAL_LAYERS * MAX_NUM_SPATIAL_LAYERS)
79 #define TXCOEFF_TIMER 0
80 #define TXCOEFF_COST_TIMER 0
86 COMPOUND_REFERENCE = 1,
87 REFERENCE_MODE_SELECT = 2,
89 } UENUM1BYTE(REFERENCE_MODE);
95 REFRESH_FRAME_CONTEXT_DISABLED,
100 REFRESH_FRAME_CONTEXT_BACKWARD,
101 } UENUM1BYTE(REFRESH_FRAME_CONTEXT_MODE);
103 #define MFMV_STACK_SIZE 3
106 uint8_t ref_frame_offset;
111 MV_REFERENCE_FRAME ref_frame;
114 typedef struct RefCntBuffer {
129 unsigned int order_hint;
130 unsigned int ref_order_hints[INTER_REFS_PER_FRAME];
136 unsigned int display_order_hint;
137 unsigned int ref_display_order_hint[INTER_REFS_PER_FRAME];
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;
199 int cdef_strengths[CDEF_MAX_STRENGTHS];
200 int cdef_uv_strengths[CDEF_MAX_STRENGTHS];
208 int delta_q_present_flag;
211 int delta_lf_present_flag;
221 int enable_order_hint;
222 int order_hint_bits_minus_1;
226 int enable_dist_wtd_comp;
228 int enable_ref_frame_mvs;
238 typedef struct SequenceHeader {
242 int max_frame_height;
247 uint8_t frame_id_numbers_present_flag;
249 int delta_frame_id_length;
254 OrderHintInfo order_hint_info;
256 uint8_t force_screen_content_tools;
259 uint8_t still_picture;
260 uint8_t reduced_still_picture_hdr;
261 uint8_t force_integer_mv;
264 uint8_t enable_filter_intra;
265 uint8_t enable_intra_edge_filter;
266 uint8_t enable_interintra_compound;
267 uint8_t enable_masked_compound;
268 uint8_t enable_dual_filter;
270 uint8_t enable_warped_motion;
272 uint8_t enable_superres;
277 uint8_t enable_restoration;
278 BITSTREAM_PROFILE profile;
283 uint8_t use_highbitdepth;
292 uint8_t separate_uv_delta_q;
293 uint8_t film_grain_params_present;
296 int operating_points_cnt_minus_1;
297 int operating_point_idc[MAX_NUM_OPERATING_POINTS];
298 int timing_info_present;
299 aom_timing_info_t timing_info;
300 uint8_t decoder_model_info_present_flag;
301 aom_dec_model_info_t decoder_model_info;
302 uint8_t display_model_info_present_flag;
303 AV1_LEVEL seq_level_idx[MAX_NUM_OPERATING_POINTS];
304 uint8_t tier[MAX_NUM_OPERATING_POINTS];
309 aom_dec_model_op_parameters_t op_params[MAX_NUM_OPERATING_POINTS + 1];
313 int skip_mode_allowed;
320 FRAME_TYPE frame_type;
321 REFERENCE_MODE reference_mode;
323 unsigned int order_hint;
324 unsigned int display_order_hint;
325 unsigned int frame_number;
326 SkipModeInfo skip_mode_info;
327 int refresh_frame_flags;
328 int frame_refs_short_signaling;
640 const qm_val_t *
giqmatrix[NUM_QM_LEVELS][3][TX_SIZES_ALL];
644 const qm_val_t *
gqmatrix[NUM_QM_LEVELS][3][TX_SIZES_ALL];
733 struct aom_internal_error_info
error;
891 #if CONFIG_ENTROPY_STATS
895 int coef_cdf_category;
906 struct segmentation
seg;
918 struct loopfilter
lf;
1039 int64_t cum_txcoeff_timer;
1040 int64_t txcoeff_timer;
1044 #if TXCOEFF_COST_TIMER
1045 int64_t cum_txcoeff_cost_timer;
1046 int64_t txcoeff_cost_timer;
1047 int64_t txcoeff_cost_count;
1059 static void lock_buffer_pool(BufferPool *
const pool) {
1060 #if CONFIG_MULTITHREAD
1061 pthread_mutex_lock(&pool->pool_mutex);
1067 static void unlock_buffer_pool(BufferPool *
const pool) {
1068 #if CONFIG_MULTITHREAD
1069 pthread_mutex_unlock(&pool->pool_mutex);
1076 if (index < 0 || index >= REF_FRAMES)
return NULL;
1081 static INLINE
int get_free_fb(
AV1_COMMON *cm) {
1082 RefCntBuffer *
const frame_bufs = cm->
buffer_pool->frame_bufs;
1086 for (i = 0; i < FRAME_BUFFERS; ++i)
1087 if (frame_bufs[i].ref_count == 0)
break;
1089 if (i != FRAME_BUFFERS) {
1090 if (frame_bufs[i].buf.use_external_reference_buffers) {
1095 ybf->y_buffer = ybf->store_buf_adr[0];
1096 ybf->u_buffer = ybf->store_buf_adr[1];
1097 ybf->v_buffer = ybf->store_buf_adr[2];
1098 ybf->use_external_reference_buffers = 0;
1101 frame_bufs[i].ref_count = 1;
1105 assert(0 &&
"Ran out of free frame buffers. Likely a reference leak.");
1114 static INLINE RefCntBuffer *assign_cur_frame_new_fb(
AV1_COMMON *
const cm) {
1122 const int new_fb_idx = get_free_fb(cm);
1123 if (new_fb_idx == INVALID_IDX)
return NULL;
1127 av1_zero(cm->
cur_frame->interp_filter_selected);
1133 static INLINE
void assign_frame_buffer_p(RefCntBuffer **lhs_ptr,
1134 RefCntBuffer *rhs_ptr) {
1135 RefCntBuffer *
const old_ptr = *lhs_ptr;
1136 if (old_ptr != NULL) {
1137 assert(old_ptr->ref_count > 0);
1139 --old_ptr->ref_count;
1144 ++rhs_ptr->ref_count;
1147 static INLINE
int frame_is_intra_only(
const AV1_COMMON *
const cm) {
1152 static INLINE
int frame_is_sframe(
const AV1_COMMON *cm) {
1159 static INLINE
int get_ref_frame_map_idx(
const AV1_COMMON *
const cm,
1160 const MV_REFERENCE_FRAME ref_frame) {
1161 return (ref_frame >= LAST_FRAME && ref_frame <= EXTREF_FRAME)
1166 static INLINE RefCntBuffer *get_ref_frame_buf(
1167 const AV1_COMMON *
const cm,
const MV_REFERENCE_FRAME ref_frame) {
1168 const int map_idx = get_ref_frame_map_idx(cm, ref_frame);
1169 return (map_idx != INVALID_IDX) ? cm->
ref_frame_map[map_idx] : NULL;
1174 static INLINE
const struct scale_factors *get_ref_scale_factors_const(
1175 const AV1_COMMON *
const cm,
const MV_REFERENCE_FRAME ref_frame) {
1176 const int map_idx = get_ref_frame_map_idx(cm, ref_frame);
1180 static INLINE
struct scale_factors *get_ref_scale_factors(
1181 AV1_COMMON *
const cm,
const MV_REFERENCE_FRAME ref_frame) {
1182 const int map_idx = get_ref_frame_map_idx(cm, ref_frame);
1186 static INLINE RefCntBuffer *get_primary_ref_frame_buf(
1189 if (primary_ref_frame == PRIMARY_REF_NONE)
return NULL;
1190 const int map_idx = get_ref_frame_map_idx(cm, primary_ref_frame + 1);
1191 return (map_idx != INVALID_IDX) ? cm->
ref_frame_map[map_idx] : NULL;
1195 static INLINE
int frame_might_allow_ref_frame_mvs(
const AV1_COMMON *cm) {
1197 cm->
seq_params.order_hint_info.enable_ref_frame_mvs &&
1198 cm->
seq_params.order_hint_info.enable_order_hint &&
1199 !frame_is_intra_only(cm);
1203 static INLINE
int frame_might_allow_warped_motion(
const AV1_COMMON *cm) {
1208 static INLINE
void ensure_mv_buffer(RefCntBuffer *buf,
AV1_COMMON *cm) {
1209 const int buf_rows = buf->mi_rows;
1210 const int buf_cols = buf->mi_cols;
1213 if (buf->mvs == NULL || buf_rows != mi_params->
mi_rows ||
1214 buf_cols != mi_params->
mi_cols) {
1216 buf->mi_rows = mi_params->
mi_rows;
1217 buf->mi_cols = mi_params->
mi_cols;
1218 CHECK_MEM_ERROR(cm, buf->mvs,
1219 (MV_REF *)aom_calloc(((mi_params->
mi_rows + 1) >> 1) *
1220 ((mi_params->
mi_cols + 1) >> 1),
1221 sizeof(*buf->mvs)));
1222 aom_free(buf->seg_map);
1226 sizeof(*buf->seg_map)));
1229 const int mem_size =
1231 int realloc = cm->
tpl_mvs == NULL;
1236 CHECK_MEM_ERROR(cm, cm->
tpl_mvs,
1237 (TPL_MV_REF *)aom_calloc(mem_size,
sizeof(*cm->
tpl_mvs)));
1242 void cfl_init(CFL_CTX *cfl,
const SequenceHeader *seq_params);
1244 static INLINE
int av1_num_planes(
const AV1_COMMON *cm) {
1245 return cm->
seq_params.monochrome ? 1 : MAX_MB_PLANE;
1248 static INLINE
void av1_init_above_context(
CommonContexts *above_contexts,
1249 int num_planes,
int tile_row,
1251 for (
int i = 0; i < num_planes; ++i) {
1259 const int num_planes = av1_num_planes(cm);
1262 for (
int i = 0; i < num_planes; ++i) {
1263 if (xd->
plane[i].plane_type == PLANE_TYPE_Y) {
1288 static INLINE
void set_entropy_context(
MACROBLOCKD *xd,
int mi_row,
int mi_col,
1289 const int num_planes) {
1291 int row_offset = mi_row;
1292 int col_offset = mi_col;
1293 for (i = 0; i < num_planes; ++i) {
1294 struct macroblockd_plane *
const pd = &xd->
plane[i];
1296 const BLOCK_SIZE bsize = xd->
mi[0]->
bsize;
1297 if (pd->subsampling_y && (mi_row & 0x01) && (mi_size_high[bsize] == 1))
1298 row_offset = mi_row - 1;
1299 if (pd->subsampling_x && (mi_col & 0x01) && (mi_size_wide[bsize] == 1))
1300 col_offset = mi_col - 1;
1301 int above_idx = col_offset;
1302 int left_idx = row_offset & MAX_MIB_MASK;
1303 pd->above_entropy_context =
1305 pd->left_entropy_context =
1310 static INLINE
int calc_mi_size(
int len) {
1312 return ALIGN_POWER_OF_TWO(len, MAX_MIB_SIZE_LOG2);
1315 static INLINE
void set_plane_n4(
MACROBLOCKD *
const xd,
int bw,
int bh,
1316 const int num_planes) {
1318 for (i = 0; i < num_planes; i++) {
1319 xd->
plane[i].width = (bw * MI_SIZE) >> xd->
plane[i].subsampling_x;
1320 xd->
plane[i].height = (bh * MI_SIZE) >> xd->
plane[i].subsampling_y;
1322 xd->
plane[i].width = AOMMAX(xd->
plane[i].width, 4);
1323 xd->
plane[i].height = AOMMAX(xd->
plane[i].height, 4);
1327 static INLINE
void set_mi_row_col(
MACROBLOCKD *xd,
const TileInfo *
const tile,
1328 int mi_row,
int bh,
int mi_col,
int bw,
1329 int mi_rows,
int mi_cols) {
1341 const int ss_x = xd->
plane[1].subsampling_x;
1342 const int ss_y = xd->
plane[1].subsampling_y;
1347 if (ss_x && bw < mi_size_wide[BLOCK_8X8])
1349 if (ss_y && bh < mi_size_high[BLOCK_8X8])
1363 const int chroma_ref = ((mi_row & 0x01) || !(bh & 0x01) || !ss_y) &&
1364 ((mi_col & 0x01) || !(bw & 0x01) || !ss_x);
1372 &xd->
mi[-(mi_row & ss_y) * xd->
mi_stride - (mi_col & ss_x)];
1402 static INLINE aom_cdf_prob *get_y_mode_cdf(FRAME_CONTEXT *tile_ctx,
1405 const PREDICTION_MODE above = av1_above_block_mode(above_mi);
1406 const PREDICTION_MODE left = av1_left_block_mode(left_mi);
1407 const int above_ctx = intra_mode_context[above];
1408 const int left_ctx = intra_mode_context[left];
1409 return tile_ctx->kf_y_cdf[above_ctx][left_ctx];
1412 static INLINE
void update_partition_context(
MACROBLOCKD *xd,
int mi_row,
1413 int mi_col, BLOCK_SIZE subsize,
1416 PARTITION_CONTEXT *
const left_ctx =
1419 const int bw = mi_size_wide[bsize];
1420 const int bh = mi_size_high[bsize];
1421 memset(above_ctx, partition_context_lookup[subsize].above, bw);
1422 memset(left_ctx, partition_context_lookup[subsize].left, bh);
1425 static INLINE
int is_chroma_reference(
int mi_row,
int mi_col, BLOCK_SIZE bsize,
1426 int subsampling_x,
int subsampling_y) {
1427 assert(bsize < BLOCK_SIZES_ALL);
1428 const int bw = mi_size_wide[bsize];
1429 const int bh = mi_size_high[bsize];
1430 int ref_pos = ((mi_row & 0x01) || !(bh & 0x01) || !subsampling_y) &&
1431 ((mi_col & 0x01) || !(bw & 0x01) || !subsampling_x);
1435 static INLINE aom_cdf_prob cdf_element_prob(
const aom_cdf_prob *cdf,
1437 assert(cdf != NULL);
1438 return (element > 0 ? cdf[element - 1] : CDF_PROB_TOP) - cdf[element];
1441 static INLINE
void partition_gather_horz_alike(aom_cdf_prob *out,
1442 const aom_cdf_prob *
const in,
1445 out[0] = CDF_PROB_TOP;
1446 out[0] -= cdf_element_prob(in, PARTITION_HORZ);
1447 out[0] -= cdf_element_prob(in, PARTITION_SPLIT);
1448 out[0] -= cdf_element_prob(in, PARTITION_HORZ_A);
1449 out[0] -= cdf_element_prob(in, PARTITION_HORZ_B);
1450 out[0] -= cdf_element_prob(in, PARTITION_VERT_A);
1451 if (bsize != BLOCK_128X128) out[0] -= cdf_element_prob(in, PARTITION_HORZ_4);
1452 out[0] = AOM_ICDF(out[0]);
1453 out[1] = AOM_ICDF(CDF_PROB_TOP);
1456 static INLINE
void partition_gather_vert_alike(aom_cdf_prob *out,
1457 const aom_cdf_prob *
const in,
1460 out[0] = CDF_PROB_TOP;
1461 out[0] -= cdf_element_prob(in, PARTITION_VERT);
1462 out[0] -= cdf_element_prob(in, PARTITION_SPLIT);
1463 out[0] -= cdf_element_prob(in, PARTITION_HORZ_A);
1464 out[0] -= cdf_element_prob(in, PARTITION_VERT_A);
1465 out[0] -= cdf_element_prob(in, PARTITION_VERT_B);
1466 if (bsize != BLOCK_128X128) out[0] -= cdf_element_prob(in, PARTITION_VERT_4);
1467 out[0] = AOM_ICDF(out[0]);
1468 out[1] = AOM_ICDF(CDF_PROB_TOP);
1471 static INLINE
void update_ext_partition_context(
MACROBLOCKD *xd,
int mi_row,
1472 int mi_col, BLOCK_SIZE subsize,
1474 PARTITION_TYPE partition) {
1475 if (bsize >= BLOCK_8X8) {
1476 const int hbs = mi_size_wide[bsize] / 2;
1477 BLOCK_SIZE bsize2 = get_partition_subsize(bsize, PARTITION_SPLIT);
1478 switch (partition) {
1479 case PARTITION_SPLIT:
1480 if (bsize != BLOCK_8X8)
break;
1481 AOM_FALLTHROUGH_INTENDED;
1482 case PARTITION_NONE:
1483 case PARTITION_HORZ:
1484 case PARTITION_VERT:
1485 case PARTITION_HORZ_4:
1486 case PARTITION_VERT_4:
1487 update_partition_context(xd, mi_row, mi_col, subsize, bsize);
1489 case PARTITION_HORZ_A:
1490 update_partition_context(xd, mi_row, mi_col, bsize2, subsize);
1491 update_partition_context(xd, mi_row + hbs, mi_col, subsize, subsize);
1493 case PARTITION_HORZ_B:
1494 update_partition_context(xd, mi_row, mi_col, subsize, subsize);
1495 update_partition_context(xd, mi_row + hbs, mi_col, bsize2, subsize);
1497 case PARTITION_VERT_A:
1498 update_partition_context(xd, mi_row, mi_col, bsize2, subsize);
1499 update_partition_context(xd, mi_row, mi_col + hbs, subsize, subsize);
1501 case PARTITION_VERT_B:
1502 update_partition_context(xd, mi_row, mi_col, subsize, subsize);
1503 update_partition_context(xd, mi_row, mi_col + hbs, bsize2, subsize);
1505 default: assert(0 &&
"Invalid partition type");
1510 static INLINE
int partition_plane_context(
const MACROBLOCKD *xd,
int mi_row,
1511 int mi_col, BLOCK_SIZE bsize) {
1513 const PARTITION_CONTEXT *left_ctx =
1516 const int bsl = mi_size_wide_log2[bsize] - mi_size_wide_log2[BLOCK_8X8];
1517 int above = (*above_ctx >> bsl) & 1, left = (*left_ctx >> bsl) & 1;
1519 assert(mi_size_wide_log2[bsize] == mi_size_high_log2[bsize]);
1522 return (left * 2 + above) + bsl * PARTITION_PLOFFSET;
1527 static INLINE
int partition_cdf_length(BLOCK_SIZE bsize) {
1528 if (bsize <= BLOCK_8X8)
1529 return PARTITION_TYPES;
1530 else if (bsize == BLOCK_128X128)
1531 return EXT_PARTITION_TYPES - 2;
1533 return EXT_PARTITION_TYPES;
1536 static INLINE
int max_block_wide(
const MACROBLOCKD *xd, BLOCK_SIZE bsize,
1538 assert(bsize < BLOCK_SIZES_ALL);
1539 int max_blocks_wide = block_size_wide[bsize];
1542 const struct macroblockd_plane *
const pd = &xd->
plane[plane];
1547 return max_blocks_wide >> MI_SIZE_LOG2;
1550 static INLINE
int max_block_high(
const MACROBLOCKD *xd, BLOCK_SIZE bsize,
1552 int max_blocks_high = block_size_high[bsize];
1555 const struct macroblockd_plane *
const pd = &xd->
plane[plane];
1560 return max_blocks_high >> MI_SIZE_LOG2;
1563 static INLINE
void av1_zero_above_context(
AV1_COMMON *
const cm,
1565 int mi_col_start,
int mi_col_end,
1566 const int tile_row) {
1567 const SequenceHeader *
const seq_params = &cm->
seq_params;
1568 const int num_planes = av1_num_planes(cm);
1569 const int width = mi_col_end - mi_col_start;
1570 const int aligned_width =
1571 ALIGN_POWER_OF_TWO(width, seq_params->mib_size_log2);
1572 const int offset_y = mi_col_start;
1573 const int width_y = aligned_width;
1574 const int offset_uv = offset_y >> seq_params->subsampling_x;
1575 const int width_uv = width_y >> seq_params->subsampling_x;
1578 av1_zero_array(above_contexts->
entropy[0][tile_row] + offset_y, width_y);
1579 if (num_planes > 1) {
1580 if (above_contexts->
entropy[1][tile_row] &&
1581 above_contexts->
entropy[2][tile_row]) {
1582 av1_zero_array(above_contexts->
entropy[1][tile_row] + offset_uv,
1584 av1_zero_array(above_contexts->
entropy[2][tile_row] + offset_uv,
1588 "Invalid value of planes");
1592 av1_zero_array(above_contexts->
partition[tile_row] + mi_col_start,
1595 memset(above_contexts->
txfm[tile_row] + mi_col_start,
1596 tx_size_wide[TX_SIZES_LARGEST], aligned_width *
sizeof(TXFM_CONTEXT));
1599 static INLINE
void av1_zero_left_context(
MACROBLOCKD *
const xd) {
1611 #if defined(__GNUC__) && __GNUC__ >= 4
1612 #pragma GCC diagnostic ignored "-Warray-bounds"
1615 #if defined(__GNUC__) && __GNUC__ >= 4
1616 #pragma GCC diagnostic warning "-Warray-bounds"
1619 static INLINE
void set_txfm_ctx(TXFM_CONTEXT *txfm_ctx, uint8_t txs,
int len) {
1621 for (i = 0; i < len; ++i) txfm_ctx[i] = txs;
1624 static INLINE
void set_txfm_ctxs(TX_SIZE tx_size,
int n4_w,
int n4_h,
int skip,
1626 uint8_t bw = tx_size_wide[tx_size];
1627 uint8_t bh = tx_size_high[tx_size];
1630 bw = n4_w * MI_SIZE;
1631 bh = n4_h * MI_SIZE;
1639 int mi_row,
int mi_col) {
1640 return mi_row * mi_params->
mi_stride + mi_col;
1644 int mi_row,
int mi_col) {
1645 const int mi_alloc_size_1d = mi_size_wide[mi_params->
mi_alloc_bsize];
1646 const int mi_alloc_row = mi_row / mi_alloc_size_1d;
1647 const int mi_alloc_col = mi_col / mi_alloc_size_1d;
1657 const int mi_grid_idx = get_mi_grid_idx(mi_params, mi_row, mi_col);
1658 const int mi_alloc_idx = get_alloc_mi_idx(mi_params, mi_row, mi_col);
1667 static INLINE
void txfm_partition_update(TXFM_CONTEXT *above_ctx,
1668 TXFM_CONTEXT *left_ctx,
1669 TX_SIZE tx_size, TX_SIZE txb_size) {
1670 BLOCK_SIZE bsize = txsize_to_bsize[txb_size];
1671 int bh = mi_size_high[bsize];
1672 int bw = mi_size_wide[bsize];
1673 uint8_t txw = tx_size_wide[tx_size];
1674 uint8_t txh = tx_size_high[tx_size];
1676 for (i = 0; i < bh; ++i) left_ctx[i] = txh;
1677 for (i = 0; i < bw; ++i) above_ctx[i] = txw;
1680 static INLINE TX_SIZE get_sqr_tx_size(
int tx_dim) {
1683 case 64:
return TX_64X64;
break;
1684 case 32:
return TX_32X32;
break;
1685 case 16:
return TX_16X16;
break;
1686 case 8:
return TX_8X8;
break;
1687 default:
return TX_4X4;
1691 static INLINE TX_SIZE get_tx_size(
int width,
int height) {
1692 if (width == height) {
1693 return get_sqr_tx_size(width);
1695 if (width < height) {
1696 if (width + width == height) {
1698 case 4:
return TX_4X8;
break;
1699 case 8:
return TX_8X16;
break;
1700 case 16:
return TX_16X32;
break;
1701 case 32:
return TX_32X64;
break;
1705 case 4:
return TX_4X16;
break;
1706 case 8:
return TX_8X32;
break;
1707 case 16:
return TX_16X64;
break;
1711 if (height + height == width) {
1713 case 4:
return TX_8X4;
break;
1714 case 8:
return TX_16X8;
break;
1715 case 16:
return TX_32X16;
break;
1716 case 32:
return TX_64X32;
break;
1720 case 4:
return TX_16X4;
break;
1721 case 8:
return TX_32X8;
break;
1722 case 16:
return TX_64X16;
break;
1730 static INLINE
int txfm_partition_context(
const TXFM_CONTEXT *
const above_ctx,
1731 const TXFM_CONTEXT *
const left_ctx,
1732 BLOCK_SIZE bsize, TX_SIZE tx_size) {
1733 const uint8_t txw = tx_size_wide[tx_size];
1734 const uint8_t txh = tx_size_high[tx_size];
1735 const int above = *above_ctx < txw;
1736 const int left = *left_ctx < txh;
1737 int category = TXFM_PARTITION_CONTEXTS;
1740 if (tx_size <= TX_4X4)
return 0;
1742 TX_SIZE max_tx_size =
1743 get_sqr_tx_size(AOMMAX(block_size_wide[bsize], block_size_high[bsize]));
1745 if (max_tx_size >= TX_8X8) {
1747 (txsize_sqr_up_map[tx_size] != max_tx_size && max_tx_size > TX_8X8) +
1748 (TX_SIZES - 1 - max_tx_size) * 2;
1750 assert(category != TXFM_PARTITION_CONTEXTS);
1751 return category * 3 + above + left;
1756 static INLINE PARTITION_TYPE get_partition(
const AV1_COMMON *
const cm,
1757 int mi_row,
int mi_col,
1760 if (mi_row >= mi_params->
mi_rows || mi_col >= mi_params->
mi_cols)
1761 return PARTITION_INVALID;
1763 const int offset = mi_row * mi_params->
mi_stride + mi_col;
1765 const BLOCK_SIZE subsize = mi[0]->
bsize;
1767 assert(bsize < BLOCK_SIZES_ALL);
1769 if (subsize == bsize)
return PARTITION_NONE;
1771 const int bhigh = mi_size_high[bsize];
1772 const int bwide = mi_size_wide[bsize];
1773 const int sshigh = mi_size_high[subsize];
1774 const int sswide = mi_size_wide[subsize];
1776 if (bsize > BLOCK_8X8 && mi_row + bwide / 2 < mi_params->
mi_rows &&
1777 mi_col + bhigh / 2 < mi_params->
mi_cols) {
1783 if (sswide == bwide) {
1787 if (sshigh * 4 == bhigh)
return PARTITION_HORZ_4;
1788 assert(sshigh * 2 == bhigh);
1790 if (mbmi_below->
bsize == subsize)
1791 return PARTITION_HORZ;
1793 return PARTITION_HORZ_B;
1794 }
else if (sshigh == bhigh) {
1798 if (sswide * 4 == bwide)
return PARTITION_VERT_4;
1799 assert(sswide * 2 == bhigh);
1801 if (mbmi_right->
bsize == subsize)
1802 return PARTITION_VERT;
1804 return PARTITION_VERT_B;
1813 if (sswide * 2 != bwide || sshigh * 2 != bhigh)
return PARTITION_SPLIT;
1815 if (mi_size_wide[mbmi_below->
bsize] == bwide)
return PARTITION_HORZ_A;
1816 if (mi_size_high[mbmi_right->
bsize] == bhigh)
return PARTITION_VERT_A;
1818 return PARTITION_SPLIT;
1821 const int vert_split = sswide < bwide;
1822 const int horz_split = sshigh < bhigh;
1823 const int split_idx = (vert_split << 1) | horz_split;
1824 assert(split_idx != 0);
1826 static const PARTITION_TYPE base_partitions[4] = {
1827 PARTITION_INVALID, PARTITION_HORZ, PARTITION_VERT, PARTITION_SPLIT
1830 return base_partitions[split_idx];
1833 static INLINE
void set_sb_size(SequenceHeader *
const seq_params,
1834 BLOCK_SIZE sb_size) {
1835 seq_params->sb_size = sb_size;
1836 seq_params->mib_size = mi_size_wide[seq_params->sb_size];
1837 seq_params->mib_size_log2 = mi_size_wide_log2[seq_params->sb_size];
1843 static INLINE
int is_coded_lossless(
const AV1_COMMON *cm,
1845 int coded_lossless = 1;
1846 if (cm->
seg.enabled) {
1847 for (
int i = 0; i < MAX_SEGMENTS; ++i) {
1856 return coded_lossless;
1859 static INLINE
int is_valid_seq_level_idx(AV1_LEVEL seq_level_idx) {
1860 return seq_level_idx == SEQ_LEVEL_MAX ||
1861 (seq_level_idx < SEQ_LEVELS &&
1863 seq_level_idx != SEQ_LEVEL_2_2 && seq_level_idx != SEQ_LEVEL_2_3 &&
1864 seq_level_idx != SEQ_LEVEL_3_2 && seq_level_idx != SEQ_LEVEL_3_3 &&
1865 seq_level_idx != SEQ_LEVEL_4_2 && seq_level_idx != SEQ_LEVEL_4_3 &&
1866 seq_level_idx != SEQ_LEVEL_7_0 && seq_level_idx != SEQ_LEVEL_7_1 &&
1867 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:725
uint8_t * last_frame_seg_map
Definition: av1_common_int.h:911
RestorationInfo rst_info[3]
Definition: av1_common_int.h:925
WarpedMotionParams global_motion[REF_FRAMES]
Definition: av1_common_int.h:949
int superres_upscaled_width
Definition: av1_common_int.h:774
bool buffer_removal_time_present
Definition: av1_common_int.h:787
int8_t ref_frame_side[REF_FRAMES]
Definition: av1_common_int.h:1016
struct scale_factors ref_scale_factors[REF_FRAMES]
Definition: av1_common_int.h:848
RefCntBuffer * prev_frame
Definition: av1_common_int.h:805
FRAME_CONTEXT * default_frame_context
Definition: av1_common_int.h:966
int ref_frame_id[REF_FRAMES]
Definition: av1_common_int.h:991
int superres_upscaled_height
Definition: av1_common_int.h:775
DeltaQInfo delta_q_info
Definition: av1_common_int.h:944
int width
Definition: av1_common_int.h:750
RefCntBuffer * cur_frame
Definition: av1_common_int.h:811
CdefInfo cdef_info
Definition: av1_common_int.h:934
loop_filter_info_n lf_info
Definition: av1_common_int.h:917
CurrentFrame current_frame
Definition: av1_common_int.h:729
unsigned int number_spatial_layers
Definition: av1_common_int.h:1031
int remapped_ref_idx[REF_FRAMES]
Definition: av1_common_int.h:833
unsigned int number_temporal_layers
Definition: av1_common_int.h:1021
RestorationLineBuffers * rlbs
Definition: av1_common_int.h:927
aom_film_grain_t film_grain_params
Definition: av1_common_int.h:939
int show_existing_frame
Definition: av1_common_int.h:879
uint32_t buffer_removal_times[(8 *4)+1]
Definition: av1_common_int.h:794
int temporal_layer_id
Definition: av1_common_int.h:1026
SequenceHeader seq_params
Definition: av1_common_int.h:955
int showable_frame
Definition: av1_common_int.h:872
int tpl_mvs_mem_size
Definition: av1_common_int.h:1005
uint32_t frame_presentation_time
Definition: av1_common_int.h:800
struct aom_internal_error_info error
Definition: av1_common_int.h:733
struct loopfilter lf
Definition: av1_common_int.h:918
int spatial_layer_id
Definition: av1_common_int.h:1036
FeatureFlags features
Definition: av1_common_int.h:884
struct scale_factors sf_identity
Definition: av1_common_int.h:840
YV12_BUFFER_CONFIG rst_frame
Definition: av1_common_int.h:928
CommonModeInfoParams mi_params
Definition: av1_common_int.h:889
uint8_t superres_scale_denominator
Definition: av1_common_int.h:782
int show_frame
Definition: av1_common_int.h:864
struct segmentation seg
Definition: av1_common_int.h:906
CommonQuantParams quant_params
Definition: av1_common_int.h:901
TPL_MV_REF * tpl_mvs
Definition: av1_common_int.h:1001
int current_frame_id
Definition: av1_common_int.h:990
int32_t * rst_tmpbuf
Definition: av1_common_int.h:926
RefCntBuffer * ref_frame_map[REF_FRAMES]
Definition: av1_common_int.h:857
CommonContexts above_contexts
Definition: av1_common_int.h:984
CommonTileParams tiles
Definition: av1_common_int.h:971
BufferPool * buffer_pool
Definition: av1_common_int.h:976
int ref_frame_sign_bias[REF_FRAMES]
Definition: av1_common_int.h:1010
FRAME_CONTEXT * fc
Definition: av1_common_int.h:960
int height
Definition: av1_common_int.h:751
int render_width
Definition: av1_common_int.h:761
int render_height
Definition: av1_common_int.h:762
Parameters related to CDEF.
Definition: av1_common_int.h:196
int cdef_bits
Definition: av1_common_int.h:202
int nb_cdef_strengths
Definition: av1_common_int.h:198
int cdef_damping
Definition: av1_common_int.h:197
Contexts used for transmitting various symbols in the bitstream.
Definition: av1_common_int.h:688
PARTITION_CONTEXT ** partition
Definition: av1_common_int.h:693
int num_planes
Definition: av1_common_int.h:717
ENTROPY_CONTEXT ** entropy[3]
Definition: av1_common_int.h:703
int num_tile_rows
Definition: av1_common_int.h:718
int num_mi_cols
Definition: av1_common_int.h:719
TXFM_CONTEXT ** txfm
Definition: av1_common_int.h:711
Params related to MB_MODE_INFO arrays and related info.
Definition: av1_common_int.h:479
int mb_cols
Definition: av1_common_int.h:489
MB_MODE_INFO * mi_alloc
Definition: av1_common_int.h:513
int mi_rows
Definition: av1_common_int.h:500
void(* setup_mi)(struct CommonModeInfoParams *mi_params)
Definition: av1_common_int.h:568
void(* free_mi)(struct CommonModeInfoParams *mi_params)
Definition: av1_common_int.h:563
int mi_cols
Definition: av1_common_int.h:505
int mi_alloc_size
Definition: av1_common_int.h:517
int MBs
Definition: av1_common_int.h:494
TX_TYPE * tx_type_map
Definition: av1_common_int.h:553
void(* set_mb_mi)(struct CommonModeInfoParams *mi_params, int width, int height)
Definition: av1_common_int.h:575
int mi_alloc_stride
Definition: av1_common_int.h:521
int mi_grid_size
Definition: av1_common_int.h:541
int mi_stride
Definition: av1_common_int.h:545
int mb_rows
Definition: av1_common_int.h:484
MB_MODE_INFO ** mi_grid_base
Definition: av1_common_int.h:537
BLOCK_SIZE mi_alloc_bsize
Definition: av1_common_int.h:528
Parameters related to quantization at the frame level.
Definition: av1_common_int.h:584
int u_ac_delta_q
Definition: av1_common_int.h:609
const qm_val_t * u_iqmatrix[8][TX_SIZES_ALL]
Definition: av1_common_int.h:658
int qmatrix_level_v
Definition: av1_common_int.h:680
const qm_val_t * giqmatrix[(1<< 4)][3][TX_SIZES_ALL]
Definition: av1_common_int.h:640
int16_t u_dequant_QTX[8][2]
Definition: av1_common_int.h:629
const qm_val_t * y_iqmatrix[8][TX_SIZES_ALL]
Definition: av1_common_int.h:654
int qmatrix_level_y
Definition: av1_common_int.h:678
int v_ac_delta_q
Definition: av1_common_int.h:614
bool using_qmatrix
Definition: av1_common_int.h:671
int u_dc_delta_q
Definition: av1_common_int.h:599
int qmatrix_level_u
Definition: av1_common_int.h:679
int base_qindex
Definition: av1_common_int.h:588
int16_t v_dequant_QTX[8][2]
Definition: av1_common_int.h:630
const qm_val_t * v_iqmatrix[8][TX_SIZES_ALL]
Definition: av1_common_int.h:662
int16_t y_dequant_QTX[8][2]
Definition: av1_common_int.h:628
int v_dc_delta_q
Definition: av1_common_int.h:603
int y_dc_delta_q
Definition: av1_common_int.h:594
const qm_val_t * gqmatrix[(1<< 4)][3][TX_SIZES_ALL]
Definition: av1_common_int.h:644
Params related to tiles.
Definition: av1_common_int.h:405
int uniform_spacing
Definition: av1_common_int.h:421
int max_width_sb
Definition: av1_common_int.h:408
int log2_rows
Definition: av1_common_int.h:428
int min_log2_rows
Definition: av1_common_int.h:440
int width
Definition: av1_common_int.h:429
int max_log2_rows
Definition: av1_common_int.h:448
int row_start_sb[MAX_TILE_ROWS+1]
Definition: av1_common_int.h:462
int cols
Definition: av1_common_int.h:406
int max_height_sb
Definition: av1_common_int.h:409
unsigned int large_scale
Definition: av1_common_int.h:466
unsigned int single_tile_decoding
Definition: av1_common_int.h:472
int max_log2_cols
Definition: av1_common_int.h:444
int log2_cols
Definition: av1_common_int.h:427
int min_log2
Definition: av1_common_int.h:452
int rows
Definition: av1_common_int.h:407
int min_inner_width
Definition: av1_common_int.h:414
int min_log2_cols
Definition: av1_common_int.h:436
int col_start_sb[MAX_TILE_COLS+1]
Definition: av1_common_int.h:457
int height
Definition: av1_common_int.h:430
Frame level features.
Definition: av1_common_int.h:336
InterpFilter interp_filter
Definition: av1_common_int.h:385
bool allow_ref_frame_mvs
Definition: av1_common_int.h:359
bool allow_warped_motion
Definition: av1_common_int.h:355
bool allow_screen_content_tools
Definition: av1_common_int.h:353
bool switchable_motion_mode
Definition: av1_common_int.h:383
TX_MODE tx_mode
Definition: av1_common_int.h:384
bool reduced_tx_set_used
Definition: av1_common_int.h:372
bool allow_intrabc
Definition: av1_common_int.h:354
int byte_alignment
Definition: av1_common_int.h:394
bool coded_lossless
Definition: av1_common_int.h:363
REFRESH_FRAME_CONTEXT_MODE refresh_frame_context
Definition: av1_common_int.h:399
bool error_resilient_mode
Definition: av1_common_int.h:378
int primary_ref_frame
Definition: av1_common_int.h:390
bool disable_cdf_update
Definition: av1_common_int.h:340
bool allow_high_precision_mv
Definition: av1_common_int.h:345
bool cur_frame_force_integer_mv
Definition: av1_common_int.h:349
bool all_lossless
Definition: av1_common_int.h:367
Stores the prediction/txfm mode of the current coding block.
Definition: blockd.h:216
BLOCK_SIZE bsize
The block size of the current coding block.
Definition: blockd.h:222
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:568
bool left_available
Definition: blockd.h:624
uint8_t * tx_type_map
Definition: blockd.h:664
int mb_to_bottom_edge
Definition: blockd.h:678
TXFM_CONTEXT * left_txfm_context
Definition: blockd.h:738
struct macroblockd_plane plane[3]
Definition: blockd.h:604
int mb_to_top_edge
Definition: blockd.h:677
int mb_to_right_edge
Definition: blockd.h:676
bool up_available
Definition: blockd.h:620
MB_MODE_INFO * above_mbmi
Definition: blockd.h:643
bool chroma_up_available
Definition: blockd.h:628
TXFM_CONTEXT * above_txfm_context
Definition: blockd.h:731
bool chroma_left_available
Definition: blockd.h:632
PARTITION_CONTEXT * above_partition_context
Definition: blockd.h:716
MB_MODE_INFO * chroma_left_mbmi
Definition: blockd.h:650
TXFM_CONTEXT left_txfm_context_buffer[MAX_MIB_SIZE]
Definition: blockd.h:745
int tx_type_map_stride
Definition: blockd.h:669
MB_MODE_INFO * chroma_above_mbmi
Definition: blockd.h:657
int mi_row
Definition: blockd.h:573
int mi_stride
Definition: blockd.h:580
bool is_last_vertical_rect
Definition: blockd.h:785
bool is_first_horizontal_rect
Definition: blockd.h:790
uint8_t width
Definition: blockd.h:763
struct aom_internal_error_info * error_info
Definition: blockd.h:836
CFL_CTX cfl
Definition: blockd.h:892
int lossless[8]
Definition: blockd.h:815
ENTROPY_CONTEXT left_entropy_context[3][MAX_MIB_SIZE]
Definition: blockd.h:708
ENTROPY_CONTEXT * above_entropy_context[3]
Definition: blockd.h:701
MB_MODE_INFO ** mi
Definition: blockd.h:615
uint8_t height
Definition: blockd.h:764
MB_MODE_INFO * left_mbmi
Definition: blockd.h:638
PARTITION_CONTEXT left_partition_context[MAX_MIB_SIZE]
Definition: blockd.h:723
bool is_chroma_ref
Definition: blockd.h:599
int mi_col
Definition: blockd.h:574
int mb_to_left_edge
Definition: blockd.h:675
YV12 frame buffer data structure.
Definition: yv12config.h:38