lavc/ffv1: move ac_byte_count to per-slice context

release/7.1
Anton Khirnov 6 months ago
parent e7d0f44138
commit 96e8af6c4d
  1. 2
      libavcodec/ffv1.h
  2. 6
      libavcodec/ffv1dec.c
  3. 9
      libavcodec/ffv1enc.c

@ -85,6 +85,7 @@ typedef struct FFV1SliceContext {
PutBitContext pb;
RangeCoder c;
int ac_byte_count; ///< number of bytes used for AC coding
uint64_t rc_stat[256][2];
uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];
} FFV1SliceContext;
@ -109,7 +110,6 @@ typedef struct FFV1Context {
const AVFrame *cur_enc_frame;
int plane_count;
int ac; ///< 1=range coder <-> 0=golomb rice
int ac_byte_count; ///< number of bytes used for AC coding
int16_t quant_tables[MAX_QUANT_TABLES][MAX_CONTEXT_INPUTS][256];
int context_count[MAX_QUANT_TABLES];
uint8_t state_transition[256];

@ -323,10 +323,10 @@ static int decode_slice(AVCodecContext *c, void *arg)
if (f->ac == AC_GOLOMB_RICE) {
if (f->version == 3 && f->micro_version > 1 || f->version > 3)
get_rac(&sc->c, (uint8_t[]) { 129 });
fs->ac_byte_count = f->version > 2 || (!x && !y) ? sc->c.bytestream - sc->c.bytestream_start - 1 : 0;
sc->ac_byte_count = f->version > 2 || (!x && !y) ? sc->c.bytestream - sc->c.bytestream_start - 1 : 0;
init_get_bits(&gb,
sc->c.bytestream_start + fs->ac_byte_count,
(sc->c.bytestream_end - sc->c.bytestream_start - fs->ac_byte_count) * 8);
sc->c.bytestream_start + sc->ac_byte_count,
(sc->c.bytestream_end - sc->c.bytestream_start - sc->ac_byte_count) * 8);
}
av_assert1(width && height);

@ -1060,10 +1060,10 @@ retry:
encode_slice_header(f, fs, sc);
}
if (f->ac == AC_GOLOMB_RICE) {
fs->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate(&sc->c, f->version > 2) : 0;
sc->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate(&sc->c, f->version > 2) : 0;
init_put_bits(&sc->pb,
sc->c.bytestream_start + fs->ac_byte_count,
sc->c.bytestream_end - sc->c.bytestream_start - fs->ac_byte_count);
sc->c.bytestream_start + sc->ac_byte_count,
sc->c.bytestream_end - sc->c.bytestream_start - sc->ac_byte_count);
}
if (f->colorspace == 0 && c->pix_fmt != AV_PIX_FMT_YA8) {
@ -1212,7 +1212,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
buf_p = pkt->data;
for (i = 0; i < f->slice_count; i++) {
FFV1Context *fs = f->slice_context[i];
FFV1SliceContext *sc = &f->slices[i];
int bytes;
@ -1220,7 +1219,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
bytes = ff_rac_terminate(&sc->c, 1);
} else {
flush_put_bits(&sc->pb); // FIXME: nicer padding
bytes = fs->ac_byte_count + put_bytes_output(&sc->pb);
bytes = sc->ac_byte_count + put_bytes_output(&sc->pb);
}
if (i > 0 || f->version > 2) {
av_assert0(bytes < pkt->size / f->slice_count);

Loading…
Cancel
Save