~ubuntu-branches/ubuntu/natty/vlc/natty

« back to all changes in this revision

Viewing changes to modules/audio_output/pulse.c

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2010-06-25 01:09:16 UTC
  • mfrom: (1.1.30 upstream)
  • Revision ID: james.westby@ubuntu.com-20100625010916-asxhep2mutg6g6pd
Tags: 1.1.0-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - build and install the libx264 plugin
  - add Xb-Npp header to vlc package
  - Add apport hook to include more vlc dependencies in bug reports
* Drop xulrunner patches.
* Drop 502_xulrunner_191.diff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include <vlc_plugin.h>
32
32
 
33
33
#include <vlc_aout.h>
 
34
#include <vlc_cpu.h>
34
35
 
35
36
#include <pulse/pulseaudio.h>
36
 
#ifdef HAVE_X11_XLIB_H
37
 
# include <X11/Xlib.h>
 
37
#ifdef X_DISPLAY_MISSING
 
38
# error Xlib required due to PulseAudio bug 799!
38
39
#endif
 
40
#include <vlc_xlib.h>
39
41
 
40
42
#include <assert.h>
41
43
 
98
100
 * Module descriptor
99
101
 *****************************************************************************/
100
102
vlc_module_begin ()
101
 
    set_shortname( "Pulse Audio" )
 
103
    set_shortname( "PulseAudio" )
102
104
    set_description( N_("Pulseaudio audio output") )
103
105
    set_capability( "audio output", 160 )
104
106
    set_category( CAT_AUDIO )
106
108
    add_shortcut( "pulseaudio" )
107
109
    add_shortcut( "pa" )
108
110
    set_callbacks( Open, Close )
109
 
    linked_with_a_crap_library_which_uses_atexit()
110
111
vlc_module_end ()
111
112
 
112
113
/*****************************************************************************
121
122
    struct pa_buffer_attr a;
122
123
    struct pa_channel_map map;
123
124
 
124
 
#ifdef HAVE_X11_XLIB_H
125
 
    if( !XInitThreads() )
 
125
    if( !vlc_xlib_init( p_this ) )
126
126
        return VLC_EGENERIC;
127
 
#endif
 
127
 
128
128
    /* Allocate structures */
129
129
    p_aout->output.p_sys = p_sys = calloc( 1, sizeof( aout_sys_t ) );
130
130
    if( p_sys == NULL )
172
172
    }
173
173
 
174
174
    /* Add a quick command line info message */
175
 
    msg_Info(p_aout, "No. of Audio Channels: %d", ss.channels);
 
175
    msg_Dbg(p_aout, "%d audio channels", ss.channels);
176
176
 
177
177
    ss.rate = p_aout->output.output.i_rate;
178
 
    ss.format = PA_SAMPLE_FLOAT32NE;
179
 
    p_aout->output.output.i_format = VLC_FOURCC('f','l','3','2');
 
178
    if (HAVE_FPU)
 
179
    {
 
180
        ss.format = PA_SAMPLE_FLOAT32NE;
 
181
        p_aout->output.output.i_format = VLC_CODEC_FL32;
 
182
    }
 
183
    else
 
184
    {
 
185
        ss.format = PA_SAMPLE_S16NE;
 
186
        p_aout->output.output.i_format = VLC_CODEC_S16N;
 
187
    }
180
188
 
181
189
    if (!pa_sample_spec_valid(&ss)) {
182
190
        msg_Err(p_aout,"Invalid sample spec");
336
344
    msg_Dbg(p_aout, "Pulse Close");
337
345
 
338
346
    if(p_sys->stream){
339
 
        pa_operation *o;
340
347
        pa_threaded_mainloop_lock(p_sys->mainloop);
341
348
        pa_stream_set_write_callback(p_sys->stream, NULL, NULL);
342
349
 
343
 
        if((o = pa_stream_drain(p_sys->stream, success_cb, p_aout))){
 
350
/* I didn't find any explanation why we need to do pa_stream_drain on close
 
351
 * as we don't really care if we lose 20ms buffer in this point anyway?
 
352
 * And disabling this speeds up closing pulseaudio quite a lot (atleast for me).
 
353
 */
 
354
#if 0
 
355
        pa_operation *o = pa_stream_drain(p_sys->stream, success_cb, p_aout);
 
356
        if(o){
344
357
            while (pa_operation_get_state(o) != PA_OPERATION_DONE) {
345
358
                CHECK_DEAD_GOTO(fail);
346
359
                pa_threaded_mainloop_wait(p_sys->mainloop);
350
363
 
351
364
            pa_operation_unref(o);
352
365
        }
353
 
 
 
366
#endif
354
367
        pa_threaded_mainloop_unlock(p_sys->mainloop);
355
368
    }
356
369
    uninit(p_aout);
431
444
}
432
445
 
433
446
static void stream_request_cb(pa_stream *s, size_t length, void *userdata) {
 
447
    VLC_UNUSED( s );
434
448
    aout_instance_t *p_aout = (aout_instance_t *)userdata;
435
449
    struct aout_sys_t * p_sys = (struct aout_sys_t *) p_aout->output.p_sys;
436
450
    mtime_t next_date;
465
479
 
466
480
        if ( p_buffer != NULL )
467
481
        {
468
 
            PULSE_DEBUG( "Pulse stream request write buffer %d", p_buffer->i_nb_bytes);
469
 
            pa_stream_write(p_sys->stream, p_buffer->p_buffer, p_buffer->i_nb_bytes, NULL, 0, PA_SEEK_RELATIVE);
470
 
            length -= p_buffer->i_nb_bytes;
 
482
            PULSE_DEBUG( "Pulse stream request write buffer %d", p_buffer->i_buffer);
 
483
            pa_stream_write(p_sys->stream, p_buffer->p_buffer, p_buffer->i_buffer, NULL, 0, PA_SEEK_RELATIVE);
 
484
            length -= p_buffer->i_buffer;
471
485
            aout_BufferFree( p_buffer );
472
486
        }
473
487
        else
484
498
}
485
499
 
486
500
static void stream_latency_update_cb(pa_stream *s, void *userdata) {
 
501
    VLC_UNUSED( s );
487
502
    aout_instance_t *p_aout = (aout_instance_t *)userdata;
488
503
    struct aout_sys_t * p_sys = (struct aout_sys_t *) p_aout->output.p_sys;
489
504
 
496
511
 
497
512
static void success_cb(pa_stream *s, int sucess, void *userdata)
498
513
{
 
514
    VLC_UNUSED( s );
499
515
    aout_instance_t *p_aout = (aout_instance_t *)userdata;
500
516
    struct aout_sys_t * p_sys = (struct aout_sys_t *) p_aout->output.p_sys;
501
517