summaryrefslogtreecommitdiff
path: root/libavcodec/nellymoserenc.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-11-22 18:12:58 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-12-08 17:51:48 +0100
commit665a3dbd369ae928f793f70e7b32a58c0cdfbd2b (patch)
tree19e1cca4fb09614b07a65f49ef05eff03e80dfd0 /libavcodec/nellymoserenc.c
parent0a56bfa71f751a2b25da8d060a019c1c75ca9d7b (diff)
downloadffmpeg-665a3dbd369ae928f793f70e7b32a58c0cdfbd2b.tar.gz
avcodec/nellymoserenc: Make encoder init-threadsafe
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec/nellymoserenc.c')
-rw-r--r--libavcodec/nellymoserenc.c41
1 files changed, 24 insertions, 17 deletions
diff --git a/libavcodec/nellymoserenc.c b/libavcodec/nellymoserenc.c
index e5c9806be8..99ede2f42b 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_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
};