Commit 2638cb55 authored by Soo-Chul Han's avatar Soo-Chul Han

fix issues with segment_pred_last

* Proper re-allocation of seg_map buffer when resolution changes
* Remove undesired resetting of seg_map buffer

* This resolves issues raised in

   https://bugs.chromium.org/p/aomedia/issues/detail?id=1064
   https://bugs.chromium.org/p/aomedia/issues/detail?id=1091

* Disable error_resilient_flag in resize_test as this covers more cases

* Will be enabled by default in separate patch

BUG=aomedia:1064
BUG=aomedia:1091

Change-Id: Ic3f0e47922784c66d240b52d30ba082bdb46dc3b
parent 9bd42785
......@@ -3407,8 +3407,12 @@ void av1_setup_past_independence(AV1_COMMON *cm) {
av1_clearall_segfeatures(&cm->seg);
if (cm->last_frame_seg_map && !cm->frame_parallel_decode)
#if !CONFIG_SEGMENT_PRED_LAST
memset(cm->last_frame_seg_map, 0, (cm->mi_rows * cm->mi_cols));
#else
memset(cm->last_frame_seg_map, 0,
(cm->prev_frame->mi_cols * cm->prev_frame->mi_rows));
#endif
if (cm->current_frame_seg_map)
memset(cm->current_frame_seg_map, 0, (cm->mi_rows * cm->mi_cols));
......
......@@ -685,6 +685,12 @@ 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_SEGMENT_PRED_LAST
aom_free(buf->seg_map);
CHECK_MEM_ERROR(cm, buf->seg_map,
(uint8_t *)aom_calloc(cm->mi_rows * cm->mi_cols,
sizeof(*buf->seg_map)));
#endif
}
#if CONFIG_MFMV
......
......@@ -751,7 +751,10 @@ static void setup_segmentation(AV1_COMMON *const cm,
seg->enabled = aom_rb_read_bit(rb);
if (!seg->enabled) return;
#if CONFIG_SEGMENT_PRED_LAST
if (cm->seg.enabled && !cm->frame_parallel_decode && cm->prev_frame)
cm->last_frame_seg_map = cm->prev_frame->seg_map;
#endif
// Segmentation map update
if (frame_is_intra_only(cm) || cm->error_resilient_mode) {
seg->update_map = 1;
......@@ -1157,16 +1160,7 @@ static void setup_superres(AV1_COMMON *const cm, struct aom_read_bit_buffer *rb,
}
}
#endif // CONFIG_HORZONLY_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)
......@@ -1195,12 +1189,6 @@ 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;
}
......@@ -2808,6 +2796,10 @@ static size_t read_uncompressed_header(AV1Decoder *pbi,
: NULL;
cm->use_prev_frame_mvs =
cm->use_ref_frame_mvs && frame_can_use_prev_frame_mvs(cm);
#if CONFIG_SEGMENT_PRED_LAST
if (cm->seg.enabled && !cm->frame_parallel_decode)
cm->last_frame_seg_map = cm->prev_frame->seg_map;
#endif
#endif
for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) {
RefBuffer *const ref_buf = &cm->frame_refs[i];
......@@ -3281,11 +3273,6 @@ size_t av1_decode_frame_headers_and_setup(AV1Decoder *pbi, const uint8_t *data,
#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
......
......@@ -3870,8 +3870,6 @@ static void encode_frame_internal(AV1_COMP *cpi) {
#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
......
......@@ -4550,21 +4550,6 @@ 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;
......@@ -4607,9 +4592,6 @@ 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 {
const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
......@@ -4924,9 +4906,6 @@ 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,
......
......@@ -483,8 +483,8 @@ class ResizeRealtimeTest
cfg_.kf_min_dist = cfg_.kf_max_dist = 3000;
// Enable dropped frames.
cfg_.rc_dropframe_thresh = 1;
// Enable error_resilience mode.
cfg_.g_error_resilient = 1;
// Disable error_resilience mode.
cfg_.g_error_resilient = 0;
// Run at low bitrate.
cfg_.rc_target_bitrate = 200;
}
......
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