output/osx: move the default device query into a function - #2556
Open
valentynkit wants to merge 2 commits into
Open
output/osx: move the default device query into a function#2556valentynkit wants to merge 2 commits into
valentynkit wants to merge 2 commits into
Conversation
Preparation for querying the default device more than once; no functional change.
dev_id is resolved once in Create() and never updated for the kAudioUnitSubType_DefaultOutput and kAudioUnitSubType_SystemOutput subtypes, because osx_output_set_device() returns early unless the subtype is kAudioUnitSubType_HALOutput. Once that device goes away, the stored id stays invalid for the rest of the process and reconnecting does not help, so GetVolume(), SetVolume() and Open() all keep failing with kAudioHardwareBadObjectError until MPD is restarted. Enable() runs only once, so re-resolving there would not help either. This is easy to hit with Bluetooth headphones: disconnect them during playback and it cannot be resumed afterwards. Both subtypes follow the current default device anyway, so query it on demand instead of caching it. The hog_device calls keep using the stored id so Disable() releases the same device Enable() hogged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Disconnect a Bluetooth headset during playback and the output never opens again, even once the headset is back and is the default output device:
That is
kAudioHardwareBadObjectError.Create()resolvesdev_idonce, andosx_output_set_device()only refreshes it forkAudioUnitSubType_HALOutput. WithkAudioUnitSubType_DefaultOutputorkAudioUnitSubType_SystemOutputit is never updated, so once that device is gone the id stays dead andGetVolume(),SetVolume()andOpen()all fail until a restart.Re-resolving in
Enable()would not help either.InternalEnable()returns early oncereally_enabledis set, and the open failure path never clears it, soEnable()runs once per process.Since both subtypes track the default device anyway, query it on demand instead of caching it. The
hog_devicecalls keep using the stored id soDisable()still releases the deviceEnable()hogged.#932 hit the same error in 2020. Its case (*), a device pinned by name disappearing, needs different handling and is not addressed here.
First commit is preparation, no functional change. Tested on macOS arm64 with
mixer_type "hardware"and nodeviceset. Before, the output stays unopenable until restart. After, playback recovers on the next open and the log stays clean. Full build, no new warnings.Both commits apply to v0.24.x if you want a separate PR for that branch.