Skip to content

Commit 47700d8

Browse files
author
Alexander Matveev
committed
8267819: CoInitialize/CoUninitialize should be called on same thread
Reviewed-by: kcr, arapte
1 parent 526f990 commit 47700d8

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

modules/javafx.media/src/main/native/gstreamer/gstreamer-lite/gst-plugins-good/sys/directsound/gstdirectsoundnotify.cpp

+13-10
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ void ReleaseNotificator(void *pObject) {
5151
bool GSTDirectSoundNotify::Init(GSTDSNotfierCallback pCallback, void *pData) {
5252
m_pCallback = pCallback;
5353
m_pData = pData;
54+
bool bCallCoUninitialize = true;
55+
bool bResult = false;
56+
57+
if (FAILED(CoInitialize(NULL))) {
58+
bCallCoUninitialize = false;
59+
}
5460

5561
HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator),
5662
NULL,
@@ -59,11 +65,15 @@ bool GSTDirectSoundNotify::Init(GSTDSNotfierCallback pCallback, void *pData) {
5965
if (SUCCEEDED(hr)) {
6066
hr = m_pEnumerator->RegisterEndpointNotificationCallback(this);
6167
if (SUCCEEDED(hr)) {
62-
return true;
68+
bResult = true;
6369
}
6470
}
6571

66-
return false;
72+
if (bCallCoUninitialize) {
73+
CoUninitialize();
74+
}
75+
76+
return bResult;
6777
}
6878

6979
void GSTDirectSoundNotify::Dispose() {
@@ -78,13 +88,6 @@ GSTDirectSoundNotify::GSTDirectSoundNotify() {
7888
m_pEnumerator = NULL;
7989
m_pCallback = NULL;
8090
m_pData = NULL;
81-
m_hrCoInit = CoInitialize(NULL);
82-
}
83-
84-
GSTDirectSoundNotify::~GSTDirectSoundNotify() {
85-
if (SUCCEEDED(m_hrCoInit)) {
86-
CoUninitialize();
87-
}
8891
}
8992

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

113116
AddRef();
114117

115-
return S_OK;
118+
return S_OK;
116119
}
117120

118121
ULONG GSTDirectSoundNotify::AddRef() {

modules/javafx.media/src/main/native/gstreamer/gstreamer-lite/gst-plugins-good/sys/directsound/gstdirectsoundnotify.h

-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class GSTDirectSoundNotify : IMMNotificationClient
4646
{
4747
public:
4848
GSTDirectSoundNotify();
49-
~GSTDirectSoundNotify();
5049

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

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

0 commit comments

Comments
 (0)