1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

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 <nfxjfg@googlemail.com>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>
This commit is contained in:
Muhammad Faiz 2018-02-03 01:18:27 +07:00
parent 8e50bd61e4
commit 3caecf7ce8
3 changed files with 19 additions and 11 deletions

View File

@ -34,6 +34,7 @@
#include "libavutil/imgutils.h" #include "libavutil/imgutils.h"
#include "libavutil/opt.h" #include "libavutil/opt.h"
#include "libavutil/pixdesc.h" #include "libavutil/pixdesc.h"
#include "libavutil/thread.h"
#include "avcodec.h" #include "avcodec.h"
#include "bytestream.h" #include "bytestream.h"
#include "internal.h" #include "internal.h"
@ -2142,10 +2143,18 @@ static int jp2_find_codestream(Jpeg2000DecoderContext *s)
return 0; return 0;
} }
static av_cold void jpeg2000_init_static_data(void)
{
ff_jpeg2000_init_tier1_luts();
ff_mqc_init_context_tables();
}
static av_cold int jpeg2000_decode_init(AVCodecContext *avctx) static av_cold int jpeg2000_decode_init(AVCodecContext *avctx)
{ {
static AVOnce init_static_once = AV_ONCE_INIT;
Jpeg2000DecoderContext *s = avctx->priv_data; Jpeg2000DecoderContext *s = avctx->priv_data;
ff_thread_once(&init_static_once, jpeg2000_init_static_data);
ff_jpeg2000dsp_init(&s->dsp); ff_jpeg2000dsp_init(&s->dsp);
return 0; return 0;
@ -2223,12 +2232,6 @@ end:
return ret; return ret;
} }
static av_cold void jpeg2000_init_static_data(AVCodec *codec)
{
ff_jpeg2000_init_tier1_luts();
ff_mqc_init_context_tables();
}
#define OFFSET(x) offsetof(Jpeg2000DecoderContext, x) #define OFFSET(x) offsetof(Jpeg2000DecoderContext, x)
#define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
@ -2252,7 +2255,6 @@ AVCodec ff_jpeg2000_decoder = {
.id = AV_CODEC_ID_JPEG2000, .id = AV_CODEC_ID_JPEG2000,
.capabilities = AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_DR1, .capabilities = AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_DR1,
.priv_data_size = sizeof(Jpeg2000DecoderContext), .priv_data_size = sizeof(Jpeg2000DecoderContext),
.init_static_data = jpeg2000_init_static_data,
.init = jpeg2000_decode_init, .init = jpeg2000_decode_init,
.decode = jpeg2000_decode_frame, .decode = jpeg2000_decode_frame,
.priv_class = &jpeg2000_class, .priv_class = &jpeg2000_class,

View File

@ -26,6 +26,7 @@
#define BITSTREAM_READER_LE #define BITSTREAM_READER_LE
#include "libavutil/channel_layout.h" #include "libavutil/channel_layout.h"
#include "libavutil/thread.h"
#include "avcodec.h" #include "avcodec.h"
#include "bytestream.h" #include "bytestream.h"
@ -204,7 +205,7 @@ static const uint8_t phase_diff_codes[] = {
INIT_VLC_LE | INIT_VLC_USE_NEW_STATIC); \ INIT_VLC_LE | INIT_VLC_USE_NEW_STATIC); \
} while (0) } while (0)
static av_cold void qdmc_init_static_data(AVCodec *codec) static av_cold void qdmc_init_static_data(void)
{ {
int i; int i;
@ -250,10 +251,13 @@ static void make_noises(QDMCContext *s)
static av_cold int qdmc_decode_init(AVCodecContext *avctx) static av_cold int qdmc_decode_init(AVCodecContext *avctx)
{ {
static AVOnce init_static_once = AV_ONCE_INIT;
QDMCContext *s = avctx->priv_data; QDMCContext *s = avctx->priv_data;
int fft_size, fft_order, size, g, j, x; int fft_size, fft_order, size, g, j, x;
GetByteContext b; GetByteContext b;
ff_thread_once(&init_static_once, qdmc_init_static_data);
if (!avctx->extradata || (avctx->extradata_size < 48)) { if (!avctx->extradata || (avctx->extradata_size < 48)) {
av_log(avctx, AV_LOG_ERROR, "extradata missing or truncated\n"); av_log(avctx, AV_LOG_ERROR, "extradata missing or truncated\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
@ -775,7 +779,6 @@ AVCodec ff_qdmc_decoder = {
.id = AV_CODEC_ID_QDMC, .id = AV_CODEC_ID_QDMC,
.priv_data_size = sizeof(QDMCContext), .priv_data_size = sizeof(QDMCContext),
.init = qdmc_decode_init, .init = qdmc_decode_init,
.init_static_data = qdmc_init_static_data,
.close = qdmc_decode_close, .close = qdmc_decode_close,
.decode = qdmc_decode_frame, .decode = qdmc_decode_frame,
.flush = qdmc_flush, .flush = qdmc_flush,

View File

@ -30,6 +30,7 @@
#include "libavutil/channel_layout.h" #include "libavutil/channel_layout.h"
#include "libavutil/float_dsp.h" #include "libavutil/float_dsp.h"
#include "libavutil/mem.h" #include "libavutil/mem.h"
#include "libavutil/thread.h"
#include "avcodec.h" #include "avcodec.h"
#include "internal.h" #include "internal.h"
#include "get_bits.h" #include "get_bits.h"
@ -310,7 +311,7 @@ static av_cold int decode_vbmtree(GetBitContext *gb, int8_t vbm_tree[25])
return 0; 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[] = { static const uint8_t bits[] = {
2, 2, 2, 4, 4, 4, 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 av_cold int wmavoice_decode_init(AVCodecContext *ctx)
{ {
static AVOnce init_static_once = AV_ONCE_INIT;
int n, flags, pitch_range, lsp16_flag; int n, flags, pitch_range, lsp16_flag;
WMAVoiceContext *s = ctx->priv_data; WMAVoiceContext *s = ctx->priv_data;
ff_thread_once(&init_static_once, wmavoice_init_static_data);
/** /**
* Extradata layout: * Extradata layout:
* - byte 0-18: WMAPro-in-WMAVoice extradata (see wmaprodec.c), * - byte 0-18: WMAPro-in-WMAVoice extradata (see wmaprodec.c),
@ -1991,7 +1995,6 @@ AVCodec ff_wmavoice_decoder = {
.id = AV_CODEC_ID_WMAVOICE, .id = AV_CODEC_ID_WMAVOICE,
.priv_data_size = sizeof(WMAVoiceContext), .priv_data_size = sizeof(WMAVoiceContext),
.init = wmavoice_decode_init, .init = wmavoice_decode_init,
.init_static_data = wmavoice_init_static_data,
.close = wmavoice_decode_end, .close = wmavoice_decode_end,
.decode = wmavoice_decode_packet, .decode = wmavoice_decode_packet,
.capabilities = AV_CODEC_CAP_SUBFRAMES | AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY, .capabilities = AV_CODEC_CAP_SUBFRAMES | AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,