Rename cabac_state.ctx to cur_ctx.

This commit is contained in:
Ari Koivula 2014-09-24 00:55:28 +03:00
parent 8b8b53fba5
commit b339004c4c
3 changed files with 38 additions and 38 deletions

View file

@ -97,20 +97,20 @@ void cabac_encode_bin(cabac_data * const data, const uint32_t bin_value)
uint32_t lps; uint32_t lps;
lps = g_auc_lpst_table[CTX_STATE(data->ctx)][(data->range >> 6) & 3]; lps = g_auc_lpst_table[CTX_STATE(data->cur_ctx)][(data->range >> 6) & 3];
data->range -= lps; data->range -= lps;
// Not the Most Probable Symbol? // Not the Most Probable Symbol?
if ((bin_value ? 1 : 0) != CTX_MPS(data->ctx)) { if ((bin_value ? 1 : 0) != CTX_MPS(data->cur_ctx)) {
int num_bits = g_auc_renorm_table[lps >> 3]; int num_bits = g_auc_renorm_table[lps >> 3];
data->low = (data->low + data->range) << num_bits; data->low = (data->low + data->range) << num_bits;
data->range = lps << num_bits; data->range = lps << num_bits;
CTX_UPDATE_LPS(data->ctx); CTX_UPDATE_LPS(data->cur_ctx);
data->bits_left -= num_bits; data->bits_left -= num_bits;
} else { } else {
CTX_UPDATE_MPS(data->ctx); CTX_UPDATE_MPS(data->cur_ctx);
if (data->range >= 256) return; if (data->range >= 256) return;
data->low <<= 1; data->low <<= 1;
@ -306,17 +306,17 @@ void cabac_write_unary_max_symbol(cabac_data * const data, cabac_ctx * const ctx
if (!max_symbol) return; if (!max_symbol) return;
data->ctx = &ctx[0]; data->cur_ctx = &ctx[0];
CABAC_BIN(data, symbol, "ums"); CABAC_BIN(data, symbol, "ums");
if (!symbol) return; if (!symbol) return;
while (--symbol) { while (--symbol) {
data->ctx = &ctx[offset]; data->cur_ctx = &ctx[offset];
CABAC_BIN(data, 1, "ums"); CABAC_BIN(data, 1, "ums");
} }
if (code_last) { if (code_last) {
data->ctx = &ctx[offset]; data->cur_ctx = &ctx[offset];
CABAC_BIN(data, 0, "ums"); CABAC_BIN(data, 0, "ums");
} }
} }

View file

@ -37,7 +37,7 @@ typedef struct
typedef struct typedef struct
{ {
cabac_ctx *ctx; cabac_ctx *cur_ctx;
uint32_t low; uint32_t low;
uint32_t range; uint32_t range;
uint32_t buffered_byte; uint32_t buffered_byte;

View file

@ -142,7 +142,7 @@ static void encode_sao_color(encoder_state * const encoder_state, sao_info *sao,
/// sao_type_idx_chroma: TR, cMax = 2, cRiceParam = 0, bins = {0, bypass} /// sao_type_idx_chroma: TR, cMax = 2, cRiceParam = 0, bins = {0, bypass}
// Encode sao_type_idx for Y and U+V. // Encode sao_type_idx for Y and U+V.
if (color_i != COLOR_V) { if (color_i != COLOR_V) {
cabac->ctx = &(cabac->ctx_sao_type_idx_model); cabac->cur_ctx = &(cabac->ctx_sao_type_idx_model);;
CABAC_BIN(cabac, sao->type != SAO_TYPE_NONE, "sao_type_idx"); CABAC_BIN(cabac, sao->type != SAO_TYPE_NONE, "sao_type_idx");
if (sao->type == SAO_TYPE_BAND) { if (sao->type == SAO_TYPE_BAND) {
CABAC_BIN_EP(cabac, 0, "sao_type_idx_ep"); CABAC_BIN_EP(cabac, 0, "sao_type_idx_ep");
@ -183,11 +183,11 @@ static void encode_sao_merge_flags(encoder_state * const encoder_state, sao_info
cabac_data * const cabac = &encoder_state->cabac; cabac_data * const cabac = &encoder_state->cabac;
// SAO merge flags are not present for the first row and column. // SAO merge flags are not present for the first row and column.
if (x_ctb > 0) { if (x_ctb > 0) {
cabac->ctx = &(cabac->ctx_sao_merge_flag_model); cabac->cur_ctx = &(cabac->ctx_sao_merge_flag_model);
CABAC_BIN(cabac, sao->merge_left_flag, "sao_merge_left_flag"); CABAC_BIN(cabac, sao->merge_left_flag, "sao_merge_left_flag");
} }
if (y_ctb > 0 && !sao->merge_left_flag) { if (y_ctb > 0 && !sao->merge_left_flag) {
cabac->ctx = &(cabac->ctx_sao_merge_flag_model); cabac->cur_ctx = &(cabac->ctx_sao_merge_flag_model);
CABAC_BIN(cabac, sao->merge_up_flag, "sao_merge_up_flag"); CABAC_BIN(cabac, sao->merge_up_flag, "sao_merge_up_flag");
} }
} }
@ -967,7 +967,7 @@ void encode_coding_tree(encoder_state * const encoder_state,
split_model++; split_model++;
} }
cabac->ctx = &(cabac->ctx_split_flag_model[split_model]); cabac->cur_ctx = &(cabac->ctx_split_flag_model[split_model]);
CABAC_BIN(cabac, split_flag, "SplitFlag"); CABAC_BIN(cabac, split_flag, "SplitFlag");
} }
@ -1006,7 +1006,7 @@ void encode_coding_tree(encoder_state * const encoder_state,
ctx_skip++; ctx_skip++;
} }
cabac->ctx = &(cabac->ctx_cu_skip_flag_model[ctx_skip]); cabac->cur_ctx = &(cabac->ctx_cu_skip_flag_model[ctx_skip]);
CABAC_BIN(cabac, cur_cu->skipped, "SkipFlag"); CABAC_BIN(cabac, cur_cu->skipped, "SkipFlag");
// IF SKIP // IF SKIP
@ -1015,7 +1015,7 @@ void encode_coding_tree(encoder_state * const encoder_state,
for (ui = 0; ui < num_cand - 1; ui++) { for (ui = 0; ui < num_cand - 1; ui++) {
int32_t symbol = (ui != cur_cu->merge_idx); int32_t symbol = (ui != cur_cu->merge_idx);
if (ui == 0) { if (ui == 0) {
cabac->ctx = &(cabac->ctx_cu_merge_idx_ext_model); cabac->cur_ctx = &(cabac->ctx_cu_merge_idx_ext_model);
CABAC_BIN(cabac, symbol, "MergeIndex"); CABAC_BIN(cabac, symbol, "MergeIndex");
} else { } else {
CABAC_BIN_EP(cabac,symbol,"MergeIndex"); CABAC_BIN_EP(cabac,symbol,"MergeIndex");
@ -1033,14 +1033,14 @@ void encode_coding_tree(encoder_state * const encoder_state,
// Prediction mode // Prediction mode
if (encoder_state->global->slicetype != SLICE_I) { if (encoder_state->global->slicetype != SLICE_I) {
cabac->ctx = &(cabac->ctx_cu_pred_mode_model); cabac->cur_ctx = &(cabac->ctx_cu_pred_mode_model);
CABAC_BIN(cabac, (cur_cu->type == CU_INTRA), "PredMode"); CABAC_BIN(cabac, (cur_cu->type == CU_INTRA), "PredMode");
} }
// part_mode // part_mode
if (cur_cu->type == CU_INTRA) { if (cur_cu->type == CU_INTRA) {
if (depth == MAX_DEPTH) { if (depth == MAX_DEPTH) {
cabac->ctx = &(cabac->ctx_part_size_model[0]); cabac->cur_ctx = &(cabac->ctx_part_size_model[0]);
if (cur_cu->part_size == SIZE_2Nx2N) { if (cur_cu->part_size == SIZE_2Nx2N) {
CABAC_BIN(cabac, 1, "part_mode 2Nx2N"); CABAC_BIN(cabac, 1, "part_mode 2Nx2N");
} else { } else {
@ -1049,7 +1049,7 @@ void encode_coding_tree(encoder_state * const encoder_state,
} }
} else { } else {
// TODO: Handle inter sizes other than 2Nx2N // TODO: Handle inter sizes other than 2Nx2N
cabac->ctx = &(cabac->ctx_part_size_model[0]); cabac->cur_ctx = &(cabac->ctx_part_size_model[0]);
CABAC_BIN(cabac, 1, "part_mode 2Nx2N"); CABAC_BIN(cabac, 1, "part_mode 2Nx2N");
} }
@ -1058,7 +1058,7 @@ void encode_coding_tree(encoder_state * const encoder_state,
// FOR each part // FOR each part
// Mergeflag // Mergeflag
int16_t num_cand = 0; int16_t num_cand = 0;
cabac->ctx = &(cabac->ctx_cu_merge_flag_ext_model); cabac->cur_ctx = &(cabac->ctx_cu_merge_flag_ext_model);
CABAC_BIN(cabac, cur_cu->merged, "MergeFlag"); CABAC_BIN(cabac, cur_cu->merged, "MergeFlag");
num_cand = MRG_MAX_NUM_CANDS; num_cand = MRG_MAX_NUM_CANDS;
if (cur_cu->merged) { //merge if (cur_cu->merged) { //merge
@ -1067,7 +1067,7 @@ void encode_coding_tree(encoder_state * const encoder_state,
for (ui = 0; ui < num_cand - 1; ui++) { for (ui = 0; ui < num_cand - 1; ui++) {
int32_t symbol = (ui != cur_cu->merge_idx); int32_t symbol = (ui != cur_cu->merge_idx);
if (ui == 0) { if (ui == 0) {
cabac->ctx = &(cabac->ctx_cu_merge_idx_ext_model); cabac->cur_ctx = &(cabac->ctx_cu_merge_idx_ext_model);
CABAC_BIN(cabac, symbol, "MergeIndex"); CABAC_BIN(cabac, symbol, "MergeIndex");
} else { } else {
CABAC_BIN_EP(cabac,symbol,"MergeIndex"); CABAC_BIN_EP(cabac,symbol,"MergeIndex");
@ -1104,14 +1104,14 @@ void encode_coding_tree(encoder_state * const encoder_state,
// parseRefFrmIdx // parseRefFrmIdx
int32_t ref_frame = cur_cu->inter.mv_ref; int32_t ref_frame = cur_cu->inter.mv_ref;
cabac->ctx = &(cabac->ctx_cu_ref_pic_model[0]); cabac->cur_ctx = &(cabac->ctx_cu_ref_pic_model[0]);
CABAC_BIN(cabac, (ref_frame != 0), "ref_frame_flag"); CABAC_BIN(cabac, (ref_frame != 0), "ref_frame_flag");
if (ref_frame > 0) { if (ref_frame > 0) {
int32_t i; int32_t i;
int32_t ref_num = encoder_state->global->ref->used_size - 2; int32_t ref_num = encoder_state->global->ref->used_size - 2;
cabac->ctx = &(cabac->ctx_cu_ref_pic_model[1]); cabac->cur_ctx = &(cabac->ctx_cu_ref_pic_model[1]);
ref_frame--; ref_frame--;
for (i = 0; i < ref_num; ++i) { for (i = 0; i < ref_num; ++i) {
@ -1135,11 +1135,11 @@ void encode_coding_tree(encoder_state * const encoder_state,
const uint32_t mvd_hor_abs = abs(mvd_hor); const uint32_t mvd_hor_abs = abs(mvd_hor);
const uint32_t mvd_ver_abs = abs(mvd_ver); const uint32_t mvd_ver_abs = abs(mvd_ver);
cabac->ctx = &(cabac->ctx_cu_mvd_model[0]); cabac->cur_ctx = &(cabac->ctx_cu_mvd_model[0]);
CABAC_BIN(cabac, (mvd_hor != 0), "abs_mvd_greater0_flag_hor"); CABAC_BIN(cabac, (mvd_hor != 0), "abs_mvd_greater0_flag_hor");
CABAC_BIN(cabac, (mvd_ver != 0), "abs_mvd_greater0_flag_ver"); CABAC_BIN(cabac, (mvd_ver != 0), "abs_mvd_greater0_flag_ver");
cabac->ctx = &(cabac->ctx_cu_mvd_model[1]); cabac->cur_ctx = &(cabac->ctx_cu_mvd_model[1]);
if (hor_abs_gr0) { if (hor_abs_gr0) {
CABAC_BIN(cabac, (mvd_hor_abs>1), "abs_mvd_greater1_flag_hor"); CABAC_BIN(cabac, (mvd_hor_abs>1), "abs_mvd_greater1_flag_hor");
@ -1182,7 +1182,7 @@ void encode_coding_tree(encoder_state * const encoder_state,
// Only need to signal coded block flag if not skipped or merged // Only need to signal coded block flag if not skipped or merged
// skip = no coded residual, merge = coded residual // skip = no coded residual, merge = coded residual
if (!cur_cu->merged) { if (!cur_cu->merged) {
cabac->ctx = &(cabac->ctx_cu_qt_root_cbf_model); cabac->cur_ctx = &(cabac->ctx_cu_qt_root_cbf_model);
CABAC_BIN(cabac, cbf, "rqt_root_cbf"); CABAC_BIN(cabac, cbf, "rqt_root_cbf");
} }
// Code (possible) coeffs to bitstream // Code (possible) coeffs to bitstream
@ -1239,7 +1239,7 @@ void encode_coding_tree(encoder_state * const encoder_state,
flag[j] = (mpm_preds[j] == -1) ? 0 : 1; flag[j] = (mpm_preds[j] == -1) ? 0 : 1;
} }
cabac->ctx = &(cabac->ctx_intra_mode_model); cabac->cur_ctx = &(cabac->ctx_intra_mode_model);
for (j = 0; j < num_pred_units; ++j) { for (j = 0; j < num_pred_units; ++j) {
CABAC_BIN(cabac, flag[j], "prev_intra_luma_pred_flag"); CABAC_BIN(cabac, flag[j], "prev_intra_luma_pred_flag");
} }
@ -1305,7 +1305,7 @@ void encode_coding_tree(encoder_state * const encoder_state,
* Table 9-37 - Assignment of ctxInc to syntax elements with context coded bins * Table 9-37 - Assignment of ctxInc to syntax elements with context coded bins
* intra_chroma_pred_mode[][] = 0, bypass, bypass * intra_chroma_pred_mode[][] = 0, bypass, bypass
*/ */
cabac->ctx = &(cabac->ctx_chroma_pred_model[0]); cabac->cur_ctx = &(cabac->ctx_chroma_pred_model[0]);
if (pred_mode == 4) { if (pred_mode == 4) {
CABAC_BIN(cabac, 0, "intra_chroma_pred_mode"); CABAC_BIN(cabac, 0, "intra_chroma_pred_mode");
} else { } else {
@ -1507,7 +1507,7 @@ void encode_transform_coeff(encoder_state * const encoder_state, int32_t x_pu,in
tr_depth < max_tr_depth && tr_depth < max_tr_depth &&
!(intra_split_flag && tr_depth == 0)) !(intra_split_flag && tr_depth == 0))
{ {
cabac->ctx = &(cabac->ctx_trans_subdiv_model[5 - ((g_convert_to_bit[LCU_WIDTH] + 2) - depth)]); cabac->cur_ctx = &(cabac->ctx_trans_subdiv_model[5 - ((g_convert_to_bit[LCU_WIDTH] + 2) - depth)]);
CABAC_BIN(cabac, split, "split_transform_flag"); CABAC_BIN(cabac, split, "split_transform_flag");
} }
@ -1517,7 +1517,7 @@ void encode_transform_coeff(encoder_state * const encoder_state, int32_t x_pu,in
// When they are not present they are inferred to be 0, except for size 4 // When they are not present they are inferred to be 0, except for size 4
// when the flags from previous level are used. // when the flags from previous level are used.
if (depth < MAX_PU_DEPTH) { if (depth < MAX_PU_DEPTH) {
cabac->ctx = &(cabac->ctx_qt_cbf_model_chroma[tr_depth]); cabac->cur_ctx = &(cabac->ctx_qt_cbf_model_chroma[tr_depth]);
if (tr_depth == 0 || parent_coeff_u) { if (tr_depth == 0 || parent_coeff_u) {
CABAC_BIN(cabac, cb_flag_u, "cbf_cb"); CABAC_BIN(cabac, cb_flag_u, "cbf_cb");
} }
@ -1541,7 +1541,7 @@ void encode_transform_coeff(encoder_state * const encoder_state, int32_t x_pu,in
// - we have chroma coefficients at this level // - we have chroma coefficients at this level
// When it is not present, it is inferred to be 1. // When it is not present, it is inferred to be 1.
if(cur_cu->type == CU_INTRA || tr_depth > 0 || cb_flag_u || cb_flag_v) { if(cur_cu->type == CU_INTRA || tr_depth > 0 || cb_flag_u || cb_flag_v) {
cabac->ctx = &(cabac->ctx_qt_cbf_model_luma[!tr_depth]); cabac->cur_ctx = &(cabac->ctx_qt_cbf_model_luma[!tr_depth]);
CABAC_BIN(cabac, cb_flag_y, "cbf_luma"); CABAC_BIN(cabac, cb_flag_y, "cbf_luma");
} }
@ -1596,7 +1596,7 @@ void encode_coeff_nxn(encoder_state * const encoder_state, coefficient *coeff, u
// transform skip flag // transform skip flag
if(width == 4 && encoder->trskip_enable) { if(width == 4 && encoder->trskip_enable) {
cabac->ctx = (type == 0) ? &(cabac->ctx_transform_skip_model_luma) : &(cabac->ctx_transform_skip_model_chroma); cabac->cur_ctx = (type == 0) ? &(cabac->ctx_transform_skip_model_luma) : &(cabac->ctx_transform_skip_model_chroma);
CABAC_BIN(cabac, tr_skip, "transform_skip_flag"); CABAC_BIN(cabac, tr_skip, "transform_skip_flag");
} }
@ -1656,7 +1656,7 @@ void encode_coeff_nxn(encoder_state * const encoder_state, coefficient *coeff, u
uint32_t sig_coeff_group = (sig_coeffgroup_flag[cg_blk_pos] != 0); uint32_t sig_coeff_group = (sig_coeffgroup_flag[cg_blk_pos] != 0);
uint32_t ctx_sig = context_get_sig_coeff_group(sig_coeffgroup_flag, cg_pos_x, uint32_t ctx_sig = context_get_sig_coeff_group(sig_coeffgroup_flag, cg_pos_x,
cg_pos_y, width); cg_pos_y, width);
cabac->ctx = &base_coeff_group_ctx[ctx_sig]; cabac->cur_ctx = &base_coeff_group_ctx[ctx_sig];
CABAC_BIN(cabac, sig_coeff_group, "coded_sub_block_flag"); CABAC_BIN(cabac, sig_coeff_group, "coded_sub_block_flag");
} }
@ -1673,7 +1673,7 @@ void encode_coeff_nxn(encoder_state * const encoder_state, coefficient *coeff, u
if (scan_pos_sig > sub_pos || i == 0 || num_non_zero) { if (scan_pos_sig > sub_pos || i == 0 || num_non_zero) {
ctx_sig = context_get_sig_ctx_inc(pattern_sig_ctx, scan_mode, pos_x, pos_y, ctx_sig = context_get_sig_ctx_inc(pattern_sig_ctx, scan_mode, pos_x, pos_y,
log2_block_size, type); log2_block_size, type);
cabac->ctx = &baseCtx[ctx_sig]; cabac->cur_ctx = &baseCtx[ctx_sig];
CABAC_BIN(cabac, sig, "sig_coeff_flag"); CABAC_BIN(cabac, sig, "sig_coeff_flag");
} }
@ -1713,7 +1713,7 @@ void encode_coeff_nxn(encoder_state * const encoder_state, coefficient *coeff, u
for (idx = 0; idx < num_c1_flag; idx++) { for (idx = 0; idx < num_c1_flag; idx++) {
uint32_t symbol = (abs_coeff[idx] > 1) ? 1 : 0; uint32_t symbol = (abs_coeff[idx] > 1) ? 1 : 0;
cabac->ctx = &base_ctx_mod[c1]; cabac->cur_ctx = &base_ctx_mod[c1];
CABAC_BIN(cabac, symbol, "coeff_abs_level_greater1_flag"); CABAC_BIN(cabac, symbol, "coeff_abs_level_greater1_flag");
if (symbol) { if (symbol) {
@ -1733,7 +1733,7 @@ void encode_coeff_nxn(encoder_state * const encoder_state, coefficient *coeff, u
if (first_c2_flag_idx != -1) { if (first_c2_flag_idx != -1) {
uint8_t symbol = (abs_coeff[first_c2_flag_idx] > 2) ? 1 : 0; uint8_t symbol = (abs_coeff[first_c2_flag_idx] > 2) ? 1 : 0;
cabac->ctx = &base_ctx_mod[0]; cabac->cur_ctx = &base_ctx_mod[0];
CABAC_BIN(cabac, symbol, "coeff_abs_level_greater2_flag"); CABAC_BIN(cabac, symbol, "coeff_abs_level_greater2_flag");
} }
} }
@ -1801,23 +1801,23 @@ void encode_last_significant_xy(encoder_state * const encoder_state,
// Last X binarization // Last X binarization
for (last_x = 0; last_x < group_idx_x ; last_x++) { for (last_x = 0; last_x < group_idx_x ; last_x++) {
cabac->ctx = &base_ctx_x[offset_x + (last_x >> shift_x)]; cabac->cur_ctx = &base_ctx_x[offset_x + (last_x >> shift_x)];
CABAC_BIN(cabac,1,"last_sig_coeff_x_prefix"); CABAC_BIN(cabac,1,"last_sig_coeff_x_prefix");
} }
if (group_idx_x < g_group_idx[width - 1]) { if (group_idx_x < g_group_idx[width - 1]) {
cabac->ctx = &base_ctx_x[offset_x + (last_x >> shift_x)]; cabac->cur_ctx = &base_ctx_x[offset_x + (last_x >> shift_x)];
CABAC_BIN(cabac,0,"last_sig_coeff_x_prefix"); CABAC_BIN(cabac,0,"last_sig_coeff_x_prefix");
} }
// Last Y binarization // Last Y binarization
for (last_y = 0; last_y < group_idx_y ; last_y++) { for (last_y = 0; last_y < group_idx_y ; last_y++) {
cabac->ctx = &base_ctx_y[offset_y + (last_y >> shift_y)]; cabac->cur_ctx = &base_ctx_y[offset_y + (last_y >> shift_y)];
CABAC_BIN(cabac,1,"last_sig_coeff_y_prefix"); CABAC_BIN(cabac,1,"last_sig_coeff_y_prefix");
} }
if (group_idx_y < g_group_idx[height - 1]) { if (group_idx_y < g_group_idx[height - 1]) {
cabac->ctx = &base_ctx_y[offset_y + (last_y >> shift_y)]; cabac->cur_ctx = &base_ctx_y[offset_y + (last_y >> shift_y)];
CABAC_BIN(cabac,0,"last_sig_coeff_y_prefix"); CABAC_BIN(cabac,0,"last_sig_coeff_y_prefix");
} }