-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ao_coreaudio: stop audio unit after idle timeout #13663
Conversation
This is the replacement pull request for PR #11667. @Akemi If there is anything you don't like and want changed do not hesitate to ask. I am happy to update as needed. I did not change the code at all other than to add a couple of comments. I am worried about the switch from synchronous to asynchronous in the |
Download the artifacts for this pull request: |
besides my comment about keeping it in sync, i think this is good to go. |
Commit 39f7f83 changed ao_driver.reset to use AudioUnitReset instead of AudioOutputUnitStop. The problem with calling AudioOutputUnitStop was that AudioOutputUnitStart takes a significant amount of time after a stop when a wireless audio device is being used. This resulted in lagging that was noticeable to users during seeking and short pause/resume cycles. Switching to AudioUnitReset eliminated this lagging. However with the switch to AudioUnitReset the macOS daemon coreaudiod continued to consume CPU time and did not release a powerd assertion that it created on behalf of mpv, preventing macOS from sleeping. This commit will change ao_coreaudio.reset to call AudioOutputUnitStop after a delay if playback has not resumed. This preserves the faster restart of playback for seeking and short pause/resume cycles and avoids preventing sleep and needless CPU consumption. Fixes mpv-player#11617 The code changes were authored by @orion1vi and @lhc70000. Co-authored-by: Collider LI <lhc199652@gmail.com>
I have updated the commit to use I was very tempted to make that change when preparing the PR, but as I do not know the macOS audio APIs I was concerned this might be some sort of event driven interface and I would be undoing some sort of improvement. |
Commit 39f7f83 changed ao_driver.reset to use AudioUnitReset instead of AudioOutputUnitStop. The problem with calling AudioOutputUnitStop was that AudioOutputUnitStart takes a significant amount of time after a stop when a wireless audio device is being used. This resulted in lagging that was noticeable to users during seeking and short pause/resume cycles. Switching to AudioUnitReset eliminated this lagging.
However with the switch to AudioUnitReset the macOS daemon coreaudiod continued to consume CPU time and did not release a powerd assertion that it created on behalf of mpv, preventing macOS from sleeping.
This commit will change ao_coreaudio.reset to call AudioOutputUnitStop after a delay if playback has not resumed. This preserves the faster restart of playback for seeking and short pause/resume cycles and avoids preventing sleep and needless CPU consumption.
Fixes #11617
The code changes were authored by @orion1vi and @lhc70000.