Skip to content

Commit 7a42d8e

Browse files
authored
Fix SAPI4 WASAPI implementation (#17817)
Fixes #17775. Fixes #17776. Fixes #17764. Fixes #17826. Summary of the issue: Some SAPI4 voices cannot work with the WASAPI implementation, because of some differences in behavior between the WASAPI implementation and the SAPI4 built-in WinMM implementation. When rapidly navigating between objects, COM error -2147418107 is sometimes raised. Description of user facing changes The issue mentioned above should be fixed. Description of development approach Changed the handling of audio object statuses, so that it acts more similar to the WinMM implementation. All SAPI 4 COM-related code will now run in a dedicated thread, _ComThread, instead of in the main thread. COM calls are performed outside the window message loop, in order to prevent the occasionally-raised COMError -2147418107 (RPC_E_CANTCALLOUT_INEXTERNALCALL). Notification methods in IAudioDestNotifySink are called asynchronously in the same COM thread to prevent deadlocks. The "audio buffer size" is set to be of 2 seconds long, instead of having an infinite size, in order to behave more similar to the built-in WinMM implementation. Bookmarks are now in another queue, _bookmarkQueue, and the original queue _audioQueue only stores audio data chunks.
1 parent 17dcf3b commit 7a42d8e

2 files changed

Lines changed: 373 additions & 236 deletions

File tree

source/monkeyPatches/comtypesMonkeyPatches.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,12 @@ def newCpbDel(self):
139139
import garbageHandler
140140

141141
garbageHandler.notifyObjectDeletion(self)
142-
self._oldCpbDel()
142+
try:
143+
self._oldCpbDel()
144+
except Exception:
145+
from logHandler import log
146+
147+
log.error(f"Exception when deleting COM pointer {self!r}:", exc_info=True)
143148
self._deleted = True
144149

145150

0 commit comments

Comments
 (0)