Commit 1be9a28f authored by Michael Niedermayer's avatar Michael Niedermayer

avcodec/rangecoder: factorize termination version code

Signed-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent 41c1643d
......@@ -449,7 +449,7 @@ static int write_extradata(FFV1Context *f)
put_symbol(c, state, f->intra = (f->avctx->gop_size < 2), 0);
}
f->avctx->extradata_size = ff_rac_terminate(c);
f->avctx->extradata_size = ff_rac_terminate(c, 0);
v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, f->avctx->extradata, f->avctx->extradata_size);
AV_WL32(f->avctx->extradata + f->avctx->extradata_size, v);
f->avctx->extradata_size += 4;
......@@ -1065,9 +1065,7 @@ retry:
encode_slice_header(f, fs);
}
if (fs->ac == AC_GOLOMB_RICE) {
if (f->version > 2)
put_rac(&fs->c, (uint8_t[]) { 129 }, 0);
fs->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate(&fs->c) : 0;
fs->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate(&fs->c, f->version > 2) : 0;
init_put_bits(&fs->pb,
fs->c.bytestream_start + fs->ac_byte_count,
fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count);
......@@ -1232,9 +1230,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
int bytes;
if (fs->ac != AC_GOLOMB_RICE) {
uint8_t state = 129;
put_rac(&fs->c, &state, 0);
bytes = ff_rac_terminate(&fs->c);
bytes = ff_rac_terminate(&fs->c, 1);
} else {
flush_put_bits(&fs->pb); // FIXME: nicer padding
bytes = fs->ac_byte_count + (put_bits_count(&fs->pb) + 7) / 8;
......
......@@ -106,8 +106,10 @@ void ff_build_rac_states(RangeCoder *c, int factor, int max_p)
}
/* Return the number of bytes written. */
int ff_rac_terminate(RangeCoder *c)
int ff_rac_terminate(RangeCoder *c, int version)
{
if (version == 1)
put_rac(c, (uint8_t[]) { 129 }, 0);
c->range = 0xFF;
c->low += 0xFF;
renorm_encoder(c);
......
......@@ -48,7 +48,7 @@ typedef struct RangeCoder {
void ff_init_range_encoder(RangeCoder *c, uint8_t *buf, int buf_size);
void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size);
int ff_rac_terminate(RangeCoder *c);
int ff_rac_terminate(RangeCoder *c, int version);
void ff_build_rac_states(RangeCoder *c, int factor, int max_p);
static inline void renorm_encoder(RangeCoder *c)
......
......@@ -1899,7 +1899,7 @@ FF_DISABLE_DEPRECATION_WARNINGS
FF_ENABLE_DEPRECATION_WARNINGS
#endif
pkt->size = ff_rac_terminate(c);
pkt->size = ff_rac_terminate(c, 0);
if (s->current_picture->key_frame)
pkt->flags |= AV_PKT_FLAG_KEY;
*got_packet = 1;
......
......@@ -842,7 +842,7 @@ static int sonic_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
// av_log(avctx, AV_LOG_DEBUG, "used bytes: %d\n", (put_bits_count(&pb)+7)/8);
avpkt->size = ff_rac_terminate(&c);
avpkt->size = ff_rac_terminate(&c, 0);
*got_packet_ptr = 1;
return 0;
......
......@@ -48,7 +48,7 @@ int main(void)
for (i = 0; i < SIZE; i++)
put_rac(&c, state, r[i] & 1);
ff_rac_terminate(&c);
ff_rac_terminate(&c, 0);
ff_init_range_decoder(&c, b, SIZE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment