Skip to content

Stop WASAPI streams if they've been inactive for more than a minute.#15097

Merged
seanbudd merged 1 commit into
nvaccess:masterfrom
jcsteh:closeInactive
Jul 14, 2023
Merged

Stop WASAPI streams if they've been inactive for more than a minute.#15097
seanbudd merged 1 commit into
nvaccess:masterfrom
jcsteh:closeInactive

Conversation

@jcsteh

@jcsteh jcsteh commented Jul 4, 2023

Copy link
Copy Markdown
Contributor

Link to issue number:

Fixes #14913.

Summary of the issue:

On some systems, when WASAPI is enabled, the system won't automatically go to sleep, even though it goes to sleep fine when WASAPI is disabled.

Description of user facing changes

When WASAPI audio is enabled, the computer now automatically goes to sleep if appropriate.

Description of development approach

When a WASAPI stream isn't stopped, this unfortunately prevents some systems from going to sleep automatically. I think this is on Windows 10 and earlier, but the precise details aren't clear. According to a Microsoft engineer, this is by design.

I originally thought this occurred when a WASAPI stream remained open. However, some testing revealed that stopping the stream seems to be enough to fix this. Previously, we didn't explicitly stop idle streams. Stopping is better than closing because opening a stream after it is closed can introduce delays or truncated audio.

Specific implementation details:

  1. Add a method to stop a WASAPI stream when it is idle.
  2. When feed() is called, track the current time as the last time the stream was definitely active. If there isn't a pending stream idle check, schedule one.
  3. Every 5 seconds, check if there are any playing streams that haven't been active for 10 seconds. If there are any, stop them.
    We use a class-wide check to avoid continually resetting timers on every audio chunk. See the docstring for WasapiWavePlayer._idleCheck for details.

Testing strategy:

Used beeps in the code to verify that streams get closed when they should.
I can't reproduce this sleep issue myself, so I asked users experiencing it to test with a try build. They reported that it fixed the issue for them.

Known issues with pull request:

None.

Change log entries:

No change log entry required because WASAPI hasn't been in a release yet.

Code Review Checklist:

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

@jcsteh jcsteh requested a review from a team as a code owner July 4, 2023 00:24
@jcsteh jcsteh requested a review from seanbudd July 4, 2023 00:24
@jcsteh

jcsteh commented Jul 4, 2023

Copy link
Copy Markdown
Contributor Author

Actually, i wonder whether pausing the stream (instead of closing it) might be enough. Marking as draft until we get that tested.

@jcsteh jcsteh marked this pull request as draft July 4, 2023 00:53
@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit 77cb061a32

@ultrasound1372

Copy link
Copy Markdown

What about letting them configure the interval? In advanced settings perhaps? With one minute as the default, unless you can somehow get the system sleep time value and other power settings. I personally have that disabled when plugged in so wouldn't need it to do so, but unsure how viable that would be really. I'd settle for configuring it myself.

@jcsteh jcsteh changed the title Close WASAPI streams if they've been inactive for more than a minute. Stop WASAPI streams if they've been inactive for more than a minute. Jul 13, 2023
@jcsteh jcsteh marked this pull request as ready for review July 13, 2023 09:27

@seanbudd seanbudd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jcsteh

@seanbudd seanbudd merged commit 384a742 into nvaccess:master Jul 14, 2023
@nvaccessAuto nvaccessAuto added this to the 2023.2 milestone Jul 14, 2023
@seanbudd seanbudd mentioned this pull request Jul 21, 2023
6 tasks
seanbudd added a commit that referenced this pull request Jul 25, 2023
Changes to handle #15150
Follow up to #14697, #14896, #15038, #15097, #15145

Summary of the issue:
WASAPI usage is known to cause intermittent crashing in #15150.
Generally, WASAPI code has not been proven to be stable.
Due to this, it should not be enabled by default in 2023.2.
WASAPI can be re-enabled by default once it is proven to be stable.

Description of user facing changes
Disable WASAPI by default, preventing intermittent crashing #15150

Description of development approach
Turn the WASAPI checkbox into a feature flag, so that it can easily be re-enabled in future.

Testing strategy:
Manual testing
Upgrading the profile: Test starting NVDA with the WASAPI config value set to "True/False" instead of a "enabled/disabled/default".

Test the various controls related to WASAPI - ensure they are saved, applied and respected correctly.
@jcsteh jcsteh deleted the closeInactive 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.

When set to use WASAPI, and using Windows 10 and below, NVDA prevents the system from automatically entering sleep

5 participants