Clean up refcounts of COM objects.
parent
1c402df66f
commit
f388b982f6
|
@ -50,7 +50,7 @@ WASAPIAudioDevice::WASAPIAudioDevice(IAudioClient* client, IAudioEngine::AudioDi
|
||||||
, isRenderCaptureRunning_(false)
|
, isRenderCaptureRunning_(false)
|
||||||
, semaphore_(nullptr)
|
, semaphore_(nullptr)
|
||||||
{
|
{
|
||||||
// empty
|
client_->AddRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
WASAPIAudioDevice::~WASAPIAudioDevice()
|
WASAPIAudioDevice::~WASAPIAudioDevice()
|
||||||
|
@ -299,6 +299,18 @@ void WASAPIAudioDevice::start()
|
||||||
log_warn("Could not initialize COM (res = %d)", res);
|
log_warn("Could not initialize COM (res = %d)", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Increment refcounts of COM objects used by thread
|
||||||
|
// to avoid instability during stop/restart.
|
||||||
|
client_->AddRef();
|
||||||
|
if (renderClient_ != nullptr)
|
||||||
|
{
|
||||||
|
renderClient_->AddRef();
|
||||||
|
}
|
||||||
|
if (captureClient_ != nullptr)
|
||||||
|
{
|
||||||
|
captureClient_->AddRef();
|
||||||
|
}
|
||||||
|
|
||||||
// Temporarily raise priority of task
|
// Temporarily raise priority of task
|
||||||
setHelperRealTime();
|
setHelperRealTime();
|
||||||
|
|
||||||
|
@ -321,6 +333,18 @@ void WASAPIAudioDevice::start()
|
||||||
log_info("Exiting render/capture thread");
|
log_info("Exiting render/capture thread");
|
||||||
|
|
||||||
clearHelperRealTime();
|
clearHelperRealTime();
|
||||||
|
|
||||||
|
// Decrement refcounts prior to exit.
|
||||||
|
client_->Release();
|
||||||
|
if (renderClient_ != nullptr)
|
||||||
|
{
|
||||||
|
renderClient_->Release();
|
||||||
|
}
|
||||||
|
if (captureClient_ != nullptr)
|
||||||
|
{
|
||||||
|
captureClient_->Release();
|
||||||
|
}
|
||||||
|
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -303,6 +303,9 @@ std::shared_ptr<IAudioDevice> WASAPIAudioEngine::getAudioDevice(wxString deviceN
|
||||||
|
|
||||||
auto devPtr = new WASAPIAudioDevice(client, direction, sampleRate, numChannels);
|
auto devPtr = new WASAPIAudioDevice(client, direction, sampleRate, numChannels);
|
||||||
result = std::shared_ptr<IAudioDevice>(devPtr);
|
result = std::shared_ptr<IAudioDevice>(devPtr);
|
||||||
|
|
||||||
|
client->Release();
|
||||||
|
device->Release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
prom->set_value(result);
|
prom->set_value(result);
|
||||||
|
|
Loading…
Reference in New Issue