]> git.sesse.net Git - vlc/blobdiff - modules/audio_output/pulse.c
DirectX/Waveout: new windows_audio_common.h file
[vlc] / modules / audio_output / pulse.c
index 19e4b75fab9fc0aa96f809ac47ff6f5383663219..a2ccfbc2a150a82da4f4daf2ec1bd61ef57d4bbb 100644 (file)
@@ -31,6 +31,7 @@
 #include <vlc_plugin.h>
 
 #include <vlc_aout.h>
+#include <vlc_cpu.h>
 
 #include <pulse/pulseaudio.h>
 
@@ -97,7 +98,7 @@ static void uninit(aout_instance_t *p_aout);
 vlc_module_begin ()
     set_shortname( "Pulse Audio" )
     set_description( N_("Pulseaudio audio output") )
-    set_capability( "audio output", 40 )
+    set_capability( "audio output", 160 )
     set_category( CAT_AUDIO )
     set_subcategory( SUBCAT_AUDIO_AOUT )
     add_shortcut( "pulseaudio" )
@@ -165,27 +166,34 @@ static int Open ( vlc_object_t *p_this )
     }
 
     /* Add a quick command line info message */
-    msg_Info(p_aout, "No. of Audio Channels: %d", ss.channels);
+    msg_Dbg(p_aout, "%d audio channels", ss.channels);
 
     ss.rate = p_aout->output.output.i_rate;
-    ss.format = PA_SAMPLE_FLOAT32NE;
-    p_aout->output.output.i_format = VLC_FOURCC('f','l','3','2');
+    if (HAVE_FPU)
+    {
+        ss.format = PA_SAMPLE_FLOAT32NE;
+        p_aout->output.output.i_format = VLC_CODEC_FL32;
+    }
+    else
+    {
+        ss.format = PA_SAMPLE_S16NE;
+        p_aout->output.output.i_format = VLC_CODEC_S16N;
+    }
 
     if (!pa_sample_spec_valid(&ss)) {
         msg_Err(p_aout,"Invalid sample spec");
         goto fail;
     }
 
-    a.maxlength = pa_bytes_per_second(&ss)/4/pa_frame_size(&ss);
-    a.tlength = a.maxlength*9/10;
-    a.prebuf = a.tlength/2;
-    a.minreq = a.tlength/10;
-
-    a.maxlength *= pa_frame_size(&ss);
-    a.tlength *= pa_frame_size(&ss);
-    a.prebuf *= pa_frame_size(&ss);
-    a.minreq *= pa_frame_size(&ss);
+    /* Reduce overall latency to 200mS to reduce audible clicks
+     * Also pulse minreq and internal buffers are now 20mS which reduces resampling
+     */
+    a.tlength = pa_bytes_per_second(&ss)/5;
+    a.maxlength = a.tlength * 2;
+    a.prebuf = a.tlength / 2;
+    a.minreq = a.tlength / 10;
 
+    /* Buffer size is 20mS */
     p_sys->buffer_size = a.minreq;
 
     /* Initialise the speaker map setup above */
@@ -225,7 +233,7 @@ static int Open ( vlc_object_t *p_this )
     pa_threaded_mainloop_wait(p_sys->mainloop);
 
     if (pa_context_get_state(p_sys->context) != PA_CONTEXT_READY) {
-        msg_Err(p_aout, "Failed to connect to server: %s", pa_strerror(pa_context_errno(p_sys->context)));
+        msg_Dbg(p_aout, "Failed to connect to server: %s", pa_strerror(pa_context_errno(p_sys->context)));
         goto unlock_and_fail;
     }
 
@@ -240,7 +248,7 @@ static int Open ( vlc_object_t *p_this )
     pa_stream_set_write_callback(p_sys->stream, stream_request_cb, p_aout);
     pa_stream_set_latency_update_callback(p_sys->stream, stream_latency_update_cb, p_aout);
 
-    if (pa_stream_connect_playback(p_sys->stream, NULL, &a, PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE, NULL, NULL) < 0) {
+    if (pa_stream_connect_playback(p_sys->stream, NULL, &a, PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE|PA_STREAM_ADJUST_LATENCY, NULL, NULL) < 0) {
         msg_Err(p_aout, "Failed to connect stream: %s", pa_strerror(pa_context_errno(p_sys->context)));
         goto unlock_and_fail;
     }
@@ -289,7 +297,7 @@ unlock_and_fail:
     if (p_sys->mainloop)
         pa_threaded_mainloop_unlock(p_sys->mainloop);
 fail:
-    msg_Err(p_aout, "Pulse initialization failed");
+    msg_Dbg(p_aout, "Pulse initialization failed");
     uninit(p_aout);
     return VLC_EGENERIC;
 }
@@ -425,6 +433,7 @@ static void stream_state_cb(pa_stream *s, void * userdata) {
 }
 
 static void stream_request_cb(pa_stream *s, size_t length, void *userdata) {
+    VLC_UNUSED( s );
     aout_instance_t *p_aout = (aout_instance_t *)userdata;
     struct aout_sys_t * p_sys = (struct aout_sys_t *) p_aout->output.p_sys;
     mtime_t next_date;
@@ -448,25 +457,20 @@ static void stream_request_cb(pa_stream *s, size_t length, void *userdata) {
                 latency = 0;
 
             }
+
             PULSE_DEBUG( "Pulse stream request latency=%"PRId64"", latency);
             next_date = mdate() + latency;
 
-
             if(p_sys->start_date < next_date + AOUT_PTS_TOLERANCE ){
-    /*
-                  vlc_mutex_lock( &p_aout->output_fifo_lock );
-                p_buffer = aout_FifoPop( p_aout, &p_aout->output.fifo );
-                vlc_mutex_unlock( &p_aout->output_fifo_lock );
-    */
                 p_buffer = aout_OutputNextBuffer( p_aout, next_date, 0);
             }
         }
 
         if ( p_buffer != NULL )
         {
-            PULSE_DEBUG( "Pulse stream request write buffer %d", p_buffer->i_nb_bytes);
-            pa_stream_write(p_sys->stream, p_buffer->p_buffer, p_buffer->i_nb_bytes, NULL, 0, PA_SEEK_RELATIVE);
-            length -= p_buffer->i_nb_bytes;
+            PULSE_DEBUG( "Pulse stream request write buffer %d", p_buffer->i_buffer);
+            pa_stream_write(p_sys->stream, p_buffer->p_buffer, p_buffer->i_buffer, NULL, 0, PA_SEEK_RELATIVE);
+            length -= p_buffer->i_buffer;
             aout_BufferFree( p_buffer );
         }
         else
@@ -483,6 +487,7 @@ static void stream_request_cb(pa_stream *s, size_t length, void *userdata) {
 }
 
 static void stream_latency_update_cb(pa_stream *s, void *userdata) {
+    VLC_UNUSED( s );
     aout_instance_t *p_aout = (aout_instance_t *)userdata;
     struct aout_sys_t * p_sys = (struct aout_sys_t *) p_aout->output.p_sys;
 
@@ -495,6 +500,7 @@ static void stream_latency_update_cb(pa_stream *s, void *userdata) {
 
 static void success_cb(pa_stream *s, int sucess, void *userdata)
 {
+    VLC_UNUSED( s );
     aout_instance_t *p_aout = (aout_instance_t *)userdata;
     struct aout_sys_t * p_sys = (struct aout_sys_t *) p_aout->output.p_sys;