[FFmpeg-cvslog] lavc/ffv1enc: store per-slice rc_stat(2?) in FFV1SliceContext

Anton Khirnov git at videolan.org
Thu Aug 1 11:17:09 EEST 2024


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Wed Jul 10 16:51:45 2024 +0200| [e7d0f44138a7b7303ccc760d28d608893dbf7641] | committer: Anton Khirnov

lavc/ffv1enc: store per-slice rc_stat(2?) in FFV1SliceContext

Instead of the per-slice FFV1Context, which will be removed in future
commits.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e7d0f44138a7b7303ccc760d28d608893dbf7641
---

 libavcodec/ffv1.c             |  6 ++----
 libavcodec/ffv1.h             |  3 +++
 libavcodec/ffv1enc.c          | 20 ++++++++++----------
 libavcodec/ffv1enc_template.c |  4 ++--
 4 files changed, 17 insertions(+), 16 deletions(-)

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 6790366149..a17fdd35ec 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -897,11 +897,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);
             }
     }
@@ -1127,16 +1127,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 1339b2bd4c..24dcf2a68e 100644
--- a/libavcodec/ffv1enc_template.c
+++ b/libavcodec/ffv1enc_template.c
@@ -75,8 +75,8 @@ RENAME(encode_line)(FFV1Context *f,
 
         if (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);
             }



More information about the ffmpeg-cvslog mailing list