From patchwork Mon Nov 23 19:37:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23995 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 0781A44A49B for ; Mon, 23 Nov 2020 21:38:29 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E15A968BC0C; Mon, 23 Nov 2020 21:38:28 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6D0A768BB97 for ; Mon, 23 Nov 2020 21:38:15 +0200 (EET) Received: by mail-wm1-f67.google.com with SMTP id 10so318587wml.2 for ; Mon, 23 Nov 2020 11:38:15 -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=jXhAXZoiqJ/8WQ9CNsUe76xZ3cFx43bws9/cBqyaf7o=; b=rwCLIWFiy9Q3L/fshldFN0dOMR9r+9a1HFa3mwA4GsnlFuYCL0iauUVWAxFb/UtVGk U9BQ3ZT6ZalxslhthQayl4uzDsSxN2B3aMahcT0uaFXUYRQKgBxV8+cE687kth0JKMkN 4xLGdlEy8h0waPjZIVQqP4N1v5LieBEIyuWbuW5jB4MlkxtSliS4dq2KEiOK0ZFmjd1u OtvMsFfjnmcOV9K3af8YyIXWo4+YRcE/WKp5cX2ISdKv5FtsnEI9EHMRNfleFvllbOxl 5J8TijHlWajhuBMk6Cb3dQvlSt0iKvdBMdrAFDOioMJJ34U/RZ12KuDFlzzeX/1vbTUM UlJQ== 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=jXhAXZoiqJ/8WQ9CNsUe76xZ3cFx43bws9/cBqyaf7o=; b=Mgqa/672K0hJvBoWEY91FlCOIjB+/feybuH7fWabJ1nYrWKKNbCjQVf6zPdHG2uGNv u+FJxQPSGN6BIm6yUIsn+5EI2D4U/sqKPyksW6PcWz5JXAn751MjxebOAt+CdcJ7VBh4 sWV/PdQd8VQk6hKzwNWVx1FYmoYtjBgsUYZ5RgU9TA6rw+vHfwTcT8jnPMPNbif432TL alR8RddJwDTUQLWCYtS9sAkazCpxkY1IDmNYaFIXMqQwZtNLpXPfok5m4H/Rsd4RPvIO HQ8atJTUaNB2044Vtd4RpbfWQmJ1iN2pnpfxxrKKTeKLV6MORu5ITI7XsB9Jlu/cTXxr WIwA== X-Gm-Message-State: AOAM531bQYtzCRwwP2KmYWZfv5nQRdUsxapa/Sd61yu4yPtpjd3cAh8z IBz2oep0LJTKigKAHl9pfgLcAMS5C1tc5g== X-Google-Smtp-Source: ABdhPJyWXNz4lx6aAChMqwqBl+PpV7xeFQ3JxsP5030w0yRt0kIFoXv69oycODQUARrV+s0V4YASnQ== X-Received: by 2002:a1c:309:: with SMTP id 9mr476123wmd.80.1606160294682; Mon, 23 Nov 2020 11:38:14 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 11:38:14 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 23 Nov 2020 20:37:20 +0100 Message-Id: <20201123193739.1249300-10-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 172/191] avcodec/nellymoserenc: Make encoder 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/nellymoserenc.c | 41 ++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/libavcodec/nellymoserenc.c b/libavcodec/nellymoserenc.c index e5c9806be8..aea9fe286c 100644 --- a/libavcodec/nellymoserenc.c +++ b/libavcodec/nellymoserenc.c @@ -38,6 +38,7 @@ #include "libavutil/common.h" #include "libavutil/float_dsp.h" #include "libavutil/mathematics.h" +#include "libavutil/thread.h" #include "audio_frame_queue.h" #include "avcodec.h" @@ -147,10 +148,29 @@ static av_cold int encode_end(AVCodecContext *avctx) return 0; } +static av_cold void nellymoser_init_static(void) +{ + /* faster way of doing + for (int i = 0; i < POW_TABLE_SIZE; i++) + pow_table[i] = 2^(-i / 2048.0 - 3.0 + POW_TABLE_OFFSET); */ + pow_table[0] = 1; + pow_table[1024] = M_SQRT1_2; + for (int i = 1; i < 513; i++) { + double tmp = exp2(-i / 2048.0); + pow_table[i] = tmp; + pow_table[1024-i] = M_SQRT1_2 / tmp; + pow_table[1024+i] = tmp * M_SQRT1_2; + pow_table[2048-i] = 0.5 / tmp; + } + /* Generate overlap window */ + ff_init_ff_sine_windows(7); +} + static av_cold int encode_init(AVCodecContext *avctx) { + static AVOnce init_static_once = AV_ONCE_INIT; NellyMoserEncodeContext *s = avctx->priv_data; - int i, ret; + int ret; if (avctx->channels != 1) { av_log(avctx, AV_LOG_ERROR, "Nellymoser supports only 1 channel\n"); @@ -175,21 +195,6 @@ static av_cold int encode_init(AVCodecContext *avctx) if (!s->fdsp) return AVERROR(ENOMEM); - /* Generate overlap window */ - ff_init_ff_sine_windows(7); - /* faster way of doing - for (i = 0; i < POW_TABLE_SIZE; i++) - pow_table[i] = 2^(-i / 2048.0 - 3.0 + POW_TABLE_OFFSET); */ - pow_table[0] = 1; - pow_table[1024] = M_SQRT1_2; - for (i = 1; i < 513; i++) { - double tmp = exp2(-i / 2048.0); - pow_table[i] = tmp; - pow_table[1024-i] = M_SQRT1_2 / tmp; - pow_table[1024+i] = tmp * M_SQRT1_2; - pow_table[2048-i] = 0.5 / tmp; - } - if (s->avctx->trellis) { s->opt = av_malloc(NELLY_BANDS * OPT_SIZE * sizeof(float )); s->path = av_malloc(NELLY_BANDS * OPT_SIZE * sizeof(uint8_t)); @@ -197,6 +202,8 @@ static av_cold int encode_init(AVCodecContext *avctx) return AVERROR(ENOMEM); } + ff_thread_once(&init_static_once, nellymoser_init_static); + return 0; } @@ -424,5 +431,5 @@ AVCodec ff_nellymoser_encoder = { .capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME | AV_CODEC_CAP_DELAY, .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_NONE }, - .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE, };