Commit 21e8adbe authored by Thomas Guillem's avatar Thomas Guillem
Browse files

pulse: hack: wait for drain completion

parent 508452ae
......@@ -75,6 +75,8 @@ struct aout_sys_t
char *sink_force; /**< Forced sink name (stream must be NULL) */
struct sink *sinks; /**< Locally-cached list of sinks */
bool underflow;
};
static void VolumeReport(audio_output_t *aout)
......@@ -352,8 +354,11 @@ static void stream_suspended_cb(pa_stream *s, void *userdata)
static void stream_underflow_cb(pa_stream *s, void *userdata)
{
audio_output_t *aout = userdata;
aout_sys_t *sys = aout->sys;
msg_Dbg(aout, "underflow");
sys->underflow = true;
pa_threaded_mainloop_signal(aout->sys->mainloop, 0);
(void) s;
}
......@@ -503,6 +508,8 @@ static void Play(audio_output_t *aout, block_t *block)
* will take place, and sooner or later a deadlock. */
pa_threaded_mainloop_lock(sys->mainloop);
sys->underflow = false;
if (sys->first_pts == VLC_TS_INVALID)
sys->first_pts = block->i_pts;
......@@ -548,6 +555,12 @@ static void Pause(audio_output_t *aout, bool paused, mtime_t date)
(void) date;
}
static void stream_drain_cb(pa_stream *s, int success, void *userdata)
{
(void) s; (void) success;
pa_threaded_mainloop_signal(userdata, 0);
}
/**
* Flush or drain the playback stream
*/
......@@ -558,14 +571,23 @@ static void Flush(audio_output_t *aout, bool wait)
pa_operation *op;
pa_threaded_mainloop_lock(sys->mainloop);
if (wait)
op = pa_stream_drain(s, NULL, NULL);
/* TODO: wait for drain completion*/
{
op = pa_stream_drain(s, stream_drain_cb, sys->mainloop);
if (op != NULL)
{
while (pa_operation_get_state(op) == PA_OPERATION_RUNNING
&& !sys->underflow)
pa_threaded_mainloop_wait(sys->mainloop);
pa_operation_unref(op);
}
}
else
{
op = pa_stream_flush(s, NULL, NULL);
if (op != NULL)
pa_operation_unref(op);
if (op != NULL)
pa_operation_unref(op);
}
sys->first_pts = VLC_TS_INVALID;
stream_stop(s, aout);
......
Supports Markdown
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