[FFmpeg-devel] [PATCH 1/2] lavc: replace internal use of AV_CODEC_CAP_AUTO_THREADS with an internal cap
Andreas Rheinhardt
andreas.rheinhardt at gmail.com
Tue Mar 9 19:49:37 EET 2021
Anton Khirnov:
> AV_CODEC_CAP_AUTO_THREADS was originally added in b4d44a45f9a to mark
> codecs that spawn threads internally and are able to select an optimal
> threads count by themselves (all such codecs are wrappers around
> external libraries). It is used by lavc generic code to check whether it
> should handle thread_count=0 itself or pass the zero directly to the
> codec implementation. Within this meaning, it is clearly supposed to be
> an internal cap rather than a public one, since from the viewpoint of a
> libavcodec user, lavc ALWAYS handles thread_count=0. Whether it happens
> in the generic code or within the codec internals is not a meaningful
> difference for the caller.
>
> External aspects of this flag will be dealt with in the following
> commit.
> ---
> libavcodec/internal.h | 4 ++++
> libavcodec/libaomdec.c | 1 +
> libavcodec/libaomenc.c | 1 +
> libavcodec/libdav1d.c | 3 ++-
> libavcodec/libdavs2.c | 1 +
> libavcodec/libkvazaar.c | 3 ++-
> libavcodec/libopenh264enc.c | 3 ++-
> libavcodec/librav1e.c | 2 +-
> libavcodec/libsvtav1.c | 1 +
> libavcodec/libuavs3d.c | 1 +
> libavcodec/libvpxdec.c | 2 ++
> libavcodec/libvpxenc.c | 2 ++
> libavcodec/libx264.c | 9 +++++----
> libavcodec/libx265.c | 1 +
> libavcodec/libxavs.c | 1 +
> libavcodec/libxavs2.c | 1 +
> libavcodec/pthread.c | 2 +-
> libavcodec/utils.c | 2 +-
> 18 files changed, 30 insertions(+), 10 deletions(-)
>
> diff --git a/libavcodec/internal.h b/libavcodec/internal.h
> index 400ea508ef..b57b996816 100644
> --- a/libavcodec/internal.h
> +++ b/libavcodec/internal.h
> @@ -74,6 +74,10 @@
> * uses ff_thread_report/await_progress().
> */
> #define FF_CODEC_CAP_ALLOCATE_PROGRESS (1 << 6)
> +/**
> + * Codec handles avctx->thread_count == 0 (auto) internally.
> + */
> +#define FF_CODEC_CAP_AUTO_THREADS (1 << 7)
>
> /**
> * AVCodec.codec_tags termination value
> diff --git a/libavcodec/libaomdec.c b/libavcodec/libaomdec.c
> index 1430a651fe..327a5e18fb 100644
> --- a/libavcodec/libaomdec.c
> +++ b/libavcodec/libaomdec.c
> @@ -237,6 +237,7 @@ AVCodec ff_libaom_av1_decoder = {
> .close = aom_free,
> .decode = aom_decode,
> .capabilities = AV_CODEC_CAP_AUTO_THREADS | AV_CODEC_CAP_DR1,
> + .caps_internal = FF_CODEC_CAP_AUTO_THREADS,
> .profiles = NULL_IF_CONFIG_SMALL(ff_av1_profiles),
> .wrapper_name = "libaom",
> };
> diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
> index 9a26b5f9ef..f99fdc0b73 100644
> --- a/libavcodec/libaomenc.c
> +++ b/libavcodec/libaomenc.c
> @@ -1346,6 +1346,7 @@ AVCodec ff_libaom_av1_encoder = {
> .encode2 = aom_encode,
> .close = aom_free,
> .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
> + .caps_internal = FF_CODEC_CAP_AUTO_THREADS,
> .profiles = NULL_IF_CONFIG_SMALL(ff_av1_profiles),
> .priv_class = &class_aom,
> .defaults = defaults,
> diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
> index 383e4557b4..93aeab4cb1 100644
> --- a/libavcodec/libdav1d.c
> +++ b/libavcodec/libdav1d.c
> @@ -485,7 +485,8 @@ AVCodec ff_libdav1d_decoder = {
> .flush = libdav1d_flush,
> .receive_frame = libdav1d_receive_frame,
> .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
> - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_SETS_PKT_DTS,
> + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_SETS_PKT_DTS |
> + FF_CODEC_CAP_AUTO_THREADS,
> .priv_class = &libdav1d_class,
> .wrapper_name = "libdav1d",
> };
> diff --git a/libavcodec/libdavs2.c b/libavcodec/libdavs2.c
> index 218f3ec239..f6a03df373 100644
> --- a/libavcodec/libdavs2.c
> +++ b/libavcodec/libdavs2.c
> @@ -222,6 +222,7 @@ AVCodec ff_libdavs2_decoder = {
> .decode = davs2_decode_frame,
> .flush = davs2_flush,
> .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
> + .caps_internal = FF_CODEC_CAP_AUTO_THREADS,
> .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
> AV_PIX_FMT_NONE },
> .wrapper_name = "libdavs2",
> diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c
> index d94cf995c8..f75aa4eda3 100644
> --- a/libavcodec/libkvazaar.c
> +++ b/libavcodec/libkvazaar.c
> @@ -341,7 +341,8 @@ AVCodec ff_libkvazaar_encoder = {
> .encode2 = libkvazaar_encode,
> .close = libkvazaar_close,
>
> - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
> + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP |
> + FF_CODEC_CAP_AUTO_THREADS,
>
> .wrapper_name = "libkvazaar",
> };
> diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
> index cf485663e1..cb5deb8b50 100644
> --- a/libavcodec/libopenh264enc.c
> +++ b/libavcodec/libopenh264enc.c
> @@ -448,7 +448,8 @@ AVCodec ff_libopenh264_encoder = {
> .encode2 = svc_encode_frame,
> .close = svc_encode_close,
> .capabilities = AV_CODEC_CAP_AUTO_THREADS,
> - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
> + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP |
> + FF_CODEC_CAP_AUTO_THREADS,
> .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P,
> AV_PIX_FMT_NONE },
> .defaults = svc_enc_defaults,
> diff --git a/libavcodec/librav1e.c b/libavcodec/librav1e.c
> index 2d5acc7d8e..bd93073664 100644
> --- a/libavcodec/librav1e.c
> +++ b/libavcodec/librav1e.c
> @@ -625,6 +625,6 @@ AVCodec ff_librav1e_encoder = {
> .defaults = librav1e_defaults,
> .pix_fmts = librav1e_pix_fmts,
> .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
> - .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
> + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS,
> .wrapper_name = "librav1e",
> };
> diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c
> index eb6043bcac..4244ae1daa 100644
> --- a/libavcodec/libsvtav1.c
> +++ b/libavcodec/libsvtav1.c
> @@ -561,6 +561,7 @@ AVCodec ff_libsvtav1_encoder = {
> .receive_packet = eb_receive_packet,
> .close = eb_enc_close,
> .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
> + .caps_internal = FF_CODEC_CAP_AUTO_THREADS,
> .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P,
> AV_PIX_FMT_YUV420P10,
> AV_PIX_FMT_NONE },
> diff --git a/libavcodec/libuavs3d.c b/libavcodec/libuavs3d.c
> index d77cc2192d..6bc0ba09f0 100644
> --- a/libavcodec/libuavs3d.c
> +++ b/libavcodec/libuavs3d.c
> @@ -254,6 +254,7 @@ AVCodec ff_libuavs3d_decoder = {
> .close = libuavs3d_end,
> .decode = libuavs3d_decode_frame,
> .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
> + .caps_internal = FF_CODEC_CAP_AUTO_THREADS,
> .flush = libuavs3d_flush,
> .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
> AV_PIX_FMT_YUV420P10LE,
> diff --git a/libavcodec/libvpxdec.c b/libavcodec/libvpxdec.c
> index 3e320446f8..7a1ccde992 100644
> --- a/libavcodec/libvpxdec.c
> +++ b/libavcodec/libvpxdec.c
> @@ -362,6 +362,7 @@ AVCodec ff_libvpx_vp8_decoder = {
> .close = vpx_free,
> .decode = vpx_decode,
> .capabilities = AV_CODEC_CAP_AUTO_THREADS | AV_CODEC_CAP_DR1,
> + .caps_internal = FF_CODEC_CAP_AUTO_THREADS,
> .wrapper_name = "libvpx",
> };
> #endif /* CONFIG_LIBVPX_VP8_DECODER */
> @@ -383,6 +384,7 @@ AVCodec ff_libvpx_vp9_decoder = {
> .close = vpx_free,
> .decode = vpx_decode,
> .capabilities = AV_CODEC_CAP_AUTO_THREADS,
> + .caps_internal = FF_CODEC_CAP_AUTO_THREADS,
> .init_static_data = ff_vp9_init_static,
> .profiles = NULL_IF_CONFIG_SMALL(ff_vp9_profiles),
> .wrapper_name = "libvpx",
> diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> index 02df4fe87b..df79839df5 100644
> --- a/libavcodec/libvpxenc.c
> +++ b/libavcodec/libvpxenc.c
> @@ -1871,6 +1871,7 @@ AVCodec ff_libvpx_vp8_encoder = {
> .encode2 = vpx_encode,
> .close = vpx_free,
> .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
> + .caps_internal = FF_CODEC_CAP_AUTO_THREADS,
> .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVA420P, AV_PIX_FMT_NONE },
> .priv_class = &class_vp8,
> .defaults = defaults,
> @@ -1901,6 +1902,7 @@ AVCodec ff_libvpx_vp9_encoder = {
> .encode2 = vpx_encode,
> .close = vpx_free,
> .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
> + .caps_internal = FF_CODEC_CAP_AUTO_THREADS,
> .profiles = NULL_IF_CONFIG_SMALL(ff_vp9_profiles),
> .priv_class = &class_vp9,
> .defaults = defaults,
> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> index 212ed7d015..8953368b5e 100644
> --- a/libavcodec/libx264.c
> +++ b/libavcodec/libx264.c
> @@ -1204,6 +1204,7 @@ AVCodec ff_libx264_encoder = {
> .close = X264_close,
> .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS |
> AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
> + .caps_internal = FF_CODEC_CAP_AUTO_THREADS,
> .priv_class = &x264_class,
> .defaults = x264_defaults,
> #if X264_BUILD < 153
> @@ -1242,11 +1243,11 @@ AVCodec ff_libx264rgb_encoder = {
> .priv_class = &rgbclass,
> .defaults = x264_defaults,
> .pix_fmts = pix_fmts_8bit_rgb,
> + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS
> #if X264_BUILD >= 158
> - .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE,
> -#else
> - .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
> + | FF_CODEC_CAP_INIT_THREADSAFE
> #endif
> + ,
> .wrapper_name = "libx264",
> };
> #endif
> @@ -1273,7 +1274,7 @@ AVCodec ff_libx262_encoder = {
> .priv_class = &X262_class,
> .defaults = x264_defaults,
> .pix_fmts = pix_fmts_8bit,
> - .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
> + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS,
> .wrapper_name = "libx264",
> };
> #endif
> diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
> index 686c205b6b..d502f47662 100644
> --- a/libavcodec/libx265.c
> +++ b/libavcodec/libx265.c
> @@ -702,5 +702,6 @@ AVCodec ff_libx265_encoder = {
> .defaults = x265_defaults,
> .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS |
> AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
> + .caps_internal = FF_CODEC_CAP_AUTO_THREADS,
> .wrapper_name = "libx265",
> };
> diff --git a/libavcodec/libxavs.c b/libavcodec/libxavs.c
> index 752ff66dfa..12d5a5eb9e 100644
> --- a/libavcodec/libxavs.c
> +++ b/libavcodec/libxavs.c
> @@ -476,6 +476,7 @@ AVCodec ff_libxavs_encoder = {
> .encode2 = XAVS_frame,
> .close = XAVS_close,
> .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
> + .caps_internal = FF_CODEC_CAP_AUTO_THREADS,
> .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
> .priv_class = &xavs_class,
> .defaults = xavs_defaults,
> diff --git a/libavcodec/libxavs2.c b/libavcodec/libxavs2.c
> index 8519f6925a..cd29d2b938 100644
> --- a/libavcodec/libxavs2.c
> +++ b/libavcodec/libxavs2.c
> @@ -295,6 +295,7 @@ AVCodec ff_libxavs2_encoder = {
> .encode2 = xavs2_encode_frame,
> .close = xavs2_close,
> .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
> + .caps_internal = FF_CODEC_CAP_AUTO_THREADS,
> .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
> AV_PIX_FMT_NONE },
> .priv_class = &libxavs2,
> diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c
> index 572471586d..a013784846 100644
> --- a/libavcodec/pthread.c
> +++ b/libavcodec/pthread.c
> @@ -56,7 +56,7 @@ static void validate_thread_parameters(AVCodecContext *avctx)
> } else if (avctx->codec->capabilities & AV_CODEC_CAP_SLICE_THREADS &&
> avctx->thread_type & FF_THREAD_SLICE) {
> avctx->active_thread_type = FF_THREAD_SLICE;
> - } else if (!(avctx->codec->capabilities & AV_CODEC_CAP_AUTO_THREADS)) {
> + } else if (!(avctx->codec->capabilities & FF_CODEC_CAP_AUTO_THREADS)) {
> avctx->thread_count = 1;
> avctx->active_thread_type = 0;
> }
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index b8a8c0ac2e..412e02de72 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -761,7 +761,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
> goto free_and_end;
> }
> }
> - if (!HAVE_THREADS && !(codec->capabilities & AV_CODEC_CAP_AUTO_THREADS))
> + if (!HAVE_THREADS && !(codec->capabilities & FF_CODEC_CAP_AUTO_THREADS))
Shouldn't you check caps_internal here and in the pthread.c change above?
> avctx->thread_count = 1;
>
> if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
>
More information about the ffmpeg-devel
mailing list