Core Audio output: Properly apply or remove default device change listener when switching preferences between the 'System Default Device' setting and manually setting the device to the current default

CQTexperiment
Christopher Snowhill 2021-12-26 21:33:28 -08:00
parent 8435416cd7
commit 8e895c88c0
1 changed files with 22 additions and 23 deletions

View File

@ -127,9 +127,6 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
} }
if (audioQueue) { if (audioQueue) {
if (outputDeviceID == deviceID)
return noErr;
AudioObjectPropertyAddress defaultDeviceAddress = theAddress; AudioObjectPropertyAddress defaultDeviceAddress = theAddress;
if (listenerapplied && !defaultDevice) { if (listenerapplied && !defaultDevice) {
@ -137,6 +134,7 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
listenerapplied = NO; listenerapplied = NO;
} }
if (outputDeviceID != deviceID) {
printf("DEVICE: %i\n", deviceID); printf("DEVICE: %i\n", deviceID);
outputDeviceID = deviceID; outputDeviceID = deviceID;
@ -162,6 +160,7 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
CFRelease(theDeviceUID); CFRelease(theDeviceUID);
if (running) if (running)
[self start]; [self start];
}
if (!listenerapplied && defaultDevice) { if (!listenerapplied && defaultDevice) {
AudioObjectAddPropertyListener(kAudioObjectSystemObject, &defaultDeviceAddress, default_device_changed, (__bridge void * _Nullable)(self)); AudioObjectAddPropertyListener(kAudioObjectSystemObject, &defaultDeviceAddress, default_device_changed, (__bridge void * _Nullable)(self));