Skip to content

Commit 3b9e6a7

Browse files
committed
avcodec/magicyuvenc: fix correlation buffers size when slices are used
1 parent fd1574d commit 3b9e6a7

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

libavcodec/magicyuvenc.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,6 @@ static av_cold int magy_encode_init(AVCodecContext *avctx)
196196
s->format = 0x6b;
197197
break;
198198
}
199-
if (s->correlate) {
200-
s->decorrelate_buf[0] = av_calloc(2U * avctx->height, FFALIGN(avctx->width, av_cpu_max_align()));
201-
if (!s->decorrelate_buf[0])
202-
return AVERROR(ENOMEM);
203-
s->decorrelate_buf[1] = s->decorrelate_buf[0] + avctx->height * FFALIGN(avctx->width, av_cpu_max_align());
204-
}
205199

206200
ff_llvidencdsp_init(&s->llvidencdsp);
207201

@@ -216,6 +210,13 @@ static av_cold int magy_encode_init(AVCodecContext *avctx)
216210
if (!s->slices)
217211
return AVERROR(ENOMEM);
218212

213+
if (s->correlate) {
214+
s->decorrelate_buf[0] = av_calloc(2U * (s->nb_slices * s->slice_height), FFALIGN(avctx->width, av_cpu_max_align()));
215+
if (!s->decorrelate_buf[0])
216+
return AVERROR(ENOMEM);
217+
s->decorrelate_buf[1] = s->decorrelate_buf[0] + (s->nb_slices * s->slice_height) * FFALIGN(avctx->width, av_cpu_max_align());
218+
}
219+
219220
s->bitslice_size = avctx->width * (s->slice_height + 2) + AV_INPUT_BUFFER_PADDING_SIZE;
220221
for (int n = 0; n < s->nb_slices; n++) {
221222
for (int i = 0; i < s->planes; i++) {
@@ -375,7 +376,7 @@ static int count_plane_slice(AVCodecContext *avctx, int n, int plane)
375376
const uint8_t *dst = sl->slice;
376377
PTable *counts = sl->counts;
377378

378-
memset(counts, 0, sizeof(*counts) * 256);
379+
memset(counts, 0, sizeof(sl->counts));
379380

380381
count_usage(dst, AV_CEIL_RSHIFT(avctx->width, s->hshift[plane]),
381382
AV_CEIL_RSHIFT(s->slice_height, s->vshift[plane]), counts);

0 commit comments

Comments
 (0)