]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/ac3tab.c
h264: fix invalid pointer arithmetic
[ffmpeg] / libavcodec / ac3tab.c
index 8f1957f8924e8cb45b7fc600837ae25a6aeb5ba3..951a1014ce10a3c7b03c434f68a054b0527f4515 100644 (file)
@@ -1,36 +1,38 @@
 /*
- * AC3 tables
+ * AC-3 tables
  * copyright (c) 2001 Fabrice Bellard
  *
- * This file is part of FFmpeg.
+ * This file is part of Libav.
  *
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav 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,
+ * Libav 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
+ * License along with Libav; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 /**
- * @file ac3tab.c
- * tables taken directly from AC3 spec.
+ * @file
+ * tables taken directly from the AC-3 spec.
  */
 
+#include "libavutil/audioconvert.h"
+#include "avcodec.h"
 #include "ac3tab.h"
 
 /**
  * Possible frame sizes.
  * from ATSC A/52 Table 5.18 Frame Size Code Table.
  */
-const uint16_t ff_ac3_frame_sizes[38][3] = {
+const uint16_t ff_ac3_frame_size_tab[38][3] = {
     { 64,   69,   96   },
     { 64,   70,   96   },
     { 80,   87,   120  },
@@ -72,26 +74,81 @@ const uint16_t ff_ac3_frame_sizes[38][3] = {
 };
 
 /**
- * Maps audio coding mode (acmod) to number of full-bandwidth channels.
+ * Map audio coding mode (acmod) to number of full-bandwidth channels.
  * from ATSC A/52 Table 5.8 Audio Coding Mode
  */
-const uint8_t ff_ac3_channels[8] = {
+const uint8_t ff_ac3_channels_tab[8] = {
     2, 1, 2, 3, 3, 4, 4, 5
 };
 
+/**
+ * Map audio coding mode (acmod) to channel layout mask.
+ */
+const uint16_t avpriv_ac3_channel_layout_tab[8] = {
+    AV_CH_LAYOUT_STEREO,
+    AV_CH_LAYOUT_MONO,
+    AV_CH_LAYOUT_STEREO,
+    AV_CH_LAYOUT_SURROUND,
+    AV_CH_LAYOUT_2_1,
+    AV_CH_LAYOUT_4POINT0,
+    AV_CH_LAYOUT_2_2,
+    AV_CH_LAYOUT_5POINT0
+};
+
+#define COMMON_CHANNEL_MAP \
+    { { 0, 1,          }, { 0, 1, 2,         } },\
+    { { 0,             }, { 0, 1,            } },\
+    { { 0, 1,          }, { 0, 1, 2,         } },\
+    { { 0, 2, 1,       }, { 0, 2, 1, 3,      } },\
+    { { 0, 1, 2,       }, { 0, 1, 3, 2,      } },\
+    { { 0, 2, 1, 3,    }, { 0, 2, 1, 4, 3,   } },
+
+/**
+ * Table to remap channels from SMPTE order to AC-3 order.
+ * [channel_mode][lfe][ch]
+ */
+const uint8_t ff_ac3_enc_channel_map[8][2][6] = {
+    COMMON_CHANNEL_MAP
+    { { 0, 1, 2, 3,    }, { 0, 1, 3, 4, 2,   } },
+    { { 0, 2, 1, 3, 4, }, { 0, 2, 1, 4, 5, 3 } },
+};
+
+/**
+ * Table to remap channels from from AC-3 order to SMPTE order.
+ * [channel_mode][lfe][ch]
+ */
+const uint8_t ff_ac3_dec_channel_map[8][2][6] = {
+    COMMON_CHANNEL_MAP
+    { { 0, 1, 2, 3,    }, { 0, 1, 4, 2, 3,   } },
+    { { 0, 2, 1, 3, 4, }, { 0, 2, 1, 5, 3, 4 } },
+};
+
 /* possible frequencies */
-const uint16_t ff_ac3_freqs[3] = { 48000, 44100, 32000 };
+const uint16_t ff_ac3_sample_rate_tab[3] = { 48000, 44100, 32000 };
 
 /* possible bitrates */
-const uint16_t ff_ac3_bitratetab[19] = {
+const uint16_t ff_ac3_bitrate_tab[19] = {
     32, 40, 48, 56, 64, 80, 96, 112, 128,
     160, 192, 224, 256, 320, 384, 448, 512, 576, 640
 };
 
-/* AC3 MDCT window */
+/**
+ * Table of bin locations for rematrixing bands
+ * reference: Section 7.5.2 Rematrixing : Frequency Band Definitions
+ */
+const uint8_t ff_ac3_rematrix_band_tab[5] = { 13, 25, 37, 61, 253 };
+
+/**
+ * Table E2.16 Default Coupling Banding Structure
+ */
+const uint8_t ff_eac3_default_cpl_band_struct[18] = {
+    0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1
+};
+
+/* AC-3 MDCT window */
 
 /* MDCT window */
-const int16_t ff_ac3_window[256] = {
+DECLARE_ALIGNED(16, const int16_t, ff_ac3_window)[AC3_WINDOW_SIZE/2] = {
     4,    7,   12,   16,   21,   28,   34,   42,
    51,   61,   72,   84,   97,  111,  127,  145,
   164,  184,  207,  231,  257,  285,  315,  347,
@@ -126,7 +183,7 @@ const int16_t ff_ac3_window[256] = {
 32767,32767,32767,32767,32767,32767,32767,32767,
 };
 
-const uint8_t ff_ac3_latab[260]= {
+const uint8_t ff_ac3_log_add_tab[260]= {
 0x40,0x3f,0x3e,0x3d,0x3c,0x3b,0x3a,0x39,0x38,0x37,
 0x36,0x35,0x34,0x34,0x33,0x32,0x31,0x30,0x2f,0x2f,
 0x2e,0x2d,0x2c,0x2c,0x2b,0x2a,0x29,0x29,0x28,0x27,
@@ -155,7 +212,7 @@ const uint8_t ff_ac3_latab[260]= {
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 };
 
-const uint16_t ff_ac3_hth[50][3]= {
+const uint16_t ff_ac3_hearing_threshold_tab[AC3_CRITICAL_BANDS][3]= {
 { 0x04d0,0x04f0,0x0580 },
 { 0x04d0,0x04f0,0x0580 },
 { 0x0440,0x0460,0x04b0 },
@@ -208,7 +265,7 @@ const uint16_t ff_ac3_hth[50][3]= {
 { 0x0840,0x0840,0x04e0 },
 };
 
-const uint8_t ff_ac3_baptab[64]= {
+const uint8_t ff_ac3_bap_tab[64]= {
     0, 1, 1, 1, 1, 1, 2, 2, 3, 3,
     3, 4, 4, 5, 5, 6, 6, 6, 6, 7,
     7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
@@ -218,32 +275,40 @@ const uint8_t ff_ac3_baptab[64]= {
     15, 15, 15, 15,
 };
 
-const uint8_t ff_sdecaytab[4]={
+const uint8_t ff_ac3_slow_decay_tab[4]={
     0x0f, 0x11, 0x13, 0x15,
 };
 
-const uint8_t ff_fdecaytab[4]={
+const uint8_t ff_ac3_fast_decay_tab[4]={
     0x3f, 0x53, 0x67, 0x7b,
 };
 
-const uint16_t ff_sgaintab[4]= {
+const uint16_t ff_ac3_slow_gain_tab[4]= {
     0x540, 0x4d8, 0x478, 0x410,
 };
 
-const uint16_t ff_dbkneetab[4]= {
+const uint16_t ff_ac3_db_per_bit_tab[4]= {
     0x000, 0x700, 0x900, 0xb00,
 };
 
-const int16_t ff_floortab[8]= {
+const int16_t ff_ac3_floor_tab[8]= {
     0x2f0, 0x2b0, 0x270, 0x230, 0x1f0, 0x170, 0x0f0, 0xf800,
 };
 
-const uint16_t ff_fgaintab[8]= {
+const uint16_t ff_ac3_fast_gain_tab[8]= {
     0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, 0x400,
 };
 
-const uint8_t ff_ac3_bndsz[50]={
-    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3,
-    3, 6, 6, 6, 6, 6, 6, 12, 12, 12, 12, 24, 24, 24, 24, 24
+/**
+ * Default channel map for a dependent substream defined by acmod
+ */
+const uint16_t ff_eac3_default_chmap[8] = {
+    AC3_CHMAP_L |               AC3_CHMAP_R, // FIXME Ch1+Ch2
+                  AC3_CHMAP_C,
+    AC3_CHMAP_L |               AC3_CHMAP_R,
+    AC3_CHMAP_L | AC3_CHMAP_C | AC3_CHMAP_R,
+    AC3_CHMAP_L |               AC3_CHMAP_R |                   AC3_CHMAP_C_SUR,
+    AC3_CHMAP_L | AC3_CHMAP_C | AC3_CHMAP_R |                   AC3_CHMAP_C_SUR,
+    AC3_CHMAP_L |               AC3_CHMAP_R | AC3_CHMAP_L_SUR |                  AC3_CHMAP_R_SUR,
+    AC3_CHMAP_L | AC3_CHMAP_C | AC3_CHMAP_R | AC3_CHMAP_L_SUR |                  AC3_CHMAP_R_SUR
 };