aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2024-07-08 11:36:58 +0200
committerAnton Khirnov <anton@khirnov.net>2024-08-01 10:09:26 +0200
commit4b9f7c7e3a9568a1982a6618c0ab77a3695675c1 (patch)
treee6bfb484e60439b3f9574af0a2e44551abe534d8 /libavcodec
parentd2f507233a6c3cbc24d342d3c31db2c3489df96d (diff)
downloadffmpeg-4b9f7c7e3a9568a1982a6618c0ab77a3695675c1.tar.gz
lavc/ffv1: drop redundant FFV1Context.quant_table
In all cases except decoding version 1 it's either not used, or contains a copy of a table from quant_tables, which we can just as well use directly. When decoding version 1, we can just as well decode into quant_tables[0], which would otherwise be unused.
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/ffv1.h1
-rw-r--r--libavcodec/ffv1dec.c10
-rw-r--r--libavcodec/ffv1enc.c6
3 files changed, 9 insertions, 8 deletions
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index dce6e177eb..4d57172d5b 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -106,7 +106,6 @@ typedef struct FFV1Context {
int ac; ///< 1=range coder <-> 0=golomb rice
int ac_byte_count; ///< number of bytes used for AC coding
PlaneContext plane[MAX_PLANES];
- int16_t quant_table[MAX_CONTEXT_INPUTS][256];
int16_t quant_tables[MAX_QUANT_TABLES][MAX_CONTEXT_INPUTS][256];
int context_count[MAX_QUANT_TABLES];
uint8_t state_transition[256];
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index a1f7206871..66d9f63c1a 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -764,7 +764,7 @@ static int read_header(FFV1Context *f)
ff_dlog(f->avctx, "%d %d %d\n",
f->chroma_h_shift, f->chroma_v_shift, f->avctx->pix_fmt);
if (f->version < 2) {
- context_count = read_quant_tables(c, f->quant_table);
+ context_count = read_quant_tables(c, f->quant_tables[0]);
if (context_count < 0) {
av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n");
return AVERROR_INVALIDDATA;
@@ -834,7 +834,7 @@ static int read_header(FFV1Context *f)
sizeof(p->quant_table));
context_count = f->context_count[idx];
} else {
- memcpy(p->quant_table, f->quant_table, sizeof(p->quant_table));
+ memcpy(p->quant_table, f->quant_tables[0], sizeof(p->quant_table));
}
if (f->version <= 2) {
@@ -1067,7 +1067,11 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
fdst->use32bit = fsrc->use32bit;
memcpy(fdst->state_transition, fsrc->state_transition,
sizeof(fdst->state_transition));
- memcpy(fdst->quant_table, fsrc->quant_table, sizeof(fsrc->quant_table));
+
+ // in version 1 there is a single per-keyframe quant table, so
+ // we need to propagate it between threads
+ if (fsrc->version < 2)
+ memcpy(fdst->quant_tables[0], fsrc->quant_tables[0], sizeof(fsrc->quant_tables[0]));
for (int i = 0; i < fdst->num_h_slices * fdst->num_v_slices; i++) {
FFV1Context *fssrc = fsrc->slice_context[i];
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 5692bfa1fc..1d00a46cdd 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -367,7 +367,7 @@ static void write_header(FFV1Context *f)
put_symbol(c, state, f->chroma_v_shift, 0);
put_rac(c, state, f->transparency);
- write_quant_tables(c, f->quant_table);
+ write_quant_tables(c, f->quant_tables[f->context_model]);
} else if (f->version < 3) {
put_symbol(c, state, f->slice_count, 0);
for (i = 0; i < f->slice_count; i++) {
@@ -735,15 +735,13 @@ static av_cold int encode_init(AVCodecContext *avctx)
}
s->context_count[0] = (11 * 11 * 11 + 1) / 2;
s->context_count[1] = (11 * 11 * 5 * 5 * 5 + 1) / 2;
- memcpy(s->quant_table, s->quant_tables[s->context_model],
- sizeof(s->quant_table));
for (i = 0; i < s->plane_count; i++) {
PlaneContext *const p = &s->plane[i];
- memcpy(p->quant_table, s->quant_table, sizeof(p->quant_table));
p->quant_table_index = s->context_model;
p->context_count = s->context_count[p->quant_table_index];
+ memcpy(p->quant_table, s->quant_tables[p->quant_table_index], sizeof(p->quant_table));
}
if ((ret = ff_ffv1_allocate_initial_states(s)) < 0)