Skip to content

Instantly share code, notes, and snippets.

@hankbao
Last active February 1, 2023 09:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hankbao/cd7c881baa3ad8a82b9b9cdfee512a82 to your computer and use it in GitHub Desktop.
Save hankbao/cd7c881baa3ad8a82b9b9cdfee512a82 to your computer and use it in GitHub Desktop.
Using AudioFormat to check the availability of the AAC hardware encoder.
// Check this: https://developer.apple.com/library/content/qa/qa1663/_index.html
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment