Changeset d8901c2f in ffmpeg
- Timestamp:
- Feb 14, 2015, 9:02:41 PM (10 years ago)
- Branches:
- master
- Children:
- ad0be703
- Parents:
- 6998400c (diff), b339019d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- Michael Niedermayer <michaelni@gmx.at> (02/14/15 20:48:32)
- git-committer:
- Michael Niedermayer <michaelni@gmx.at> (02/14/15 21:02:41)
- Location:
- libavcodec
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libavcodec/Makefile
r6998400c rd8901c2f 190 190 OBJS-$(CONFIG_CYUV_DECODER) += cyuv.o 191 191 OBJS-$(CONFIG_DCA_DECODER) += dcadec.o dca.o dcadsp.o \ 192 synth_filter.o192 dca_exss.o synth_filter.o 193 193 OBJS-$(CONFIG_DCA_ENCODER) += dcaenc.o dca.o 194 194 OBJS-$(CONFIG_DIRAC_DECODER) += diracdec.o dirac.o diracdsp.o \ -
libavcodec/dca.h
r6998400c rd8901c2f 27 27 28 28 #include <stdint.h> 29 30 #include "libavutil/float_dsp.h" 29 31 #include "libavutil/internal.h" 32 33 #include "avcodec.h" 34 #include "dcadsp.h" 35 #include "fmtconvert.h" 36 #include "get_bits.h" 30 37 31 38 /** DCA syncwords, also used for bitstream type detection */ … … 38 45 #define DCA_HD_MARKER 0x64582025 39 46 47 #define DCA_PRIM_CHANNELS_MAX (7) 48 #define DCA_ABITS_MAX (32) /* Should be 28 */ 49 #define DCA_SUBSUBFRAMES_MAX (4) 50 #define DCA_SUBFRAMES_MAX (16) 51 #define DCA_BLOCKS_MAX (16) 52 #define DCA_LFE_MAX (3) 53 #define DCA_CHSETS_MAX (4) 54 #define DCA_CHSET_CHANS_MAX (8) 55 56 #define DCA_MAX_FRAME_SIZE 16384 57 #define DCA_MAX_EXSS_HEADER_SIZE 4096 58 59 #define DCA_BUFFER_PADDING_SIZE 1024 60 61 enum DCAExtensionMask { 62 DCA_EXT_CORE = 0x001, ///< core in core substream 63 DCA_EXT_XXCH = 0x002, ///< XXCh channels extension in core substream 64 DCA_EXT_X96 = 0x004, ///< 96/24 extension in core substream 65 DCA_EXT_XCH = 0x008, ///< XCh channel extension in core substream 66 DCA_EXT_EXSS_CORE = 0x010, ///< core in ExSS (extension substream) 67 DCA_EXT_EXSS_XBR = 0x020, ///< extended bitrate extension in ExSS 68 DCA_EXT_EXSS_XXCH = 0x040, ///< XXCh channels extension in ExSS 69 DCA_EXT_EXSS_X96 = 0x080, ///< 96/24 extension in ExSS 70 DCA_EXT_EXSS_LBR = 0x100, ///< low bitrate component in ExSS 71 DCA_EXT_EXSS_XLL = 0x200, ///< lossless extension in ExSS 72 }; 73 74 typedef struct DCAContext { 75 const AVClass *class; ///< class for AVOptions 76 AVCodecContext *avctx; 77 /* Frame header */ 78 int frame_type; ///< type of the current frame 79 int samples_deficit; ///< deficit sample count 80 int crc_present; ///< crc is present in the bitstream 81 int sample_blocks; ///< number of PCM sample blocks 82 int frame_size; ///< primary frame byte size 83 int amode; ///< audio channels arrangement 84 int sample_rate; ///< audio sampling rate 85 int bit_rate; ///< transmission bit rate 86 int bit_rate_index; ///< transmission bit rate index 87 88 int dynrange; ///< embedded dynamic range flag 89 int timestamp; ///< embedded time stamp flag 90 int aux_data; ///< auxiliary data flag 91 int hdcd; ///< source material is mastered in HDCD 92 int ext_descr; ///< extension audio descriptor flag 93 int ext_coding; ///< extended coding flag 94 int aspf; ///< audio sync word insertion flag 95 int lfe; ///< low frequency effects flag 96 int predictor_history; ///< predictor history flag 97 int header_crc; ///< header crc check bytes 98 int multirate_inter; ///< multirate interpolator switch 99 int version; ///< encoder software revision 100 int copy_history; ///< copy history 101 int source_pcm_res; ///< source pcm resolution 102 int front_sum; ///< front sum/difference flag 103 int surround_sum; ///< surround sum/difference flag 104 int dialog_norm; ///< dialog normalisation parameter 105 106 /* Primary audio coding header */ 107 int subframes; ///< number of subframes 108 int total_channels; ///< number of channels including extensions 109 int prim_channels; ///< number of primary audio channels 110 int subband_activity[DCA_PRIM_CHANNELS_MAX]; ///< subband activity count 111 int vq_start_subband[DCA_PRIM_CHANNELS_MAX]; ///< high frequency vq start subband 112 int joint_intensity[DCA_PRIM_CHANNELS_MAX]; ///< joint intensity coding index 113 int transient_huffman[DCA_PRIM_CHANNELS_MAX]; ///< transient mode code book 114 int scalefactor_huffman[DCA_PRIM_CHANNELS_MAX]; ///< scale factor code book 115 int bitalloc_huffman[DCA_PRIM_CHANNELS_MAX]; ///< bit allocation quantizer select 116 int quant_index_huffman[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]; ///< quantization index codebook select 117 float scalefactor_adj[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]; ///< scale factor adjustment 118 119 /* Primary audio coding side information */ 120 int subsubframes[DCA_SUBFRAMES_MAX]; ///< number of subsubframes 121 int partial_samples[DCA_SUBFRAMES_MAX]; ///< partial subsubframe samples count 122 int prediction_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< prediction mode (ADPCM used or not) 123 int prediction_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< prediction VQ coefs 124 int bitalloc[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< bit allocation index 125 int transition_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< transition mode (transients) 126 int32_t scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][2];///< scale factors (2 if transient) 127 int joint_huff[DCA_PRIM_CHANNELS_MAX]; ///< joint subband scale factors codebook 128 int joint_scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< joint subband scale factors 129 float downmix_coef[DCA_PRIM_CHANNELS_MAX + 1][2]; ///< stereo downmix coefficients 130 int dynrange_coef; ///< dynamic range coefficient 131 132 /* Core substream's embedded downmix coefficients (cf. ETSI TS 102 114 V1.4.1) 133 * Input: primary audio channels (incl. LFE if present) 134 * Output: downmix audio channels (up to 4, no LFE) */ 135 uint8_t core_downmix; ///< embedded downmix coefficients available 136 uint8_t core_downmix_amode; ///< audio channel arrangement of embedded downmix 137 uint16_t core_downmix_codes[DCA_PRIM_CHANNELS_MAX + 1][4]; ///< embedded downmix coefficients (9-bit codes) 138 139 int32_t high_freq_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< VQ encoded high frequency subbands 140 141 float lfe_data[2 * DCA_LFE_MAX * (DCA_BLOCKS_MAX + 4)]; ///< Low frequency effect data 142 int lfe_scale_factor; 143 144 /* Subband samples history (for ADPCM) */ 145 DECLARE_ALIGNED(16, float, subband_samples_hist)[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][4]; 146 DECLARE_ALIGNED(32, float, subband_fir_hist)[DCA_PRIM_CHANNELS_MAX][512]; 147 DECLARE_ALIGNED(32, float, subband_fir_noidea)[DCA_PRIM_CHANNELS_MAX][32]; 148 int hist_index[DCA_PRIM_CHANNELS_MAX]; 149 DECLARE_ALIGNED(32, float, raXin)[32]; 150 151 int output; ///< type of output 152 153 DECLARE_ALIGNED(32, float, subband_samples)[DCA_BLOCKS_MAX][DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][8]; 154 float *samples_chanptr[DCA_PRIM_CHANNELS_MAX + 1]; 155 float *extra_channels[DCA_PRIM_CHANNELS_MAX + 1]; 156 uint8_t *extra_channels_buffer; 157 unsigned int extra_channels_buffer_size; 158 159 uint8_t dca_buffer[DCA_MAX_FRAME_SIZE + DCA_MAX_EXSS_HEADER_SIZE + DCA_BUFFER_PADDING_SIZE]; 160 int dca_buffer_size; ///< how much data is in the dca_buffer 161 162 const int8_t *channel_order_tab; ///< channel reordering table, lfe and non lfe 163 GetBitContext gb; 164 /* Current position in DCA frame */ 165 int current_subframe; 166 int current_subsubframe; 167 168 int core_ext_mask; ///< present extensions in the core substream 169 170 /* XCh extension information */ 171 int xch_present; ///< XCh extension present and valid 172 int xch_base_channel; ///< index of first (only) channel containing XCH data 173 int xch_disable; ///< whether the XCh extension should be decoded or not 174 175 /* XXCH extension information */ 176 int xxch_chset; 177 int xxch_nbits_spk_mask; 178 uint32_t xxch_core_spkmask; 179 uint32_t xxch_spk_masks[4]; /* speaker masks, last element is core mask */ 180 int xxch_chset_nch[4]; 181 float xxch_dmix_sf[DCA_CHSETS_MAX]; 182 183 uint32_t xxch_dmix_embedded; /* lower layer has mix pre-embedded, per chset */ 184 float xxch_dmix_coeff[DCA_PRIM_CHANNELS_MAX][32]; /* worst case sizing */ 185 186 int8_t xxch_order_tab[32]; 187 int8_t lfe_index; 188 189 /* ExSS header parser */ 190 int static_fields; ///< static fields present 191 int mix_metadata; ///< mixing metadata present 192 int num_mix_configs; ///< number of mix out configurations 193 int mix_config_num_ch[4]; ///< number of channels in each mix out configuration 194 195 int profile; 196 197 int debug_flag; ///< used for suppressing repeated error messages output 198 AVFloatDSPContext *fdsp; 199 FFTContext imdct; 200 SynthFilterContext synth; 201 DCADSPContext dcadsp; 202 FmtConvertContext fmt_conv; 203 } DCAContext; 204 40 205 extern av_export const uint32_t avpriv_dca_sample_rates[16]; 41 206 … … 46 211 int max_size); 47 212 213 int ff_dca_xbr_parse_frame(DCAContext *s); 214 int ff_dca_xxch_decode_frame(DCAContext *s); 215 48 216 #endif /* AVCODEC_DCA_H */ -
libavcodec/dcadec.c
r6998400c rd8901c2f 41 41 #include "dcadsp.h" 42 42 #include "dcahuff.h" 43 #include "dca_exss.h" 43 44 #include "fft.h" 44 45 #include "fmtconvert.h" … … 53 54 54 55 //#define TRACE 55 56 #define DCA_PRIM_CHANNELS_MAX (7)57 #define DCA_ABITS_MAX (32) /* Should be 28 */58 #define DCA_SUBSUBFRAMES_MAX (4)59 #define DCA_SUBFRAMES_MAX (16)60 #define DCA_BLOCKS_MAX (16)61 #define DCA_LFE_MAX (3)62 #define DCA_CHSETS_MAX (4)63 #define DCA_CHSET_CHANS_MAX (8)64 56 65 57 enum DCAMode { … … 77 69 }; 78 70 79 /* these are unconfirmed but should be mostly correct */80 enum DCAExSSSpeakerMask {81 DCA_EXSS_FRONT_CENTER = 0x0001,82 DCA_EXSS_FRONT_LEFT_RIGHT = 0x0002,83 DCA_EXSS_SIDE_REAR_LEFT_RIGHT = 0x0004,84 DCA_EXSS_LFE = 0x0008,85 DCA_EXSS_REAR_CENTER = 0x0010,86 DCA_EXSS_FRONT_HIGH_LEFT_RIGHT = 0x0020,87 DCA_EXSS_REAR_LEFT_RIGHT = 0x0040,88 DCA_EXSS_FRONT_HIGH_CENTER = 0x0080,89 DCA_EXSS_OVERHEAD = 0x0100,90 DCA_EXSS_CENTER_LEFT_RIGHT = 0x0200,91 DCA_EXSS_WIDE_LEFT_RIGHT = 0x0400,92 DCA_EXSS_SIDE_LEFT_RIGHT = 0x0800,93 DCA_EXSS_LFE2 = 0x1000,94 DCA_EXSS_SIDE_HIGH_LEFT_RIGHT = 0x2000,95 DCA_EXSS_REAR_HIGH_CENTER = 0x4000,96 DCA_EXSS_REAR_HIGH_LEFT_RIGHT = 0x8000,97 };98 71 99 72 enum DCAXxchSpeakerMask { … … 159 132 }; 160 133 161 enum DCAExtensionMask {162 DCA_EXT_CORE = 0x001, ///< core in core substream163 DCA_EXT_XXCH = 0x002, ///< XXCh channels extension in core substream164 DCA_EXT_X96 = 0x004, ///< 96/24 extension in core substream165 DCA_EXT_XCH = 0x008, ///< XCh channel extension in core substream166 DCA_EXT_EXSS_CORE = 0x010, ///< core in ExSS (extension substream)167 DCA_EXT_EXSS_XBR = 0x020, ///< extended bitrate extension in ExSS168 DCA_EXT_EXSS_XXCH = 0x040, ///< XXCh channels extension in ExSS169 DCA_EXT_EXSS_X96 = 0x080, ///< 96/24 extension in ExSS170 DCA_EXT_EXSS_LBR = 0x100, ///< low bitrate component in ExSS171 DCA_EXT_EXSS_XLL = 0x200, ///< lossless extension in ExSS172 };173 174 134 /* -1 are reserved or unknown */ 175 135 static const int dca_ext_audio_descr_mask[] = { … … 183 143 -1, 184 144 }; 185 186 /* extensions that reside in core substream */187 #define DCA_CORE_EXTS (DCA_EXT_XCH | DCA_EXT_XXCH | DCA_EXT_X96)188 145 189 146 /* Tables for mapping dts channel configurations to libavcodec multichannel api. … … 322 279 #define HEADER_SIZE 14 323 280 324 #define DCA_MAX_FRAME_SIZE 16384325 #define DCA_MAX_EXSS_HEADER_SIZE 4096326 327 #define DCA_BUFFER_PADDING_SIZE 1024328 329 281 #define DCA_NSYNCAUX 0x9A1105A0 330 282 … … 348 300 ba->offset; 349 301 } 350 351 typedef struct DCAContext {352 const AVClass *class; ///< class for AVOptions353 AVCodecContext *avctx;354 /* Frame header */355 int frame_type; ///< type of the current frame356 int samples_deficit; ///< deficit sample count357 int crc_present; ///< crc is present in the bitstream358 int sample_blocks; ///< number of PCM sample blocks359 int frame_size; ///< primary frame byte size360 int amode; ///< audio channels arrangement361 int sample_rate; ///< audio sampling rate362 int bit_rate; ///< transmission bit rate363 int bit_rate_index; ///< transmission bit rate index364 365 int dynrange; ///< embedded dynamic range flag366 int timestamp; ///< embedded time stamp flag367 int aux_data; ///< auxiliary data flag368 int hdcd; ///< source material is mastered in HDCD369 int ext_descr; ///< extension audio descriptor flag370 int ext_coding; ///< extended coding flag371 int aspf; ///< audio sync word insertion flag372 int lfe; ///< low frequency effects flag373 int predictor_history; ///< predictor history flag374 int header_crc; ///< header crc check bytes375 int multirate_inter; ///< multirate interpolator switch376 int version; ///< encoder software revision377 int copy_history; ///< copy history378 int source_pcm_res; ///< source pcm resolution379 int front_sum; ///< front sum/difference flag380 int surround_sum; ///< surround sum/difference flag381 int dialog_norm; ///< dialog normalisation parameter382 383 /* Primary audio coding header */384 int subframes; ///< number of subframes385 int total_channels; ///< number of channels including extensions386 int prim_channels; ///< number of primary audio channels387 int subband_activity[DCA_PRIM_CHANNELS_MAX]; ///< subband activity count388 int vq_start_subband[DCA_PRIM_CHANNELS_MAX]; ///< high frequency vq start subband389 int joint_intensity[DCA_PRIM_CHANNELS_MAX]; ///< joint intensity coding index390 int transient_huffman[DCA_PRIM_CHANNELS_MAX]; ///< transient mode code book391 int scalefactor_huffman[DCA_PRIM_CHANNELS_MAX]; ///< scale factor code book392 int bitalloc_huffman[DCA_PRIM_CHANNELS_MAX]; ///< bit allocation quantizer select393 int quant_index_huffman[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]; ///< quantization index codebook select394 float scalefactor_adj[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]; ///< scale factor adjustment395 396 /* Primary audio coding side information */397 int subsubframes[DCA_SUBFRAMES_MAX]; ///< number of subsubframes398 int partial_samples[DCA_SUBFRAMES_MAX]; ///< partial subsubframe samples count399 int prediction_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< prediction mode (ADPCM used or not)400 int prediction_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< prediction VQ coefs401 int bitalloc[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< bit allocation index402 int transition_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< transition mode (transients)403 int32_t scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][2];///< scale factors (2 if transient)404 int joint_huff[DCA_PRIM_CHANNELS_MAX]; ///< joint subband scale factors codebook405 int joint_scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< joint subband scale factors406 float downmix_coef[DCA_PRIM_CHANNELS_MAX + 1][2]; ///< stereo downmix coefficients407 int dynrange_coef; ///< dynamic range coefficient408 409 /* Core substream's embedded downmix coefficients (cf. ETSI TS 102 114 V1.4.1)410 * Input: primary audio channels (incl. LFE if present)411 * Output: downmix audio channels (up to 4, no LFE) */412 uint8_t core_downmix; ///< embedded downmix coefficients available413 uint8_t core_downmix_amode; ///< audio channel arrangement of embedded downmix414 uint16_t core_downmix_codes[DCA_PRIM_CHANNELS_MAX + 1][4]; ///< embedded downmix coefficients (9-bit codes)415 416 int32_t high_freq_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< VQ encoded high frequency subbands417 418 float lfe_data[2 * DCA_LFE_MAX * (DCA_BLOCKS_MAX + 4)]; ///< Low frequency effect data419 int lfe_scale_factor;420 421 /* Subband samples history (for ADPCM) */422 DECLARE_ALIGNED(16, float, subband_samples_hist)[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][4];423 DECLARE_ALIGNED(32, float, subband_fir_hist)[DCA_PRIM_CHANNELS_MAX][512];424 DECLARE_ALIGNED(32, float, subband_fir_noidea)[DCA_PRIM_CHANNELS_MAX][32];425 int hist_index[DCA_PRIM_CHANNELS_MAX];426 DECLARE_ALIGNED(32, float, raXin)[32];427 428 int output; ///< type of output429 430 DECLARE_ALIGNED(32, float, subband_samples)[DCA_BLOCKS_MAX][DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][8];431 float *samples_chanptr[DCA_PRIM_CHANNELS_MAX + 1];432 float *extra_channels[DCA_PRIM_CHANNELS_MAX + 1];433 uint8_t *extra_channels_buffer;434 unsigned int extra_channels_buffer_size;435 436 uint8_t dca_buffer[DCA_MAX_FRAME_SIZE + DCA_MAX_EXSS_HEADER_SIZE + DCA_BUFFER_PADDING_SIZE];437 int dca_buffer_size; ///< how much data is in the dca_buffer438 439 const int8_t *channel_order_tab; ///< channel reordering table, lfe and non lfe440 GetBitContext gb;441 /* Current position in DCA frame */442 int current_subframe;443 int current_subsubframe;444 445 int core_ext_mask; ///< present extensions in the core substream446 447 /* XCh extension information */448 int xch_present; ///< XCh extension present and valid449 int xch_base_channel; ///< index of first (only) channel containing XCH data450 int xch_disable; ///< whether the XCh extension should be decoded or not451 452 /* XXCH extension information */453 int xxch_chset;454 int xxch_nbits_spk_mask;455 uint32_t xxch_core_spkmask;456 uint32_t xxch_spk_masks[4]; /* speaker masks, last element is core mask */457 int xxch_chset_nch[4];458 float xxch_dmix_sf[DCA_CHSETS_MAX];459 460 uint32_t xxch_dmix_embedded; /* lower layer has mix pre-embedded, per chset */461 float xxch_dmix_coeff[DCA_PRIM_CHANNELS_MAX][32]; /* worst case sizing */462 463 int8_t xxch_order_tab[32];464 int8_t lfe_index;465 466 /* ExSS header parser */467 int static_fields; ///< static fields present468 int mix_metadata; ///< mixing metadata present469 int num_mix_configs; ///< number of mix out configurations470 int mix_config_num_ch[4]; ///< number of channels in each mix out configuration471 472 int profile;473 474 int debug_flag; ///< used for suppressing repeated error messages output475 AVFloatDSPContext *fdsp;476 FFTContext imdct;477 SynthFilterContext synth;478 DCADSPContext dcadsp;479 FmtConvertContext fmt_conv;480 } DCAContext;481 302 482 303 static float dca_dmix_code(unsigned code); … … 1595 1416 } 1596 1417 1597 /** 1598 * Return the number of channels in an ExSS speaker mask (HD) 1599 */ 1600 static int dca_exss_mask2count(int mask) 1601 { 1602 /* count bits that mean speaker pairs twice */ 1603 return av_popcount(mask) + 1604 av_popcount(mask & (DCA_EXSS_CENTER_LEFT_RIGHT | 1605 DCA_EXSS_FRONT_LEFT_RIGHT | 1606 DCA_EXSS_FRONT_HIGH_LEFT_RIGHT | 1607 DCA_EXSS_WIDE_LEFT_RIGHT | 1608 DCA_EXSS_SIDE_LEFT_RIGHT | 1609 DCA_EXSS_SIDE_HIGH_LEFT_RIGHT | 1610 DCA_EXSS_SIDE_REAR_LEFT_RIGHT | 1611 DCA_EXSS_REAR_LEFT_RIGHT | 1612 DCA_EXSS_REAR_HIGH_LEFT_RIGHT)); 1613 } 1614 1615 /** 1616 * Skip mixing coefficients of a single mix out configuration (HD) 1617 */ 1618 static void dca_exss_skip_mix_coeffs(GetBitContext *gb, int channels, int out_ch) 1619 { 1620 int i; 1621 1622 for (i = 0; i < channels; i++) { 1623 int mix_map_mask = get_bits(gb, out_ch); 1624 int num_coeffs = av_popcount(mix_map_mask); 1625 skip_bits_long(gb, num_coeffs * 6); 1626 } 1627 } 1628 1629 /** 1630 * Parse extension substream asset header (HD) 1631 */ 1632 static int dca_exss_parse_asset_header(DCAContext *s) 1633 { 1634 int header_pos = get_bits_count(&s->gb); 1635 int header_size; 1636 int channels = 0; 1637 int embedded_stereo = 0; 1638 int embedded_6ch = 0; 1639 int drc_code_present; 1640 int extensions_mask = 0; 1641 int i, j; 1642 1643 if (get_bits_left(&s->gb) < 16) 1644 return -1; 1645 1646 /* We will parse just enough to get to the extensions bitmask with which 1647 * we can set the profile value. */ 1648 1649 header_size = get_bits(&s->gb, 9) + 1; 1650 skip_bits(&s->gb, 3); // asset index 1651 1652 if (s->static_fields) { 1653 if (get_bits1(&s->gb)) 1654 skip_bits(&s->gb, 4); // asset type descriptor 1655 if (get_bits1(&s->gb)) 1656 skip_bits_long(&s->gb, 24); // language descriptor 1657 1658 if (get_bits1(&s->gb)) { 1659 /* How can one fit 1024 bytes of text here if the maximum value 1660 * for the asset header size field above was 512 bytes? */ 1661 int text_length = get_bits(&s->gb, 10) + 1; 1662 if (get_bits_left(&s->gb) < text_length * 8) 1663 return -1; 1664 skip_bits_long(&s->gb, text_length * 8); // info text 1665 } 1666 1667 skip_bits(&s->gb, 5); // bit resolution - 1 1668 skip_bits(&s->gb, 4); // max sample rate code 1669 channels = get_bits(&s->gb, 8) + 1; 1670 1671 if (get_bits1(&s->gb)) { // 1-to-1 channels to speakers 1672 int spkr_remap_sets; 1673 int spkr_mask_size = 16; 1674 int num_spkrs[7]; 1675 1676 if (channels > 2) 1677 embedded_stereo = get_bits1(&s->gb); 1678 if (channels > 6) 1679 embedded_6ch = get_bits1(&s->gb); 1680 1681 if (get_bits1(&s->gb)) { 1682 spkr_mask_size = (get_bits(&s->gb, 2) + 1) << 2; 1683 skip_bits(&s->gb, spkr_mask_size); // spkr activity mask 1684 } 1685 1686 spkr_remap_sets = get_bits(&s->gb, 3); 1687 1688 for (i = 0; i < spkr_remap_sets; i++) { 1689 /* std layout mask for each remap set */ 1690 num_spkrs[i] = dca_exss_mask2count(get_bits(&s->gb, spkr_mask_size)); 1691 } 1692 1693 for (i = 0; i < spkr_remap_sets; i++) { 1694 int num_dec_ch_remaps = get_bits(&s->gb, 5) + 1; 1695 if (get_bits_left(&s->gb) < 0) 1696 return -1; 1697 1698 for (j = 0; j < num_spkrs[i]; j++) { 1699 int remap_dec_ch_mask = get_bits_long(&s->gb, num_dec_ch_remaps); 1700 int num_dec_ch = av_popcount(remap_dec_ch_mask); 1701 skip_bits_long(&s->gb, num_dec_ch * 5); // remap codes 1702 } 1703 } 1704 } else { 1705 skip_bits(&s->gb, 3); // representation type 1706 } 1707 } 1708 1709 drc_code_present = get_bits1(&s->gb); 1710 if (drc_code_present) 1711 get_bits(&s->gb, 8); // drc code 1712 1713 if (get_bits1(&s->gb)) 1714 skip_bits(&s->gb, 5); // dialog normalization code 1715 1716 if (drc_code_present && embedded_stereo) 1717 get_bits(&s->gb, 8); // drc stereo code 1718 1719 if (s->mix_metadata && get_bits1(&s->gb)) { 1720 skip_bits(&s->gb, 1); // external mix 1721 skip_bits(&s->gb, 6); // post mix gain code 1722 1723 if (get_bits(&s->gb, 2) != 3) // mixer drc code 1724 skip_bits(&s->gb, 3); // drc limit 1725 else 1726 skip_bits(&s->gb, 8); // custom drc code 1727 1728 if (get_bits1(&s->gb)) // channel specific scaling 1729 for (i = 0; i < s->num_mix_configs; i++) 1730 skip_bits_long(&s->gb, s->mix_config_num_ch[i] * 6); // scale codes 1731 else 1732 skip_bits_long(&s->gb, s->num_mix_configs * 6); // scale codes 1733 1734 for (i = 0; i < s->num_mix_configs; i++) { 1735 if (get_bits_left(&s->gb) < 0) 1736 return -1; 1737 dca_exss_skip_mix_coeffs(&s->gb, channels, s->mix_config_num_ch[i]); 1738 if (embedded_6ch) 1739 dca_exss_skip_mix_coeffs(&s->gb, 6, s->mix_config_num_ch[i]); 1740 if (embedded_stereo) 1741 dca_exss_skip_mix_coeffs(&s->gb, 2, s->mix_config_num_ch[i]); 1742 } 1743 } 1744 1745 switch (get_bits(&s->gb, 2)) { 1746 case 0: 1747 extensions_mask = get_bits(&s->gb, 12); 1748 break; 1749 case 1: 1750 extensions_mask = DCA_EXT_EXSS_XLL; 1751 break; 1752 case 2: 1753 extensions_mask = DCA_EXT_EXSS_LBR; 1754 break; 1755 case 3: 1756 extensions_mask = 0; /* aux coding */ 1757 break; 1758 } 1759 1760 /* not parsed further, we were only interested in the extensions mask */ 1761 1762 if (get_bits_left(&s->gb) < 0) 1763 return -1; 1764 1765 if (get_bits_count(&s->gb) - header_pos > header_size * 8) { 1766 av_log(s->avctx, AV_LOG_WARNING, "Asset header size mismatch.\n"); 1767 return -1; 1768 } 1769 skip_bits_long(&s->gb, header_pos + header_size * 8 - get_bits_count(&s->gb)); 1770 1771 if (extensions_mask & DCA_EXT_EXSS_XLL) 1772 s->profile = FF_PROFILE_DTS_HD_MA; 1773 else if (extensions_mask & (DCA_EXT_EXSS_XBR | DCA_EXT_EXSS_X96 | 1774 DCA_EXT_EXSS_XXCH)) 1775 s->profile = FF_PROFILE_DTS_HD_HRA; 1776 1777 if (!(extensions_mask & DCA_EXT_CORE)) 1778 av_log(s->avctx, AV_LOG_WARNING, "DTS core detection mismatch.\n"); 1779 if ((extensions_mask & DCA_CORE_EXTS) != s->core_ext_mask) 1780 av_log(s->avctx, AV_LOG_WARNING, 1781 "DTS extensions detection mismatch (%d, %d)\n", 1782 extensions_mask & DCA_CORE_EXTS, s->core_ext_mask); 1783 1784 return 0; 1785 } 1786 1787 static int dca_xbr_parse_frame(DCAContext *s) 1418 int ff_dca_xbr_parse_frame(DCAContext *s) 1788 1419 { 1789 1420 int scale_table_high[DCA_CHSET_CHANS_MAX][DCA_SUBBANDS][2]; … … 1945 1576 } 1946 1577 1578 1947 1579 /* parse initial header for XXCH and dump details */ 1948 static intdca_xxch_decode_frame(DCAContext *s)1580 int ff_dca_xxch_decode_frame(DCAContext *s) 1949 1581 { 1950 1582 int hdr_size, spkmsk_bits, num_chsets, core_spk, hdr_pos; … … 1997 1629 1998 1630 return 0; 1999 }2000 2001 /**2002 * Parse extension substream header (HD)2003 */2004 static void dca_exss_parse_header(DCAContext *s)2005 {2006 int asset_size[8];2007 int ss_index;2008 int blownup;2009 int num_audiop = 1;2010 int num_assets = 1;2011 int active_ss_mask[8];2012 int i, j;2013 int start_posn;2014 int hdrsize;2015 uint32_t mkr;2016 2017 if (get_bits_left(&s->gb) < 52)2018 return;2019 2020 start_posn = get_bits_count(&s->gb) - 32;2021 2022 skip_bits(&s->gb, 8); // user data2023 ss_index = get_bits(&s->gb, 2);2024 2025 blownup = get_bits1(&s->gb);2026 hdrsize = get_bits(&s->gb, 8 + 4 * blownup) + 1; // header_size2027 skip_bits(&s->gb, 16 + 4 * blownup); // hd_size2028 2029 s->static_fields = get_bits1(&s->gb);2030 if (s->static_fields) {2031 skip_bits(&s->gb, 2); // reference clock code2032 skip_bits(&s->gb, 3); // frame duration code2033 2034 if (get_bits1(&s->gb))2035 skip_bits_long(&s->gb, 36); // timestamp2036 2037 /* a single stream can contain multiple audio assets that can be2038 * combined to form multiple audio presentations */2039 2040 num_audiop = get_bits(&s->gb, 3) + 1;2041 if (num_audiop > 1) {2042 avpriv_request_sample(s->avctx,2043 "Multiple DTS-HD audio presentations");2044 /* ignore such streams for now */2045 return;2046 }2047 2048 num_assets = get_bits(&s->gb, 3) + 1;2049 if (num_assets > 1) {2050 avpriv_request_sample(s->avctx, "Multiple DTS-HD audio assets");2051 /* ignore such streams for now */2052 return;2053 }2054 2055 for (i = 0; i < num_audiop; i++)2056 active_ss_mask[i] = get_bits(&s->gb, ss_index + 1);2057 2058 for (i = 0; i < num_audiop; i++)2059 for (j = 0; j <= ss_index; j++)2060 if (active_ss_mask[i] & (1 << j))2061 skip_bits(&s->gb, 8); // active asset mask2062 2063 s->mix_metadata = get_bits1(&s->gb);2064 if (s->mix_metadata) {2065 int mix_out_mask_size;2066 2067 skip_bits(&s->gb, 2); // adjustment level2068 mix_out_mask_size = (get_bits(&s->gb, 2) + 1) << 2;2069 s->num_mix_configs = get_bits(&s->gb, 2) + 1;2070 2071 for (i = 0; i < s->num_mix_configs; i++) {2072 int mix_out_mask = get_bits(&s->gb, mix_out_mask_size);2073 s->mix_config_num_ch[i] = dca_exss_mask2count(mix_out_mask);2074 }2075 }2076 }2077 2078 av_assert0(num_assets > 0); // silence a warning2079 2080 for (i = 0; i < num_assets; i++)2081 asset_size[i] = get_bits_long(&s->gb, 16 + 4 * blownup);2082 2083 for (i = 0; i < num_assets; i++) {2084 if (dca_exss_parse_asset_header(s))2085 return;2086 }2087 2088 /* not parsed further, we were only interested in the extensions mask2089 * from the asset header */2090 2091 j = get_bits_count(&s->gb);2092 if (start_posn + hdrsize * 8 > j)2093 skip_bits_long(&s->gb, start_posn + hdrsize * 8 - j);2094 2095 for (i = 0; i < num_assets; i++) {2096 start_posn = get_bits_count(&s->gb);2097 mkr = get_bits_long(&s->gb, 32);2098 2099 /* parse extensions that we know about */2100 if (mkr == 0x655e315e) {2101 dca_xbr_parse_frame(s);2102 } else if (mkr == 0x47004a03) {2103 dca_xxch_decode_frame(s);2104 s->core_ext_mask |= DCA_EXT_XXCH; /* xxx use for chan reordering */2105 } else {2106 av_log(s->avctx, AV_LOG_DEBUG,2107 "DTS-ExSS: unknown marker = 0x%08x\n", mkr);2108 }2109 2110 /* skip to end of block */2111 j = get_bits_count(&s->gb);2112 if (start_posn + asset_size[i] * 8 > j)2113 skip_bits_long(&s->gb, start_posn + asset_size[i] * 8 - j);2114 }2115 1631 } 2116 1632 … … 2292 1808 * but not in DTS-ES which contains XCh extensions instead */ 2293 1809 s->core_ext_mask |= DCA_EXT_XXCH; 2294 dca_xxch_decode_frame(s);1810 ff_dca_xxch_decode_frame(s); 2295 1811 break; 2296 1812 … … 2326 1842 if (s->dca_buffer_size - s->frame_size > 32 && 2327 1843 get_bits_long(&s->gb, 32) == DCA_HD_MARKER) 2328 dca_exss_parse_header(s);1844 ff_dca_exss_parse_header(s); 2329 1845 2330 1846 avctx->profile = s->profile; -
libavcodec/dcaenc.c
r6998400c rd8901c2f 44 44 #define AUBANDS 25 45 45 46 typedef struct DCA Context {46 typedef struct DCAEncContext { 47 47 PutBitContext pb; 48 48 int frame_size; … … 74 74 int32_t worst_noise_ever; 75 75 int consumed_bits; 76 } DCA Context;76 } DCAEncContext; 77 77 78 78 static int32_t cos_table[2048]; … … 106 106 static int encode_init(AVCodecContext *avctx) 107 107 { 108 DCA Context *c = avctx->priv_data;108 DCAEncContext *c = avctx->priv_data; 109 109 uint64_t layout = avctx->channel_layout; 110 110 int i, min_frame_bits; … … 236 236 } 237 237 238 static void subband_transform(DCA Context *c, const int32_t *input)238 static void subband_transform(DCAEncContext *c, const int32_t *input) 239 239 { 240 240 int ch, subs, i, k, j; … … 286 286 } 287 287 288 static void lfe_downsample(DCA Context *c, const int32_t *input)288 static void lfe_downsample(DCAEncContext *c, const int32_t *input) 289 289 { 290 290 /* FIXME: make 128x LFE downsampling possible */ … … 443 443 } 444 444 445 typedef void (*walk_band_t)(DCA Context *c, int band1, int band2, int f,445 typedef void (*walk_band_t)(DCAEncContext *c, int band1, int band2, int f, 446 446 int32_t spectrum1, int32_t spectrum2, int channel, 447 447 int32_t * arg); 448 448 449 static void walk_band_low(DCA Context *c, int band, int channel,449 static void walk_band_low(DCAEncContext *c, int band, int channel, 450 450 walk_band_t walk, int32_t *arg) 451 451 { … … 462 462 } 463 463 464 static void walk_band_high(DCA Context *c, int band, int channel,464 static void walk_band_high(DCAEncContext *c, int band, int channel, 465 465 walk_band_t walk, int32_t *arg) 466 466 { … … 477 477 } 478 478 479 static void update_band_masking(DCA Context *c, int band1, int band2,479 static void update_band_masking(DCAEncContext *c, int band1, int band2, 480 480 int f, int32_t spectrum1, int32_t spectrum2, 481 481 int channel, int32_t * arg) … … 487 487 } 488 488 489 static void calc_masking(DCA Context *c, const int32_t *input)489 static void calc_masking(DCAEncContext *c, const int32_t *input) 490 490 { 491 491 int i, k, band, ch, ssf; … … 520 520 } 521 521 522 static void find_peaks(DCA Context *c)522 static void find_peaks(DCAEncContext *c) 523 523 { 524 524 int band, ch; … … 553 553 #define USED_26ABITS 4 554 554 555 static int init_quantization_noise(DCA Context *c, int noise)555 static int init_quantization_noise(DCAEncContext *c, int noise) 556 556 { 557 557 int ch, band, ret = 0; … … 590 590 } 591 591 592 static void assign_bits(DCA Context *c)592 static void assign_bits(DCAEncContext *c) 593 593 { 594 594 /* Find the bounds where the binary search should work */ … … 628 628 } 629 629 630 static void shift_history(DCA Context *c, const int32_t *input)630 static void shift_history(DCAEncContext *c, const int32_t *input) 631 631 { 632 632 int k, ch; … … 678 678 } 679 679 680 static void calc_scales(DCA Context *c)680 static void calc_scales(DCAEncContext *c) 681 681 { 682 682 int band, ch; … … 692 692 } 693 693 694 static void quantize_all(DCA Context *c)694 static void quantize_all(DCAEncContext *c) 695 695 { 696 696 int sample, band, ch; … … 702 702 } 703 703 704 static void put_frame_header(DCA Context *c)704 static void put_frame_header(DCAEncContext *c) 705 705 { 706 706 /* SYNC */ … … 785 785 } 786 786 787 static void put_primary_audio_header(DCA Context *c)787 static void put_primary_audio_header(DCAEncContext *c) 788 788 { 789 789 static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 }; … … 831 831 } 832 832 833 static void put_subframe_samples(DCA Context *c, int ss, int band, int ch)833 static void put_subframe_samples(DCAEncContext *c, int ss, int band, int ch) 834 834 { 835 835 if (c->abits[band][ch] <= 7) { … … 854 854 } 855 855 856 static void put_subframe(DCA Context *c, int subframe)856 static void put_subframe(DCAEncContext *c, int subframe) 857 857 { 858 858 int i, band, ss, ch; … … 914 914 const AVFrame *frame, int *got_packet_ptr) 915 915 { 916 DCA Context *c = avctx->priv_data;916 DCAEncContext *c = avctx->priv_data; 917 917 const int32_t *samples; 918 918 int ret, i; … … 959 959 .type = AVMEDIA_TYPE_AUDIO, 960 960 .id = AV_CODEC_ID_DTS, 961 .priv_data_size = sizeof(DCA Context),961 .priv_data_size = sizeof(DCAEncContext), 962 962 .init = encode_init, 963 963 .encode2 = encode_frame,
Note:
See TracChangeset
for help on using the changeset viewer.