From patchwork Tue Mar 9 18:24:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 26287 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id C2EA944A4D7 for ; Tue, 9 Mar 2021 20:25:06 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9656368A78A; Tue, 9 Mar 2021 20:25:06 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C0A4B68A48F for ; Tue, 9 Mar 2021 20:24:59 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 5305E240684 for ; Tue, 9 Mar 2021 19:24:59 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id XNDfZhDrALNL for ; Tue, 9 Mar 2021 19:24:58 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 410DF24048A for ; Tue, 9 Mar 2021 19:24:58 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id CFB9F3A0555; Tue, 9 Mar 2021 19:24:57 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 9 Mar 2021 19:24:52 +0100 Message-Id: <20210309182452.3365-1-anton@khirnov.net> X-Mailer: git-send-email 2.30.0 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavc: replace internal use of AV_CODEC_CAP_AUTO_THREADS with an internal cap X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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. --- Also applied the change to libx264 instance I missed previously --- 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 | 15 ++++++++------- libavcodec/libx265.c | 1 + libavcodec/libxavs.c | 1 + libavcodec/libxavs2.c | 1 + libavcodec/pthread.c | 2 +- libavcodec/utils.c | 2 +- 18 files changed, 33 insertions(+), 13 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..f152e453ce 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 @@ -1211,11 +1212,11 @@ AVCodec ff_libx264_encoder = { #else .pix_fmts = pix_fmts_all, #endif + .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 @@ -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..14b7cca4fe 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->caps_internal & 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..01b603e2ea 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->caps_internal & FF_CODEC_CAP_AUTO_THREADS)) avctx->thread_count = 1; if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {