[vlc-devel] [PATCH] pulse: fix audio dropout when the input buffering takes too long

Jonathan Calmels jbjcalmels at gmail.com
Sun Feb 22 16:24:41 CET 2015


Under the pulse audio output, if the input buffering takes too much time (~2s), the audio drops out completely.
This is due to pa_stream_get_latency returning a zero latency when in fact it should return a negative one.
pa_stream_get_latency reports a negative latency only for recording streams.

This patch solves the problem but other suggestions are welcome.

---
 modules/audio_output/vlcpulse.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/modules/audio_output/vlcpulse.c b/modules/audio_output/vlcpulse.c
index feecfa7..aae417f 100644
--- a/modules/audio_output/vlcpulse.c
+++ b/modules/audio_output/vlcpulse.c
@@ -252,13 +252,20 @@ void vlc_pa_rttime_free (pa_threaded_mainloop *mainloop, pa_time_event *e)
  */
 mtime_t vlc_pa_get_latency(vlc_object_t *obj, pa_context *ctx, pa_stream *s)
 {
-    pa_usec_t latency;
-    int negative;
+    pa_usec_t t, c;
 
-    if (pa_stream_get_latency(s, &latency, &negative)) {
+    /* XXX pa_stream_get_latency does not report negative latency for playback stream.
+    Use pa_stream_get_time and pa_bytes_to_usec instead and return their difference. */
+
+    if (pa_stream_get_time(s, &t)) {
         if (pa_context_errno (ctx) != PA_ERR_NODATA)
             vlc_pa_error(obj, "unknown latency", ctx);
         return VLC_TS_INVALID;
     }
-    return negative ? -latency : +latency;
+
+    const pa_timing_info* ti = pa_stream_get_timing_info(s);
+    const pa_sample_spec* ss = pa_stream_get_sample_spec(s);
+    c = pa_bytes_to_usec((uint64_t) ti->write_index, ss);
+
+    return (mtime_t) (c >= t) ? (c - t) : -(t - c);
 }
-- 
2.3.0




More information about the vlc-devel mailing list