From patchwork Fri Nov 20 07:33:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23908 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 605B744AB03 for ; Fri, 20 Nov 2020 09:54:58 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 31E9E68BDAC; Fri, 20 Nov 2020 09:35:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DE76768BCF1 for ; Fri, 20 Nov 2020 09:35:01 +0200 (EET) Received: by mail-ed1-f65.google.com with SMTP id t9so8494404edq.8 for ; Thu, 19 Nov 2020 23:35:01 -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=kVoS/eviu9eDF2hezAx6m8lvxGMmu5if0jfbxhoNp7g=; b=Tm8/3I930iNpEoIrRP1h7N4yBA/T35x2T7BSVG9DRtT0gQvU6HDjEGsCiHli9G+CeL Qx6ewetwIKIMOum2M/kxexQu+YXgscLwQFAEslM8tEnw2KaNIGJzvIoEU6eCTH6M4iLf tARUEYNYHkMurDjwpsgHh21D2sLvSKuQ2XxECxTZ6XC0GsVSOd4rSId85fScnBETPBI3 z5q7LEw0ad16bbn5oyPSz+47uJsBdSJkRoOItaUJMLOqafzpBGh/KLC0CBGtIyDWuSny MYFLWyDBp0tH8GLnEFviX4dX27DI/lrx70uh6UBkQNOD6BOFC3NVG2wRGEMhu6IofkgN /vmQ== 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=kVoS/eviu9eDF2hezAx6m8lvxGMmu5if0jfbxhoNp7g=; b=U4XA4skeZA0f+Z1h0UpUfAe0Yd1viVM/zqkSmif954SibPg6gKxOOliAL205rbiA8T 7v/u9IOQEcfMyNmr0h0CVvV4AVKOCjXutUNROWa1nZX7LRQ071nmaYVtfMy3Cu7T+/zG c9G4z96/05AZNwh4Z/dIvMSuWLEmoXOw10ZjhYPLH830DDGOrN61U8K+YOkayN6XJ5h8 R+y6ugJlx43+opQ8mpKOS9D1QklICrvXTTdEczqCO/5HW4NUhMZhIWITQ59+iD6UGJ++ p3u2WmqLipFXy3WkjRz10jwRRRC+Lgzv8xxXsJIP59o/a6H0FNQCabyldDQKSsjown/3 1yMQ== X-Gm-Message-State: AOAM533kN+pIFxlIMrNdZJX1XUsSmrR1UyXizCCsWbfpnFmoUTc3cKz+ +i/F4BybXM3HaGyhGE9gZGblYl8k3eZrQQ== X-Google-Smtp-Source: ABdhPJxxXXvEEm9OwWCA/bffoBbTRX3hjLVoDKEnydwi+qzF+5th53Nf7NcIj6ee9QUNu8NPIuneOQ== X-Received: by 2002:a05:6402:22af:: with SMTP id cx15mr33260985edb.207.1605857701112; Thu, 19 Nov 2020 23:35:01 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id i13sm769110ejv.84.2020.11.19.23.34.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 23:35:00 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Nov 2020 08:33:21 +0100 Message-Id: <20201120073327.820745-57-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 156/162] avcodec/mpegaudiodec: Make decoders 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" Simple now that ff_mpadsp_init() and ff_mpa_synth_init_* are thread-safe. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegaudiodec_fixed.c | 6 +++++- libavcodec/mpegaudiodec_float.c | 6 +++++- libavcodec/mpegaudiodec_template.c | 10 ++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/libavcodec/mpegaudiodec_fixed.c b/libavcodec/mpegaudiodec_fixed.c index a2c433954b..853c55528d 100644 --- a/libavcodec/mpegaudiodec_fixed.c +++ b/libavcodec/mpegaudiodec_fixed.c @@ -52,6 +52,7 @@ AVCodec ff_mp1_decoder = { .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE }, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, }; #endif #if CONFIG_MP2_DECODER @@ -68,6 +69,7 @@ AVCodec ff_mp2_decoder = { .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE }, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, }; #endif #if CONFIG_MP3_DECODER @@ -84,6 +86,7 @@ AVCodec ff_mp3_decoder = { .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE }, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, }; #endif #if CONFIG_MP3ADU_DECODER @@ -100,6 +103,7 @@ AVCodec ff_mp3adu_decoder = { .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE }, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, }; #endif #if CONFIG_MP3ON4_DECODER @@ -116,6 +120,6 @@ AVCodec ff_mp3on4_decoder = { .flush = flush_mp3on4, .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_NONE }, - .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE, }; #endif diff --git a/libavcodec/mpegaudiodec_float.c b/libavcodec/mpegaudiodec_float.c index 4aa52d4f53..88438ea21a 100644 --- a/libavcodec/mpegaudiodec_float.c +++ b/libavcodec/mpegaudiodec_float.c @@ -52,6 +52,7 @@ AVCodec ff_mp1float_decoder = { .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_NONE }, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, }; #endif #if CONFIG_MP2FLOAT_DECODER @@ -68,6 +69,7 @@ AVCodec ff_mp2float_decoder = { .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_NONE }, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, }; #endif #if CONFIG_MP3FLOAT_DECODER @@ -84,6 +86,7 @@ AVCodec ff_mp3float_decoder = { .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_NONE }, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, }; #endif #if CONFIG_MP3ADUFLOAT_DECODER @@ -100,6 +103,7 @@ AVCodec ff_mp3adufloat_decoder = { .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_NONE }, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, }; #endif #if CONFIG_MP3ON4FLOAT_DECODER @@ -116,6 +120,6 @@ AVCodec ff_mp3on4float_decoder = { .flush = flush_mp3on4, .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE }, - .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE, }; #endif diff --git a/libavcodec/mpegaudiodec_template.c b/libavcodec/mpegaudiodec_template.c index b03f7cfc33..1faaa0ae52 100644 --- a/libavcodec/mpegaudiodec_template.c +++ b/libavcodec/mpegaudiodec_template.c @@ -30,6 +30,7 @@ #include "libavutil/crc.h" #include "libavutil/float_dsp.h" #include "libavutil/libm.h" +#include "libavutil/thread.h" #include "avcodec.h" #include "get_bits.h" #include "internal.h" @@ -405,14 +406,9 @@ static av_cold void decode_init_static(void) static av_cold int decode_init(AVCodecContext * avctx) { - static int initialized_tables = 0; + static AVOnce init_static_once = AV_ONCE_INIT; MPADecodeContext *s = avctx->priv_data; - if (!initialized_tables) { - decode_init_static(); - initialized_tables = 1; - } - s->avctx = avctx; #if USE_FLOATS @@ -438,6 +434,8 @@ static av_cold int decode_init(AVCodecContext * avctx) if (avctx->codec_id == AV_CODEC_ID_MP3ADU) s->adu_mode = 1; + ff_thread_once(&init_static_once, decode_init_static); + return 0; }