[FFmpeg-devel] [PATCH] mpegaudiodec: share identical tables between float and fixed decoder.
Reimar Döffinger
Reimar.Doeffinger at gmx.de
Sun Aug 31 22:47:09 CEST 2014
ff_mpa_table_4_3_value alone saves over 128kB.
Signed-off-by: Reimar Döffinger <Reimar.Doeffinger at gmx.de>
---
libavcodec/Makefile | 24 +++---
libavcodec/mpegaudio_tablegen.c | 13 +--
libavcodec/mpegaudio_tablegen.h | 26 +++---
libavcodec/mpegaudiodec_common.c | 135 +++++++++++++++++++++++++++++++
libavcodec/mpegaudiodec_common.h | 54 +++++++++++++
libavcodec/mpegaudiodec_template.c | 159 +++++++------------------------------
libavcodec/mpegaudiodectab.h | 14 ++--
7 files changed, 256 insertions(+), 169 deletions(-)
create mode 100644 libavcodec/mpegaudiodec_common.c
create mode 100644 libavcodec/mpegaudiodec_common.h
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 28ae252..3936f03 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -304,20 +304,20 @@ OBJS-$(CONFIG_MMVIDEO_DECODER) += mmvideo.o
OBJS-$(CONFIG_MOTIONPIXELS_DECODER) += motionpixels.o
OBJS-$(CONFIG_MOVTEXT_DECODER) += movtextdec.o ass.o
OBJS-$(CONFIG_MOVTEXT_ENCODER) += movtextenc.o ass_split.o
-OBJS-$(CONFIG_MP1_DECODER) += mpegaudiodec_fixed.o
-OBJS-$(CONFIG_MP1FLOAT_DECODER) += mpegaudiodec_float.o
-OBJS-$(CONFIG_MP2_DECODER) += mpegaudiodec_fixed.o
-OBJS-$(CONFIG_MP2_ENCODER) += mpegaudioenc_float.o mpegaudio.o \
+OBJS-$(CONFIG_MP1_DECODER) += mpegaudiodec_fixed.o mpegaudiodec_common.o
+OBJS-$(CONFIG_MP1FLOAT_DECODER) += mpegaudiodec_float.o mpegaudiodec_common.o
+OBJS-$(CONFIG_MP2_DECODER) += mpegaudiodec_fixed.o mpegaudiodec_common.o
+OBJS-$(CONFIG_MP2_ENCODER) += mpegaudioenc_float.o mpegaudiodec_common.o mpegaudio.o \
mpegaudiodata.o mpegaudiodsp_data.o
-OBJS-$(CONFIG_MP2FIXED_ENCODER) += mpegaudioenc_fixed.o mpegaudio.o \
+OBJS-$(CONFIG_MP2FIXED_ENCODER) += mpegaudioenc_fixed.o mpegaudiodec_common.o mpegaudio.o \
mpegaudiodata.o mpegaudiodsp_data.o
-OBJS-$(CONFIG_MP2FLOAT_DECODER) += mpegaudiodec_float.o
-OBJS-$(CONFIG_MP3_DECODER) += mpegaudiodec_fixed.o
-OBJS-$(CONFIG_MP3ADU_DECODER) += mpegaudiodec_fixed.o
-OBJS-$(CONFIG_MP3ADUFLOAT_DECODER) += mpegaudiodec_float.o
-OBJS-$(CONFIG_MP3FLOAT_DECODER) += mpegaudiodec_float.o
-OBJS-$(CONFIG_MP3ON4_DECODER) += mpegaudiodec_fixed.o mpeg4audio.o
-OBJS-$(CONFIG_MP3ON4FLOAT_DECODER) += mpegaudiodec_float.o mpeg4audio.o
+OBJS-$(CONFIG_MP2FLOAT_DECODER) += mpegaudiodec_float.o mpegaudiodec_common.o
+OBJS-$(CONFIG_MP3_DECODER) += mpegaudiodec_fixed.o mpegaudiodec_common.o
+OBJS-$(CONFIG_MP3ADU_DECODER) += mpegaudiodec_fixed.o mpegaudiodec_common.o
+OBJS-$(CONFIG_MP3ADUFLOAT_DECODER) += mpegaudiodec_float.o mpegaudiodec_common.o
+OBJS-$(CONFIG_MP3FLOAT_DECODER) += mpegaudiodec_float.o mpegaudiodec_common.o
+OBJS-$(CONFIG_MP3ON4_DECODER) += mpegaudiodec_fixed.o mpegaudiodec_common.o mpeg4audio.o
+OBJS-$(CONFIG_MP3ON4FLOAT_DECODER) += mpegaudiodec_float.o mpegaudiodec_common.o mpeg4audio.o
OBJS-$(CONFIG_MPC7_DECODER) += mpc7.o mpc.o
OBJS-$(CONFIG_MPC8_DECODER) += mpc8.o mpc.o
OBJS-$(CONFIG_MPEGVIDEO_DECODER) += mpeg12dec.o mpeg12.o mpeg12data.o
diff --git a/libavcodec/mpegaudio_tablegen.c b/libavcodec/mpegaudio_tablegen.c
index 90c9de4..2f57600 100644
--- a/libavcodec/mpegaudio_tablegen.c
+++ b/libavcodec/mpegaudio_tablegen.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#define CONFIG_HARDCODED_TABLES 0
+#define VLC int
#include "mpegaudio_tablegen.h"
#include "tableprint.h"
@@ -31,12 +32,12 @@ int main(void)
write_fileheader();
- WRITE_ARRAY("static const", int8_t, table_4_3_exp);
- WRITE_ARRAY("static const", uint32_t, table_4_3_value);
- WRITE_ARRAY("static const", uint32_t, exp_table_fixed);
- WRITE_ARRAY("static const", float, exp_table_float);
- WRITE_2D_ARRAY("static const", uint32_t, expval_table_fixed);
- WRITE_2D_ARRAY("static const", float, expval_table_float);
+ WRITE_ARRAY("const", int8_t, ff_mpa_table_4_3_exp);
+ WRITE_ARRAY("const", uint32_t, ff_mpa_table_4_3_value);
+ WRITE_ARRAY("const", uint32_t, ff_mpa_exp_table_fixed);
+ WRITE_ARRAY("const", float, ff_mpa_exp_table_float);
+ WRITE_2D_ARRAY("const", uint32_t, ff_mpa_expval_table_fixed);
+ WRITE_2D_ARRAY("const", float, ff_mpa_expval_table_float);
return 0;
}
diff --git a/libavcodec/mpegaudio_tablegen.h b/libavcodec/mpegaudio_tablegen.h
index 86b2cd3..7ad57c5 100644
--- a/libavcodec/mpegaudio_tablegen.h
+++ b/libavcodec/mpegaudio_tablegen.h
@@ -26,18 +26,18 @@
#include <stdint.h>
#include <math.h>
#include "libavutil/attributes.h"
+#include "mpegaudiodec_common.h"
-#define TABLE_4_3_SIZE (8191 + 16)*4
#if CONFIG_HARDCODED_TABLES
#define mpegaudio_tableinit()
#include "libavcodec/mpegaudio_tables.h"
#else
-static int8_t table_4_3_exp[TABLE_4_3_SIZE];
-static uint32_t table_4_3_value[TABLE_4_3_SIZE];
-static uint32_t exp_table_fixed[512];
-static uint32_t expval_table_fixed[512][16];
-static float exp_table_float[512];
-static float expval_table_float[512][16];
+int8_t ff_mpa_table_4_3_exp[TABLE_4_3_SIZE];
+uint32_t ff_mpa_table_4_3_value[TABLE_4_3_SIZE];
+uint32_t ff_mpa_exp_table_fixed[512];
+uint32_t ff_mpa_expval_table_fixed[512][16];
+float ff_mpa_exp_table_float[512];
+float ff_mpa_expval_table_float[512][16];
#define FRAC_BITS 23
#define IMDCT_SCALAR 1.759
@@ -56,19 +56,19 @@ static av_cold void mpegaudio_tableinit(void)
e += FRAC_BITS - 31 + 5 - 100;
/* normalized to FRAC_BITS */
- table_4_3_value[i] = m;
- table_4_3_exp[i] = -e;
+ ff_mpa_table_4_3_value[i] = m;
+ ff_mpa_table_4_3_exp[i] = -e;
}
for (exponent = 0; exponent < 512; exponent++) {
for (value = 0; value < 16; value++) {
/* cbrtf() isn't available on all systems, so we use powf(). */
double f = (double)value * pow(value, 1.0 / 3.0) * pow(2, (exponent - 400) * 0.25 + FRAC_BITS + 5) / IMDCT_SCALAR;
/* llrint() isn't always available, so round and cast manually. */
- expval_table_fixed[exponent][value] = (long long int) (f < 0xFFFFFFFF ? floor(f + 0.5) : 0xFFFFFFFF);
- expval_table_float[exponent][value] = f;
+ ff_mpa_expval_table_fixed[exponent][value] = (long long int) (f < 0xFFFFFFFF ? floor(f + 0.5) : 0xFFFFFFFF);
+ ff_mpa_expval_table_float[exponent][value] = f;
}
- exp_table_fixed[exponent] = expval_table_fixed[exponent][1];
- exp_table_float[exponent] = expval_table_float[exponent][1];
+ ff_mpa_exp_table_fixed[exponent] = ff_mpa_expval_table_fixed[exponent][1];
+ ff_mpa_exp_table_float[exponent] = ff_mpa_expval_table_float[exponent][1];
}
}
#endif /* CONFIG_HARDCODED_TABLES */
diff --git a/libavcodec/mpegaudiodec_common.c b/libavcodec/mpegaudiodec_common.c
new file mode 100644
index 0000000..d8f59cf
--- /dev/null
+++ b/libavcodec/mpegaudiodec_common.c
@@ -0,0 +1,135 @@
+/*
+ * MPEG Audio decoder part share between float and fixed point versions
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdint.h>
+#include "get_bits.h"
+#include "mpegaudiodec_common.h"
+#include "mpegaudiodectab.h"
+#include "mpegaudiodata.h"
+
+/* vlc structure for decoding layer 3 huffman tables */
+VLC ff_mpa_huff_vlc[16];
+static VLC_TYPE huff_vlc_tables[
+ 0 + 128 + 128 + 128 + 130 + 128 + 154 + 166 +
+ 142 + 204 + 190 + 170 + 542 + 460 + 662 + 414
+ ][2];
+static const int huff_vlc_tables_sizes[16] = {
+ 0, 128, 128, 128, 130, 128, 154, 166,
+ 142, 204, 190, 170, 542, 460, 662, 414
+};
+VLC ff_mpa_huff_quad_vlc[2];
+static VLC_TYPE huff_quad_vlc_tables[128+16][2];
+static const int huff_quad_vlc_tables_sizes[2] = { 128, 16 };
+/* computed from band_size_long */
+uint16_t ff_mpa_band_index_long[9][23];
+
+#include "mpegaudio_tablegen.h"
+
+static int16_t division_tab3[1<<6 ];
+static int16_t division_tab5[1<<8 ];
+static int16_t division_tab9[1<<11];
+
+int16_t * const ff_mpa_division_tabs[4] = {
+ division_tab3, division_tab5, NULL, division_tab9
+};
+
+/* lower 2 bits: modulo 3, higher bits: shift */
+uint16_t ff_mpa_scale_factor_modshift[64];
+
+av_cold void ff_mpa_decode_init_common_static(void)
+{
+ int i, j, k;
+ int offset;
+
+ /* scale factors table for layer 1/2 */
+ for (i = 0; i < 64; i++) {
+ int shift, mod;
+ /* 1.0 (i = 3) is normalized to 2 ^ FRAC_BITS */
+ shift = i / 3;
+ mod = i % 3;
+ ff_mpa_scale_factor_modshift[i] = mod | (shift << 2);
+ }
+
+ /* huffman decode tables */
+ offset = 0;
+ for (i = 1; i < 16; i++) {
+ const HuffTable *h = &mpa_huff_tables[i];
+ int xsize, x, y;
+ uint8_t tmp_bits [512] = { 0 };
+ uint16_t tmp_codes[512] = { 0 };
+
+ xsize = h->xsize;
+
+ j = 0;
+ for (x = 0; x < xsize; x++) {
+ for (y = 0; y < xsize; y++) {
+ tmp_bits [(x << 5) | y | ((x&&y)<<4)]= h->bits [j ];
+ tmp_codes[(x << 5) | y | ((x&&y)<<4)]= h->codes[j++];
+ }
+ }
+
+ /* XXX: fail test */
+ ff_mpa_huff_vlc[i].table = huff_vlc_tables+offset;
+ ff_mpa_huff_vlc[i].table_allocated = huff_vlc_tables_sizes[i];
+ init_vlc(&ff_mpa_huff_vlc[i], 7, 512,
+ tmp_bits, 1, 1, tmp_codes, 2, 2,
+ INIT_VLC_USE_NEW_STATIC);
+ offset += huff_vlc_tables_sizes[i];
+ }
+ av_assert0(offset == FF_ARRAY_ELEMS(huff_vlc_tables));
+
+ offset = 0;
+ for (i = 0; i < 2; i++) {
+ ff_mpa_huff_quad_vlc[i].table = huff_quad_vlc_tables+offset;
+ ff_mpa_huff_quad_vlc[i].table_allocated = huff_quad_vlc_tables_sizes[i];
+ init_vlc(&ff_mpa_huff_quad_vlc[i], i == 0 ? 7 : 4, 16,
+ mpa_quad_bits[i], 1, 1, mpa_quad_codes[i], 1, 1,
+ INIT_VLC_USE_NEW_STATIC);
+ offset += huff_quad_vlc_tables_sizes[i];
+ }
+ av_assert0(offset == FF_ARRAY_ELEMS(huff_quad_vlc_tables));
+
+ for (i = 0; i < 9; i++) {
+ k = 0;
+ for (j = 0; j < 22; j++) {
+ ff_mpa_band_index_long[i][j] = k;
+ k += ff_mpa_band_size_long[i][j];
+ }
+ ff_mpa_band_index_long[i][22] = k;
+ }
+
+ /* compute n ^ (4/3) and store it in mantissa/exp format */
+ mpegaudio_tableinit();
+
+ for (i = 0; i < 4; i++) {
+ if (ff_mpa_quant_bits[i] < 0) {
+ for (j = 0; j < (1 << (-ff_mpa_quant_bits[i]+1)); j++) {
+ int val1, val2, val3, steps;
+ int val = j;
+ steps = ff_mpa_quant_steps[i];
+ val1 = val % steps;
+ val /= steps;
+ val2 = val % steps;
+ val3 = val / steps;
+ ff_mpa_division_tabs[i][j] = val1 + (val2 << 4) + (val3 << 8);
+ }
+ }
+ }
+}
diff --git a/libavcodec/mpegaudiodec_common.h b/libavcodec/mpegaudiodec_common.h
new file mode 100644
index 0000000..e084715
--- /dev/null
+++ b/libavcodec/mpegaudiodec_common.h
@@ -0,0 +1,54 @@
+/*
+ * MPEG Audio decoder part share between float and fixed point versions
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_MPEGAUDIODEC_COMMON_H
+#define AVCODEC_MPEGAUDIODEC_COMMON_H
+
+#define TABLE_4_3_SIZE (8191 + 16)*4
+
+#if CONFIG_HARDCODED_TABLES
+#define MPA_TABLE_CONST const
+#else
+#define MPA_TABLE_CONST
+#endif
+extern MPA_TABLE_CONST int8_t ff_mpa_table_4_3_exp[TABLE_4_3_SIZE];
+extern MPA_TABLE_CONST uint32_t ff_mpa_table_4_3_value[TABLE_4_3_SIZE];
+extern MPA_TABLE_CONST uint32_t ff_mpa_exp_table_fixed[512];
+extern MPA_TABLE_CONST uint32_t ff_mpa_expval_table_fixed[512][16];
+extern MPA_TABLE_CONST float ff_mpa_exp_table_float[512];
+extern MPA_TABLE_CONST float ff_mpa_expval_table_float[512][16];
+
+extern const uint8_t ff_mpa_slen_table[2][16];
+extern const uint8_t ff_mpa_lsf_nsf_table[6][3][4];
+extern const uint8_t ff_mpa_band_size_long[9][22];
+extern const uint8_t ff_mpa_band_size_short[9][13];
+extern const uint8_t ff_mpa_pretab[2][22];
+extern const float ff_mpa_ci_table[8];
+extern const uint8_t ff_mpa_huff_data[32][2];
+
+extern VLC ff_mpa_huff_vlc[16];
+extern VLC ff_mpa_huff_quad_vlc[2];
+extern uint16_t ff_mpa_band_index_long[9][23];
+extern int16_t * const ff_mpa_division_tabs[4];
+extern uint16_t ff_mpa_scale_factor_modshift[64];
+
+av_cold void ff_mpa_decode_init_common_static(void);
+
+#endif /* AVCODEC_MPEGAUDIODEC_COMMON_H */
diff --git a/libavcodec/mpegaudiodec_template.c b/libavcodec/mpegaudiodec_template.c
index c4c03d9..5576c33 100644
--- a/libavcodec/mpegaudiodec_template.c
+++ b/libavcodec/mpegaudiodec_template.c
@@ -42,6 +42,7 @@
#include "mpegaudio.h"
#include "mpegaudiodecheader.h"
+#include "mpegaudiodec_common.h"
#define BACKSTEP_SIZE 512
#define EXTRABYTES 24
@@ -92,39 +93,11 @@ typedef struct MPADecodeContext {
#define HEADER_SIZE 4
#include "mpegaudiodata.h"
-#include "mpegaudiodectab.h"
-
-/* vlc structure for decoding layer 3 huffman tables */
-static VLC huff_vlc[16];
-static VLC_TYPE huff_vlc_tables[
- 0 + 128 + 128 + 128 + 130 + 128 + 154 + 166 +
- 142 + 204 + 190 + 170 + 542 + 460 + 662 + 414
- ][2];
-static const int huff_vlc_tables_sizes[16] = {
- 0, 128, 128, 128, 130, 128, 154, 166,
- 142, 204, 190, 170, 542, 460, 662, 414
-};
-static VLC huff_quad_vlc[2];
-static VLC_TYPE huff_quad_vlc_tables[128+16][2];
-static const int huff_quad_vlc_tables_sizes[2] = { 128, 16 };
-/* computed from band_size_long */
-static uint16_t band_index_long[9][23];
-#include "mpegaudio_tablegen.h"
/* intensity stereo coef table */
static INTFLOAT is_table[2][16];
static INTFLOAT is_table_lsf[2][2][16];
static INTFLOAT csa_table[8][4];
-static int16_t division_tab3[1<<6 ];
-static int16_t division_tab5[1<<8 ];
-static int16_t division_tab9[1<<11];
-
-static int16_t * const division_tabs[4] = {
- division_tab3, division_tab5, NULL, division_tab9
-};
-
-/* lower 2 bits: modulo 3, higher bits: shift */
-static uint16_t scale_factor_modshift[64];
/* [i][j]: 2^(-j/3) * FRAC_ONE * 2^(i+2) / (2^(i+2) - 1) */
static int32_t scale_factor_mult[15][3];
/* mult table for layer 2 group quantization */
@@ -175,10 +148,10 @@ static void init_long_region(MPADecodeContext *s, GranuleDef *g,
int ra1, int ra2)
{
int l;
- g->region_size[0] = band_index_long[s->sample_rate_index][ra1 + 1] >> 1;
+ g->region_size[0] = ff_mpa_band_index_long[s->sample_rate_index][ra1 + 1] >> 1;
/* should not overflow */
l = FFMIN(ra1 + ra2 + 2, 22);
- g->region_size[1] = band_index_long[s->sample_rate_index][ l] >> 1;
+ g->region_size[1] = ff_mpa_band_index_long[s->sample_rate_index][ l] >> 1;
}
static void compute_band_indexes(MPADecodeContext *s, GranuleDef *g)
@@ -213,7 +186,7 @@ static inline int l1_unscale(int n, int mant, int scale_factor)
int shift, mod;
int64_t val;
- shift = scale_factor_modshift[scale_factor];
+ shift = ff_mpa_scale_factor_modshift[scale_factor];
mod = shift & 3;
shift >>= 2;
val = MUL64((int)(mant + (-1U << n) + 1), scale_factor_mult[n-1][mod]);
@@ -226,7 +199,7 @@ static inline int l2_unscale_group(int steps, int mant, int scale_factor)
{
int shift, mod, val;
- shift = scale_factor_modshift[scale_factor];
+ shift = ff_mpa_scale_factor_modshift[scale_factor];
mod = shift & 3;
shift >>= 2;
@@ -243,8 +216,8 @@ static inline int l3_unscale(int value, int exponent)
unsigned int m;
int e;
- e = table_4_3_exp [4 * value + (exponent & 3)];
- m = table_4_3_value[4 * value + (exponent & 3)];
+ e = ff_mpa_table_4_3_exp [4 * value + (exponent & 3)];
+ m = ff_mpa_table_4_3_value[4 * value + (exponent & 3)];
e -= exponent >> 2;
#ifdef DEBUG
if(e < 1)
@@ -259,17 +232,7 @@ static inline int l3_unscale(int value, int exponent)
static av_cold void decode_init_static(void)
{
- int i, j, k;
- int offset;
-
- /* scale factors table for layer 1/2 */
- for (i = 0; i < 64; i++) {
- int shift, mod;
- /* 1.0 (i = 3) is normalized to 2 ^ FRAC_BITS */
- shift = i / 3;
- mod = i % 3;
- scale_factor_modshift[i] = mod | (shift << 2);
- }
+ int i, j;
/* scale factor multiply for layer 1 */
for (i = 0; i < 15; i++) {
@@ -287,73 +250,7 @@ static av_cold void decode_init_static(void)
RENAME(ff_mpa_synth_init)(RENAME(ff_mpa_synth_window));
- /* huffman decode tables */
- offset = 0;
- for (i = 1; i < 16; i++) {
- const HuffTable *h = &mpa_huff_tables[i];
- int xsize, x, y;
- uint8_t tmp_bits [512] = { 0 };
- uint16_t tmp_codes[512] = { 0 };
-
- xsize = h->xsize;
-
- j = 0;
- for (x = 0; x < xsize; x++) {
- for (y = 0; y < xsize; y++) {
- tmp_bits [(x << 5) | y | ((x&&y)<<4)]= h->bits [j ];
- tmp_codes[(x << 5) | y | ((x&&y)<<4)]= h->codes[j++];
- }
- }
-
- /* XXX: fail test */
- huff_vlc[i].table = huff_vlc_tables+offset;
- huff_vlc[i].table_allocated = huff_vlc_tables_sizes[i];
- init_vlc(&huff_vlc[i], 7, 512,
- tmp_bits, 1, 1, tmp_codes, 2, 2,
- INIT_VLC_USE_NEW_STATIC);
- offset += huff_vlc_tables_sizes[i];
- }
- av_assert0(offset == FF_ARRAY_ELEMS(huff_vlc_tables));
-
- offset = 0;
- for (i = 0; i < 2; i++) {
- huff_quad_vlc[i].table = huff_quad_vlc_tables+offset;
- huff_quad_vlc[i].table_allocated = huff_quad_vlc_tables_sizes[i];
- init_vlc(&huff_quad_vlc[i], i == 0 ? 7 : 4, 16,
- mpa_quad_bits[i], 1, 1, mpa_quad_codes[i], 1, 1,
- INIT_VLC_USE_NEW_STATIC);
- offset += huff_quad_vlc_tables_sizes[i];
- }
- av_assert0(offset == FF_ARRAY_ELEMS(huff_quad_vlc_tables));
-
- for (i = 0; i < 9; i++) {
- k = 0;
- for (j = 0; j < 22; j++) {
- band_index_long[i][j] = k;
- k += band_size_long[i][j];
- }
- band_index_long[i][22] = k;
- }
-
- /* compute n ^ (4/3) and store it in mantissa/exp format */
-
- mpegaudio_tableinit();
-
- for (i = 0; i < 4; i++) {
- if (ff_mpa_quant_bits[i] < 0) {
- for (j = 0; j < (1 << (-ff_mpa_quant_bits[i]+1)); j++) {
- int val1, val2, val3, steps;
- int val = j;
- steps = ff_mpa_quant_steps[i];
- val1 = val % steps;
- val /= steps;
- val2 = val % steps;
- val3 = val / steps;
- division_tabs[i][j] = val1 + (val2 << 4) + (val3 << 8);
- }
- }
- }
-
+ ff_mpa_decode_init_common_static();
for (i = 0; i < 7; i++) {
float f;
@@ -389,7 +286,7 @@ static av_cold void decode_init_static(void)
for (i = 0; i < 8; i++) {
float ci, cs, ca;
- ci = ci_table[i];
+ ci = ff_mpa_ci_table[i];
cs = 1.0 / sqrt(1.0 + ci * ci);
ca = cs * ci;
#if !USE_FLOATS
@@ -647,7 +544,7 @@ static int mp_decode_layer2(MPADecodeContext *s)
int v2;
/* 3 values at the same time */
v = get_bits(&s->gb, -bits);
- v2 = division_tabs[qindex][v];
+ v2 = ff_mpa_division_tabs[qindex][v];
steps = ff_mpa_quant_steps[qindex];
s->sb_samples[ch][k * 12 + l + 0][i] =
@@ -775,8 +672,8 @@ static void exponents_from_scale_factors(MPADecodeContext *s, GranuleDef *g,
gain = g->global_gain - 210;
shift = g->scalefac_scale + 1;
- bstab = band_size_long[s->sample_rate_index];
- pretab = mpa_pretab[g->preflag];
+ bstab = ff_mpa_band_size_long[s->sample_rate_index];
+ pretab = ff_mpa_pretab[g->preflag];
for (i = 0; i < g->long_end; i++) {
v0 = gain - ((g->scale_factors[i] + pretab[i]) << shift) + 400;
len = bstab[i];
@@ -785,7 +682,7 @@ static void exponents_from_scale_factors(MPADecodeContext *s, GranuleDef *g,
}
if (g->short_start < 13) {
- bstab = band_size_short[s->sample_rate_index];
+ bstab = ff_mpa_band_size_short[s->sample_rate_index];
gains[0] = gain - (g->subblock_gain[0] << 3);
gains[1] = gain - (g->subblock_gain[1] << 3);
gains[2] = gain - (g->subblock_gain[2] << 3);
@@ -856,9 +753,9 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
continue;
/* select vlc table */
k = g->table_select[i];
- l = mpa_huff_data[k][0];
- linbits = mpa_huff_data[k][1];
- vlc = &huff_vlc[l];
+ l = ff_mpa_huff_data[k][0];
+ linbits = ff_mpa_huff_data[k][1];
+ vlc = &ff_mpa_huff_vlc[l];
if (!l) {
memset(&g->sb_hybrid[s_index], 0, sizeof(*g->sb_hybrid) * 2 * j);
@@ -894,7 +791,7 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
x = y >> 5;
y = y & 0x0f;
if (x < 15) {
- READ_FLIP_SIGN(g->sb_hybrid + s_index, RENAME(expval_table)[exponent] + x)
+ READ_FLIP_SIGN(g->sb_hybrid + s_index, RENAME(ff_mpa_expval_table)[exponent] + x)
} else {
x += get_bitsz(&s->gb, linbits);
v = l3_unscale(x, exponent);
@@ -903,7 +800,7 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
g->sb_hybrid[s_index] = v;
}
if (y < 15) {
- READ_FLIP_SIGN(g->sb_hybrid + s_index + 1, RENAME(expval_table)[exponent] + y)
+ READ_FLIP_SIGN(g->sb_hybrid + s_index + 1, RENAME(ff_mpa_expval_table)[exponent] + y)
} else {
y += get_bitsz(&s->gb, linbits);
v = l3_unscale(y, exponent);
@@ -916,7 +813,7 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
y = y & 0x0f;
x += y;
if (x < 15) {
- READ_FLIP_SIGN(g->sb_hybrid + s_index + !!y, RENAME(expval_table)[exponent] + x)
+ READ_FLIP_SIGN(g->sb_hybrid + s_index + !!y, RENAME(ff_mpa_expval_table)[exponent] + x)
} else {
x += get_bitsz(&s->gb, linbits);
v = l3_unscale(x, exponent);
@@ -931,7 +828,7 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
}
/* high frequencies */
- vlc = &huff_quad_vlc[g->count1table_select];
+ vlc = &ff_mpa_huff_quad_vlc[g->count1table_select];
last_pos = 0;
while (s_index <= 572) {
int pos, code;
@@ -964,7 +861,7 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
int v;
int pos = s_index + idxtab[code];
code ^= 8 >> idxtab[code];
- READ_FLIP_SIGN(g->sb_hybrid + pos, RENAME(exp_table)+exponents[pos])
+ READ_FLIP_SIGN(g->sb_hybrid + pos, RENAME(ff_mpa_exp_table)+exponents[pos])
}
s_index += 4;
}
@@ -1008,7 +905,7 @@ static void reorder_block(MPADecodeContext *s, GranuleDef *g)
}
for (i = g->short_start; i < 13; i++) {
- len = band_size_short[s->sample_rate_index][i];
+ len = ff_mpa_band_size_short[s->sample_rate_index][i];
ptr1 = ptr;
dst = tmp;
for (j = len; j > 0; j--) {
@@ -1052,7 +949,7 @@ static void compute_stereo(MPADecodeContext *s, GranuleDef *g0, GranuleDef *g1)
/* for last band, use previous scale factor */
if (i != 11)
k -= 3;
- len = band_size_short[s->sample_rate_index][i];
+ len = ff_mpa_band_size_short[s->sample_rate_index][i];
for (l = 2; l >= 0; l--) {
tab0 -= len;
tab1 -= len;
@@ -1096,7 +993,7 @@ found1:
non_zero_found_short[2];
for (i = g1->long_end - 1;i >= 0;i--) {
- len = band_size_long[s->sample_rate_index][i];
+ len = ff_mpa_band_size_long[s->sample_rate_index][i];
tab0 -= len;
tab1 -= len;
/* test if non zero band. if so, stop doing i-stereo */
@@ -1422,8 +1319,8 @@ static int mp_decode_layer3(MPADecodeContext *s)
int slen, slen1, slen2;
/* MPEG1 scale factors */
- slen1 = slen_table[0][g->scalefac_compress];
- slen2 = slen_table[1][g->scalefac_compress];
+ slen1 = ff_mpa_slen_table[0][g->scalefac_compress];
+ slen2 = ff_mpa_slen_table[1][g->scalefac_compress];
av_dlog(s->avctx, "slen1=%d slen2=%d\n", slen1, slen2);
if (g->block_type == 2) {
n = g->switch_point ? 17 : 18;
@@ -1508,7 +1405,7 @@ static int mp_decode_layer3(MPADecodeContext *s)
j = 0;
for (k = 0; k < 4; k++) {
- n = lsf_nsf_table[tindex2][tindex][k];
+ n = ff_mpa_lsf_nsf_table[tindex2][tindex][k];
sl = slen[k];
if (sl) {
for (i = 0; i < n; i++)
diff --git a/libavcodec/mpegaudiodectab.h b/libavcodec/mpegaudiodectab.h
index accd12b..5764396 100644
--- a/libavcodec/mpegaudiodectab.h
+++ b/libavcodec/mpegaudiodectab.h
@@ -43,13 +43,13 @@ typedef struct HuffTable {
} HuffTable;
/* layer3 scale factor size */
-static const uint8_t slen_table[2][16] = {
+const uint8_t ff_mpa_slen_table[2][16] = {
{ 0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4 },
{ 0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3 },
};
/* number of lsf scale factors for a given size */
-static const uint8_t lsf_nsf_table[6][3][4] = {
+const uint8_t ff_mpa_lsf_nsf_table[6][3][4] = {
{ { 6, 5, 5, 5 }, { 9, 9, 9, 9 }, { 6, 9, 9, 9 } },
{ { 6, 5, 7, 3 }, { 9, 9, 12, 6 }, { 6, 9, 12, 6 } },
{ { 11, 10, 0, 0 }, { 18, 18, 0, 0 }, { 15, 18, 0, 0 } },
@@ -521,7 +521,7 @@ static const HuffTable mpa_huff_tables[16] = {
{ 16, mpa_huffbits_24, mpa_huffcodes_24 },
};
-static const uint8_t mpa_huff_data[32][2] = {
+const uint8_t ff_mpa_huff_data[32][2] = {
{ 0, 0 },
{ 1, 0 },
{ 2, 0 },
@@ -569,7 +569,7 @@ static const uint8_t mpa_quad_bits[2][16] = {
};
/* band size tables */
-static const uint8_t band_size_long[9][22] = {
+const uint8_t ff_mpa_band_size_long[9][22] = {
{ 4, 4, 4, 4, 4, 4, 6, 6, 8, 8, 10,
12, 16, 20, 24, 28, 34, 42, 50, 54, 76, 158, }, /* 44100 */
{ 4, 4, 4, 4, 4, 4, 6, 6, 6, 8, 10,
@@ -590,7 +590,7 @@ static const uint8_t band_size_long[9][22] = {
40, 48, 56, 64, 76, 90, 2, 2, 2, 2, 2, }, /* 8000 */
};
-static const uint8_t band_size_short[9][13] = {
+const uint8_t ff_mpa_band_size_short[9][13] = {
{ 4, 4, 4, 4, 6, 8, 10, 12, 14, 18, 22, 30, 56, }, /* 44100 */
{ 4, 4, 4, 4, 6, 6, 10, 12, 14, 16, 20, 26, 66, }, /* 48000 */
{ 4, 4, 4, 4, 6, 8, 12, 16, 20, 26, 34, 42, 12, }, /* 32000 */
@@ -602,13 +602,13 @@ static const uint8_t band_size_short[9][13] = {
{ 8, 8, 8, 12, 16, 20, 24, 28, 36, 2, 2, 2, 26, }, /* 8000 */
};
-static const uint8_t mpa_pretab[2][22] = {
+const uint8_t ff_mpa_pretab[2][22] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0 },
};
/* table for alias reduction (XXX: store it as integer !) */
-static const float ci_table[8] = {
+const float ff_mpa_ci_table[8] = {
-0.6, -0.535, -0.33, -0.185, -0.095, -0.041, -0.0142, -0.0037,
};
--
2.1.0
More information about the ffmpeg-devel
mailing list