[FFmpeg-cvslog] avcodec/mpegvideo: Support custom slice context sizes
Andreas Rheinhardt
git at videolan.org
Wed Mar 26 06:10:23 EET 2025
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Sun Mar 16 14:52:36 2025 +0100| [f293f95632b5519cf4c8aa5cfe3b87c0e9d006bb] | committer: Andreas Rheinhardt
avcodec/mpegvideo: Support custom slice context sizes
This is in preparation for adding a special slice context for
the encoders and moving all the encoder-specific fields to it.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f293f95632b5519cf4c8aa5cfe3b87c0e9d006bb
---
libavcodec/mpegvideo.c | 3 ++-
libavcodec/mpegvideo.h | 3 +++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 8055e6c0e2..126fefa1be 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -375,6 +375,7 @@ static av_cold int init_duplicate_context(MpegEncContext *s)
av_cold int ff_mpv_init_duplicate_contexts(MpegEncContext *s)
{
int nb_slices = s->slice_context_count, ret;
+ size_t slice_size = s->slice_ctx_size ? s->slice_ctx_size : sizeof(*s);
s->parent = s;
@@ -382,7 +383,7 @@ av_cold int ff_mpv_init_duplicate_contexts(MpegEncContext *s)
* fields allocated in init_duplicate_context are NULL after
* copying. This prevents double-frees upon allocation error. */
for (int i = 1; i < nb_slices; i++) {
- s->thread_context[i] = av_memdup(s, sizeof(MpegEncContext));
+ s->thread_context[i] = av_memdup(s, slice_size);
if (!s->thread_context[i])
return AVERROR(ENOMEM);
if ((ret = init_duplicate_context(s->thread_context[i])) < 0)
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 69efc81096..02894ce68f 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -469,6 +469,9 @@ typedef struct MpegEncContext {
* a frame size change */
int context_reinit;
+ /// If set, ff_mpv_common_init() will allocate slice contexts of this size
+ unsigned slice_ctx_size;
+
ERContext er;
int error_rate;
More information about the ffmpeg-cvslog
mailing list