Commit 6cc1fd31 authored by Jingning Han's avatar Jingning Han

Refactor motion field mv buffer

Reduce the needed memory space for motion field estimation.

Change-Id: I9caa228aa804a06370a34715a1c3463564d8d86b
parent f9970a5d
......@@ -134,6 +134,10 @@ static aom_codec_err_t decoder_destroy(aom_codec_alg_priv_t *ctx) {
#if CONFIG_MULTITHREAD
pthread_mutex_destroy(&frame_worker_data->stats_mutex);
pthread_cond_destroy(&frame_worker_data->stats_cond);
#endif
#if CONFIG_MFMV
aom_free(frame_worker_data->pbi->common.tpl_mvs);
frame_worker_data->pbi->common.tpl_mvs = NULL;
#endif
aom_free(frame_worker_data);
}
......
......@@ -134,10 +134,6 @@ void av1_free_ref_frame_buffers(BufferPool *pool) {
}
aom_free(pool->frame_bufs[i].mvs);
pool->frame_bufs[i].mvs = NULL;
#if CONFIG_MFMV
aom_free(pool->frame_bufs[i].tpl_mvs);
pool->frame_bufs[i].tpl_mvs = NULL;
#endif
aom_free_frame_buffer(&pool->frame_bufs[i].buf);
#if CONFIG_HASH_ME
av1_hash_table_destroy(&pool->frame_bufs[i].hash_table);
......
......@@ -544,8 +544,7 @@ static int add_tpl_ref_mv(const AV1_COMMON *cm,
return coll_blk_count;
const TPL_MV_REF *prev_frame_mvs =
cm->cur_frame->tpl_mvs +
((mi_row + mi_pos.row) >> 1) * (cm->mi_stride >> 1) +
cm->tpl_mvs + ((mi_row + mi_pos.row) >> 1) * (cm->mi_stride >> 1) +
((mi_col + mi_pos.col) >> 1);
MV_REFERENCE_FRAME rf[2];
......@@ -1648,7 +1647,7 @@ void av1_setup_motion_field(AV1_COMMON *cm) {
int lst2_frame_index = 0, lst3_frame_index = 0;
int bwd_frame_index = 0, alt2_frame_index = 0;
#endif
TPL_MV_REF *tpl_mvs_base = cm->cur_frame->tpl_mvs;
TPL_MV_REF *tpl_mvs_base = cm->tpl_mvs;
for (int ref_frame = 0; ref_frame < INTER_REFS_PER_FRAME; ++ref_frame) {
int size = ((cm->mi_rows + MAX_MIB_SIZE) >> 1) * (cm->mi_stride >> 1);
......
......@@ -141,9 +141,6 @@ typedef struct {
#endif
#endif // CONFIG_FRAME_MARKER
#if CONFIG_MFMV
TPL_MV_REF *tpl_mvs;
#endif
MV_REF *mvs;
int mi_rows;
int mi_cols;
......@@ -547,6 +544,9 @@ typedef struct AV1Common {
#if CONFIG_ADAPT_SCAN
int use_adapt_scan;
#endif
#if CONFIG_MFMV
TPL_MV_REF *tpl_mvs;
#endif
} AV1_COMMON;
// TODO(hkuang): Don't need to lock the whole pool after implementing atomic
......@@ -642,15 +642,18 @@ static INLINE void ensure_mv_buffer(RefCntBuffer *buf, AV1_COMMON *cm) {
cm, buf->mvs,
(MV_REF *)aom_calloc(cm->mi_rows * cm->mi_cols, sizeof(*buf->mvs)));
#endif // CONFIG_TMV
}
#if CONFIG_MFMV
aom_free(buf->tpl_mvs);
CHECK_MEM_ERROR(cm, buf->tpl_mvs, (TPL_MV_REF *)aom_calloc(
((cm->mi_rows + MAX_MIB_SIZE) >> 1) *
(cm->mi_stride >> 1),
sizeof(*buf->tpl_mvs)));
#endif
if (cm->tpl_mvs == NULL || buf->mi_rows < cm->mi_rows ||
buf->mi_cols < cm->mi_cols) {
aom_free(cm->tpl_mvs);
CHECK_MEM_ERROR(cm, cm->tpl_mvs, (TPL_MV_REF *)aom_calloc(
((cm->mi_rows + MAX_MIB_SIZE) >> 1) *
(cm->mi_stride >> 1),
sizeof(*cm->tpl_mvs)));
}
#endif
}
#if CONFIG_VAR_REFS
......
......@@ -552,6 +552,11 @@ static void dealloc_compressor_data(AV1_COMP *cpi) {
cpi->td.mb.mask_buf = NULL;
#endif
#if CONFIG_MFMV
aom_free(cm->tpl_mvs);
cm->tpl_mvs = NULL;
#endif
av1_free_ref_frame_buffers(cm->buffer_pool);
#if CONFIG_LV_MAP
av1_free_txb_buf(cpi);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment