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