• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavcodec/ac3enc.h

Go to the documentation of this file.
00001 /*
00002  * AC-3 encoder & E-AC-3 encoder common header
00003  * Copyright (c) 2000 Fabrice Bellard
00004  * Copyright (c) 2006-2010 Justin Ruggles <justin.ruggles@gmail.com>
00005  *
00006  * This file is part of Libav.
00007  *
00008  * Libav is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * Libav is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with Libav; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00028 #ifndef AVCODEC_AC3ENC_H
00029 #define AVCODEC_AC3ENC_H
00030 
00031 #include <stdint.h>
00032 #include "ac3.h"
00033 #include "ac3dsp.h"
00034 #include "avcodec.h"
00035 #include "dsputil.h"
00036 #include "put_bits.h"
00037 #include "fft.h"
00038 
00039 #ifndef CONFIG_AC3ENC_FLOAT
00040 #define CONFIG_AC3ENC_FLOAT 0
00041 #endif
00042 
00043 #define OFFSET(param) offsetof(AC3EncodeContext, options.param)
00044 #define AC3ENC_PARAM (AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
00045 
00046 #define AC3ENC_TYPE_AC3_FIXED   0
00047 #define AC3ENC_TYPE_AC3         1
00048 #define AC3ENC_TYPE_EAC3        2
00049 
00050 #if CONFIG_AC3ENC_FLOAT
00051 #define AC3_NAME(x) ff_ac3_float_ ## x
00052 #define MAC_COEF(d,a,b) ((d)+=(a)*(b))
00053 typedef float SampleType;
00054 typedef float CoefType;
00055 typedef float CoefSumType;
00056 #else
00057 #define AC3_NAME(x) ff_ac3_fixed_ ## x
00058 #define MAC_COEF(d,a,b) MAC64(d,a,b)
00059 typedef int16_t SampleType;
00060 typedef int32_t CoefType;
00061 typedef int64_t CoefSumType;
00062 #endif
00063 
00064 
00065 typedef struct AC3MDCTContext {
00066     const SampleType *window;           
00067     FFTContext fft;                     
00068 } AC3MDCTContext;
00069 #if 0
00070 
00073 typedef struct AC3EncOptions {
00074     /* AC-3 metadata options*/
00075     int dialogue_level;
00076     int bitstream_mode;
00077     float center_mix_level;
00078     float surround_mix_level;
00079     int dolby_surround_mode;
00080     int audio_production_info;
00081     int mixing_level;
00082     int room_type;
00083     int copyright;
00084     int original;
00085     int extended_bsi_1;
00086     int preferred_stereo_downmix;
00087     float ltrt_center_mix_level;
00088     float ltrt_surround_mix_level;
00089     float loro_center_mix_level;
00090     float loro_surround_mix_level;
00091     int extended_bsi_2;
00092     int dolby_surround_ex_mode;
00093     int dolby_headphone_mode;
00094     int ad_converter_type;
00095 
00096     /* other encoding options */
00097     int allow_per_frame_metadata;
00098     int stereo_rematrixing;
00099     int channel_coupling;
00100     int cpl_start;
00101 } AC3EncOptions;
00102 #endif
00103 
00106 typedef struct AC3Block {
00107     CoefType **mdct_coef;                       
00108     int32_t  **fixed_coef;                      
00109     uint8_t  **exp;                             
00110     uint8_t  **grouped_exp;                     
00111     int16_t  **psd;                             
00112     int16_t  **band_psd;                        
00113     int16_t  **mask;                            
00114     uint16_t **qmant;                           
00115     uint8_t  **cpl_coord_exp;                   
00116     uint8_t  **cpl_coord_mant;                  
00117     uint8_t  coeff_shift[AC3_MAX_CHANNELS];     
00118     uint8_t  new_rematrixing_strategy;          
00119     int      num_rematrixing_bands;             
00120     uint8_t  rematrixing_flags[4];              
00121     int      new_cpl_strategy;                  
00122     int      cpl_in_use;                        
00123     uint8_t  channel_in_cpl[AC3_MAX_CHANNELS];  
00124     int      num_cpl_channels;                  
00125     uint8_t  new_cpl_coords;                    
00126     uint8_t  cpl_master_exp[AC3_MAX_CHANNELS];  
00127     int      new_snr_offsets;                   
00128     int      new_cpl_leak;                      
00129     int      end_freq[AC3_MAX_CHANNELS];        
00130 } AC3Block;
00131 
00135 typedef struct AC3EncodeContext {
00136     AVClass *av_class;                      
00137     AC3EncOptions options;                  
00138     AVCodecContext *avctx;                  
00139     PutBitContext pb;                       
00140     DSPContext dsp;
00141     AC3DSPContext ac3dsp;                   
00142     AC3MDCTContext *mdct;                   
00143 
00144     AC3Block blocks[AC3_MAX_BLOCKS];        
00145 
00146     int fixed_point;                        
00147     int eac3;                               
00148     int bitstream_id;                       
00149     int bitstream_mode;                     
00150 
00151     int bit_rate;                           
00152     int sample_rate;                        
00153 
00154     int frame_size_min;                     
00155     int frame_size;                         
00156     int frame_size_code;                    
00157     uint16_t crc_inv[2];
00158     int64_t bits_written;                   
00159     int64_t samples_written;                
00160 
00161     int fbw_channels;                       
00162     int channels;                           
00163     int lfe_on;                             
00164     int lfe_channel;                        
00165     int has_center;                         
00166     int has_surround;                       
00167     int channel_mode;                       
00168     const uint8_t *channel_map;             
00169 
00170     int center_mix_level;                   
00171     int surround_mix_level;                 
00172     int ltrt_center_mix_level;              
00173     int ltrt_surround_mix_level;            
00174     int loro_center_mix_level;              
00175     int loro_surround_mix_level;            
00176 
00177     int cutoff;                             
00178     int bandwidth_code;                     
00179     int start_freq[AC3_MAX_CHANNELS];       
00180     int cpl_end_freq;                       
00181 
00182     int cpl_on;                             
00183     int cpl_enabled;                        
00184     int num_cpl_subbands;                   
00185     int num_cpl_bands;                      
00186     uint8_t cpl_band_sizes[AC3_MAX_CPL_BANDS];  
00187 
00188     int rematrixing_enabled;                
00189 
00190     /* bitrate allocation control */
00191     int slow_gain_code;                     
00192     int slow_decay_code;                    
00193     int fast_decay_code;                    
00194     int db_per_bit_code;                    
00195     int floor_code;                         
00196     AC3BitAllocParameters bit_alloc;        
00197     int coarse_snr_offset;                  
00198     int fast_gain_code[AC3_MAX_CHANNELS];   
00199     int fine_snr_offset[AC3_MAX_CHANNELS];  
00200     int frame_bits_fixed;                   
00201     int frame_bits;                         
00202     int exponent_bits;                      
00203 
00204     SampleType *windowed_samples;
00205     SampleType **planar_samples;
00206     uint8_t *bap_buffer;
00207     uint8_t *bap1_buffer;
00208     CoefType *mdct_coef_buffer;
00209     int32_t *fixed_coef_buffer;
00210     uint8_t *exp_buffer;
00211     uint8_t *grouped_exp_buffer;
00212     int16_t *psd_buffer;
00213     int16_t *band_psd_buffer;
00214     int16_t *mask_buffer;
00215     uint16_t *qmant_buffer;
00216     uint8_t *cpl_coord_exp_buffer;
00217     uint8_t *cpl_coord_mant_buffer;
00218 
00219     uint8_t exp_strategy[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; 
00220     uint8_t exp_ref_block[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; 
00221     uint8_t *ref_bap     [AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; 
00222     int ref_bap_set;                                         
00223 
00224     /* fixed vs. float function pointers */
00225     void (*mdct_end)(AC3MDCTContext *mdct);
00226     int  (*mdct_init)(AVCodecContext *avctx, AC3MDCTContext *mdct, int nbits);
00227     void (*apply_window)(DSPContext *dsp, SampleType *output,
00228                          const SampleType *input, const SampleType *window,
00229                          unsigned int len);
00230     int  (*normalize_samples)(struct AC3EncodeContext *s);
00231     void (*scale_coefficients)(struct AC3EncodeContext *s);
00232 
00233     /* fixed vs. float templated function pointers */
00234     int  (*allocate_sample_buffers)(struct AC3EncodeContext *s);
00235     void (*deinterleave_input_samples)(struct AC3EncodeContext *s,
00236                                        const SampleType *samples);
00237     void (*apply_mdct)(struct AC3EncodeContext *s);
00238     void (*apply_channel_coupling)(struct AC3EncodeContext *s);
00239     void (*compute_rematrixing_strategy)(struct AC3EncodeContext *s);
00240 
00241     /* AC-3 vs. E-AC-3 function pointers */
00242     void (*output_frame_header)(struct AC3EncodeContext *s);
00243 } AC3EncodeContext;
00244 
00245 
00246 int ff_ac3_encode_init(AVCodecContext *avctx);
00247 
00248 int ff_ac3_encode_frame(AVCodecContext *avctx, unsigned char *frame,
00249                         int buf_size, void *data);
00250 
00251 int ff_ac3_encode_close(AVCodecContext *avctx);
00252 
00253 
00254 /* prototypes for functions in ac3enc_fixed.c and ac3enc_float.c */
00255 
00256 void ff_ac3_fixed_mdct_end(AC3MDCTContext *mdct);
00257 void ff_ac3_float_mdct_end(AC3MDCTContext *mdct);
00258 
00259 int ff_ac3_fixed_mdct_init(AVCodecContext *avctx, AC3MDCTContext *mdct,
00260                            int nbits);
00261 int ff_ac3_float_mdct_init(AVCodecContext *avctx, AC3MDCTContext *mdct,
00262                            int nbits);
00263 
00264 void ff_ac3_fixed_apply_window(DSPContext *dsp, SampleType *output,
00265                                const SampleType *input,
00266                                const SampleType *window, unsigned int len);
00267 void ff_ac3_float_apply_window(DSPContext *dsp, SampleType *output,
00268                                const SampleType *input,
00269                                const SampleType *window, unsigned int len);
00270 
00271 int ff_ac3_fixed_normalize_samples(AC3EncodeContext *s);
00272 
00273 void ff_ac3_fixed_scale_coefficients(AC3EncodeContext *s);
00274 void ff_ac3_float_scale_coefficients(AC3EncodeContext *s);
00275 
00276 
00277 /* prototypes for functions in ac3enc_template.c */
00278 
00279 int ff_ac3_fixed_allocate_sample_buffers(AC3EncodeContext *s);
00280 int ff_ac3_float_allocate_sample_buffers(AC3EncodeContext *s);
00281 
00282 void ff_ac3_fixed_deinterleave_input_samples(AC3EncodeContext *s,
00283                                              const SampleType *samples);
00284 void ff_ac3_float_deinterleave_input_samples(AC3EncodeContext *s,
00285                                              const SampleType *samples);
00286 
00287 void ff_ac3_fixed_apply_mdct(AC3EncodeContext *s);
00288 void ff_ac3_float_apply_mdct(AC3EncodeContext *s);
00289 
00290 void ff_ac3_fixed_apply_channel_coupling(AC3EncodeContext *s);
00291 void ff_ac3_float_apply_channel_coupling(AC3EncodeContext *s);
00292 
00293 void ff_ac3_fixed_compute_rematrixing_strategy(AC3EncodeContext *s);
00294 void ff_ac3_float_compute_rematrixing_strategy(AC3EncodeContext *s);
00295 
00296 #endif /* AVCODEC_AC3ENC_H */

Generated on Fri Feb 22 2013 07:24:25 for FFmpeg by  doxygen 1.7.1