diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2025-06-13 06:10:27 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2025-06-21 22:08:52 +0200 |
commit | c4ebe55f94ff9e55bada7dbe9ff2fb9e75d85800 (patch) | |
tree | b2b9dda25097f2d8788c2803afad6db6a086a184 /libavcodec/mpegvideo_enc.c | |
parent | dba1061ba456701fcef17f52ac673687440bd966 (diff) | |
download | ffmpeg-c4ebe55f94ff9e55bada7dbe9ff2fb9e75d85800.tar.gz |
avcodec/mpegvideo: Allocate ac_val jointly
They are currently allocated separately per slice; allocating them
jointly allows to avoid saving them in ff_update_duplicate_context().
The way it is done also avoids allocating ac_val for encoders that
don't need it (e.g. H.263 or H.263+ with AIC).
This entailed moving setting nb_slices to ff_mpv_init_context_frame()
which is called from ff_mpv_common_frame_size_change(). The resultant
nb_slices will always be one when called from a decoder using
ff_mpv_common_frame_size_change().
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/mpegvideo_enc.c')
-rw-r--r-- | libavcodec/mpegvideo_enc.c | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 870cf7f5a7..3bec6b57cf 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -518,24 +518,36 @@ static av_cold int init_slice_buffers(MPVMainEncContext *const m) static_assert(DCT_ERROR_SIZE * MAX_THREADS + ALIGN - 1 <= SIZE_MAX, "Need checks for potential overflow."); unsigned nb_slices = s->c.slice_context_count; + char *dct_error = NULL; - if (!m->noise_reduction) - return 0; + if (m->noise_reduction) { + if (!FF_ALLOCZ_TYPED_ARRAY(s->dct_offset, 2)) + return AVERROR(ENOMEM); + dct_error = av_mallocz(ALIGN - 1 + nb_slices * DCT_ERROR_SIZE); + if (!dct_error) + return AVERROR(ENOMEM); + m->dct_error_sum_base = dct_error; + dct_error += FFALIGN((uintptr_t)dct_error, ALIGN) - (uintptr_t)dct_error; + } - if (!FF_ALLOCZ_TYPED_ARRAY(s->dct_offset, 2)) - return AVERROR(ENOMEM); - char *dct_error = av_mallocz(ALIGN - 1 + nb_slices * DCT_ERROR_SIZE); - if (!dct_error) - return AVERROR(ENOMEM); - m->dct_error_sum_base = dct_error; - dct_error += FFALIGN((uintptr_t)dct_error, ALIGN) - (uintptr_t)dct_error; + const int y_size = s->c.b8_stride * (2 * s->c.mb_height + 1); + const int c_size = s->c.mb_stride * (s->c.mb_height + 1); + const int yc_size = y_size + 2 * c_size; + ptrdiff_t offset = 0; for (unsigned i = 0; i < nb_slices; ++i) { MPVEncContext *const s2 = s->c.enc_contexts[i]; - s2->dct_offset = s->dct_offset; - s2->dct_error_sum = (void*)dct_error; - dct_error += DCT_ERROR_SIZE; + if (dct_error) { + s2->dct_offset = s->dct_offset; + s2->dct_error_sum = (void*)dct_error; + dct_error += DCT_ERROR_SIZE; + } + + if (s2->c.ac_val) { + s2->c.ac_val += offset; + offset += yc_size; + } } return 0; } |