Use kvz_cabac_bins_verbose flag to control cabac debug printing

This commit is contained in:
Marko Viitanen 2018-09-26 12:01:23 +03:00
parent 7c37f456f9
commit 63760ca0cf
4 changed files with 15 additions and 8 deletions

View file

@ -83,7 +83,7 @@ void kvz_bitstream_align(bitstream_t *stream);
void kvz_bitstream_align_zero(bitstream_t *stream);
/* In debug mode print out some extra info */
#ifdef KVZ_DEBUG_PRINT_CABAC
#ifdef VERBOSE
/* Counter to keep up with bits written */
#define WRITE_U(stream, data, bits, name) { printf("%-40s u(%d) : %d\n", name,bits,data); kvz_bitstream_put(stream,data,bits);}
#define WRITE_UE(stream, data, name) { printf("%-40s ue(v): %d\n", name,data); kvz_bitstream_put_ue(stream,data);}

View file

@ -25,8 +25,9 @@
#include "extras/crypto.h"
#include "kvazaar.h"
#ifdef VERBOSE
#ifdef KVZ_DEBUG_PRINT_CABAC
uint32_t kvz_cabac_bins_count = 0;
bool kvz_cabac_bins_verbose = true;
#endif
const uint8_t kvz_g_auc_next_state_mps[128] =
@ -570,5 +571,5 @@ void kvz_cabac_write_ep_ex_golomb(encoder_state_t * const state,
bins = ( (bins >> (num_bins >>1) ) << (num_bins >>1) ) | state->crypto_prev_pos;
}
}
kvz_cabac_encode_bins_ep(data, bins, num_bins);
CABAC_BINS_EP(data, bins, num_bins, "ep_ex_golomb");
}

View file

@ -123,26 +123,27 @@ void kvz_cabac_write_unary_max_symbol_ep(cabac_data_t *data, unsigned int symbol
#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 ]; }
#ifdef VERBOSE
#ifdef KVZ_DEBUG_PRINT_CABAC
extern uint32_t kvz_cabac_bins_count;
extern bool kvz_cabac_bins_verbose;
#define CABAC_BIN(data, value, name) { \
uint32_t prev_state = (data)->cur_ctx->uc_state; \
printf("%d %d [%d:%d] %s = %u, range = %u LPS = %u state = %u -> ", \
if(kvz_cabac_bins_verbose) printf("%d %d [%d:%d] %s = %u, range = %u LPS = %u state = %u -> ", \
kvz_cabac_bins_count++, (data)->range, (data)->range-kvz_g_auc_lpst_table[CTX_STATE(data->cur_ctx)][((data)->range >> 6) & 3], kvz_g_auc_lpst_table[CTX_STATE(data->cur_ctx)][((data)->range >> 6) & 3], (name), (uint32_t)(value), (data)->range, kvz_g_auc_lpst_table[CTX_STATE(data->cur_ctx)][((data)->range >> 6) & 3], prev_state); \
kvz_cabac_encode_bin((data), (value)); \
printf("%u\n", (data)->cur_ctx->uc_state); }
if(kvz_cabac_bins_verbose) printf("%u\n", (data)->cur_ctx->uc_state); }
#define CABAC_BINS_EP(data, value, bins, name) { \
uint32_t prev_state = (data)->cur_ctx->uc_state; \
kvz_cabac_encode_bins_ep((data), (value), (bins)); \
printf("%d %s = %u(%u bins), state = %u -> %u\n", \
if(kvz_cabac_bins_verbose) printf("%d %s = %u(%u bins), state = %u -> %u\n", \
kvz_cabac_bins_count, (name), (uint32_t)(value), (bins), prev_state, (data)->cur_ctx->uc_state); kvz_cabac_bins_count+=bins;}
#define CABAC_BIN_EP(data, value, name) { \
uint32_t prev_state = (data)->cur_ctx->uc_state; \
kvz_cabac_encode_bin_ep((data), (value)); \
printf("%d %s = %u, state = %u -> %u\n", \
if(kvz_cabac_bins_verbose) printf("%d %s = %u, state = %u -> %u\n", \
kvz_cabac_bins_count++, (name), (uint32_t)(value), prev_state, (data)->cur_ctx->uc_state); }
#else
#define CABAC_BIN(data, value, name) \

View file

@ -1261,6 +1261,11 @@ static void _encode_one_frame_add_bitstream_deps(const encoder_state_t * const s
void kvz_encode_one_frame(encoder_state_t * const state, kvz_picture* frame)
{
#if KVZ_DEBUG_PRINT_CABAC == 1
kvz_cabac_bins_count = 0;
if (state->frame->num == 1) kvz_cabac_bins_verbose = true;
else kvz_cabac_bins_verbose = false;
#endif
encoder_state_init_new_frame(state, frame);
encoder_state_encode(state);