[FFmpeg-cvslog] avcodec/rangecoder: factorize termination version code
Michael Niedermayer
git at videolan.org
Mon Dec 31 19:06:22 EET 2018
ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Wed Dec 19 02:40:18 2018 +0100| [1be9a28f8e8cd2553f978670901174a8808b9a1a] | committer: Michael Niedermayer
avcodec/rangecoder: factorize termination version code
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1be9a28f8e8cd2553f978670901174a8808b9a1a
---
libavcodec/ffv1enc.c | 10 +++-------
libavcodec/rangecoder.c | 4 +++-
libavcodec/rangecoder.h | 2 +-
libavcodec/snowenc.c | 2 +-
libavcodec/sonic.c | 2 +-
libavcodec/tests/rangecoder.c | 2 +-
6 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index f5eb0feb4e..796d81f7c6 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -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;
diff --git a/libavcodec/rangecoder.c b/libavcodec/rangecoder.c
index 0d53bef076..fa7d5526d1 100644
--- a/libavcodec/rangecoder.c
+++ b/libavcodec/rangecoder.c
@@ -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);
diff --git a/libavcodec/rangecoder.h b/libavcodec/rangecoder.h
index 44af88b8f5..e5c7a3cc71 100644
--- a/libavcodec/rangecoder.h
+++ b/libavcodec/rangecoder.h
@@ -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)
diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
index 61a658fa44..df1729a083 100644
--- a/libavcodec/snowenc.c
+++ b/libavcodec/snowenc.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;
diff --git a/libavcodec/sonic.c b/libavcodec/sonic.c
index 2e3ca79fdd..34d2952e69 100644
--- a/libavcodec/sonic.c
+++ b/libavcodec/sonic.c
@@ -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;
diff --git a/libavcodec/tests/rangecoder.c b/libavcodec/tests/rangecoder.c
index 2da5c0ce33..76a13e7091 100644
--- a/libavcodec/tests/rangecoder.c
+++ b/libavcodec/tests/rangecoder.c
@@ -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);
More information about the ffmpeg-cvslog
mailing list