]> git.sesse.net Git - vlc/blob - include/ac3_decoder.h
. fix� une erreur de syntaxe dans video_fb.c
[vlc] / include / ac3_decoder.h
1 /*****************************************************************************
2  * ac3_decoder.h : ac3 decoder thread interface
3  * (c)1999 VideoLAN
4  *****************************************************************************/
5
6 /* Exponent strategy constants */
7 #define EXP_REUSE       (0)
8 #define EXP_D15         (1)
9 #define EXP_D25         (2)
10 #define EXP_D45         (3)
11
12 /* Delta bit allocation constants */
13 #define DELTA_BIT_REUSE         (0)
14 #define DELTA_BIT_NEW           (1)
15 #define DELTA_BIT_NONE          (2)
16 #define DELTA_BIT_RESERVED      (3)
17
18 /* The following structures are filled in by their corresponding parse_*
19  * functions. See http://www.atsc.org/Standards/A52/a_52.pdf for
20  * full details on each field. Indented fields are used to denote
21  * conditional fields.
22  */
23
24 typedef struct syncinfo_s
25 {
26         /* Sync word == 0x0B77 */
27         /* u16   syncword; */
28         /* crc for the first 5/8 of the sync block */
29         /* u16   crc1; */
30         /* Stream Sampling Rate (kHz) 0 = 48, 1 = 44.1, 2 = 32, 3 = reserved */
31         u16             fscod;
32         /* Frame size code */
33         u16             frmsizecod;
34
35         /* Information not in the AC-3 bitstream, but derived */
36         /* Frame size in 16 bit words */
37         u16 frame_size;
38         /* Bit rate in kilobits */
39         u16 bit_rate;
40
41 } syncinfo_t;
42
43 typedef struct bsi_s
44 {
45         /* Bit stream identification == 0x8 */
46         u16 bsid;
47         /* Bit stream mode */
48         u16 bsmod;
49         /* Audio coding mode */
50         u16 acmod;
51         /* If we're using the centre channel then */
52                 /* centre mix level */
53                 u16 cmixlev;
54         /* If we're using the surround channel then */
55                 /* surround mix level */
56                 u16 surmixlev;
57         /* If we're in 2/0 mode then */
58                 /* Dolby surround mix level - NOT USED - */
59                 u16 dsurmod;
60         /* Low frequency effects on */
61         u16 lfeon;
62         /* Dialogue Normalization level */
63         u16 dialnorm;
64         /* Compression exists */
65         u16 compre;
66                 /* Compression level */
67                 u16 compr;
68         /* Language code exists */
69         u16 langcode;
70                 /* Language code */
71                 u16 langcod;
72         /* Audio production info exists*/
73         u16 audprodie;
74                 u16 mixlevel;
75                 u16 roomtyp;
76         /* If we're in dual mono mode (acmod == 0) then extra stuff */
77                 u16 dialnorm2;
78                 u16 compr2e;
79                         u16 compr2;
80                 u16 langcod2e;
81                         u16 langcod2;
82                 u16 audprodi2e;
83                         u16 mixlevel2;
84                         u16 roomtyp2;
85         /* Copyright bit */
86         u16 copyrightb;
87         /* Original bit */
88         u16 origbs;
89         /* Timecode 1 exists */
90         u16 timecod1e;
91                 /* Timecode 1 */
92                 u16 timecod1;
93         /* Timecode 2 exists */
94         u16 timecod2e;
95                 /* Timecode 2 */
96                 u16 timecod2;
97         /* Additional bit stream info exists */
98         u16 addbsie;
99                 /* Additional bit stream length - 1 (in bytes) */
100                 u16 addbsil;
101                 /* Additional bit stream information (max 64 bytes) */
102                 u8      addbsi[64];
103
104         /* Information not in the AC-3 bitstream, but derived */
105         /* Number of channels (excluding LFE)
106          * Derived from acmod */
107         u16 nfchans;
108
109 } bsi_t;
110
111 /* more pain */
112 typedef struct audblk_s
113 {
114         /* block switch bit indexed by channel num */
115         u16 blksw[5];
116         /* dither enable bit indexed by channel num */
117         u16 dithflag[5];
118         /* dynamic range gain exists */
119         u16 dynrnge;
120                 /* dynamic range gain */
121                 u16 dynrng;
122         /* if acmod==0 then */
123         /* dynamic range 2 gain exists */
124         u16 dynrng2e;
125                 /* dynamic range 2 gain */
126                 u16 dynrng2;
127         /* coupling strategy exists */
128         u16 cplstre;
129                 /* coupling in use */
130                 u16 cplinu;
131                         /* channel coupled */
132                         u16 chincpl[5];
133                         /* if acmod==2 then */
134                                 /* Phase flags in use */
135                                 u16 phsflginu;
136                         /* coupling begin frequency code */
137                         u16 cplbegf;
138                         /* coupling end frequency code */
139                         u16 cplendf;
140                         /* coupling band structure bits */
141                         u16 cplbndstrc[18];
142                         /* Do coupling co-ords exist for this channel? */
143                         u16 cplcoe[5];
144                         /* Master coupling co-ordinate */
145                         u16 mstrcplco[5];
146                         /* Per coupling band coupling co-ordinates */
147                         u16 cplcoexp[5][18];
148                         u16     cplcomant[5][18];
149                         /* Phase flags for dual mono */
150                         u16 phsflg[18];
151         /* Is there a rematrixing strategy */
152         u16 rematstr;
153                 /* Rematrixing bits */
154                 u16 rematflg[4];
155         /* Coupling exponent strategy */
156         u16 cplexpstr;
157         /* Exponent strategy for full bandwidth channels */
158         u16 chexpstr[5];
159         /* Exponent strategy for lfe channel */
160         u16 lfeexpstr;
161         /* Channel bandwidth for independent channels */
162         u16 chbwcod[5];
163                 /* The absolute coupling exponent */
164                 u16 cplabsexp;
165                 /* Coupling channel exponents (D15 mode gives 18 * 12 /3  encoded exponents */
166                 u16 cplexps[18 * 12 / 3];
167         /* Sanity checking constant */
168         u32     magic2;
169         /* fbw channel exponents */
170         u16 exps[5][252 / 3];
171         /* channel gain range */
172         u16 gainrng[5];
173         /* low frequency exponents */
174         u16 lfeexps[3];
175
176         /* Bit allocation info */
177         u16 baie;
178                 /* Slow decay code */
179                 u16 sdcycod;
180                 /* Fast decay code */
181                 u16 fdcycod;
182                 /* Slow gain code */
183                 u16 sgaincod;
184                 /* dB per bit code */
185                 u16 dbpbcod;
186                 /* masking floor code */
187                 u16 floorcod;
188
189         /* SNR offset info */
190         u16 snroffste;
191                 /* coarse SNR offset */
192                 u16 csnroffst;
193                 /* coupling fine SNR offset */
194                 u16 cplfsnroffst;
195                 /* coupling fast gain code */
196                 u16 cplfgaincod;
197                 /* fbw fine SNR offset */
198                 u16 fsnroffst[5];
199                 /* fbw fast gain code */
200                 u16 fgaincod[5];
201                 /* lfe fine SNR offset */
202                 u16 lfefsnroffst;
203                 /* lfe fast gain code */
204                 u16 lfefgaincod;
205         
206         /* Coupling leak info */
207         u16 cplleake;
208                 /* coupling fast leak initialization */
209                 u16 cplfleak;
210                 /* coupling slow leak initialization */
211                 u16 cplsleak;
212         
213         /* delta bit allocation info */
214         u16 deltbaie;
215                 /* coupling delta bit allocation exists */
216                 u16 cpldeltbae;
217                 /* fbw delta bit allocation exists */
218                 u16 deltbae[5];
219                 /* number of cpl delta bit segments */
220                 u16 cpldeltnseg;
221                         /* coupling delta bit allocation offset */
222                         u16 cpldeltoffst[8];
223                         /* coupling delta bit allocation length */
224                         u16 cpldeltlen[8];
225                         /* coupling delta bit allocation length */
226                         u16 cpldeltba[8];
227                 /* number of delta bit segments */
228                 u16 deltnseg[5];
229                         /* fbw delta bit allocation offset */
230                         u16 deltoffst[5][8];
231                         /* fbw delta bit allocation length */
232                         u16 deltlen[5][8];
233                         /* fbw delta bit allocation length */
234                         u16 deltba[5][8];
235
236         /* skip length exists */
237         u16 skiple;
238                 /* skip length */
239                 u16 skipl;
240
241         /* channel mantissas */
242 //      u16     chmant[5][256];
243
244         /* coupling mantissas */
245         float cplfbw[ 256 ];
246 //      u16     cplmant[256];
247
248         /* coupling mantissas */
249 //      u16     lfemant[7];
250
251         /*  -- Information not in the bitstream, but derived thereof  -- */
252
253         /* Number of coupling sub-bands */
254         u16 ncplsubnd;
255
256         /* Number of combined coupling sub-bands
257          * Derived from ncplsubnd and cplbndstrc */
258         u16 ncplbnd;
259
260         /* Number of exponent groups by channel
261          * Derived from strmant, endmant */
262         u16 nchgrps[5];
263
264         /* Number of coupling exponent groups
265          * Derived from cplbegf, cplendf, cplexpstr */
266         u16 ncplgrps;
267                         
268         /* End mantissa numbers of fbw channels */
269         u16 endmant[5];
270
271         /* Start and end mantissa numbers for the coupling channel */
272         u16 cplstrtmant;
273         u16 cplendmant;
274
275         /* Decoded exponent info */
276         u16 fbw_exp[5][256];
277         u16 cpl_exp[256];
278         u16 lfe_exp[7];
279
280         /* Bit allocation pointer results */
281         u16 fbw_bap[5][256];
282         //FIXME figure out exactly how many entries there should be (253-37?)
283         u16 cpl_bap[256];
284         u16 lfe_bap[7];
285
286 } audblk_t;
287
288 /* Everything you wanted to know about band structure */
289 /*
290  * The entire frequency domain is represented by 256 real
291  * floating point fourier coefficients. Only the lower 253
292  * coefficients are actually utilized however. We use arrays
293  * of 256 to be efficient in some cases.
294  *
295  * The 5 full bandwidth channels (fbw) can have their higher
296  * frequencies coupled together. These coupled channels then
297  * share their high frequency components.
298  *
299  * This coupling band is broken up into 18 sub-bands starting
300  * at mantissa number 37. Each sub-band is 12 bins wide.
301  *
302  * There are 50 bit allocation sub-bands which cover the entire
303  * frequency range. The sub-bands are of non-uniform width, and
304  * approximate a 1/6 octave scale.
305  */
306
307 typedef struct stream_coeffs_s
308 {
309         float fbw[5][256];
310         float lfe[256];
311
312 } stream_coeffs_t;
313
314 typedef struct stream_samples_s
315 {
316         float channel[6][256];
317
318 } stream_samples_t;
319
320 #define AC3DEC_FRAME_SIZE (2*256)
321
322 /*****************************************************************************
323  * ac3dec_frame_t
324  *****************************************************************************/
325 typedef s16 ac3dec_frame_t[ AC3DEC_FRAME_SIZE ];
326
327 /*****************************************************************************
328  * ac3dec_thread_t : ac3 decoder thread descriptor
329  *****************************************************************************/
330 typedef struct ac3dec_thread_s
331 {
332     /*
333      * Thread properties
334      */
335     vlc_thread_t        thread_id;                /* id for thread functions */
336     boolean_t           b_die;                                 /* `die' flag */
337     boolean_t           b_error;                             /* `error' flag */
338     boolean_t           b_invalid;                         /* `invalid' flag */
339
340     /*
341      * Input properties
342      */
343     decoder_fifo_t      fifo;                  /* stores the PES stream data */
344     /* The bit stream structure handles the PES stream at the bit level */
345     bit_stream_t        bit_stream;
346
347     /*
348      * Decoder properties
349      */
350     unsigned int        total_bits_read;
351
352     syncinfo_t          syncinfo;
353     bsi_t               bsi;
354     audblk_t            audblk;
355
356     stream_coeffs_t     coeffs;
357     stream_samples_t    samples;
358
359     /*
360      * Output properties
361      */
362     aout_fifo_t *       p_aout_fifo; /* stores the decompressed audio frames */
363     aout_thread_t *     p_aout;           /* needed to create the audio fifo */
364
365 } ac3dec_thread_t;
366
367 /*****************************************************************************
368  * Prototypes
369  *****************************************************************************/
370 ac3dec_thread_t *       ac3dec_CreateThread( input_thread_t * p_input );
371 void                    ac3dec_DestroyThread( ac3dec_thread_t * p_ac3dec );