2012-06-04 10:47:12 +00:00
|
|
|
/**
|
|
|
|
* HEVC Encoder
|
|
|
|
* - Marko Viitanen ( fador at iki.fi ), Tampere University of Technology, Department of Computer Systems.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \file cabac.h
|
|
|
|
\brief CABAC
|
|
|
|
\author Marko Viitanen
|
|
|
|
\date 2012-06
|
|
|
|
|
|
|
|
Content-adaptive binary arithmetic coder
|
|
|
|
*/
|
|
|
|
#ifndef __CABAC_H
|
|
|
|
#define __CABAC_H
|
|
|
|
|
|
|
|
extern const uint8_t g_aucNextStateMPS[ 128 ];
|
|
|
|
extern const uint8_t g_aucNextStateLPS[ 128 ];
|
|
|
|
extern const uint32_t g_entropyBits[128];
|
|
|
|
extern uint8_t g_nextState[128][2];
|
|
|
|
|
|
|
|
extern const uint8_t g_aucLPSTable[64][4];
|
|
|
|
extern const uint8_t g_aucRenormTable[32];
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint8_t ucState;
|
|
|
|
uint32_t binsCoded;
|
|
|
|
} cabac_ctx;
|
2012-06-06 13:20:29 +00:00
|
|
|
|
2012-06-07 14:38:28 +00:00
|
|
|
#define CTX_STATE(ctx) (ctx->ucState>>1)
|
|
|
|
#define CTX_MPS(ctx) (ctx->ucState&1)
|
2012-06-04 10:47:12 +00:00
|
|
|
|
|
|
|
void cxt_init(cabac_ctx* ctx,uint32_t qp, uint32_t initValue );
|
|
|
|
void cxt_buildNextStateTable();
|
|
|
|
void ctx_update(cabac_ctx* ctx, int val );
|
2012-06-08 12:26:07 +00:00
|
|
|
//void ctx_update_LPS(cabac_ctx* ctx);
|
|
|
|
//void ctx_update_MPS(cabac_ctx* ctx);
|
|
|
|
#define ctx_update_LPS(ctx) { (ctx)->ucState = g_aucNextStateLPS[ (ctx)->ucState ]; }
|
|
|
|
#define ctx_update_MPS(ctx) { (ctx)->ucState = g_aucNextStateMPS[ (ctx)->ucState ]; }
|
|
|
|
|
2012-06-04 10:47:12 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-06-07 14:38:28 +00:00
|
|
|
cabac_ctx *ctx;
|
2012-06-04 10:47:12 +00:00
|
|
|
uint32_t uiLow;
|
|
|
|
uint32_t uiRange;
|
|
|
|
uint32_t bufferedByte;
|
|
|
|
int32_t numBufferedBytes;
|
|
|
|
int32_t bitsLeft;
|
|
|
|
uint32_t uiBinsCoded;
|
|
|
|
int32_t binCountIncrement;
|
|
|
|
uint64_t fracBits;
|
|
|
|
bitstream* stream;
|
|
|
|
} cabac_data;
|
|
|
|
|
|
|
|
extern cabac_data cabac;
|
|
|
|
|
2012-06-07 14:38:28 +00:00
|
|
|
void cabac_start(cabac_data* data);
|
2012-06-04 10:47:12 +00:00
|
|
|
void cabac_init(cabac_data* data);
|
|
|
|
void cabac_encodeBin(cabac_data* data, uint32_t binValue );
|
|
|
|
void cabac_encodeFlush(cabac_data* data, uint8_t end );
|
|
|
|
void cabac_encodeBinEP(cabac_data* data, uint32_t binValue );
|
|
|
|
void cabac_encodeBinsEP(cabac_data* data, uint32_t binValues, int numBins );
|
|
|
|
void cabac_write(cabac_data* data);
|
|
|
|
void cabac_finish(cabac_data* data);
|
|
|
|
void cabac_flush(cabac_data* data);
|
2012-06-08 12:26:07 +00:00
|
|
|
void cabac_encoderflush(cabac_data* data, uint8_t end);
|
|
|
|
void cabac_encodeBinTrm(cabac_data* data, uint8_t binValue );
|
2012-06-04 10:47:12 +00:00
|
|
|
|
|
|
|
|
2012-06-07 14:38:28 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
#define CABAC_BIN(data, value, name) { uint32_t prev_state = (data)->ctx->ucState;\
|
|
|
|
cabac_encodeBin(data, value); \
|
2012-06-12 14:35:45 +00:00
|
|
|
printf("%s = %d prev_state=%d state=%d\n",name,value,prev_state, (data)->ctx->ucState);}
|
|
|
|
#define CABAC_BINS_EP(data, value,bins, name) { uint32_t prev_state = (data)->ctx->ucState;\
|
|
|
|
cabac_encodeBinsEP(data, value,bins); \
|
|
|
|
printf("%s = %d prev_state=%d state=%d\n",name,value,prev_state, (data)->ctx->ucState);}
|
2012-06-07 14:38:28 +00:00
|
|
|
#else
|
|
|
|
#define CABAC_BIN(data, value, name) cabac_encodeBin(data, value);
|
2012-06-12 14:35:45 +00:00
|
|
|
#define CABAC_BINS_EP(data, value,bins, name) cabac_encodeBinsEP(data, value,bins);
|
2012-06-07 14:38:28 +00:00
|
|
|
#endif
|
|
|
|
|
2012-06-04 10:47:12 +00:00
|
|
|
#endif
|