From 545f096ef23d4f70062379d9c4184b15189c2143 Mon Sep 17 00:00:00 2001 From: Jerome Jiang Date: Mon, 26 Nov 2018 17:10:37 -0800 Subject: [PATCH] VP9 SVC: fix crash on scaling partition. When scaling up partition from lower resolution layer L, mi_row and mi_col from L must be smaller than mi_rows and mi_cols from L. Before this change, the condition was based on mi_rows from top layer divided by 2, which is not necessarily equal to the mi_rows from lower resolution layer. Added variable in SVC structure to keep track of mi_rows and mi_cols from each spatial layer. Re-enable partition scaling for 1080p. BUG=webm:1578 Change-Id: Icc1c701b095cfe0a92bfecca1ed39dbe21da12b6 --- vp9/encoder/vp9_encodeframe.c | 5 +++-- vp9/encoder/vp9_speed_features.c | 3 +-- vp9/encoder/vp9_svc_layercontext.c | 2 ++ vp9/encoder/vp9_svc_layercontext.h | 2 ++ 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index d5d1d279e..98343f0d2 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -930,7 +930,9 @@ static int scale_partitioning_svc(VP9_COMP *cpi, MACROBLOCK *x, MACROBLOCKD *xd, PARTITION_TYPE partition_high; if (mi_row_high >= cm->mi_rows || mi_col_high >= cm->mi_cols) return 0; - if (mi_row >= (cm->mi_rows >> 1) || mi_col >= (cm->mi_cols >> 1)) return 0; + if (mi_row >= svc->mi_rows[svc->spatial_layer_id - 1] || + mi_col >= svc->mi_cols[svc->spatial_layer_id - 1]) + return 0; // Find corresponding (mi_col/mi_row) block down-scaled by 2x2. start_pos = mi_row * (svc->mi_stride[svc->spatial_layer_id - 1]) + mi_col; @@ -5658,7 +5660,6 @@ static void encode_frame_internal(VP9_COMP *cpi) { xd->mi = cm->mi_grid_visible; xd->mi[0] = cm->mi; - vp9_zero(*td->counts); vp9_zero(cpi->td.rd_counts); diff --git a/vp9/encoder/vp9_speed_features.c b/vp9/encoder/vp9_speed_features.c index fbd24d0d2..9b6c69a73 100644 --- a/vp9/encoder/vp9_speed_features.c +++ b/vp9/encoder/vp9_speed_features.c @@ -713,8 +713,7 @@ static void set_rt_speed_feature_framesize_independent( // TODO(jianj): Investigate webm:1578 if (cpi->use_svc && cpi->svc.use_partition_reuse && cpi->svc.number_spatial_layers == 3 && cpi->svc.temporal_layer_id > 0 && - cpi->oxcf.width * cpi->oxcf.height > 640 * 480 && - cpi->oxcf.width * cpi->oxcf.height < 1920 * 1080) + cpi->oxcf.width * cpi->oxcf.height > 640 * 480) sf->svc_use_lowres_part = 1; // For SVC when golden is used as second temporal reference: to avoid // encode time increase only use this feature on base temporal layer. diff --git a/vp9/encoder/vp9_svc_layercontext.c b/vp9/encoder/vp9_svc_layercontext.c index 033684e2e..c4c5b5a9f 100644 --- a/vp9/encoder/vp9_svc_layercontext.c +++ b/vp9/encoder/vp9_svc_layercontext.c @@ -737,6 +737,8 @@ int vp9_one_pass_cbr_svc_start_layer(VP9_COMP *const cpi) { } svc->force_zero_mode_spatial_ref = 1; svc->mi_stride[svc->spatial_layer_id] = cpi->common.mi_stride; + svc->mi_rows[svc->spatial_layer_id] = cpi->common.mi_rows; + svc->mi_cols[svc->spatial_layer_id] = cpi->common.mi_cols; if (svc->temporal_layering_mode == VP9E_TEMPORAL_LAYERING_MODE_0212) { set_flags_and_fb_idx_for_temporal_mode3(cpi); diff --git a/vp9/encoder/vp9_svc_layercontext.h b/vp9/encoder/vp9_svc_layercontext.h index 17d7a8a50..31d95f9d6 100644 --- a/vp9/encoder/vp9_svc_layercontext.h +++ b/vp9/encoder/vp9_svc_layercontext.h @@ -125,6 +125,8 @@ typedef struct SVC { BLOCK_SIZE *prev_partition_svc; int mi_stride[VPX_MAX_LAYERS]; + int mi_rows[VPX_MAX_LAYERS]; + int mi_cols[VPX_MAX_LAYERS]; int first_layer_denoise; -- 2.40.0