@@ -186,7 +186,6 @@ bool AudioDeviceWindowsCore::CoreAudioIsSupported()
186
186
187
187
bool MMDeviceIsAvailable (false );
188
188
bool coreAudioIsSupported (false );
189
- bool coUninitializeIsRequired (true );
190
189
191
190
HRESULT hr (S_OK);
192
191
TCHAR buf[MAXERRORLENGTH];
@@ -199,8 +198,8 @@ bool AudioDeviceWindowsCore::CoreAudioIsSupported()
199
198
// wrapper also ensures that each call to CoInitializeEx is balanced
200
199
// by a corresponding call to CoUninitialize.
201
200
//
202
- ScopedCOMInitializer com_init (ScopedCOMInitializer::kMTA );
203
- if (!com_init .succeeded ()) {
201
+ ScopedCOMInitializer comInit (ScopedCOMInitializer::kMTA );
202
+ if (!comInit .succeeded ()) {
204
203
// Things will work even if an STA thread is calling this method but we
205
204
// want to ensure that MTA is used and therefore return false here.
206
205
return false ;
@@ -3114,10 +3113,9 @@ WebRtc_Word32 AudioDeviceWindowsCore::StopPlayout()
3114
3113
WEBRTC_TRACE (kTraceInfo , kTraceAudioDevice , _id,
3115
3114
" webrtc_core_audio_render_thread is now closed" );
3116
3115
3117
- // Ensure that the thread has released these interfaces properly
3118
- assert (NULL == _ptrClientOut);
3119
- assert (NULL == _ptrRenderClient);
3120
-
3116
+ SAFE_RELEASE (_ptrClientOut);
3117
+ SAFE_RELEASE (_ptrRenderClient);
3118
+
3121
3119
_playIsInitialized = false ;
3122
3120
_playing = false ;
3123
3121
@@ -3427,12 +3425,12 @@ DWORD AudioDeviceWindowsCore::DoRenderThread()
3427
3425
LARGE_INTEGER t2;
3428
3426
WebRtc_Word32 time (0 );
3429
3427
3430
- hr = CoInitializeEx ( NULL , COM_THREADING_MODEL);
3431
- if ( FAILED (hr))
3432
- {
3433
- _TraceCOMError (hr);
3434
- WEBRTC_TRACE ( kTraceWarning , kTraceAudioDevice , _id, " unable to initialize COM in render thread" );
3435
- return hr ;
3428
+ // Initialize COM as MTA in this thread.
3429
+ ScopedCOMInitializer comInit (ScopedCOMInitializer:: kMTA );
3430
+ if (!comInit. succeeded ()) {
3431
+ WEBRTC_TRACE ( kTraceError , kTraceAudioDevice , _id,
3432
+ " failed to initialize COM in render thread" );
3433
+ return - 1 ;
3436
3434
}
3437
3435
3438
3436
_SetThreadName (-1 , " webrtc_core_audio_render_thread" );
@@ -3665,10 +3663,6 @@ DWORD AudioDeviceWindowsCore::DoRenderThread()
3665
3663
WEBRTC_TRACE (kTraceInfo , kTraceAudioDevice , _id, " _Rendering thread is now terminated properly" );
3666
3664
}
3667
3665
3668
- SAFE_RELEASE (_ptrClientOut);
3669
- SAFE_RELEASE (_ptrRenderClient);
3670
-
3671
- CoUninitialize ();
3672
3666
return (DWORD)hr;
3673
3667
}
3674
3668
@@ -3677,15 +3671,6 @@ DWORD AudioDeviceWindowsCore::InitCaptureThreadPriority()
3677
3671
HRESULT hr = S_OK;
3678
3672
_hMmTask = NULL ;
3679
3673
3680
- hr = CoInitializeEx (NULL , COM_THREADING_MODEL);
3681
- if (FAILED (hr))
3682
- {
3683
- _TraceCOMError (hr);
3684
- WEBRTC_TRACE (kTraceWarning , kTraceAudioDevice , _id,
3685
- " unable to initialize COM in capture thread" );
3686
- return hr;
3687
- }
3688
-
3689
3674
_SetThreadName (-1 , " webrtc_core_audio_capture_thread" );
3690
3675
3691
3676
// Use Multimedia Class Scheduler Service (MMCSS) to boost the thread
@@ -3735,6 +3720,14 @@ DWORD AudioDeviceWindowsCore::DoCaptureThreadPollDMO()
3735
3720
assert (_mediaBuffer != NULL );
3736
3721
bool keepRecording = true ;
3737
3722
3723
+ // Initialize COM as MTA in this thread.
3724
+ ScopedCOMInitializer comInit (ScopedCOMInitializer::kMTA );
3725
+ if (!comInit.succeeded ()) {
3726
+ WEBRTC_TRACE (kTraceError , kTraceAudioDevice , _id,
3727
+ " failed to initialize COM in polling DMO thread" );
3728
+ return -1 ;
3729
+ }
3730
+
3738
3731
HRESULT hr = InitCaptureThreadPriority ();
3739
3732
if (FAILED (hr))
3740
3733
{
@@ -3861,7 +3854,6 @@ DWORD AudioDeviceWindowsCore::DoCaptureThreadPollDMO()
3861
3854
" Capturing thread is now terminated properly" );
3862
3855
}
3863
3856
3864
- CoUninitialize ();
3865
3857
return hr;
3866
3858
}
3867
3859
@@ -3891,6 +3883,14 @@ DWORD AudioDeviceWindowsCore::DoCaptureThread()
3891
3883
3892
3884
_readSamples = 0 ;
3893
3885
3886
+ // Initialize COM as MTA in this thread.
3887
+ ScopedCOMInitializer comInit (ScopedCOMInitializer::kMTA );
3888
+ if (!comInit.succeeded ()) {
3889
+ WEBRTC_TRACE (kTraceError , kTraceAudioDevice , _id,
3890
+ " failed to initialize COM in capture thread" );
3891
+ return -1 ;
3892
+ }
3893
+
3894
3894
hr = InitCaptureThreadPriority ();
3895
3895
if (FAILED (hr))
3896
3896
{
@@ -4171,7 +4171,6 @@ DWORD AudioDeviceWindowsCore::DoCaptureThread()
4171
4171
delete [] syncBuffer;
4172
4172
}
4173
4173
4174
- CoUninitialize ();
4175
4174
return (DWORD)hr;
4176
4175
}
4177
4176
0 commit comments