Skip to content

Commit 544ccb1

Browse files
authored
WasapiWavePlayer.feed: Log exceptions but don't raise them. (#16738)
Fixes #16722. Summary of the issue: When a client disconnects from a Remote Desktop session without exiting NVDA on the server, WASAPI can throw ERROR_TOO_MANY_FILES, which is not a WASAPI error code and thus not expected by the C++ code. E_NOTFOUND is also possible, probably thrown by IMMDeviceEnumerator::GetDefaultAudioEndpoint. WasapiWavePlayer.feed raises an exception, which breaks the oneCore driver because it isn't expecting exceptions. Speech is broken henceforth. Description of user facing changes Speech is no longer silent after disconnecting from and reconnecting to a Remote Desktop session. Description of development approach I changed WasapiWavePlayer.feed to log exceptions and return without raising them. I could have tweaked the C++ code to handle ERROR_TOO_MANY_FILES and E_NOTFOUND as well as the codes it already handles (AUDCLNT_E_DEVICE_INVALIDATED and AUDCLNT_E_NOT_INITIALIZED). However, I figured it was best to make this code more resilient in general by catching exceptions, especially given that WinmmWavePlayer.feed also catches exceptions.
1 parent 3c981e2 commit 544ccb1

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

source/nvwave.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -907,20 +907,31 @@ def feed(
907907
@param size: The size of the data in bytes if data is a ctypes pointer.
908908
If data is a Python bytes object, size should be None.
909909
@param onDone: Function to call when this chunk has finished playing.
910-
@raise WindowsError: If there was an error playing the audio.
910+
@raise WindowsError: If there was an error initially opening the device.
911911
"""
912912
self.open()
913913
if self._audioDucker:
914914
self._audioDucker.enable()
915915
feedId = c_uint() if onDone else None
916916
# Never treat this instance as idle while we're feeding.
917917
self._lastActiveTime = None
918-
NVDAHelper.localLib.wasPlay_feed(
919-
self._player,
920-
data,
921-
size if size is not None else len(data),
922-
byref(feedId) if onDone else None
923-
)
918+
try:
919+
NVDAHelper.localLib.wasPlay_feed(
920+
self._player,
921+
data,
922+
size if size is not None else len(data),
923+
byref(feedId) if onDone else None
924+
)
925+
except WindowsError:
926+
# #16722: This might occur on a Remote Desktop server when a client session
927+
# disconnects without exiting NVDA. That will cause audio to become
928+
# unavailable with an unexpected error code. In any case, the C++
929+
# WasapiPlayer code will reopen the device when we next try to feed, so
930+
# just log the error here and return without raising it. Otherwise, we
931+
# might break code which isn't expecting to handle exceptions from feed
932+
# such as the oneCore synth driver.
933+
log.debugWarning("Error feeding audio", exc_info=True)
934+
return
924935
if onDone:
925936
self._doneCallbacks[feedId.value] = onDone
926937
self._lastActiveTime = time.time()

user_docs/en/changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Unicode CLDR has also been updated.
6767
* In LibreOffice Writer (version 24.8 and newer), when toggling text formatting (bold, italic, underline, subscript/superscript, alignment) using the corresponding keyboard shortcut, NVDA announces the new formatting attribute (e.g. "Bold on", "Bold off"). (#4248, @michaelweghorn)
6868
* When navigating with the cursor keys in text boxes in applications which use UI Automation, NVDA no longer sometimes reports the wrong character, word, etc. (#16711, @jcsteh)
6969
* When pasting into the Windows 10/11 Calculator, NVDA now correctly reports the full number pasted. (#16573, @TristanBurchett)
70+
* Speech is no longer silent after disconnecting from and reconnecting to a Remote Desktop session. (#16722, @jcsteh)
7071
* Support added for text review commands for an object's name in Visual Studio Code. (#16248, @Cary-Rowen)
7172

7273
### Changes for Developers

0 commit comments

Comments
 (0)