aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2025-06-13 01:10:18 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2025-06-21 22:08:52 +0200
commit8f92885b1fd72635af25e57b61f85bcff7e76ae3 (patch)
treedd6edc72ad5bb59223bbc5c4a85542afe041fd0c
parent85692e5da1eae28c582fd2c5fb6a1620e824ca96 (diff)
downloadffmpeg-8f92885b1fd72635af25e57b61f85bcff7e76ae3.tar.gz
avcodec/mpegvideo: Defer init of enc slice ctxs in ff_mpv_common_init()
This will allow to perform initializations between ff_mpv_common_init() and ff_mpv_init_duplicate_contexts() that will be automatically copied to the slice contexts. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
-rw-r--r--libavcodec/mpegvideo.c8
-rw-r--r--libavcodec/mpegvideo_enc.c9
2 files changed, 11 insertions, 6 deletions
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index e329771b38..f6e997193d 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -431,9 +431,11 @@ av_cold int ff_mpv_common_init(MpegEncContext *s)
s->slice_context_count = nb_slices;
// if (s->width && s->height) {
- ret = ff_mpv_init_duplicate_contexts(s);
- if (ret < 0)
- goto fail;
+ if (!s->encoding) {
+ ret = ff_mpv_init_duplicate_contexts(s);
+ if (ret < 0)
+ goto fail;
+ }
// }
return 0;
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index af1e77cfec..1fae5fbeb0 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1023,9 +1023,9 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
m->lmin = m->lmax;
}
- /* ff_mpv_common_init() will copy (memdup) the contents of the main slice
- * to the slice contexts, so we initialize various fields of it
- * before calling ff_mpv_common_init(). */
+ /* ff_mpv_init_duplicate_contexts() will copy (memdup) the contents of the
+ * main slice to the slice contexts, so we initialize various fields of it
+ * before calling ff_mpv_init_duplicate_contexts(). */
s->parent = m;
ff_mpv_idct_init(&s->c);
init_unquantize(s, avctx);
@@ -1059,6 +1059,9 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
ret = ff_mpv_common_init(&s->c);
if (ret < 0)
return ret;
+ ret = ff_mpv_init_duplicate_contexts(&s->c);
+ if (ret < 0)
+ return ret;
if (s->c.slice_context_count > 1) {
for (int i = 0; i < s->c.slice_context_count; ++i) {