From ae2d79c954297d31e76edc0f60406b6a894a2d10 Mon Sep 17 00:00:00 2001 From: Laurent Fasnacht Date: Tue, 15 Apr 2014 14:20:26 +0200 Subject: [PATCH 1/4] Remove encoder_control.cqmfile --- src/encmain.c | 5 ----- src/encoder.c | 15 +++++++++++---- src/encoder.h | 1 - 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/encmain.c b/src/encmain.c index 7c2f541b..33f939fe 100644 --- a/src/encmain.c +++ b/src/encmain.c @@ -59,7 +59,6 @@ int main(int argc, char *argv[]) config *cfg = NULL; //!< Global configuration FILE *input = NULL; //!< input file (YUV) FILE *output = NULL; //!< output file (HEVC NAL stream) - FILE *cqmfile = NULL; //!< HM-compatible CQM file encoder_control *encoder = NULL; //!< Encoder control struct double psnr[3] = { 0.0, 0.0, 0.0 }; uint64_t curpos = 0; @@ -250,9 +249,6 @@ int main(int argc, char *argv[]) encoder->vui.chroma_loc = (int8_t)encoder->cfg->vui.chroma_loc; // AUD encoder->aud_enable = (int8_t)encoder->cfg->aud_enable; - // CQM - cqmfile = cfg->cqmfile ? fopen(cfg->cqmfile, "rb") : NULL; - encoder->cqmfile = cqmfile; init_encoder_input(&encoder->in, input, cfg->width, cfg->height); @@ -392,7 +388,6 @@ int main(int argc, char *argv[]) fclose(input); fclose(output); - if(cqmfile != NULL) fclose(cqmfile); if(recout != NULL) fclose(recout); // Deallocating diff --git a/src/encoder.c b/src/encoder.c index 1a87c07a..9623f65f 100644 --- a/src/encoder.c +++ b/src/encoder.c @@ -311,7 +311,17 @@ encoder_control *init_encoder_control(config *cfg) enc_c->ref = pic_list; enc_c->ref_list = REF_PIC_LIST_0; - + + // CQM + { + FILE* cqmfile; + cqmfile = cfg->cqmfile ? fopen(cfg->cqmfile, "rb") : NULL; + if (cqmfile) { + scalinglist_parse(enc_c, cqmfile); + fclose(cqmfile); + } + } + return enc_c; init_failure: @@ -409,9 +419,6 @@ void encode_one_frame(encoder_control* encoder) picture_list_rem(encoder->ref, encoder->ref->used_size - 1, 1); } - if (encoder->frame == 0 && encoder->cqmfile) - scalinglist_parse(encoder, encoder->cqmfile); - encoder->poc = 0; encoder->in.cur_pic->slicetype = SLICE_I; diff --git a/src/encoder.h b/src/encoder.h index e5b18263..4fdfea00 100644 --- a/src/encoder.h +++ b/src/encoder.h @@ -106,7 +106,6 @@ typedef struct } vui; int8_t aud_enable; - FILE *cqmfile; // \brief Costum Quantization Matrices //scaling list uint8_t scaling_list_enable; From 763b775d3e7d8cfbd236d0504473a8829cd14349 Mon Sep 17 00:00:00 2001 From: Laurent Fasnacht Date: Tue, 15 Apr 2014 14:30:14 +0200 Subject: [PATCH 2/4] encoder_control->cfg is const --- src/encoder.c | 2 +- src/encoder.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/encoder.c b/src/encoder.c index 9623f65f..e781ae37 100644 --- a/src/encoder.c +++ b/src/encoder.c @@ -708,7 +708,7 @@ void encode_prefix_sei_version(const encoder_control * const encoder) int i, length; char buf[STR_BUF_LEN] = { 0 }; char *s = buf + 16; - config *cfg = encoder->cfg; + const config *cfg = encoder->cfg; // random uuid_iso_iec_11578 generated with www.famkruithof.net/uuid/uuidgen static const uint8_t uuid[16] = { diff --git a/src/encoder.h b/src/encoder.h index 4fdfea00..aca455e7 100644 --- a/src/encoder.h +++ b/src/encoder.h @@ -71,7 +71,7 @@ typedef struct { int32_t frame; int32_t poc; /*!< \brief picture order count */ - config *cfg; + const config *cfg; encoder_input in; encoder_me me; bitstream *stream; From 288a4537baecb71d49941ee4c35196accfb90075 Mon Sep 17 00:00:00 2001 From: Laurent Fasnacht Date: Tue, 15 Apr 2014 14:37:16 +0200 Subject: [PATCH 3/4] const bit_table for exp_golomb --- src/bitstream.c | 13 ++++++++----- src/bitstream.h | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/bitstream.c b/src/bitstream.c index 189cce4e..c279462a 100644 --- a/src/bitstream.c +++ b/src/bitstream.c @@ -63,7 +63,7 @@ void printf_bitstream(char *msg, ...) } #endif -bit_table *g_exp_table; +const bit_table *g_exp_table; //From wikipedia //http://en.wikipedia.org/wiki/Binary_logarithm#Algorithm @@ -89,16 +89,19 @@ int init_exp_golomb(uint32_t len) uint32_t code_num; uint8_t M; uint32_t info; - g_exp_table = (bit_table*)malloc(len*sizeof(bit_table)); - if(!g_exp_table) + bit_table* exp_table; + exp_table = (bit_table*)malloc(len*sizeof(bit_table)); + if(!exp_table) return 0; for (code_num = 0; code_num < len; code_num++) { M = (uint8_t)floor_log2(code_num + 1); info = code_num + 1 - (uint32_t)pow(2, M); - g_exp_table[code_num].len = M * 2 + 1; - g_exp_table[code_num].value = (1< Date: Tue, 15 Apr 2014 16:08:01 +0200 Subject: [PATCH 4/4] g_sig_last_scan -> const uint32_t* --- src/encoder.c | 23 ++++++++++++++--------- src/encoder.h | 2 +- src/rdo.c | 2 +- src/transform.c | 6 +++--- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/encoder.c b/src/encoder.c index e781ae37..d3d7ec95 100644 --- a/src/encoder.c +++ b/src/encoder.c @@ -44,7 +44,7 @@ double g_lambda_cost[55]; double g_cur_lambda_cost; -uint32_t* g_sig_last_scan[3][5]; +const uint32_t* g_sig_last_scan[3][5]; int8_t g_convert_to_bit[LCU_WIDTH + 1]; int8_t g_bitdepth = 8; @@ -198,12 +198,17 @@ void init_tables(void) c = 2; for (i = 0; i < 5; i++) { - g_sig_last_scan[0][i] = (uint32_t*)malloc(c*c*sizeof(uint32_t)); - g_sig_last_scan[1][i] = (uint32_t*)malloc(c*c*sizeof(uint32_t)); - g_sig_last_scan[2][i] = (uint32_t*)malloc(c*c*sizeof(uint32_t)); + uint32_t *sls0, *sls1, *sls2; + sls0 = (uint32_t*)malloc(c*c*sizeof(uint32_t)); + sls1 = (uint32_t*)malloc(c*c*sizeof(uint32_t)); + sls2 = (uint32_t*)malloc(c*c*sizeof(uint32_t)); - init_sig_last_scan(g_sig_last_scan[0][i], g_sig_last_scan[1][i], - g_sig_last_scan[2][i], c, c); + init_sig_last_scan(sls0, sls1, sls2, c, c); + + g_sig_last_scan[0][i] = sls0; + g_sig_last_scan[1][i] = sls1; + g_sig_last_scan[2][i] = sls2; + c <<= 1; } } @@ -242,9 +247,9 @@ void free_tables(void) { int i; for (i = 0; i < 5; i++) { - free(g_sig_last_scan[0][i]); - free(g_sig_last_scan[1][i]); - free(g_sig_last_scan[2][i]); + FREE_POINTER(g_sig_last_scan[0][i]); + FREE_POINTER(g_sig_last_scan[1][i]); + FREE_POINTER(g_sig_last_scan[2][i]); } } encoder_control *init_encoder_control(config *cfg) diff --git a/src/encoder.h b/src/encoder.h index aca455e7..83ab31a9 100644 --- a/src/encoder.h +++ b/src/encoder.h @@ -161,7 +161,7 @@ static const uint8_t g_min_in_group[10] = { * First index: scan pattern 0 = diagonal, 1 = horizontal, 2 = vertical * Second index: (log2 - 1) size of transform block. 2x2 .. 32x32 */ -extern uint32_t* g_sig_last_scan[3][5]; +extern const uint32_t* g_sig_last_scan[3][5]; /*** * List of indices for 4x4 coefficient groups within 8x8 transform block. diff --git a/src/rdo.c b/src/rdo.c index a0e74453..0dfe81fc 100644 --- a/src/rdo.c +++ b/src/rdo.c @@ -438,7 +438,7 @@ void rdoq(const encoder_control * const encoder, cabac_data *cabac, coefficient uint32_t c2_idx = 0; int32_t base_level; - uint32_t *scan = g_sig_last_scan[ scan_mode ][ log2_block_size - 1 ]; + const uint32_t *scan = g_sig_last_scan[ scan_mode ][ log2_block_size - 1 ]; uint32_t cg_num = width * height >> 4; diff --git a/src/transform.c b/src/transform.c index fefe9ab6..983f8f60 100644 --- a/src/transform.c +++ b/src/transform.c @@ -857,8 +857,8 @@ void itransform2d(int16_t *block,int16_t *coeff, int8_t block_size, int32_t mode void quant(const encoder_control * const encoder, int16_t *coef, int16_t *q_coef, int32_t width, int32_t height, uint32_t *ac_sum, int8_t type, int8_t scan_idx, int8_t block_type ) { - uint32_t log2_block_size = g_convert_to_bit[ width ] + 2; - uint32_t *scan = g_sig_last_scan[ scan_idx ][ log2_block_size - 1 ]; + const uint32_t log2_block_size = g_convert_to_bit[ width ] + 2; + const uint32_t * const scan = g_sig_last_scan[ scan_idx ][ log2_block_size - 1 ]; #if ENABLE_SIGN_HIDING == 1 int32_t delta_u[LCU_WIDTH*LCU_WIDTH>>2]; @@ -1103,7 +1103,7 @@ int scalinglist_parse(encoder_control * const encoder, FILE *fp) for (size_id = 0; size_id < SCALING_LIST_SIZE_NUM; size_id++) { uint32_t list_id; uint32_t size = MIN(MAX_MATRIX_COEF_NUM, (int32_t)g_scaling_list_size[size_id]); - //uint32_t *scan = (size_id == 0) ? g_sig_last_scan[SCAN_DIAG][1] : g_sig_last_scan_32x32; + //const uint32_t * const scan = (size_id == 0) ? g_sig_last_scan[SCAN_DIAG][1] : g_sig_last_scan_32x32; for (list_id = 0; list_id < g_scaling_list_num[size_id]; list_id++) { int found;