[FFmpeg-cvslog] avcodec/mpegvideo: Add pointer to main context to slice contexts
Andreas Rheinhardt
git at videolan.org
Wed Mar 26 06:09:46 EET 2025
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Sat Mar 15 07:16:33 2025 +0100| [6e02882656ead99d9b881104521cbcb38d100811] | committer: Andreas Rheinhardt
avcodec/mpegvideo: Add pointer to main context to slice contexts
It is a pointer to const to allow the slice threads to inspect
values without modifying them; also make it a simple cast
for codecs that don't support slice threading.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6e02882656ead99d9b881104521cbcb38d100811
---
libavcodec/mpegvideo.c | 2 ++
libavcodec/mpegvideo.h | 4 ++++
libavcodec/mpegvideoenc.h | 12 ++++++++++++
3 files changed, 18 insertions(+)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 9cd67151aa..bc367fba07 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -387,6 +387,8 @@ av_cold int ff_mpv_init_duplicate_contexts(MpegEncContext *s)
{
int nb_slices = s->slice_context_count, ret;
+ s->parent = s;
+
/* We initialize the copies before the original so that
* fields allocated in init_duplicate_context are NULL after
* copying. This prevents double-frees upon allocation error. */
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index bdab782b29..04eade13aa 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -86,6 +86,10 @@ typedef struct MpegEncContext {
uint8_t permutated_intra_v_scantable[64];
struct AVCodecContext *avctx;
+ union {
+ const struct MpegEncContext *parent;
+ const struct MPVMainEncContext *encparent;
+ };
/* The following pointer is intended for codecs sharing code
* between decoder and encoder and in need of a common context to do so. */
void *private_ctx;
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index a1543689a8..fcf6d09507 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -30,6 +30,7 @@
#include <float.h>
+#include "libavutil/avassert.h"
#include "libavutil/opt.h"
#include "mpegvideo.h"
#include "ratecontrol.h"
@@ -91,6 +92,17 @@ typedef struct MPVMainEncContext {
int64_t mc_mb_var_sum; ///< motion compensated MB variance for current frame
} MPVMainEncContext;
+static inline const MPVMainEncContext *slice_to_mainenc(const MpegEncContext *s)
+{
+#ifdef NO_SLICE_THREADING_HERE
+ av_assert2(s->slice_context_count <= 1 &&
+ !(s->avctx->codec->capabilities & AV_CODEC_CAP_SLICE_THREADS));
+ return (const MPVMainEncContext*)s;
+#else
+ return s->encparent;
+#endif
+}
+
#define MAX_FCODE 7
#define UNI_AC_ENC_INDEX(run,level) ((run)*128 + (level))
#define INPLACE_OFFSET 16
More information about the ffmpeg-cvslog
mailing list