On Mon, 24 Jul 2023 09:58:09 GMT, Alexey Ivanov <aiva...@openjdk.org> wrote:
>> Renjith Kannath Pariyangad has updated the pull request incrementally with >> one additional commit since the last revision: >> >> Disabled OLE1 from CoInit > > src/java.desktop/windows/native/libjsound/PLATFORM_API_WinOS_DirectSound.cpp > line 482: > >> 480: DWORD WINAPI __stdcall DS_StartBufferHelper::ThreadProc(void *param) >> 481: { >> 482: ::CoInitializeEx(NULL, COINIT_MULTITHREADED | >> COINIT_DISABLE_OLE1DDE); > > You're changing the COM for this thread from `COINIT_APARTMENTTHREADED` to > `COINIT_MULTITHREADED`. > > Do DirectSound objects support multi-threading? I couldn't find anything > quickly. > > A Microsoft sample for [Creating the Device > Object](https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ee416365(v=vs.85)) > uses `CoInitializeEx(NULL, 0)`. > > The documentation for > [`CoInitializeEx`](https://learn.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-coinitializeex) > says, “You need to initialize the COM library on a thread before you call > any of the library functions…” > > This implies that any thread which creates DirectSound objects must > initialise COM first. I can't see it happening. Do I miss anything? @aivanov-jdk, Thank you for your time and reviews, `CoInitializeEx(NULL, 0)` also resolving this problem because as per document **The default is COINIT_MULTITHREADED**. In my debug session noticed `DirectSoundCaptureEnumerate` getting called ahead of thread call or ::CoInitialize and that was the root cause this failure. For resolving this found 3 ways and all works: 1 . Use COM multi-threading :- Simplest approach with respect to other solutions 2. Hold the call till CoInitialize : - Can end up in deadlock situation so that need to be taken care. 3. Do another CoInitialize before call :- not a good approach _This implies that any thread which creates DirectSound objects must initialise COM first. I can't see it happening. Do I miss anything?_ `DS_StartBufferHelper` class initializing COM in thread and all member functions checking initialization status before making any calls. So another solution may be restructure the code for accessing `isInitialized()` method from outer methods and proceed. (approach 2 in better way) ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/14898#discussion_r1273063731