From patchwork Fri Nov 20 07:19:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23815 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 5C5E444AFE3 for ; Fri, 20 Nov 2020 09:35:21 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DBEF768BB46; Fri, 20 Nov 2020 09:25:23 +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 A24D768BB29 for ; Fri, 20 Nov 2020 09:25:11 +0200 (EET) Received: by mail-ed1-f65.google.com with SMTP id l5so8453302edq.11 for ; Thu, 19 Nov 2020 23:25:11 -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=s0+iFVivPwOS6nYG3yKHBgLufttVbFUEKMbfd0hI90Q=; b=WIEw8SVU8AaMvYk2MWKF62EH8HGG5rd7mZOx+/appVwE9RbqI3rOGZlbQ/MtCJZYGV 9T6Ix3CUDDUjCg43RGKN1HspY0vZmcukKc3NajPdNpmBicCKZGSp9jllmcTBhvnBX59R sA3Ig8Sm0a8tJGDGsYZqjKEgG6IOovZzT36zNWDz5moSgnjF40nj6JnE2Ll+CzU4g1mX Rj0fxvkjfVOHG6qdLpRtHwg+b+uWMqHQWdmM8u/8Sc1jMkv7MLVg+h0f5ozURHjPBm1b x1GozGY94eGsqRMDXa2A2nYVXhPRQSqa9mShVP/hFl/ewPYLlQL7aQy5PBj8ttXoWbnH pEnQ== 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=s0+iFVivPwOS6nYG3yKHBgLufttVbFUEKMbfd0hI90Q=; b=EwWszzP8kcXY+cIx+pb95r43vPRCLzJt4Y4dezh3FMiNNz9niMU/qqXqk3WGNsURGO s8BFvrqPMCUmfIUbnVWPT6L4PPCl/hhtFwbDIVkWgaQYAmISTAGsH716iuc9ckm/Qems WwwOw1BWAspdDJwKOWTeDDbR+M+g+Xmxfzp/L3A9b8XrJ+s7XAquAOhSOvRbR6ktSl7r MOyKZhCQxbdZDDGjtye7r6bROgaCuffhL9GnORThVYIqgqc3GeqhRFy/MLhrKzyddJli fAq88d1ox7RooOO6cj3bHeSIsioMJdIrzaUTINZhVoWC8l3797RscZVCZXIaZiQ9mVWb w53Q== X-Gm-Message-State: AOAM53062kGyf0jHujxSKHTqTVCPDxqNKsfw62lRGHvQLVwKk+tZ5+Z2 /E84uG9GQ1lLRkg1+/vQc4P3E5rKtkqUpA== X-Google-Smtp-Source: ABdhPJywYNby6usYTZf/xlD78621AQXW1r4RUui4c6C0swOA/4qIuCj0e44XZLLGEauENDYPbhBjuA== X-Received: by 2002:aa7:cdd9:: with SMTP id h25mr34497393edw.294.1605857110739; Thu, 19 Nov 2020 23:25:10 -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.25.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 23:25:10 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Nov 2020 08:19:33 +0100 Message-Id: <20201120072116.818090-61-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 060/162] avcodec/mpc8: 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" Signed-off-by: Andreas Rheinhardt --- libavcodec/mpc8.c | 62 +++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/libavcodec/mpc8.c b/libavcodec/mpc8.c index c263762c8b..6939716176 100644 --- a/libavcodec/mpc8.c +++ b/libavcodec/mpc8.c @@ -27,6 +27,7 @@ #include "libavutil/channel_layout.h" #include "libavutil/lfg.h" +#include "libavutil/thread.h" #include "avcodec.h" #include "get_bits.h" #include "internal.h" @@ -107,15 +108,40 @@ static av_cold void build_vlc(VLC *vlc, unsigned *buf_offset, *syms += num; } -static av_cold int mpc8_decode_init(AVCodecContext * avctx) +static av_cold void mpc8_init_static(void) { - int i, offset = 0; - MPCContext *c = avctx->priv_data; - GetBitContext gb; - static int vlc_initialized = 0; const uint8_t *q_syms = mpc8_q_syms, *bands_syms = mpc8_bands_syms; const uint8_t *res_syms = mpc8_res_syms, *scfi_syms = mpc8_scfi_syms; const uint8_t *dscf_syms = mpc8_dscf_syms; + unsigned offset = 0; + + build_vlc(&band_vlc, &offset, mpc8_bands_len_counts, &bands_syms, 0); + + build_vlc(&q1_vlc, &offset, mpc8_q1_len_counts, &q_syms, 0); + build_vlc(&q9up_vlc, &offset, mpc8_q9up_len_counts, &q_syms, 0); + + for (int i = 0; i < 2; i++){ + build_vlc(&scfi_vlc[i], &offset, mpc8_scfi_len_counts[i], &scfi_syms, 0); + + build_vlc(&dscf_vlc[i], &offset, mpc8_dscf_len_counts[i], &dscf_syms, 0); + + build_vlc(&res_vlc[i], &offset, mpc8_res_len_counts[i], &res_syms, 0); + + build_vlc(&q2_vlc[i], &offset, mpc8_q2_len_counts[i], &q_syms, 0); + build_vlc(&q3_vlc[i], &offset, mpc8_q34_len_counts[i], + &q_syms, -48 - 16 * i); + for (int j = 0; j < 4; j++) + build_vlc(&quant_vlc[j][i], &offset, mpc8_q5_8_len_counts[i][j], + &q_syms, -((8 << j) - 1)); + } + ff_mpa_synth_init_fixed(); +} + +static av_cold int mpc8_decode_init(AVCodecContext * avctx) +{ + static AVOnce init_static_once = AV_ONCE_INIT; + MPCContext *c = avctx->priv_data; + GetBitContext gb; int channels; if(avctx->extradata_size < 2){ @@ -146,30 +172,7 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx) avctx->channel_layout = (channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO; avctx->channels = channels; - if(vlc_initialized) return 0; - av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n"); - - build_vlc(&band_vlc, &offset, mpc8_bands_len_counts, &bands_syms, 0); - - build_vlc(&q1_vlc, &offset, mpc8_q1_len_counts, &q_syms, 0); - build_vlc(&q9up_vlc, &offset, mpc8_q9up_len_counts, &q_syms, 0); - - for(i = 0; i < 2; i++){ - build_vlc(&scfi_vlc[i], &offset, mpc8_scfi_len_counts[i], &scfi_syms, 0); - - build_vlc(&dscf_vlc[i], &offset, mpc8_dscf_len_counts[i], &dscf_syms, 0); - - build_vlc(&res_vlc[i], &offset, mpc8_res_len_counts[i], &res_syms, 0); - - build_vlc(&q2_vlc[i], &offset, mpc8_q2_len_counts[i], &q_syms, 0); - build_vlc(&q3_vlc[i], &offset, mpc8_q34_len_counts[i], - &q_syms, -48 - 16 * i); - for (int j = 0; j < 4; j++) - build_vlc(&quant_vlc[j][i], &offset, mpc8_q5_8_len_counts[i][j], - &q_syms, -((8 << j) - 1)); - } - vlc_initialized = 1; - ff_mpa_synth_init_fixed(); + ff_thread_once(&init_static_once, mpc8_init_static); return 0; } @@ -392,4 +395,5 @@ AVCodec ff_mpc8_decoder = { .capabilities = AV_CODEC_CAP_DR1, .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_NONE }, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, };