ac3enc.h
Go to the documentation of this file.
1 /*
2  * AC-3 encoder & E-AC-3 encoder common header
3  * Copyright (c) 2000 Fabrice Bellard
4  * Copyright (c) 2006-2010 Justin Ruggles <justin.ruggles@gmail.com>
5  *
6  * This file is part of Libav.
7  *
8  * Libav is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * Libav is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with Libav; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
28 #ifndef AVCODEC_AC3ENC_H
29 #define AVCODEC_AC3ENC_H
30 
31 #include <stdint.h>
32 #include "ac3.h"
33 #include "ac3dsp.h"
34 #include "avcodec.h"
35 #include "dsputil.h"
36 #include "put_bits.h"
37 #include "fft.h"
38 
39 #ifndef CONFIG_AC3ENC_FLOAT
40 #define CONFIG_AC3ENC_FLOAT 0
41 #endif
42 
43 #define OFFSET(param) offsetof(AC3EncodeContext, options.param)
44 #define AC3ENC_PARAM (AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
45 
46 #define AC3ENC_TYPE_AC3_FIXED 0
47 #define AC3ENC_TYPE_AC3 1
48 #define AC3ENC_TYPE_EAC3 2
49 
50 #if CONFIG_AC3ENC_FLOAT
51 #define AC3_NAME(x) ff_ac3_float_ ## x
52 #define MAC_COEF(d,a,b) ((d)+=(a)*(b))
53 #define COEF_MIN (-16777215.0/16777216.0)
54 #define COEF_MAX ( 16777215.0/16777216.0)
55 #define NEW_CPL_COORD_THRESHOLD 0.03
56 typedef float SampleType;
57 typedef float CoefType;
58 typedef float CoefSumType;
59 #else
60 #define AC3_NAME(x) ff_ac3_fixed_ ## x
61 #define MAC_COEF(d,a,b) MAC64(d,a,b)
62 #define COEF_MIN -16777215
63 #define COEF_MAX 16777215
64 #define NEW_CPL_COORD_THRESHOLD 503317
65 typedef int16_t SampleType;
66 typedef int32_t CoefType;
67 typedef int64_t CoefSumType;
68 #endif
69 
70 /* common option values */
71 #define AC3ENC_OPT_NONE -1
72 #define AC3ENC_OPT_AUTO -1
73 #define AC3ENC_OPT_OFF 0
74 #define AC3ENC_OPT_ON 1
75 #define AC3ENC_OPT_NOT_INDICATED 0
76 #define AC3ENC_OPT_MODE_ON 2
77 #define AC3ENC_OPT_MODE_OFF 1
78 
79 /* specific option values */
80 #define AC3ENC_OPT_LARGE_ROOM 1
81 #define AC3ENC_OPT_SMALL_ROOM 2
82 #define AC3ENC_OPT_DOWNMIX_LTRT 1
83 #define AC3ENC_OPT_DOWNMIX_LORO 2
84 #define AC3ENC_OPT_ADCONV_STANDARD 0
85 #define AC3ENC_OPT_ADCONV_HDCD 1
86 
87 
91 typedef struct AC3EncOptions {
92  /* AC-3 metadata options*/
102  int original;
115 
116  /* other encoding options */
121 } AC3EncOptions;
122 
126 typedef struct AC3Block {
128  int32_t **fixed_coef;
129  uint8_t **exp;
130  uint8_t **grouped_exp;
131  int16_t **psd;
132  int16_t **band_psd;
133  int16_t **mask;
134  uint16_t **qmant;
135  uint8_t **cpl_coord_exp;
136  uint8_t **cpl_coord_mant;
140  uint8_t rematrixing_flags[4];
150 } AC3Block;
151 
155 typedef struct AC3EncodeContext {
164 
166 
168  int eac3;
171 
172  int bit_rate;
174 
180  uint16_t crc_inv[2];
181  int64_t bits_written;
182  int64_t samples_written;
183 
185  int channels;
186  int lfe_on;
191  const uint8_t *channel_map;
192 
199 
200  int cutoff;
204 
205  int cpl_on;
210 
212 
213  /* bitrate allocation control */
226 
229  uint8_t *bap_buffer;
230  uint8_t *bap1_buffer;
233  uint8_t *exp_buffer;
235  int16_t *psd_buffer;
236  int16_t *band_psd_buffer;
237  int16_t *mask_buffer;
238  int16_t *qmant_buffer;
241 
248 
249  /* fixed vs. float function pointers */
251  int (*mdct_init)(struct AC3EncodeContext *s);
252 
253  /* fixed vs. float templated function pointers */
255 
256  /* AC-3 vs. E-AC-3 function pointers */
259 
260 
261 extern const uint64_t ff_ac3_channel_layouts[19];
262 
264 
266 
268 
270 
272 
274 
276 
278 
280 
282 
283 void ff_ac3_output_frame(AC3EncodeContext *s, unsigned char *frame);
284 
285 
286 /* prototypes for functions in ac3enc_fixed.c and ac3enc_float.c */
287 
290 
293 
294 
295 /* prototypes for functions in ac3enc_template.c */
296 
299 
300 int ff_ac3_fixed_encode_frame(AVCodecContext *avctx, unsigned char *frame,
301  int buf_size, void *data);
302 int ff_ac3_float_encode_frame(AVCodecContext *avctx, unsigned char *frame,
303  int buf_size, void *data);
304 
305 #endif /* AVCODEC_AC3ENC_H */