Commit 0c3e30d0 authored by Glen Gray's avatar Glen Gray Committed by Jean-Paul Saman

Pulse: Revert pulse audio rewrite

The rewrite of pulse audio between 2.0.4 and 2.0.5 triggers lipsync issues in
various use cases. Reverting this change for the 2.0.x branches resolves this
issue.
Signed-off-by: default avatarJean-Paul Saman <jpsaman@videolan.org>
parent 3913a4ce
......@@ -75,9 +75,8 @@ struct aout_sys_t
pa_time_event *trigger; /**< Deferred stream trigger */
pa_volume_t base_volume; /**< 0dB reference volume */
pa_cvolume cvolume; /**< actual sink input volume */
mtime_t first_pts; /**< Play time of buffer start */
mtime_t last_pts; /**< Play time of buffer write offset */
mtime_t paused; /**< Time when (last) paused */
mtime_t pts; /**< Play time of buffer write offset */
mtime_t desync; /**< Measured desynchronization */
unsigned rate; /**< Current stream sample rate */
};
......@@ -193,8 +192,7 @@ static void stream_reset_sync(pa_stream *s, audio_output_t *aout)
aout_sys_t *sys = aout->sys;
const unsigned rate = aout->format.i_rate;
sys->first_pts = VLC_TS_INVALID;
sys->last_pts = VLC_TS_INVALID;
sys->pts = VLC_TS_INVALID;
sys->desync = 0;
pa_operation *op = pa_stream_update_sample_rate(s, rate, NULL, NULL);
if (unlikely(op == NULL))
......@@ -203,7 +201,7 @@ static void stream_reset_sync(pa_stream *s, audio_output_t *aout)
sys->rate = rate;
}
static void stream_start_now(pa_stream *s, audio_output_t *aout)
static void stream_start(pa_stream *s, audio_output_t *aout)
{
aout_sys_t *sys = aout->sys;
pa_operation *op;
......@@ -244,7 +242,7 @@ static void stream_trigger_cb(pa_mainloop_api *api, pa_time_event *e,
msg_Dbg(aout, "starting deferred");
vlc_pa_rttime_free(sys->mainloop, sys->trigger);
sys->trigger = NULL;
stream_start_now(sys->stream, aout);
stream_start(sys->stream, aout);
(void) api; (void) e; (void) tv;
}
......@@ -254,12 +252,12 @@ static void stream_trigger_cb(pa_mainloop_api *api, pa_time_event *e,
* in order to minimize desync and resampling during early playback.
* @note PulseAudio lock required.
*/
static void stream_start(pa_stream *s, audio_output_t *aout)
static void stream_resync(audio_output_t *aout, pa_stream *s)
{
aout_sys_t *sys = aout->sys;
mtime_t delta;
assert (sys->first_pts != VLC_TS_INVALID);
assert (sys->pts != VLC_TS_INVALID);
if (sys->trigger != NULL) {
vlc_pa_rttime_free(sys->mainloop, sys->trigger);
......@@ -272,7 +270,7 @@ static void stream_start(pa_stream *s, audio_output_t *aout)
delta = 0; /* screwed */
}
delta = (sys->first_pts - mdate()) - delta;
delta = (sys->pts - mdate()) - delta;
if (delta > 0) {
msg_Dbg(aout, "deferring start (%"PRId64" us)", delta);
delta += pa_rtclock_now();
......@@ -280,7 +278,7 @@ static void stream_start(pa_stream *s, audio_output_t *aout)
stream_trigger_cb, aout);
} else {
msg_Warn(aout, "starting late (%"PRId64" us)", delta);
stream_start_now(s, aout);
stream_start(s, aout);
}
}
......@@ -292,13 +290,12 @@ static void stream_latency_cb(pa_stream *s, void *userdata)
if (sys->paused != VLC_TS_INVALID)
return; /* nothing to do while paused */
if (sys->last_pts == VLC_TS_INVALID) {
msg_Dbg(aout, "nothing to play");
assert (sys->first_pts == VLC_TS_INVALID);
if (sys->pts == VLC_TS_INVALID) {
msg_Dbg(aout, "missing latency from input");
return;
}
if (pa_stream_is_corked(s) > 0) {
stream_start(s, aout);
stream_resync(aout, s);
return;
}
......@@ -307,7 +304,7 @@ static void stream_latency_cb(pa_stream *s, void *userdata)
if (delta == VLC_TS_INVALID)
return;
delta = (sys->last_pts - mdate()) - delta;
delta = (sys->pts - mdate()) - delta;
change = delta - sys->desync;
sys->desync = delta;
//msg_Dbg(aout, "desync: %+"PRId64" us (variation: %+"PRId64" us)",
......@@ -473,7 +470,7 @@ static void stream_suspended_cb(pa_stream *s, void *userdata)
audio_output_t *aout = userdata;
msg_Dbg(aout, "suspended");
(void) s;
stream_reset_sync(s, aout);
}
static void stream_underflow_cb(pa_stream *s, void *userdata)
......@@ -574,12 +571,9 @@ static void Play(audio_output_t *aout, block_t *block)
pa_threaded_mainloop_lock(sys->mainloop);
}
if (sys->first_pts == VLC_TS_INVALID)
sys->first_pts = block->i_pts;
sys->last_pts = pts;
sys->pts = pts;
if (pa_stream_is_corked(s) > 0)
stream_start(s, aout);
stream_resync(aout, s);
#if 0 /* Fault injector to test underrun recovery */
static volatile unsigned u = 0;
......@@ -618,12 +612,8 @@ static void Pause(audio_output_t *aout, bool paused, mtime_t date)
date -= sys->paused;
msg_Dbg(aout, "resuming after %"PRId64" us", date);
sys->paused = VLC_TS_INVALID;
if (sys->last_pts != VLC_TS_INVALID) {
sys->first_pts += date;
sys->last_pts += date;
stream_start(s, aout);
}
sys->pts += date;
stream_resync(aout, s);
}
pa_threaded_mainloop_unlock(sys->mainloop);
......@@ -869,7 +859,7 @@ static int Open(vlc_object_t *obj)
* TODO? tlength could be adaptively increased to reduce wakeups. */
attr.tlength = pa_usec_to_bytes(AOUT_MIN_PREPARE_TIME, &ss);
attr.prebuf = 0; /* trigger manually */
attr.minreq = attr.tlength / 3;
attr.minreq = -1;
attr.fragsize = 0; /* not used for output */
/* Allocate structures */
......@@ -888,9 +878,8 @@ static int Open(vlc_object_t *obj)
sys->stream = NULL;
sys->context = ctx;
sys->trigger = NULL;
sys->first_pts = VLC_TS_INVALID;
sys->last_pts = VLC_TS_INVALID;
sys->paused = VLC_TS_INVALID;
sys->pts = VLC_TS_INVALID;
sys->desync = 0;
sys->rate = ss.rate;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment