Changeset d8901c2f in ffmpeg


Ignore:
Timestamp:
Feb 14, 2015, 9:02:41 PM (10 years ago)
Author:
Michael Niedermayer <michaelni@gmx.at>
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)
Message:

Merge commit 'b339019de4e5f4d3c661bbdba98ae248ab77e2f0'

Conflicts:

libavcodec/Makefile
libavcodec/dcadec.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>

Location:
libavcodec
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • libavcodec/Makefile

    r6998400c rd8901c2f  
    190190OBJS-$(CONFIG_CYUV_DECODER)            += cyuv.o
    191191OBJS-$(CONFIG_DCA_DECODER)             += dcadec.o dca.o dcadsp.o      \
    192                                           synth_filter.o
     192                                          dca_exss.o synth_filter.o
    193193OBJS-$(CONFIG_DCA_ENCODER)             += dcaenc.o dca.o
    194194OBJS-$(CONFIG_DIRAC_DECODER)           += diracdec.o dirac.o diracdsp.o \
  • libavcodec/dca.h

    r6998400c rd8901c2f  
    2727
    2828#include <stdint.h>
     29
     30#include "libavutil/float_dsp.h"
    2931#include "libavutil/internal.h"
     32
     33#include "avcodec.h"
     34#include "dcadsp.h"
     35#include "fmtconvert.h"
     36#include "get_bits.h"
    3037
    3138/** DCA syncwords, also used for bitstream type detection */
     
    3845#define DCA_HD_MARKER     0x64582025
    3946
     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
     61enum 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
     74typedef 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
    40205extern av_export const uint32_t avpriv_dca_sample_rates[16];
    41206
     
    46211                             int max_size);
    47212
     213int ff_dca_xbr_parse_frame(DCAContext *s);
     214int ff_dca_xxch_decode_frame(DCAContext *s);
     215
    48216#endif /* AVCODEC_DCA_H */
  • libavcodec/dcadec.c

    r6998400c rd8901c2f  
    4141#include "dcadsp.h"
    4242#include "dcahuff.h"
     43#include "dca_exss.h"
    4344#include "fft.h"
    4445#include "fmtconvert.h"
     
    5354
    5455//#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)
    6456
    6557enum DCAMode {
     
    7769};
    7870
    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 };
    9871
    9972enum DCAXxchSpeakerMask {
     
    159132};
    160133
    161 enum DCAExtensionMask {
    162     DCA_EXT_CORE       = 0x001, ///< core in core substream
    163     DCA_EXT_XXCH       = 0x002, ///< XXCh channels extension in core substream
    164     DCA_EXT_X96        = 0x004, ///< 96/24 extension in core substream
    165     DCA_EXT_XCH        = 0x008, ///< XCh channel extension in core substream
    166     DCA_EXT_EXSS_CORE  = 0x010, ///< core in ExSS (extension substream)
    167     DCA_EXT_EXSS_XBR   = 0x020, ///< extended bitrate extension in ExSS
    168     DCA_EXT_EXSS_XXCH  = 0x040, ///< XXCh channels extension in ExSS
    169     DCA_EXT_EXSS_X96   = 0x080, ///< 96/24 extension in ExSS
    170     DCA_EXT_EXSS_LBR   = 0x100, ///< low bitrate component in ExSS
    171     DCA_EXT_EXSS_XLL   = 0x200, ///< lossless extension in ExSS
    172 };
    173 
    174134/* -1 are reserved or unknown */
    175135static const int dca_ext_audio_descr_mask[] = {
     
    183143    -1,
    184144};
    185 
    186 /* extensions that reside in core substream */
    187 #define DCA_CORE_EXTS (DCA_EXT_XCH | DCA_EXT_XXCH | DCA_EXT_X96)
    188145
    189146/* Tables for mapping dts channel configurations to libavcodec multichannel api.
     
    322279#define HEADER_SIZE                 14
    323280
    324 #define DCA_MAX_FRAME_SIZE       16384
    325 #define DCA_MAX_EXSS_HEADER_SIZE  4096
    326 
    327 #define DCA_BUFFER_PADDING_SIZE   1024
    328 
    329281#define DCA_NSYNCAUX        0x9A1105A0
    330282
     
    348300           ba->offset;
    349301}
    350 
    351 typedef struct DCAContext {
    352     const AVClass *class;       ///< class for AVOptions
    353     AVCodecContext *avctx;
    354     /* Frame header */
    355     int frame_type;             ///< type of the current frame
    356     int samples_deficit;        ///< deficit sample count
    357     int crc_present;            ///< crc is present in the bitstream
    358     int sample_blocks;          ///< number of PCM sample blocks
    359     int frame_size;             ///< primary frame byte size
    360     int amode;                  ///< audio channels arrangement
    361     int sample_rate;            ///< audio sampling rate
    362     int bit_rate;               ///< transmission bit rate
    363     int bit_rate_index;         ///< transmission bit rate index
    364 
    365     int dynrange;               ///< embedded dynamic range flag
    366     int timestamp;              ///< embedded time stamp flag
    367     int aux_data;               ///< auxiliary data flag
    368     int hdcd;                   ///< source material is mastered in HDCD
    369     int ext_descr;              ///< extension audio descriptor flag
    370     int ext_coding;             ///< extended coding flag
    371     int aspf;                   ///< audio sync word insertion flag
    372     int lfe;                    ///< low frequency effects flag
    373     int predictor_history;      ///< predictor history flag
    374     int header_crc;             ///< header crc check bytes
    375     int multirate_inter;        ///< multirate interpolator switch
    376     int version;                ///< encoder software revision
    377     int copy_history;           ///< copy history
    378     int source_pcm_res;         ///< source pcm resolution
    379     int front_sum;              ///< front sum/difference flag
    380     int surround_sum;           ///< surround sum/difference flag
    381     int dialog_norm;            ///< dialog normalisation parameter
    382 
    383     /* Primary audio coding header */
    384     int subframes;              ///< number of subframes
    385     int total_channels;         ///< number of channels including extensions
    386     int prim_channels;          ///< number of primary audio channels
    387     int subband_activity[DCA_PRIM_CHANNELS_MAX];    ///< subband activity count
    388     int vq_start_subband[DCA_PRIM_CHANNELS_MAX];    ///< high frequency vq start subband
    389     int joint_intensity[DCA_PRIM_CHANNELS_MAX];     ///< joint intensity coding index
    390     int transient_huffman[DCA_PRIM_CHANNELS_MAX];   ///< transient mode code book
    391     int scalefactor_huffman[DCA_PRIM_CHANNELS_MAX]; ///< scale factor code book
    392     int bitalloc_huffman[DCA_PRIM_CHANNELS_MAX];    ///< bit allocation quantizer select
    393     int quant_index_huffman[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]; ///< quantization index codebook select
    394     float scalefactor_adj[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX];   ///< scale factor adjustment
    395 
    396     /* Primary audio coding side information */
    397     int subsubframes[DCA_SUBFRAMES_MAX];                         ///< number of subsubframes
    398     int partial_samples[DCA_SUBFRAMES_MAX];                      ///< partial subsubframe samples count
    399     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 coefs
    401     int bitalloc[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS];           ///< bit allocation index
    402     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 codebook
    405     int joint_scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< joint subband scale factors
    406     float downmix_coef[DCA_PRIM_CHANNELS_MAX + 1][2];            ///< stereo downmix coefficients
    407     int dynrange_coef;                                           ///< dynamic range coefficient
    408 
    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 available
    413     uint8_t  core_downmix_amode;                                 ///< audio channel arrangement of embedded downmix
    414     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 subbands
    417 
    418     float lfe_data[2 * DCA_LFE_MAX * (DCA_BLOCKS_MAX + 4)];      ///< Low frequency effect data
    419     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 output
    429 
    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_buffer
    438 
    439     const int8_t *channel_order_tab;  ///< channel reordering table, lfe and non lfe
    440     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 substream
    446 
    447     /* XCh extension information */
    448     int xch_present;            ///< XCh extension present and valid
    449     int xch_base_channel;       ///< index of first (only) channel containing XCH data
    450     int xch_disable;            ///< whether the XCh extension should be decoded or not
    451 
    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 present
    468     int mix_metadata;           ///< mixing metadata present
    469     int num_mix_configs;        ///< number of mix out configurations
    470     int mix_config_num_ch[4];   ///< number of channels in each mix out configuration
    471 
    472     int profile;
    473 
    474     int debug_flag;             ///< used for suppressing repeated error messages output
    475     AVFloatDSPContext *fdsp;
    476     FFTContext imdct;
    477     SynthFilterContext synth;
    478     DCADSPContext dcadsp;
    479     FmtConvertContext fmt_conv;
    480 } DCAContext;
    481302
    482303static float dca_dmix_code(unsigned code);
     
    15951416}
    15961417
    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)
     1418int ff_dca_xbr_parse_frame(DCAContext *s)
    17881419{
    17891420    int scale_table_high[DCA_CHSET_CHANS_MAX][DCA_SUBBANDS][2];
     
    19451576}
    19461577
     1578
    19471579/* parse initial header for XXCH and dump details */
    1948 static int dca_xxch_decode_frame(DCAContext *s)
     1580int ff_dca_xxch_decode_frame(DCAContext *s)
    19491581{
    19501582    int hdr_size, spkmsk_bits, num_chsets, core_spk, hdr_pos;
     
    19971629
    19981630    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 data
    2023     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_size
    2027     skip_bits(&s->gb, 16 + 4 * blownup); // hd_size
    2028 
    2029     s->static_fields = get_bits1(&s->gb);
    2030     if (s->static_fields) {
    2031         skip_bits(&s->gb, 2); // reference clock code
    2032         skip_bits(&s->gb, 3); // frame duration code
    2033 
    2034         if (get_bits1(&s->gb))
    2035             skip_bits_long(&s->gb, 36); // timestamp
    2036 
    2037         /* a single stream can contain multiple audio assets that can be
    2038          * 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 mask
    2062 
    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 level
    2068             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 warning
    2079 
    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 mask
    2089      * 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         }
    21151631}
    21161632
     
    22921808                 * but not in DTS-ES which contains XCh extensions instead */
    22931809                s->core_ext_mask |= DCA_EXT_XXCH;
    2294                 dca_xxch_decode_frame(s);
     1810                ff_dca_xxch_decode_frame(s);
    22951811                break;
    22961812
     
    23261842    if (s->dca_buffer_size - s->frame_size > 32 &&
    23271843        get_bits_long(&s->gb, 32) == DCA_HD_MARKER)
    2328         dca_exss_parse_header(s);
     1844        ff_dca_exss_parse_header(s);
    23291845
    23301846    avctx->profile = s->profile;
  • libavcodec/dcaenc.c

    r6998400c rd8901c2f  
    4444#define AUBANDS 25
    4545
    46 typedef struct DCAContext {
     46typedef struct DCAEncContext {
    4747    PutBitContext pb;
    4848    int frame_size;
     
    7474    int32_t worst_noise_ever;
    7575    int consumed_bits;
    76 } DCAContext;
     76} DCAEncContext;
    7777
    7878static int32_t cos_table[2048];
     
    106106static int encode_init(AVCodecContext *avctx)
    107107{
    108     DCAContext *c = avctx->priv_data;
     108    DCAEncContext *c = avctx->priv_data;
    109109    uint64_t layout = avctx->channel_layout;
    110110    int i, min_frame_bits;
     
    236236}
    237237
    238 static void subband_transform(DCAContext *c, const int32_t *input)
     238static void subband_transform(DCAEncContext *c, const int32_t *input)
    239239{
    240240    int ch, subs, i, k, j;
     
    286286}
    287287
    288 static void lfe_downsample(DCAContext *c, const int32_t *input)
     288static void lfe_downsample(DCAEncContext *c, const int32_t *input)
    289289{
    290290    /* FIXME: make 128x LFE downsampling possible */
     
    443443}
    444444
    445 typedef void (*walk_band_t)(DCAContext *c, int band1, int band2, int f,
     445typedef void (*walk_band_t)(DCAEncContext *c, int band1, int band2, int f,
    446446                            int32_t spectrum1, int32_t spectrum2, int channel,
    447447                            int32_t * arg);
    448448
    449 static void walk_band_low(DCAContext *c, int band, int channel,
     449static void walk_band_low(DCAEncContext *c, int band, int channel,
    450450                          walk_band_t walk, int32_t *arg)
    451451{
     
    462462}
    463463
    464 static void walk_band_high(DCAContext *c, int band, int channel,
     464static void walk_band_high(DCAEncContext *c, int band, int channel,
    465465                           walk_band_t walk, int32_t *arg)
    466466{
     
    477477}
    478478
    479 static void update_band_masking(DCAContext *c, int band1, int band2,
     479static void update_band_masking(DCAEncContext *c, int band1, int band2,
    480480                                int f, int32_t spectrum1, int32_t spectrum2,
    481481                                int channel, int32_t * arg)
     
    487487}
    488488
    489 static void calc_masking(DCAContext *c, const int32_t *input)
     489static void calc_masking(DCAEncContext *c, const int32_t *input)
    490490{
    491491    int i, k, band, ch, ssf;
     
    520520}
    521521
    522 static void find_peaks(DCAContext *c)
     522static void find_peaks(DCAEncContext *c)
    523523{
    524524    int band, ch;
     
    553553#define USED_26ABITS 4
    554554
    555 static int init_quantization_noise(DCAContext *c, int noise)
     555static int init_quantization_noise(DCAEncContext *c, int noise)
    556556{
    557557    int ch, band, ret = 0;
     
    590590}
    591591
    592 static void assign_bits(DCAContext *c)
     592static void assign_bits(DCAEncContext *c)
    593593{
    594594    /* Find the bounds where the binary search should work */
     
    628628}
    629629
    630 static void shift_history(DCAContext *c, const int32_t *input)
     630static void shift_history(DCAEncContext *c, const int32_t *input)
    631631{
    632632    int k, ch;
     
    678678}
    679679
    680 static void calc_scales(DCAContext *c)
     680static void calc_scales(DCAEncContext *c)
    681681{
    682682    int band, ch;
     
    692692}
    693693
    694 static void quantize_all(DCAContext *c)
     694static void quantize_all(DCAEncContext *c)
    695695{
    696696    int sample, band, ch;
     
    702702}
    703703
    704 static void put_frame_header(DCAContext *c)
     704static void put_frame_header(DCAEncContext *c)
    705705{
    706706    /* SYNC */
     
    785785}
    786786
    787 static void put_primary_audio_header(DCAContext *c)
     787static void put_primary_audio_header(DCAEncContext *c)
    788788{
    789789    static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 };
     
    831831}
    832832
    833 static void put_subframe_samples(DCAContext *c, int ss, int band, int ch)
     833static void put_subframe_samples(DCAEncContext *c, int ss, int band, int ch)
    834834{
    835835    if (c->abits[band][ch] <= 7) {
     
    854854}
    855855
    856 static void put_subframe(DCAContext *c, int subframe)
     856static void put_subframe(DCAEncContext *c, int subframe)
    857857{
    858858    int i, band, ss, ch;
     
    914914                        const AVFrame *frame, int *got_packet_ptr)
    915915{
    916     DCAContext *c = avctx->priv_data;
     916    DCAEncContext *c = avctx->priv_data;
    917917    const int32_t *samples;
    918918    int ret, i;
     
    959959    .type                  = AVMEDIA_TYPE_AUDIO,
    960960    .id                    = AV_CODEC_ID_DTS,
    961     .priv_data_size        = sizeof(DCAContext),
     961    .priv_data_size        = sizeof(DCAEncContext),
    962962    .init                  = encode_init,
    963963    .encode2               = encode_frame,
Note: See TracChangeset for help on using the changeset viewer.