Skip to content

Commit

Permalink
avcodec/ffv1: simplify version checks with combined_version
Browse files Browse the repository at this point in the history
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
  • Loading branch information
michaelni committed Jan 21, 2025
1 parent c0769e9 commit 0c237d6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion libavcodec/ffv1.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ int ff_slice_coord(const FFV1Context *f, int width, int sx, int num_h_slices, in
int mpw = 1<<chroma_shift;
int awidth = FFALIGN(width, mpw);

if (f->version < 4 || f->version == 4 && f->micro_version < 3)
if (f->combined_version <= 0x40002)
return width * sx / num_h_slices;

sx = (2LL * awidth * sx + num_h_slices * mpw) / (2 * num_h_slices * mpw) * mpw;
Expand Down
1 change: 1 addition & 0 deletions libavcodec/ffv1.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ typedef struct FFV1Context {
uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];
int version;
int micro_version;
int combined_version;
int width, height;
int chroma_planes;
int chroma_h_shift, chroma_v_shift;
Expand Down
9 changes: 6 additions & 3 deletions libavcodec/ffv1dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
y = sc->slice_y;

if (ac == AC_GOLOMB_RICE) {
if (f->version == 3 && f->micro_version > 1 || f->version > 3)
if (f->combined_version >= 0x30002)
get_rac(&sc->c, (uint8_t[]) { 129 });
sc->ac_byte_count = f->version > 2 || (!x && !y) ? sc->c.bytestream - sc->c.bytestream_start - 1 : 0;
init_get_bits(&gb,
Expand Down Expand Up @@ -433,11 +433,13 @@ static int read_extra_header(FFV1Context *f)
f->version);
return AVERROR_PATCHWELCOME;
}
f->combined_version = f->version << 16;
if (f->version > 2) {
c.bytestream_end -= 4;
f->micro_version = get_symbol(&c, state, 0);
if (f->micro_version < 0)
if (f->micro_version < 0 || f->micro_version > 65535)
return AVERROR_INVALIDDATA;
f->combined_version += f->micro_version;
}
f->ac = get_symbol(&c, state, 0);

Expand Down Expand Up @@ -505,7 +507,7 @@ static int read_extra_header(FFV1Context *f)
f->ec = get_symbol(&c, state, 0);
if (f->ec >= 2)
f->crcref = 0x7a8c4079;
if (f->micro_version > 2)
if (f->combined_version >= 0x30003)
f->intra = get_symbol(&c, state, 0);
}

Expand Down Expand Up @@ -1104,6 +1106,7 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)

fdst->version = fsrc->version;
fdst->micro_version = fsrc->micro_version;
fdst->combined_version = fsrc->combined_version;
fdst->chroma_planes = fsrc->chroma_planes;
fdst->chroma_h_shift = fsrc->chroma_h_shift;
fdst->chroma_v_shift = fsrc->chroma_v_shift;
Expand Down
2 changes: 2 additions & 0 deletions libavcodec/ffv1enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,13 @@ av_cold int ff_ffv1_write_extradata(AVCodecContext *avctx)
ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8);

put_symbol(&c, state, f->version, 0);
f->combined_version = f->version << 16;
if (f->version > 2) {
if (f->version == 3) {
f->micro_version = 4;
} else if (f->version == 4)
f->micro_version = 3;
f->combined_version += f->micro_version;
put_symbol(&c, state, f->micro_version, 0);
}

Expand Down

0 comments on commit 0c237d6

Please sign in to comment.