[FFmpeg-cvslog] avcodec/magicyuvenc: fix correlation buffers size when slices are used

Paul B Mahol git at videolan.org
Sun Sep 10 14:49:07 EEST 2023


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sun Sep 10 13:35:29 2023 +0200| [3b9e6a7333c1c8334e338394851e2e93f949e9e6] | committer: Paul B Mahol

avcodec/magicyuvenc: fix correlation buffers size when slices are used

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

 libavcodec/magicyuvenc.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/libavcodec/magicyuvenc.c b/libavcodec/magicyuvenc.c
index b166ec4f2f..427d4848e6 100644
--- a/libavcodec/magicyuvenc.c
+++ b/libavcodec/magicyuvenc.c
@@ -196,12 +196,6 @@ static av_cold int magy_encode_init(AVCodecContext *avctx)
         s->format = 0x6b;
         break;
     }
-    if (s->correlate) {
-        s->decorrelate_buf[0] = av_calloc(2U * avctx->height, FFALIGN(avctx->width, av_cpu_max_align()));
-        if (!s->decorrelate_buf[0])
-            return AVERROR(ENOMEM);
-        s->decorrelate_buf[1] = s->decorrelate_buf[0] + avctx->height * FFALIGN(avctx->width, av_cpu_max_align());
-    }
 
     ff_llvidencdsp_init(&s->llvidencdsp);
 
@@ -216,6 +210,13 @@ static av_cold int magy_encode_init(AVCodecContext *avctx)
     if (!s->slices)
         return AVERROR(ENOMEM);
 
+    if (s->correlate) {
+        s->decorrelate_buf[0] = av_calloc(2U * (s->nb_slices * s->slice_height), FFALIGN(avctx->width, av_cpu_max_align()));
+        if (!s->decorrelate_buf[0])
+            return AVERROR(ENOMEM);
+        s->decorrelate_buf[1] = s->decorrelate_buf[0] + (s->nb_slices * s->slice_height) * FFALIGN(avctx->width, av_cpu_max_align());
+    }
+
     s->bitslice_size = avctx->width * (s->slice_height + 2) + AV_INPUT_BUFFER_PADDING_SIZE;
     for (int n = 0; n < s->nb_slices; n++) {
         for (int i = 0; i < s->planes; i++) {
@@ -375,7 +376,7 @@ static int count_plane_slice(AVCodecContext *avctx, int n, int plane)
     const uint8_t *dst = sl->slice;
     PTable *counts = sl->counts;
 
-    memset(counts, 0, sizeof(*counts) * 256);
+    memset(counts, 0, sizeof(sl->counts));
 
     count_usage(dst, AV_CEIL_RSHIFT(avctx->width, s->hshift[plane]),
                 AV_CEIL_RSHIFT(s->slice_height, s->vshift[plane]), counts);



More information about the ffmpeg-cvslog mailing list