From patchwork Fri Nov 20 07:19:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23955 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:c00a:0:0:0:0:0 with SMTP id c10csp953054ybf; Thu, 19 Nov 2020 23:32:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJyLP3rYMDHEdpVwP25RSexCimqRvGpF+9MU31xJmaxLkQ4qdwbm0i/t5L2t5ud9ErFEHd/m X-Received: by 2002:a1c:7213:: with SMTP id n19mr8169930wmc.36.1605857573736; Thu, 19 Nov 2020 23:32:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605857573; cv=none; d=google.com; s=arc-20160816; b=qDvawZHBgZxp/TOcgixfunWpwBEIs4M4LfBbz+MKnf5VT6a0oDVEzh0ra0ux8BHKsb 6wwWTjxtQIwTMscoS6Z57DtxJ0B6Tf44uXJ72fFFx6dbo0ZG04KmF8E215A4tHBMmUBt ycEPUkCphtmFoDau9Sy6vSnHsYZlgAbiWmEPXZY/lJ968HjLg1f12JwnVPKgjCMYZxUa jXwi+pIiRpCxZeThP02asoNuZqC/FD8GSwOxjz2heeKv4oCgyjV5nVO9bg3Uz3Hplux3 0gA3f4PlKM843BVhlmb91T1XQCbwf1YHRl+AfZgso2ldNE/3wJS0qohjqHQ0eVl/X2z2 5GfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=Igc6sugHLmKZpJKjFWgYFXgkZRWvuwBUkLDbd5Fh1bE=; b=cNpfKQWLgfhnGrWUu9bq8A1oR1JDgczIlKm1qkVrME86Gk5Q9ZHSbW6UWnqOlTToGW qV+YCFzztIZ80r+Jem4DoNWHHPyUJ6ehHRdYHQ/KwBD1fPJcvoGaWXfxiRulQYmgnDQH zx2i2ZEUvfag1HdmkpiYo/iXjNY9Uda7w/8VXAWC1zUP4zbZHaYgeLDq0XTyr2IwLFzL Xkx70RefsBRaHQMIqdhRS8tMoqKxtX0zbFHcXZx8qisKeUtCnU4krUyntCY0V5dbjrxa +SQg7pPLsQN7w7q6oDOW6Sbxh0jzNoKsC0vssME9rIy2PYMAOsQvd36wkkMnbLyGQPuF 39uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=iyphQvKv; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id r15si1988112wrc.73.2020.11.19.23.32.53; Thu, 19 Nov 2020 23:32:53 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=iyphQvKv; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D458668BB18; Fri, 20 Nov 2020 09:25:10 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3BBE568BA96 for ; Fri, 20 Nov 2020 09:24:56 +0200 (EET) Received: by mail-ed1-f68.google.com with SMTP id t11so8444576edj.13 for ; Thu, 19 Nov 2020 23:24:56 -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:reply-to :mime-version:content-transfer-encoding; bh=HIzgKoQZ3nYbCFBYOione7jDywAp9ctLnoCwEsqQMb8=; b=iyphQvKvn2UdZcPyzcnvbCkdnL+BH6ffAEeeljbsof4Ag20wa4SiTswB+9d6wPRxD4 +qMsz/jFc85AiUfXLprYq/57PdruLJxTgSlmX9v6MXkRvH1ChjaxPUnAiDz08XTCGds/ KAlk83g8ZO1DN2l+81GgGe6PruXpM4/XTZw39HljeNLkbaC6gpD8d7muzOs6bTeKb53H yUvPCRwCjtvBmPtYSg1q/RgiWhdT0RIAQPRaRalwsKo0z2YXDqGjPIDoN8Kjs0dJrfOJ NNKBm/J9a2aww0sYZ8R8koPBPziYfR5ZE7PmAJdyoQym5SHyF5ZTjl/rHWp6Qk04eewl 7cHw== 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:reply-to:mime-version:content-transfer-encoding; bh=HIzgKoQZ3nYbCFBYOione7jDywAp9ctLnoCwEsqQMb8=; b=GctSml1aWw08kT30rDlQAr9HOke8AyKhwQasZfDwc7rMJO8G222Z/B6cEZJl5Qdx6L bDnC9CSGH+FH3pIFY/ndoqv690a+c7gf/1h0UnhZTGTUs2AqcUQ9o5SZP+fqLKw3upPj MoF/MbViRyyEB4XrWCw3exmaYffMIAd/0Wtu3I2TW7Ad7W+uYvEDF9PnOg49NsS9RADF h682QVnGLRwWKRacz9LpHSrnJvhfWcZdBpVt9xtUE0vSu2Lh/ilQIUUlww8QESeCBVBs oL1kI5R+bjJ/n8veV9D6DpFyVQkq89hw+lMfPZK5tBt26UfnrglNB+Aak42+mtIYcp7G 2CKQ== X-Gm-Message-State: AOAM531cUm2NHiIJYRx9fgx2taUPgUvSGq665+SGNqDSXGDouVccrqqr N3en/3tYXrNYvocwEDnkJHaex20ByxXqHw== X-Received: by 2002:a50:99d6:: with SMTP id n22mr35160291edb.261.1605857095489; Thu, 19 Nov 2020 23:24:55 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id lz27sm779419ejb.39.2020.11.19.23.24.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 23:24:54 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Nov 2020 08:19:18 +0100 Message-Id: <20201120072116.818090-46-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201120072116.818090-1-andreas.rheinhardt@gmail.com> References: <20201120072116.818090-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 045/162] avcodec/motionpixels: Make decoder init-threadsafe 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" X-TUID: XhMNFqnKoKmc Content-Length: 3445 Signed-off-by: Andreas Rheinhardt --- libavcodec/motionpixels.c | 12 ++++++++++-- libavcodec/motionpixels_tablegen.h | 3 +-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/libavcodec/motionpixels.c b/libavcodec/motionpixels.c index 22deb9d1bd..b08a2f624b 100644 --- a/libavcodec/motionpixels.c +++ b/libavcodec/motionpixels.c @@ -19,6 +19,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/thread.h" + +#include "config.h" + #include "avcodec.h" #include "get_bits.h" #include "bswapdsp.h" @@ -64,6 +68,7 @@ static av_cold int mp_decode_end(AVCodecContext *avctx) static av_cold int mp_decode_init(AVCodecContext *avctx) { + av_unused static AVOnce init_static_once = AV_ONCE_INIT; MotionPixelsContext *mp = avctx->priv_data; int w4 = (avctx->width + 3) & ~3; int h4 = (avctx->height + 3) & ~3; @@ -73,7 +78,6 @@ static av_cold int mp_decode_init(AVCodecContext *avctx) return AVERROR_INVALIDDATA; } - motionpixels_tableinit(); mp->avctx = avctx; ff_bswapdsp_init(&mp->bdsp); mp->changes_map = av_mallocz_array(avctx->width, h4); @@ -88,6 +92,10 @@ static av_cold int mp_decode_init(AVCodecContext *avctx) if (!mp->frame) return AVERROR(ENOMEM); +#if !CONFIG_HARDCODED_TABLES + ff_thread_once(&init_static_once, motionpixels_tableinit); +#endif + return 0; } @@ -347,5 +355,5 @@ AVCodec ff_motionpixels_decoder = { .close = mp_decode_end, .decode = mp_decode_frame, .capabilities = AV_CODEC_CAP_DR1, - .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE, }; diff --git a/libavcodec/motionpixels_tablegen.h b/libavcodec/motionpixels_tablegen.h index 9239b6a667..fd10c80cba 100644 --- a/libavcodec/motionpixels_tablegen.h +++ b/libavcodec/motionpixels_tablegen.h @@ -84,8 +84,7 @@ static av_cold void mp_build_rgb_yuv_table(YuvPixel *p) static av_cold void motionpixels_tableinit(void) { - if (!mp_rgb_yuv_table[0].u) - mp_build_rgb_yuv_table(mp_rgb_yuv_table); + mp_build_rgb_yuv_table(mp_rgb_yuv_table); } #endif /* CONFIG_HARDCODED_TABLES */