27 #ifndef AVCODEC_RANGECODER_H 28 #define AVCODEC_RANGECODER_H 38 int outstanding_count;
40 uint8_t zero_state[256];
41 uint8_t one_state[256];
42 uint8_t *bytestream_start;
44 uint8_t *bytestream_end;
46 #define MAX_OVERREAD 2 49 void ff_init_range_encoder(
RangeCoder *c, uint8_t *buf,
int buf_size);
50 void ff_init_range_decoder(
RangeCoder *c,
const uint8_t *buf,
int buf_size);
52 void ff_build_rac_states(
RangeCoder *c,
int factor,
int max_p);
54 static inline void renorm_encoder(
RangeCoder *c)
57 while (c->range < 0x100) {
58 if (c->outstanding_byte < 0) {
59 c->outstanding_byte = c->low >> 8;
60 }
else if (c->low <= 0xFF00) {
61 *c->bytestream++ = c->outstanding_byte;
62 for (; c->outstanding_count; c->outstanding_count--)
63 *c->bytestream++ = 0xFF;
64 c->outstanding_byte = c->low >> 8;
65 }
else if (c->low >= 0x10000) {
66 *c->bytestream++ = c->outstanding_byte + 1;
67 for (; c->outstanding_count; c->outstanding_count--)
68 *c->bytestream++ = 0x00;
69 c->outstanding_byte = (c->low >> 8) & 0xFF;
71 c->outstanding_count++;
74 c->low = (c->low & 0xFF) << 8;
81 int x = c->bytestream - c->bytestream_start + c->outstanding_count;
82 if (c->outstanding_byte >= 0)
84 return 8 * x - av_log2(c->range);
87 static inline void put_rac(
RangeCoder *c, uint8_t *
const state,
int bit)
89 int range1 = (c->range * (*state)) >> 8;
96 *state = c->zero_state[*state];
98 c->low += c->range - range1;
100 *state = c->one_state[*state];
108 if (c->range < 0x100) {
111 if (c->bytestream < c->bytestream_end) {
112 c->low += c->bytestream[0];
119 static inline int get_rac(
RangeCoder *c, uint8_t *
const state)
121 int range1 = (c->range * (*state)) >> 8;
124 if (c->low < c->range) {
125 *state = c->zero_state[*state];
130 *state = c->one_state[*state];
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:64
simple assert() macros that are a bit more flexible than ISO C assert().
common internal and external API header