~ubuntu-branches/ubuntu/maverick/vlc/maverick

« back to all changes in this revision

Viewing changes to modules/audio_output/portaudio.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-09-17 21:56:14 UTC
  • mfrom: (1.1.17 upstream)
  • Revision ID: james.westby@ubuntu.com-20080917215614-tj0vx8xzd57e52t8
Tags: 0.9.2-1ubuntu1
* New Upstream Release, exception granted by
    - dktrkranz, norsetto, Hobbsee (via irc). LP: #270404

Changes done in ubuntu:

* add libxul-dev to build-depends
* make sure that vlc is build against libxul in configure. This doesn't
  change anything in the package, but makes it more robust if building
  in an 'unclean' chroot or when modifying the package.
* debian/control: make Vcs-* fields point to the motumedia branch
* add libx264-dev and libass-dev to build-depends
  LP: #210354, #199870
* actually enable libass support by passing --enable-libass to configure
* enable libdca: add libdca-dev to build depends and --enable-libdca
* install the x264 plugin.

Changes already in the pkg-multimedia branch in debian:

* don't install usr/share/vlc/mozilla in debian/mozilla-plugin-vlc.install  
* new upstream .desktop file now registers flash video mimetype LP: #261567
* add Xb-Npp-Applications to mozilla-plugin-vlc
* remove duplicate entries in debian/vlc-nox.install

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * portaudio.c : portaudio (v19) audio output plugin
3
3
 *****************************************************************************
4
4
 * Copyright (C) 2002, 2006 the VideoLAN team
5
 
 * $Id: da2758aadbae32248fc3adf871604aa7e5936bb2 $
 
5
 * $Id: 3a8764063d76ff4a2d99377b69fa764dc0fd998d $
6
6
 *
7
7
 * Authors: Frederic Ruget <frederic.ruget@free.fr>
8
8
 *          Gildas Bazin <gbazin@videolan.org>
11
11
 * it under the terms of the GNU General Public License as published by
12
12
 * the Free Software Foundation; either version 2 of the License, or
13
13
 * (at your option) any later version.
14
 
 * 
 
14
 *
15
15
 * This program is distributed in the hope that it will be useful,
16
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
25
/*****************************************************************************
26
26
 * Preamble
27
27
 *****************************************************************************/
28
 
#include <string.h>
29
 
#include <stdlib.h>
30
 
 
31
 
#include <vlc/vlc.h>
32
 
#include <vlc/aout.h>
 
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
 
33
38
#include <portaudio.h>
34
39
 
35
 
#include "aout_internal.h"
36
 
 
37
40
#define FRAME_SIZE 1024              /* The size is in samples, not in bytes */
38
41
 
39
42
#ifdef WIN32
50
53
 
51
54
    vlc_cond_t  wait;
52
55
    vlc_mutex_t lock_wait;
53
 
    vlc_bool_t  b_wait;
 
56
    bool  b_wait;
54
57
    vlc_cond_t  signal;
55
58
    vlc_mutex_t lock_signal;
56
 
    vlc_bool_t  b_signal;
 
59
    bool  b_signal;
57
60
 
58
61
} pa_thread_t;
59
62
 
67
70
    PaDeviceIndex i_device_id;
68
71
    const PaDeviceInfo *deviceInfo;
69
72
 
70
 
    vlc_bool_t b_chan_reorder;              /* do we need channel reordering */
 
73
    bool b_chan_reorder;              /* do we need channel reordering */
71
74
    int pi_chan_table[AOUT_CHAN_MAX];
72
75
    uint32_t i_channel_mask;
73
76
    uint32_t i_bits_per_sample;
74
77
    uint32_t i_channels;
75
78
};
76
79
 
77
 
static const uint32_t pi_channels_in[] =
78
 
    { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT,
79
 
      AOUT_CHAN_MIDDLELEFT, AOUT_CHAN_MIDDLERIGHT,
80
 
      AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT,
81
 
      AOUT_CHAN_CENTER, AOUT_CHAN_LFE, 0 };
82
80
static const uint32_t pi_channels_out[] =
83
81
    { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT,
84
82
      AOUT_CHAN_CENTER, AOUT_CHAN_LFE,
85
 
      AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT,
 
83
      AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, AOUT_CHAN_REARCENTER,
86
84
      AOUT_CHAN_MIDDLELEFT, AOUT_CHAN_MIDDLERIGHT, 0 };
87
85
 
88
86
#ifdef PORTAUDIO_IS_SERIOUSLY_BROKEN
89
 
static vlc_bool_t b_init = 0;
 
87
static bool b_init = 0;
90
88
static pa_thread_t *pa_thread;
91
 
static void PORTAUDIOThread( pa_thread_t * );
 
89
static void* PORTAUDIOThread( vlc_object_t * );
92
90
#endif
93
91
 
94
92
/*****************************************************************************
109
107
 
110
108
vlc_module_begin();
111
109
    set_shortname( "PortAudio" );
112
 
    set_description( _("PORTAUDIO audio output") );
 
110
    set_description( N_("PORTAUDIO audio output") );
113
111
    set_category( CAT_AUDIO );
114
112
    set_subcategory( SUBCAT_AUDIO_AOUT );
115
113
    add_integer( "portaudio-device", 0, NULL,
116
 
                 DEVICE_TEXT, DEVICE_LONGTEXT, VLC_FALSE );
 
114
                 DEVICE_TEXT, DEVICE_LONGTEXT, false );
117
115
    set_capability( "audio output", 0 );
118
116
    set_callbacks( Open, Close );
119
117
vlc_module_end();
134
132
 
135
133
    out_date = mdate() + (mtime_t) ( 1000000 *
136
134
        ( paDate->outputBufferDacTime - paDate->currentTime ) );
137
 
    p_buffer = aout_OutputNextBuffer( p_aout, out_date, VLC_TRUE );
 
135
    p_buffer = aout_OutputNextBuffer( p_aout, out_date, true );
138
136
 
139
137
    if ( p_buffer != NULL )
140
138
    {
145
143
                                 p_sys->i_channels, p_sys->pi_chan_table,
146
144
                                 p_sys->i_bits_per_sample );
147
145
        }
148
 
        p_aout->p_vlc->pf_memcpy( outputBuffer, p_buffer->p_buffer,
149
 
                                  framesPerBuffer * p_sys->i_sample_size );
 
146
        vlc_memcpy( outputBuffer, p_buffer->p_buffer,
 
147
                    framesPerBuffer * p_sys->i_sample_size );
150
148
        /* aout_BufferFree may be dangereous here, but then so is
151
149
         * aout_OutputNextBuffer (calls aout_BufferFree internally).
152
150
         * one solution would be to link the no longer useful buffers
158
156
    else
159
157
        /* Audio output buffer shortage -> stop the fill process and wait */
160
158
    {
161
 
        p_aout->p_vlc->pf_memset( outputBuffer, 0,
162
 
                                  framesPerBuffer * p_sys->i_sample_size );
 
159
        vlc_memset( outputBuffer, 0, framesPerBuffer * p_sys->i_sample_size );
163
160
    }
164
161
    return 0;
165
162
}
179
176
    /* Allocate p_sys structure */
180
177
    p_sys = (aout_sys_t *)malloc( sizeof(aout_sys_t) );
181
178
    if( p_sys == NULL )
182
 
    {
183
 
        msg_Err( p_aout, "out of memory" );
184
179
        return VLC_ENOMEM;
185
 
    }
186
180
    p_sys->p_aout = p_aout;
187
181
    p_sys->p_stream = 0;
188
182
    p_aout->output.p_sys = p_sys;
210
204
            msg_Err( p_aout, "closing the device returned %d", i_err );
211
205
        }
212
206
 
213
 
        b_init = VLC_TRUE;
 
207
        b_init = true;
214
208
 
215
209
        /* Now we need to setup our DirectSound play notification structure */
216
210
        pa_thread = vlc_object_create( p_aout, sizeof(pa_thread_t) );
217
211
        pa_thread->p_aout = p_aout;
218
 
        pa_thread->b_error = VLC_FALSE;
219
 
        vlc_mutex_init( p_aout, &pa_thread->lock_wait );
 
212
        pa_thread->b_error = false;
 
213
        vlc_mutex_init( &pa_thread->lock_wait );
220
214
        vlc_cond_init( p_aout, &pa_thread->wait );
221
 
        pa_thread->b_wait = VLC_FALSE;
222
 
        vlc_mutex_init( p_aout, &pa_thread->lock_signal );
 
215
        pa_thread->b_wait = false;
 
216
        vlc_mutex_init( &pa_thread->lock_signal );
223
217
        vlc_cond_init( p_aout, &pa_thread->signal );
224
 
        pa_thread->b_signal = VLC_FALSE;
 
218
        pa_thread->b_signal = false;
225
219
 
226
220
        /* Create PORTAUDIOThread */
227
221
        if( vlc_thread_create( pa_thread, "aout", PORTAUDIOThread,
228
 
                               VLC_THREAD_PRIORITY_OUTPUT, VLC_FALSE ) )
 
222
                               VLC_THREAD_PRIORITY_OUTPUT, false ) )
229
223
        {
230
224
            msg_Err( p_aout, "cannot create PORTAUDIO thread" );
231
225
            return VLC_EGENERIC;
234
228
    else
235
229
    {
236
230
        pa_thread->p_aout = p_aout;
237
 
        pa_thread->b_wait = VLC_FALSE;
238
 
        pa_thread->b_signal = VLC_FALSE;
239
 
        pa_thread->b_error = VLC_FALSE;
 
231
        pa_thread->b_wait = false;
 
232
        pa_thread->b_signal = false;
 
233
        pa_thread->b_error = false;
240
234
    }
241
235
 
242
236
    /* Signal start of stream */
243
237
    vlc_mutex_lock( &pa_thread->lock_signal );
244
 
    pa_thread->b_signal = VLC_TRUE;
 
238
    pa_thread->b_signal = true;
245
239
    vlc_cond_signal( &pa_thread->signal );
246
240
    vlc_mutex_unlock( &pa_thread->lock_signal );
247
241
 
250
244
    if( !pa_thread->b_wait )
251
245
        vlc_cond_wait( &pa_thread->wait, &pa_thread->lock_wait );
252
246
    vlc_mutex_unlock( &pa_thread->lock_wait );
253
 
    pa_thread->b_wait = VLC_FALSE;
 
247
    pa_thread->b_wait = false;
254
248
 
255
249
    if( pa_thread->b_error )
256
250
    {
295
289
 
296
290
    /* Signal end of stream */
297
291
    vlc_mutex_lock( &pa_thread->lock_signal );
298
 
    pa_thread->b_signal = VLC_TRUE;
 
292
    pa_thread->b_signal = true;
299
293
    vlc_cond_signal( &pa_thread->signal );
300
294
    vlc_mutex_unlock( &pa_thread->lock_signal );
301
295
 
304
298
    if( !pa_thread->b_wait )
305
299
        vlc_cond_wait( &pa_thread->wait, &pa_thread->lock_wait );
306
300
    vlc_mutex_unlock( &pa_thread->lock_wait );
307
 
    pa_thread->b_wait = VLC_FALSE;
 
301
    pa_thread->b_wait = false;
308
302
 
309
303
#else
310
304
 
440
434
 
441
435
        var_AddCallback( p_aout, "audio-device", aout_ChannelsRestart, NULL );
442
436
 
443
 
        val.b_bool = VLC_TRUE;
 
437
        val.b_bool = true;
444
438
        var_Set( p_aout, "intf-change", val );
445
439
    }
446
440
 
516
510
    p_aout->output.p_sys->i_channels = i_channels;
517
511
 
518
512
    p_aout->output.p_sys->b_chan_reorder =
519
 
        aout_CheckChannelReorder( pi_channels_in, pi_channels_out,
 
513
        aout_CheckChannelReorder( NULL, pi_channels_out,
520
514
                                  i_channel_mask, i_channels,
521
515
                                  p_aout->output.p_sys->pi_chan_table );
522
516
 
573
567
 * PORTAUDIOThread: all interactions with libportaudio.a are handled
574
568
 * in this single thread.  Otherwise libportaudio.a is _not_ happy :-(
575
569
 *****************************************************************************/
576
 
static void PORTAUDIOThread( pa_thread_t *pa_thread )
 
570
static void* PORTAUDIOThread( vlc_object_t *p_this )
577
571
{
 
572
    pa_thread_t *pa_thread = (pa_thread_t*)p_this;
578
573
    aout_instance_t *p_aout;
579
574
    aout_sys_t *p_sys;
580
575
    int i_err;
581
576
 
582
 
    while( !pa_thread->b_die )
 
577
    while( vlc_object_alive (pa_thread) )
583
578
    {
584
579
        /* Wait for start of stream */
585
580
        vlc_mutex_lock( &pa_thread->lock_signal );
586
581
        if( !pa_thread->b_signal )
587
582
            vlc_cond_wait( &pa_thread->signal, &pa_thread->lock_signal );
588
583
        vlc_mutex_unlock( &pa_thread->lock_signal );
589
 
        pa_thread->b_signal = VLC_FALSE;
 
584
        pa_thread->b_signal = false;
590
585
 
591
586
        p_aout = pa_thread->p_aout;
592
587
        p_sys = p_aout->output.p_sys;
594
589
        if( PAOpenDevice( p_aout ) != VLC_SUCCESS )
595
590
        {
596
591
            msg_Err( p_aout, "cannot open portaudio device" );
597
 
            pa_thread->b_error = VLC_TRUE;
 
592
            pa_thread->b_error = true;
598
593
        }
599
594
 
600
595
        if( !pa_thread->b_error && PAOpenStream( p_aout ) != VLC_SUCCESS )
601
596
        {
602
597
            msg_Err( p_aout, "cannot open portaudio device" );
603
 
            pa_thread->b_error = VLC_TRUE;
 
598
            pa_thread->b_error = true;
604
599
 
605
600
            i_err = Pa_Terminate();
606
601
            if( i_err != paNoError )
612
607
 
613
608
        /* Tell the main thread that we are ready */
614
609
        vlc_mutex_lock( &pa_thread->lock_wait );
615
 
        pa_thread->b_wait = VLC_TRUE;
 
610
        pa_thread->b_wait = true;
616
611
        vlc_cond_signal( &pa_thread->wait );
617
612
        vlc_mutex_unlock( &pa_thread->lock_wait );
618
613
 
621
616
        if( !pa_thread->b_signal )
622
617
            vlc_cond_wait( &pa_thread->signal, &pa_thread->lock_signal );
623
618
        vlc_mutex_unlock( &pa_thread->lock_signal );
624
 
        pa_thread->b_signal = VLC_FALSE;
 
619
        pa_thread->b_signal = false;
625
620
 
626
621
        if( pa_thread->b_error ) continue;
627
622
 
646
641
 
647
642
        /* Tell the main thread that we are ready */
648
643
        vlc_mutex_lock( &pa_thread->lock_wait );
649
 
        pa_thread->b_wait = VLC_TRUE;
 
644
        pa_thread->b_wait = true;
650
645
        vlc_cond_signal( &pa_thread->wait );
651
646
        vlc_mutex_unlock( &pa_thread->lock_wait );
652
647
    }
 
648
    return NULL;
653
649
}
654
650
#endif