Commit 934af35b authored by Soo-Chul Han's avatar Soo-Chul Han

add segment_pred_last(adopted)

temporal segment map prediction from LAST frame instead of previous

Change-Id: I2f803581c2a6ff72ae428783e596aa3281492073
parent 8263f80c
......@@ -48,6 +48,7 @@ void av1_set_mb_mi(AV1_COMMON *cm, int width, int height) {
cm->MBs = cm->mb_rows * cm->mb_cols;
}
#if !CONFIG_SEGMENT_PRED_LAST
static int alloc_seg_map(AV1_COMMON *cm, int rows, int cols) {
int i;
int seg_map_size = rows * cols;
......@@ -94,6 +95,7 @@ static void free_seg_map(AV1_COMMON *cm) {
}
cm->seg_map_alloc_size = 0;
}
#endif
void av1_free_ref_frame_buffers(BufferPool *pool) {
int i;
......@@ -106,6 +108,10 @@ void av1_free_ref_frame_buffers(BufferPool *pool) {
}
aom_free(pool->frame_bufs[i].mvs);
pool->frame_bufs[i].mvs = NULL;
#if CONFIG_SEGMENT_PRED_LAST
aom_free(pool->frame_bufs[i].seg_map);
pool->frame_bufs[i].seg_map = 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);
......@@ -203,7 +209,9 @@ void av1_free_restoration_buffers(AV1_COMMON *cm) {
void av1_free_context_buffers(AV1_COMMON *cm) {
int i;
cm->free_mi(cm);
#if !CONFIG_SEGMENT_PRED_LAST
free_seg_map(cm);
#endif
for (i = 0; i < MAX_MB_PLANE; i++) {
aom_free(cm->above_context[i]);
cm->above_context[i] = NULL;
......@@ -230,11 +238,13 @@ int av1_alloc_context_buffers(AV1_COMMON *cm, int width, int height) {
if (cm->alloc_mi(cm, new_mi_size)) goto fail;
}
#if !CONFIG_SEGMENT_PRED_LAST
if (cm->seg_map_alloc_size < cm->mi_rows * cm->mi_cols) {
// Create the segmentation map structure and set to 0.
free_seg_map(cm);
if (alloc_seg_map(cm, cm->mi_rows, cm->mi_cols)) goto fail;
}
#endif
if (cm->above_context_alloc_cols < cm->mi_cols) {
// TODO(geza.lore): These are bigger than they need to be.
......@@ -293,10 +303,12 @@ void av1_remove_common(AV1_COMMON *cm) {
void av1_init_context_buffers(AV1_COMMON *cm) {
cm->setup_mi(cm);
#if !CONFIG_SEGMENT_PRED_LAST
if (cm->last_frame_seg_map && !cm->frame_parallel_decode)
memset(cm->last_frame_seg_map, 0, cm->mi_rows * cm->mi_cols);
#endif
}
#if !CONFIG_SEGMENT_PRED_LAST
void av1_swap_current_and_last_seg_map(AV1_COMMON *cm) {
// Swap indices.
const int tmp = cm->seg_map_idx;
......@@ -306,3 +318,4 @@ void av1_swap_current_and_last_seg_map(AV1_COMMON *cm) {
cm->current_frame_seg_map = cm->seg_map_array[cm->seg_map_idx];
cm->last_frame_seg_map = cm->seg_map_array[cm->prev_seg_map_idx];
}
#endif
......@@ -39,7 +39,9 @@ void av1_free_state_buffers(struct AV1Common *cm);
void av1_set_mb_mi(struct AV1Common *cm, int width, int height);
int av1_get_MBs(int width, int height);
#if !CONFIG_SEGMENT_PRED_LAST
void av1_swap_current_and_last_seg_map(struct AV1Common *cm);
#endif
#ifdef __cplusplus
} // extern "C"
......
......@@ -151,6 +151,9 @@ typedef struct {
#endif // CONFIG_FRAME_MARKER
MV_REF *mvs;
#if CONFIG_SEGMENT_PRED_LAST
uint8_t *seg_map;
#endif
int mi_rows;
int mi_cols;
// Width and height give the size of the buffer (before any upscaling, unlike
......@@ -391,11 +394,13 @@ typedef struct AV1Common {
int use_ref_frame_mvs;
#if !CONFIG_SEGMENT_PRED_LAST
// Persistent mb segment id map used in prediction.
int seg_map_idx;
int prev_seg_map_idx;
uint8_t *seg_map_array[NUM_PING_PONG_BUFFERS];
#endif
uint8_t *last_frame_seg_map;
uint8_t *current_frame_seg_map;
#if CONFIG_Q_SEGMENTATION
......
......@@ -1401,7 +1401,16 @@ static void setup_superres(AV1_COMMON *const cm, struct aom_read_bit_buffer *rb,
}
}
#endif // CONFIG_FRAME_SUPERRES
#if CONFIG_SEGMENT_PRED_LAST
static void resize_segmap_buffer(AV1_COMMON *cm) {
aom_free(cm->cur_frame->seg_map);
cm->cur_frame->mi_rows = cm->mi_rows;
cm->cur_frame->mi_cols = cm->mi_cols;
CHECK_MEM_ERROR(cm, cm->cur_frame->seg_map,
(uint8_t *)aom_calloc(cm->mi_rows * cm->mi_cols,
sizeof(*cm->cur_frame->seg_map)));
}
#endif
static void resize_context_buffers(AV1_COMMON *cm, int width, int height) {
#if CONFIG_SIZE_LIMIT
if (width > DECODE_WIDTH_LIMIT || height > DECODE_HEIGHT_LIMIT)
......@@ -1430,6 +1439,12 @@ static void resize_context_buffers(AV1_COMMON *cm, int width, int height) {
}
ensure_mv_buffer(cm->cur_frame, cm);
#if CONFIG_SEGMENT_PRED_LAST
if (cm->cur_frame->seg_map == NULL || cm->mi_rows > cm->cur_frame->mi_rows ||
cm->mi_cols > cm->cur_frame->mi_cols) {
resize_segmap_buffer(cm);
}
#endif
cm->cur_frame->width = cm->width;
cm->cur_frame->height = cm->height;
}
......@@ -3521,6 +3536,15 @@ size_t av1_decode_frame_headers_and_setup(AV1Decoder *pbi, const uint8_t *data,
(cm->last_frame_type != KEY_FRAME);
#endif // CONFIG_TEMPMV_SIGNALING
#if CONFIG_SEGMENT_PRED_LAST
cm->current_frame_seg_map = cm->cur_frame->seg_map;
if (cm->current_frame_seg_map)
memset(cm->current_frame_seg_map, 0, (cm->mi_rows * cm->mi_cols));
if (cm->seg.temporal_update) {
cm->last_frame_seg_map = cm->prev_frame->seg_map;
}
#endif
#if CONFIG_MFMV
av1_setup_motion_field(cm);
#endif // CONFIG_MFMV
......
......@@ -397,7 +397,11 @@ int av1_receive_compressed_data(AV1Decoder *pbi, size_t size,
if (cm->is_reference_frame) cm->prev_frame = cm->cur_frame;
if (cm->seg.enabled && !cm->frame_parallel_decode)
#if CONFIG_SEGMENT_PRED_LAST
cm->last_frame_seg_map = cm->prev_frame->seg_map;
#else
av1_swap_current_and_last_seg_map(cm);
#endif
}
// Update progress in frame parallel decode.
......
......@@ -4215,6 +4215,12 @@ static void encode_frame_internal(AV1_COMP *cpi) {
cm->use_prev_frame_mvs = 0;
}
#endif // CONFIG_TEMPMV_SIGNALING
#if CONFIG_SEGMENT_PRED_LAST
if (cm->prev_frame) cm->last_frame_seg_map = cm->prev_frame->seg_map;
cm->current_frame_seg_map = cm->cur_frame->seg_map;
if (cm->current_frame_seg_map)
memset(cm->current_frame_seg_map, 0, (cm->mi_rows * cm->mi_cols));
#endif
// Special case: set prev_mi to NULL when the previous mode info
// context cannot be used.
......
......@@ -741,7 +741,11 @@ static void configure_static_seg_features(AV1_COMP *cpi) {
static void update_reference_segmentation_map(AV1_COMP *cpi) {
AV1_COMMON *const cm = &cpi->common;
MODE_INFO **mi_8x8_ptr = cm->mi_grid_visible;
#if CONFIG_SEGMENT_PRED_LAST
uint8_t *cache_ptr = cm->current_frame_seg_map;
#else
uint8_t *cache_ptr = cm->last_frame_seg_map;
#endif
int row, col;
for (row = 0; row < cm->mi_rows; row++) {
......@@ -3929,6 +3933,21 @@ static INLINE void alloc_frame_mvs(AV1_COMMON *const cm, int buffer_idx) {
new_fb_ptr->height = cm->height;
}
#if CONFIG_SEGMENT_PRED_LAST
static INLINE void alloc_frame_segmap(AV1_COMMON *const cm, int buffer_idx) {
RefCntBuffer *const new_fb_ptr = &cm->buffer_pool->frame_bufs[buffer_idx];
if (new_fb_ptr->seg_map == NULL || new_fb_ptr->mi_rows < cm->mi_rows ||
new_fb_ptr->mi_cols < cm->mi_cols) {
aom_free(new_fb_ptr->seg_map);
CHECK_MEM_ERROR(cm, new_fb_ptr->seg_map,
(uint8_t *)aom_calloc(cm->mi_rows * cm->mi_cols,
sizeof(*new_fb_ptr->seg_map)));
new_fb_ptr->mi_rows = cm->mi_rows;
new_fb_ptr->mi_cols = cm->mi_cols;
}
}
#endif
static void scale_references(AV1_COMP *cpi) {
AV1_COMMON *cm = &cpi->common;
MV_REFERENCE_FRAME ref_frame;
......@@ -3972,6 +3991,9 @@ static void scale_references(AV1_COMP *cpi) {
(int)cm->bit_depth);
cpi->scaled_ref_idx[ref_frame - 1] = new_fb;
alloc_frame_mvs(cm, new_fb);
#if CONFIG_SEGMENT_PRED_LAST
alloc_frame_segmap(cm, new_fb);
#endif
}
#else
if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) {
......@@ -3995,6 +4017,9 @@ static void scale_references(AV1_COMP *cpi) {
av1_resize_and_extend_frame(ref, &new_fb_ptr->buf);
cpi->scaled_ref_idx[ref_frame - 1] = new_fb;
alloc_frame_mvs(cm, new_fb);
#if CONFIG_SEGMENT_PRED_LAST
alloc_frame_segmap(cm, new_fb);
#endif
}
#endif // CONFIG_HIGHBITDEPTH
} else {
......@@ -4322,6 +4347,9 @@ static void set_frame_size(AV1_COMP *cpi, int width, int height) {
#endif
alloc_frame_mvs(cm, cm->new_fb_idx);
#if CONFIG_SEGMENT_PRED_LAST
alloc_frame_segmap(cm, cm->new_fb_idx);
#endif
// Reset the frame pointers to the current frame size.
if (aom_realloc_frame_buffer(get_frame_new_buffer(cm), cm->width, cm->height,
......@@ -5675,7 +5703,18 @@ static void encode_frame_to_data_rate(AV1_COMP *cpi, size_t *size,
dump_filtered_recon_frames(cpi);
#endif // DUMP_RECON_FRAMES
#if CONFIG_SEGMENT_PRED_LAST
if (cm->seg.enabled) {
if (cm->seg.update_map) {
update_reference_segmentation_map(cpi);
} else {
memcpy(cm->current_frame_seg_map, cm->last_frame_seg_map,
cm->mi_cols * cm->mi_rows * sizeof(uint8_t));
}
}
#else
if (cm->seg.update_map) update_reference_segmentation_map(cpi);
#endif
if (frame_is_intra_only(cm) == 0) {
release_scaled_references(cpi);
......
......@@ -183,6 +183,7 @@ set(CONFIG_RECT_TX_EXT 0 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_REFERENCE_BUFFER 1 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_REF_ADAPT 0 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_SEGMENT_GLOBALMV 1 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_SEGMENT_PRED_LAST 0 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_SHORT_FILTER 1 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_SIMPLE_BWD_ADAPT 1 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_SIMPLIFY_TX_MODE 0 CACHE NUMBER "AV1 experiment flag.")
......
......@@ -336,6 +336,7 @@ EXPERIMENT_LIST="
eighth_pel_mv_only
mono_video
q_segmentation
segment_pred_last
"
CONFIG_LIST="
dependency_tracking
......
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