Skip to content
Snippets Groups Projects
Commit 6160a51e authored by pierre-luc's avatar pierre-luc
Browse files

[#1805] Remove the old flawed signal mechanism which was failing in

some cases. The PulseLayer is now closed after the playback stream was
drained. This step is however optional and might be removed if wanted.
This step shouldn't be noticeable as the stream is probably already empty
when the draining is performed.
parent f7ac1932
Branches
Tags
No related merge requests found
...@@ -56,11 +56,43 @@ AudioStream::connectStream() ...@@ -56,11 +56,43 @@ AudioStream::connectStream()
return true; return true;
} }
static void success_cb(pa_stream *s, int success, void *userdata) {
assert(s);
pa_threaded_mainloop * mainloop = (pa_threaded_mainloop *) userdata;
pa_threaded_mainloop_signal(mainloop, 0);
}
bool
AudioStream::drainStream(void) {
if (_audiostream) {
_debug("Draining stream\n");
pa_operation * operation;
pa_threaded_mainloop_lock(_mainloop);
if ((operation = pa_stream_drain(_audiostream, success_cb, _mainloop))) {
while (pa_operation_get_state(operation) != PA_OPERATION_DONE) {
if (!_context || pa_context_get_state(_context) != PA_CONTEXT_READY || !_audiostream || pa_stream_get_state(_audiostream) != PA_STREAM_READY) {
_debug("Connection died: %s\n", _context ? pa_strerror(pa_context_errno(_context)) : "NULL");
pa_operation_unref(operation);
break;
} else {
pa_threaded_mainloop_wait(_mainloop);
}
}
}
pa_threaded_mainloop_unlock(_mainloop);
}
}
bool bool
AudioStream::disconnectStream (void) AudioStream::disconnectStream (void)
{ {
ost::MutexLock guard (_mutex);
_debug ("Destroy audio streams\n"); _debug ("Destroy audio streams\n");
pa_threaded_mainloop_lock(_mainloop); pa_threaded_mainloop_lock(_mainloop);
...@@ -95,7 +127,6 @@ AudioStream::stream_state_callback (pa_stream* s, void* user_data) ...@@ -95,7 +127,6 @@ AudioStream::stream_state_callback (pa_stream* s, void* user_data)
case PA_STREAM_TERMINATED: case PA_STREAM_TERMINATED:
_debug ("Stream is terminating...\n"); _debug ("Stream is terminating...\n");
pa_threaded_mainloop_signal(m, 0);
break; break;
case PA_STREAM_READY: case PA_STREAM_READY:
......
...@@ -83,6 +83,11 @@ class AudioStream { ...@@ -83,6 +83,11 @@ class AudioStream {
*/ */
bool connectStream(); bool connectStream();
/**
* Drain the given stream.
*/
bool drainStream(void);
/** /**
* Disconnect the pulseaudio stream * Disconnect the pulseaudio stream
*/ */
......
...@@ -52,18 +52,29 @@ PulseLayer::closeLayer (void) ...@@ -52,18 +52,29 @@ PulseLayer::closeLayer (void)
{ {
_debug ("PulseLayer::closeLayer :: Destroy pulselayer\n"); _debug ("PulseLayer::closeLayer :: Destroy pulselayer\n");
// Commenting the line below will make the
// PulseLayer to close immediately, not
// waiting for the playback buffer to be
// emptied. It should not hurt.
playback->drainStream();
if(m) {
pa_threaded_mainloop_stop(m);
}
playback->disconnectStream(); playback->disconnectStream();
record->disconnectStream(); record->disconnectStream();
pa_threaded_mainloop_lock (m); if(context) {
pa_threaded_mainloop_wait(m);
if(m) {
pa_context_disconnect (context); pa_context_disconnect (context);
pa_context_unref (context); pa_context_unref (context);
context = NULL;
} }
pa_threaded_mainloop_unlock (m);
if(m) {
pa_threaded_mainloop_free (m); pa_threaded_mainloop_free (m);
m = NULL;
}
return true; return true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment