diff mbox series

[FFmpeg-devel,20/39] lavc/ffv1enc: store per-slice rc_stat(2?) in FFV1SliceContext

Message ID 20240716171155.31838-20-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,01/39] tests/fate/vcodec: add vsynth tests for FFV1 version 2 | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov July 16, 2024, 5:11 p.m. UTC
Instead of the per-slice FFV1Context, which will be removed in future
commits.
---
 libavcodec/ffv1.c             |  6 ++----
 libavcodec/ffv1.h             |  3 +++
 libavcodec/ffv1enc.c          | 20 ++++++++++----------
 libavcodec/ffv1enc_template.c |  4 ++--
 4 files changed, 17 insertions(+), 16 deletions(-)

Comments

Michael Niedermayer July 24, 2024, 7:30 p.m. UTC | #1
On Tue, Jul 16, 2024 at 07:11:35PM +0200, Anton Khirnov wrote:
> Instead of the per-slice FFV1Context, which will be removed in future
> commits.
> ---
>  libavcodec/ffv1.c             |  6 ++----
>  libavcodec/ffv1.h             |  3 +++
>  libavcodec/ffv1enc.c          | 20 ++++++++++----------
>  libavcodec/ffv1enc_template.c |  4 ++--
>  4 files changed, 17 insertions(+), 16 deletions(-)

LGTM

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 490baac233..4ef04f6b9b 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -127,7 +127,6 @@  av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
 
         f->slice_context[i++] = fs;
         memcpy(fs, f, sizeof(*fs));
-        memset(fs->rc_stat2, 0, sizeof(fs->rc_stat2));
 
         sc->slice_width  = sxe - sxs;
         sc->slice_height = sye - sys;
@@ -208,9 +207,8 @@  av_cold int ff_ffv1_close(AVCodecContext *avctx)
     for (j = 0; j < s->quant_table_count; j++) {
         av_freep(&s->initial_states[j]);
         for (i = 0; i < s->max_slice_count; i++) {
-            FFV1Context *sf = s->slice_context[i];
-            if (sf)
-                av_freep(&sf->rc_stat2[j]);
+            FFV1SliceContext *sc = &s->slices[i];
+            av_freep(&sc->rc_stat2[j]);
         }
         av_freep(&s->rc_stat2[j]);
     }
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index 01c35dc942..bee7b75614 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -84,6 +84,9 @@  typedef struct FFV1SliceContext {
     PlaneContext plane[MAX_PLANES];
     PutBitContext pb;
     RangeCoder c;
+
+    uint64_t rc_stat[256][2];
+    uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];
 } FFV1SliceContext;
 
 typedef struct FFV1Context {
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index d615d3da87..e3d094141c 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -896,11 +896,11 @@  slices_ok:
             return AVERROR(ENOMEM);
         for (i = 0; i < s->quant_table_count; i++)
             for (j = 0; j < s->max_slice_count; j++) {
-                FFV1Context *sf = s->slice_context[j];
-                av_assert0(!sf->rc_stat2[i]);
-                sf->rc_stat2[i] = av_mallocz(s->context_count[i] *
-                                             sizeof(*sf->rc_stat2[i]));
-                if (!sf->rc_stat2[i])
+                FFV1SliceContext *sc = &s->slices[j];
+                av_assert0(!sc->rc_stat2[i]);
+                sc->rc_stat2[i] = av_mallocz(s->context_count[i] *
+                                             sizeof(*sc->rc_stat2[i]));
+                if (!sc->rc_stat2[i])
                     return AVERROR(ENOMEM);
             }
     }
@@ -1126,16 +1126,16 @@  static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
 
             av_assert0(f->slice_count == f->max_slice_count);
             for (j = 0; j < f->slice_count; j++) {
-                FFV1Context *fs = f->slice_context[j];
+                const FFV1SliceContext *sc = &f->slices[j];
                 for (i = 0; i < 256; i++) {
-                    f->rc_stat[i][0] += fs->rc_stat[i][0];
-                    f->rc_stat[i][1] += fs->rc_stat[i][1];
+                    f->rc_stat[i][0] += sc->rc_stat[i][0];
+                    f->rc_stat[i][1] += sc->rc_stat[i][1];
                 }
                 for (i = 0; i < f->quant_table_count; i++) {
                     for (k = 0; k < f->context_count[i]; k++)
                         for (m = 0; m < 32; m++) {
-                            f->rc_stat2[i][k][m][0] += fs->rc_stat2[i][k][m][0];
-                            f->rc_stat2[i][k][m][1] += fs->rc_stat2[i][k][m][1];
+                            f->rc_stat2[i][k][m][0] += sc->rc_stat2[i][k][m][0];
+                            f->rc_stat2[i][k][m][1] += sc->rc_stat2[i][k][m][1];
                         }
                 }
             }
diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c
index c27a2e3a39..c79146d619 100644
--- a/libavcodec/ffv1enc_template.c
+++ b/libavcodec/ffv1enc_template.c
@@ -74,8 +74,8 @@  RENAME(encode_line)(FFV1Context *f,
 
         if (f->ac != AC_GOLOMB_RICE) {
             if (s->flags & AV_CODEC_FLAG_PASS1) {
-                put_symbol_inline(c, p->state[context], diff, 1, s->rc_stat,
-                                  s->rc_stat2[p->quant_table_index][context]);
+                put_symbol_inline(c, p->state[context], diff, 1, sc->rc_stat,
+                                  sc->rc_stat2[p->quant_table_index][context]);
             } else {
                 put_symbol_inline(c, p->state[context], diff, 1, NULL, NULL);
             }