Disable bit debug code when VERBOSE is not defined and count bits when combining the intra cus

This commit is contained in:
Joose Sainio 2021-12-07 09:11:47 +02:00
parent 9ed8d0a7d9
commit d2299adb1c
4 changed files with 36 additions and 4 deletions

View file

@ -139,7 +139,11 @@ extern double bits_written;
#define CTX_UPDATE_LPS(ctx) { (ctx)->uc_state = kvz_g_auc_next_state_lps[ (ctx)->uc_state ]; }
#define CTX_UPDATE_MPS(ctx) { (ctx)->uc_state = kvz_g_auc_next_state_mps[ (ctx)->uc_state ]; }
#define FILE_BITS(bits, x, y, depth, name) fprintf(bit_cost_file, "%s\t%d\t%d\t%d\t%f\n", (name), (x), (y), (depth), (bits))
#ifdef VERBOSE
#define FILE_BITS(bits, x, y, depth, name) fprintf(bit_cost_file, "%s\t%d\t%d\t%d\t%f\n", (name), (x), (y), (depth), (bits))
#else
#define FILE_BITS(bits, x, y, depth, name) {}
#endif
#ifdef VERBOSE
#define CABAC_BIN(data, value, name) { \

View file

@ -923,10 +923,13 @@ end:
if (is_last_cu_in_qg(state, x, y, depth)) {
state->last_qp = cur_cu->qp;
}
#ifdef VERBOSE
if((x % 64 != 0 && y % 64 != 0) || 1) {
fprintf(stderr, "%f\t%d\t%d\t%d\n", bits_written, x, y, depth);
bits_written = 0;
}
#endif
}

View file

@ -110,7 +110,7 @@
typedef int16_t coeff_t;
#define VERBOSE 1
// #define VERBOSE 1
/* CONFIG VARIABLES */

View file

@ -854,12 +854,31 @@ static double search_cu(encoder_state_t * const state, int x, int y, int depth,
&& x + cu_width <= frame->width && y + cu_width <= frame->height
&& state->encoder_control->cfg.combine_intra_cus)
{
cu_info_t *cu_d1 = LCU_GET_CU_AT_PX(&work_tree[depth + 1], x_local, y_local);
// If the best CU in depth+1 is intra and the biggest it can be, try it.
if (cu_d1->type == CU_INTRA && cu_d1->depth == depth + 1) {
cabac_data_t temp_cabac;
memcpy(&temp_cabac, &state->search_cabac, sizeof(temp_cabac));
memcpy(&state->search_cabac, &pre_search_cabac, sizeof(pre_search_cabac));
cost = 0;
double bits = 0;
if (depth < MAX_DEPTH) {
uint8_t split_model = get_ctx_cu_split_model(lcu, x, y, depth);
cabac_ctx_t* ctx = &(state->search_cabac.ctx.split_flag_model[split_model]);
state->search_cabac.cur_ctx = ctx;
bits += CTX_ENTROPY_FBITS(ctx, 0);
CABAC_BIN(&state->search_cabac, 0, "no_split_search");
}
else if (depth == MAX_DEPTH && cur_cu->type == CU_INTRA) {
// Add cost of intra part_size.
const cabac_ctx_t* ctx = &(state->search_cabac.ctx.part_size_model[0]);
bits += CTX_ENTROPY_FBITS(ctx, 1); // NxN
state->search_cabac.cur_ctx = ctx;
FILE_BITS(CTX_ENTROPY_FBITS(ctx, 1), x, y, depth, "split");
CABAC_BIN(&state->search_cabac, 1, "split_search");
}
cur_cu->intra = cu_d1->intra;
cur_cu->type = CU_INTRA;
@ -876,6 +895,9 @@ static double search_cu(encoder_state_t * const state, int x, int y, int depth,
cur_cu->intra.mode, mode_chroma,
NULL, lcu);
double mode_bits = calc_mode_bits(state, lcu, cur_cu, x, y);
cost += mode_bits * state->lambda;
cost += kvz_cu_rd_cost_luma(state, x_local, y_local, depth, cur_cu, lcu, &bits);
if (has_chroma) {
cost += kvz_cu_rd_cost_chroma(state, x_local, y_local, depth, cur_cu, lcu, &bits);
@ -888,8 +910,9 @@ static double search_cu(encoder_state_t * const state, int x, int y, int depth,
cost += CTX_ENTROPY_FBITS(ctx, 0) * state->lambda;
// Add the cost of coding intra mode only once.
double mode_bits = calc_mode_bits(state, lcu, cur_cu, x, y);
cost += mode_bits * state->lambda;
memcpy(&post_seach_cabac, &state->search_cabac, sizeof(post_seach_cabac));
memcpy(&state->search_cabac, &temp_cabac, sizeof(temp_cabac));
}
}
@ -1058,7 +1081,9 @@ static void copy_lcu_to_cu_data(const encoder_state_t * const state, int x_px, i
*/
void kvz_search_lcu(encoder_state_t * const state, const int x, const int y, const yuv_t * const hor_buf, const yuv_t * const ver_buf)
{
#ifdef VERBOSE
if (bit_cost_file == NULL) bit_cost_file = fopen("bits_file.txt", "w");
#endif
memcpy(&state->search_cabac, &state->cabac, sizeof(cabac_data_t));
state->search_cabac.only_count = 1;
assert(x % LCU_WIDTH == 0);