From patchwork Fri Nov 27 01:02:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 24085 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 EE61E44BB5D for ; Fri, 27 Nov 2020 03:12:02 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3E20E68BB3F; Fri, 27 Nov 2020 03:07:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 566AE68BB5A for ; Fri, 27 Nov 2020 03:07:18 +0200 (EET) Received: by mail-wr1-f65.google.com with SMTP id e7so3948494wrv.6 for ; Thu, 26 Nov 2020 17:07:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=L5fk3keU/me35WyfpdMs66KggxXvt7283EdvsMX8Dlk=; b=JmKtjYBbdQB2BahUVMZftnYR9rq+CUf0frkW0WoKAqvAYv3VNkIuBo8qEn1+K7Pzt8 9ApDE5cvTLfKSShQb5VMHfuVHhvRKpN79LXoHLNpXZEbmvt55CFOoOs/fRQbjhff4h3z HDmfhfmWbELLYFIYrufcS9WNVtMS/7iyEHM1m3XA3B9PpKWC2yxbBtNGTuekPet2nxzH eoSJPALZIuoyiz1iRhNUmFeLqIGlY/ZvvUgMlzcTEDY+4g8gPD9kaxSD2UnOdXmgWyxf 1s+8uk22HYuG1yl0pUBvxm+tNjelDfKT5gITJmrBe5ENQk6Cn66qf/iFzK8fTKH+hhuz vCRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=L5fk3keU/me35WyfpdMs66KggxXvt7283EdvsMX8Dlk=; b=ESqQmBpihbwyZyjgD3BzFcrGiKkU64mh1QYIQbWfvkupkytEBGmI0adjzTfxFWvEfm ROAJmS0EtHJ3nm8IbYg/6i8tor2TslaweOBX0RuU3O+GKZzqm8rWUycv8PCPAom1zRa5 7LgbnUqFd7TiAogx5V7gC8s4CG4Qb5Tq4bxZ/Exl8Ky0VierF8loyzIuVUVcX8QxGLou 5VlIt2X7lbdToXVnmRpZP17pvTQ5SA54qXNRjuizeJ7V58dz1c0peutyd7zEimSP3YU9 Qj3mC9Gmarg4+yS8nyQsaspjNGUvS+V7ELGAHNTfz+FHJRKjWG9Gyn+xll0M+pv8IypE 6U+w== X-Gm-Message-State: AOAM530aFVn5D2aMSDD/BtPcfEPXxHfOCPr7LMg7MqfA4vp5K2oBK0m/ uNlvcNVhNGYyUA+smrP9hJBDYLoJSZTyhg== X-Google-Smtp-Source: ABdhPJyAtgn2ixk2Feh63kG6iRL7zeqFUolMDaLtOAiIZ3wtusde99jKrbomYHrpYfzPfypuXwhMcA== X-Received: by 2002:adf:9287:: with SMTP id 7mr7060390wrn.370.1606439237658; Thu, 26 Nov 2020 17:07:17 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id l8sm10504450wro.46.2020.11.26.17.07.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Nov 2020 17:07:17 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Nov 2020 02:02:41 +0100 Message-Id: <20201127010249.2724610-37-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201127010249.2724610-1-andreas.rheinhardt@gmail.com> References: <20201127010249.2724610-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 37/45] avcodec: Fix invalid uses of ff_codec_open2_recursive() 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Normally no two codecs with FF_CODEC_CAP_INIT_THREADSAFE unset can be initialized at the same time: a mutex in avcodec_open2() ensures this. This implies that one cannot simply open a codec with a non-threadsafe init-function from the init function of a codec whose own init function is not threadsafe either as the child codec couldn't acquire the lock. ff_codec_open2_recursive() exists to get around this limitation: If the init function of the child codec to be initialized is not thread-safe, the mutex is unlocked, the child is initialized and the mutex is locked again. This of course has as a prerequisite that the parent AVCodecContext actually holds the lock, i.e. that the parent codec's init function is not thread-safe. If it is, then one can (and has to) just use avcodec_open2() directly (if the child's init function is not thread-safe, then avcodec_open2() will have to acquire the mutex itself (and potentially wait for it), so that it is perfectly fine for an otherwise thread-safe init function to open a codec with a potentially non-thread-safe init function via avcodec_open2()). Yet several of the users of ff_codec_open2_recursive() have the FF_CODEC_CAP_INIT_THREADSAFE flag set; this only worked because all the child codecs' init functions were thread-safe themselves so that ff_codec_open2_recursive() didn't touch the mutex at all. But of course the real solution to this is to directly use avcodec_open2(). Signed-off-by: Andreas Rheinhardt --- libavcodec/avrndec.c | 2 +- libavcodec/imm5.c | 4 ++-- libavcodec/tdsc.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/avrndec.c b/libavcodec/avrndec.c index c5a60acd4f..d85e3c2000 100644 --- a/libavcodec/avrndec.c +++ b/libavcodec/avrndec.c @@ -65,7 +65,7 @@ static av_cold int init(AVCodecContext *avctx) a->mjpeg_avctx->width = avctx->width; a->mjpeg_avctx->height = avctx->height; - if ((ret = ff_codec_open2_recursive(a->mjpeg_avctx, codec, &thread_opt)) < 0) { + if ((ret = avcodec_open2(a->mjpeg_avctx, codec, &thread_opt)) < 0) { av_log(avctx, AV_LOG_ERROR, "MJPEG codec failed to open\n"); } av_dict_free(&thread_opt); diff --git a/libavcodec/imm5.c b/libavcodec/imm5.c index 917b414e66..5f8faa4dd0 100644 --- a/libavcodec/imm5.c +++ b/libavcodec/imm5.c @@ -63,7 +63,7 @@ static av_cold int imm5_init(AVCodecContext *avctx) ctx->h264_avctx->thread_count = 1; ctx->h264_avctx->flags = avctx->flags; ctx->h264_avctx->flags2 = avctx->flags2; - ret = ff_codec_open2_recursive(ctx->h264_avctx, codec, NULL); + ret = avcodec_open2(ctx->h264_avctx, codec, NULL); if (ret < 0) return ret; @@ -76,7 +76,7 @@ static av_cold int imm5_init(AVCodecContext *avctx) ctx->hevc_avctx->thread_count = 1; ctx->hevc_avctx->flags = avctx->flags; ctx->hevc_avctx->flags2 = avctx->flags2; - ret = ff_codec_open2_recursive(ctx->hevc_avctx, codec, NULL); + ret = avcodec_open2(ctx->hevc_avctx, codec, NULL); if (ret < 0) return ret; diff --git a/libavcodec/tdsc.c b/libavcodec/tdsc.c index dfd80f6dbc..7c888b6ec8 100644 --- a/libavcodec/tdsc.c +++ b/libavcodec/tdsc.c @@ -125,7 +125,7 @@ static av_cold int tdsc_init(AVCodecContext *avctx) ctx->jpeg_avctx->flags2 = avctx->flags2; ctx->jpeg_avctx->dct_algo = avctx->dct_algo; ctx->jpeg_avctx->idct_algo = avctx->idct_algo; - ret = ff_codec_open2_recursive(ctx->jpeg_avctx, codec, NULL); + ret = avcodec_open2(ctx->jpeg_avctx, codec, NULL); if (ret < 0) return ret;