I’m a CoreAudio beginner and I got tripped up over this one. Hopefully this post (and radar bug) will improve error reporting in future releases of Apple’s audio queue services API.
Here’s the problem: we’re supposed to use the AudioQueueSetProperty
API when associating a AudioQueueRef
with an AudioObject
. Instead of passing the AudioDeviceID
of the device, we’re supposed to pass the device unique id
, a pointer to a CFStringRef
.
The call to AudioQueueSetProperty
will succeed regardless of the CFStringRef's
value
What does that mean? That means you’ll fail later in your application if you’ve passed a bad value to AudioQueueSetProperty
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
AudioQueueRef audioQueue = ...; CFStringRef garbageUID = (CFStringRef)@"Garbage!"; OSStatus status = AudioQueueSetProperty(audioQueue, kAudioQueueProperty_CurrentDevice, &garbageUID, sizeof(CFStringRef)); // status is still noErr ... // Sometime later UInt32 cookieSize; status = AudioQueueGetPropertySize (audioQueue, kAudioQueueProperty_MagicCookie, &cookieSize); // And now status is kAudioQueueErr_InvalidDevice |