From patchwork Fri May 22 14:04:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 19806 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 B6E7644A48C for ; Fri, 22 May 2020 17:05:02 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 908F668ACE4; Fri, 22 May 2020 17:05:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (unknown [176.97.15.10]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AA43268A69C for ; Fri, 22 May 2020 17:04:56 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id DF43E28A645 for ; Fri, 22 May 2020 16:04:55 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id pOdx732bY2W4 for ; Fri, 22 May 2020 16:04:54 +0200 (CEST) Received: from quelana.khirnov.net (quelana.khirnov.net [IPv6:2a00:c500:561:200::1]) (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 "quelana.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 9EE6728A485 for ; Fri, 22 May 2020 16:04:54 +0200 (CEST) Received: from localhost (quelana.khirnov.net [IPv6:::1]) by quelana.khirnov.net (Postfix) with ESMTP id 3E38222D8F for ; Fri, 22 May 2020 16:04:54 +0200 (CEST) Received: from quelana.khirnov.net ([IPv6:::1]) by localhost (quelana.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id RgwAKA_i3QES for ; Fri, 22 May 2020 16:04:51 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) by quelana.khirnov.net (Postfix) with ESMTP id 19AB620279 for ; Fri, 22 May 2020 16:04:51 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id 2B64520E008E; Fri, 22 May 2020 16:04:47 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 22 May 2020 16:04:41 +0200 Message-Id: <20200522140441.32421-1-anton@khirnov.net> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [RFC/PATCH] avcodec: deprecate thread_safe_callbacks 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" They add considerable complexity to frame-threading implementation, which includes an unavoidably leaking error path, while the advantages of this option to the users are highly dubious. It should be always possible and desirable for the callers to make their get_buffer2() implementation thread-safe, so deprecate this option. --- The patch is incomplete and not ready to be pushed, I am mainly gathering opinions. Is anyone aware of a valid use case for thread_safe_callbacks? --- libavcodec/avcodec.h | 7 +++++++ libavcodec/utils.c | 13 +++++++++++++ libavcodec/version.h | 3 +++ 3 files changed, 23 insertions(+) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index f10b7a06ec..2dec0d8ca0 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1934,6 +1934,7 @@ typedef struct AVCodecContext { */ int active_thread_type; +#if FF_API_THREAD_SAFE_CALLBACKS /** * Set by the client if its custom get_buffer() callback can be called * synchronously from another thread, which allows faster multithreaded decoding. @@ -1941,8 +1942,14 @@ typedef struct AVCodecContext { * Ignored if the default get_buffer() is used. * - encoding: Set by user. * - decoding: Set by user. + * + * @deprecated the custom get_buffer2() callback should always be + * thread-safe. Thread-unsafe get_buffer2() implementations will be + * invalid once this field is removed. */ + attribute_deprecated int thread_safe_callbacks; +#endif /** * The codec may call this to execute several independent things. diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 3255679550..10d5e552c2 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -673,6 +673,19 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code goto free_and_end; } +#if FF_API_THREAD_SAFE_CALLBACKS +FF_DISABLE_DEPRECATION_WARNINGS + if ((avctx->thread_type & FF_THREAD_FRAME) && + avctx->get_buffer2 != avcodec_default_get_buffer2 && + !avctx->thread_safe_callbacks) { + av_log(avctx, AV_LOG_WARNING, "Requested frame threading with a " + "custom get_buffer2() implementation which is not marked as " + "thread safe. This is not supported anymore, make your " + "callback thread-safe.\n"); + } +FF_ENABLE_DEPRECATION_WARNINGS +#endif + avctx->codec = codec; if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) && avctx->codec_id == AV_CODEC_ID_NONE) { diff --git a/libavcodec/version.h b/libavcodec/version.h index 9fc637313d..5b4dfea579 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -144,6 +144,9 @@ #ifndef FF_API_UNUSED_CODEC_CAPS #define FF_API_UNUSED_CODEC_CAPS (LIBAVCODEC_VERSION_MAJOR < 59) #endif +#ifndef FF_API_THREAD_SAFE_CALLBACKS +#define FF_API_THREAD_SAFE_CALLBACKS (LIBAVCODEC_VERSION_MAJOR < 59) +#endif #endif /* AVCODEC_VERSION_H */