From patchwork Mon Nov 23 19:37:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23994 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 8DCB344A49B for ; Mon, 23 Nov 2020 21:38:27 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6D3E768BBDD; Mon, 23 Nov 2020 21:38:27 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CE4BC68BBCC for ; Mon, 23 Nov 2020 21:38:19 +0200 (EET) Received: by mail-wr1-f66.google.com with SMTP id g14so4598509wrm.13 for ; Mon, 23 Nov 2020 11:38:19 -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=Na8JO5jEg538zOIvatD8OWRnguI0JUZUV41TSIQPysM=; b=FoAddYS6jj7T8X9J0JSBJqR5vJbuvQCSvzAlsSy13wp7xoMTFGARVJeCnmfqrEtZld X0qX37TSQ45YF4FBJdfxZnMm6VNrNU/LRamQIgLHjAfGVD+DpW7Dmn3xS3r07qW161zd 5J1ahpb2pYe7A1kzHlsTQ/y6UipHjNnzGcsVN6/MYkHDbX+Q5nI+WdVpBOKUGKvTJd8+ abxSjPTVmz2jQJvsMTLX4pe1Ce8zXlPjYR2z14a/uJD5Be6eHRyrVqVNIGFp03jReAue 7q8PafmRr0IamQNrQwb80xj4hkiYO8vS+mKdio2yKa96GfIw2V0Wg3NRiIyWP2DXmJul ZoQA== 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=Na8JO5jEg538zOIvatD8OWRnguI0JUZUV41TSIQPysM=; b=IHfepGohemeh9+7TKO2UOLIbjVo2d/mf6wQJq2XfvgKXhsAU4OeYYllNU+PNnJxj0Y KdpbpddQ87M26zjER84dfuxEYfrivCPYe1ll8rhdED5KzSjV+PLdgKI5LDuRU1dT8zGz A3y/VG/rTPBPfWRlqfVOLHodoIafxRxPj1pRmeB3L5Kr147dqlD1rttGQiL+tnx8OGQF P7KRqTe7zugiBkvM83WSfm7AJdp3J/Q5i3lepXWTKlIspQ0X9T9D/iWBIKTe8bCiEtjL /Q9KRRFm1G/G+aj1VasZwju587iBF1dAgboySWJRUCBjBTW7zRdj4hU3BIU1ucUerk6B difQ== X-Gm-Message-State: AOAM532ULjCDPZWDAmqNLnR1kZwJEhw2vv0+vag15DNLOmPzKpah5+ii xQJr3Zlo2G285bEiWYXiDvy4i2xVId9zCg== X-Google-Smtp-Source: ABdhPJwkHLWgPIaWBeVDjIL0GRAvHNmFL6Vob/2WIyg0L7/K/tZY/ZjjAzgYa9zbaWyLchxctz9MGA== X-Received: by 2002:adf:a3ca:: with SMTP id m10mr1321049wrb.228.1606160299048; Mon, 23 Nov 2020 11:38:19 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id e6sm564086wme.27.2020.11.23.11.38.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 11:38:18 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 23 Nov 2020 20:37:24 +0100 Message-Id: <20201123193739.1249300-14-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 176/191] avcodec/aactab: Make AAC encoder and decoders actually 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" Commit 1a29804558c13ef512d9ef73a9b0d782af4fa5f2 guarded several initializations of static data in the AAC decoders with an AVOnce and set the FF_CODEC_CAP_INIT_THREADSAFE flag, believing the former to be sufficient for the latter. It wasn't, because several of these static tables are shared with other components, so that there might be data races if they are initialized from multiple threads. This affected initializing the ff_sine_* tables as well as initializing the ff_aac_pow*sf_tab tables (shared between both decoders and encoder) as well as ff_aac_kbd_* tables (shared between encoder and floating point decoder). Commit 3d62e7a30fa552be52d12b31e3e0f79153aff891 set the FF_CODEC_CAP_INIT_THREADSAFE flag for the AAC encoder. More explicitly, this commit used the same AVOnce to guard initializing ff_aac_pow*sf_tab in the encoder and to guard initializing the static data of each decoder; the ensuing catastrophe was "fixed" in commit ec0719264cb9a9d5cbaf225da48929aea24997a3 by using a single AVOnce for each codec again. But the codec cap has not been removed and therefore the encoder claimed to be init-threadsafe, but wasn't, because of the same tables as above. The ff_sine_* tables as well as ff_aac_pow*sf_tab tables have already been fixed; this commit deals with the ff_aac_kbd_* tables, making the encoder as well as the floating-point decoder init-threadsafe (the fixed-point decoder is it already). Signed-off-by: Andreas Rheinhardt --- libavcodec/aactab.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libavcodec/aactab.c b/libavcodec/aactab.c index b9d1336d97..abe5fd7567 100644 --- a/libavcodec/aactab.c +++ b/libavcodec/aactab.c @@ -45,13 +45,19 @@ float ff_aac_pow34sf_tab[428]; DECLARE_ALIGNED(32, float, ff_aac_kbd_long_1024)[1024]; DECLARE_ALIGNED(32, float, ff_aac_kbd_short_128)[128]; -av_cold void ff_aac_float_common_init(void) +static av_cold void aac_float_common_init(void) { ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); ff_init_ff_sine_windows(10); ff_init_ff_sine_windows(7); } + +av_cold void ff_aac_float_common_init(void) +{ + static AVOnce init_static_once = AV_ONCE_INIT; + ff_thread_once(&init_static_once, aac_float_common_init); +} #endif const uint8_t ff_aac_num_swb_1024[] = {