avcodec/codec_internal: Add macros for update_thread_context(_for_user)

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@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2022-08-29 15:03:21 +02:00
parent 48286d4d98
commit 73fada029c
18 changed files with 33 additions and 32 deletions

View File

@ -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,
};

View File

@ -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)

View File

@ -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 |

View File

@ -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,
};

View File

@ -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 |

View File

@ -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,
};

View File

@ -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),

View File

@ -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

View File

@ -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 |

View File

@ -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 []) {

View File

@ -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,
};

View File

@ -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,
};

View File

@ -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,

View File

@ -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,
};

View File

@ -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),

View File

@ -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 []) {

View File

@ -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 |

View File

@ -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.
*