sender: Deplete ACLs on exit.
[paraslash.git] / wmadec_filter.c
index 13f1946402ad3295faa06637f9ec9e434d0f67a4..edf50cb0b3834d8971fe9602f6528e2f2bd86e5d 100644 (file)
@@ -5,8 +5,7 @@
  *
  * Copyright (c) 2002 The FFmpeg Project
  *
- * Licensed under the GNU Lesser General Public License.
- * For licencing details see COPYING.LIB.
+ * Licensed under the GNU Lesser General Public License, see file COPYING.LIB.
  */
 
 /** \file wmadec_filter.c paraslash's WMA decoder. */
@@ -15,8 +14,6 @@
  * This decoder handles Microsoft Windows Media Audio data version 2.
  */
 
-#define _XOPEN_SOURCE 600
-
 #include <math.h>
 #include <regex.h>
 #include <sys/select.h>
@@ -81,7 +78,6 @@ struct private_wmadec_data {
        struct vlc coef_vlc[2];
        uint16_t *run_table[2];
        uint16_t *level_table[2];
-       const struct coef_vlc_table *coef_vlcs[2];
        /** Frame length in samples. */
        int frame_len;
        /** log2 of frame_len. */
@@ -100,8 +96,6 @@ struct private_wmadec_data {
        int block_len;
        /** Current position in frame. */
        int block_pos;
-       /** True if mid/side stereo mode. */
-       uint8_t ms_stereo;
        /** True if channel is coded. */
        uint8_t channel_coded[MAX_CHANNELS];
        /** log2 ratio frame/exp. length. */
@@ -159,34 +153,27 @@ static void sine_window_init(float *window, int n)
                window[i] = sinf((i + 0.5) * (M_PI / (2.0 * n)));
 }
 
-static void init_coef_vlc(struct vlc *vlc, uint16_t **prun_table,
-               uint16_t **plevel_table, const struct coef_vlc_table *vlc_table)
+static void init_coef_vlc(struct private_wmadec_data *pwd, int sidx, int didx)
 {
-       int n = vlc_table->n;
-       const uint8_t *table_bits = vlc_table->huffbits;
-       const uint32_t *table_codes = vlc_table->huffcodes;
-       const uint16_t *levels_table = vlc_table->levels;
-       uint16_t *run_table, *level_table;
-       int i, l, j, k, level;
-
-       init_vlc(vlc, VLCBITS, n, table_bits, table_codes, 4);
+       const struct coef_vlc_table *src = coef_vlcs + sidx;
+       struct vlc *dst = pwd->coef_vlc + didx;
+       int i, l, j, k, level, n = src->n;
 
-       run_table = para_malloc(n * sizeof(uint16_t));
-       level_table = para_malloc(n * sizeof(uint16_t));
+       init_vlc(dst, VLCBITS, n, src->huffbits, src->huffcodes, 4);
+       pwd->run_table[didx] = para_malloc(n * sizeof(uint16_t));
+       pwd->level_table[didx] = para_malloc(n * sizeof(uint16_t));
        i = 2;
        level = 1;
        k = 0;
        while (i < n) {
-               l = levels_table[k++];
+               l = src->levels[k++];
                for (j = 0; j < l; j++) {
-                       run_table[i] = j;
-                       level_table[i] = level;
+                       pwd->run_table[didx][i] = j;
+                       pwd->level_table[didx][i] = level;
                        i++;
                }
                level++;
        }
-       *prun_table = run_table;
-       *plevel_table = level_table;
 }
 
 /* compute the scale factor band sizes for each MDCT block size */
@@ -396,19 +383,15 @@ static int wma_init(struct private_wmadec_data *pwd)
        }
 
        /* choose the VLC tables for the coefficients */
-       coef_vlc_table = 2;
+       coef_vlc_table = 4;
        if (ahi->sample_rate >= 32000) {
                if (bps1 < 0.72)
                        coef_vlc_table = 0;
                else if (bps1 < 1.16)
-                       coef_vlc_table = 1;
+                       coef_vlc_table = 2;
        }
-       pwd->coef_vlcs[0] = &coef_vlcs[coef_vlc_table * 2];
-       pwd->coef_vlcs[1] = &coef_vlcs[coef_vlc_table * 2 + 1];
-       init_coef_vlc(&pwd->coef_vlc[0], &pwd->run_table[0], &pwd->level_table[0],
-               pwd->coef_vlcs[0]);
-       init_coef_vlc(&pwd->coef_vlc[1], &pwd->run_table[1], &pwd->level_table[1],
-               pwd->coef_vlcs[1]);
+       init_coef_vlc(pwd, coef_vlc_table, 0);
+       init_coef_vlc(pwd, coef_vlc_table + 1, 1);
        return 0;
 }
 
@@ -810,6 +793,7 @@ static int wma_decode_block(struct private_wmadec_data *pwd)
        int ret, n, v, ch, code, bsize;
        int coef_nb_bits, total_gain;
        int nb_coefs[MAX_CHANNELS];
+       bool ms_stereo = false; /* mid/side stereo mode */
 
        /* compute current block length */
        if (pwd->ahi.use_variable_block_len) {
@@ -847,7 +831,7 @@ static int wma_decode_block(struct private_wmadec_data *pwd)
                return -E_INCOHERENT_BLOCK_LEN;
 
        if (pwd->ahi.channels == 2)
-               pwd->ms_stereo = get_bit(&pwd->gb);
+               ms_stereo = get_bit(&pwd->gb);
        v = 0;
        for (ch = 0; ch < pwd->ahi.channels; ch++) {
                int a = get_bit(&pwd->gb);
@@ -913,7 +897,7 @@ static int wma_decode_block(struct private_wmadec_data *pwd)
                 * special VLC tables are used for ms stereo because there is
                 * potentially less energy there
                 */
-               tindex = (ch == 1 && pwd->ms_stereo);
+               tindex = ch == 1 && ms_stereo;
                coef_vlc = &pwd->coef_vlc[tindex];
                run_table = pwd->run_table[tindex];
                level_table = pwd->level_table[tindex];
@@ -948,7 +932,7 @@ static int wma_decode_block(struct private_wmadec_data *pwd)
                }
        }
        compute_mdct_coefficients(pwd, bsize, total_gain, nb_coefs);
-       if (pwd->ms_stereo && pwd->channel_coded[1]) {
+       if (ms_stereo && pwd->channel_coded[1]) {
                float a, b;
                int i;
                /*
@@ -976,7 +960,7 @@ next:
                n4 = pwd->block_len / 2;
                if (pwd->channel_coded[ch])
                        imdct(pwd->mdct_ctx[bsize], pwd->output, pwd->coefs[ch]);
-               else if (!(pwd->ms_stereo && ch == 1))
+               else if (!(ms_stereo && ch == 1))
                        memset(pwd->output, 0, sizeof(pwd->output));
 
                /* multiply by the window and add in the frame */