From patchwork Wed Mar 10 12:03:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 26308 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 C6D8D44B739 for ; Wed, 10 Mar 2021 14:03:57 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B49BE68AAD0; Wed, 10 Mar 2021 14:03:57 +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 43D4568A831 for ; Wed, 10 Mar 2021 14:03:50 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id CA8A424068A for ; Wed, 10 Mar 2021 13:03:44 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id m6pbPq_ZMxoD for ; Wed, 10 Mar 2021 13:03:44 +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 0552E240694 for ; Wed, 10 Mar 2021 13:03:42 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 9DB7A3A0427; Wed, 10 Mar 2021 13:03:41 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 13:03:32 +0100 Message-Id: <20210310120332.27225-7-anton@khirnov.net> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210310120332.27225-1-anton@khirnov.net> References: <20210310120332.27225-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 7/7] lavc: do not hold the codec init lock longer than necessary 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" The only potentially unsafe operation is the codec-specific init function. --- libavcodec/utils.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index e0f6234bd7..952adb5277 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -570,8 +570,6 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code if (options) av_dict_copy(&tmp, *options, 0); - lock_avcodec(codec); - avci = av_mallocz(sizeof(*avci)); if (!avci) { ret = AVERROR(ENOMEM); @@ -723,9 +721,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code av_log(avctx, AV_LOG_WARNING, "Warning: not compiled with thread support, using thread emulation\n"); if (CONFIG_FRAME_THREAD_ENCODER && av_codec_is_encoder(avctx->codec)) { - unlock_avcodec(codec); //we will instantiate a few encoders thus kick the counter to prevent false detection of a problem ret = ff_frame_thread_encoder_init(avctx, options ? *options : NULL); - lock_avcodec(codec); if (ret < 0) goto free_and_end; } @@ -749,7 +745,9 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code if ( avctx->codec->init && (!(avctx->active_thread_type&FF_THREAD_FRAME) || avci->frame_thread_encoder)) { + lock_avcodec(codec); ret = avctx->codec->init(avctx); + unlock_avcodec(codec); if (ret < 0) { codec_init_ok = -1; goto free_and_end; @@ -834,7 +832,6 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code } end: - unlock_avcodec(codec); if (options) { av_dict_free(options); *options = tmp;