iOS検出AACコードサポート状況
2330 ワード
iOSがAAC HEの符号化をサポートしているかどうかを検出するには、VideoCoreからコードを取り出し、少し修正します.
stackoverflowでint整数を文字に変換するマクロを探しました.古典的です.
stackoverflowでint整数を文字に変換するマクロを探しました.古典的です.
#include
#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
", (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
",
(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("
list %s %s %s
", FourCC2Str(encoderDescriptions[i].mType), FourCC2Str(encoderDescriptions[i].mSubType), FourCC2Str(encoderDescriptions[i].mManufacturer));
}
return isAvailable;
}