AVAudioSession methods failing without returning an error and leading to a non-functional AUGraph

Originator:speyer.richard
Number:rdar://19156110 Date Originated:12/5/2014
Status:Open Resolved:
Product:iOS Product Version:8.1.1
Classification:Serious Bug Reproducible:Always
 
Summary:
See steps below for more detail, but effectively setting an "unsupported" preferredSampleRate on the AVAudioSession will not yield an error on the API call and will lead to many more errors and unexpected behaviors.

Steps to Reproduce:
1. On an inactive audio session, call  [[AVAudioSession sharedInstance] setPreferredSampleRate:48000.0f error:&error]
2. Observe that the method returns YES and the NSError parameter is not set (remains nil)
3. Call [[AVAudioSession sharedInstance] preferredSampleRate] and observe that 48000.0f is returned
4. In Xcode, open the Devices window and expose the live device console for an the attached iPhone.
5. Observe the following error fire every time setPreferredSampleRate is called:
Dec  4 19:00:35 Richards-iPhone-6 mediaserverd[8722] <Error>: 19:00:35.173 EXCEPTION:  ERROR:     [0x104360000] >va> 1765: kAudioDeviceUnsupportedFormatError: "Attempt to set an unsupported sample rate (48000.000000 Hz)"

6. Despite this, continue to use the AVAudioSession in PlayAndRecord mode and initialize a basic AUGraph with input and output callbacks
7. Observe that while output is routed to speaker/earpiece/headphones everything appears to work fine
8. Adjust AVAudioSession to route I/O to attached Bluetooth device by setting the  AVAudioSessionCategoryOptionAllowBluetooth option
9. Observe: Suddenly, no input/output callbacks are received at all, but no errors are fired
10. Observe the following error firing continuously in the live console in Xcode/Devices:
Dec  4 18:42:45 Richards-iPhone-6 mediaserverd[8722] <Error>: kAudioUnitErr_TooManyFramesToProcess : inFramesToProcess=24576, mMaxFramesPerSlice=4096

11. Observe that returning to speaker/earpiece/headphone will make this error disappear
12. Both of these errors can be resolved by simply not calling setPreferredSampleRate with an “unsupported” rate

Expected Results:
I observe a few bugs in this flow:
1) setPreferredSampleRate should be returning NO and setting a NSError with the above information when the call fails
2) preferredSampleRate should *not* return the rate which failed to be set
3) It is questionable whether or not there should be an error which only occurs when using a Bluetooth device, but this error *must* be exposed to the developer in some way

However, at the end I think the core bug is that the developer is allowed to proceed with a mis-configured AVAudioSession that can lead to many more errors down the road.

Actual Results:
See steps 5, 9, and 10 for the actual results and errors in this flow leading to a non-functional audio session

Version:
iOS 8.1.1

Notes:


Configuration:
iPhone 6 and 6+, AT&T, both WiFi and WWAN

Attachments:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!