Commit d37f4061 authored by Piyush Aggarwal's avatar Piyush Aggarwal 🎮
Browse files

systemvolumeplugin_win: fix a desktop memory leak that occurs when sink list is open on Android app

parent 8cd17dbe
Pipeline #66773 passed with stage
in 7 minutes and 37 seconds
......@@ -413,19 +413,56 @@ bool SystemvolumePlugin::receivePacket(const NetworkPacket &np)
if (sinkList.contains(name))
{
// unregister ControlChangeNotify before doing any changes to a sink
HRESULT unregisterSuccess = E_POINTER;
auto sinkListIterator = this->sinkList.find(name);
auto &sink = sinkListIterator.value();
if (!(sinkListIterator == this->sinkList.end())) {
unregisterSuccess = sink.first->UnregisterControlChangeNotify(sink.second);
}
if (np.has(QStringLiteral("volume")))
{
sinkList[name].first->SetMasterVolumeLevelScalar((float)np.get<int>(QStringLiteral("volume")) / 100, NULL);
float currentVolume;
sink.first->GetMasterVolumeLevelScalar(&currentVolume);
float requestedVolume = (float)np.get<int>(QStringLiteral("volume"), 100) / 100;
if (currentVolume != requestedVolume) {
sinkList[name].first->SetMasterVolumeLevelScalar(requestedVolume, NULL);
}
}
if (np.has(QStringLiteral("muted")))
{
sinkList[name].first->SetMute(np.get<bool>(QStringLiteral("muted")), NULL);
BOOL currentMuteStatus;
sink.first->GetMute(&currentMuteStatus);
BOOL requestedMuteStatus = np.get<bool>(QStringLiteral("muted"), false);
if(currentMuteStatus != requestedMuteStatus) {
sinkList[name].first->SetMute(requestedMuteStatus, NULL);
}
}
if (np.has(QStringLiteral("enabled")))
{
// get the current default device ID
IMMDevice *defaultDevice = nullptr;
deviceEnumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, &defaultDevice);
LPWSTR defaultId = NULL;
defaultDevice->GetId(&defaultId);
defaultDevice->Release();
// get current sink's device ID
QString qDefaultId = QString::fromWCharArray(defaultId);
QString currentDeviceId = idToNameMap.key(name);
if ((bool)qDefaultId.compare(currentDeviceId)) {
setDefaultAudioPlaybackDevice(name, np.get<bool>(QStringLiteral("enabled")));
}
}
// re-register ControlChangeNotify in case we unregistered it
if (unregisterSuccess == S_OK) {
sink.first->RegisterControlChangeNotify(sink.second);
}
}
}
return true;
}
......
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