X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fcabac.c;h=a718d51ddbbf0861a4c7643867c05f143ab1b16d;hb=bf29794022db597f526a8575648244a7c6ee15ed;hp=1a877dd2b5c1e0dd7500a4e6a66056c217b70d4e;hpb=1a9ffc59d27cae059026192496027794c9273ab0;p=ffmpeg diff --git a/libavcodec/cabac.c b/libavcodec/cabac.c index 1a877dd2b5c..a718d51ddbb 100644 --- a/libavcodec/cabac.c +++ b/libavcodec/cabac.c @@ -200,150 +200,3 @@ int ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size){ return AVERROR_INVALIDDATA; return 0; } - -#ifdef TEST -#define SIZE 10240 - -#include "libavutil/lfg.h" -#include "avcodec.h" - -static inline void put_cabac_bit(CABACContext *c, int b){ - put_bits(&c->pb, 1, b); - for(;c->outstanding_count; c->outstanding_count--){ - put_bits(&c->pb, 1, 1-b); - } -} - -static inline void renorm_cabac_encoder(CABACContext *c){ - while(c->range < 0x100){ - //FIXME optimize - if(c->low<0x100){ - put_cabac_bit(c, 0); - }else if(c->low<0x200){ - c->outstanding_count++; - c->low -= 0x100; - }else{ - put_cabac_bit(c, 1); - c->low -= 0x200; - } - - c->range+= c->range; - c->low += c->low; - } -} - -static void put_cabac(CABACContext *c, uint8_t * const state, int bit){ - int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + *state]; - - if(bit == ((*state)&1)){ - c->range -= RangeLPS; - *state = ff_h264_mlps_state[128 + *state]; - }else{ - c->low += c->range - RangeLPS; - c->range = RangeLPS; - *state= ff_h264_mlps_state[127 - *state]; - } - - renorm_cabac_encoder(c); -} - -/** - * @param bit 0 -> write zero bit, !=0 write one bit - */ -static void put_cabac_bypass(CABACContext *c, int bit){ - c->low += c->low; - - if(bit){ - c->low += c->range; - } -//FIXME optimize - if(c->low<0x200){ - put_cabac_bit(c, 0); - }else if(c->low<0x400){ - c->outstanding_count++; - c->low -= 0x200; - }else{ - put_cabac_bit(c, 1); - c->low -= 0x400; - } -} - -/** - * - * @return the number of bytes written - */ -static int put_cabac_terminate(CABACContext *c, int bit){ - c->range -= 2; - - if(!bit){ - renorm_cabac_encoder(c); - }else{ - c->low += c->range; - c->range= 2; - - renorm_cabac_encoder(c); - - av_assert0(c->low <= 0x1FF); - put_cabac_bit(c, c->low>>9); - put_bits(&c->pb, 2, ((c->low>>7)&3)|1); - - flush_put_bits(&c->pb); //FIXME FIXME FIXME XXX wrong - } - - return (put_bits_count(&c->pb)+7)>>3; -} - -int main(void){ - CABACContext c; - uint8_t b[9*SIZE]; - uint8_t r[9*SIZE]; - int i, ret = 0; - uint8_t state[10]= {0}; - AVLFG prng; - - av_lfg_init(&prng, 1); - ff_init_cabac_encoder(&c, b, SIZE); - - for(i=0; i>8)&1; - } - - for(i=0; i