Modularize a buffer related info in AV1_COMP
This CL groups MB_MODE_INFO_EXT_FRAME and related
variables from AV1_COMP into a new struct ModeInfoExtFrame,
adds documentation, and cleans up function interfaces.
BUG=aomedia:2610
Change-Id: I5ca6268e28012ee5741d6cec555815f7004ebad6
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index 805a112..aafa9fd 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -1311,12 +1311,15 @@
#endif
#if ENC_MISMATCH_DEBUG
-static AOM_INLINE void enc_dump_logs(AV1_COMP *cpi, int mi_row, int mi_col) {
- AV1_COMMON *const cm = &cpi->common;
+static AOM_INLINE void enc_dump_logs(
+ const AV1_COMMON *const cm,
+ const MBMIExtFrameBufferInfo *const mbmi_ext_info, int mi_row, int mi_col) {
const MB_MODE_INFO *const mbmi = *(
cm->mi_params.mi_grid_base + (mi_row * cm->mi_params.mi_stride + mi_col));
- const MB_MODE_INFO_EXT_FRAME *const mbmi_ext_frame_base =
- cpi->mbmi_ext_frame_base + get_mi_ext_idx(&cm->mi_params, mi_row, mi_col);
+ const MB_MODE_INFO_EXT_FRAME *const mbmi_ext_frame =
+ mbmi_ext_info->frame_base + get_mi_ext_idx(mi_row, mi_col,
+ cm->mi_params.mi_alloc_bsize,
+ mbmi_ext_info->stride);
if (is_inter_block(mbmi)) {
#define FRAME_TO_CHECK 11
if (cm->current_frame.frame_number == FRAME_TO_CHECK &&
@@ -1378,7 +1381,7 @@
set_ref_ptrs(cm, xd, m->ref_frame[0], m->ref_frame[1]);
#if ENC_MISMATCH_DEBUG
- enc_dump_logs(cpi, xd->mi_row, xd->mi_col);
+ enc_dump_logs(cm, &cpi->mbmi_ext_info, xd->mi_row, xd->mi_col);
#endif // ENC_MISMATCH_DEBUG
pack_inter_mode_mvs(cpi, w);
@@ -1485,7 +1488,9 @@
const int grid_idx = mi_row * mi_params->mi_stride + mi_col;
xd->mi = mi_params->mi_grid_base + grid_idx;
cpi->td.mb.mbmi_ext_frame =
- cpi->mbmi_ext_frame_base + get_mi_ext_idx(cpi, mi_row, mi_col);
+ cpi->mbmi_ext_info.frame_base +
+ get_mi_ext_idx(mi_row, mi_col, cm->mi_params.mi_alloc_bsize,
+ cpi->mbmi_ext_info.stride);
xd->tx_type_map = mi_params->tx_type_map + grid_idx;
xd->tx_type_map_stride = mi_params->mi_stride;
diff --git a/av1/encoder/block.h b/av1/encoder/block.h
index e0a96c2..51c84d8 100644
--- a/av1/encoder/block.h
+++ b/av1/encoder/block.h
@@ -107,7 +107,7 @@
uint8_t ref_mv_count[MODE_CTX_REF_FRAMES];
} MB_MODE_INFO_EXT;
-// Structure to store winner reference mode information at frame level. This
+// Structure to store best mode information at frame level. This
// frame level information will be used during bitstream preparation stage.
typedef struct {
CANDIDATE_MV ref_mv_stack[USABLE_REF_MV_STACK_SIZE];
diff --git a/av1/encoder/encode_strategy.c b/av1/encoder/encode_strategy.c
index d978335..8a064f1 100644
--- a/av1/encoder/encode_strategy.c
+++ b/av1/encoder/encode_strategy.c
@@ -904,8 +904,9 @@
av1_init_mi_buffers(&cm->mi_params);
setup_mi(cpi, frame_input->source);
av1_init_macroblockd(cm, xd, NULL);
- memset(cpi->mbmi_ext_frame_base, 0,
- cpi->mbmi_ext_alloc_size * sizeof(*cpi->mbmi_ext_frame_base));
+ memset(
+ cpi->mbmi_ext_info.frame_base, 0,
+ cpi->mbmi_ext_info.alloc_size * sizeof(*cpi->mbmi_ext_info.frame_base));
av1_set_speed_features_framesize_independent(cpi, oxcf->speed);
av1_set_speed_features_framesize_dependent(cpi, oxcf->speed);
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 5a3c2d3..cf92f21 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -394,7 +394,8 @@
const int mi_width = mi_size_wide[bsize];
const int mi_height = mi_size_high[bsize];
- set_mode_info_offsets(cpi, x, xd, mi_row, mi_col);
+ set_mode_info_offsets(&cpi->common.mi_params, &cpi->mbmi_ext_info, x, xd,
+ mi_row, mi_col);
set_entropy_context(xd, mi_row, mi_col, num_planes);
xd->above_txfm_context = cm->above_contexts.txfm[tile->tile_row] + mi_col;
@@ -1678,10 +1679,10 @@
}
}
// TODO(Ravi/Remya): Move this copy function to a better logical place
- // This function will copy the winner reference mode information from block
- // level (x->mbmi_ext) to frame level (cpi->mbmi_ext_frame_base). This frame
- // level buffer (cpi->mbmi_ext_frame_base) will be used during bitstream
- // preparation.
+ // This function will copy the best mode information from block
+ // level (x->mbmi_ext) to frame level (cpi->mbmi_ext_info.frame_base). This
+ // frame level buffer (cpi->mbmi_ext_info.frame_base) will be used during
+ // bitstream preparation.
av1_copy_mbmi_ext_to_mbmi_ext_frame(x->mbmi_ext_frame, x->mbmi_ext,
av1_ref_frame_type(xd->mi[0]->ref_frame));
x->rdmult = origin_mult;
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 6bb1e59..43f85a3 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -715,16 +715,16 @@
av1_init_wedge_masks();
}
-static void dealloc_context_buffers_ext(AV1_COMP *cpi) {
- if (cpi->mbmi_ext_frame_base) {
- aom_free(cpi->mbmi_ext_frame_base);
- cpi->mbmi_ext_frame_base = NULL;
- cpi->mbmi_ext_alloc_size = 0;
+static void dealloc_context_buffers_ext(MBMIExtFrameBufferInfo *mbmi_ext_info) {
+ if (mbmi_ext_info->frame_base) {
+ aom_free(mbmi_ext_info->frame_base);
+ mbmi_ext_info->frame_base = NULL;
+ mbmi_ext_info->alloc_size = 0;
}
}
-static void alloc_context_buffers_ext(AV1_COMP *cpi) {
- AV1_COMMON *cm = &cpi->common;
+static void alloc_context_buffers_ext(AV1_COMMON *cm,
+ MBMIExtFrameBufferInfo *mbmi_ext_info) {
const CommonModeInfoParams *const mi_params = &cm->mi_params;
const int mi_alloc_size_1d = mi_size_wide[mi_params->mi_alloc_bsize];
@@ -734,16 +734,16 @@
(mi_params->mi_cols + mi_alloc_size_1d - 1) / mi_alloc_size_1d;
const int new_ext_mi_size = mi_alloc_rows * mi_alloc_cols;
- if (new_ext_mi_size > cpi->mbmi_ext_alloc_size) {
- dealloc_context_buffers_ext(cpi);
+ if (new_ext_mi_size > mbmi_ext_info->alloc_size) {
+ dealloc_context_buffers_ext(mbmi_ext_info);
CHECK_MEM_ERROR(
- cm, cpi->mbmi_ext_frame_base,
- aom_calloc(new_ext_mi_size, sizeof(*cpi->mbmi_ext_frame_base)));
- cpi->mbmi_ext_alloc_size = new_ext_mi_size;
+ cm, mbmi_ext_info->frame_base,
+ aom_calloc(new_ext_mi_size, sizeof(*mbmi_ext_info->frame_base)));
+ mbmi_ext_info->alloc_size = new_ext_mi_size;
}
// The stride needs to be updated regardless of whether new allocation
// happened or not.
- cpi->mbmi_ext_stride = mi_alloc_cols;
+ mbmi_ext_info->stride = mi_alloc_cols;
}
static void reset_film_grain_chroma_params(aom_film_grain_t *pars) {
@@ -806,7 +806,7 @@
AV1_COMMON *const cm = &cpi->common;
const int num_planes = av1_num_planes(cm);
- dealloc_context_buffers_ext(cpi);
+ dealloc_context_buffers_ext(&cpi->mbmi_ext_info);
aom_free(cpi->tile_data);
cpi->tile_data = NULL;
@@ -1124,7 +1124,7 @@
if (!is_stat_generation_stage(cpi)) {
av1_alloc_txb_buf(cpi);
- alloc_context_buffers_ext(cpi);
+ alloc_context_buffers_ext(cm, &cpi->mbmi_ext_info);
}
aom_free(cpi->tile_tok[0][0]);
@@ -1232,7 +1232,8 @@
av1_init_macroblockd(cm, xd, NULL);
- if (!is_stat_generation_stage(cpi)) alloc_context_buffers_ext(cpi);
+ if (!is_stat_generation_stage(cpi))
+ alloc_context_buffers_ext(cm, &cpi->mbmi_ext_info);
set_tile_info(cpi);
}
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index 75165c6..6eadff3 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -746,6 +746,17 @@
YV12_BUFFER_CONFIG buf;
} EncRefCntBuffer;
+typedef struct {
+ // Buffer to store mode information at mi_alloc_bsize (4x4 or 8x8) level for
+ // use in bitstream preparation. frame_base[mi_row * stride + mi_col] stores
+ // the mode information of block (mi_row,mi_col).
+ MB_MODE_INFO_EXT_FRAME *frame_base;
+ // Size of frame_base buffer.
+ int alloc_size;
+ // Stride of frame_base buffer.
+ int stride;
+} MBMIExtFrameBufferInfo;
+
#if CONFIG_COLLECT_PARTITION_STATS == 2
typedef struct PartitionStats {
int partition_decisions[6][EXT_PARTITION_TYPES];
@@ -961,9 +972,10 @@
QUANTS quants;
ThreadData td;
FRAME_COUNTS counts;
- MB_MODE_INFO_EXT_FRAME *mbmi_ext_frame_base;
- int mbmi_ext_alloc_size;
- int mbmi_ext_stride;
+
+ // Holds buffer storing mode information at 4x4/8x8 level.
+ MBMIExtFrameBufferInfo mbmi_ext_info;
+
CB_COEFF_BUFFER *coeff_buffer_base;
Dequants dequants;
AV1_COMMON common;
@@ -1608,26 +1620,27 @@
cm->current_frame.frame_type == KEY_FRAME);
}
-// Get index into the 'cpi->mbmi_ext_frame_base' array for the given 'mi_row'
-// and 'mi_col'.
-static INLINE int get_mi_ext_idx(const AV1_COMP *const cpi, int mi_row,
- int mi_col) {
- const BLOCK_SIZE mi_ext_bsize = cpi->common.mi_params.mi_alloc_bsize;
- const int mi_ext_size_1d = mi_size_wide[mi_ext_bsize];
+// Get index into the 'cpi->mbmi_ext_info.frame_base' array for the given
+// 'mi_row' and 'mi_col'.
+static INLINE int get_mi_ext_idx(const int mi_row, const int mi_col,
+ const BLOCK_SIZE mi_alloc_bsize,
+ const int mbmi_ext_stride) {
+ const int mi_ext_size_1d = mi_size_wide[mi_alloc_bsize];
const int mi_ext_row = mi_row / mi_ext_size_1d;
const int mi_ext_col = mi_col / mi_ext_size_1d;
- return mi_ext_row * cpi->mbmi_ext_stride + mi_ext_col;
+ return mi_ext_row * mbmi_ext_stride + mi_ext_col;
}
// Lighter version of set_offsets that only sets the mode info
// pointers.
-static INLINE void set_mode_info_offsets(const AV1_COMP *const cpi,
- MACROBLOCK *const x,
- MACROBLOCKD *const xd, int mi_row,
- int mi_col) {
- set_mi_offsets(&cpi->common.mi_params, xd, mi_row, mi_col);
- const int ext_idx = get_mi_ext_idx(cpi, mi_row, mi_col);
- x->mbmi_ext_frame = cpi->mbmi_ext_frame_base + ext_idx;
+static INLINE void set_mode_info_offsets(
+ const CommonModeInfoParams *const mi_params,
+ const MBMIExtFrameBufferInfo *const mbmi_ext_info, MACROBLOCK *const x,
+ MACROBLOCKD *const xd, int mi_row, int mi_col) {
+ set_mi_offsets(mi_params, xd, mi_row, mi_col);
+ const int ext_idx = get_mi_ext_idx(mi_row, mi_col, mi_params->mi_alloc_bsize,
+ mbmi_ext_info->stride);
+ x->mbmi_ext_frame = mbmi_ext_info->frame_base + ext_idx;
}
// Check to see if the given partition size is allowed for a specified number
diff --git a/av1/encoder/mv_prec.c b/av1/encoder/mv_prec.c
index c36f0b2..8fcbde9 100644
--- a/av1/encoder/mv_prec.c
+++ b/av1/encoder/mv_prec.c
@@ -186,7 +186,9 @@
const MB_MODE_INFO *mbmi =
mi_params->mi_grid_base[mi_row * mi_params->mi_stride + mi_col];
const MB_MODE_INFO_EXT_FRAME *mbmi_ext_frame =
- cpi->mbmi_ext_frame_base + get_mi_ext_idx(cpi, mi_row, mi_col);
+ cpi->mbmi_ext_info.frame_base +
+ get_mi_ext_idx(mi_row, mi_col, cm->mi_params.mi_alloc_bsize,
+ cpi->mbmi_ext_info.stride);
if (!is_inter_block(mbmi)) {
mv_stats->intra_count++;
diff --git a/av1/encoder/partition_strategy.h b/av1/encoder/partition_strategy.h
index e9e624b..f9b4d8b 100644
--- a/av1/encoder/partition_strategy.h
+++ b/av1/encoder/partition_strategy.h
@@ -146,7 +146,8 @@
const int mi_width = mi_size_wide[bsize];
const int mi_height = mi_size_high[bsize];
- set_mode_info_offsets(cpi, x, xd, mi_row, mi_col);
+ set_mode_info_offsets(&cpi->common.mi_params, &cpi->mbmi_ext_info, x, xd,
+ mi_row, mi_col);
// Set up destination pointers.
av1_setup_dst_planes(xd->plane, bsize, &cm->cur_frame->buf, mi_row, mi_col, 0,
diff --git a/av1/encoder/tpl_model.c b/av1/encoder/tpl_model.c
index 7c34de7..6f3b50d 100644
--- a/av1/encoder/tpl_model.c
+++ b/av1/encoder/tpl_model.c
@@ -238,7 +238,8 @@
const int mi_width = mi_size_wide[bsize];
const int mi_height = mi_size_high[bsize];
- set_mode_info_offsets(cpi, x, xd, mi_row, mi_col);
+ set_mode_info_offsets(&cpi->common.mi_params, &cpi->mbmi_ext_info, x, xd,
+ mi_row, mi_col);
set_mi_row_col(xd, &xd->tile, mi_row, mi_height, mi_col, mi_width,
cm->mi_params.mi_rows, cm->mi_params.mi_cols);
set_plane_n4(xd, mi_size_wide[bsize], mi_size_high[bsize],
diff --git a/av1/encoder/var_based_part.c b/av1/encoder/var_based_part.c
index 6740670..be762ae 100644
--- a/av1/encoder/var_based_part.c
+++ b/av1/encoder/var_based_part.c
@@ -128,7 +128,8 @@
int mi_col, BLOCK_SIZE bsize) {
if (cpi->common.mi_params.mi_cols > mi_col &&
cpi->common.mi_params.mi_rows > mi_row) {
- set_mode_info_offsets(cpi, x, xd, mi_row, mi_col);
+ set_mode_info_offsets(&cpi->common.mi_params, &cpi->mbmi_ext_info, x, xd,
+ mi_row, mi_col);
xd->mi[0]->sb_type = bsize;
}
}