dca_xll.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (C) 2016 foo86
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVCODEC_DCA_XLL_H
  21. #define AVCODEC_DCA_XLL_H
  22. #include "libavutil/common.h"
  23. #include "libavutil/mem.h"
  24. #include "avcodec.h"
  25. #include "internal.h"
  26. #include "get_bits.h"
  27. #include "dca.h"
  28. #include "dcadsp.h"
  29. #include "dca_exss.h"
  30. #define DCA_XLL_CHSETS_MAX 3
  31. #define DCA_XLL_CHANNELS_MAX 8
  32. #define DCA_XLL_BANDS_MAX 2
  33. #define DCA_XLL_ADAPT_PRED_ORDER_MAX 16
  34. #define DCA_XLL_DECI_HISTORY_MAX 8
  35. #define DCA_XLL_DMIX_SCALES_MAX ((DCA_XLL_CHSETS_MAX - 1) * DCA_XLL_CHANNELS_MAX)
  36. #define DCA_XLL_DMIX_COEFFS_MAX (DCA_XLL_DMIX_SCALES_MAX * DCA_XLL_CHANNELS_MAX)
  37. #define DCA_XLL_PBR_BUFFER_MAX (240 << 10)
  38. #define DCA_XLL_SAMPLE_BUFFERS_MAX 3
  39. typedef struct DCAXllBand {
  40. int decor_enabled; ///< Pairwise channel decorrelation flag
  41. int orig_order[DCA_XLL_CHANNELS_MAX]; ///< Original channel order
  42. int decor_coeff[DCA_XLL_CHANNELS_MAX / 2]; ///< Pairwise channel coefficients
  43. int adapt_pred_order[DCA_XLL_CHANNELS_MAX]; ///< Adaptive predictor order
  44. int highest_pred_order; ///< Highest adaptive predictor order
  45. int fixed_pred_order[DCA_XLL_CHANNELS_MAX]; ///< Fixed predictor order
  46. int adapt_refl_coeff[DCA_XLL_CHANNELS_MAX][DCA_XLL_ADAPT_PRED_ORDER_MAX]; ///< Adaptive predictor reflection coefficients
  47. int dmix_embedded; ///< Downmix performed by encoder in frequency band
  48. int lsb_section_size; ///< Size of LSB section in any segment
  49. int nscalablelsbs[DCA_XLL_CHANNELS_MAX]; ///< Number of bits to represent the samples in LSB part
  50. int bit_width_adjust[DCA_XLL_CHANNELS_MAX]; ///< Number of bits discarded by authoring
  51. int32_t *msb_sample_buffer[DCA_XLL_CHANNELS_MAX]; ///< MSB sample buffer pointers
  52. int32_t *lsb_sample_buffer[DCA_XLL_CHANNELS_MAX]; ///< LSB sample buffer pointers or NULL
  53. } DCAXllBand;
  54. typedef struct DCAXllChSet {
  55. // Channel set header
  56. int nchannels; ///< Number of channels in the channel set (N)
  57. int residual_encode; ///< Residual encoding mask (0 - residual, 1 - full channel)
  58. int pcm_bit_res; ///< PCM bit resolution (variable)
  59. int storage_bit_res; ///< Storage bit resolution (16 or 24)
  60. int freq; ///< Original sampling frequency (max. 96000 Hz)
  61. int primary_chset; ///< Primary channel set flag
  62. int dmix_coeffs_present; ///< Downmix coefficients present in stream
  63. int dmix_embedded; ///< Downmix already performed by encoder
  64. int dmix_type; ///< Primary channel set downmix type
  65. int hier_chset; ///< Whether the channel set is part of a hierarchy
  66. int hier_ofs; ///< Number of preceding channels in a hierarchy (M)
  67. int dmix_coeff[DCA_XLL_DMIX_COEFFS_MAX]; ///< Downmixing coefficients
  68. int dmix_scale[DCA_XLL_DMIX_SCALES_MAX]; ///< Downmixing scales
  69. int dmix_scale_inv[DCA_XLL_DMIX_SCALES_MAX]; ///< Inverse downmixing scales
  70. int ch_mask; ///< Channel mask for set
  71. int ch_remap[DCA_XLL_CHANNELS_MAX]; ///< Channel to speaker map
  72. int nfreqbands; ///< Number of frequency bands (1 or 2)
  73. int nabits; ///< Number of bits to read bit allocation coding parameter
  74. DCAXllBand bands[DCA_XLL_BANDS_MAX]; ///< Frequency bands
  75. // Frequency band coding parameters
  76. int seg_common; ///< Segment type
  77. int rice_code_flag[DCA_XLL_CHANNELS_MAX]; ///< Rice coding flag
  78. int bitalloc_hybrid_linear[DCA_XLL_CHANNELS_MAX]; ///< Binary code length for isolated samples
  79. int bitalloc_part_a[DCA_XLL_CHANNELS_MAX]; ///< Coding parameter for part A of segment
  80. int bitalloc_part_b[DCA_XLL_CHANNELS_MAX]; ///< Coding parameter for part B of segment
  81. int nsamples_part_a[DCA_XLL_CHANNELS_MAX]; ///< Number of samples in part A of segment
  82. // Decimator history
  83. DECLARE_ALIGNED(32, int32_t, deci_history)[DCA_XLL_CHANNELS_MAX][DCA_XLL_DECI_HISTORY_MAX]; ///< Decimator history for frequency band 1
  84. // Sample buffers
  85. unsigned int sample_size[DCA_XLL_SAMPLE_BUFFERS_MAX];
  86. int32_t *sample_buffer[DCA_XLL_SAMPLE_BUFFERS_MAX];
  87. } DCAXllChSet;
  88. typedef struct DCAXllDecoder {
  89. AVCodecContext *avctx;
  90. GetBitContext gb;
  91. int frame_size; ///< Number of bytes in a lossless frame
  92. int nchsets; ///< Number of channels sets per frame
  93. int nframesegs; ///< Number of segments per frame
  94. int nsegsamples_log2; ///< log2(nsegsamples)
  95. int nsegsamples; ///< Samples in segment per one frequency band
  96. int nframesamples_log2; ///< log2(nframesamples)
  97. int nframesamples; ///< Samples in frame per one frequency band
  98. int seg_size_nbits; ///< Number of bits used to read segment size
  99. int band_crc_present; ///< Presence of CRC16 within each frequency band
  100. int scalable_lsbs; ///< MSB/LSB split flag
  101. int ch_mask_nbits; ///< Number of bits used to read channel mask
  102. int fixed_lsb_width; ///< Fixed LSB width
  103. DCAXllChSet chset[DCA_XLL_CHSETS_MAX]; ///< Channel sets
  104. int *navi; ///< NAVI table
  105. unsigned int navi_size;
  106. int nfreqbands; ///< Highest number of frequency bands
  107. int nchannels; ///< Total number of channels in a hierarchy
  108. int nreschsets; ///< Number of channel sets that have residual encoded channels
  109. int nactivechsets; ///< Number of active channel sets to decode
  110. int hd_stream_id; ///< Previous DTS-HD stream ID for detecting changes
  111. uint8_t *pbr_buffer; ///< Peak bit rate (PBR) smoothing buffer
  112. int pbr_length; ///< Length in bytes of data currently buffered
  113. int pbr_delay; ///< Delay in frames before decoding buffered data
  114. DCADSPContext *dcadsp;
  115. int output_mask;
  116. int32_t *output_samples[DCA_SPEAKER_COUNT];
  117. } DCAXllDecoder;
  118. int ff_dca_xll_parse(DCAXllDecoder *s, uint8_t *data, DCAExssAsset *asset);
  119. int ff_dca_xll_filter_frame(DCAXllDecoder *s, AVFrame *frame);
  120. av_cold void ff_dca_xll_flush(DCAXllDecoder *s);
  121. av_cold void ff_dca_xll_close(DCAXllDecoder *s);
  122. #endif