Skip to content

playWaveFile: Repeatedly call stop until we're certain the previous file playback has been stopped.#15763

Merged
seanbudd merged 1 commit into
nvaccess:masterfrom
jcsteh:stopLoop
Nov 9, 2023
Merged

playWaveFile: Repeatedly call stop until we're certain the previous file playback has been stopped.#15763
seanbudd merged 1 commit into
nvaccess:masterfrom
jcsteh:stopLoop

Conversation

@jcsteh

@jcsteh jcsteh commented Nov 9, 2023

Copy link
Copy Markdown
Contributor

Link to issue number:

Fixes #15757.

Summary of the issue:

Asynchronously playing multiple files in quick succession can block while one of the files plays. However, async playback should never block.

Description of user facing changes

NVDA no longer sometimes freezes briefly when multiple sounds are played in rapid succession.

Description of development approach

There are several race conditions where the background thread might feed audio after we call stop in the main thread. Some of these are difficult to fix with locks because they involve switches between Python and blocking native code. We now just keep calling stop until we know that the backgroundd thread is done, which means it was successfully stopped. We know when the background thread is done because it sets fileWavePlayer to None.

Testing strategy:

Ran the following Python console snippet:

import nvwave; nvwave.playWaveFile("waves/start.wav"); nvwave.playWaveFile("waves/start.wav")

Before this change, the first call often blocked, resulting in two sounds playing. After the change, it doesn't block and only the final sound plays.

Known issues with pull request:

Strictly speaking, this code "spins" calling stop(). Spinning is generally bad. In practice, this should only call stop() a few times at most, since the background thread should clean up as soon as it is stopped.

Code Review Checklist:

  • Documentation:
    • Change log entry
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English
  • API is compatible with existing add-ons.
  • Security precautions taken.

@jcsteh jcsteh requested a review from a team as a code owner November 9, 2023 02:52
@jcsteh jcsteh requested a review from seanbudd November 9, 2023 02:52
@seanbudd seanbudd merged commit 5cc028b into nvaccess:master Nov 9, 2023
@nvaccessAuto nvaccessAuto added this to the 2024.1 milestone Nov 9, 2023
@Brian1Gaff

Brian1Gaff commented Nov 9, 2023 via email

Copy link
Copy Markdown

@jcsteh

jcsteh commented Nov 9, 2023

Copy link
Copy Markdown
Contributor Author

No. This is only relevant to this particular stream of audio and is not impacted by any other streams, whether those streams belong to NVDA or other applications.

@jcsteh jcsteh deleted the stopLoop branch May 25, 2026 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Potential freeze when WASAPI is enabled

4 participants