Determining the availability of the AAC hardware encoder at runtime
Q: How can I determine the availability of the AAC hardware encoder at runtime?
A: How can I determine the availability of the AAC hardware encoder at runtime?
iOS 4.0 and later supports hardware-assisted offline encoding using Extended Audio File and Audio Converter APIs.
To check for the availablility of the AAC hardware encoder, get the Audio Format kAudioFormatProperty_Encoders
property using kAudioFormatMPEG4AAC
as the encoder specifier, then compare the mSubType
and mManufacturer
fields of returned AudioClassDescription
structures for kAudioFormatMPEG4AAC
and kAppleHardwareAudioCodecManufacturer
, as shown in Listing 1.
Listing 1 Using AudioFormat to check the availability of the AAC hardware encoder.
Boolean IsAACHardwareEncoderAvailable(void) { Boolean isAvailable = false; OSStatus error; // get an array of AudioClassDescriptions for all installed encoders for the given format // the specifier is the format that we are interested in - this is 'aac ' in our case UInt32 encoderSpecifier = kAudioFormatMPEG4AAC; UInt32 size; error = AudioFormatGetPropertyInfo(kAudioFormatProperty_Encoders, sizeof(encoderSpecifier), &encoderSpecifier, &size); if (error) { printf("AudioFormatGetPropertyInfo kAudioFormatProperty_Encoders error %lu %4.4s\n", error, (char*)&error); return false; } UInt32 numEncoders = size / sizeof(AudioClassDescription); AudioClassDescription encoderDescriptions[numEncoders]; error = AudioFormatGetProperty(kAudioFormatProperty_Encoders, sizeof(encoderSpecifier), &encoderSpecifier, &size, encoderDescriptions); if (error) { printf("AudioFormatGetProperty kAudioFormatProperty_Encoders error %lu %4.4s\n", error, (char*)&error); return false; } for (UInt32 i=0; i < numEncoders; ++i) { if (encoderDescriptions[i].mSubType == kAudioFormatMPEG4AAC && encoderDescriptions[i].mManufacturer == kAppleHardwareAudioCodecManufacturer) isAvailable = true; } return isAvailable; } |
The check demonstrated above is only one of a number of steps that must be followed when performing hardware-assisted offline encoding. For details concerning Audio Session configuration and Interruption Handling during an encoding operation, refer to the Audio Session Programming Guide, iPhoneExtAudioFileConvertTest and iPhoneACFileConvertTest samples available in the iOS Reference Library.
Document Revision History
Date | Notes |
---|---|
2010-12-23 | Updated for 4.1 |
2009-09-08 | New document that describes how to find out if the AAC hardware encoder is available at runtime. |
Copyright © 2010 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2010-12-23