iOS檢測 AAC編碼支持情況

要檢測iOS是否支持AAC HE的編碼情況,從VideoCore摘了一段代碼,稍作修改。

stackoverflow上找了個int整數轉化為字符的宏,很經典


#include <TargetConditionals.h>
#if TARGET_RT_BIG_ENDIAN
#   define FourCC2Str(fourcc) (const char[]){*((char*)&fourcc), *(((char*)&fourcc)+1), *(((char*)&fourcc)+2), *(((char*)&fourcc)+3),0}
#else
#   define FourCC2Str(fourcc) (const char[]){*(((char*)&fourcc)+3), *(((char*)&fourcc)+2), *(((char*)&fourcc)+1), *(((char*)&fourcc)+0),0}
#endif

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 encoderSpecifier = kAudioFormatMPEG4AAC_HE;
//    UInt32 encoderSpecifier = kAudioFormatMPEG4AAC_HE_V2;
    UInt32 size;
    
    error = AudioFormatGetPropertyInfo(kAudioFormatProperty_Encoders, sizeof(encoderSpecifier),
                                       &encoderSpecifier, &size);
    if (error) { printf("AudioFormatGetPropertyInfo kAudioFormatProperty_Encoders error %d %4.4s\n", (int)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 %d %4.4s\n",
                      (int)error, (char*)&error); return false; }
    
    for (UInt32 i=0; i < numEncoders; ++i) {
        if (encoderDescriptions[i].mSubType == kAudioFormatMPEG4AAC &&
            encoderDescriptions[i].mManufacturer == kAppleHardwareAudioCodecManufacturer) isAvailable = true;
        
        printf("\n\n list %s %s %s \n", FourCC2Str(encoderDescriptions[i].mType), FourCC2Str(encoderDescriptions[i].mSubType), FourCC2Str(encoderDescriptions[i].mManufacturer));
    }
    
    return isAvailable;
}
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容