[FFmpeg-devel] [PATCH 18/18] avcodec/codec_internal: Add macros for update_thread_context(_for_user)

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Mon Aug 29 16:45:47 EEST 2022


It reduces typing: Before this patch, there were 11 callbacks
that exceeded the 80 char line length limit; now there are zero.
It also allows to remove ONLY_IF_THREADS_ENABLED() in
libavutil/internal.h.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavcodec/cfhd.c           |  2 +-
 libavcodec/codec_internal.h | 12 ++++++++++++
 libavcodec/ffv1dec.c        |  2 +-
 libavcodec/h264dec.c        |  4 ++--
 libavcodec/hevcdec.c        |  2 +-
 libavcodec/mimic.c          |  2 +-
 libavcodec/mpeg12dec.c      |  2 +-
 libavcodec/mpeg4videodec.c  |  4 ++--
 libavcodec/pngdec.c         |  4 ++--
 libavcodec/proresdec2.c     |  2 +-
 libavcodec/rv30.c           |  2 +-
 libavcodec/rv40.c           |  2 +-
 libavcodec/takdec.c         |  2 +-
 libavcodec/vp3.c            |  6 +++---
 libavcodec/vp8.c            |  2 +-
 libavcodec/vp9.c            |  2 +-
 libavcodec/wavpack.c        |  2 +-
 libavutil/internal.h        | 11 -----------
 18 files changed, 33 insertions(+), 32 deletions(-)

diff --git a/libavcodec/cfhd.c b/libavcodec/cfhd.c
index 9eaac9ecfd..1af9cd44a9 100644
--- a/libavcodec/cfhd.c
+++ b/libavcodec/cfhd.c
@@ -1464,7 +1464,7 @@ const FFCodec ff_cfhd_decoder = {
     .init             = cfhd_init,
     .close            = cfhd_close,
     FF_CODEC_DECODE_CB(cfhd_decode),
-    .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
+    UPDATE_THREAD_CONTEXT(update_thread_context),
     .p.capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
     .caps_internal    = FF_CODEC_CAP_INIT_CLEANUP,
 };
diff --git a/libavcodec/codec_internal.h b/libavcodec/codec_internal.h
index 310e243d84..2d9b4f6460 100644
--- a/libavcodec/codec_internal.h
+++ b/libavcodec/codec_internal.h
@@ -264,6 +264,18 @@ typedef struct FFCodec {
 #define CODEC_LONG_NAME(str) .p.long_name = str
 #endif
 
+#if HAVE_THREADS
+#define UPDATE_THREAD_CONTEXT(func) \
+        .update_thread_context          = (func)
+#define UPDATE_THREAD_CONTEXT_FOR_USER(func) \
+        .update_thread_context_for_user = (func)
+#else
+#define UPDATE_THREAD_CONTEXT(func) \
+        .update_thread_context          = NULL
+#define UPDATE_THREAD_CONTEXT_FOR_USER(func) \
+        .update_thread_context_for_user = NULL
+#endif
+
 #define FF_CODEC_DECODE_CB(func)                          \
     .cb_type           = FF_CODEC_CB_TYPE_DECODE,         \
     .cb.decode         = (func)
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 2fc8941362..794c58cc40 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -1077,7 +1077,7 @@ const FFCodec ff_ffv1_decoder = {
     .init           = decode_init,
     .close          = ff_ffv1_close,
     FF_CODEC_DECODE_CB(decode_frame),
-    .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
+    UPDATE_THREAD_CONTEXT(update_thread_context),
     .p.capabilities = AV_CODEC_CAP_DR1 /*| AV_CODEC_CAP_DRAW_HORIZ_BAND*/ |
                       AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS,
     .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP |
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 3cef3f39f5..8f56f3ff92 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -1105,8 +1105,8 @@ const FFCodec ff_h264_decoder = {
     .caps_internal         = FF_CODEC_CAP_EXPORTS_CROPPING |
                              FF_CODEC_CAP_ALLOCATE_PROGRESS | FF_CODEC_CAP_INIT_CLEANUP,
     .flush                 = h264_decode_flush,
-    .update_thread_context = ONLY_IF_THREADS_ENABLED(ff_h264_update_thread_context),
-    .update_thread_context_for_user = ONLY_IF_THREADS_ENABLED(ff_h264_update_thread_context_for_user),
+    UPDATE_THREAD_CONTEXT(ff_h264_update_thread_context),
+    UPDATE_THREAD_CONTEXT_FOR_USER(ff_h264_update_thread_context_for_user),
     .p.profiles            = NULL_IF_CONFIG_SMALL(ff_h264_profiles),
     .p.priv_class          = &h264_class,
 };
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 91bafa2114..90961f87be 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -3854,7 +3854,7 @@ const FFCodec ff_hevc_decoder = {
     .close                 = hevc_decode_free,
     FF_CODEC_DECODE_CB(hevc_decode_frame),
     .flush                 = hevc_decode_flush,
-    .update_thread_context = ONLY_IF_THREADS_ENABLED(hevc_update_thread_context),
+    UPDATE_THREAD_CONTEXT(hevc_update_thread_context),
     .p.capabilities        = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
                              AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS,
     .caps_internal         = FF_CODEC_CAP_EXPORTS_CROPPING |
diff --git a/libavcodec/mimic.c b/libavcodec/mimic.c
index c506a42322..1d4f2b85c1 100644
--- a/libavcodec/mimic.c
+++ b/libavcodec/mimic.c
@@ -446,7 +446,7 @@ const FFCodec ff_mimic_decoder = {
     .close                 = mimic_decode_end,
     FF_CODEC_DECODE_CB(mimic_decode_frame),
     .p.capabilities        = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
-    .update_thread_context = ONLY_IF_THREADS_ENABLED(mimic_decode_update_thread_context),
+    UPDATE_THREAD_CONTEXT(mimic_decode_update_thread_context),
     .caps_internal         = FF_CODEC_CAP_ALLOCATE_PROGRESS |
                              FF_CODEC_CAP_INIT_CLEANUP,
 };
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 2aa5bc776d..7133696f3c 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -2880,7 +2880,7 @@ const FFCodec ff_mpeg1video_decoder = {
     .caps_internal         = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
     .flush                 = flush,
     .p.max_lowres          = 3,
-    .update_thread_context = ONLY_IF_THREADS_ENABLED(mpeg_decode_update_thread_context),
+    UPDATE_THREAD_CONTEXT(mpeg_decode_update_thread_context),
     .hw_configs            = (const AVCodecHWConfigInternal *const []) {
 #if CONFIG_MPEG1_NVDEC_HWACCEL
                                HWACCEL_NVDEC(mpeg1),
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 8eb81688ef..4dbf37afe5 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -3686,8 +3686,8 @@ const FFCodec ff_mpeg4_decoder = {
     .p.max_lowres          = 3,
     .p.pix_fmts            = ff_h263_hwaccel_pixfmt_list_420,
     .p.profiles            = NULL_IF_CONFIG_SMALL(ff_mpeg4_video_profiles),
-    .update_thread_context = ONLY_IF_THREADS_ENABLED(mpeg4_update_thread_context),
-    .update_thread_context_for_user = ONLY_IF_THREADS_ENABLED(mpeg4_update_thread_context_for_user),
+    UPDATE_THREAD_CONTEXT(mpeg4_update_thread_context),
+    UPDATE_THREAD_CONTEXT_FOR_USER(mpeg4_update_thread_context_for_user),
     .p.priv_class = &mpeg4_class,
     .hw_configs            = (const AVCodecHWConfigInternal *const []) {
 #if CONFIG_MPEG4_NVDEC_HWACCEL
diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 9e7d9b589f..582953d17b 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -1722,7 +1722,7 @@ const FFCodec ff_apng_decoder = {
     .init           = png_dec_init,
     .close          = png_dec_end,
     FF_CODEC_DECODE_CB(decode_frame_apng),
-    .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
+    UPDATE_THREAD_CONTEXT(update_thread_context),
     .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS /*| AV_CODEC_CAP_DRAW_HORIZ_BAND*/,
     .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP |
                       FF_CODEC_CAP_ALLOCATE_PROGRESS |
@@ -1740,7 +1740,7 @@ const FFCodec ff_png_decoder = {
     .init           = png_dec_init,
     .close          = png_dec_end,
     FF_CODEC_DECODE_CB(decode_frame_png),
-    .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
+    UPDATE_THREAD_CONTEXT(update_thread_context),
     .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS /*| AV_CODEC_CAP_DRAW_HORIZ_BAND*/,
     .caps_internal  = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |
                       FF_CODEC_CAP_ALLOCATE_PROGRESS | FF_CODEC_CAP_INIT_CLEANUP |
diff --git a/libavcodec/proresdec2.c b/libavcodec/proresdec2.c
index 68b29deadb..5ec579b994 100644
--- a/libavcodec/proresdec2.c
+++ b/libavcodec/proresdec2.c
@@ -878,7 +878,7 @@ const FFCodec ff_prores_decoder = {
     .init           = decode_init,
     .close          = decode_close,
     FF_CODEC_DECODE_CB(decode_frame),
-    .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
+    UPDATE_THREAD_CONTEXT(update_thread_context),
     .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS,
     .p.profiles     = NULL_IF_CONFIG_SMALL(ff_prores_profiles),
     .hw_configs     = (const AVCodecHWConfigInternal *const []) {
diff --git a/libavcodec/rv30.c b/libavcodec/rv30.c
index 0361e75580..be62577f99 100644
--- a/libavcodec/rv30.c
+++ b/libavcodec/rv30.c
@@ -307,6 +307,6 @@ const FFCodec ff_rv30_decoder = {
         AV_PIX_FMT_YUV420P,
         AV_PIX_FMT_NONE
     },
-    .update_thread_context = ONLY_IF_THREADS_ENABLED(ff_rv34_decode_update_thread_context),
+    UPDATE_THREAD_CONTEXT(ff_rv34_decode_update_thread_context),
     .caps_internal         = FF_CODEC_CAP_ALLOCATE_PROGRESS,
 };
diff --git a/libavcodec/rv40.c b/libavcodec/rv40.c
index 728a04062a..75849b173e 100644
--- a/libavcodec/rv40.c
+++ b/libavcodec/rv40.c
@@ -590,6 +590,6 @@ const FFCodec ff_rv40_decoder = {
         AV_PIX_FMT_YUV420P,
         AV_PIX_FMT_NONE
     },
-    .update_thread_context = ONLY_IF_THREADS_ENABLED(ff_rv34_decode_update_thread_context),
+    UPDATE_THREAD_CONTEXT(ff_rv34_decode_update_thread_context),
     .caps_internal         = FF_CODEC_CAP_ALLOCATE_PROGRESS,
 };
diff --git a/libavcodec/takdec.c b/libavcodec/takdec.c
index f7fb34617d..68ad1e9ed7 100644
--- a/libavcodec/takdec.c
+++ b/libavcodec/takdec.c
@@ -946,7 +946,7 @@ const FFCodec ff_tak_decoder = {
     .init             = tak_decode_init,
     .close            = tak_decode_close,
     FF_CODEC_DECODE_CB(tak_decode_frame),
-    .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
+    UPDATE_THREAD_CONTEXT(update_thread_context),
     .p.capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_CHANNEL_CONF,
     .p.sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_U8P,
                                                         AV_SAMPLE_FMT_S16P,
diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index 58dd81cd61..31775455a4 100644
--- a/libavcodec/vp3.c
+++ b/libavcodec/vp3.c
@@ -3179,7 +3179,7 @@ const FFCodec ff_theora_decoder = {
     .p.capabilities        = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DRAW_HORIZ_BAND |
                              AV_CODEC_CAP_FRAME_THREADS,
     .flush                 = vp3_decode_flush,
-    .update_thread_context = ONLY_IF_THREADS_ENABLED(vp3_update_thread_context),
+    UPDATE_THREAD_CONTEXT(vp3_update_thread_context),
     .caps_internal         = FF_CODEC_CAP_INIT_CLEANUP |
                              FF_CODEC_CAP_EXPORTS_CROPPING | FF_CODEC_CAP_ALLOCATE_PROGRESS,
 };
@@ -3197,7 +3197,7 @@ const FFCodec ff_vp3_decoder = {
     .p.capabilities        = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DRAW_HORIZ_BAND |
                              AV_CODEC_CAP_FRAME_THREADS,
     .flush                 = vp3_decode_flush,
-    .update_thread_context = ONLY_IF_THREADS_ENABLED(vp3_update_thread_context),
+    UPDATE_THREAD_CONTEXT(vp3_update_thread_context),
     .caps_internal         = FF_CODEC_CAP_INIT_CLEANUP |
                              FF_CODEC_CAP_ALLOCATE_PROGRESS,
 };
@@ -3215,7 +3215,7 @@ const FFCodec ff_vp4_decoder = {
     .p.capabilities        = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DRAW_HORIZ_BAND |
                              AV_CODEC_CAP_FRAME_THREADS,
     .flush                 = vp3_decode_flush,
-    .update_thread_context = ONLY_IF_THREADS_ENABLED(vp3_update_thread_context),
+    UPDATE_THREAD_CONTEXT(vp3_update_thread_context),
     .caps_internal         = FF_CODEC_CAP_INIT_CLEANUP |
                              FF_CODEC_CAP_ALLOCATE_PROGRESS,
 };
diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c
index 6545002fd7..0e16e75faa 100644
--- a/libavcodec/vp8.c
+++ b/libavcodec/vp8.c
@@ -3003,7 +3003,7 @@ const FFCodec ff_vp8_decoder = {
                              AV_CODEC_CAP_SLICE_THREADS,
     .caps_internal         = FF_CODEC_CAP_ALLOCATE_PROGRESS,
     .flush                 = vp8_decode_flush,
-    .update_thread_context = ONLY_IF_THREADS_ENABLED(vp8_decode_update_thread_context),
+    UPDATE_THREAD_CONTEXT(vp8_decode_update_thread_context),
     .hw_configs            = (const AVCodecHWConfigInternal *const []) {
 #if CONFIG_VP8_VAAPI_HWACCEL
                                HWACCEL_VAAPI(vp8),
diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index acbbce5624..029e9156c5 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -1882,7 +1882,7 @@ const FFCodec ff_vp9_decoder = {
                              FF_CODEC_CAP_SLICE_THREAD_HAS_MF |
                              FF_CODEC_CAP_ALLOCATE_PROGRESS,
     .flush                 = vp9_decode_flush,
-    .update_thread_context = ONLY_IF_THREADS_ENABLED(vp9_decode_update_thread_context),
+    UPDATE_THREAD_CONTEXT(vp9_decode_update_thread_context),
     .p.profiles            = NULL_IF_CONFIG_SMALL(ff_vp9_profiles),
     .bsfs                  = "vp9_superframe_split",
     .hw_configs            = (const AVCodecHWConfigInternal *const []) {
diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c
index a326b06e94..7aa1f65e17 100644
--- a/libavcodec/wavpack.c
+++ b/libavcodec/wavpack.c
@@ -1707,7 +1707,7 @@ const FFCodec ff_wavpack_decoder = {
     .close          = wavpack_decode_end,
     FF_CODEC_DECODE_CB(wavpack_decode_frame),
     .flush          = wavpack_decode_flush,
-    .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
+    UPDATE_THREAD_CONTEXT(update_thread_context),
     .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
                       AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_CHANNEL_CONF,
     .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP |
diff --git a/libavutil/internal.h b/libavutil/internal.h
index 40072d4e30..c9e30bc5e9 100644
--- a/libavutil/internal.h
+++ b/libavutil/internal.h
@@ -115,17 +115,6 @@
 #   define NULL_IF_CONFIG_SMALL(x) x
 #endif
 
-/**
- * Return NULL if a threading library has not been enabled.
- * Used to disable threading functions in AVCodec definitions
- * when not needed.
- */
-#if HAVE_THREADS
-#   define ONLY_IF_THREADS_ENABLED(x) x
-#else
-#   define ONLY_IF_THREADS_ENABLED(x) NULL
-#endif
-
 /**
  * Log a generic warning message about a missing feature.
  *
-- 
2.34.1



More information about the ffmpeg-devel mailing list