lavc/ffv1: move ac_byte_count to per-slice context

This commit is contained in:
Anton Khirnov 2024-07-10 17:20:07 +02:00
parent e7d0f44138
commit 96e8af6c4d
3 changed files with 8 additions and 9 deletions

View File

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

View File

@ -323,10 +323,10 @@ static int decode_slice(AVCodecContext *c, void *arg)
if (f->ac == AC_GOLOMB_RICE) { if (f->ac == AC_GOLOMB_RICE) {
if (f->version == 3 && f->micro_version > 1 || f->version > 3) if (f->version == 3 && f->micro_version > 1 || f->version > 3)
get_rac(&sc->c, (uint8_t[]) { 129 }); 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, init_get_bits(&gb,
sc->c.bytestream_start + fs->ac_byte_count, sc->c.bytestream_start + sc->ac_byte_count,
(sc->c.bytestream_end - sc->c.bytestream_start - fs->ac_byte_count) * 8); (sc->c.bytestream_end - sc->c.bytestream_start - sc->ac_byte_count) * 8);
} }
av_assert1(width && height); av_assert1(width && height);

View File

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