]> git.sesse.net Git - vlc/blob - src/audio_decoder/audio_decoder.c
Encore un commit venu tout droit des abysses de l'enfer, d�sol� pour
[vlc] / src / audio_decoder / audio_decoder.c
1 /*****************************************************************************
2  * audio_decoder.c: MPEG1 Layer I-II audio decoder thread
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  *
6  * Authors:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program 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  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public
19  * License along with this program; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *****************************************************************************/
23
24 /*
25  * TODO :
26  *
27  * - optimiser les NeedBits() et les GetBits() du code là où c'est possible ;
28  * - vlc_cond_signal() / vlc_cond_wait() ;
29  *
30  */
31
32 /*****************************************************************************
33  * Preamble
34  *****************************************************************************/
35 #include <unistd.h>                                              /* getpid() */
36
37 #include <stdio.h>                                           /* "intf_msg.h" */
38 #include <stdlib.h>                                      /* malloc(), free() */
39 #include <sys/types.h>                        /* on BSD, uio.h needs types.h */
40 #include <sys/uio.h>                                            /* "input.h" */
41
42 #include "common.h"
43 #include "config.h"
44 #include "mtime.h"
45 #include "threads.h"
46 #include "debug.h"                                      /* "input_netlist.h" */
47
48 #include "intf_msg.h"                        /* intf_DbgMsg(), intf_ErrMsg() */
49
50 #include "input.h"                                           /* pes_packet_t */
51 #include "input_netlist.h"                         /* input_NetlistFreePES() */
52 #include "decoder_fifo.h"         /* DECODER_FIFO_(ISEMPTY|START|INCSTART)() */
53
54 #include "audio_output.h"               /* aout_fifo_t (for audio_decoder.h) */
55
56 #include "audio_constants.h"
57 #include "audio_decoder.h"
58 #include "audio_math.h"                                    /* DCT32(), PCM() */
59
60 /*****************************************************************************
61  * Local prototypes
62  *****************************************************************************/
63 static int      InitThread              ( adec_thread_t * p_adec );
64 static void     RunThread               ( adec_thread_t * p_adec );
65 static void     ErrorThread             ( adec_thread_t * p_adec );
66 static void     EndThread               ( adec_thread_t * p_adec );
67
68 /*
69 static int      adec_Layer1_Mono        ( adec_thread_t * p_adec );
70 static int      adec_Layer1_Stereo      ( adec_thread_t * p_adec );
71 static int      adec_Layer2_Mono        ( adec_thread_t * p_adec );
72 static int      adec_Layer2_Stereo      ( adec_thread_t * p_adec );
73
74 static byte_t   GetByte                 ( bit_stream_t * p_bit_stream );
75 static void     NeedBits                ( bit_stream_t * p_bit_stream, int i_bits );
76 static void     DumpBits                ( bit_stream_t * p_bit_stream, int i_bits );
77 static int      FindHeader              ( adec_thread_t * p_adec );
78 */
79
80 /*****************************************************************************
81  * adec_CreateThread: creates an audio decoder thread
82  *****************************************************************************
83  * This function creates a new audio decoder thread, and returns a pointer to
84  * its description. On error, it returns NULL.
85  *****************************************************************************/
86 adec_thread_t * adec_CreateThread( input_thread_t * p_input )
87 {
88     adec_thread_t *     p_adec;
89
90     intf_DbgMsg("adec debug: creating audio decoder thread\n");
91
92     /* Allocate the memory needed to store the thread's structure */
93     if ( (p_adec = (adec_thread_t *)malloc( sizeof(adec_thread_t) )) == NULL )
94     {
95         intf_ErrMsg("adec error: not enough memory for adec_CreateThread() to create the new thread\n");
96         return( NULL );
97     }
98
99     /*
100      * Initialize the thread properties
101      */
102     p_adec->b_die = 0;
103     p_adec->b_error = 0;
104
105     /*
106      * Initialize the input properties
107      */
108     /* Initialize the decoder fifo's data lock and conditional variable and set
109      * its buffer as empty */
110     vlc_mutex_init( &p_adec->fifo.data_lock );
111     vlc_cond_init( &p_adec->fifo.data_wait );
112     p_adec->fifo.i_start = 0;
113     p_adec->fifo.i_end = 0;
114     /* Initialize the bit stream structure */
115     p_adec->bit_stream.p_input = p_input;
116     p_adec->bit_stream.p_decoder_fifo = &p_adec->fifo;
117     p_adec->bit_stream.fifo.buffer = 0;
118     p_adec->bit_stream.fifo.i_available = 0;
119
120     /*
121      * Initialize the decoder properties
122      */
123     p_adec->bank_0.actual = p_adec->bank_0.v1;
124     p_adec->bank_0.pos = 0;
125     p_adec->bank_1.actual = p_adec->bank_1.v1;
126     p_adec->bank_1.pos = 0;
127
128     /*
129      * Initialize the output properties
130      */
131     p_adec->p_aout = p_input->p_aout;
132     p_adec->p_aout_fifo = NULL;
133
134     /* Spawn the audio decoder thread */
135     if ( vlc_thread_create(&p_adec->thread_id, "audio decoder", (vlc_thread_func_t)RunThread, (void *)p_adec) )
136     {
137         intf_ErrMsg("adec error: can't spawn audio decoder thread\n");
138         free( p_adec );
139         return( NULL );
140     }
141
142     intf_DbgMsg("adec debug: audio decoder thread (%p) created\n", p_adec);
143     return( p_adec );
144 }
145
146 /*****************************************************************************
147  * adec_DestroyThread: destroys an audio decoder thread
148  *****************************************************************************
149  * This function asks an audio decoder thread to terminate. This function has
150  * not to wait until the decoder thread has really died, because the killer (ie
151  * this function's caller) is the input thread, that's why we are sure that no
152  * other thread will try to access to this thread's descriptor after its
153  * destruction.
154  *****************************************************************************/
155 void adec_DestroyThread( adec_thread_t * p_adec )
156 {
157     intf_DbgMsg("adec debug: requesting termination of audio decoder thread %p\n", p_adec);
158
159     /* Ask thread to kill itself */
160     p_adec->b_die = 1;
161
162     /* Make sure the decoder thread leaves the GetByte() function */
163     vlc_mutex_lock( &(p_adec->fifo.data_lock) );
164     vlc_cond_signal( &(p_adec->fifo.data_wait) );
165     vlc_mutex_unlock( &(p_adec->fifo.data_lock) );
166
167     /* Waiting for the decoder thread to exit */
168     /* Remove this as soon as the "status" flag is implemented */
169     vlc_thread_join( p_adec->thread_id );
170 }
171
172 /* Following functions are local */
173
174 /*****************************************************************************
175  * FindHeader : parses an input stream until an audio frame header could be
176  *              found
177  *****************************************************************************
178  * When this function returns successfully, the header can be found in the
179  * buffer of the bit stream fifo.
180  *****************************************************************************/
181 static int FindHeader( adec_thread_t * p_adec )
182 {
183     while ( (!p_adec->b_die) && (!p_adec->b_error) )
184     {
185         NeedBits( &p_adec->bit_stream, 32 );
186         if ( (p_adec->bit_stream.fifo.buffer & ADEC_HEADER_SYNCWORD_MASK) == ADEC_HEADER_SYNCWORD_MASK )
187         {
188             return( 0 );
189         }
190         DumpBits( &p_adec->bit_stream, 8 );
191     }
192
193     return( -1 );
194 }
195
196 /*****************************************************************************
197  * adec_Layer`L'_`M': decodes an mpeg 1, layer `L', mode `M', audio frame
198  *****************************************************************************
199  * These functions decode the audio frame which has already its header loaded
200  * in the i_header member of the audio decoder thread structure and its first
201  * byte of data described by the bit stream structure of the audio decoder
202  * thread (there is no bit available in the bit buffer yet)
203  *****************************************************************************/
204
205 /*****************************************************************************
206  * adec_Layer1_Mono
207  *****************************************************************************/
208 static __inline__ int adec_Layer1_Mono( adec_thread_t * p_adec )
209 {
210     p_adec->bit_stream.fifo.buffer = 0;
211     p_adec->bit_stream.fifo.i_available = 0;
212     return( 0 );
213 }
214
215 /*****************************************************************************
216  * adec_Layer1_Stereo
217  *****************************************************************************/
218 static __inline__ int adec_Layer1_Stereo( adec_thread_t * p_adec )
219 {
220     p_adec->bit_stream.fifo.buffer = 0;
221     p_adec->bit_stream.fifo.i_available = 0;
222     return( 0 );
223 }
224
225 /*****************************************************************************
226  * adec_Layer2_Mono
227  *****************************************************************************/
228 static __inline__ int adec_Layer2_Mono( adec_thread_t * p_adec )
229 {
230     p_adec->bit_stream.fifo.buffer = 0;
231     p_adec->bit_stream.fifo.i_available = 0;
232     return( 0 );
233 }
234
235 /*****************************************************************************
236  * adec_Layer2_Stereo
237  *****************************************************************************/
238 static __inline__ int adec_Layer2_Stereo( adec_thread_t * p_adec )
239 {
240     typedef struct requantization_s
241     {
242         byte_t                          i_bits_per_codeword;
243         const float *                   pf_ungroup;
244         float                           f_slope;
245         float                           f_offset;
246     } requantization_t;
247
248     static const float                  pf_scalefactor[64] = ADEC_SCALE_FACTOR;
249
250     static u32                          i_header;
251     static int                          i_sampling_frequency, i_mode, i_bound;
252     static int                          pi_allocation_0[32], pi_allocation_1[32]; /* see ISO/IEC 11172-3 2.4.1.6 */
253     int                                 i_sb, i_nbal;
254     float                               f_scalefactor_0, f_scalefactor_1;
255
256     static const byte_t                 ppi_bitrate_per_channel_index[4][15] = ADEC_LAYER2_BITRATE_PER_CHANNEL_INDEX;
257     static const byte_t                 ppi_sblimit[3][11] = ADEC_LAYER2_SBLIMIT;
258     static const byte_t                 ppi_nbal[2][32] = ADEC_LAYER2_NBAL;
259
260     static const float                  pf_ungroup3[3*3*3 * 3] = ADEC_LAYER2_UNGROUP3;
261     static const float                  pf_ungroup5[5*5*5 * 3] = ADEC_LAYER2_UNGROUP5;
262     static const float                  pf_ungroup9[9*9*9 * 3] = ADEC_LAYER2_UNGROUP9;
263
264     static const requantization_t       p_requantization_cd[16] = ADEC_LAYER2_REQUANTIZATION_CD;
265     static const requantization_t       p_requantization_ab1[16] = ADEC_LAYER2_REQUANTIZATION_AB1;
266     static const requantization_t       p_requantization_ab2[16] = ADEC_LAYER2_REQUANTIZATION_AB2;
267     static const requantization_t       p_requantization_ab3[16] = ADEC_LAYER2_REQUANTIZATION_AB3;
268     static const requantization_t       p_requantization_ab4[16] = ADEC_LAYER2_REQUANTIZATION_AB4;
269     static const requantization_t *     pp_requantization_ab[30] = ADEC_LAYER2_REQUANTIZATION_AB;
270
271     static int                          i_sblimit, i_bitrate_per_channel_index;
272     static int                          pi_scfsi_0[30], pi_scfsi_1[30];
273     static const byte_t *               pi_nbal;
274     static float                        ppf_sample_0[3][32], ppf_sample_1[3][32];
275     static const requantization_t *     pp_requantization_0[30];
276     static const requantization_t *     pp_requantization_1[30];
277     static requantization_t             requantization;
278     static const float *                pf_ungroup;
279
280     static float                        pf_scalefactor_0_0[30], pf_scalefactor_0_1[30], pf_scalefactor_0_2[30];
281     static float                        pf_scalefactor_1_0[30], pf_scalefactor_1_1[30], pf_scalefactor_1_2[30];
282
283     int                                 i_2nbal, i_gr;
284     float                               f_dummy;
285
286     long                                l_end_frame;
287     s16 *                               p_s16;
288
289     int                                 i_need = 0, i_dump = 0;
290 #if 0
291     static const int                    pi_framesize[512] = ADEC_FRAME_SIZE;
292 #endif
293
294     /* Read the audio frame header and flush the bit buffer */
295     i_header = p_adec->bit_stream.fifo.buffer;
296     p_adec->bit_stream.fifo.buffer = 0;
297     p_adec->bit_stream.fifo.i_available = 0;
298     /* Read the sampling frequency (see ISO/IEC 11172-3 2.4.2.3) */
299     i_sampling_frequency = (int)((i_header & ADEC_HEADER_SAMPLING_FREQUENCY_MASK)
300         >> ADEC_HEADER_SAMPLING_FREQUENCY_SHIFT);
301     /* Read the mode (see ISO/IEC 11172-3 2.4.2.3) */
302     i_mode = (int)((i_header & ADEC_HEADER_MODE_MASK) >> ADEC_HEADER_MODE_SHIFT);
303     /* If a CRC can be found in the frame, get rid of it */
304     if ( (i_header & ADEC_HEADER_PROTECTION_BIT_MASK) == 0 )
305     {
306         GetByte( &p_adec->bit_stream );
307         GetByte( &p_adec->bit_stream );
308     }
309
310     /* Find out the bitrate per channel index */
311     i_bitrate_per_channel_index = (int)ppi_bitrate_per_channel_index[i_mode]
312         [(i_header & ADEC_HEADER_BITRATE_INDEX_MASK) >> ADEC_HEADER_BITRATE_INDEX_SHIFT];
313     /* Find out the number of subbands */
314     i_sblimit = (int)ppi_sblimit[i_sampling_frequency][i_bitrate_per_channel_index];
315     /* Check if the frame is valid or not */
316     if ( i_sblimit == 0 )
317     {
318         return( 0 );                                 /* the frame is invalid */
319     }
320     /* Find out the number of bits allocated */
321     pi_nbal = ppi_nbal[ (i_bitrate_per_channel_index <= 2) ? 0 : 1 ];
322
323     /* Find out the `bound' subband (see ISO/IEC 11172-3 2.4.2.3) */
324     if ( i_mode == 1 )
325     {
326         i_bound = (int)(((i_header & ADEC_HEADER_MODE_EXTENSION_MASK) >> (ADEC_HEADER_MODE_EXTENSION_SHIFT - 2)) + 4);
327         if ( i_bound > i_sblimit )
328         {
329             i_bound = i_sblimit;
330         }
331     }
332     else
333     {
334         i_bound = i_sblimit;
335     }
336
337     /* Read the allocation information (see ISO/IEC 11172-3 2.4.1.6) */
338     for ( i_sb = 0; i_sb < i_bound; i_sb++ )
339     {
340         i_2nbal = 2 * (i_nbal = (int)pi_nbal[ i_sb ]);
341         NeedBits( &p_adec->bit_stream, i_2nbal );
342         i_need += i_2nbal;
343         pi_allocation_0[ i_sb ] = (int)(p_adec->bit_stream.fifo.buffer >> (32 - i_nbal));
344         p_adec->bit_stream.fifo.buffer <<= i_nbal;
345         pi_allocation_1[ i_sb ] = (int)(p_adec->bit_stream.fifo.buffer >> (32 - i_nbal));
346         p_adec->bit_stream.fifo.buffer <<= i_nbal;
347         p_adec->bit_stream.fifo.i_available -= i_2nbal;
348         i_dump += i_2nbal;
349     }
350     for ( ; i_sb < i_sblimit; i_sb++ )
351     {
352         i_nbal = (int)pi_nbal[ i_sb ];
353         NeedBits( &p_adec->bit_stream, i_nbal );
354         i_need += i_nbal;
355         pi_allocation_0[ i_sb ] = (int)(p_adec->bit_stream.fifo.buffer >> (32 - i_nbal));
356         DumpBits( &p_adec->bit_stream, i_nbal );
357         i_dump += i_nbal;
358     }
359
360 #define MACRO( p_requantization ) \
361     for ( i_sb = 0; i_sb < i_bound; i_sb++ ) \
362     { \
363         if ( pi_allocation_0[i_sb] ) \
364         { \
365             pp_requantization_0[i_sb] = &((p_requantization)[pi_allocation_0[i_sb]]); \
366             NeedBits( &p_adec->bit_stream, 2 ); \
367             i_need += 2; \
368             pi_scfsi_0[i_sb] = (int)(p_adec->bit_stream.fifo.buffer >> (32 - 2)); \
369             DumpBits( &p_adec->bit_stream, 2 ); \
370             i_dump += 2; \
371         } \
372         else \
373         { \
374             ppf_sample_0[0][i_sb] = .0; \
375             ppf_sample_0[1][i_sb] = .0; \
376             ppf_sample_0[2][i_sb] = .0; \
377         } \
378 \
379         if ( pi_allocation_1[i_sb] ) \
380         { \
381             pp_requantization_1[i_sb] = &((p_requantization)[pi_allocation_1[i_sb]]); \
382             NeedBits( &p_adec->bit_stream, 2 ); \
383             i_need += 2; \
384             pi_scfsi_1[i_sb] = (int)(p_adec->bit_stream.fifo.buffer >> (32 - 2)); \
385             DumpBits( &p_adec->bit_stream, 2 ); \
386             i_dump += 2; \
387         } \
388         else \
389         { \
390             ppf_sample_1[0][i_sb] = .0; \
391             ppf_sample_1[1][i_sb] = .0; \
392             ppf_sample_1[2][i_sb] = .0; \
393         } \
394     } \
395 \
396     for ( ; i_sb < i_sblimit; i_sb++ ) \
397     { \
398         if ( pi_allocation_0[i_sb] ) \
399         { \
400             pp_requantization_0[i_sb] = &((p_requantization)[pi_allocation_0[i_sb]]); \
401             NeedBits( &p_adec->bit_stream, 4 ); \
402             i_need += 4; \
403             pi_scfsi_0[i_sb] = (int)(p_adec->bit_stream.fifo.buffer >> (32 - 2)); \
404             p_adec->bit_stream.fifo.buffer <<= 2; \
405             pi_scfsi_1[i_sb] = (int)(p_adec->bit_stream.fifo.buffer >> (32 - 2)); \
406             p_adec->bit_stream.fifo.buffer <<= 2; \
407             p_adec->bit_stream.fifo.i_available -= 4; \
408             i_dump += 4; \
409         } \
410         else \
411         { \
412             ppf_sample_0[0][i_sb] = .0; \
413             ppf_sample_0[1][i_sb] = .0; \
414             ppf_sample_0[2][i_sb] = .0; \
415             ppf_sample_1[0][i_sb] = .0; \
416             ppf_sample_1[1][i_sb] = .0; \
417             ppf_sample_1[2][i_sb] = .0; \
418         } \
419     }
420 /* #define MACRO */
421
422     if ( i_bitrate_per_channel_index <= 2 )
423     {
424         MACRO( p_requantization_cd )
425     }
426     else
427     {
428         MACRO( pp_requantization_ab[i_sb] )
429     }
430
431 #define SWITCH( pi_scfsi, pf_scalefactor_0, pf_scalefactor_1, pf_scalefactor_2 )\
432     switch ( (pi_scfsi)[i_sb] ) \
433     { \
434         case 0: \
435             NeedBits( &p_adec->bit_stream, (3*6) ); \
436             i_need += 18; \
437             (pf_scalefactor_0)[i_sb] = pf_scalefactor[p_adec->bit_stream.fifo.buffer >> (32 - 6)]; \
438             p_adec->bit_stream.fifo.buffer <<= 6; \
439             (pf_scalefactor_1)[i_sb] = pf_scalefactor[p_adec->bit_stream.fifo.buffer >> (32 - 6)]; \
440             p_adec->bit_stream.fifo.buffer <<= 6; \
441             (pf_scalefactor_2)[i_sb] = pf_scalefactor[p_adec->bit_stream.fifo.buffer >> (32 - 6)]; \
442             p_adec->bit_stream.fifo.buffer <<= 6; \
443             p_adec->bit_stream.fifo.i_available -= (3*6); \
444             i_dump += 18; \
445             break; \
446 \
447         case 1: \
448             NeedBits( &p_adec->bit_stream, (2*6) ); \
449             i_need += 12; \
450             (pf_scalefactor_0)[i_sb] = \
451                 (pf_scalefactor_1)[i_sb] = pf_scalefactor[p_adec->bit_stream.fifo.buffer >> (32 - 6)]; \
452             p_adec->bit_stream.fifo.buffer <<= 6; \
453             (pf_scalefactor_2)[i_sb] = pf_scalefactor[p_adec->bit_stream.fifo.buffer >> (32 - 6)]; \
454             p_adec->bit_stream.fifo.buffer <<= 6; \
455             p_adec->bit_stream.fifo.i_available -= (2*6); \
456             i_dump += 12; \
457             break; \
458 \
459         case 2: \
460             NeedBits( &p_adec->bit_stream, (1*6) ); \
461             i_need += 6; \
462             (pf_scalefactor_0)[i_sb] = \
463                 (pf_scalefactor_1)[i_sb] = \
464                 (pf_scalefactor_2)[i_sb] = pf_scalefactor[p_adec->bit_stream.fifo.buffer >> (32 - 6)]; \
465             DumpBits( &p_adec->bit_stream, (1*6) ); \
466             i_dump += 6; \
467             break; \
468 \
469         case 3: \
470             NeedBits( &p_adec->bit_stream, (2*6) ); \
471             i_need += 12; \
472             (pf_scalefactor_0)[i_sb] = pf_scalefactor[p_adec->bit_stream.fifo.buffer >> (32 - 6)]; \
473             p_adec->bit_stream.fifo.buffer <<= 6; \
474             (pf_scalefactor_1)[i_sb] = \
475                 (pf_scalefactor_2)[i_sb] = pf_scalefactor[p_adec->bit_stream.fifo.buffer >> (32 - 6)]; \
476             p_adec->bit_stream.fifo.buffer <<= 6; \
477             p_adec->bit_stream.fifo.i_available -= (2*6); \
478             i_dump += 12; \
479             break; \
480     }
481 /* #define SWITCH */
482
483     for ( i_sb = 0; i_sb < i_bound; i_sb++ )
484     {
485         if ( pi_allocation_0[i_sb] )
486         {
487             SWITCH( pi_scfsi_0, pf_scalefactor_0_0, pf_scalefactor_0_1, pf_scalefactor_0_2 )
488         }
489         if ( pi_allocation_1[i_sb] )
490         {
491             SWITCH( pi_scfsi_1, pf_scalefactor_1_0, pf_scalefactor_1_1, pf_scalefactor_1_2 )
492         }
493     }
494     for ( ; i_sb < i_sblimit; i_sb++ )
495     {
496         if ( pi_allocation_0[i_sb] )
497         {
498             SWITCH( pi_scfsi_0, pf_scalefactor_0_0, pf_scalefactor_0_1, pf_scalefactor_0_2 )
499             SWITCH( pi_scfsi_1, pf_scalefactor_1_0, pf_scalefactor_1_1, pf_scalefactor_1_2 )
500         }
501     }
502     for ( ; i_sb < 32; i_sb++ )
503     {
504         ppf_sample_0[0][i_sb] = .0;
505         ppf_sample_0[1][i_sb] = .0;
506         ppf_sample_0[2][i_sb] = .0;
507         ppf_sample_1[0][i_sb] = .0;
508         ppf_sample_1[1][i_sb] = .0;
509         ppf_sample_1[2][i_sb] = .0;
510     }
511
512 #define NEXT_BUF \
513 /* fprintf(stderr, "%p\n", p_adec->p_aout_fifo->buffer); */ \
514 /* fprintf(stderr, "l_end_frame == %li, %p\n", l_end_frame, (aout_frame_t *)p_adec->p_aout_fifo->buffer + l_end_frame); */ \
515     p_s16 = ((adec_frame_t *)p_adec->p_aout_fifo->buffer)[ l_end_frame ]; \
516 /* fprintf(stderr, "p_s16 == %p\n", p_s16); */ \
517     l_end_frame += 1; \
518     l_end_frame &= AOUT_FIFO_SIZE;
519 /* #define NEXT_BUF */
520
521 #define GROUPTEST( pp_requantization, ppf_sample, pf_sf ) \
522     requantization = *((pp_requantization)[i_sb]); \
523     if ( requantization.pf_ungroup == NULL ) \
524     { \
525         NeedBits( &p_adec->bit_stream, requantization.i_bits_per_codeword ); \
526         i_need += requantization.i_bits_per_codeword; \
527         (ppf_sample)[0][i_sb] = (f_scalefactor_0 = (pf_sf)[i_sb]) * (requantization.f_slope * \
528             (p_adec->bit_stream.fifo.buffer >> (32 - requantization.i_bits_per_codeword)) + requantization.f_offset); \
529         DumpBits( &p_adec->bit_stream, requantization.i_bits_per_codeword ); \
530         i_dump += requantization.i_bits_per_codeword; \
531 \
532         NeedBits( &p_adec->bit_stream, requantization.i_bits_per_codeword ); \
533         i_need += requantization.i_bits_per_codeword; \
534         (ppf_sample)[1][i_sb] = f_scalefactor_0 * (requantization.f_slope * \
535             (p_adec->bit_stream.fifo.buffer >> (32 - requantization.i_bits_per_codeword)) + requantization.f_offset); \
536         DumpBits( &p_adec->bit_stream, requantization.i_bits_per_codeword ); \
537         i_dump += requantization.i_bits_per_codeword; \
538 \
539         NeedBits( &p_adec->bit_stream, requantization.i_bits_per_codeword ); \
540         i_need += requantization.i_bits_per_codeword; \
541         (ppf_sample)[2][i_sb] = f_scalefactor_0 * (requantization.f_slope * \
542             (p_adec->bit_stream.fifo.buffer >> (32 - requantization.i_bits_per_codeword)) + requantization.f_offset); \
543         DumpBits( &p_adec->bit_stream, requantization.i_bits_per_codeword ); \
544         i_dump += requantization.i_bits_per_codeword; \
545     } \
546     else \
547     { \
548         NeedBits( &p_adec->bit_stream, requantization.i_bits_per_codeword ); \
549         i_need += requantization.i_bits_per_codeword; \
550         pf_ungroup = requantization.pf_ungroup + 3 * \
551             (p_adec->bit_stream.fifo.buffer >> (32 - requantization.i_bits_per_codeword)); \
552         DumpBits( &p_adec->bit_stream, requantization.i_bits_per_codeword ); \
553         i_dump += requantization.i_bits_per_codeword; \
554         (ppf_sample)[0][i_sb] = (f_scalefactor_0 = (pf_sf)[i_sb]) * pf_ungroup[0]; \
555         (ppf_sample)[1][i_sb] = f_scalefactor_0 * pf_ungroup[1]; \
556         (ppf_sample)[2][i_sb] = f_scalefactor_0 * pf_ungroup[2]; \
557     }
558 /* #define GROUPTEST */
559
560 #define READ_SAMPLE_L2S( pf_scalefactor_0, pf_scalefactor_1, i_grlimit ) \
561     for ( ; i_gr < (i_grlimit); i_gr++ ) \
562     { \
563         for ( i_sb = 0; i_sb < i_bound; i_sb++ ) \
564         { \
565             if ( pi_allocation_0[i_sb] ) \
566             { \
567                 GROUPTEST( pp_requantization_0, ppf_sample_0, (pf_scalefactor_0) ) \
568             } \
569             if ( pi_allocation_1[i_sb] ) \
570             { \
571                 GROUPTEST( pp_requantization_1, ppf_sample_1, (pf_scalefactor_1) ) \
572             } \
573         } \
574         for ( ; i_sb < i_sblimit; i_sb++ ) \
575         { \
576             if ( pi_allocation_0[i_sb] ) \
577             { \
578                 requantization = *(pp_requantization_0[i_sb]); \
579                 if ( requantization.pf_ungroup == NULL ) \
580                 { \
581                     NeedBits( &p_adec->bit_stream, requantization.i_bits_per_codeword ); \
582                     i_need += requantization.i_bits_per_codeword; \
583                     ppf_sample_0[0][i_sb] = (f_scalefactor_0 = (pf_scalefactor_0)[i_sb]) * \
584                         (requantization.f_slope * (f_dummy = \
585                         (float)(p_adec->bit_stream.fifo.buffer >> (32 - requantization.i_bits_per_codeword))) + \
586                         requantization.f_offset); \
587                     DumpBits( &p_adec->bit_stream, requantization.i_bits_per_codeword ); \
588                     i_dump += requantization.i_bits_per_codeword; \
589                     ppf_sample_1[0][i_sb] = (f_scalefactor_1 = (pf_scalefactor_1)[i_sb]) * \
590                         (requantization.f_slope * f_dummy + requantization.f_offset); \
591 \
592                     NeedBits( &p_adec->bit_stream, requantization.i_bits_per_codeword ); \
593                     i_need += requantization.i_bits_per_codeword; \
594                     ppf_sample_0[1][i_sb] = f_scalefactor_0 * \
595                         (requantization.f_slope * (f_dummy = \
596                         (float)(p_adec->bit_stream.fifo.buffer >> (32 - requantization.i_bits_per_codeword))) + \
597                         requantization.f_offset); \
598                     DumpBits( &p_adec->bit_stream, requantization.i_bits_per_codeword ); \
599                     i_dump += requantization.i_bits_per_codeword; \
600                     ppf_sample_1[1][i_sb] = f_scalefactor_1 * \
601                         (requantization.f_slope * f_dummy + requantization.f_offset); \
602 \
603                     NeedBits( &p_adec->bit_stream, requantization.i_bits_per_codeword ); \
604                     i_need += requantization.i_bits_per_codeword; \
605                     ppf_sample_0[2][i_sb] = f_scalefactor_0 * \
606                         (requantization.f_slope * (f_dummy = \
607                         (float)(p_adec->bit_stream.fifo.buffer >> (32 - requantization.i_bits_per_codeword))) + \
608                         requantization.f_offset); \
609                     DumpBits( &p_adec->bit_stream, requantization.i_bits_per_codeword ); \
610                     i_dump += requantization.i_bits_per_codeword; \
611                     ppf_sample_1[2][i_sb] = f_scalefactor_1 * \
612                         (requantization.f_slope * f_dummy + requantization.f_offset); \
613                 } \
614                 else \
615                 { \
616                     NeedBits( &p_adec->bit_stream, requantization.i_bits_per_codeword ); \
617                     i_need += requantization.i_bits_per_codeword; \
618                     pf_ungroup = requantization.pf_ungroup + 3 * \
619                         (p_adec->bit_stream.fifo.buffer >> (32 - requantization.i_bits_per_codeword)); \
620                     DumpBits( &p_adec->bit_stream, requantization.i_bits_per_codeword ); \
621                     i_dump += requantization.i_bits_per_codeword; \
622 \
623                     ppf_sample_0[0][i_sb] = (f_scalefactor_0 = (pf_scalefactor_0)[i_sb]) * pf_ungroup[0]; \
624                     ppf_sample_0[1][i_sb] = f_scalefactor_0 * pf_ungroup[1]; \
625                     ppf_sample_0[2][i_sb] = f_scalefactor_0 * pf_ungroup[2]; \
626 \
627                     ppf_sample_1[0][i_sb] = (f_scalefactor_1 = (pf_scalefactor_1)[i_sb]) * pf_ungroup[0]; \
628                     ppf_sample_1[1][i_sb] = f_scalefactor_1 * pf_ungroup[1]; \
629                     ppf_sample_1[2][i_sb] = f_scalefactor_1 * pf_ungroup[2]; \
630                 } \
631             } \
632         } \
633 \
634 /* fprintf(stderr, "%p", p_s16); */ \
635         DCT32( ppf_sample_0[0], &p_adec->bank_0 ); \
636         PCM( &p_adec->bank_0, &p_s16, 2 ); \
637 /* fprintf(stderr, " %p", p_s16); */ \
638         p_s16 -= 63; \
639 /* fprintf(stderr, " %p\n", p_s16); */ \
640 \
641 /* fprintf(stderr, "%p", p_s16); */ \
642         DCT32( ppf_sample_1[0], &p_adec->bank_1 ); \
643         PCM( &p_adec->bank_1, &p_s16, 2 ); \
644 /* fprintf(stderr, " %p", p_s16); */ \
645         p_s16 -= 1; \
646 /* fprintf(stderr, " %p\n", p_s16); */ \
647 \
648 /* fprintf(stderr, "%p", p_s16); */ \
649         DCT32( ppf_sample_0[1], &p_adec->bank_0 ); \
650         PCM( &p_adec->bank_0, &p_s16, 2 ); \
651 /* fprintf(stderr, " %p", p_s16); */ \
652         p_s16 -= 63; \
653 /* fprintf(stderr, " %p\n", p_s16); */ \
654 \
655 /* fprintf(stderr, "%p", p_s16); */ \
656         DCT32( ppf_sample_1[1], &p_adec->bank_1 ); \
657         PCM( &p_adec->bank_1, &p_s16, 2 ); \
658 /* fprintf(stderr, " %p", p_s16); */ \
659         p_s16 -= 1; \
660 /* fprintf(stderr, " %p\n", p_s16); */ \
661 \
662 /* fprintf(stderr, "%p", p_s16); */ \
663         DCT32( ppf_sample_0[2], &p_adec->bank_0 ); \
664         PCM( &p_adec->bank_0, &p_s16, 2 ); \
665 /* fprintf(stderr, " %p", p_s16); */ \
666         p_s16 -= 63; \
667 /* fprintf(stderr, " %p\n", p_s16); */ \
668 \
669 /* fprintf(stderr, "%p", p_s16); */ \
670         DCT32( ppf_sample_1[2], &p_adec->bank_1 ); \
671         PCM( &p_adec->bank_1, &p_s16, 2 ); \
672 /* fprintf(stderr, " %p", p_s16); */ \
673         p_s16 -= 1; \
674 /* fprintf(stderr, " %p\n", p_s16); */ \
675     }
676 /* #define READ_SAMPLE_L2S */
677
678     l_end_frame = p_adec->p_aout_fifo->l_end_frame;
679     i_gr = 0;
680
681     NEXT_BUF
682     READ_SAMPLE_L2S( pf_scalefactor_0_0, pf_scalefactor_1_0, 2 )
683
684     NEXT_BUF
685     READ_SAMPLE_L2S( pf_scalefactor_0_0, pf_scalefactor_1_0, 4 )
686
687     NEXT_BUF
688     READ_SAMPLE_L2S( pf_scalefactor_0_1, pf_scalefactor_1_1, 6 )
689
690     NEXT_BUF
691     READ_SAMPLE_L2S( pf_scalefactor_0_1, pf_scalefactor_1_1, 8 )
692
693     NEXT_BUF
694     READ_SAMPLE_L2S( pf_scalefactor_0_2, pf_scalefactor_1_2, 10 )
695
696     NEXT_BUF
697     READ_SAMPLE_L2S( pf_scalefactor_0_2, pf_scalefactor_1_2, 12 )
698
699 #if 0
700     fprintf(stderr, "adec debug: layer == %i, padding_bit == %i, sampling_frequency == %i, bitrate_index == %i\n",
701         (i_header & ADEC_HEADER_LAYER_MASK) >> ADEC_HEADER_LAYER_SHIFT,
702         (i_header & ADEC_HEADER_PADDING_BIT_MASK) >> ADEC_HEADER_PADDING_BIT_SHIFT,
703         (i_header & ADEC_HEADER_SAMPLING_FREQUENCY_MASK) >> ADEC_HEADER_SAMPLING_FREQUENCY_SHIFT,
704         (i_header & ADEC_HEADER_BITRATE_INDEX_MASK) >> ADEC_HEADER_BITRATE_INDEX_SHIFT);
705     fprintf(stderr, "adec debug: framesize == %i, i_need == %i, i_dump == %i\n",
706         pi_framesize[ 128 * ((i_header & ADEC_HEADER_LAYER_MASK) >> ADEC_HEADER_LAYER_SHIFT) +
707             64 * ((i_header & ADEC_HEADER_PADDING_BIT_MASK) >> ADEC_HEADER_PADDING_BIT_SHIFT) +
708             16 * ((i_header & ADEC_HEADER_SAMPLING_FREQUENCY_MASK) >> ADEC_HEADER_SAMPLING_FREQUENCY_SHIFT) +
709             1 * ((i_header & ADEC_HEADER_BITRATE_INDEX_MASK) >> ADEC_HEADER_BITRATE_INDEX_SHIFT) ],
710         i_need,
711         i_dump);
712 #endif
713     p_adec->bit_stream.fifo.buffer = 0;
714     p_adec->bit_stream.fifo.i_available = 0;
715     return( 6 );
716 }
717
718 /*****************************************************************************
719  * InitThread : initialize an audio decoder thread
720  *****************************************************************************
721  * This function is called from RunThread and performs the second step of the
722  * initialization. It returns 0 on success.
723  *****************************************************************************/
724 static int InitThread( adec_thread_t * p_adec )
725 {
726     aout_fifo_t         aout_fifo;
727
728     intf_DbgMsg("adec debug: initializing audio decoder thread %p\n", p_adec);
729
730     /* Our first job is to initialize the bit stream structure with the
731      * beginning of the input stream */
732     vlc_mutex_lock( &p_adec->fifo.data_lock );
733     while ( DECODER_FIFO_ISEMPTY(p_adec->fifo) )
734     {
735         if ( p_adec->b_die )
736         {
737             vlc_mutex_unlock( &p_adec->fifo.data_lock );
738             return( -1 );
739         }
740         vlc_cond_wait( &p_adec->fifo.data_wait, &p_adec->fifo.data_lock );
741     }
742     p_adec->bit_stream.p_ts = DECODER_FIFO_START( p_adec->fifo )->p_first_ts;
743     p_adec->bit_stream.p_byte = p_adec->bit_stream.p_ts->buffer + p_adec->bit_stream.p_ts->i_payload_start;
744     p_adec->bit_stream.p_end = p_adec->bit_stream.p_ts->buffer + p_adec->bit_stream.p_ts->i_payload_end;
745     vlc_mutex_unlock( &p_adec->fifo.data_lock );
746
747     /* Now we look for an audio frame header in the input stream */
748     if ( FindHeader(p_adec) )
749     {
750         return( -1 );                             /* b_die or b_error is set */
751     }
752
753     /*
754      * We have the header and all its informations : we must be able to create
755      * the audio output fifo.
756      */
757
758     /* Is the sound in mono mode or stereo mode ? */
759     if ( (p_adec->bit_stream.fifo.buffer & ADEC_HEADER_MODE_MASK) == ADEC_HEADER_MODE_MASK )
760     {
761         intf_DbgMsg("adec debug: mode == mono\n");
762         aout_fifo.i_type = AOUT_ADEC_MONO_FIFO;
763         aout_fifo.i_channels = 1;
764         aout_fifo.b_stereo = 0;
765     }
766     else
767     {
768         intf_DbgMsg("adec debug: mode == stereo\n");
769         aout_fifo.i_type = AOUT_ADEC_STEREO_FIFO;
770         aout_fifo.i_channels = 2;
771         aout_fifo.b_stereo = 1;
772     }
773
774     /* Checking the sampling frequency */
775     switch ( (p_adec->bit_stream.fifo.buffer & ADEC_HEADER_SAMPLING_FREQUENCY_MASK) \
776              >> ADEC_HEADER_SAMPLING_FREQUENCY_SHIFT )
777     {
778         case 0:
779             intf_DbgMsg("adec debug: sampling_frequency == 44100 Hz\n");
780             aout_fifo.l_rate = 44100;
781             break;
782
783         case 1:
784             intf_DbgMsg("adec debug: sampling_frequency == 48000 Hz\n");
785             aout_fifo.l_rate = 48000;
786             break;
787
788         case 2:
789             intf_DbgMsg("adec debug: sampling_frequency == 32000 Hz\n");
790             aout_fifo.l_rate = 32000;
791             break;
792
793         case 3:
794             intf_ErrMsg("adec error: can't create audio output fifo (sampling_frequency == `reserved')\n");
795             return( -1 );
796     }
797
798     aout_fifo.l_frame_size = ADEC_FRAME_SIZE;
799
800     /* Creating the audio output fifo */
801     if ( (p_adec->p_aout_fifo = aout_CreateFifo(p_adec->p_aout, &aout_fifo)) == NULL )
802     {
803         return( -1 );
804     }
805
806     intf_DbgMsg("adec debug: audio decoder thread %p initialized\n", p_adec);
807     return( 0 );
808 }
809
810 /*****************************************************************************
811  * RunThread : audio decoder thread
812  *****************************************************************************
813  * Audio decoder thread. This function does only returns when the thread is
814  * terminated.
815  *****************************************************************************/
816 static void RunThread( adec_thread_t * p_adec )
817 {
818 #if 0
819     static const int    pi_framesize[512] = ADEC_FRAME_SIZE;
820     int                 i_header;
821     int                 i_framesize;
822     int                 i_dummy;
823 #endif
824
825     intf_DbgMsg("adec debug: running audio decoder thread (%p) (pid == %i)\n", p_adec, getpid());
826
827     msleep( INPUT_PTS_DELAY );
828
829     /* Initializing the audio decoder thread */
830     if ( InitThread(p_adec) )
831     {
832         p_adec->b_error = 1;
833     }
834
835     /* Audio decoder thread's main loop */
836     while ( (!p_adec->b_die) && (!p_adec->b_error) )
837     {
838         switch ( (p_adec->bit_stream.fifo.buffer & ADEC_HEADER_LAYER_MASK) >> ADEC_HEADER_LAYER_SHIFT )
839         {
840             /* Reserved */
841             case 0:
842                 intf_DbgMsg("adec debug: layer == 0 (reserved)\n");
843                 p_adec->bit_stream.fifo.buffer = 0;
844                 p_adec->bit_stream.fifo.i_available = 0;
845                 break;
846
847             /* Layer III */
848             case 1:
849                 p_adec->bit_stream.fifo.buffer = 0;
850                 p_adec->bit_stream.fifo.i_available = 0;
851                 break;
852
853             /* Layer II */
854             case 2:
855                 if ( (p_adec->bit_stream.fifo.buffer & ADEC_HEADER_MODE_MASK) == ADEC_HEADER_MODE_MASK )
856                 {
857                     adec_Layer2_Mono( p_adec );
858                 }
859                 else
860                 {
861                     /* Waiting until there is enough free space in the audio output fifo
862                      * in order to store the new decoded frames */
863                     vlc_mutex_lock( &p_adec->p_aout_fifo->data_lock );
864                     /* adec_Layer2_Stereo() produces 6 output frames (2*1152/384)...
865                      * If these 6 frames were recorded in the audio output fifo, the
866                      * l_end_frame index would be incremented 6 times. But, if after
867                      * this operation the audio output fifo contains less than 6 frames,
868                      * it would mean that we had not enough room to store the 6 frames :-P */
869                     while ( (((p_adec->p_aout_fifo->l_end_frame + 6) - p_adec->p_aout_fifo->l_start_frame) & AOUT_FIFO_SIZE) < 6 ) /* XXX?? */
870                     {
871                         vlc_cond_wait( &p_adec->p_aout_fifo->data_wait, &p_adec->p_aout_fifo->data_lock );
872                     }
873                     if ( DECODER_FIFO_START(p_adec->fifo)->b_has_pts )
874                     {
875                         p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->l_end_frame] = DECODER_FIFO_START(p_adec->fifo)->i_pts;
876                         DECODER_FIFO_START(p_adec->fifo)->b_has_pts = 0;
877                     }
878                     else
879                     {
880                         p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->l_end_frame] = LAST_MDATE;
881                     }
882                     vlc_mutex_unlock( &p_adec->p_aout_fifo->data_lock );
883
884                     /* Decoding the frames */
885                     if ( adec_Layer2_Stereo(p_adec) )
886                     {
887                         vlc_mutex_lock( &p_adec->p_aout_fifo->data_lock );
888
889                         /* Frame 1 */
890                         p_adec->p_aout_fifo->l_end_frame = (p_adec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
891
892                         /* Frame 2 */
893                         p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->l_end_frame] = LAST_MDATE;
894                         p_adec->p_aout_fifo->l_end_frame = (p_adec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
895
896                         /* Frame 3 */
897                         p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->l_end_frame] = LAST_MDATE;
898                         p_adec->p_aout_fifo->l_end_frame = (p_adec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
899
900                         /* Frame 4 */
901                         p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->l_end_frame] = LAST_MDATE;
902                         p_adec->p_aout_fifo->l_end_frame = (p_adec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
903
904                         /* Frame 5 */
905                         p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->l_end_frame] = LAST_MDATE;
906                         p_adec->p_aout_fifo->l_end_frame = (p_adec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
907
908                         /* Frame 6 */
909                         p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->l_end_frame] = LAST_MDATE;
910                         p_adec->p_aout_fifo->l_end_frame = (p_adec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
911
912                         vlc_cond_signal( &p_adec->p_aout_fifo->data_wait );
913
914                         vlc_mutex_unlock( &p_adec->p_aout_fifo->data_lock );
915                     }
916                 }
917                 break;
918
919             /* Layer I */
920             case 3:
921                 if ( (p_adec->bit_stream.fifo.buffer & ADEC_HEADER_MODE_MASK) == ADEC_HEADER_MODE_MASK )
922                 {
923                     adec_Layer1_Mono( p_adec );
924                 }
925                 else
926                 {
927                     adec_Layer1_Stereo( p_adec );
928                 }
929                 break;
930
931             default:
932                 intf_DbgMsg("adec debug: layer == %i (unknown)\n",
933                     (p_adec->bit_stream.fifo.buffer & ADEC_HEADER_LAYER_MASK) >> ADEC_HEADER_LAYER_SHIFT);
934                 p_adec->bit_stream.fifo.buffer = 0;
935                 p_adec->bit_stream.fifo.i_available = 0;
936                 break;
937         }
938         FindHeader( p_adec );
939     }
940
941     /* If b_error is set, the audio decoder thread enters the error loop */
942     if ( p_adec->b_error )
943     {
944         ErrorThread( p_adec );
945     }
946
947     /* End of the audio decoder thread */
948     EndThread( p_adec );
949 }
950
951 /*****************************************************************************
952  * ErrorThread : audio decoder's RunThread() error loop
953  *****************************************************************************
954  * This function is called when an error occured during thread main's loop. The
955  * thread can still receive feed, but must be ready to terminate as soon as
956  * possible.
957  *****************************************************************************/
958 static void ErrorThread( adec_thread_t *p_adec )
959 {
960     /* We take the lock, because we are going to read/write the start/end
961      * indexes of the decoder fifo */
962     vlc_mutex_lock( &p_adec->fifo.data_lock );
963
964     /* Wait until a `die' order is sent */
965     while( !p_adec->b_die )
966     {
967         /* Trash all received PES packets */
968         while( !DECODER_FIFO_ISEMPTY(p_adec->fifo) )
969         {
970             input_NetlistFreePES( p_adec->bit_stream.p_input, DECODER_FIFO_START(p_adec->fifo) );
971             DECODER_FIFO_INCSTART( p_adec->fifo );
972         }
973
974         /* Waiting for the input thread to put new PES packets in the fifo */
975         vlc_cond_wait( &p_adec->fifo.data_wait, &p_adec->fifo.data_lock );
976     }
977
978     /* We can release the lock before leaving */
979     vlc_mutex_unlock( &p_adec->fifo.data_lock );
980 }
981
982 /*****************************************************************************
983  * EndThread : audio decoder thread destruction
984  *****************************************************************************
985  * This function is called when the thread ends after a sucessfull
986  * initialization.
987  *****************************************************************************/
988 static void EndThread( adec_thread_t *p_adec )
989 {
990     intf_DbgMsg("adec debug: destroying audio decoder thread %p\n", p_adec);
991
992     /* If the audio output fifo was created, we destroy it */
993     if ( p_adec->p_aout_fifo != NULL )
994     {
995         aout_DestroyFifo( p_adec->p_aout_fifo );
996
997         /* Make sure the output thread leaves the NextFrame() function */
998         vlc_mutex_lock( &(p_adec->p_aout_fifo->data_lock) );
999         vlc_cond_signal( &(p_adec->p_aout_fifo->data_wait) );
1000         vlc_mutex_unlock( &(p_adec->p_aout_fifo->data_lock) );
1001     }
1002     /* Destroy descriptor */
1003     free( p_adec );
1004
1005     intf_DbgMsg("adec debug: audio decoder thread %p destroyed\n", p_adec);
1006 }