From 62da0bf162f369cd99f2ffe37e4cb21810422e37 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Tue, 8 Sep 2015 14:14:28 -0400 Subject: [PATCH] Make reset_frame_context an enum. In vp9, [0] and [1] had identical meaning, so merge them into a single value. Make it impossible to code RESET_FRAME_CONTEXT_NONE for intra_only frames, since that is a non-sensical combination. See issue 1030. Change-Id: If450c74162d35ca63a9d279beaa53ff9cdd6612b --- vp10/common/entropymode.c | 6 +++--- vp10/common/onyxc_int.h | 12 ++++++++---- vp10/decoder/decodeframe.c | 29 +++++++++++++++++++++++++++-- vp10/encoder/bitstream.c | 21 +++++++++++++++++++-- vp10/encoder/encoder.c | 8 ++++---- 5 files changed, 61 insertions(+), 15 deletions(-) diff --git a/vp10/common/entropymode.c b/vp10/common/entropymode.c index 0622a7d2c..009f1c913 100644 --- a/vp10/common/entropymode.c +++ b/vp10/common/entropymode.c @@ -448,12 +448,12 @@ void vp10_setup_past_independence(VP10_COMMON *cm) { vp10_init_mv_probs(cm); cm->fc->initialized = 1; - if (cm->frame_type == KEY_FRAME || - cm->error_resilient_mode || cm->reset_frame_context == 3) { + if (cm->frame_type == KEY_FRAME || cm->error_resilient_mode || + cm->reset_frame_context == RESET_FRAME_CONTEXT_ALL) { // Reset all frame contexts. for (i = 0; i < FRAME_CONTEXTS; ++i) cm->frame_contexts[i] = *cm->fc; - } else if (cm->reset_frame_context == 2) { + } else if (cm->reset_frame_context == RESET_FRAME_CONTEXT_CURRENT) { // Reset only the frame context specified in the frame header. cm->frame_contexts[cm->frame_context_idx] = *cm->fc; } diff --git a/vp10/common/onyxc_int.h b/vp10/common/onyxc_int.h index 4118d89f2..a30cc61b5 100644 --- a/vp10/common/onyxc_int.h +++ b/vp10/common/onyxc_int.h @@ -57,6 +57,12 @@ typedef enum { REFERENCE_MODES = 3, } REFERENCE_MODE; +typedef enum { + RESET_FRAME_CONTEXT_NONE = 0, + RESET_FRAME_CONTEXT_CURRENT = 1, + RESET_FRAME_CONTEXT_ALL = 2, +} RESET_FRAME_CONTEXT_MODE; + typedef struct { int_mv mv[2]; MV_REFERENCE_FRAME ref_frame[2]; @@ -161,10 +167,8 @@ typedef struct VP10Common { int allow_high_precision_mv; - // Flag signaling that the frame context should be reset to default values. - // 0 or 1 implies don't reset, 2 reset just the context specified in the - // frame header, 3 reset all contexts. - int reset_frame_context; + // Flag signaling which frame contexts should be reset to default values. + RESET_FRAME_CONTEXT_MODE reset_frame_context; // MBs, mb_rows/cols is in 16-pixel units; mi_rows/cols is in // MODE_INFO (8-pixel) units. diff --git a/vp10/decoder/decodeframe.c b/vp10/decoder/decodeframe.c index e3c97c68c..2c308d083 100644 --- a/vp10/decoder/decodeframe.c +++ b/vp10/decoder/decodeframe.c @@ -1849,8 +1849,33 @@ static size_t read_uncompressed_header(VP10Decoder *pbi, } else { cm->intra_only = cm->show_frame ? 0 : vpx_rb_read_bit(rb); - cm->reset_frame_context = cm->error_resilient_mode ? - 0 : vpx_rb_read_literal(rb, 2); + if (cm->error_resilient_mode) { + cm->reset_frame_context = RESET_FRAME_CONTEXT_ALL; + } else { +#if CONFIG_MISC_FIXES + if (cm->intra_only) { + cm->reset_frame_context = + vpx_rb_read_bit(rb) ? RESET_FRAME_CONTEXT_ALL + : RESET_FRAME_CONTEXT_CURRENT; + } else { + cm->reset_frame_context = + vpx_rb_read_bit(rb) ? RESET_FRAME_CONTEXT_CURRENT + : RESET_FRAME_CONTEXT_NONE; + if (cm->reset_frame_context == RESET_FRAME_CONTEXT_CURRENT) + cm->reset_frame_context = + vpx_rb_read_bit(rb) ? RESET_FRAME_CONTEXT_ALL + : RESET_FRAME_CONTEXT_CURRENT; + } +#else + static const RESET_FRAME_CONTEXT_MODE reset_frame_context_conv_tbl[4] = { + RESET_FRAME_CONTEXT_NONE, RESET_FRAME_CONTEXT_NONE, + RESET_FRAME_CONTEXT_CURRENT, RESET_FRAME_CONTEXT_ALL + }; + + cm->reset_frame_context = + reset_frame_context_conv_tbl[vpx_rb_read_literal(rb, 2)]; +#endif + } if (cm->intra_only) { if (!vp10_read_sync_code(rb)) diff --git a/vp10/encoder/bitstream.c b/vp10/encoder/bitstream.c index 2b60ac5d7..c41f0ef79 100644 --- a/vp10/encoder/bitstream.c +++ b/vp10/encoder/bitstream.c @@ -1092,8 +1092,25 @@ static void write_uncompressed_header(VP10_COMP *cpi, if (!cm->show_frame) vpx_wb_write_bit(wb, cm->intra_only); - if (!cm->error_resilient_mode) - vpx_wb_write_literal(wb, cm->reset_frame_context, 2); + if (!cm->error_resilient_mode) { +#if CONFIG_MISC_FIXES + if (cm->intra_only) { + vpx_wb_write_bit(wb, + cm->reset_frame_context == RESET_FRAME_CONTEXT_ALL); + } else { + vpx_wb_write_bit(wb, + cm->reset_frame_context != RESET_FRAME_CONTEXT_NONE); + if (cm->reset_frame_context != RESET_FRAME_CONTEXT_NONE) + vpx_wb_write_bit(wb, + cm->reset_frame_context == RESET_FRAME_CONTEXT_ALL); + } +#else + static const int reset_frame_context_conv_tbl[3] = { 0, 2, 3 }; + + vpx_wb_write_literal(wb, + reset_frame_context_conv_tbl[cm->reset_frame_context], 2); +#endif + } if (cm->intra_only) { write_sync_code(wb); diff --git a/vp10/encoder/encoder.c b/vp10/encoder/encoder.c index 4713549ef..85659a244 100644 --- a/vp10/encoder/encoder.c +++ b/vp10/encoder/encoder.c @@ -1422,7 +1422,7 @@ void vp10_change_config(struct VP10_COMP *cpi, const VP10EncoderConfig *oxcf) { cpi->refresh_golden_frame = 0; cpi->refresh_last_frame = 1; cm->refresh_frame_context = 1; - cm->reset_frame_context = 0; + cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; vp10_reset_segment_features(&cm->seg); vp10_set_high_precision_mv(cpi, 0); @@ -3554,11 +3554,11 @@ static void encode_frame_to_data_rate(VP10_COMP *cpi, // By default, encoder assumes decoder can use prev_mi. if (cm->error_resilient_mode) { cm->frame_parallel_decoding_mode = 1; - cm->reset_frame_context = 0; + cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; cm->refresh_frame_context = 0; } else if (cm->intra_only) { // Only reset the current context. - cm->reset_frame_context = 2; + cm->reset_frame_context = RESET_FRAME_CONTEXT_CURRENT; } } @@ -3955,7 +3955,7 @@ int vp10_get_compressed_data(VP10_COMP *cpi, unsigned int *frame_flags, cpi->multi_arf_allowed = 0; // Normal defaults - cm->reset_frame_context = 0; + cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; cm->refresh_frame_context = 1; cpi->refresh_last_frame = 1;