[FFmpeg-cvslog] atrac3: initialize static tables in AVCodec.init_static_data()

Justin Ruggles git at videolan.org
Tue Oct 23 12:58:36 CEST 2012


ffmpeg | branch: master | Justin Ruggles <justin.ruggles at gmail.com> | Thu Oct 18 23:04:03 2012 -0400| [5d1007f74dd496d54b932242004382f44e3b22b4] | committer: Justin Ruggles

atrac3: initialize static tables in AVCodec.init_static_data()

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

 libavcodec/atrac3.c |   53 ++++++++++++++++++++++++++-------------------------
 1 file changed, 27 insertions(+), 26 deletions(-)

diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c
index 69b42fd..9e0f273 100644
--- a/libavcodec/atrac3.c
+++ b/libavcodec/atrac3.c
@@ -117,6 +117,7 @@ typedef struct ATRAC3Context {
 } ATRAC3Context;
 
 static DECLARE_ALIGNED(32, float, mdct_window)[MDCT_SIZE];
+static VLC_TYPE atrac3_vlc_table[4096][2];
 static VLC   spectral_coeff_tab[7];
 static float gain_tab1[16];
 static float gain_tab2[31];
@@ -838,14 +839,37 @@ static int atrac3_decode_frame(AVCodecContext *avctx, void *data,
     return avctx->block_align;
 }
 
+static void atrac3_init_static_data(AVCodec *codec)
+{
+    int i;
+
+    init_atrac3_window();
+    ff_atrac_generate_tables();
+
+    /* Initialize the VLC tables. */
+    for (i = 0; i < 7; i++) {
+        spectral_coeff_tab[i].table = &atrac3_vlc_table[atrac3_vlc_offs[i]];
+        spectral_coeff_tab[i].table_allocated = atrac3_vlc_offs[i + 1] -
+                                                atrac3_vlc_offs[i    ];
+        init_vlc(&spectral_coeff_tab[i], 9, huff_tab_sizes[i],
+                 huff_bits[i],  1, 1,
+                 huff_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
+    }
+
+    /* Generate gain tables */
+    for (i = 0; i < 16; i++)
+        gain_tab1[i] = powf(2.0, (4 - i));
+
+    for (i = -15; i < 16; i++)
+        gain_tab2[i + 15] = powf(2.0, i * -0.125);
+}
+
 static av_cold int atrac3_decode_init(AVCodecContext *avctx)
 {
     int i, ret;
     int version, delay, samples_per_frame, frame_factor;
     const uint8_t *edata_ptr = avctx->extradata;
     ATRAC3Context *q = avctx->priv_data;
-    static VLC_TYPE atrac3_vlc_table[4096][2];
-    static int vlcs_initialized = 0;
 
     /* Take data from the AVCodecContext (RM container). */
     q->sample_rate     = avctx->sample_rate;
@@ -935,20 +959,6 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx)
     if (q->decoded_bytes_buffer == NULL)
         return AVERROR(ENOMEM);
 
-
-    /* Initialize the VLC tables. */
-    if (!vlcs_initialized) {
-        for (i = 0; i < 7; i++) {
-            spectral_coeff_tab[i].table = &atrac3_vlc_table[atrac3_vlc_offs[i]];
-            spectral_coeff_tab[i].table_allocated = atrac3_vlc_offs[i + 1] -
-                                                    atrac3_vlc_offs[i    ];
-            init_vlc(&spectral_coeff_tab[i], 9, huff_tab_sizes[i],
-                     huff_bits[i], 1, 1,
-                     huff_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
-        }
-        vlcs_initialized = 1;
-    }
-
     avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
 
     /* initialize the MDCT transform */
@@ -958,16 +968,6 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx)
         return ret;
     }
 
-    init_atrac3_window();
-    ff_atrac_generate_tables();
-
-    /* Generate gain tables */
-    for (i = 0; i < 16; i++)
-        gain_tab1[i] = powf(2.0, (4 - i));
-
-    for (i = -15; i < 16; i++)
-        gain_tab2[i + 15] = powf(2.0, i * -0.125);
-
     /* init the joint-stereo decoding data */
     q->weighting_delay[0] = 0;
     q->weighting_delay[1] = 7;
@@ -1003,6 +1003,7 @@ AVCodec ff_atrac3_decoder = {
     .id               = AV_CODEC_ID_ATRAC3,
     .priv_data_size   = sizeof(ATRAC3Context),
     .init             = atrac3_decode_init,
+    .init_static_data = atrac3_init_static_data,
     .close            = atrac3_decode_close,
     .decode           = atrac3_decode_frame,
     .capabilities     = CODEC_CAP_SUBFRAMES | CODEC_CAP_DR1,



More information about the ffmpeg-cvslog mailing list