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.

191 lines
9.0KB

  1. /*
  2. * DCA compatible decoder
  3. * Copyright (C) 2004 Gildas Bazin
  4. * Copyright (C) 2004 Benjamin Zores
  5. * Copyright (C) 2006 Benjamin Larsson
  6. * Copyright (C) 2007 Konstantin Shishkov
  7. *
  8. * This file is part of Libav.
  9. *
  10. * Libav is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * Libav is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with Libav; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. #ifndef AVCODEC_DCA_H
  25. #define AVCODEC_DCA_H
  26. #include <stdint.h>
  27. #include "libavutil/float_dsp.h"
  28. #include "libavutil/internal.h"
  29. #include "avcodec.h"
  30. #include "dcadsp.h"
  31. #include "fmtconvert.h"
  32. #include "get_bits.h"
  33. #define DCA_PRIM_CHANNELS_MAX (7)
  34. #define DCA_ABITS_MAX (32) /* Should be 28 */
  35. #define DCA_SUBSUBFRAMES_MAX (4)
  36. #define DCA_SUBFRAMES_MAX (16)
  37. #define DCA_BLOCKS_MAX (16)
  38. #define DCA_LFE_MAX (3)
  39. #define DCA_MAX_FRAME_SIZE 16384
  40. #define DCA_MAX_EXSS_HEADER_SIZE 4096
  41. #define DCA_BUFFER_PADDING_SIZE 1024
  42. enum DCAExtensionMask {
  43. DCA_EXT_CORE = 0x001, ///< core in core substream
  44. DCA_EXT_XXCH = 0x002, ///< XXCh channels extension in core substream
  45. DCA_EXT_X96 = 0x004, ///< 96/24 extension in core substream
  46. DCA_EXT_XCH = 0x008, ///< XCh channel extension in core substream
  47. DCA_EXT_EXSS_CORE = 0x010, ///< core in ExSS (extension substream)
  48. DCA_EXT_EXSS_XBR = 0x020, ///< extended bitrate extension in ExSS
  49. DCA_EXT_EXSS_XXCH = 0x040, ///< XXCh channels extension in ExSS
  50. DCA_EXT_EXSS_X96 = 0x080, ///< 96/24 extension in ExSS
  51. DCA_EXT_EXSS_LBR = 0x100, ///< low bitrate component in ExSS
  52. DCA_EXT_EXSS_XLL = 0x200, ///< lossless extension in ExSS
  53. };
  54. typedef struct DCAContext {
  55. AVClass *class; ///< class for AVOptions
  56. AVCodecContext *avctx;
  57. /* Frame header */
  58. int frame_type; ///< type of the current frame
  59. int samples_deficit; ///< deficit sample count
  60. int crc_present; ///< crc is present in the bitstream
  61. int sample_blocks; ///< number of PCM sample blocks
  62. int frame_size; ///< primary frame byte size
  63. int amode; ///< audio channels arrangement
  64. int sample_rate; ///< audio sampling rate
  65. int bit_rate; ///< transmission bit rate
  66. int bit_rate_index; ///< transmission bit rate index
  67. int dynrange; ///< embedded dynamic range flag
  68. int timestamp; ///< embedded time stamp flag
  69. int aux_data; ///< auxiliary data flag
  70. int hdcd; ///< source material is mastered in HDCD
  71. int ext_descr; ///< extension audio descriptor flag
  72. int ext_coding; ///< extended coding flag
  73. int aspf; ///< audio sync word insertion flag
  74. int lfe; ///< low frequency effects flag
  75. int predictor_history; ///< predictor history flag
  76. int header_crc; ///< header crc check bytes
  77. int multirate_inter; ///< multirate interpolator switch
  78. int version; ///< encoder software revision
  79. int copy_history; ///< copy history
  80. int source_pcm_res; ///< source pcm resolution
  81. int front_sum; ///< front sum/difference flag
  82. int surround_sum; ///< surround sum/difference flag
  83. int dialog_norm; ///< dialog normalisation parameter
  84. /* Primary audio coding header */
  85. int subframes; ///< number of subframes
  86. int total_channels; ///< number of channels including extensions
  87. int prim_channels; ///< number of primary audio channels
  88. int subband_activity[DCA_PRIM_CHANNELS_MAX]; ///< subband activity count
  89. int vq_start_subband[DCA_PRIM_CHANNELS_MAX]; ///< high frequency vq start subband
  90. int joint_intensity[DCA_PRIM_CHANNELS_MAX]; ///< joint intensity coding index
  91. int transient_huffman[DCA_PRIM_CHANNELS_MAX]; ///< transient mode code book
  92. int scalefactor_huffman[DCA_PRIM_CHANNELS_MAX]; ///< scale factor code book
  93. int bitalloc_huffman[DCA_PRIM_CHANNELS_MAX]; ///< bit allocation quantizer select
  94. int quant_index_huffman[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]; ///< quantization index codebook select
  95. float scalefactor_adj[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]; ///< scale factor adjustment
  96. /* Primary audio coding side information */
  97. int subsubframes[DCA_SUBFRAMES_MAX]; ///< number of subsubframes
  98. int partial_samples[DCA_SUBFRAMES_MAX]; ///< partial subsubframe samples count
  99. int prediction_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< prediction mode (ADPCM used or not)
  100. int prediction_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< prediction VQ coefs
  101. int bitalloc[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< bit allocation index
  102. int transition_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< transition mode (transients)
  103. int32_t scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][2];///< scale factors (2 if transient)
  104. int joint_huff[DCA_PRIM_CHANNELS_MAX]; ///< joint subband scale factors codebook
  105. int joint_scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< joint subband scale factors
  106. float downmix_coef[DCA_PRIM_CHANNELS_MAX + 1][2]; ///< stereo downmix coefficients
  107. int dynrange_coef; ///< dynamic range coefficient
  108. /* Core substream's embedded downmix coefficients (cf. ETSI TS 102 114 V1.4.1)
  109. * Input: primary audio channels (incl. LFE if present)
  110. * Output: downmix audio channels (up to 4, no LFE) */
  111. uint8_t core_downmix; ///< embedded downmix coefficients available
  112. uint8_t core_downmix_amode; ///< audio channel arrangement of embedded downmix
  113. uint16_t core_downmix_codes[DCA_PRIM_CHANNELS_MAX + 1][4]; ///< embedded downmix coefficients (9-bit codes)
  114. int32_t high_freq_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< VQ encoded high frequency subbands
  115. float lfe_data[2 * DCA_LFE_MAX * (DCA_BLOCKS_MAX + 4)]; ///< Low frequency effect data
  116. int lfe_scale_factor;
  117. /* Subband samples history (for ADPCM) */
  118. DECLARE_ALIGNED(16, float, subband_samples_hist)[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][4];
  119. DECLARE_ALIGNED(32, float, subband_fir_hist)[DCA_PRIM_CHANNELS_MAX][512];
  120. DECLARE_ALIGNED(32, float, subband_fir_noidea)[DCA_PRIM_CHANNELS_MAX][32];
  121. int hist_index[DCA_PRIM_CHANNELS_MAX];
  122. DECLARE_ALIGNED(32, float, raXin)[32];
  123. int output; ///< type of output
  124. DECLARE_ALIGNED(32, float, subband_samples)[DCA_BLOCKS_MAX][DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][8];
  125. float *samples_chanptr[DCA_PRIM_CHANNELS_MAX + 1];
  126. float *extra_channels[DCA_PRIM_CHANNELS_MAX + 1];
  127. uint8_t *extra_channels_buffer;
  128. unsigned int extra_channels_buffer_size;
  129. uint8_t dca_buffer[DCA_MAX_FRAME_SIZE + DCA_MAX_EXSS_HEADER_SIZE + DCA_BUFFER_PADDING_SIZE];
  130. int dca_buffer_size; ///< how much data is in the dca_buffer
  131. const int8_t *channel_order_tab; ///< channel reordering table, lfe and non lfe
  132. GetBitContext gb;
  133. /* Current position in DCA frame */
  134. int current_subframe;
  135. int current_subsubframe;
  136. int core_ext_mask; ///< present extensions in the core substream
  137. /* XCh extension information */
  138. int xch_present; ///< XCh extension present and valid
  139. int xch_base_channel; ///< index of first (only) channel containing XCH data
  140. int xch_disable; ///< whether the XCh extension should be decoded or not
  141. /* ExSS header parser */
  142. int static_fields; ///< static fields present
  143. int mix_metadata; ///< mixing metadata present
  144. int num_mix_configs; ///< number of mix out configurations
  145. int mix_config_num_ch[4]; ///< number of channels in each mix out configuration
  146. int profile;
  147. int debug_flag; ///< used for suppressing repeated error messages output
  148. AVFloatDSPContext fdsp;
  149. FFTContext imdct;
  150. SynthFilterContext synth;
  151. DCADSPContext dcadsp;
  152. FmtConvertContext fmt_conv;
  153. } DCAContext;
  154. extern av_export const uint32_t avpriv_dca_sample_rates[16];
  155. /**
  156. * Convert bitstream to one representation based on sync marker
  157. */
  158. int ff_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
  159. int max_size);
  160. void ff_dca_exss_parse_header(DCAContext *s);
  161. #endif /* AVCODEC_DCA_H */