]> git.sesse.net Git - vlc/blob - modules/audio_output/portaudio.c
vlc_cond_init: really remove useless parameter
[vlc] / modules / audio_output / portaudio.c
1 /*****************************************************************************
2  * portaudio.c : portaudio (v19) audio output plugin
3  *****************************************************************************
4  * Copyright (C) 2002, 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Frederic Ruget <frederic.ruget@free.fr>
8  *          Gildas Bazin <gbazin@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <vlc_common.h>
34 #include <vlc_plugin.h>
35 #include <vlc_aout.h>
36
37
38 #include <portaudio.h>
39
40 #define FRAME_SIZE 1024              /* The size is in samples, not in bytes */
41
42 #ifdef WIN32
43 #   define PORTAUDIO_IS_SERIOUSLY_BROKEN 1
44 #endif
45
46 /*****************************************************************************
47  * aout_sys_t: portaudio audio output method descriptor
48  *****************************************************************************/
49 typedef struct pa_thread_t
50 {
51     VLC_COMMON_MEMBERS
52     aout_instance_t *p_aout;
53
54     vlc_cond_t  wait;
55     vlc_mutex_t lock_wait;
56     bool  b_wait;
57     vlc_cond_t  signal;
58     vlc_mutex_t lock_signal;
59     bool  b_signal;
60
61 } pa_thread_t;
62
63 struct aout_sys_t
64 {
65     aout_instance_t *p_aout;
66     PaStream *p_stream;
67
68     PaDeviceIndex i_devices;
69     int i_sample_size;
70     PaDeviceIndex i_device_id;
71     const PaDeviceInfo *deviceInfo;
72
73     bool b_chan_reorder;              /* do we need channel reordering */
74     int pi_chan_table[AOUT_CHAN_MAX];
75     uint32_t i_channel_mask;
76     uint32_t i_bits_per_sample;
77     uint32_t i_channels;
78 };
79
80 static const uint32_t pi_channels_out[] =
81     { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT,
82       AOUT_CHAN_CENTER, AOUT_CHAN_LFE,
83       AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, AOUT_CHAN_REARCENTER,
84       AOUT_CHAN_MIDDLELEFT, AOUT_CHAN_MIDDLERIGHT, 0 };
85
86 #ifdef PORTAUDIO_IS_SERIOUSLY_BROKEN
87 static bool b_init = 0;
88 static pa_thread_t *pa_thread;
89 static void* PORTAUDIOThread( vlc_object_t * );
90 #endif
91
92 /*****************************************************************************
93  * Local prototypes.
94  *****************************************************************************/
95 static int  Open        ( vlc_object_t * );
96 static void Close       ( vlc_object_t * );
97 static void Play        ( aout_instance_t * );
98
99 static int PAOpenDevice( aout_instance_t * );
100 static int PAOpenStream( aout_instance_t * );
101
102 /*****************************************************************************
103  * Module descriptor
104  *****************************************************************************/
105 #define DEVICE_TEXT N_("Output device")
106 #define DEVICE_LONGTEXT N_("Portaudio identifier for the output device")
107
108 vlc_module_begin();
109     set_shortname( "PortAudio" );
110     set_description( N_("PORTAUDIO audio output") );
111     set_category( CAT_AUDIO );
112     set_subcategory( SUBCAT_AUDIO_AOUT );
113     add_integer( "portaudio-device", 0, NULL,
114                  DEVICE_TEXT, DEVICE_LONGTEXT, false );
115     set_capability( "audio output", 0 );
116     set_callbacks( Open, Close );
117 vlc_module_end();
118
119 /* This routine will be called by the PortAudio engine when audio is needed.
120  * It may called at interrupt level on some machines so don't do anything
121  * that could mess up the system like calling malloc() or free().
122  */
123 static int paCallback( const void *inputBuffer, void *outputBuffer,
124                        unsigned long framesPerBuffer,
125                        const PaStreamCallbackTimeInfo *paDate,
126                        PaStreamCallbackFlags statusFlags, void *p_cookie )
127 {
128     struct aout_sys_t *p_sys = (struct aout_sys_t*) p_cookie;
129     aout_instance_t   *p_aout = p_sys->p_aout;
130     aout_buffer_t     *p_buffer;
131     mtime_t out_date;
132
133     out_date = mdate() + (mtime_t) ( 1000000 *
134         ( paDate->outputBufferDacTime - paDate->currentTime ) );
135     p_buffer = aout_OutputNextBuffer( p_aout, out_date, true );
136
137     if ( p_buffer != NULL )
138     {
139         if( p_sys->b_chan_reorder )
140         {
141             /* Do the channel reordering here */
142             aout_ChannelReorder( p_buffer->p_buffer, p_buffer->i_nb_bytes,
143                                  p_sys->i_channels, p_sys->pi_chan_table,
144                                  p_sys->i_bits_per_sample );
145         }
146         vlc_memcpy( outputBuffer, p_buffer->p_buffer,
147                     framesPerBuffer * p_sys->i_sample_size );
148         /* aout_BufferFree may be dangereous here, but then so is
149          * aout_OutputNextBuffer (calls aout_BufferFree internally).
150          * one solution would be to link the no longer useful buffers
151          * in a second fifo (in aout_OutputNextBuffer too) and to
152          * wait until we are in Play to do the actual free.
153          */
154         aout_BufferFree( p_buffer );
155     }
156     else
157         /* Audio output buffer shortage -> stop the fill process and wait */
158     {
159         vlc_memset( outputBuffer, 0, framesPerBuffer * p_sys->i_sample_size );
160     }
161     return 0;
162 }
163
164 /*****************************************************************************
165  * Open: open the audio device
166  *****************************************************************************/
167 static int Open( vlc_object_t * p_this )
168 {
169     aout_instance_t *p_aout = (aout_instance_t *)p_this;
170     struct aout_sys_t * p_sys;
171     vlc_value_t val;
172     int i_err;
173
174     msg_Dbg( p_aout, "entering Open()");
175
176     /* Allocate p_sys structure */
177     p_sys = (aout_sys_t *)malloc( sizeof(aout_sys_t) );
178     if( p_sys == NULL )
179         return VLC_ENOMEM;
180     p_sys->p_aout = p_aout;
181     p_sys->p_stream = 0;
182     p_aout->output.p_sys = p_sys;
183     p_aout->output.pf_play = Play;
184
185     /* Retrieve output device id from config */
186     var_Create( p_aout, "portaudio-device", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT);
187     var_Get( p_aout, "portaudio-device", &val );
188     p_sys->i_device_id = val.i_int;
189
190 #ifdef PORTAUDIO_IS_SERIOUSLY_BROKEN
191     if( !b_init )
192     {
193         /* Test device */
194         if( PAOpenDevice( p_aout ) != VLC_SUCCESS )
195         {
196             msg_Err( p_aout, "cannot open portaudio device" );
197             free( p_sys );
198             return VLC_EGENERIC;
199         }
200
201         /* Close device for now. We'll re-open it later on */
202         if( ( i_err = Pa_Terminate() ) != paNoError )
203         {
204             msg_Err( p_aout, "closing the device returned %d", i_err );
205         }
206
207         b_init = true;
208
209         /* Now we need to setup our DirectSound play notification structure */
210         pa_thread = vlc_object_create( p_aout, sizeof(pa_thread_t) );
211         pa_thread->p_aout = p_aout;
212         pa_thread->b_error = false;
213         vlc_mutex_init( &pa_thread->lock_wait );
214         vlc_cond_init( &pa_thread->wait );
215         pa_thread->b_wait = false;
216         vlc_mutex_init( &pa_thread->lock_signal );
217         vlc_cond_init( &pa_thread->signal );
218         pa_thread->b_signal = false;
219
220         /* Create PORTAUDIOThread */
221         if( vlc_thread_create( pa_thread, "aout", PORTAUDIOThread,
222                                VLC_THREAD_PRIORITY_OUTPUT, false ) )
223         {
224             msg_Err( p_aout, "cannot create PORTAUDIO thread" );
225             return VLC_EGENERIC;
226         }
227     }
228     else
229     {
230         pa_thread->p_aout = p_aout;
231         pa_thread->b_wait = false;
232         pa_thread->b_signal = false;
233         pa_thread->b_error = false;
234     }
235
236     /* Signal start of stream */
237     vlc_mutex_lock( &pa_thread->lock_signal );
238     pa_thread->b_signal = true;
239     vlc_cond_signal( &pa_thread->signal );
240     vlc_mutex_unlock( &pa_thread->lock_signal );
241
242     /* Wait until thread is ready */
243     vlc_mutex_lock( &pa_thread->lock_wait );
244     if( !pa_thread->b_wait )
245         vlc_cond_wait( &pa_thread->wait, &pa_thread->lock_wait );
246     vlc_mutex_unlock( &pa_thread->lock_wait );
247     pa_thread->b_wait = false;
248
249     if( pa_thread->b_error )
250     {
251         msg_Err( p_aout, "PORTAUDIO thread failed" );
252         Close( p_this );
253         return VLC_EGENERIC;
254     }
255
256     return VLC_SUCCESS;
257
258 #else
259
260     if( PAOpenDevice( p_aout ) != VLC_SUCCESS )
261     {
262         msg_Err( p_aout, "cannot open portaudio device" );
263         free( p_sys );
264         return VLC_EGENERIC;
265     }
266
267     if( PAOpenStream( p_aout ) != VLC_SUCCESS )
268     {
269         msg_Err( p_aout, "cannot open portaudio device" );
270     }
271
272     return VLC_SUCCESS;
273
274 #endif
275 }
276
277 /*****************************************************************************
278  * Close: close the audio device
279  *****************************************************************************/
280 static void Close ( vlc_object_t *p_this )
281 {
282     aout_instance_t *p_aout = (aout_instance_t *)p_this;
283     aout_sys_t *p_sys = p_aout->output.p_sys;
284     int i_err;
285
286     msg_Dbg( p_aout, "closing portaudio");
287
288 #ifdef PORTAUDIO_IS_SERIOUSLY_BROKEN
289
290     /* Signal end of stream */
291     vlc_mutex_lock( &pa_thread->lock_signal );
292     pa_thread->b_signal = true;
293     vlc_cond_signal( &pa_thread->signal );
294     vlc_mutex_unlock( &pa_thread->lock_signal );
295
296     /* Wait until thread is ready */
297     vlc_mutex_lock( &pa_thread->lock_wait );
298     if( !pa_thread->b_wait )
299         vlc_cond_wait( &pa_thread->wait, &pa_thread->lock_wait );
300     vlc_mutex_unlock( &pa_thread->lock_wait );
301     pa_thread->b_wait = false;
302
303 #else
304
305     i_err = Pa_StopStream( p_sys->p_stream );
306     if( i_err != paNoError )
307     {
308         msg_Err( p_aout, "Pa_StopStream: %d (%s)", i_err,
309                  Pa_GetErrorText( i_err ) );
310     }
311     i_err = Pa_CloseStream( p_sys->p_stream );
312     if( i_err != paNoError )
313     {
314         msg_Err( p_aout, "Pa_CloseStream: %d (%s)", i_err,
315                  Pa_GetErrorText( i_err ) );
316     }
317
318     i_err = Pa_Terminate();
319     if( i_err != paNoError )
320     {
321         msg_Err( p_aout, "Pa_Terminate: %d (%s)", i_err,
322                  Pa_GetErrorText( i_err ) );
323     }
324
325 #endif
326
327     msg_Dbg( p_aout, "portaudio closed");
328     free( p_sys );
329 }
330
331 static int PAOpenDevice( aout_instance_t *p_aout )
332 {
333     aout_sys_t *p_sys = p_aout->output.p_sys;
334     const PaDeviceInfo *p_pdi;
335     PaError i_err;
336     vlc_value_t val, text;
337     int i;
338
339     /* Initialize portaudio */
340     i_err = Pa_Initialize();
341     if( i_err != paNoError )
342     {
343         msg_Err( p_aout, "Pa_Initialize returned %d : %s",
344                  i_err, Pa_GetErrorText( i_err ) );
345
346         return VLC_EGENERIC;
347     }
348
349     p_sys->i_devices = Pa_GetDeviceCount();
350     if( p_sys->i_devices < 0 )
351     {
352         i_err = p_sys->i_devices;
353         msg_Err( p_aout, "Pa_GetDeviceCount returned %d : %s", i_err,
354                  Pa_GetErrorText( i_err ) );
355
356         goto error;
357     }
358
359     /* Display all devices info */
360     msg_Dbg( p_aout, "number of devices = %d", p_sys->i_devices );
361     for( i = 0; i < p_sys->i_devices; i++ )
362     {
363         p_pdi = Pa_GetDeviceInfo( i );
364         msg_Dbg( p_aout, "------------------------------------- #%d", i );
365         msg_Dbg( p_aout, "Name         = %s", p_pdi->name );
366         msg_Dbg( p_aout, "Max Inputs   = %d, Max Outputs = %d",
367                   p_pdi->maxInputChannels, p_pdi->maxOutputChannels );
368     }
369     msg_Dbg( p_aout, "-------------------------------------" );
370
371     msg_Dbg( p_aout, "requested device is #%d", p_sys->i_device_id );
372     if( p_sys->i_device_id >= p_sys->i_devices )
373     {
374         msg_Err( p_aout, "device %d does not exist", p_sys->i_device_id );
375         goto error;
376     }
377     p_sys->deviceInfo = Pa_GetDeviceInfo( p_sys->i_device_id );
378
379     if( p_sys->deviceInfo->maxOutputChannels < 1 )
380     {
381         msg_Err( p_aout, "no channel available" );
382         goto error;
383     }
384
385     if( var_Type( p_aout, "audio-device" ) == 0 )
386     {
387         var_Create( p_aout, "audio-device", VLC_VAR_INTEGER|VLC_VAR_HASCHOICE);
388         text.psz_string = _("Audio Device");
389         var_Change( p_aout, "audio-device", VLC_VAR_SETTEXT, &text, NULL );
390
391         if( p_sys->deviceInfo->maxOutputChannels >= 1 )
392         {
393             val.i_int = AOUT_VAR_MONO;
394             text.psz_string = N_("Mono");
395             var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE,
396                         &val, &text );
397             msg_Dbg( p_aout, "device supports 1 channel" );
398         }
399         if( p_sys->deviceInfo->maxOutputChannels >= 2 )
400         {
401             val.i_int = AOUT_VAR_STEREO;
402             text.psz_string = N_("Stereo");
403             var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE,
404                         &val, &text );
405             var_Change( p_aout, "audio-device", VLC_VAR_SETDEFAULT,
406                         &val, NULL );
407             var_Set( p_aout, "audio-device", val );
408             msg_Dbg( p_aout, "device supports 2 channels" );
409         }
410         if( p_sys->deviceInfo->maxOutputChannels >= 4 )
411         {
412             val.i_int = AOUT_VAR_2F2R;
413             text.psz_string = N_("2 Front 2 Rear");
414             var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE,
415                         &val, &text );
416             msg_Dbg( p_aout, "device supports 4 channels" );
417         }
418         if( p_sys->deviceInfo->maxOutputChannels >= 5 )
419         {
420             val.i_int = AOUT_VAR_3F2R;
421             text.psz_string = N_("3 Front 2 Rear");
422             var_Change( p_aout, "audio-device",
423                         VLC_VAR_ADDCHOICE, &val, &text );
424             msg_Dbg( p_aout, "device supports 5 channels" );
425         }
426         if( p_sys->deviceInfo->maxOutputChannels >= 6 )
427         {
428             val.i_int = AOUT_VAR_5_1;
429             text.psz_string = "5.1";
430             var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE,
431                         &val, &text );
432             msg_Dbg( p_aout, "device supports 5.1 channels" );
433         }
434
435         var_AddCallback( p_aout, "audio-device", aout_ChannelsRestart, NULL );
436
437         val.b_bool = true;
438         var_Set( p_aout, "intf-change", val );
439     }
440
441     /* Audio format is paFloat32 (always supported by portaudio v19) */
442     p_aout->output.output.i_format = VLC_FOURCC('f','l','3','2');
443
444     return VLC_SUCCESS;
445
446  error:
447     if( ( i_err = Pa_Terminate() ) != paNoError )
448     {
449         msg_Err( p_aout, "Pa_Terminate returned %d", i_err );
450     }
451     return VLC_EGENERIC;
452 }
453
454 static int PAOpenStream( aout_instance_t *p_aout )
455 {
456     aout_sys_t *p_sys = p_aout->output.p_sys;
457     const PaHostErrorInfo* paLastHostErrorInfo = Pa_GetLastHostErrorInfo();
458     PaStreamParameters paStreamParameters;
459     vlc_value_t val;
460     int i_channels, i_err;
461     uint32_t i_channel_mask;
462
463     if( var_Get( p_aout, "audio-device", &val ) < 0 )
464     {
465         return VLC_EGENERIC;
466     }
467
468     if( val.i_int == AOUT_VAR_5_1 )
469     {
470         p_aout->output.output.i_physical_channels
471             = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
472               | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT
473               | AOUT_CHAN_LFE;
474     }
475     else if( val.i_int == AOUT_VAR_3F2R )
476     {
477         p_aout->output.output.i_physical_channels
478             = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
479             | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT;
480     }
481     else if( val.i_int == AOUT_VAR_2F2R )
482     {
483         p_aout->output.output.i_physical_channels
484             = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
485             | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT;
486     }
487     else if( val.i_int == AOUT_VAR_MONO )
488     {
489         p_aout->output.output.i_physical_channels = AOUT_CHAN_CENTER;
490     }
491     else
492     {
493         p_aout->output.output.i_physical_channels
494             = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
495     }
496
497     i_channels = aout_FormatNbChannels( &p_aout->output.output );
498     msg_Dbg( p_aout, "nb_channels requested = %d", i_channels );
499     i_channel_mask = p_aout->output.output.i_physical_channels;
500
501     /* Calculate the frame size in bytes */
502     p_sys->i_sample_size = 4 * i_channels;
503     p_aout->output.i_nb_samples = FRAME_SIZE;
504     aout_FormatPrepare( &p_aout->output.output );
505     aout_VolumeSoftInit( p_aout );
506
507     /* Check for channel reordering */
508     p_aout->output.p_sys->i_channel_mask = i_channel_mask;
509     p_aout->output.p_sys->i_bits_per_sample = 32; /* forced to paFloat32 */
510     p_aout->output.p_sys->i_channels = i_channels;
511
512     p_aout->output.p_sys->b_chan_reorder =
513         aout_CheckChannelReorder( NULL, pi_channels_out,
514                                   i_channel_mask, i_channels,
515                                   p_aout->output.p_sys->pi_chan_table );
516
517     if( p_aout->output.p_sys->b_chan_reorder )
518     {
519         msg_Dbg( p_aout, "channel reordering needed" );
520     }
521
522     paStreamParameters.device = p_sys->i_device_id;
523     paStreamParameters.channelCount = i_channels;
524     paStreamParameters.sampleFormat = paFloat32;
525     paStreamParameters.suggestedLatency =
526         p_sys->deviceInfo->defaultLowOutputLatency;
527     paStreamParameters.hostApiSpecificStreamInfo = NULL;
528
529     i_err = Pa_OpenStream( &p_sys->p_stream, NULL /* no input */,
530                 &paStreamParameters, (double)p_aout->output.output.i_rate,
531                 FRAME_SIZE, paClipOff, paCallback, p_sys );
532     if( i_err != paNoError )
533     {
534         msg_Err( p_aout, "Pa_OpenStream returns %d : %s", i_err,
535                  Pa_GetErrorText( i_err ) );
536         if( i_err == paUnanticipatedHostError )
537         {
538             msg_Err( p_aout, "type %d code %ld : %s",
539                      paLastHostErrorInfo->hostApiType,
540                      paLastHostErrorInfo->errorCode,
541                      paLastHostErrorInfo->errorText );
542         }
543         p_sys->p_stream = 0;
544         return VLC_EGENERIC;
545     }
546
547     i_err = Pa_StartStream( p_sys->p_stream );
548     if( i_err != paNoError )
549     {
550         msg_Err( p_aout, "Pa_StartStream() failed" );
551         Pa_CloseStream( p_sys->p_stream );
552         return VLC_EGENERIC;
553     }
554
555     return VLC_SUCCESS;
556 }
557
558 /*****************************************************************************
559  * Play: play sound
560  *****************************************************************************/
561 static void Play( aout_instance_t * p_aout )
562 {
563 }
564
565 #ifdef PORTAUDIO_IS_SERIOUSLY_BROKEN
566 /*****************************************************************************
567  * PORTAUDIOThread: all interactions with libportaudio.a are handled
568  * in this single thread.  Otherwise libportaudio.a is _not_ happy :-(
569  *****************************************************************************/
570 static void* PORTAUDIOThread( vlc_object_t *p_this )
571 {
572     pa_thread_t *pa_thread = (pa_thread_t*)p_this;
573     aout_instance_t *p_aout;
574     aout_sys_t *p_sys;
575     int i_err;
576     int canc = vlc_savecancel ();
577
578     while( vlc_object_alive (pa_thread) )
579     {
580         /* Wait for start of stream */
581         vlc_mutex_lock( &pa_thread->lock_signal );
582         if( !pa_thread->b_signal )
583             vlc_cond_wait( &pa_thread->signal, &pa_thread->lock_signal );
584         vlc_mutex_unlock( &pa_thread->lock_signal );
585         pa_thread->b_signal = false;
586
587         p_aout = pa_thread->p_aout;
588         p_sys = p_aout->output.p_sys;
589
590         if( PAOpenDevice( p_aout ) != VLC_SUCCESS )
591         {
592             msg_Err( p_aout, "cannot open portaudio device" );
593             pa_thread->b_error = true;
594         }
595
596         if( !pa_thread->b_error && PAOpenStream( p_aout ) != VLC_SUCCESS )
597         {
598             msg_Err( p_aout, "cannot open portaudio device" );
599             pa_thread->b_error = true;
600
601             i_err = Pa_Terminate();
602             if( i_err != paNoError )
603             {
604                 msg_Err( p_aout, "Pa_Terminate: %d (%s)", i_err,
605                          Pa_GetErrorText( i_err ) );
606             }
607         }
608
609         /* Tell the main thread that we are ready */
610         vlc_mutex_lock( &pa_thread->lock_wait );
611         pa_thread->b_wait = true;
612         vlc_cond_signal( &pa_thread->wait );
613         vlc_mutex_unlock( &pa_thread->lock_wait );
614
615         /* Wait for end of stream */
616         vlc_mutex_lock( &pa_thread->lock_signal );
617         if( !pa_thread->b_signal )
618             vlc_cond_wait( &pa_thread->signal, &pa_thread->lock_signal );
619         vlc_mutex_unlock( &pa_thread->lock_signal );
620         pa_thread->b_signal = false;
621
622         if( pa_thread->b_error ) continue;
623
624         i_err = Pa_StopStream( p_sys->p_stream );
625         if( i_err != paNoError )
626         {
627             msg_Err( p_aout, "Pa_StopStream: %d (%s)", i_err,
628                      Pa_GetErrorText( i_err ) );
629         }
630         i_err = Pa_CloseStream( p_sys->p_stream );
631         if( i_err != paNoError )
632         {
633             msg_Err( p_aout, "Pa_CloseStream: %d (%s)", i_err,
634                      Pa_GetErrorText( i_err ) );
635         }
636         i_err = Pa_Terminate();
637         if( i_err != paNoError )
638         {
639             msg_Err( p_aout, "Pa_Terminate: %d (%s)", i_err,
640                      Pa_GetErrorText( i_err ) );
641         }
642
643         /* Tell the main thread that we are ready */
644         vlc_mutex_lock( &pa_thread->lock_wait );
645         pa_thread->b_wait = true;
646         vlc_cond_signal( &pa_thread->wait );
647         vlc_mutex_unlock( &pa_thread->lock_wait );
648     }
649     vlc_restorecancel (canc);
650     return NULL;
651 }
652 #endif