How to check iOS device chip is A9 or A10?

Viewed 1535

Apple announced HEVC encode support for A10 devices running iOS 11, and HEVC decode support for A9 devices running iOS 11.

Before create those hardware codec, how to check if current device is support the feature?

What is the chip? A8, A9, or A10 without hard code the model.

3 Answers

For encoder, I could not find an official way but this seems to work in my tests:

#import <AVFoundation/AVFoundation.h>
#import <VideoToolbox/VideoToolbox.h>


- (BOOL)videoCodecTypeHevcIsSuppored {
    if (@available(iOS 11, *)) {
        CFMutableDictionaryRef encoderSpecification = CFDictionaryCreateMutable( NULL,0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
        CFDictionarySetValue(encoderSpecification, kVTCompressionPropertyKey_ProfileLevel, kVTProfileLevel_HEVC_Main_AutoLevel);
        CFDictionarySetValue(encoderSpecification, kVTCompressionPropertyKey_RealTime, kCFBooleanTrue);
        OSStatus status = VTCopySupportedPropertyDictionaryForEncoder(3840, 2160, kCMVideoCodecType_HEVC, encoderSpecification, nil, nil);
        if (status == kVTCouldNotFindVideoEncoderErr) {
            return NO;
        }
        return YES;
    }
    return NO;
}

kanso's great answer in Swift 4.

Assumes that we target only iOS11 or higher and adds an extra check:

import AVFoundation
import VideoToolbox

@available (iOS 11, *)
func isHEVCHardwareEncodingSupported() -> Bool {
    let encoderSpecDict : [String : Any] =
        [kVTCompressionPropertyKey_ProfileLevel as String : kVTProfileLevel_HEVC_Main_AutoLevel,
         kVTCompressionPropertyKey_RealTime as String : true]

    let status = VTCopySupportedPropertyDictionaryForEncoder(3840, 2160,
                                                             kCMVideoCodecType_HEVC,
                                                             encoderSpecDict as CFDictionary,
                                                             nil, nil)
    if status == kVTCouldNotFindVideoEncoderErr {
        return false
    }

    if status != noErr {
        return false
    }

    return true
}
Related