int main(void) { RangeCoder c; int i; uint8_t state[10]; AVLFG prng; av_lfg_init(&prng, 1); ff_init_range_encoder(&c, b, SIZE); ff_build_rac_states(&c, (1LL << 32) / 20, 128 + 64 + 32 + 16); memset(state, 128, sizeof(state)); for (i = 0; i < SIZE; i++) r[i] = av_lfg_get(&prng) % 7; for (i = 0; i < SIZE; i++) put_rac(&c, state, r[i] & 1); ff_rac_terminate(&c); ff_init_range_decoder(&c, b, SIZE); memset(state, 128, sizeof(state)); for (i = 0; i < SIZE; i++) if ((r[i] & 1) != get_rac(&c, state)) { av_log(NULL, AV_LOG_ERROR, "rac failure at %d\n", i); return 1; } return 0; }
void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size){ /* cast to avoid compiler warning */ ff_init_range_encoder(c, (uint8_t *) buf, buf_size); c->low =(*c->bytestream++)<<8; c->low+= *c->bytestream++; }
av_cold void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size) { /* cast to avoid compiler warning */ ff_init_range_encoder(c, (uint8_t *)buf, buf_size); c->low = bytestream_get_be16((const uint8_t **)&c->bytestream); }
av_cold void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size) { /* cast to avoid compiler warning */ ff_init_range_encoder(c, (uint8_t *)buf, buf_size); c->low = AV_RB16(c->bytestream); c->bytestream += 2; }
int main(void){ RangeCoder c; uint8_t b[9*SIZE]; uint8_t r[9*SIZE]; int i; uint8_t state[10]= {0}; AVLFG prng; av_lfg_init(&prng, 1); ff_init_range_encoder(&c, b, SIZE); ff_build_rac_states(&c, 0.05*(1LL<<32), 128+64+32+16); memset(state, 128, sizeof(state)); for(i=0; i<SIZE; i++){ r[i] = av_lfg_get(&prng) % 7; } for(i=0; i<SIZE; i++){ START_TIMER put_rac(&c, state, r[i]&1); STOP_TIMER("put_rac") } ff_rac_terminate(&c); ff_init_range_decoder(&c, b, SIZE); memset(state, 128, sizeof(state)); for(i=0; i<SIZE; i++){ START_TIMER if( (r[i]&1) != get_rac(&c, state) ) av_log(NULL, AV_LOG_DEBUG, "rac failure at %d\n", i); STOP_TIMER("get_rac") } return 0; }
void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size){ ff_init_range_encoder(c, buf, buf_size); c->low =(*c->bytestream++)<<8; c->low+= *c->bytestream++; }