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