mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-23 18:14:06 +00:00
Moved context information inside cabac_data.
This is required in order to be able to work on parallelism.
This commit is contained in:
parent
8a14bd3b7b
commit
816ae13b1d
38
src/cabac.h
38
src/cabac.h
|
@ -27,10 +27,14 @@
|
|||
#include "global.h"
|
||||
|
||||
#include "bitstream.h"
|
||||
#include "context.h"
|
||||
|
||||
|
||||
// Types
|
||||
typedef struct
|
||||
{
|
||||
uint8_t uc_state;
|
||||
} cabac_ctx;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cabac_ctx *ctx;
|
||||
|
@ -41,6 +45,38 @@ typedef struct
|
|||
int32_t bits_left;
|
||||
int8_t only_count;
|
||||
bitstream *stream;
|
||||
|
||||
// CONTEXTS
|
||||
cabac_ctx ctx_sao_merge_flag_model;
|
||||
cabac_ctx ctx_sao_type_idx_model;
|
||||
cabac_ctx ctx_split_flag_model[3]; //!< \brief split flag context models
|
||||
cabac_ctx ctx_intra_mode_model; //!< \brief intra mode context models
|
||||
cabac_ctx ctx_chroma_pred_model[2];
|
||||
cabac_ctx ctx_trans_subdiv_model[3]; //!< \brief intra mode context models
|
||||
cabac_ctx ctx_qt_cbf_model_luma[3];
|
||||
cabac_ctx ctx_qt_cbf_model_chroma[3];
|
||||
cabac_ctx ctx_part_size_model[4];
|
||||
cabac_ctx ctx_cu_sig_coeff_group_model[4];
|
||||
cabac_ctx ctx_cu_sig_model_luma[27];
|
||||
cabac_ctx ctx_cu_sig_model_chroma[15];
|
||||
cabac_ctx ctx_cu_ctx_last_y_luma[15];
|
||||
cabac_ctx ctx_cu_ctx_last_y_chroma[15];
|
||||
cabac_ctx ctx_cu_ctx_last_x_luma[15];
|
||||
cabac_ctx ctx_cu_ctx_last_x_chroma[15];
|
||||
cabac_ctx ctx_cu_one_model_luma[16];
|
||||
cabac_ctx ctx_cu_one_model_chroma[8];
|
||||
cabac_ctx ctx_cu_abs_model_luma[4];
|
||||
cabac_ctx ctx_cu_abs_model_chroma[2];
|
||||
cabac_ctx ctx_cu_pred_mode_model;
|
||||
cabac_ctx ctx_cu_skip_flag_model[3];
|
||||
cabac_ctx ctx_cu_merge_idx_ext_model;
|
||||
cabac_ctx ctx_cu_merge_flag_ext_model;
|
||||
cabac_ctx ctx_cu_mvd_model[2];
|
||||
cabac_ctx ctx_cu_ref_pic_model[2];
|
||||
cabac_ctx ctx_mvp_idx_model[2];
|
||||
cabac_ctx ctx_cu_qt_root_cbf_model;
|
||||
cabac_ctx ctx_transform_skip_model_luma;
|
||||
cabac_ctx ctx_transform_skip_model_chroma;
|
||||
} cabac_data;
|
||||
|
||||
|
||||
|
|
116
src/context.c
116
src/context.c
|
@ -175,39 +175,6 @@ static const uint8_t INIT_TRANSFORMSKIP_FLAG[3][2] =
|
|||
};
|
||||
|
||||
|
||||
// CONTEXTS
|
||||
cabac_ctx g_sao_merge_flag_model;
|
||||
cabac_ctx g_sao_type_idx_model;
|
||||
cabac_ctx g_split_flag_model[3]; //!< \brief split flag context models
|
||||
cabac_ctx g_intra_mode_model; //!< \brief intra mode context models
|
||||
cabac_ctx g_chroma_pred_model[2];
|
||||
cabac_ctx g_trans_subdiv_model[3]; //!< \brief intra mode context models
|
||||
cabac_ctx g_qt_cbf_model_luma[3];
|
||||
cabac_ctx g_qt_cbf_model_chroma[3];
|
||||
cabac_ctx g_part_size_model[4];
|
||||
cabac_ctx g_cu_sig_coeff_group_model[4];
|
||||
cabac_ctx g_cu_sig_model_luma[27];
|
||||
cabac_ctx g_cu_sig_model_chroma[15];
|
||||
cabac_ctx g_cu_ctx_last_y_luma[15];
|
||||
cabac_ctx g_cu_ctx_last_y_chroma[15];
|
||||
cabac_ctx g_cu_ctx_last_x_luma[15];
|
||||
cabac_ctx g_cu_ctx_last_x_chroma[15];
|
||||
cabac_ctx g_cu_one_model_luma[16];
|
||||
cabac_ctx g_cu_one_model_chroma[8];
|
||||
cabac_ctx g_cu_abs_model_luma[4];
|
||||
cabac_ctx g_cu_abs_model_chroma[2];
|
||||
cabac_ctx g_cu_pred_mode_model;
|
||||
cabac_ctx g_cu_skip_flag_model[3];
|
||||
cabac_ctx g_cu_merge_idx_ext_model;
|
||||
cabac_ctx g_cu_merge_flag_ext_model;
|
||||
cabac_ctx g_cu_mvd_model[2];
|
||||
cabac_ctx g_cu_ref_pic_model[2];
|
||||
cabac_ctx g_mvp_idx_model[2];
|
||||
cabac_ctx g_cu_qt_root_cbf_model;
|
||||
cabac_ctx g_transform_skip_model_luma;
|
||||
cabac_ctx g_transform_skip_model_chroma;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -231,76 +198,77 @@ void ctx_init(cabac_ctx *ctx, uint32_t qp, uint32_t init_value)
|
|||
* \param encoder encoder control struct
|
||||
* \param slice type of slice we are coding (P/B/I)
|
||||
*/
|
||||
void init_contexts(int8_t QP, int8_t slice)
|
||||
|
||||
void init_contexts(cabac_data *cabac, int8_t QP, int8_t slice)
|
||||
{
|
||||
uint16_t i;
|
||||
|
||||
// Initialize contexts
|
||||
ctx_init(&g_transform_skip_model_luma, QP, INIT_TRANSFORMSKIP_FLAG[slice][0]);
|
||||
ctx_init(&g_transform_skip_model_chroma, QP, INIT_TRANSFORMSKIP_FLAG[slice][1]);
|
||||
ctx_init(&cabac->ctx_transform_skip_model_luma, QP, INIT_TRANSFORMSKIP_FLAG[slice][0]);
|
||||
ctx_init(&cabac->ctx_transform_skip_model_chroma, QP, INIT_TRANSFORMSKIP_FLAG[slice][1]);
|
||||
|
||||
ctx_init(&g_sao_merge_flag_model, QP, INIT_SAO_MERGE_FLAG[slice]);
|
||||
ctx_init(&g_sao_type_idx_model, QP, INIT_SAO_TYPE_IDX[slice]);
|
||||
ctx_init(&cabac->ctx_sao_merge_flag_model, QP, INIT_SAO_MERGE_FLAG[slice]);
|
||||
ctx_init(&cabac->ctx_sao_type_idx_model, QP, INIT_SAO_TYPE_IDX[slice]);
|
||||
|
||||
ctx_init(&g_cu_merge_flag_ext_model, QP, INIT_MERGE_FLAG_EXT[slice][0]);
|
||||
ctx_init(&g_cu_merge_idx_ext_model, QP, INIT_MERGE_IDX_EXT[slice][0]);
|
||||
ctx_init(&g_cu_pred_mode_model, QP, INIT_PRED_MODE[slice][0]);
|
||||
ctx_init(&cabac->ctx_cu_merge_flag_ext_model, QP, INIT_MERGE_FLAG_EXT[slice][0]);
|
||||
ctx_init(&cabac->ctx_cu_merge_idx_ext_model, QP, INIT_MERGE_IDX_EXT[slice][0]);
|
||||
ctx_init(&cabac->ctx_cu_pred_mode_model, QP, INIT_PRED_MODE[slice][0]);
|
||||
|
||||
ctx_init(&g_cu_skip_flag_model[0], QP, INIT_SKIP_FLAG[slice][0]);
|
||||
ctx_init(&g_cu_skip_flag_model[1], QP, INIT_SKIP_FLAG[slice][1]);
|
||||
ctx_init(&g_cu_skip_flag_model[2], QP, INIT_SKIP_FLAG[slice][2]);
|
||||
ctx_init(&cabac->ctx_cu_skip_flag_model[0], QP, INIT_SKIP_FLAG[slice][0]);
|
||||
ctx_init(&cabac->ctx_cu_skip_flag_model[1], QP, INIT_SKIP_FLAG[slice][1]);
|
||||
ctx_init(&cabac->ctx_cu_skip_flag_model[2], QP, INIT_SKIP_FLAG[slice][2]);
|
||||
|
||||
ctx_init(&g_split_flag_model[0], QP, INIT_SPLIT_FLAG[slice][0]);
|
||||
ctx_init(&g_split_flag_model[1], QP, INIT_SPLIT_FLAG[slice][1]);
|
||||
ctx_init(&g_split_flag_model[2], QP, INIT_SPLIT_FLAG[slice][2]);
|
||||
ctx_init(&cabac->ctx_split_flag_model[0], QP, INIT_SPLIT_FLAG[slice][0]);
|
||||
ctx_init(&cabac->ctx_split_flag_model[1], QP, INIT_SPLIT_FLAG[slice][1]);
|
||||
ctx_init(&cabac->ctx_split_flag_model[2], QP, INIT_SPLIT_FLAG[slice][2]);
|
||||
|
||||
ctx_init(&g_intra_mode_model, QP, INIT_INTRA_PRED_MODE[slice]);
|
||||
ctx_init(&cabac->ctx_intra_mode_model, QP, INIT_INTRA_PRED_MODE[slice]);
|
||||
|
||||
ctx_init(&g_chroma_pred_model[0], QP, INIT_CHROMA_PRED_MODE[slice][0]);
|
||||
ctx_init(&g_chroma_pred_model[1], QP, INIT_CHROMA_PRED_MODE[slice][1]);
|
||||
ctx_init(&cabac->ctx_chroma_pred_model[0], QP, INIT_CHROMA_PRED_MODE[slice][0]);
|
||||
ctx_init(&cabac->ctx_chroma_pred_model[1], QP, INIT_CHROMA_PRED_MODE[slice][1]);
|
||||
|
||||
ctx_init(&g_cu_abs_model_chroma[0], QP, INIT_ABS_FLAG[slice][4]);
|
||||
ctx_init(&g_cu_abs_model_chroma[1], QP, INIT_ABS_FLAG[slice][5]);
|
||||
ctx_init(&cabac->ctx_cu_abs_model_chroma[0], QP, INIT_ABS_FLAG[slice][4]);
|
||||
ctx_init(&cabac->ctx_cu_abs_model_chroma[1], QP, INIT_ABS_FLAG[slice][5]);
|
||||
|
||||
//TODO: ignore P/B contexts on intra frame
|
||||
ctx_init(&g_cu_qt_root_cbf_model, QP, INIT_QT_ROOT_CBF[slice][0]);
|
||||
ctx_init(&cabac->ctx_cu_qt_root_cbf_model, QP, INIT_QT_ROOT_CBF[slice][0]);
|
||||
|
||||
ctx_init(&g_cu_mvd_model[0], QP, INIT_MVD[slice][0]);
|
||||
ctx_init(&g_cu_mvd_model[1], QP, INIT_MVD[slice][1]);
|
||||
ctx_init(&g_cu_ref_pic_model[0], QP, INIT_REF_PIC[slice][0]);
|
||||
ctx_init(&g_cu_ref_pic_model[1], QP, INIT_REF_PIC[slice][1]);
|
||||
ctx_init(&g_mvp_idx_model[0], QP, INIT_MVP_IDX[slice][0]);
|
||||
ctx_init(&g_mvp_idx_model[1], QP, INIT_MVP_IDX[slice][1]);
|
||||
ctx_init(&cabac->ctx_cu_mvd_model[0], QP, INIT_MVD[slice][0]);
|
||||
ctx_init(&cabac->ctx_cu_mvd_model[1], QP, INIT_MVD[slice][1]);
|
||||
ctx_init(&cabac->ctx_cu_ref_pic_model[0], QP, INIT_REF_PIC[slice][0]);
|
||||
ctx_init(&cabac->ctx_cu_ref_pic_model[1], QP, INIT_REF_PIC[slice][1]);
|
||||
ctx_init(&cabac->ctx_mvp_idx_model[0], QP, INIT_MVP_IDX[slice][0]);
|
||||
ctx_init(&cabac->ctx_mvp_idx_model[1], QP, INIT_MVP_IDX[slice][1]);
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
ctx_init(&g_cu_sig_coeff_group_model[i], QP, INIT_SIG_CG_FLAG[slice][i]);
|
||||
ctx_init(&g_cu_abs_model_luma[i], QP, INIT_ABS_FLAG[slice][i]);
|
||||
ctx_init(&g_part_size_model[i], QP, INIT_PART_SIZE[slice][i]);
|
||||
ctx_init(&cabac->ctx_cu_sig_coeff_group_model[i], QP, INIT_SIG_CG_FLAG[slice][i]);
|
||||
ctx_init(&cabac->ctx_cu_abs_model_luma[i], QP, INIT_ABS_FLAG[slice][i]);
|
||||
ctx_init(&cabac->ctx_part_size_model[i], QP, INIT_PART_SIZE[slice][i]);
|
||||
}
|
||||
for (i = 0; i < 3; i++) {
|
||||
ctx_init(&g_trans_subdiv_model[i], QP, INIT_TRANS_SUBDIV_FLAG[slice][i]);
|
||||
ctx_init(&g_qt_cbf_model_luma[i], QP, INIT_QT_CBF[slice][i]);
|
||||
ctx_init(&g_qt_cbf_model_chroma[i], QP, INIT_QT_CBF[slice][i+3]);
|
||||
ctx_init(&cabac->ctx_trans_subdiv_model[i], QP, INIT_TRANS_SUBDIV_FLAG[slice][i]);
|
||||
ctx_init(&cabac->ctx_qt_cbf_model_luma[i], QP, INIT_QT_CBF[slice][i]);
|
||||
ctx_init(&cabac->ctx_qt_cbf_model_chroma[i], QP, INIT_QT_CBF[slice][i+3]);
|
||||
}
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
ctx_init(&g_cu_one_model_chroma[i], QP, INIT_ONE_FLAG[slice][i+16]);
|
||||
ctx_init(&cabac->ctx_cu_one_model_chroma[i], QP, INIT_ONE_FLAG[slice][i+16]);
|
||||
}
|
||||
|
||||
for (i = 0; i < 15; i++) {
|
||||
ctx_init(&g_cu_ctx_last_y_luma[i], QP, INIT_LAST[slice][i] );
|
||||
ctx_init(&g_cu_ctx_last_x_luma[i], QP, INIT_LAST[slice][i] );
|
||||
ctx_init(&cabac->ctx_cu_ctx_last_y_luma[i], QP, INIT_LAST[slice][i] );
|
||||
ctx_init(&cabac->ctx_cu_ctx_last_x_luma[i], QP, INIT_LAST[slice][i] );
|
||||
|
||||
ctx_init(&g_cu_ctx_last_y_chroma[i], QP, INIT_LAST[slice][i+15] );
|
||||
ctx_init(&g_cu_ctx_last_x_chroma[i], QP, INIT_LAST[slice][i+15] );
|
||||
ctx_init(&cabac->ctx_cu_ctx_last_y_chroma[i], QP, INIT_LAST[slice][i+15] );
|
||||
ctx_init(&cabac->ctx_cu_ctx_last_x_chroma[i], QP, INIT_LAST[slice][i+15] );
|
||||
|
||||
ctx_init(&g_cu_one_model_luma[i], QP, INIT_ONE_FLAG[slice][i]);
|
||||
ctx_init(&cabac->ctx_cu_one_model_luma[i], QP, INIT_ONE_FLAG[slice][i]);
|
||||
}
|
||||
ctx_init(&g_cu_one_model_luma[15], QP, INIT_ONE_FLAG[slice][15]);
|
||||
ctx_init(&cabac->ctx_cu_one_model_luma[15], QP, INIT_ONE_FLAG[slice][15]);
|
||||
|
||||
for (i = 0; i < 27; i++) {
|
||||
ctx_init(&g_cu_sig_model_luma[i], QP, INIT_SIG_FLAG[slice][i]);
|
||||
if(i < 15) ctx_init(&g_cu_sig_model_chroma[i], QP, INIT_SIG_FLAG[slice][i+27]);
|
||||
ctx_init(&cabac->ctx_cu_sig_model_luma[i], QP, INIT_SIG_FLAG[slice][i]);
|
||||
if(i < 15) ctx_init(&cabac->ctx_cu_sig_model_chroma[i], QP, INIT_SIG_FLAG[slice][i+27]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,17 +26,13 @@
|
|||
|
||||
#include "global.h"
|
||||
|
||||
|
||||
// Types
|
||||
typedef struct
|
||||
{
|
||||
uint8_t uc_state;
|
||||
} cabac_ctx;
|
||||
#include "encoder.h"
|
||||
#include "cabac.h"
|
||||
|
||||
|
||||
// Functions
|
||||
void ctx_init(cabac_ctx* ctx, uint32_t qp, uint32_t init_value);
|
||||
void init_contexts(int8_t QP, int8_t slice);
|
||||
void init_contexts(cabac_data *cabac, int8_t QP, int8_t slice);
|
||||
int32_t context_calc_pattern_sig_ctx( const uint32_t *sig_coeff_group_flag, uint32_t pos_x, uint32_t pos_y, int32_t width);
|
||||
|
||||
uint32_t context_get_sig_coeff_group( uint32_t *sig_coeff_group_flag,uint32_t pos_x, uint32_t pos_y,int32_t width);
|
||||
|
@ -45,37 +41,6 @@ uint32_t context_get_sig_coeff_group( uint32_t *sig_coeff_group_flag,uint32_t po
|
|||
int32_t context_get_sig_ctx_inc(int32_t pattern_sig_ctx,uint32_t scan_idx,int32_t pos_x,
|
||||
int32_t pos_y,int32_t block_type, int8_t texture_type);
|
||||
|
||||
// CONTEXTS
|
||||
extern cabac_ctx g_sao_merge_flag_model;
|
||||
extern cabac_ctx g_sao_type_idx_model;
|
||||
extern cabac_ctx g_split_flag_model[3];
|
||||
extern cabac_ctx g_intra_mode_model;
|
||||
extern cabac_ctx g_chroma_pred_model[2];
|
||||
extern cabac_ctx g_trans_subdiv_model[3];
|
||||
extern cabac_ctx g_qt_cbf_model_luma[3];
|
||||
extern cabac_ctx g_qt_cbf_model_chroma[3];
|
||||
extern cabac_ctx g_part_size_model[4];
|
||||
extern cabac_ctx g_cu_sig_coeff_group_model[4];
|
||||
extern cabac_ctx g_cu_sig_model_luma[27];
|
||||
extern cabac_ctx g_cu_sig_model_chroma[15];
|
||||
extern cabac_ctx g_cu_ctx_last_y_luma[15];
|
||||
extern cabac_ctx g_cu_ctx_last_y_chroma[15];
|
||||
extern cabac_ctx g_cu_ctx_last_x_luma[15];
|
||||
extern cabac_ctx g_cu_ctx_last_x_chroma[15];
|
||||
extern cabac_ctx g_cu_one_model_luma[16];
|
||||
extern cabac_ctx g_cu_one_model_chroma[8];
|
||||
extern cabac_ctx g_cu_abs_model_luma[4];
|
||||
extern cabac_ctx g_cu_abs_model_chroma[2];
|
||||
extern cabac_ctx g_cu_pred_mode_model;
|
||||
extern cabac_ctx g_cu_skip_flag_model[3];
|
||||
extern cabac_ctx g_cu_merge_idx_ext_model;
|
||||
extern cabac_ctx g_cu_merge_flag_ext_model;
|
||||
extern cabac_ctx g_cu_mvd_model[2];
|
||||
extern cabac_ctx g_cu_ref_pic_model[2];
|
||||
extern cabac_ctx g_mvp_idx_model[2];
|
||||
extern cabac_ctx g_cu_qt_root_cbf_model;
|
||||
extern cabac_ctx g_transform_skip_model_luma;
|
||||
extern cabac_ctx g_transform_skip_model_chroma;
|
||||
#define CNU 154
|
||||
|
||||
#endif
|
||||
|
|
|
@ -464,7 +464,7 @@ void encode_one_frame(encoder_control* encoder)
|
|||
cabac.stream = encoder->stream;
|
||||
|
||||
cabac_start(&cabac);
|
||||
init_contexts(encoder->QP, encoder->in.cur_pic->slicetype);
|
||||
init_contexts(&cabac, encoder->QP, encoder->in.cur_pic->slicetype);
|
||||
scalinglist_process();
|
||||
encode_slice_header(encoder);
|
||||
bitstream_align(encoder->stream);
|
||||
|
@ -1212,7 +1212,7 @@ static void encode_sao_color(encoder_control *encoder, cabac_data *cabac, sao_in
|
|||
/// sao_type_idx_chroma: TR, cMax = 2, cRiceParam = 0, bins = {0, bypass}
|
||||
// Encode sao_type_idx for Y and U+V.
|
||||
if (color_i != COLOR_V) {
|
||||
cabac->ctx = &g_sao_type_idx_model;
|
||||
cabac->ctx = &(cabac->ctx_sao_type_idx_model);;
|
||||
CABAC_BIN(cabac, sao->type == SAO_TYPE_NONE ? 0 : 1, "sao_type_idx");
|
||||
if (sao->type == SAO_TYPE_BAND) {
|
||||
CABAC_BIN_EP(cabac, 0, "sao_type_idx_ep");
|
||||
|
@ -1253,11 +1253,11 @@ static void encode_sao_merge_flags(sao_info *sao, cabac_data *cabac,
|
|||
{
|
||||
// SAO merge flags are not present for the first row and column.
|
||||
if (x_ctb > 0) {
|
||||
cabac->ctx = &g_sao_merge_flag_model;
|
||||
cabac->ctx = &(cabac->ctx_sao_merge_flag_model);
|
||||
CABAC_BIN(cabac, sao->merge_left_flag ? 1 : 0, "sao_merge_left_flag");
|
||||
}
|
||||
if (y_ctb > 0 && !sao->merge_left_flag) {
|
||||
cabac->ctx = &g_sao_merge_flag_model;
|
||||
cabac->ctx = &(cabac->ctx_sao_merge_flag_model);
|
||||
CABAC_BIN(cabac, sao->merge_up_flag ? 1 : 0, "sao_merge_up_flag");
|
||||
}
|
||||
}
|
||||
|
@ -1310,7 +1310,7 @@ void encode_coding_tree(encoder_control *encoder, cabac_data *cabac,
|
|||
split_model++;
|
||||
}
|
||||
|
||||
cabac->ctx = &g_split_flag_model[split_model];
|
||||
cabac->ctx = &(cabac->ctx_split_flag_model[split_model]);
|
||||
CABAC_BIN(cabac, split_flag, "SplitFlag");
|
||||
}
|
||||
|
||||
|
@ -1349,7 +1349,7 @@ void encode_coding_tree(encoder_control *encoder, cabac_data *cabac,
|
|||
ctx_skip++;
|
||||
}
|
||||
|
||||
cabac->ctx = &g_cu_skip_flag_model[ctx_skip];
|
||||
cabac->ctx = &(cabac->ctx_cu_skip_flag_model[ctx_skip]);
|
||||
CABAC_BIN(cabac, cur_cu->skipped, "SkipFlag");
|
||||
|
||||
// IF SKIP
|
||||
|
@ -1358,7 +1358,7 @@ void encode_coding_tree(encoder_control *encoder, cabac_data *cabac,
|
|||
for (ui = 0; ui < num_cand - 1; ui++) {
|
||||
int32_t symbol = (ui != cur_cu->merge_idx);
|
||||
if (ui == 0) {
|
||||
cabac->ctx = &g_cu_merge_idx_ext_model;
|
||||
cabac->ctx = &(cabac->ctx_cu_merge_idx_ext_model);
|
||||
CABAC_BIN(cabac, symbol, "MergeIndex");
|
||||
} else {
|
||||
CABAC_BIN_EP(cabac,symbol,"MergeIndex");
|
||||
|
@ -1376,14 +1376,14 @@ void encode_coding_tree(encoder_control *encoder, cabac_data *cabac,
|
|||
|
||||
// Prediction mode
|
||||
if (encoder->in.cur_pic->slicetype != SLICE_I) {
|
||||
cabac->ctx = &g_cu_pred_mode_model;
|
||||
cabac->ctx = &(cabac->ctx_cu_pred_mode_model);
|
||||
CABAC_BIN(cabac, (cur_cu->type == CU_INTRA), "PredMode");
|
||||
}
|
||||
|
||||
// part_mode
|
||||
if (cur_cu->type == CU_INTRA) {
|
||||
if (depth == MAX_DEPTH) {
|
||||
cabac->ctx = &g_part_size_model[0];
|
||||
cabac->ctx = &(cabac->ctx_part_size_model[0]);
|
||||
if (cur_cu->part_size == SIZE_2Nx2N) {
|
||||
CABAC_BIN(cabac, 1, "part_mode 2Nx2N");
|
||||
} else {
|
||||
|
@ -1392,7 +1392,7 @@ void encode_coding_tree(encoder_control *encoder, cabac_data *cabac,
|
|||
}
|
||||
} else {
|
||||
// TODO: Handle inter sizes other than 2Nx2N
|
||||
cabac->ctx = &g_part_size_model[0];
|
||||
cabac->ctx = &(cabac->ctx_part_size_model[0]);
|
||||
CABAC_BIN(cabac, 1, "part_mode 2Nx2N");
|
||||
}
|
||||
|
||||
|
@ -1401,7 +1401,7 @@ void encode_coding_tree(encoder_control *encoder, cabac_data *cabac,
|
|||
// FOR each part
|
||||
// Mergeflag
|
||||
int16_t num_cand = 0;
|
||||
cabac->ctx = &g_cu_merge_flag_ext_model;
|
||||
cabac->ctx = &(cabac->ctx_cu_merge_flag_ext_model);
|
||||
CABAC_BIN(cabac, cur_cu->merged, "MergeFlag");
|
||||
num_cand = MRG_MAX_NUM_CANDS;
|
||||
if (cur_cu->merged) { //merge
|
||||
|
@ -1410,7 +1410,7 @@ void encode_coding_tree(encoder_control *encoder, cabac_data *cabac,
|
|||
for (ui = 0; ui < num_cand - 1; ui++) {
|
||||
int32_t symbol = (ui != cur_cu->merge_idx);
|
||||
if (ui == 0) {
|
||||
cabac->ctx = &g_cu_merge_idx_ext_model;
|
||||
cabac->ctx = &(cabac->ctx_cu_merge_idx_ext_model);
|
||||
CABAC_BIN(cabac, symbol, "MergeIndex");
|
||||
} else {
|
||||
CABAC_BIN_EP(cabac,symbol,"MergeIndex");
|
||||
|
@ -1447,14 +1447,14 @@ void encode_coding_tree(encoder_control *encoder, cabac_data *cabac,
|
|||
// parseRefFrmIdx
|
||||
int32_t ref_frame = cur_cu->inter.mv_ref;
|
||||
|
||||
cabac->ctx = &g_cu_ref_pic_model[0];
|
||||
cabac->ctx = &(cabac->ctx_cu_ref_pic_model[0]);
|
||||
CABAC_BIN(cabac, (ref_frame == 0) ? 0 : 1, "ref_frame_flag");
|
||||
|
||||
if (ref_frame > 0) {
|
||||
int32_t i;
|
||||
int32_t ref_num = encoder->ref->used_size - 2;
|
||||
|
||||
cabac->ctx = &g_cu_ref_pic_model[1];
|
||||
cabac->ctx = &(cabac->ctx_cu_ref_pic_model[1]);
|
||||
ref_frame--;
|
||||
|
||||
for (i = 0; i < ref_num; ++i) {
|
||||
|
@ -1478,11 +1478,11 @@ void encode_coding_tree(encoder_control *encoder, cabac_data *cabac,
|
|||
const uint32_t mvd_hor_abs = abs(mvd_hor);
|
||||
const uint32_t mvd_ver_abs = abs(mvd_ver);
|
||||
|
||||
cabac->ctx = &g_cu_mvd_model[0];
|
||||
cabac->ctx = &(cabac->ctx_cu_mvd_model[0]);
|
||||
CABAC_BIN(cabac, (mvd_hor!=0)?1:0, "abs_mvd_greater0_flag_hor");
|
||||
CABAC_BIN(cabac, (mvd_ver!=0)?1:0, "abs_mvd_greater0_flag_ver");
|
||||
|
||||
cabac->ctx = &g_cu_mvd_model[1];
|
||||
cabac->ctx = &(cabac->ctx_cu_mvd_model[1]);
|
||||
|
||||
if (hor_abs_gr0) {
|
||||
CABAC_BIN(cabac, (mvd_hor_abs>1)?1:0, "abs_mvd_greater1_flag_hor");
|
||||
|
@ -1510,7 +1510,7 @@ void encode_coding_tree(encoder_control *encoder, cabac_data *cabac,
|
|||
}
|
||||
|
||||
// Signal which candidate MV to use
|
||||
cabac_write_unary_max_symbol(cabac, g_mvp_idx_model, cur_cu->inter.mv_cand, 1,
|
||||
cabac_write_unary_max_symbol(cabac, cabac->ctx_mvp_idx_model, cur_cu->inter.mv_cand, 1,
|
||||
AMVP_MAX_NUM_CANDS - 1);
|
||||
}
|
||||
}
|
||||
|
@ -1521,7 +1521,7 @@ void encode_coding_tree(encoder_control *encoder, cabac_data *cabac,
|
|||
// Only need to signal coded block flag if not skipped or merged
|
||||
// skip = no coded residual, merge = coded residual
|
||||
if (!cur_cu->merged) {
|
||||
cabac->ctx = &g_cu_qt_root_cbf_model;
|
||||
cabac->ctx = &(cabac->ctx_cu_qt_root_cbf_model);
|
||||
CABAC_BIN(cabac, cur_cu->coeff_top_y[depth] | cur_cu->coeff_top_u[depth] | cur_cu->coeff_top_v[depth], "rqt_root_cbf");
|
||||
}
|
||||
// Code (possible) coeffs to bitstream
|
||||
|
@ -1578,7 +1578,7 @@ void encode_coding_tree(encoder_control *encoder, cabac_data *cabac,
|
|||
flag[j] = (mpm_preds[j] == -1) ? 0 : 1;
|
||||
}
|
||||
|
||||
cabac->ctx = &g_intra_mode_model;
|
||||
cabac->ctx = &(cabac->ctx_intra_mode_model);
|
||||
for (j = 0; j < num_pred_units; ++j) {
|
||||
CABAC_BIN(cabac, flag[j], "prev_intra_luma_pred_flag");
|
||||
}
|
||||
|
@ -1640,7 +1640,7 @@ void encode_coding_tree(encoder_control *encoder, cabac_data *cabac,
|
|||
* Table 9-37 - Assignment of ctxInc to syntax elements with context coded bins
|
||||
* intra_chroma_pred_mode[][] = 0, bypass, bypass
|
||||
*/
|
||||
cabac->ctx = &g_chroma_pred_model[0];
|
||||
cabac->ctx = &(cabac->ctx_chroma_pred_model[0]);
|
||||
if (pred_mode == 4) {
|
||||
CABAC_BIN(cabac, 0, "intra_chroma_pred_mode");
|
||||
} else {
|
||||
|
@ -1700,7 +1700,7 @@ void encode_coding_tree(encoder_control *encoder, cabac_data *cabac,
|
|||
/* end coding_unit */
|
||||
}
|
||||
|
||||
static void transform_chroma(encoder_control *encoder, cu_info *cur_cu,
|
||||
static void transform_chroma(encoder_control *encoder, cabac_data *cabac, cu_info *cur_cu,
|
||||
int depth, pixel *base_u, pixel *pred_u,
|
||||
coefficient *coeff_u, int8_t scan_idx_chroma,
|
||||
coefficient *pre_quant_coeff, coefficient *block)
|
||||
|
@ -1725,7 +1725,7 @@ static void transform_chroma(encoder_control *encoder, cu_info *cur_cu,
|
|||
|
||||
transform2d(block, pre_quant_coeff, width_c, 65535);
|
||||
if (encoder->rdoq_enable) {
|
||||
rdoq(encoder, pre_quant_coeff, coeff_u, width_c, width_c, &ac_sum, 2,
|
||||
rdoq(encoder, cabac, pre_quant_coeff, coeff_u, width_c, width_c, &ac_sum, 2,
|
||||
scan_idx_chroma, cur_cu->type, cur_cu->tr_depth-cur_cu->depth);
|
||||
} else {
|
||||
quant(encoder, pre_quant_coeff, coeff_u, width_c, width_c, &ac_sum, 2,
|
||||
|
@ -1988,7 +1988,7 @@ void encode_transform_tree(encoder_control* encoder, cabac_data *cabac, int32_t
|
|||
}
|
||||
|
||||
if (encoder->rdoq_enable) {
|
||||
rdoq(encoder, pre_quant_coeff, coeff_y, width, width, &ac_sum, 0,
|
||||
rdoq(encoder, cabac, pre_quant_coeff, coeff_y, width, width, &ac_sum, 0,
|
||||
scan_idx_luma, cur_cu->type, cur_cu->tr_depth-cur_cu->depth);
|
||||
} else {
|
||||
quant(encoder, pre_quant_coeff, coeff_y, width, width, &ac_sum, 0, scan_idx_luma, cur_cu->type);
|
||||
|
@ -2072,7 +2072,7 @@ void encode_transform_tree(encoder_control* encoder, cabac_data *cabac, int32_t
|
|||
}
|
||||
}
|
||||
|
||||
transform_chroma(encoder, cur_cu, chroma_depth, base_u, pred_u, coeff_u, scan_idx_chroma, pre_quant_coeff, block);
|
||||
transform_chroma(encoder, cabac, cur_cu, chroma_depth, base_u, pred_u, coeff_u, scan_idx_chroma, pre_quant_coeff, block);
|
||||
for (i = 0; i < chroma_size; i++) {
|
||||
if (coeff_u[i] != 0) {
|
||||
int d;
|
||||
|
@ -2082,7 +2082,7 @@ void encode_transform_tree(encoder_control* encoder, cabac_data *cabac, int32_t
|
|||
break;
|
||||
}
|
||||
}
|
||||
transform_chroma(encoder, cur_cu, chroma_depth, base_v, pred_v, coeff_v, scan_idx_chroma, pre_quant_coeff, block);
|
||||
transform_chroma(encoder, cabac, cur_cu, chroma_depth, base_v, pred_v, coeff_v, scan_idx_chroma, pre_quant_coeff, block);
|
||||
for (i = 0; i < chroma_size; i++) {
|
||||
if (coeff_v[i] != 0) {
|
||||
int d;
|
||||
|
@ -2308,7 +2308,7 @@ void encode_transform_coeff(encoder_control *encoder, cabac_data *cabac, int32_t
|
|||
tr_depth < max_tr_depth &&
|
||||
!(intra_split_flag && tr_depth == 0))
|
||||
{
|
||||
cabac->ctx = &g_trans_subdiv_model[5 - ((g_convert_to_bit[LCU_WIDTH] + 2) - depth)];
|
||||
cabac->ctx = &(cabac->ctx_trans_subdiv_model[5 - ((g_convert_to_bit[LCU_WIDTH] + 2) - depth)]);
|
||||
CABAC_BIN(cabac, split, "split_transform_flag");
|
||||
}
|
||||
|
||||
|
@ -2318,7 +2318,7 @@ void encode_transform_coeff(encoder_control *encoder, cabac_data *cabac, int32_t
|
|||
// When they are not present they are inferred to be 0, except for size 4
|
||||
// when the flags from previous level are used.
|
||||
if (depth < MAX_PU_DEPTH) {
|
||||
cabac->ctx = &g_qt_cbf_model_chroma[tr_depth];
|
||||
cabac->ctx = &(cabac->ctx_qt_cbf_model_chroma[tr_depth]);
|
||||
if (tr_depth == 0 || parent_coeff_u) {
|
||||
CABAC_BIN(cabac, cb_flag_u, "cbf_cb");
|
||||
}
|
||||
|
@ -2342,7 +2342,7 @@ void encode_transform_coeff(encoder_control *encoder, cabac_data *cabac, int32_t
|
|||
// - we have chroma coefficients at this level
|
||||
// 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) {
|
||||
cabac->ctx = &g_qt_cbf_model_luma[!tr_depth];
|
||||
cabac->ctx = &(cabac->ctx_qt_cbf_model_luma[!tr_depth]);
|
||||
CABAC_BIN(cabac, cb_flag_y, "cbf_luma");
|
||||
}
|
||||
|
||||
|
@ -2378,14 +2378,14 @@ void encode_coeff_nxn(encoder_control *encoder, cabac_data *cabac, coefficient *
|
|||
const uint32_t *scan_cg = g_sig_last_scan_cg[log2_block_size - 2][scan_mode];
|
||||
|
||||
// Init base contexts according to block type
|
||||
cabac_ctx *base_coeff_group_ctx = &g_cu_sig_coeff_group_model[type];
|
||||
cabac_ctx *baseCtx = (type == 0) ? &g_cu_sig_model_luma[0] :
|
||||
&g_cu_sig_model_chroma[0];
|
||||
cabac_ctx *base_coeff_group_ctx = &(cabac->ctx_cu_sig_coeff_group_model[type]);
|
||||
cabac_ctx *baseCtx = (type == 0) ? &(cabac->ctx_cu_sig_model_luma[0]) :
|
||||
&(cabac->ctx_cu_sig_model_chroma[0]);
|
||||
memset(sig_coeffgroup_flag,0,sizeof(uint32_t)*64);
|
||||
|
||||
// transform skip flag
|
||||
if(width == 4 && encoder->trskip_enable) {
|
||||
cabac->ctx = (type == 0) ? &g_transform_skip_model_luma : &g_transform_skip_model_chroma;
|
||||
cabac->ctx = (type == 0) ? &(cabac->ctx_transform_skip_model_luma) : &(cabac->ctx_transform_skip_model_chroma);
|
||||
CABAC_BIN(cabac, tr_skip, "transform_skip_flag");
|
||||
}
|
||||
|
||||
|
@ -2502,8 +2502,8 @@ void encode_coeff_nxn(encoder_control *encoder, cabac_data *cabac, coefficient *
|
|||
|
||||
c1 = 1;
|
||||
|
||||
base_ctx_mod = (type == 0) ? &g_cu_one_model_luma[4 * ctx_set] :
|
||||
&g_cu_one_model_chroma[4 * ctx_set];
|
||||
base_ctx_mod = (type == 0) ? &(cabac->ctx_cu_one_model_luma[4 * ctx_set]) :
|
||||
&(cabac->ctx_cu_one_model_chroma[4 * ctx_set]);
|
||||
num_c1_flag = MIN(num_non_zero, C1FLAG_NUMBER);
|
||||
first_c2_flag_idx = -1;
|
||||
|
||||
|
@ -2524,8 +2524,8 @@ void encode_coeff_nxn(encoder_control *encoder, cabac_data *cabac, coefficient *
|
|||
}
|
||||
|
||||
if (c1 == 0) {
|
||||
base_ctx_mod = (type == 0) ? &g_cu_abs_model_luma[ctx_set] :
|
||||
&g_cu_abs_model_chroma[ctx_set];
|
||||
base_ctx_mod = (type == 0) ? &(cabac->ctx_cu_abs_model_luma[ctx_set]) :
|
||||
&(cabac->ctx_cu_abs_model_chroma[ctx_set]);
|
||||
|
||||
if (first_c2_flag_idx != -1) {
|
||||
uint8_t symbol = (abs_coeff[first_c2_flag_idx] > 2) ? 1 : 0;
|
||||
|
@ -2584,8 +2584,8 @@ void encode_last_significant_xy(cabac_data *cabac,
|
|||
int group_idx_x;
|
||||
int group_idx_y;
|
||||
int last_x,last_y,i;
|
||||
cabac_ctx *base_ctx_x = (type ? g_cu_ctx_last_x_chroma : g_cu_ctx_last_x_luma);
|
||||
cabac_ctx *base_ctx_y = (type ? g_cu_ctx_last_y_chroma : g_cu_ctx_last_y_luma);
|
||||
cabac_ctx *base_ctx_x = (type ? cabac->ctx_cu_ctx_last_x_chroma : cabac->ctx_cu_ctx_last_x_luma);
|
||||
cabac_ctx *base_ctx_y = (type ? cabac->ctx_cu_ctx_last_y_chroma : cabac->ctx_cu_ctx_last_y_luma);
|
||||
|
||||
if (scan == SCAN_VER) {
|
||||
SWAP( lastpos_x, lastpos_y,uint8_t );
|
||||
|
|
120
src/rdo.c
120
src/rdo.c
|
@ -63,7 +63,7 @@ const uint32_t entropy_bits[128] =
|
|||
* \param type data type (0 == luma)
|
||||
* \returns bits needed to code input coefficients
|
||||
*/
|
||||
int32_t get_coeff_cost(encoder_control *encoder, coefficient *coeff, int32_t width, int32_t type)
|
||||
int32_t get_coeff_cost(encoder_control *encoder, cabac_data *cabac, coefficient *coeff, int32_t width, int32_t type)
|
||||
{
|
||||
cabac_data temp_cabac;
|
||||
int32_t cost = 0;
|
||||
|
@ -89,55 +89,56 @@ int32_t get_coeff_cost(encoder_control *encoder, coefficient *coeff, int32_t wid
|
|||
|
||||
// Store contexts TODO: handle contexts better
|
||||
if(type==0) {
|
||||
memcpy(last_x,g_cu_ctx_last_x_luma, sizeof(cabac_ctx)*15);
|
||||
memcpy(last_y,g_cu_ctx_last_y_luma, sizeof(cabac_ctx)*15);
|
||||
memcpy(abs_model,g_cu_abs_model_luma, sizeof(cabac_ctx)*4);
|
||||
memcpy(one_model,g_cu_one_model_luma, sizeof(cabac_ctx)*16);
|
||||
memcpy(sig_model,g_cu_sig_model_luma, sizeof(cabac_ctx)*27);
|
||||
memcpy(&transform_skip,&g_transform_skip_model_luma, sizeof(cabac_ctx));
|
||||
memcpy(last_x,cabac->ctx_cu_ctx_last_x_luma, sizeof(cabac_ctx)*15);
|
||||
memcpy(last_y,cabac->ctx_cu_ctx_last_y_luma, sizeof(cabac_ctx)*15);
|
||||
memcpy(abs_model,cabac->ctx_cu_abs_model_luma, sizeof(cabac_ctx)*4);
|
||||
memcpy(one_model,cabac->ctx_cu_one_model_luma, sizeof(cabac_ctx)*16);
|
||||
memcpy(sig_model,cabac->ctx_cu_sig_model_luma, sizeof(cabac_ctx)*27);
|
||||
memcpy(&transform_skip,&cabac->ctx_transform_skip_model_luma, sizeof(cabac_ctx));
|
||||
} else {
|
||||
memcpy(last_x,g_cu_ctx_last_x_chroma, sizeof(cabac_ctx)*15);
|
||||
memcpy(last_y,g_cu_ctx_last_y_chroma, sizeof(cabac_ctx)*15);
|
||||
memcpy(abs_model,g_cu_abs_model_chroma, sizeof(cabac_ctx)*2);
|
||||
memcpy(one_model,g_cu_one_model_chroma, sizeof(cabac_ctx)*8);
|
||||
memcpy(sig_model,g_cu_sig_model_chroma, sizeof(cabac_ctx)*15);
|
||||
memcpy(&transform_skip,&g_transform_skip_model_chroma, sizeof(cabac_ctx));
|
||||
memcpy(last_x,cabac->ctx_cu_ctx_last_x_chroma, sizeof(cabac_ctx)*15);
|
||||
memcpy(last_y,cabac->ctx_cu_ctx_last_y_chroma, sizeof(cabac_ctx)*15);
|
||||
memcpy(abs_model,cabac->ctx_cu_abs_model_chroma, sizeof(cabac_ctx)*2);
|
||||
memcpy(one_model,cabac->ctx_cu_one_model_chroma, sizeof(cabac_ctx)*8);
|
||||
memcpy(sig_model,cabac->ctx_cu_sig_model_chroma, sizeof(cabac_ctx)*15);
|
||||
memcpy(&transform_skip,&cabac->ctx_transform_skip_model_chroma, sizeof(cabac_ctx));
|
||||
}
|
||||
memcpy(sig_coeff_group,g_cu_sig_coeff_group_model,sizeof(cabac_ctx)*4);
|
||||
memcpy(sig_coeff_group,cabac->ctx_cu_sig_coeff_group_model,sizeof(cabac_ctx)*4);
|
||||
|
||||
// Store cabac state
|
||||
memcpy(&temp_cabac,&cabac,sizeof(cabac_data));
|
||||
memcpy(&temp_cabac,cabac,sizeof(cabac_data));
|
||||
|
||||
// Clear bytes and bits and set mode to "count"
|
||||
cabac.only_count = 1;
|
||||
cabac.num_buffered_bytes = 0;
|
||||
cabac.bits_left = 23;
|
||||
cabac->only_count = 1;
|
||||
cabac->num_buffered_bytes = 0;
|
||||
cabac->bits_left = 23;
|
||||
|
||||
// Execute the coding function
|
||||
encode_coeff_nxn(encoder, coeff, width, type, SCAN_DIAG, 0);
|
||||
encode_coeff_nxn(encoder, cabac, coeff, width, type, SCAN_DIAG, 0);
|
||||
|
||||
// Store bitcost before restoring cabac
|
||||
cost = (23-cabac.bits_left) + (cabac.num_buffered_bytes << 3);
|
||||
cost = (23-cabac->bits_left) + (cabac->num_buffered_bytes << 3);
|
||||
|
||||
// Restore cabac state
|
||||
memcpy(&cabac,&temp_cabac,sizeof(cabac_data));
|
||||
memcpy(cabac,&temp_cabac,sizeof(cabac_data));
|
||||
|
||||
// Restore contexts TODO: handle contexts better
|
||||
if(type==0) {
|
||||
memcpy(g_cu_ctx_last_x_luma,last_x, sizeof(cabac_ctx)*15);
|
||||
memcpy(g_cu_ctx_last_y_luma,last_y, sizeof(cabac_ctx)*15);
|
||||
memcpy(g_cu_abs_model_luma,abs_model, sizeof(cabac_ctx)*4);
|
||||
memcpy(g_cu_one_model_luma,one_model, sizeof(cabac_ctx)*16);
|
||||
memcpy(g_cu_sig_model_luma,sig_model, sizeof(cabac_ctx)*27);
|
||||
memcpy(&g_transform_skip_model_luma,&transform_skip, sizeof(cabac_ctx));
|
||||
memcpy(cabac->ctx_cu_ctx_last_x_luma,last_x, sizeof(cabac_ctx)*15);
|
||||
memcpy(cabac->ctx_cu_ctx_last_y_luma,last_y, sizeof(cabac_ctx)*15);
|
||||
memcpy(cabac->ctx_cu_abs_model_luma,abs_model, sizeof(cabac_ctx)*4);
|
||||
memcpy(cabac->ctx_cu_one_model_luma,one_model, sizeof(cabac_ctx)*16);
|
||||
memcpy(cabac->ctx_cu_sig_model_luma,sig_model, sizeof(cabac_ctx)*27);
|
||||
memcpy(&cabac->ctx_transform_skip_model_luma,&transform_skip, sizeof(cabac_ctx));
|
||||
} else {
|
||||
memcpy(g_cu_ctx_last_x_chroma,last_x, sizeof(cabac_ctx)*15);
|
||||
memcpy(g_cu_ctx_last_y_chroma,last_y, sizeof(cabac_ctx)*15);
|
||||
memcpy(g_cu_abs_model_chroma,abs_model, sizeof(cabac_ctx)*2);
|
||||
memcpy(g_cu_one_model_chroma,one_model, sizeof(cabac_ctx)*8);
|
||||
memcpy(g_cu_sig_model_chroma,sig_model, sizeof(cabac_ctx)*15);
|
||||
memcpy(&g_transform_skip_model_chroma,&transform_skip, sizeof(cabac_ctx));
|
||||
memcpy(cabac->ctx_cu_ctx_last_x_chroma,last_x, sizeof(cabac_ctx)*15);
|
||||
memcpy(cabac->ctx_cu_ctx_last_y_chroma,last_y, sizeof(cabac_ctx)*15);
|
||||
memcpy(cabac->ctx_cu_abs_model_chroma,abs_model, sizeof(cabac_ctx)*2);
|
||||
memcpy(cabac->ctx_cu_one_model_chroma,one_model, sizeof(cabac_ctx)*8);
|
||||
memcpy(cabac->ctx_cu_sig_model_chroma,sig_model, sizeof(cabac_ctx)*15);
|
||||
memcpy(&cabac->ctx_transform_skip_model_chroma,&transform_skip, sizeof(cabac_ctx));
|
||||
}
|
||||
memcpy(g_cu_sig_coeff_group_model,sig_coeff_group,sizeof(cabac_ctx)*4);
|
||||
memcpy(cabac->ctx_cu_sig_coeff_group_model,sig_coeff_group,sizeof(cabac_ctx)*4);
|
||||
|
||||
|
||||
return cost;
|
||||
|
@ -154,7 +155,8 @@ int32_t get_coeff_cost(encoder_control *encoder, coefficient *coeff, int32_t wid
|
|||
* \returns cost of given absolute transform level
|
||||
* From HM 12.0
|
||||
*/
|
||||
double get_ic_rate_cost (uint32_t abs_level,
|
||||
double get_ic_rate_cost (cabac_data *cabac,
|
||||
uint32_t abs_level,
|
||||
uint16_t ctx_num_one,
|
||||
uint16_t ctx_num_abs,
|
||||
uint16_t abs_go_rice,
|
||||
|
@ -165,8 +167,8 @@ double get_ic_rate_cost (uint32_t abs_level,
|
|||
{
|
||||
double rate = 32768.0;
|
||||
uint32_t base_level = (c1_idx < C1FLAG_NUMBER)? (2 + (c2_idx < C2FLAG_NUMBER)) : 1;
|
||||
cabac_ctx *base_one_ctx = (type == 0) ? &g_cu_one_model_luma[0] : &g_cu_one_model_chroma[0];
|
||||
cabac_ctx *base_abs_ctx = (type == 0) ? &g_cu_abs_model_luma[0] : &g_cu_abs_model_chroma[0];
|
||||
cabac_ctx *base_one_ctx = (type == 0) ? &(cabac->ctx_cu_one_model_luma[0]) : &(cabac->ctx_cu_one_model_chroma[0]);
|
||||
cabac_ctx *base_abs_ctx = (type == 0) ? &(cabac->ctx_cu_abs_model_luma[0]) : &(cabac->ctx_cu_abs_model_chroma[0]);
|
||||
|
||||
if ( abs_level >= base_level ) {
|
||||
int32_t symbol = abs_level - base_level;
|
||||
|
@ -201,13 +203,13 @@ double get_ic_rate_cost (uint32_t abs_level,
|
|||
}
|
||||
|
||||
|
||||
int32_t get_ic_rate( uint32_t abs_level, uint16_t ctx_num_one,uint16_t ctx_num_abs,
|
||||
int32_t get_ic_rate( cabac_data *cabac, uint32_t abs_level, uint16_t ctx_num_one,uint16_t ctx_num_abs,
|
||||
uint16_t abs_go_rice, uint32_t c1_idx, uint32_t c2_idx, int8_t type)
|
||||
{
|
||||
int32_t rate = 0;
|
||||
uint32_t base_level = (c1_idx < C1FLAG_NUMBER)? (2 + (c2_idx < C2FLAG_NUMBER)) : 1;
|
||||
cabac_ctx *base_one_ctx = (type == 0) ? &g_cu_one_model_luma[0] : &g_cu_one_model_chroma[0];
|
||||
cabac_ctx *base_abs_ctx = (type == 0) ? &g_cu_abs_model_luma[0] : &g_cu_abs_model_chroma[0];
|
||||
cabac_ctx *base_one_ctx = (type == 0) ? &(cabac->ctx_cu_one_model_luma[0]) : &(cabac->ctx_cu_one_model_chroma[0]);
|
||||
cabac_ctx *base_abs_ctx = (type == 0) ? &(cabac->ctx_cu_abs_model_luma[0]) : &(cabac->ctx_cu_abs_model_chroma[0]);
|
||||
|
||||
if(!abs_level) return 0;
|
||||
|
||||
|
@ -262,7 +264,7 @@ int32_t get_ic_rate( uint32_t abs_level, uint16_t ctx_num_one,uint16_t ctx_num_a
|
|||
* This method calculates the best quantized transform level for a given scan position.
|
||||
* From HM 12.0
|
||||
*/
|
||||
uint32_t get_coded_level ( encoder_control* encoder, double *coded_cost, double *coded_cost0, double *coded_cost_sig,
|
||||
uint32_t get_coded_level ( encoder_control* encoder, cabac_data *cabac, double *coded_cost, double *coded_cost0, double *coded_cost_sig,
|
||||
int32_t level_double, uint32_t max_abs_level,
|
||||
uint16_t ctx_num_sig, uint16_t ctx_num_one, uint16_t ctx_num_abs,
|
||||
uint16_t abs_go_rice,
|
||||
|
@ -273,7 +275,7 @@ uint32_t get_coded_level ( encoder_control* encoder, double *coded_cost, double
|
|||
uint32_t best_abs_level = 0;
|
||||
int32_t abs_level;
|
||||
int32_t min_abs_level;
|
||||
cabac_ctx* base_sig_model = type?g_cu_sig_model_chroma:g_cu_sig_model_luma;
|
||||
cabac_ctx* base_sig_model = type?(cabac->ctx_cu_sig_model_chroma):(cabac->ctx_cu_sig_model_luma);
|
||||
|
||||
if( !last && max_abs_level < 3 ) {
|
||||
*coded_cost_sig = g_lambda_cost[encoder->QP] * CTX_ENTROPY_BITS(&base_sig_model[ctx_num_sig], 0);
|
||||
|
@ -291,7 +293,7 @@ uint32_t get_coded_level ( encoder_control* encoder, double *coded_cost, double
|
|||
for (abs_level = max_abs_level; abs_level >= min_abs_level ; abs_level-- ) {
|
||||
double err = (double)(level_double - ( abs_level << q_bits ) );
|
||||
double cur_cost = err * err * temp + g_lambda_cost[encoder->QP] *
|
||||
get_ic_rate_cost( abs_level, ctx_num_one, ctx_num_abs,
|
||||
get_ic_rate_cost( cabac, abs_level, ctx_num_one, ctx_num_abs,
|
||||
abs_go_rice, c1_idx, c2_idx, type);
|
||||
cur_cost += cur_cost_sig;
|
||||
|
||||
|
@ -330,15 +332,15 @@ static double get_rate_last(encoder_control* encoder,
|
|||
return g_lambda_cost[encoder->QP]*uiCost;
|
||||
}
|
||||
|
||||
static void calc_last_bits(int32_t width, int32_t height, int8_t type,
|
||||
static void calc_last_bits(cabac_data *cabac, int32_t width, int32_t height, int8_t type,
|
||||
int32_t* last_x_bits, int32_t* last_y_bits)
|
||||
{
|
||||
int32_t bits_x = 0, bits_y = 0;
|
||||
int32_t blk_size_offset_x, blk_size_offset_y, shiftX, shiftY;
|
||||
int32_t ctx;
|
||||
|
||||
cabac_ctx *base_ctx_x = (type ? g_cu_ctx_last_x_chroma : g_cu_ctx_last_x_luma);
|
||||
cabac_ctx *base_ctx_y = (type ? g_cu_ctx_last_y_chroma : g_cu_ctx_last_y_luma);
|
||||
cabac_ctx *base_ctx_x = (type ? cabac->ctx_cu_ctx_last_x_chroma : cabac->ctx_cu_ctx_last_x_luma);
|
||||
cabac_ctx *base_ctx_y = (type ? cabac->ctx_cu_ctx_last_y_chroma : cabac->ctx_cu_ctx_last_y_luma);
|
||||
|
||||
blk_size_offset_x = type ? 0: (g_convert_to_bit[ width ] *3 + ((g_convert_to_bit[ width ] +1)>>2));
|
||||
blk_size_offset_y = type ? 0: (g_convert_to_bit[ height ]*3 + ((g_convert_to_bit[ height ]+1)>>2));
|
||||
|
@ -366,7 +368,7 @@ static void calc_last_bits(int32_t width, int32_t height, int8_t type,
|
|||
* coding engines using probability models like CABAC
|
||||
* From HM 12.0
|
||||
*/
|
||||
void rdoq(encoder_control *encoder, coefficient *coef, coefficient *dest_coeff, int32_t width,
|
||||
void rdoq(encoder_control *encoder, cabac_data *cabac, coefficient *coef, coefficient *dest_coeff, int32_t width,
|
||||
int32_t height, uint32_t *abs_sum, int8_t type, int8_t scan_mode, int8_t block_type, int8_t tr_depth)
|
||||
{
|
||||
uint32_t log2_tr_size = g_convert_to_bit[ width ] + 2;
|
||||
|
@ -421,9 +423,9 @@ void rdoq(encoder_control *encoder, coefficient *coef, coefficient *dest_coeff,
|
|||
uint32_t cg_num = width * height >> 4;
|
||||
int32_t scanpos;
|
||||
|
||||
cabac_ctx *base_coeff_group_ctx = &g_cu_sig_coeff_group_model[type];
|
||||
cabac_ctx *baseCtx = (type == 0) ? &g_cu_sig_model_luma[0] : &g_cu_sig_model_chroma[0];
|
||||
cabac_ctx *base_one_ctx = (type == 0) ? &g_cu_one_model_luma[0] : &g_cu_one_model_chroma[0];
|
||||
cabac_ctx *base_coeff_group_ctx = &(cabac->ctx_cu_sig_coeff_group_model[type]);
|
||||
cabac_ctx *baseCtx = (type == 0) ? &(cabac->ctx_cu_sig_model_luma[0]) : &(cabac->ctx_cu_sig_model_chroma[0]);
|
||||
cabac_ctx *base_one_ctx = (type == 0) ? &(cabac->ctx_cu_one_model_luma[0]) : &(cabac->ctx_cu_one_model_chroma[0]);
|
||||
|
||||
double best_cost = 0;
|
||||
int32_t ctx_cbf = 0;
|
||||
|
@ -434,7 +436,7 @@ void rdoq(encoder_control *encoder, coefficient *coef, coefficient *dest_coeff,
|
|||
coeffgroup_rd_stats rd_stats;
|
||||
|
||||
int32_t last_x_bits[32],last_y_bits[32];
|
||||
calc_last_bits(width, height, type,last_x_bits, last_y_bits);
|
||||
calc_last_bits(cabac, width, height, type,last_x_bits, last_y_bits);
|
||||
|
||||
memset( cost_coeff, 0, sizeof(double) * max_num_coeff );
|
||||
memset( cost_sig, 0, sizeof(double) * max_num_coeff );
|
||||
|
@ -489,7 +491,7 @@ void rdoq(encoder_control *encoder, coefficient *coef, coefficient *dest_coeff,
|
|||
uint16_t abs_ctx = ctx_set + c2;
|
||||
|
||||
if( scanpos == last_scanpos ) {
|
||||
level = get_coded_level(encoder, &cost_coeff[ scanpos ], &cost_coeff0[ scanpos ], &cost_sig[ scanpos ],
|
||||
level = get_coded_level(encoder, cabac, &cost_coeff[ scanpos ], &cost_coeff0[ scanpos ], &cost_sig[ scanpos ],
|
||||
level_double, max_abs_level, 0, one_ctx, abs_ctx, go_rice_param,
|
||||
c1_idx, c2_idx, q_bits, temp, 1, type );
|
||||
} else {
|
||||
|
@ -497,16 +499,16 @@ void rdoq(encoder_control *encoder, coefficient *coef, coefficient *dest_coeff,
|
|||
uint32_t pos_x = blkpos - ( pos_y << log2_block_size );
|
||||
uint16_t ctx_sig = (uint16_t)context_get_sig_ctx_inc(pattern_sig_ctx, scan_mode, pos_x, pos_y,
|
||||
log2_block_size, type);
|
||||
level = get_coded_level(encoder, &cost_coeff[ scanpos ], &cost_coeff0[ scanpos ], &cost_sig[ scanpos ],
|
||||
level = get_coded_level(encoder, cabac, &cost_coeff[ scanpos ], &cost_coeff0[ scanpos ], &cost_sig[ scanpos ],
|
||||
level_double, max_abs_level, ctx_sig, one_ctx, abs_ctx, go_rice_param,
|
||||
c1_idx, c2_idx, q_bits, temp, 0, type );
|
||||
sig_rate_delta[ blkpos ] = CTX_ENTROPY_BITS(&baseCtx[ctx_sig],1) - CTX_ENTROPY_BITS(&baseCtx[ctx_sig],0);
|
||||
}
|
||||
delta_u[ blkpos ] = (level_double - ((int32_t)level << q_bits)) >> (q_bits-8);
|
||||
if( level > 0 ) {
|
||||
int32_t rate_now = get_ic_rate( level, one_ctx, abs_ctx, go_rice_param, c1_idx, c2_idx, type);
|
||||
rate_inc_up [blkpos] = get_ic_rate( level+1, one_ctx, abs_ctx, go_rice_param, c1_idx, c2_idx, type) - rate_now;
|
||||
rate_inc_down[blkpos] = get_ic_rate( level-1, one_ctx, abs_ctx, go_rice_param, c1_idx, c2_idx, type) - rate_now;
|
||||
int32_t rate_now = get_ic_rate( cabac, level, one_ctx, abs_ctx, go_rice_param, c1_idx, c2_idx, type);
|
||||
rate_inc_up [blkpos] = get_ic_rate( cabac, level+1, one_ctx, abs_ctx, go_rice_param, c1_idx, c2_idx, type) - rate_now;
|
||||
rate_inc_down[blkpos] = get_ic_rate( cabac, level-1, one_ctx, abs_ctx, go_rice_param, c1_idx, c2_idx, type) - rate_now;
|
||||
} else { // level == 0
|
||||
rate_inc_up[blkpos] = CTX_ENTROPY_BITS(&base_one_ctx[one_ctx],0);
|
||||
}
|
||||
|
@ -626,10 +628,10 @@ void rdoq(encoder_control *encoder, coefficient *coef, coefficient *dest_coeff,
|
|||
|
||||
|
||||
if( block_type != CU_INTRA && !type/* && pcCU->getTransformIdx( uiAbsPartIdx ) == 0*/ ) {
|
||||
best_cost = block_uncoded_cost + g_lambda_cost[encoder->QP]*CTX_ENTROPY_BITS(&g_cu_qt_root_cbf_model,0);
|
||||
base_cost += g_lambda_cost[encoder->QP]*CTX_ENTROPY_BITS(&g_cu_qt_root_cbf_model,1);
|
||||
best_cost = block_uncoded_cost + g_lambda_cost[encoder->QP]*CTX_ENTROPY_BITS(&(cabac->ctx_cu_qt_root_cbf_model),0);
|
||||
base_cost += g_lambda_cost[encoder->QP]*CTX_ENTROPY_BITS(&(cabac->ctx_cu_qt_root_cbf_model),1);
|
||||
} else {
|
||||
cabac_ctx* base_cbf_model = type?g_qt_cbf_model_chroma:g_qt_cbf_model_luma;
|
||||
cabac_ctx* base_cbf_model = type?(cabac->ctx_qt_cbf_model_chroma):(cabac->ctx_qt_cbf_model_luma);
|
||||
ctx_cbf = ( type ? tr_depth : !tr_depth);
|
||||
best_cost = block_uncoded_cost + g_lambda_cost[encoder->QP]*CTX_ENTROPY_BITS(&base_cbf_model[ctx_cbf],0);
|
||||
base_cost += g_lambda_cost[encoder->QP]*CTX_ENTROPY_BITS(&base_cbf_model[ctx_cbf],1);
|
||||
|
|
10
src/rdo.h
10
src/rdo.h
|
@ -42,16 +42,16 @@ extern const uint32_t g_go_rice_range[5];
|
|||
extern const uint32_t g_go_rice_prefix_len[5];
|
||||
|
||||
|
||||
void rdoq(encoder_control *encoder, coefficient *coef, coefficient *dest_coeff, int32_t width,
|
||||
void rdoq(encoder_control *encoder, cabac_data *cabac, coefficient *coef, coefficient *dest_coeff, int32_t width,
|
||||
int32_t height, uint32_t *abs_sum, int8_t type, int8_t scan_mode, int8_t block_type, int8_t tr_depth);
|
||||
|
||||
int32_t get_coeff_cost(encoder_control *encoder, coefficient *coeff, int32_t width, int32_t type);
|
||||
int32_t get_coeff_cost(encoder_control *encoder, cabac_data *cabac, coefficient *coeff, int32_t width, int32_t type);
|
||||
|
||||
int32_t get_ic_rate( uint32_t abs_level, uint16_t ctx_num_one,uint16_t ctx_num_abs,
|
||||
int32_t get_ic_rate(cabac_data *cabac, uint32_t abs_level, uint16_t ctx_num_one,uint16_t ctx_num_abs,
|
||||
uint16_t abs_go_rice, uint32_t c1_idx, uint32_t c2_idx, int8_t type);
|
||||
double get_ic_rate_cost (uint32_t abs_level, uint16_t ctx_num_one, uint16_t ctx_num_abs,
|
||||
double get_ic_rate_cost (cabac_data *cabac, uint32_t abs_level, uint16_t ctx_num_one, uint16_t ctx_num_abs,
|
||||
uint16_t abs_go_rice, uint32_t c1_idx, uint32_t c2_idx, int8_t type);
|
||||
uint32_t get_coded_level ( encoder_control* encoder, double* coded_cost, double* coded_cost0, double* coded_cost_sig,
|
||||
uint32_t get_coded_level ( encoder_control* encoder, cabac_data *cabac, double* coded_cost, double* coded_cost0, double* coded_cost_sig,
|
||||
int32_t level_double, uint32_t max_abs_level,
|
||||
uint16_t ctx_num_sig, uint16_t ctx_num_one, uint16_t ctx_num_abs,
|
||||
uint16_t abs_go_rice,
|
||||
|
|
Loading…
Reference in a new issue