Browse code

qdm2: use init_static_data

Luca Barbato authored on 2013/06/27 09:20:59
Showing 1 changed files
... ...
@@ -218,116 +218,145 @@ static const uint16_t qdm2_vlc_offs[] = {
218 218
 
219 219
 static av_cold void qdm2_init_vlc(void)
220 220
 {
221
-    static int vlcs_initialized = 0;
222 221
     static VLC_TYPE qdm2_table[3838][2];
223 222
 
224
-    if (!vlcs_initialized) {
225
-
226
-        vlc_tab_level.table = &qdm2_table[qdm2_vlc_offs[0]];
227
-        vlc_tab_level.table_allocated = qdm2_vlc_offs[1] - qdm2_vlc_offs[0];
228
-        init_vlc (&vlc_tab_level, 8, 24,
229
-            vlc_tab_level_huffbits, 1, 1,
230
-            vlc_tab_level_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
231
-
232
-        vlc_tab_diff.table = &qdm2_table[qdm2_vlc_offs[1]];
233
-        vlc_tab_diff.table_allocated = qdm2_vlc_offs[2] - qdm2_vlc_offs[1];
234
-        init_vlc (&vlc_tab_diff, 8, 37,
235
-            vlc_tab_diff_huffbits, 1, 1,
236
-            vlc_tab_diff_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
237
-
238
-        vlc_tab_run.table = &qdm2_table[qdm2_vlc_offs[2]];
239
-        vlc_tab_run.table_allocated = qdm2_vlc_offs[3] - qdm2_vlc_offs[2];
240
-        init_vlc (&vlc_tab_run, 5, 6,
241
-            vlc_tab_run_huffbits, 1, 1,
242
-            vlc_tab_run_huffcodes, 1, 1, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
243
-
244
-        fft_level_exp_alt_vlc.table = &qdm2_table[qdm2_vlc_offs[3]];
245
-        fft_level_exp_alt_vlc.table_allocated = qdm2_vlc_offs[4] - qdm2_vlc_offs[3];
246
-        init_vlc (&fft_level_exp_alt_vlc, 8, 28,
247
-            fft_level_exp_alt_huffbits, 1, 1,
248
-            fft_level_exp_alt_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
249
-
250
-
251
-        fft_level_exp_vlc.table = &qdm2_table[qdm2_vlc_offs[4]];
252
-        fft_level_exp_vlc.table_allocated = qdm2_vlc_offs[5] - qdm2_vlc_offs[4];
253
-        init_vlc (&fft_level_exp_vlc, 8, 20,
254
-            fft_level_exp_huffbits, 1, 1,
255
-            fft_level_exp_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
256
-
257
-        fft_stereo_exp_vlc.table = &qdm2_table[qdm2_vlc_offs[5]];
258
-        fft_stereo_exp_vlc.table_allocated = qdm2_vlc_offs[6] - qdm2_vlc_offs[5];
259
-        init_vlc (&fft_stereo_exp_vlc, 6, 7,
260
-            fft_stereo_exp_huffbits, 1, 1,
261
-            fft_stereo_exp_huffcodes, 1, 1, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
262
-
263
-        fft_stereo_phase_vlc.table = &qdm2_table[qdm2_vlc_offs[6]];
264
-        fft_stereo_phase_vlc.table_allocated = qdm2_vlc_offs[7] - qdm2_vlc_offs[6];
265
-        init_vlc (&fft_stereo_phase_vlc, 6, 9,
266
-            fft_stereo_phase_huffbits, 1, 1,
267
-            fft_stereo_phase_huffcodes, 1, 1, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
268
-
269
-        vlc_tab_tone_level_idx_hi1.table = &qdm2_table[qdm2_vlc_offs[7]];
270
-        vlc_tab_tone_level_idx_hi1.table_allocated = qdm2_vlc_offs[8] - qdm2_vlc_offs[7];
271
-        init_vlc (&vlc_tab_tone_level_idx_hi1, 8, 20,
272
-            vlc_tab_tone_level_idx_hi1_huffbits, 1, 1,
273
-            vlc_tab_tone_level_idx_hi1_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
274
-
275
-        vlc_tab_tone_level_idx_mid.table = &qdm2_table[qdm2_vlc_offs[8]];
276
-        vlc_tab_tone_level_idx_mid.table_allocated = qdm2_vlc_offs[9] - qdm2_vlc_offs[8];
277
-        init_vlc (&vlc_tab_tone_level_idx_mid, 8, 24,
278
-            vlc_tab_tone_level_idx_mid_huffbits, 1, 1,
279
-            vlc_tab_tone_level_idx_mid_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
280
-
281
-        vlc_tab_tone_level_idx_hi2.table = &qdm2_table[qdm2_vlc_offs[9]];
282
-        vlc_tab_tone_level_idx_hi2.table_allocated = qdm2_vlc_offs[10] - qdm2_vlc_offs[9];
283
-        init_vlc (&vlc_tab_tone_level_idx_hi2, 8, 24,
284
-            vlc_tab_tone_level_idx_hi2_huffbits, 1, 1,
285
-            vlc_tab_tone_level_idx_hi2_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
286
-
287
-        vlc_tab_type30.table = &qdm2_table[qdm2_vlc_offs[10]];
288
-        vlc_tab_type30.table_allocated = qdm2_vlc_offs[11] - qdm2_vlc_offs[10];
289
-        init_vlc (&vlc_tab_type30, 6, 9,
290
-            vlc_tab_type30_huffbits, 1, 1,
291
-            vlc_tab_type30_huffcodes, 1, 1, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
292
-
293
-        vlc_tab_type34.table = &qdm2_table[qdm2_vlc_offs[11]];
294
-        vlc_tab_type34.table_allocated = qdm2_vlc_offs[12] - qdm2_vlc_offs[11];
295
-        init_vlc (&vlc_tab_type34, 5, 10,
296
-            vlc_tab_type34_huffbits, 1, 1,
297
-            vlc_tab_type34_huffcodes, 1, 1, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
298
-
299
-        vlc_tab_fft_tone_offset[0].table = &qdm2_table[qdm2_vlc_offs[12]];
300
-        vlc_tab_fft_tone_offset[0].table_allocated = qdm2_vlc_offs[13] - qdm2_vlc_offs[12];
301
-        init_vlc (&vlc_tab_fft_tone_offset[0], 8, 23,
302
-            vlc_tab_fft_tone_offset_0_huffbits, 1, 1,
303
-            vlc_tab_fft_tone_offset_0_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
304
-
305
-        vlc_tab_fft_tone_offset[1].table = &qdm2_table[qdm2_vlc_offs[13]];
306
-        vlc_tab_fft_tone_offset[1].table_allocated = qdm2_vlc_offs[14] - qdm2_vlc_offs[13];
307
-        init_vlc (&vlc_tab_fft_tone_offset[1], 8, 28,
308
-            vlc_tab_fft_tone_offset_1_huffbits, 1, 1,
309
-            vlc_tab_fft_tone_offset_1_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
310
-
311
-        vlc_tab_fft_tone_offset[2].table = &qdm2_table[qdm2_vlc_offs[14]];
312
-        vlc_tab_fft_tone_offset[2].table_allocated = qdm2_vlc_offs[15] - qdm2_vlc_offs[14];
313
-        init_vlc (&vlc_tab_fft_tone_offset[2], 8, 32,
314
-            vlc_tab_fft_tone_offset_2_huffbits, 1, 1,
315
-            vlc_tab_fft_tone_offset_2_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
316
-
317
-        vlc_tab_fft_tone_offset[3].table = &qdm2_table[qdm2_vlc_offs[15]];
318
-        vlc_tab_fft_tone_offset[3].table_allocated = qdm2_vlc_offs[16] - qdm2_vlc_offs[15];
319
-        init_vlc (&vlc_tab_fft_tone_offset[3], 8, 35,
320
-            vlc_tab_fft_tone_offset_3_huffbits, 1, 1,
321
-            vlc_tab_fft_tone_offset_3_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
322
-
323
-        vlc_tab_fft_tone_offset[4].table = &qdm2_table[qdm2_vlc_offs[16]];
324
-        vlc_tab_fft_tone_offset[4].table_allocated = qdm2_vlc_offs[17] - qdm2_vlc_offs[16];
325
-        init_vlc (&vlc_tab_fft_tone_offset[4], 8, 38,
326
-            vlc_tab_fft_tone_offset_4_huffbits, 1, 1,
327
-            vlc_tab_fft_tone_offset_4_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
328
-
329
-        vlcs_initialized=1;
330
-    }
223
+    vlc_tab_level.table           = &qdm2_table[qdm2_vlc_offs[0]];
224
+    vlc_tab_level.table_allocated = qdm2_vlc_offs[1] - qdm2_vlc_offs[0];
225
+    init_vlc(&vlc_tab_level, 8, 24,
226
+             vlc_tab_level_huffbits, 1, 1,
227
+             vlc_tab_level_huffcodes, 2, 2,
228
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
229
+
230
+    vlc_tab_diff.table           = &qdm2_table[qdm2_vlc_offs[1]];
231
+    vlc_tab_diff.table_allocated = qdm2_vlc_offs[2] - qdm2_vlc_offs[1];
232
+    init_vlc(&vlc_tab_diff, 8, 37,
233
+             vlc_tab_diff_huffbits, 1, 1,
234
+             vlc_tab_diff_huffcodes, 2, 2,
235
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
236
+
237
+    vlc_tab_run.table           = &qdm2_table[qdm2_vlc_offs[2]];
238
+    vlc_tab_run.table_allocated = qdm2_vlc_offs[3] - qdm2_vlc_offs[2];
239
+    init_vlc(&vlc_tab_run, 5, 6,
240
+             vlc_tab_run_huffbits, 1, 1,
241
+             vlc_tab_run_huffcodes, 1, 1,
242
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
243
+
244
+    fft_level_exp_alt_vlc.table           = &qdm2_table[qdm2_vlc_offs[3]];
245
+    fft_level_exp_alt_vlc.table_allocated = qdm2_vlc_offs[4] -
246
+                                            qdm2_vlc_offs[3];
247
+    init_vlc(&fft_level_exp_alt_vlc, 8, 28,
248
+             fft_level_exp_alt_huffbits, 1, 1,
249
+             fft_level_exp_alt_huffcodes, 2, 2,
250
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
251
+
252
+    fft_level_exp_vlc.table           = &qdm2_table[qdm2_vlc_offs[4]];
253
+    fft_level_exp_vlc.table_allocated = qdm2_vlc_offs[5] - qdm2_vlc_offs[4];
254
+    init_vlc(&fft_level_exp_vlc, 8, 20,
255
+             fft_level_exp_huffbits, 1, 1,
256
+             fft_level_exp_huffcodes, 2, 2,
257
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
258
+
259
+    fft_stereo_exp_vlc.table           = &qdm2_table[qdm2_vlc_offs[5]];
260
+    fft_stereo_exp_vlc.table_allocated = qdm2_vlc_offs[6] -
261
+                                         qdm2_vlc_offs[5];
262
+    init_vlc(&fft_stereo_exp_vlc, 6, 7,
263
+             fft_stereo_exp_huffbits, 1, 1,
264
+             fft_stereo_exp_huffcodes, 1, 1,
265
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
266
+
267
+    fft_stereo_phase_vlc.table           = &qdm2_table[qdm2_vlc_offs[6]];
268
+    fft_stereo_phase_vlc.table_allocated = qdm2_vlc_offs[7] -
269
+                                           qdm2_vlc_offs[6];
270
+    init_vlc(&fft_stereo_phase_vlc, 6, 9,
271
+             fft_stereo_phase_huffbits, 1, 1,
272
+             fft_stereo_phase_huffcodes, 1, 1,
273
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
274
+
275
+    vlc_tab_tone_level_idx_hi1.table =
276
+        &qdm2_table[qdm2_vlc_offs[7]];
277
+    vlc_tab_tone_level_idx_hi1.table_allocated = qdm2_vlc_offs[8] -
278
+                                                 qdm2_vlc_offs[7];
279
+    init_vlc(&vlc_tab_tone_level_idx_hi1, 8, 20,
280
+             vlc_tab_tone_level_idx_hi1_huffbits, 1, 1,
281
+             vlc_tab_tone_level_idx_hi1_huffcodes, 2, 2,
282
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
283
+
284
+    vlc_tab_tone_level_idx_mid.table =
285
+        &qdm2_table[qdm2_vlc_offs[8]];
286
+    vlc_tab_tone_level_idx_mid.table_allocated = qdm2_vlc_offs[9] -
287
+                                                 qdm2_vlc_offs[8];
288
+    init_vlc(&vlc_tab_tone_level_idx_mid, 8, 24,
289
+             vlc_tab_tone_level_idx_mid_huffbits, 1, 1,
290
+             vlc_tab_tone_level_idx_mid_huffcodes, 2, 2,
291
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
292
+
293
+    vlc_tab_tone_level_idx_hi2.table =
294
+        &qdm2_table[qdm2_vlc_offs[9]];
295
+    vlc_tab_tone_level_idx_hi2.table_allocated = qdm2_vlc_offs[10] -
296
+                                                 qdm2_vlc_offs[9];
297
+    init_vlc(&vlc_tab_tone_level_idx_hi2, 8, 24,
298
+             vlc_tab_tone_level_idx_hi2_huffbits, 1, 1,
299
+             vlc_tab_tone_level_idx_hi2_huffcodes, 2, 2,
300
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
301
+
302
+    vlc_tab_type30.table           = &qdm2_table[qdm2_vlc_offs[10]];
303
+    vlc_tab_type30.table_allocated = qdm2_vlc_offs[11] - qdm2_vlc_offs[10];
304
+    init_vlc(&vlc_tab_type30, 6, 9,
305
+             vlc_tab_type30_huffbits, 1, 1,
306
+             vlc_tab_type30_huffcodes, 1, 1,
307
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
308
+
309
+    vlc_tab_type34.table           = &qdm2_table[qdm2_vlc_offs[11]];
310
+    vlc_tab_type34.table_allocated = qdm2_vlc_offs[12] - qdm2_vlc_offs[11];
311
+    init_vlc(&vlc_tab_type34, 5, 10,
312
+             vlc_tab_type34_huffbits, 1, 1,
313
+             vlc_tab_type34_huffcodes, 1, 1,
314
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
315
+
316
+    vlc_tab_fft_tone_offset[0].table =
317
+        &qdm2_table[qdm2_vlc_offs[12]];
318
+    vlc_tab_fft_tone_offset[0].table_allocated = qdm2_vlc_offs[13] -
319
+                                                 qdm2_vlc_offs[12];
320
+    init_vlc(&vlc_tab_fft_tone_offset[0], 8, 23,
321
+             vlc_tab_fft_tone_offset_0_huffbits, 1, 1,
322
+             vlc_tab_fft_tone_offset_0_huffcodes, 2, 2,
323
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
324
+
325
+    vlc_tab_fft_tone_offset[1].table =
326
+        &qdm2_table[qdm2_vlc_offs[13]];
327
+    vlc_tab_fft_tone_offset[1].table_allocated = qdm2_vlc_offs[14] -
328
+                                                 qdm2_vlc_offs[13];
329
+    init_vlc(&vlc_tab_fft_tone_offset[1], 8, 28,
330
+             vlc_tab_fft_tone_offset_1_huffbits, 1, 1,
331
+             vlc_tab_fft_tone_offset_1_huffcodes, 2, 2,
332
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
333
+
334
+    vlc_tab_fft_tone_offset[2].table =
335
+        &qdm2_table[qdm2_vlc_offs[14]];
336
+    vlc_tab_fft_tone_offset[2].table_allocated = qdm2_vlc_offs[15] -
337
+                                                 qdm2_vlc_offs[14];
338
+    init_vlc(&vlc_tab_fft_tone_offset[2], 8, 32,
339
+             vlc_tab_fft_tone_offset_2_huffbits, 1, 1,
340
+             vlc_tab_fft_tone_offset_2_huffcodes, 2, 2,
341
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
342
+
343
+    vlc_tab_fft_tone_offset[3].table =
344
+        &qdm2_table[qdm2_vlc_offs[15]];
345
+    vlc_tab_fft_tone_offset[3].table_allocated = qdm2_vlc_offs[16] -
346
+                                                 qdm2_vlc_offs[15];
347
+    init_vlc(&vlc_tab_fft_tone_offset[3], 8, 35,
348
+             vlc_tab_fft_tone_offset_3_huffbits, 1, 1,
349
+             vlc_tab_fft_tone_offset_3_huffcodes, 2, 2,
350
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
351
+
352
+    vlc_tab_fft_tone_offset[4].table =
353
+        &qdm2_table[qdm2_vlc_offs[16]];
354
+    vlc_tab_fft_tone_offset[4].table_allocated = qdm2_vlc_offs[17] -
355
+                                                 qdm2_vlc_offs[16];
356
+    init_vlc(&vlc_tab_fft_tone_offset[4], 8, 38,
357
+             vlc_tab_fft_tone_offset_4_huffbits, 1, 1,
358
+             vlc_tab_fft_tone_offset_4_huffcodes, 2, 2,
359
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
331 360
 }
332 361
 
333 362
 static int qdm2_get_vlc (GetBitContext *gb, VLC *vlc, int flag, int depth)
... ...
@@ -1649,20 +1678,12 @@ static void qdm2_synthesis_filter (QDM2Context *q, int index)
1649 1649
  *
1650 1650
  * @param q    context
1651 1651
  */
1652
-static av_cold void qdm2_init(QDM2Context *q) {
1653
-    static int initialized = 0;
1654
-
1655
-    if (initialized != 0)
1656
-        return;
1657
-    initialized = 1;
1658
-
1652
+static av_cold void qdm2_init_static_data(AVCodec *codec) {
1659 1653
     qdm2_init_vlc();
1660 1654
     ff_mpa_synth_init_float(ff_mpa_synth_window_float);
1661 1655
     softclip_table_init();
1662 1656
     rnd_table_init();
1663 1657
     init_noise_samples();
1664
-
1665
-    av_log(NULL, AV_LOG_DEBUG, "init done\n");
1666 1658
 }
1667 1659
 
1668 1660
 
... ...
@@ -1843,8 +1864,6 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx)
1843 1843
     ff_rdft_init(&s->rdft_ctx, s->fft_order, IDFT_C2R);
1844 1844
     ff_mpadsp_init(&s->mpadsp);
1845 1845
 
1846
-    qdm2_init(s);
1847
-
1848 1846
     avctx->sample_fmt = AV_SAMPLE_FMT_S16;
1849 1847
 
1850 1848
     return 0;
... ...
@@ -1957,13 +1976,14 @@ static int qdm2_decode_frame(AVCodecContext *avctx, void *data,
1957 1957
 
1958 1958
 AVCodec ff_qdm2_decoder =
1959 1959
 {
1960
-    .name           = "qdm2",
1961
-    .type           = AVMEDIA_TYPE_AUDIO,
1962
-    .id             = AV_CODEC_ID_QDM2,
1963
-    .priv_data_size = sizeof(QDM2Context),
1964
-    .init           = qdm2_decode_init,
1965
-    .close          = qdm2_decode_close,
1966
-    .decode         = qdm2_decode_frame,
1967
-    .capabilities   = CODEC_CAP_DR1,
1968
-    .long_name      = NULL_IF_CONFIG_SMALL("QDesign Music Codec 2"),
1960
+    .name             = "qdm2",
1961
+    .type             = AVMEDIA_TYPE_AUDIO,
1962
+    .id               = AV_CODEC_ID_QDM2,
1963
+    .priv_data_size   = sizeof(QDM2Context),
1964
+    .init             = qdm2_decode_init,
1965
+    .init_static_data = qdm2_init_static_data,
1966
+    .close            = qdm2_decode_close,
1967
+    .decode           = qdm2_decode_frame,
1968
+    .capabilities     = CODEC_CAP_DR1,
1969
+    .long_name        = NULL_IF_CONFIG_SMALL("QDesign Music Codec 2"),
1969 1970
 };