You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
4.5KB

  1. /*
  2. * copyright (c) 2001 Fabrice Bellard
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * Libav is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. * @file
  22. * mpeg audio declarations for both encoder and decoder.
  23. */
  24. #ifndef AVCODEC_MPEGAUDIO_H
  25. #define AVCODEC_MPEGAUDIO_H
  26. #ifndef CONFIG_FLOAT
  27. # define CONFIG_FLOAT 0
  28. #endif
  29. #include "avcodec.h"
  30. #include "get_bits.h"
  31. #include "dsputil.h"
  32. /* max frame size, in samples */
  33. #define MPA_FRAME_SIZE 1152
  34. /* max compressed frame size */
  35. #define MPA_MAX_CODED_FRAME_SIZE 1792
  36. #define MPA_MAX_CHANNELS 2
  37. #define SBLIMIT 32 /* number of subbands */
  38. #define MPA_STEREO 0
  39. #define MPA_JSTEREO 1
  40. #define MPA_DUAL 2
  41. #define MPA_MONO 3
  42. /* header + layer + bitrate + freq + lsf/mpeg25 */
  43. #define SAME_HEADER_MASK \
  44. (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19))
  45. #define MP3_MASK 0xFFFE0CCF
  46. #ifndef FRAC_BITS
  47. #define FRAC_BITS 23 /* fractional bits for sb_samples and dct */
  48. #define WFRAC_BITS 16 /* fractional bits for window */
  49. #endif
  50. #define FRAC_ONE (1 << FRAC_BITS)
  51. #define FIX(a) ((int)((a) * FRAC_ONE))
  52. #if CONFIG_FLOAT
  53. typedef float OUT_INT;
  54. #else
  55. typedef int16_t OUT_INT;
  56. #endif
  57. #if CONFIG_FLOAT
  58. # define INTFLOAT float
  59. typedef float MPA_INT;
  60. #elif FRAC_BITS <= 15
  61. # define INTFLOAT int
  62. typedef int16_t MPA_INT;
  63. #else
  64. # define INTFLOAT int
  65. typedef int32_t MPA_INT;
  66. #endif
  67. #define BACKSTEP_SIZE 512
  68. #define EXTRABYTES 24
  69. /* layer 3 "granule" */
  70. typedef struct GranuleDef {
  71. uint8_t scfsi;
  72. int part2_3_length;
  73. int big_values;
  74. int global_gain;
  75. int scalefac_compress;
  76. uint8_t block_type;
  77. uint8_t switch_point;
  78. int table_select[3];
  79. int subblock_gain[3];
  80. uint8_t scalefac_scale;
  81. uint8_t count1table_select;
  82. int region_size[3]; /* number of huffman codes in each region */
  83. int preflag;
  84. int short_start, long_end; /* long/short band indexes */
  85. uint8_t scale_factors[40];
  86. INTFLOAT sb_hybrid[SBLIMIT * 18]; /* 576 samples */
  87. } GranuleDef;
  88. #define MPA_DECODE_HEADER \
  89. int frame_size; \
  90. int error_protection; \
  91. int layer; \
  92. int sample_rate; \
  93. int sample_rate_index; /* between 0 and 8 */ \
  94. int bit_rate; \
  95. int nb_channels; \
  96. int mode; \
  97. int mode_ext; \
  98. int lsf;
  99. typedef struct MPADecodeHeader {
  100. MPA_DECODE_HEADER
  101. } MPADecodeHeader;
  102. typedef struct MPADecodeContext {
  103. MPA_DECODE_HEADER
  104. uint8_t last_buf[2*BACKSTEP_SIZE + EXTRABYTES];
  105. int last_buf_size;
  106. /* next header (used in free format parsing) */
  107. uint32_t free_format_next_header;
  108. GetBitContext gb;
  109. GetBitContext in_gb;
  110. DECLARE_ALIGNED(16, MPA_INT, synth_buf)[MPA_MAX_CHANNELS][512 * 2];
  111. int synth_buf_offset[MPA_MAX_CHANNELS];
  112. DECLARE_ALIGNED(16, INTFLOAT, sb_samples)[MPA_MAX_CHANNELS][36][SBLIMIT];
  113. INTFLOAT mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */
  114. GranuleDef granules[2][2]; /* Used in Layer 3 */
  115. #ifdef DEBUG
  116. int frame_count;
  117. #endif
  118. int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3
  119. int dither_state;
  120. int error_recognition;
  121. AVCodecContext* avctx;
  122. MPADSPContext mpadsp;
  123. } MPADecodeContext;
  124. /* layer 3 huffman tables */
  125. typedef struct HuffTable {
  126. int xsize;
  127. const uint8_t *bits;
  128. const uint16_t *codes;
  129. } HuffTable;
  130. int ff_mpa_l2_select_table(int bitrate, int nb_channels, int freq, int lsf);
  131. int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bitrate);
  132. /* fast header check for resync */
  133. static inline int ff_mpa_check_header(uint32_t header){
  134. /* header */
  135. if ((header & 0xffe00000) != 0xffe00000)
  136. return -1;
  137. /* layer check */
  138. if ((header & (3<<17)) == 0)
  139. return -1;
  140. /* bit rate */
  141. if ((header & (0xf<<12)) == 0xf<<12)
  142. return -1;
  143. /* frequency */
  144. if ((header & (3<<10)) == 3<<10)
  145. return -1;
  146. return 0;
  147. }
  148. #endif /* AVCODEC_MPEGAUDIO_H */