From: Brandon Young Date: Wed, 23 Mar 2016 18:47:07 +0000 (-0700) Subject: Quantization Profiles Strictly on Entropy Context X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=43195061b74c612787d9586d4e4a196d8fa6ceac;p=libvpx Quantization Profiles Strictly on Entropy Context Allow for 3 quant profiles from entropy context Refactored dq_offset bands to allow for re-optimization based on number of quantization profiles Change-Id: Ib8d7e8854ad4e0bf8745038df28833d91efcfbea --- diff --git a/vp9/common/vp9_blockd.h b/vp9/common/vp9_blockd.h index c72abd066..4f5337979 100644 --- a/vp9/common/vp9_blockd.h +++ b/vp9/common/vp9_blockd.h @@ -77,14 +77,17 @@ extern "C" { #endif // CONFIG_MULTI_REF #if CONFIG_NEW_QUANT -#define QUANT_PROFILES 2 +#define QUANT_PROFILES 3 +#define Q_CTX_BASED_PROFILES 1 #if QUANT_PROFILES > 1 -static INLINE int switchable_dq_profile_used(BLOCK_SIZE bsize) { - return bsize >= BLOCK_16X16; -} + #define Q_THRESHOLD_MIN 0 #define Q_THRESHOLD_MAX 1000 + +static INLINE int switchable_dq_profile_used(int q_ctx, BLOCK_SIZE bsize) { + return ((bsize >= BLOCK_32X32) * q_ctx); +} #endif // QUANT_PROFILES > 1 #endif // CONFIG_NEW_QUANT @@ -313,6 +316,7 @@ typedef struct { #endif // CONFIG_PALETTE #if CONFIG_NEW_QUANT int dq_off_index; + int send_dq_bit; #endif // CONFIG_NEW_QUANT } MB_MODE_INFO; diff --git a/vp9/common/vp9_entropy.h b/vp9/common/vp9_entropy.h index 25b46a564..4508f50ef 100644 --- a/vp9/common/vp9_entropy.h +++ b/vp9/common/vp9_entropy.h @@ -260,7 +260,6 @@ static INLINE int get_entropy_context(TX_SIZE tx_size, const ENTROPY_CONTEXT *a, assert(0 && "Invalid transform size."); break; } - return combine_entropy_contexts(above_ec, left_ec); } diff --git a/vp9/common/vp9_entropymode.c b/vp9/common/vp9_entropymode.c index e29fa12e7..176734fae 100644 --- a/vp9/common/vp9_entropymode.c +++ b/vp9/common/vp9_entropymode.c @@ -944,7 +944,7 @@ const vp9_tree_index vp9_copy_mode_tree[TREE_SIZE(COPY_MODE_COUNT - 1)] = { }; #endif // CONFIG_COPY_MODE -#if CONFIG_NEW_QUANT +#if CONFIG_NEW_QUANT && !Q_CTX_BASED_PROFILES #if QUANT_PROFILES == 2 const vp9_tree_index vp9_dq_profile_tree[TREE_SIZE(QUANT_PROFILES)] = { -0, -1 @@ -962,7 +962,7 @@ static const vp9_prob default_dq_profile_prob[QUANT_PROFILES - 1] = { 240, 128 }; #endif // QUANT_PROFILES != 2 and QUANT_PROFILES != 3 -#endif // CONFIG_NEW_QUANT +#endif // CONFIG_NEW_QUANT && !Q_CTX_BASED_PROFILES #if CONFIG_TX64X64 void tx_counts_to_branch_counts_64x64(const unsigned int *tx_count_64x64p, @@ -1116,9 +1116,9 @@ void vp9_init_mode_probs(FRAME_CONTEXT *fc) { #if CONFIG_WEDGE_PARTITION vp9_copy(fc->wedge_interinter_prob, default_wedge_interinter_prob); #endif // CONFIG_WEDGE_PARTITION -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES vp9_copy(fc->dq_profile_prob, default_dq_profile_prob); -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES } const vp9_tree_index vp9_switchable_interp_tree @@ -1347,10 +1347,10 @@ void vp9_adapt_mode_probs(VP9_COMMON *cm) { counts->uv_palette_enabled[i]); #endif // CONFIG_PALETTE -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES adapt_probs(vp9_dq_profile_tree, pre_fc->dq_profile_prob, counts->dq_profile, fc->dq_profile_prob); -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES } static void set_default_lf_deltas(struct loopfilter *lf) { diff --git a/vp9/common/vp9_entropymode.h b/vp9/common/vp9_entropymode.h index 0cdae03c9..374636156 100644 --- a/vp9/common/vp9_entropymode.h +++ b/vp9/common/vp9_entropymode.h @@ -133,9 +133,9 @@ typedef struct frame_contexts { #if CONFIG_GLOBAL_MOTION vp9_prob global_motion_types_prob[GLOBAL_MOTION_TYPES - 1]; #endif // CONFIG_GLOBAL_MOTION -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES vp9_prob dq_profile_prob[QUANT_PROFILES - 1]; -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES } FRAME_CONTEXT; typedef struct { @@ -214,9 +214,9 @@ typedef struct { #if CONFIG_GLOBAL_MOTION unsigned int global_motion_types[GLOBAL_MOTION_TYPES]; #endif // CONFIG_GLOBAL_MOTION -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES unsigned int dq_profile[QUANT_PROFILES]; -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES } FRAME_COUNTS; extern const vp9_prob vp9_kf_uv_mode_prob[INTRA_MODES][INTRA_MODES - 1]; @@ -262,9 +262,9 @@ extern const vp9_tree_index vp9_inter_compound_mode_tree [TREE_SIZE(INTER_COMPOUND_MODES)]; #endif // CONFIG_NEW_INTER -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES extern const vp9_tree_index vp9_dq_profile_tree[TREE_SIZE(QUANT_PROFILES)]; -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES void vp9_setup_past_independence(struct VP9Common *cm); #if CONFIG_ROW_TILE diff --git a/vp9/common/vp9_quant_common.c b/vp9/common/vp9_quant_common.c index 33f123540..6b943f0c3 100644 --- a/vp9/common/vp9_quant_common.c +++ b/vp9/common/vp9_quant_common.c @@ -43,36 +43,36 @@ static const uint8_t vp9_nuq_knots_lossless[COEF_BANDS][NUQ_KNOTS] = { static const uint8_t vp9_nuq_knots[QUANT_PROFILES][COEF_BANDS][NUQ_KNOTS] = { { - {86, 122, 128}, // dc, band 0 - {86, 122, 128}, // band 1 - {86, 122, 128}, // band 2 - {88, 122, 128}, // band 3 - {88, 122, 128}, // band 4 - {88, 122, 128}, // band 5 + {86, 122, 134}, // dc, band 0 + {78, 122, 134}, // band 1 + {78, 122, 134}, // band 2 + {84, 122, 133}, // band 3 + {88, 122, 134}, // band 4 + {88, 122, 134}, // band 5 #if CONFIG_TX_SKIP {86, 122, 128}, // band 6 #endif // CONFIG_TX_SKIP }, #if QUANT_PROFILES > 1 { - {86, 122, 128}, // dc, band 0 - {86, 122, 128}, // band 1 - {86, 122, 128}, // band 2 - {88, 122, 128}, // band 3 - {88, 122, 128}, // band 4 - {88, 122, 128}, // band 5 + {86, 122, 134}, // dc, band 0 + {78, 122, 134}, // band 1 + {78, 122, 134}, // band 2 + {84, 122, 134}, // band 3 + {88, 122, 134}, // band 4 + {88, 122, 134}, // band 5 #if CONFIG_TX_SKIP {86, 122, 128}, // band 6 #endif // CONFIG_TX_SKIP }, #if QUANT_PROFILES > 2 { - {86, 122, 128}, // dc, band 0 - {86, 122, 128}, // band 1 - {86, 122, 128}, // band 2 - {88, 122, 128}, // band 3 - {88, 122, 128}, // band 4 - {88, 122, 128}, // band 5 + {86, 122, 134}, // dc, band 0 + {78, 122, 135}, // band 1 + {78, 122, 134}, // band 2 + {84, 122, 133}, // band 3 + {88, 122, 134}, // band 4 + {88, 122, 134}, // band 5 #if CONFIG_TX_SKIP {86, 122, 128}, // band 6 #endif // CONFIG_TX_SKIP @@ -86,27 +86,47 @@ static const uint8_t vp9_nuq_doff_lossless[COEF_BANDS] = { 0, 0, 0, 0, 0, 0, 0 #endif // CONFIG_TX_SKIP }; + +#if QUANT_PROFILES == 1 +static const uint8_t vp9_nuq_doff[QUANT_PROFILES][COEF_BANDS] = { + { 8, 15, 16, 22, 23, 24, // dq_off_index = 0 +#if CONFIG_TX_SKIP + 8 +#endif // CONFIG_TX_SKIP + } +}; +#elif QUANT_PROFILES == 2 static const uint8_t vp9_nuq_doff[QUANT_PROFILES][COEF_BANDS] = { { 8, 15, 16, 22, 23, 24, // dq_off_index = 0 #if CONFIG_TX_SKIP 8 #endif // CONFIG_TX_SKIP }, -#if QUANT_PROFILES > 1 - { 6, 12, 13, 16, 17, 18, // dq_off_index = 1 + { 13, 20, 21, 27, 28, 29, // dq_off_index = 1 #if CONFIG_TX_SKIP 8 #endif // CONFIG_TX_SKIP }, -#if QUANT_PROFILES > 2 - { 10, 18, 19, 23, 25, 26, // dq_off_index = 2 +}; +#else // QUANT_PROFILES == 3 +static const uint8_t vp9_nuq_doff[QUANT_PROFILES][COEF_BANDS] = { + { 6, 14, 15, 22, 23, 27, // dq_off_index = 0 +#if CONFIG_TX_SKIP + 8 +#endif // CONFIG_TX_SKIP + }, + { 6, 15, 17, 22, 23, 23, // dq_off_index = 1 +#if CONFIG_TX_SKIP + 8 +#endif // CONFIG_TX_SKIP + }, + { 6, 14, 16, 22, 23, 27, // dq_off_index = 2 #if CONFIG_TX_SKIP 8 #endif // CONFIG_TX_SKIP } -#endif // QUANT_PROFILES > 2 -#endif // QUANT_PROFILES > 1 }; +#endif // Allow different quantization profiles in different q ranges, // to enable entropy-constraints in scalar quantization. diff --git a/vp9/decoder/vp9_decodeframe.c b/vp9/decoder/vp9_decodeframe.c index 0061615f9..aa15a7c93 100644 --- a/vp9/decoder/vp9_decodeframe.c +++ b/vp9/decoder/vp9_decodeframe.c @@ -136,13 +136,13 @@ static void read_switchable_interp_probs(FRAME_CONTEXT *fc, vp9_reader *r) { vp9_diff_update_prob(r, &fc->switchable_interp_prob[j][i]); } -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES static void read_dq_profile_probs(FRAME_CONTEXT *fc, vp9_reader *r) { int i; for (i = 0; i < QUANT_PROFILES - 1; ++i) vp9_diff_update_prob(r, &fc->dq_profile_prob[i]); } -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES static void read_inter_mode_probs(FRAME_CONTEXT *fc, vp9_reader *r) { int i, j; @@ -918,10 +918,10 @@ static void set_param_topblock(VP9_COMMON *const cm, MACROBLOCKD *const xd, BLOCK_SIZE bsize, int mi_row, int mi_col, #if CONFIG_EXT_TX int txfm, -#endif +#endif // CONFIG_EXT_TX #if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 int dq_off_index, -#endif +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 int skip) { const int bw = num_8x8_blocks_wide_lookup[bsize]; const int bh = num_8x8_blocks_high_lookup[bsize]; @@ -938,10 +938,10 @@ static void set_param_topblock(VP9_COMMON *const cm, MACROBLOCKD *const xd, xd->mi[y * cm->mi_stride + x].mbmi.skip = skip; #if CONFIG_EXT_TX xd->mi[y * cm->mi_stride + x].mbmi.ext_txfrm = txfm; -#endif +#endif // CONFIG_EXT_TX #if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 xd->mi[y * cm->mi_stride + x].mbmi.dq_off_index = dq_off_index; -#endif +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 } } @@ -1858,21 +1858,18 @@ static void decode_partition(VP9_COMMON *const cm, MACROBLOCKD *const xd, } } #endif // CONFIG_EXT_TX - /* - printf("D[%d/%d, %d %d] sb_type %d skip %d}\n", cm->current_video_frame, cm->show_frame, - mi_row, mi_col, bsize, skip); - */ -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES if (cm->base_qindex > Q_THRESHOLD_MIN && cm->base_qindex < Q_THRESHOLD_MAX && - switchable_dq_profile_used(bsize) && !skip && + switchable_dq_profile_used(get_entropy_context_sb(xd, bsize), bsize) && + !skip && !vp9_segfeature_active( &cm->seg, xd->mi[0].mbmi.segment_id, SEG_LVL_SKIP)) { dq_off_index = vp9_read_dq_profile(cm, r); } else { dq_off_index = 0; } -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES } #endif // CONFIG_SUPERTX if (subsize < BLOCK_8X8) { @@ -3554,9 +3551,9 @@ static int read_compressed_header(VP9Decoder *pbi, const uint8_t *data, read_inter_compound_mode_probs(fc, &r); #endif // CONFIG_NEW_INTER -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES read_dq_profile_probs(fc, &r); -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES if (cm->interp_filter == SWITCHABLE) read_switchable_interp_probs(fc, &r); diff --git a/vp9/decoder/vp9_decodemv.c b/vp9/decoder/vp9_decodemv.c index 4dd2a443e..31e07b789 100644 --- a/vp9/decoder/vp9_decodemv.c +++ b/vp9/decoder/vp9_decodemv.c @@ -66,7 +66,7 @@ static PREDICTION_MODE read_inter_compound_mode(VP9_COMMON *cm, vp9_reader *r, } #endif // CONFIG_NEW_INTER -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES int vp9_read_dq_profile(VP9_COMMON *cm, vp9_reader *r) { const int dq_profile = vp9_read_tree(r, vp9_dq_profile_tree, cm->fc.dq_profile_prob); @@ -75,7 +75,7 @@ int vp9_read_dq_profile(VP9_COMMON *cm, vp9_reader *r) { } return dq_profile; } -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES static PREDICTION_MODE read_inter_mode(VP9_COMMON *cm, vp9_reader *r, int ctx) { @@ -518,16 +518,31 @@ static void read_intra_frame_mode_info(VP9_COMMON *const cm, #endif // CONFIG_SR_MODE #endif // CONFIG_PALETTE -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES if (cm->base_qindex > Q_THRESHOLD_MIN && cm->base_qindex < Q_THRESHOLD_MAX && - switchable_dq_profile_used(mbmi->sb_type) && + switchable_dq_profile_used(get_entropy_context_sb(xd, mbmi->sb_type), + mbmi->sb_type) && !mbmi->skip && !vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { mbmi->dq_off_index = vp9_read_dq_profile(cm, r); } else { mbmi->dq_off_index = 0; } -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES + +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && Q_CTX_BASED_PROFILES + if (switchable_dq_profile_used(get_entropy_context_sb(xd, bsize), + bsize) == 2) { + mbmi->dq_off_index = 1; +#if QUANT_PROFILES > 2 + } else if (switchable_dq_profile_used(get_entropy_context_sb(xd, bsize), + bsize) == 1) { + mbmi->dq_off_index = 2; +#endif // QUANT_PROFILES > 2 + } else { + mbmi->dq_off_index = 0; + } +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && Q_CTX_BASED_PROFILES mbmi->ref_frame[0] = INTRA_FRAME; mbmi->ref_frame[1] = NONE; @@ -1537,13 +1552,28 @@ static void read_inter_frame_mode_info(VP9_COMMON *const cm, mbmi->mode = NEARESTMV; mbmi->skip = skip_backup; mbmi->copy_mode = copy_mode_backup; -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES if (!(cm->base_qindex > Q_THRESHOLD_MIN && cm->base_qindex < Q_THRESHOLD_MAX && - switchable_dq_profile_used(mbmi->sb_type) && + switchable_dq_profile_used(get_entropy_context_sb(xd, mbmi->sb_type), + mbmi->sb_type) && !vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP))) mbmi->dq_off_index = 0; -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && Q_CTX_BASED_PROFILES + if (switchable_dq_profile_used(get_entropy_context_sb(xd, mbmi->sb_type), + mbmi->sb_type) == 2) { + mbmi->dq_off_index = 1; +#if QUANT_PROFILES > 2 + } else if (switchable_dq_profile_used(get_entropy_context_sb(xd, + mbmi->sb_type), + mbmi->sb_type) == 1) { + mbmi->dq_off_index = 2; +#endif // QUANT_PROFILES > 2 + } else { + mbmi->dq_off_index = 0; + } +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && Q_CTX_BASED_PROFILES } #endif // CONFIG_COPY_MODE @@ -1728,10 +1758,11 @@ static void read_inter_frame_mode_info(VP9_COMMON *const cm, #endif // CONFIG_SR_MODE #endif // CONFIG_PALETTE -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES if (cm->base_qindex > Q_THRESHOLD_MIN && cm->base_qindex < Q_THRESHOLD_MAX && - switchable_dq_profile_used(mbmi->sb_type) && + switchable_dq_profile_used(get_entropy_context_sb(xd, mbmi->sb_type), + mbmi->sb_type) && #if CONFIG_SUPERTX !supertx_enabled && #endif @@ -1744,7 +1775,22 @@ static void read_inter_frame_mode_info(VP9_COMMON *const cm, } else { mbmi->dq_off_index = 0; } -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES + +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && Q_CTX_BASED_PROFILES + if (switchable_dq_profile_used(get_entropy_context_sb(xd, mbmi->sb_type), + mbmi->sb_type) == 2) { + mbmi->dq_off_index = 1; +#if QUANT_PROFILES > 2 + } else if (switchable_dq_profile_used(get_entropy_context_sb(xd, + mbmi->sb_type), + mbmi->sb_type) == 1) { + mbmi->dq_off_index = 2; + #endif // QUANT_PROFILES > 2 + } else { + mbmi->dq_off_index = 0; + } +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && Q_CTX_BASED_PROFILES #if CONFIG_EXT_TX if (inter_block && diff --git a/vp9/decoder/vp9_decodemv.h b/vp9/decoder/vp9_decodemv.h index 7fe1c6531..8048f8ce2 100644 --- a/vp9/decoder/vp9_decodemv.h +++ b/vp9/decoder/vp9_decodemv.h @@ -30,9 +30,9 @@ void vp9_read_mode_info(VP9_COMMON *cm, MACROBLOCKD *xd, #endif #endif int mi_row, int mi_col, vp9_reader *r); -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES int vp9_read_dq_profile(VP9_COMMON *cm, vp9_reader *r); -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES #ifdef __cplusplus } // extern "C" diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c index 08e2c458d..f7c9c80e1 100644 --- a/vp9/encoder/vp9_bitstream.c +++ b/vp9/encoder/vp9_bitstream.c @@ -69,9 +69,9 @@ static struct vp9_token inter_compound_mode_encodings[INTER_COMPOUND_MODES]; #if CONFIG_GLOBAL_MOTION static struct vp9_token global_motion_types_encodings[GLOBAL_MOTION_TYPES]; #endif // CONFIG_GLOBAL_MOTION -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES static struct vp9_token dq_profile_encodings[QUANT_PROFILES]; -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES #if CONFIG_SUPERTX static int vp9_check_supertx(VP9_COMMON *cm, int mi_row, int mi_col, @@ -118,9 +118,9 @@ void vp9_entropy_mode_init() { vp9_tokens_from_tree(global_motion_types_encodings, vp9_global_motion_types_tree); #endif // CONFIG_GLOBAL_MOTION -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES vp9_tokens_from_tree(dq_profile_encodings, vp9_dq_profile_tree); -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES } static void write_intra_mode(vp9_writer *w, PREDICTION_MODE mode, @@ -246,7 +246,7 @@ static void update_skip_probs(VP9_COMMON *cm, vp9_writer *w) { vp9_cond_prob_diff_update(w, &cm->fc.skip_probs[k], cm->counts.skip[k]); } -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES static void write_dq_profile(const VP9_COMMON *cm, int dq_profile, vp9_writer *w) { vp9_write_token(w, vp9_dq_profile_tree, cm->fc.dq_profile_prob, @@ -258,7 +258,7 @@ static void update_dq_profile_probs(VP9_COMMON *cm, vp9_writer *w) { cm->fc.dq_profile_prob, cm->counts.dq_profile, QUANT_PROFILES, w); } -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES #if CONFIG_SR_MODE #if SR_USE_MULTI_F @@ -756,9 +756,9 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, const MODE_INFO *mi, write_selected_tx_size(cm, xd, mbmi->tx_size, bsize, w); } -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES if (cm->base_qindex > Q_THRESHOLD_MIN && cm->base_qindex < Q_THRESHOLD_MAX && - switchable_dq_profile_used(mbmi->sb_type) && + mbmi->send_dq_bit && #if CONFIG_SUPERTX !supertx_enabled && #endif // CONFIG_SUPERTX @@ -767,11 +767,12 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, const MODE_INFO *mi, #if CONFIG_COPY_MODE if (mbmi->copy_mode == NOREF) #endif // CONFIG_COPY_MODE + write_dq_profile(cm, mbmi->dq_off_index, w); } else { assert(mbmi->dq_off_index == 0); } -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES #if CONFIG_EXT_TX if (is_inter && @@ -1201,16 +1202,16 @@ static void write_mb_modes_kf(const VP9_COMMON *cm, write_selected_tx_size(cm, xd, mbmi->tx_size, bsize, w); } -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES if (cm->base_qindex > Q_THRESHOLD_MIN && cm->base_qindex < Q_THRESHOLD_MAX && - switchable_dq_profile_used(mbmi->sb_type) && + mbmi->send_dq_bit && !mbmi->skip && !vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { write_dq_profile(cm, mbmi->dq_off_index, w); } else { assert(mbmi->dq_off_index == 0); } -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES #if CONFIG_TX_SKIP if (bsize >= BLOCK_8X8) { @@ -1422,16 +1423,16 @@ static void write_modes_sb(VP9_COMP *cpi, &ext_tx_encodings[xd->mi[0].mbmi.ext_txfrm]); #endif // CONFIG_WAVELETS #endif // CONFIG_EXT_TX -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES if (!xd->mi[0].mbmi.skip && cm->base_qindex > Q_THRESHOLD_MIN && cm->base_qindex < Q_THRESHOLD_MAX && - switchable_dq_profile_used(bsize) && + xd->mi[0].mbmi.send_dq_bit && !vp9_segfeature_active( &cm->seg, xd->mi[0].mbmi.segment_id, SEG_LVL_SKIP)) { write_dq_profile(cm, xd->mi[0].mbmi.dq_off_index, w); } -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES } } #endif // CONFIG_SUPERTX @@ -2815,9 +2816,9 @@ static size_t write_compressed_header(VP9_COMP *cpi, uint8_t *data) { update_inter_compound_mode_probs(cm, &header_bc); #endif // CONFIG_NEW_INTER -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES update_dq_profile_probs(cm, &header_bc); -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES if (cm->interp_filter == SWITCHABLE) update_switchable_interp_probs(cm, &header_bc); diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index 748c51ef5..83d54f81f 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -1928,16 +1928,16 @@ static void encode_sb(VP9_COMP *cpi, const TileInfo *const tile, cm->counts.supertx [partition_supertx_context_lookup[partition]][supertx_size][1]++; cm->counts.supertx_size[supertx_size]++; -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES if (cm->base_qindex > Q_THRESHOLD_MIN && cm->base_qindex < Q_THRESHOLD_MAX && - switchable_dq_profile_used(bsize) && !xd->mi[0].mbmi.skip && + xd->mi[0].mbmi.send_dq_bit && !vp9_segfeature_active(&cm->seg, xd->mi[0].mbmi.segment_id, SEG_LVL_SKIP)) { ++cm->counts.dq_profile[xd->mi[0].mbmi.dq_off_index]; } -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES #if CONFIG_EXT_TX #if CONFIG_WAVELETS if (!xd->mi[0].mbmi.skip) @@ -2957,7 +2957,7 @@ static void rd_test_partition3(VP9_COMP *cpi, const TileInfo *const tile, #endif #if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 dq_index, -#endif +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 supertx_size, pc_tree); } } @@ -3362,7 +3362,7 @@ static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, #endif #if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 dq_index, -#endif +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 supertx_size, pc_tree); } } @@ -3631,7 +3631,7 @@ static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, #endif #if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 &dq_index, -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES pc_tree); tmp_rate += vp9_cost_bit( @@ -4921,12 +4921,12 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled, vp9_encode_sb(x, MAX(bsize, BLOCK_8X8)); vp9_tokenize_sb(cpi, t, !output_enabled, MAX(bsize, BLOCK_8X8)); } -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES // This is not strictly required, but is a good practice. // If you remove this, the assert in vp9_bitstream.c needs to be removed also. if (mbmi->skip) mbmi->dq_off_index = 0; -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES #if CONFIG_INTRABC if (frame_is_intra_only(cm) && output_enabled && bsize >= BLOCK_8X8) { @@ -4993,10 +4993,10 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled, ++cm->counts.ext_tx[mbmi->tx_size][mbmi->ext_txfrm]; } #endif // CONFIG_EXT_TX -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES if (cm->base_qindex > Q_THRESHOLD_MIN && cm->base_qindex < Q_THRESHOLD_MAX && - switchable_dq_profile_used(mbmi->sb_type) && + mbmi->send_dq_bit && #if CONFIG_COPY_MODE (frame_is_intra_only(cm) || mbmi->copy_mode == NOREF) && #endif // CONFIG_COPY_MODE @@ -5004,7 +5004,7 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled, !vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { ++cm->counts.dq_profile[mbmi->dq_off_index]; } -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES #if CONFIG_TX_SKIP if (bsize >= BLOCK_8X8) { int q_idx = vp9_get_qindex(&cm->seg, mbmi->segment_id, cm->base_qindex); @@ -6080,6 +6080,6 @@ static void rd_supertx_sb(VP9_COMP *cpi, const TileInfo *const tile, #endif // CONFIG_EXT_TX #if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 *dq_index = 0; -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && } #endif // CONFIG_SUPERTX diff --git a/vp9/encoder/vp9_encodemb.c b/vp9/encoder/vp9_encodemb.c index a1230d70e..bcb8877fe 100644 --- a/vp9/encoder/vp9_encodemb.c +++ b/vp9/encoder/vp9_encodemb.c @@ -1105,7 +1105,8 @@ void vp9_xform_quant_fp_nuq(MACROBLOCK *x, int plane, int block, #endif vp9_highbd_quantize_fp_nuq(coeff, 16, x->skip_block, p->quant_fp, pd->dequant, - (const cumbins_type_nuq *)p->cumbins_nuq, + (const cumbins_type_nuq *) + p->cumbins_nuq[dq], (const dequant_val_type_nuq *) pd->dequant_val_nuq[dq], qcoeff, dqcoeff, eob, diff --git a/vp9/encoder/vp9_encoder.h b/vp9/encoder/vp9_encoder.h index 29be840f9..3df4702c8 100644 --- a/vp9/encoder/vp9_encoder.h +++ b/vp9/encoder/vp9_encoder.h @@ -434,9 +434,9 @@ typedef struct VP9_COMP { [PALETTE_COLORS]; #endif // CONFIG_PALETTE -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES int dq_profile_costs[QUANT_PROFILES]; -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES PICK_MODE_CONTEXT *leaf_tree; PC_TREE *pc_tree; diff --git a/vp9/encoder/vp9_rd.c b/vp9/encoder/vp9_rd.c index cfab1a4b9..ab9ee7ce0 100644 --- a/vp9/encoder/vp9_rd.c +++ b/vp9/encoder/vp9_rd.c @@ -104,10 +104,10 @@ static void fill_mode_costs(VP9_COMP *cpi) { vp9_cost_tokens(cpi->palette_uv_color_costs[i][j], fc->palette_uv_color_prob[i][j], vp9_palette_color_tree); #endif // CONFIG_PALETTE -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES vp9_cost_tokens(cpi->dq_profile_costs, fc->dq_profile_prob, vp9_dq_profile_tree); -#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES } static void fill_token_costs(vp9_coeff_cost *c, diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index 5d9ff7901..7a2f64dc3 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -2388,13 +2388,17 @@ static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x, } #if CONFIG_NEW_QUANT mic->mbmi.dq_off_index = 0; -#if QUANT_PROFILES > 1 + mic->mbmi.send_dq_bit = 0; +#if QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES if (cpi->common.base_qindex > Q_THRESHOLD_MIN && cpi->common.base_qindex < Q_THRESHOLD_MAX && - !xd->lossless && switchable_dq_profile_used(bsize)) { + !xd->lossless && + switchable_dq_profile_used(get_entropy_context_sb(xd, bsize), + bsize)) { int64_t local_tx_cache[TX_MODES]; int i; int best_dq = -1; + mic->mbmi.send_dq_bit = 1; for (i = 0; i < QUANT_PROFILES; i++) { mic->mbmi.dq_off_index = i; super_block_yrd(cpi, x, &this_rate_tokenonly, &this_distortion, @@ -2412,7 +2416,22 @@ static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x, *rate_tokenonly = this_rate_tokenonly; *distortion = this_distortion; } -#endif // QUANT_PROFILES > 1 +#endif // QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES + +#if QUANT_PROFILES > 1 && Q_CTX_BASED_PROFILES + if (switchable_dq_profile_used(get_entropy_context_sb(xd, bsize), + bsize) == 2) { + mic->mbmi.dq_off_index = 1; +#if QUANT_PROFILES > 2 + } else if (switchable_dq_profile_used(get_entropy_context_sb(xd, bsize), + bsize) == 1) { + mic->mbmi.dq_off_index = 2; +#endif // QUANT_PROFILES > 2 + } else { + mic->mbmi.dq_off_index = 0; + } +#endif // QUANT_PROFILES > 1 && Q_CTX_BASED_PROFILES + #endif // CONFIG_NEW_QUANT #if CONFIG_TX_SKIP @@ -6094,17 +6113,20 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, #if CONFIG_NEW_QUANT mbmi->dq_off_index = 0; -#if QUANT_PROFILES > 1 + mbmi->send_dq_bit = 0; +#if QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES // Choose the best dq_index if (cm->base_qindex > Q_THRESHOLD_MIN && cm->base_qindex < Q_THRESHOLD_MAX && - !xd->lossless && switchable_dq_profile_used(bsize)) { + !xd->lossless && + switchable_dq_profile_used(get_entropy_context_sb(xd, bsize), bsize)) { int64_t rdcost_dq; int rate_y_dq; int64_t distortion_y_dq; int dummy; int64_t best_rdcost_dq = INT64_MAX; int best_dq = -1; + mbmi->send_dq_bit = 1; for (i = 0; i < QUANT_PROFILES; i++) { mbmi->dq_off_index = i; super_block_yrd(cpi, x, &rate_y_dq, &distortion_y_dq, &dummy, psse, @@ -6122,7 +6144,22 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, } mbmi->dq_off_index = best_dq; } -#endif // QUANT_PROFILES > 1 +#endif // QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES + +#if QUANT_PROFILES > 1 && Q_CTX_BASED_PROFILES + if (switchable_dq_profile_used(get_entropy_context_sb(xd, bsize), + bsize) == 2) { + mbmi->dq_off_index = 1; +#if QUANT_PROFILES > 2 + } else if (switchable_dq_profile_used(get_entropy_context_sb(xd, bsize), + bsize) == 1) { + mbmi->dq_off_index = 2; +#endif // QUANT_PROFILES > 2 + } else { + mbmi->dq_off_index = 0; + } +#endif // QUANT_PROFILES > 1 && Q_CTX_BASED_PROFILES + #endif // CONFIG_NEW_QUANT // Y cost and distortion @@ -7450,16 +7487,20 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, #if CONFIG_NEW_QUANT mbmi->dq_off_index = 0; -#if QUANT_PROFILES > 1 + mbmi->send_dq_bit = 0; +#if QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES if (cm->base_qindex > Q_THRESHOLD_MIN && cm->base_qindex < Q_THRESHOLD_MAX && - !xd->lossless && switchable_dq_profile_used(bsize)) { + !xd->lossless && + switchable_dq_profile_used(get_entropy_context_sb(xd, bsize), + bsize)) { int64_t rdcost_dq; int rate_y_dq; int64_t distortion_y_dq; int dummy; int64_t best_rdcost_dq = INT64_MAX; int best_dq = -1; + mbmi->send_dq_bit = 1; for (i = 0; i < QUANT_PROFILES; i++) { mbmi->dq_off_index = i; super_block_yrd(cpi, x, &rate_y_dq, &distortion_y_dq, &dummy, @@ -7476,7 +7517,22 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, } mbmi->dq_off_index = best_dq; } -#endif // QUANT_PROFILES > 1 +#endif // QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES + +#if QUANT_PROFILES > 1 && Q_CTX_BASED_PROFILES + if (switchable_dq_profile_used(get_entropy_context_sb(xd, bsize), + bsize) == 2) { + mbmi->dq_off_index = 1; +#if QUANT_PROFILES > 2 + } else if (switchable_dq_profile_used(get_entropy_context_sb(xd, bsize), + bsize) == 1) { + mbmi->dq_off_index = 2; +#endif // QUANT_PROFILES > 2 + } else { + mbmi->dq_off_index = 0; + } +#endif // QUANT_PROFILES > 1 && Q_CTX_BASED_PROFILES + #endif // CONFIG_NEW_QUANT } else { @@ -7934,13 +7990,17 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, mbmi->tx_skip[0] = 0; mbmi->tx_skip[1] = 0; #endif // CONFIG_TX_SKIP -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES if (!(cm->base_qindex > Q_THRESHOLD_MIN && cm->base_qindex < Q_THRESHOLD_MAX && - switchable_dq_profile_used(mbmi->sb_type) && + switchable_dq_profile_used(get_entropy_context_sb(xd, mbmi->sb_type), + mbmi->sb_type) && !vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP))) mbmi->dq_off_index = 0; -#endif +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && Q_CTX_BASED_PROFILES + mbmi->dq_off_index = 0; +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && Q_CTX_BASED_PROFILES x->skip = 0; set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); for (i = 0; i < MAX_MB_PLANE; i++) { @@ -8048,10 +8108,10 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, rate2 += rate_copy_mode; this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); -#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 +#if CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES if (this_skip2 && mbmi->dq_off_index > 0) mbmi->dq_off_index = 0; -#endif +#endif // CONFIG_NEW_QUANT && QUANT_PROFILES > 1 && !Q_CTX_BASED_PROFILES if (this_rd < best_rd) { rd_cost->rate = rate2;