From: Michael Niedermayer <michael@niedermayer.cc>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH 1/4] avcodec/ffv1: simplify version checks with combined_version
Date: Sat, 18 Jan 2025 05:59:57 +0100
Message-ID: <20250118050001.1809058-1-michael@niedermayer.cc> (raw)
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
libavcodec/ffv1.c | 2 +-
libavcodec/ffv1.h | 1 +
libavcodec/ffv1dec.c | 9 ++++++---
libavcodec/ffv1enc.c | 2 ++
4 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 927763e24d4..f303ed769f0 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -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;
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index ca03fd2b109..576769ae1e0 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -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;
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 78458158735..5aec6cdce26 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -306,7 +306,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,
@@ -432,11 +432,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);
@@ -504,7 +506,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);
}
@@ -1032,6 +1034,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;
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index e2db1b41640..c6f450ae6c0 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -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);
}
--
2.48.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next reply other threads:[~2025-01-18 5:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-18 4:59 Michael Niedermayer [this message]
2025-01-18 4:59 ` [FFmpeg-devel] [PATCH 2/4] avcodec/ffv1enc: dont reset version Michael Niedermayer
2025-01-21 1:52 ` Michael Niedermayer
2025-01-18 4:59 ` [FFmpeg-devel] [PATCH 3/4] avcodec/ffv1: Basic float16 support Michael Niedermayer
2025-01-18 5:00 ` [FFmpeg-devel] [PATCH 4/4] avcodec/ffv1: NOT FOR GIT, experiment about float decorrelation Michael Niedermayer
2025-01-18 8:33 ` Lynne
2025-01-18 23:02 ` Michael Niedermayer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250118050001.1809058-1-michael@niedermayer.cc \
--to=michael@niedermayer.cc \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git