Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8267819: CoInitialize/CoUninitialize should be called on same thread #40

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -51,6 +51,12 @@ void ReleaseNotificator(void *pObject) {
bool GSTDirectSoundNotify::Init(GSTDSNotfierCallback pCallback, void *pData) {
m_pCallback = pCallback;
m_pData = pData;
bool bCallCoUninitialize = true;
bool bResult = false;

if (FAILED(CoInitialize(NULL))) {
bCallCoUninitialize = false;
}

HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator),
NULL,
@@ -59,11 +65,15 @@ bool GSTDirectSoundNotify::Init(GSTDSNotfierCallback pCallback, void *pData) {
if (SUCCEEDED(hr)) {
hr = m_pEnumerator->RegisterEndpointNotificationCallback(this);
if (SUCCEEDED(hr)) {
return true;
bResult = true;
}
}

return false;
if (bCallCoUninitialize) {
CoUninitialize();
}

return bResult;
}

void GSTDirectSoundNotify::Dispose() {
@@ -78,13 +88,6 @@ GSTDirectSoundNotify::GSTDirectSoundNotify() {
m_pEnumerator = NULL;
m_pCallback = NULL;
m_pData = NULL;
m_hrCoInit = CoInitialize(NULL);
}

GSTDirectSoundNotify::~GSTDirectSoundNotify() {
if (SUCCEEDED(m_hrCoInit)) {
CoUninitialize();
}
}

HRESULT GSTDirectSoundNotify::OnDefaultDeviceChanged(EDataFlow flow,
@@ -112,7 +115,7 @@ HRESULT GSTDirectSoundNotify::QueryInterface(REFIID iid, void** ppUnk) {

AddRef();

return S_OK;
return S_OK;
}

ULONG GSTDirectSoundNotify::AddRef() {
@@ -46,7 +46,6 @@ class GSTDirectSoundNotify : IMMNotificationClient
{
public:
GSTDirectSoundNotify();
~GSTDirectSoundNotify();

bool Init(GSTDSNotfierCallback pCallback, void *pData);
void Dispose();
@@ -67,7 +66,6 @@ class GSTDirectSoundNotify : IMMNotificationClient
IMMDeviceEnumerator* m_pEnumerator;
GSTDSNotfierCallback m_pCallback;
void *m_pData;
HRESULT m_hrCoInit;

// IUnknown
IFACEMETHODIMP QueryInterface(const IID& iid, void** ppUnk);