[vlc-commits] PulseAudio: fix wild buffer expansion if the server dies and simplify

Rémi Denis-Courmont git at videolan.org
Thu Mar 31 22:26:22 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Mar 31 23:16:02 2011 +0300| [a51d0bd24ea4b5debff833ba89aa82a39724ce90] | committer: Rémi Denis-Courmont

PulseAudio: fix wild buffer expansion if the server dies and simplify

The write callback is not called if the stream dies. We need something
to dequeue and free audio frames.

Also, there is no need to check the start date. The audio output core
simply returns NULL if there is no data yet.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a51d0bd24ea4b5debff833ba89aa82a39724ce90
---

 modules/audio_output/pulse.c |   40 +++++++++++++++++-----------------------
 1 files changed, 17 insertions(+), 23 deletions(-)

diff --git a/modules/audio_output/pulse.c b/modules/audio_output/pulse.c
index 94f1c02..b319383 100644
--- a/modules/audio_output/pulse.c
+++ b/modules/audio_output/pulse.c
@@ -48,7 +48,6 @@ struct aout_sys_t
     struct pa_context *context; /**< PulseAudio connection context */
     struct pa_threaded_mainloop *mainloop; /**< PulseAudio event loop */
     size_t buffer_size;
-    mtime_t start_date;
 };
 
 /*****************************************************************************
@@ -209,7 +208,6 @@ static int Open ( vlc_object_t *p_this )
     if (unlikely(sys == NULL))
         return VLC_ENOMEM;
     sys->stream = NULL;
-    sys->start_date = VLC_TS_INVALID;
 
     sys->mainloop = pa_threaded_mainloop_new();
     if (unlikely(sys->mainloop == NULL)) {
@@ -317,12 +315,15 @@ fail:
 static void Play(aout_instance_t * aout)
 {
     struct aout_sys_t *sys = aout->output.p_sys;
+    pa_stream_state_t state;
 
-    if (likely(sys->start_date != VLC_TS_INVALID))
-        return;
     pa_threaded_mainloop_lock(sys->mainloop);
-    sys->start_date = aout_FifoFirstDate(aout, &aout->output.fifo);
+    state = pa_stream_get_state(sys->stream);
     pa_threaded_mainloop_unlock(sys->mainloop);
+
+    /* Keep purging the FIFO if the stream died */
+    if (state != PA_STREAM_READY)
+        block_Release(aout_FifoPop(aout, &aout->output.fifo));
 }
 
 /*****************************************************************************
@@ -409,28 +410,21 @@ static void stream_request_cb(pa_stream *s, size_t length, void *userdata)
     size_t buffer_size = sys->buffer_size;
 
     do {
-        block_t *block = NULL;
-
-        if (sys->start_date != VLC_TS_INVALID) {
-            pa_usec_t latency;
-            int negative;
-
-            if (pa_stream_get_latency(s, &latency, &negative) < 0){
-                if (pa_context_errno(sys->context) != PA_ERR_NODATA) {
-                    msg_Err(aout, "cannot determine latency: %s",
-                            pa_strerror(pa_context_errno(sys->context)));
-                }
-                latency = 0;
+        pa_usec_t latency;
+        int negative;
 
+        if (pa_stream_get_latency(s, &latency, &negative) < 0){
+            if (pa_context_errno(sys->context) != PA_ERR_NODATA) {
+                msg_Err(aout, "cannot determine latency: %s",
+                        pa_strerror(pa_context_errno(sys->context)));
             }
-
-            //msg_Dbg(p_aout, "latency=%"PRId64, latency);
-            mtime_t next_date = mdate() + latency;
-
-            if (sys->start_date < next_date + AOUT_PTS_TOLERANCE)
-                block = aout_OutputNextBuffer(aout, next_date, 0);
+            latency = 0;
         }
 
+        //msg_Dbg(p_aout, "latency=%"PRId64, latency);
+        mtime_t next_date = mdate() + latency;
+
+        block_t *block = aout_OutputNextBuffer(aout, next_date, 0);
         if (block != NULL)
             /* PA won't let us pass a reference to the buffer meta data... */
             block = block_Realloc (block, sizeof (block), block->i_buffer);



More information about the vlc-commits mailing list