From 3caecf7ce8e9642cd17942e61f12803bbab52ad2 Mon Sep 17 00:00:00 2001 From: Muhammad Faiz Date: Sat, 3 Feb 2018 01:18:27 +0700 Subject: avcodec: do not use init_static_data on some codecs They don't modify AVCodec, no needs to call it at register. They will be wasteful if these codecs are unused. Instead, call static data initialization at codecs' init. Benchmark: old: 51281340 decicycles in avcodec_register_all, 1 runs, 0 skips new: 6738960 decicycles in avcodec_register_all, 1 runs, 0 skips Reviewed-by: wm4 Reviewed-by: Michael Niedermayer Signed-off-by: Muhammad Faiz --- libavcodec/wmavoice.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'libavcodec/wmavoice.c') diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c index 3f86d0da35..444e303b0d 100644 --- a/libavcodec/wmavoice.c +++ b/libavcodec/wmavoice.c @@ -30,6 +30,7 @@ #include "libavutil/channel_layout.h" #include "libavutil/float_dsp.h" #include "libavutil/mem.h" +#include "libavutil/thread.h" #include "avcodec.h" #include "internal.h" #include "get_bits.h" @@ -310,7 +311,7 @@ static av_cold int decode_vbmtree(GetBitContext *gb, int8_t vbm_tree[25]) return 0; } -static av_cold void wmavoice_init_static_data(AVCodec *codec) +static av_cold void wmavoice_init_static_data(void) { static const uint8_t bits[] = { 2, 2, 2, 4, 4, 4, @@ -365,9 +366,12 @@ static av_cold void wmavoice_flush(AVCodecContext *ctx) */ static av_cold int wmavoice_decode_init(AVCodecContext *ctx) { + static AVOnce init_static_once = AV_ONCE_INIT; int n, flags, pitch_range, lsp16_flag; WMAVoiceContext *s = ctx->priv_data; + ff_thread_once(&init_static_once, wmavoice_init_static_data); + /** * Extradata layout: * - byte 0-18: WMAPro-in-WMAVoice extradata (see wmaprodec.c), @@ -1991,7 +1995,6 @@ AVCodec ff_wmavoice_decoder = { .id = AV_CODEC_ID_WMAVOICE, .priv_data_size = sizeof(WMAVoiceContext), .init = wmavoice_decode_init, - .init_static_data = wmavoice_init_static_data, .close = wmavoice_decode_end, .decode = wmavoice_decode_packet, .capabilities = AV_CODEC_CAP_SUBFRAMES | AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY, -- cgit v1.2.3