2013-09-19 07:35:34 +00:00
|
|
|
#ifndef BITSTREAM_H_
|
|
|
|
#define BITSTREAM_H_
|
2013-09-18 14:29:30 +00:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* \brief Bitstream can be written to one or several bits at a time.
|
|
|
|
*
|
|
|
|
* \author Marko Viitanen ( fador@iki.fi ),
|
|
|
|
* Tampere University of Technology,
|
|
|
|
* Department of Pervasive Computing.
|
|
|
|
* \author Ari Koivula ( ari@koivu.la ),
|
|
|
|
* Tampere University of Technology,
|
|
|
|
* Department of Pervasive Computing.
|
|
|
|
*/
|
2012-05-30 12:37:42 +00:00
|
|
|
|
2013-09-18 09:16:03 +00:00
|
|
|
#include "global.h"
|
|
|
|
|
2012-05-30 12:37:42 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint32_t data[32];
|
|
|
|
uint8_t cur_byte;
|
2013-09-18 09:42:16 +00:00
|
|
|
uint8_t cur_bit;
|
2012-06-04 10:47:12 +00:00
|
|
|
FILE* output;
|
2012-06-05 11:01:47 +00:00
|
|
|
uint8_t* buffer;
|
|
|
|
uint32_t buffer_pos;
|
2012-06-06 10:42:02 +00:00
|
|
|
uint32_t bufferlen;
|
2012-05-30 12:37:42 +00:00
|
|
|
} bitstream;
|
2012-06-05 11:01:47 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint8_t len;
|
|
|
|
uint32_t value;
|
2013-09-18 09:42:16 +00:00
|
|
|
} bit_table;
|
2012-06-05 11:01:47 +00:00
|
|
|
|
2013-09-18 09:42:16 +00:00
|
|
|
extern bit_table *g_exp_table;
|
2012-06-05 12:38:54 +00:00
|
|
|
|
2013-09-18 09:42:16 +00:00
|
|
|
int floor_log2(unsigned int n);
|
2012-05-30 12:37:42 +00:00
|
|
|
|
2012-06-06 10:42:02 +00:00
|
|
|
void bitstream_alloc(bitstream* stream, uint32_t alloc);
|
|
|
|
void bitstream_clear_buffer(bitstream* stream);
|
2012-06-05 11:01:47 +00:00
|
|
|
void bitstream_init(bitstream* stream);
|
|
|
|
void bitstream_put(bitstream* stream, uint32_t data, uint8_t bits);
|
2013-02-05 13:48:06 +00:00
|
|
|
|
|
|
|
/* Use macros to force inlining */
|
2012-06-05 14:45:17 +00:00
|
|
|
#define bitstream_put_ue(stream, data) { bitstream_put(stream,g_exp_table[data].value,g_exp_table[data].len); }
|
2013-03-07 15:42:00 +00:00
|
|
|
#define bitstream_put_se(stream, data) { uint32_t index=(uint32_t)(((data)<=0)?(-(data))<<1:((data)<<1)-1); \
|
2012-06-05 14:45:17 +00:00
|
|
|
bitstream_put(stream,g_exp_table[index].value,g_exp_table[index].len); }
|
2012-06-05 11:01:47 +00:00
|
|
|
|
|
|
|
void bitstream_align(bitstream* stream);
|
2013-02-21 14:45:22 +00:00
|
|
|
void bitstream_align_zero(bitstream* stream);
|
2012-05-30 12:37:42 +00:00
|
|
|
void bitstream_flush(bitstream* stream);
|
2012-06-05 11:01:47 +00:00
|
|
|
void init_exp_golomb(uint32_t len);
|
|
|
|
|
2013-02-05 13:48:06 +00:00
|
|
|
|
|
|
|
/* In debug mode print out some extra info */
|
2013-03-07 15:42:00 +00:00
|
|
|
#ifdef NOTDEFINED//_DEBUG
|
2013-02-05 13:48:06 +00:00
|
|
|
/* Counter to keep up with bits written */
|
2012-06-05 11:01:47 +00:00
|
|
|
static int WRITE_VALUE = 0;
|
2012-06-05 14:45:17 +00:00
|
|
|
#define WRITE_U(stream, data, bits, name) { printf("%8d %-40s u(%d) : %d\n",WRITE_VALUE, name,bits,data); bitstream_put(stream,data,bits); WRITE_VALUE++;}
|
|
|
|
#define WRITE_UE(stream, data, name) { printf("%8d %-40s ue(v): %d\n",WRITE_VALUE, name,data); bitstream_put_ue(stream,data); WRITE_VALUE++;}
|
2012-06-07 14:38:28 +00:00
|
|
|
#define WRITE_SE(stream, data, name) { printf("%8d %-40s se(v): %d\n",WRITE_VALUE, name,data); bitstream_put_se(stream,(data)); WRITE_VALUE++;}
|
2012-06-05 11:01:47 +00:00
|
|
|
#else
|
|
|
|
#define WRITE_U(stream, data, bits, name) { bitstream_put(stream,data,bits); }
|
|
|
|
#define WRITE_UE(stream, data, name) { bitstream_put_ue(stream,data); }
|
|
|
|
#define WRITE_SE(stream, data, name) { bitstream_put_se(stream,data); }
|
|
|
|
#endif
|
|
|
|
|
2012-05-30 12:37:42 +00:00
|
|
|
|
|
|
|
#endif
|