Make g_exp_table statically allocated.

Removes the need to free the table.
This commit is contained in:
Arttu Ylä-Outinen 2015-06-03 11:18:45 +03:00
parent b130ecc9bb
commit 4a7b86a43b
5 changed files with 16 additions and 42 deletions

View file

@ -44,6 +44,8 @@ const uint32_t bit_set_mask[] =
0x10000000,0x20000000,0x40000000,0x80000000 0x10000000,0x20000000,0x40000000,0x80000000
}; };
bit_table_t g_exp_table[EXP_GOLOMB_TABLE_SIZE];
//#define VERBOSE //#define VERBOSE
@ -59,8 +61,6 @@ void printf_bitstream(char *msg, ...)
} }
#endif #endif
const bit_table_t *g_exp_table;
static int floor_log2(unsigned int n) { static int floor_log2(unsigned int n) {
assert(n != 0); assert(n != 0);
@ -74,40 +74,26 @@ static int floor_log2(unsigned int n) {
} }
/** /**
* \brief Initialize the Exp Golomb code table with desired number of values * \brief Initialize the Exp Golomb code table.
* \param len table length to init
* \return 1 on success, 0 on failure
* *
* Allocates g_exp_table with len*sizeof(bit_table) and fills it with exponential golomb codes * Fills g_exp_table with exponential golomb codes.
*/ */
int init_exp_golomb(const uint32_t len) void init_exp_golomb()
{ {
static int exp_table_initialized = 0;
if (exp_table_initialized) return;
uint32_t code_num; uint32_t code_num;
uint8_t M; uint8_t M;
uint32_t info; uint32_t info;
bit_table_t *exp_table; for (code_num = 0; code_num < EXP_GOLOMB_TABLE_SIZE; code_num++) {
exp_table = (bit_table_t*)malloc(len*sizeof(bit_table_t));
if(!exp_table)
return 0;
for (code_num = 0; code_num < len; code_num++) {
M = (uint8_t)floor_log2(code_num + 1); M = (uint8_t)floor_log2(code_num + 1);
info = code_num + 1 - (uint32_t)pow(2, M); info = code_num + 1 - (uint32_t)pow(2, M);
exp_table[code_num].len = M * 2 + 1; g_exp_table[code_num].len = M * 2 + 1;
exp_table[code_num].value = (1<<M) | info; g_exp_table[code_num].value = (1<<M) | info;
} }
g_exp_table = exp_table; exp_table_initialized = 1;
return 1;
}
/**
* \brief Free Exp Golomb tables
*/
void free_exp_golomb()
{
FREE_POINTER(g_exp_table);
} }
/** /**

View file

@ -66,7 +66,7 @@ typedef struct
uint32_t value; uint32_t value;
} bit_table_t; } bit_table_t;
extern const bit_table_t *g_exp_table; extern bit_table_t g_exp_table[EXP_GOLOMB_TABLE_SIZE];
int bitstream_init(bitstream_t * stream, bitstream_type type); int bitstream_init(bitstream_t * stream, bitstream_type type);
int bitstream_finalize(bitstream_t * stream); int bitstream_finalize(bitstream_t * stream);
@ -84,8 +84,7 @@ int bitstream_clear(bitstream_t *stream);
void bitstream_align(bitstream_t *stream); void bitstream_align(bitstream_t *stream);
void bitstream_align_zero(bitstream_t *stream); void bitstream_align_zero(bitstream_t *stream);
int init_exp_golomb(uint32_t len); void init_exp_golomb();
void free_exp_golomb();
/* In debug mode print out some extra info */ /* In debug mode print out some extra info */

View file

@ -133,12 +133,6 @@ int main(int argc, char *argv[])
} }
} }
//Allocate and init exp golomb table
if (!init_exp_golomb(4096*8)) {
fprintf(stderr, "Failed to allocate the exp golomb code table, shutting down!\n");
goto exit_failure;
}
const kvz_api *api = kvz_api_get(8); const kvz_api *api = kvz_api_get(8);
kvz_encoder* enc = api->encoder_open(cfg); kvz_encoder* enc = api->encoder_open(cfg);
@ -303,8 +297,6 @@ int main(int argc, char *argv[])
// Deallocating // Deallocating
config_destroy(cfg); config_destroy(cfg);
free_exp_golomb();
CHECKPOINTS_FINALIZE(); CHECKPOINTS_FINALIZE();
return EXIT_SUCCESS; return EXIT_SUCCESS;

View file

@ -196,6 +196,7 @@ typedef int16_t coeff_t;
#define MAX_TR_DYNAMIC_RANGE 15 #define MAX_TR_DYNAMIC_RANGE 15
#define EXP_GOLOMB_TABLE_SIZE (4096*8)
//DEBUG BITMASK //DEBUG BITMASK
#define _DEBUG_PERF_FRAME_LEVEL 0x0001 #define _DEBUG_PERF_FRAME_LEVEL 0x0001

View file

@ -54,11 +54,7 @@ static kvz_encoder * kvazaar_open(config_t *cfg)
goto kvazaar_open_failure; goto kvazaar_open_failure;
} }
//Allocate and init exp golomb table init_exp_golomb();
if (!init_exp_golomb(4096 * 8)) {
fprintf(stderr, "Failed to allocate the exp golomb code table, shutting down!\n");
goto kvazaar_open_failure;
}
encoder = MALLOC(kvz_encoder, 1); encoder = MALLOC(kvz_encoder, 1);
if (!encoder) { if (!encoder) {