Last active
February 1, 2023 09:10
-
-
Save hankbao/cd7c881baa3ad8a82b9b9cdfee512a82 to your computer and use it in GitHub Desktop.
Using AudioFormat to check the availability of the AAC hardware encoder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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