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);
69 void ff_build_rac_states(
RangeCoder *c,
int factor,
int max_p);
71 static inline void renorm_encoder(
RangeCoder *c)
74 while (c->range < 0x100) {
75 if (c->outstanding_byte < 0) {
76 c->outstanding_byte = c->low >> 8;
77 }
else if (c->low <= 0xFF00) {
78 *c->bytestream++ = c->outstanding_byte;
79 for (; c->outstanding_count; c->outstanding_count--)
80 *c->bytestream++ = 0xFF;
81 c->outstanding_byte = c->low >> 8;
82 }
else if (c->low >= 0x10000) {
83 *c->bytestream++ = c->outstanding_byte + 1;
84 for (; c->outstanding_count; c->outstanding_count--)
85 *c->bytestream++ = 0x00;
86 c->outstanding_byte = (c->low >> 8) & 0xFF;
88 c->outstanding_count++;
91 c->low = (c->low & 0xFF) << 8;
98 int x = c->bytestream - c->bytestream_start + c->outstanding_count;
99 if (c->outstanding_byte >= 0)
101 return 8 * x - av_log2(c->range);
104 static inline void put_rac(
RangeCoder *c, uint8_t *
const state,
int bit)
106 int range1 = (c->range * (*state)) >> 8;
113 *state = c->zero_state[*state];
115 c->low += c->range - range1;
117 *state = c->one_state[*state];
125 if (c->range < 0x100) {
128 if (c->bytestream < c->bytestream_end) {
129 c->low += c->bytestream[0];
136 static inline int get_rac(
RangeCoder *c, uint8_t *
const state)
138 int range1 = (c->range * (*state)) >> 8;
141 if (c->low < c->range) {
142 *state = c->zero_state[*state];
147 *state = c->one_state[*state];
int ff_rac_terminate(RangeCoder *c, int version)
Terminates the range coder.
Definition: rangecoder.c:109
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:64
int ff_rac_check_termination(RangeCoder *c, int version)
Check if at the current position there is a valid looking termination.
Definition: rangecoder.c:125
simple assert() macros that are a bit more flexible than ISO C assert().
common internal and external API header