[FFmpeg-cvslog] avcodec: do not use init_static_data on some codecs

Muhammad Faiz git at videolan.org
Sun Feb 4 01:34:17 EET 2018


ffmpeg | branch: master | Muhammad Faiz <mfcc64 at gmail.com> | Sat Feb  3 01:18:27 2018 +0700| [3caecf7ce8e9642cd17942e61f12803bbab52ad2] | committer: Muhammad Faiz

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 at googlemail.com>
Reviewed-by: Michael Niedermayer <michael at niedermayer.cc>
Signed-off-by: Muhammad Faiz <mfcc64 at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3caecf7ce8e9642cd17942e61f12803bbab52ad2
---

 libavcodec/jpeg2000dec.c | 16 +++++++++-------
 libavcodec/qdmc.c        |  7 +++++--
 libavcodec/wmavoice.c    |  7 +++++--
 3 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index 01fe4b3949..4cf8a2880c 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -34,6 +34,7 @@
 #include "libavutil/imgutils.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
+#include "libavutil/thread.h"
 #include "avcodec.h"
 #include "bytestream.h"
 #include "internal.h"
@@ -2142,10 +2143,18 @@ static int jp2_find_codestream(Jpeg2000DecoderContext *s)
     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 AVOnce init_static_once = AV_ONCE_INIT;
     Jpeg2000DecoderContext *s = avctx->priv_data;
 
+    ff_thread_once(&init_static_once, jpeg2000_init_static_data);
     ff_jpeg2000dsp_init(&s->dsp);
 
     return 0;
@@ -2223,12 +2232,6 @@ end:
     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 VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
 
@@ -2252,7 +2255,6 @@ AVCodec ff_jpeg2000_decoder = {
     .id               = AV_CODEC_ID_JPEG2000,
     .capabilities     = AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_DR1,
     .priv_data_size   = sizeof(Jpeg2000DecoderContext),
-    .init_static_data = jpeg2000_init_static_data,
     .init             = jpeg2000_decode_init,
     .decode           = jpeg2000_decode_frame,
     .priv_class       = &jpeg2000_class,
diff --git a/libavcodec/qdmc.c b/libavcodec/qdmc.c
index 1c8952b97b..f1f86accd8 100644
--- a/libavcodec/qdmc.c
+++ b/libavcodec/qdmc.c
@@ -26,6 +26,7 @@
 #define BITSTREAM_READER_LE
 
 #include "libavutil/channel_layout.h"
+#include "libavutil/thread.h"
 
 #include "avcodec.h"
 #include "bytestream.h"
@@ -204,7 +205,7 @@ static const uint8_t phase_diff_codes[] = {
                            INIT_VLC_LE | INIT_VLC_USE_NEW_STATIC); \
     } while (0)
 
-static av_cold void qdmc_init_static_data(AVCodec *codec)
+static av_cold void qdmc_init_static_data(void)
 {
     int i;
 
@@ -250,10 +251,13 @@ static void make_noises(QDMCContext *s)
 
 static av_cold int qdmc_decode_init(AVCodecContext *avctx)
 {
+    static AVOnce init_static_once = AV_ONCE_INIT;
     QDMCContext *s = avctx->priv_data;
     int fft_size, fft_order, size, g, j, x;
     GetByteContext b;
 
+    ff_thread_once(&init_static_once, qdmc_init_static_data);
+
     if (!avctx->extradata || (avctx->extradata_size < 48)) {
         av_log(avctx, AV_LOG_ERROR, "extradata missing or truncated\n");
         return AVERROR_INVALIDDATA;
@@ -775,7 +779,6 @@ AVCodec ff_qdmc_decoder = {
     .id               = AV_CODEC_ID_QDMC,
     .priv_data_size   = sizeof(QDMCContext),
     .init             = qdmc_decode_init,
-    .init_static_data = qdmc_init_static_data,
     .close            = qdmc_decode_close,
     .decode           = qdmc_decode_frame,
     .flush            = qdmc_flush,
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,



More information about the ffmpeg-cvslog mailing list