Commit 227606a7 authored by David Redondo's avatar David Redondo 🏎
Browse files

Handle changing target more cleanly

Disconnect so we get no more callbacks and fix potential assert when
changing targets when both are not nullptr.
parent 7e6e8e97
...@@ -38,10 +38,7 @@ VolumeMonitor::VolumeMonitor(QObject* parent) ...@@ -38,10 +38,7 @@ VolumeMonitor::VolumeMonitor(QObject* parent)
VolumeMonitor::~VolumeMonitor() VolumeMonitor::~VolumeMonitor()
{ {
if (m_stream) { setTarget(nullptr);
pa_stream_unref(m_stream);
}
Context::instance()->unref(); Context::instance()->unref();
} }
...@@ -66,14 +63,21 @@ void QPulseAudio::VolumeMonitor::setTarget(QPulseAudio::VolumeObject* target) ...@@ -66,14 +63,21 @@ void QPulseAudio::VolumeMonitor::setTarget(QPulseAudio::VolumeObject* target)
if (target == m_target) { if (target == m_target) {
return; return;
} }
m_target = target;
if (target) { if (m_stream) {
createStream(); pa_stream_disconnect(m_stream);
} else if (m_stream) {
pa_stream_unref(m_stream); pa_stream_unref(m_stream);
pa_stream_set_read_callback(m_stream, nullptr, nullptr);
pa_stream_set_suspended_callback(m_stream, nullptr, nullptr);
m_stream = nullptr; m_stream = nullptr;
Q_EMIT availableChanged(); Q_EMIT availableChanged();
} }
m_target = target;
if (target) {
createStream();
}
} }
void VolumeMonitor::createStream() void VolumeMonitor::createStream()
......
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