AudioConverter APIs should use CFErrorRef instead of integer error codes

Originator:joachimb
Number:rdar://29206399 Date Originated:10-Nov-2016 01:48 PM
Status:Open Resolved:
Product:iOS SDK Product Version:Any
Classification:Enhancement Reproducible:Always
 
Summary:
This goes for all C-based APIs at Apple, but AudioConverter just wasted two work days for me, so this is now an AudioConverter-specific radar.

AudioConverter's APIs use integer error codes, and has no way of introspecting what that error actually means. kAudioFormatUnsupportedDataFormatError can mean that any field of any of the input or output formats is wrong, or a combination. Internally in the implementation, there was a specific reason for this error to be returned, so a CFErrorRef would be able to have a localized description explaining exactly (or at least roughly) what was wrong with the formats.

The same goes for kAudioFormatUnspecifiedError, kAudioFormatUnsupportedPropertyError, kAudioFormatBadPropertySizeError, and other errors that are basically saying "one of the parameters was wrong somehow", which is almost impossible to decipher without very deep understanding of the class.

In this specific case, I was getting kAudioFormatUnsupportedDataFormatError because my input format said it was a 16-bit unsigned integer PCM format. AudioConverter does not support 16-bit unsigned, but this information is not available in any headers, documentation or even error messages. Instead, I had to trial-and-error for two days to find it.

For every if statement returning -50 in your code base replaced with a proper CFErrorRef or NSError, you will be saving your platform developers hundreds of hours of debugging and development time (and I don't even think that's an exaggeration). Please, spend time on this, for our sake.

Steps to Reproduce:
1. Create an AudioStreamBasicDescription with mFormatFlags set to 0
2. Call AudioConverterCreate with this ASBD as the input format

Expected Results:
1. Get a CFErrorRef with AudioToolbox as the domain and kAudioFormatUnsupportedDataFormatError as the code, and a localized description (or some other text field) in userinfo explaining which parameter is at fault and why (in this case, "AudioConverter only supports signed 16-bit PCM, not unsigned. See kAudioFormatFlagIsSignedInteger").

Actual Results:
1. Get an OSStatus return with kAudioFormatUnsupportedDataFormatError, with a side of tears and frustration.

Version:
All versions of iOS and macOS ever

Notes:


Configuration:
Any

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!