Commit 41eac259 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

PulseAudio: flush or drain at end, not both

Draining after flushing makes no sense. By the way, we should probably
wait for draining to complete. But there seems to be a race condition
in libpulse and this causes a deadlock.
parent fe231329
...@@ -188,6 +188,16 @@ static int stream_wait(pa_stream *stream) ...@@ -188,6 +188,16 @@ static int stream_wait(pa_stream *stream)
return 0; return 0;
} }
#ifdef LIBPULSE_GETS_A_CLUE
static void stream_success_cb(pa_stream *s, int success, void *userdata)
{
vlc_pa_signal(0);
(void) s; (void) success; (void) userdata;
}
#else
# define stream_success_cb NULL
#endif
/* Memory free callback. The block_t address is in front of the data. */ /* Memory free callback. The block_t address is in front of the data. */
static void data_free(void *data) static void data_free(void *data)
{ {
...@@ -591,12 +601,20 @@ static void Close (vlc_object_t *obj) ...@@ -591,12 +601,20 @@ static void Close (vlc_object_t *obj)
if (s != NULL) { if (s != NULL) {
pa_operation *op; pa_operation *op;
op = pa_stream_flush(s, NULL, NULL); if (pa_stream_is_corked(s) > 0)
if (op != NULL) /* Stream paused: discard all buffers */
pa_operation_unref(op); op = pa_stream_flush(s, stream_success_cb, NULL);
op = pa_stream_drain(s, NULL, NULL); else
if (op != NULL) /* Stream playing: wait until buffers are played */
op = pa_stream_drain(s, stream_success_cb, NULL);
if (likely(op != NULL)) {
#ifdef LIBPULSE_GETS_A_CLUE
while (pa_operation_get_state(op) == PA_OPERATION_RUNNING)
vlc_pa_wait();
#endif
pa_operation_unref(op); pa_operation_unref(op);
}
pa_stream_disconnect(s); pa_stream_disconnect(s);
pa_stream_unref(s); pa_stream_unref(s);
} }
......
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