Here has new hardwrare decode methods from iOS8,
we can use "VTDecompressionSessionDecodeFrame" to decode h264 from iOS8,
I try to coding a program which able to print the fps of hardware decode,
but here has a problem, the callback is asynchronously,
so how can I calculate the fps exactly?
I found a method "VTDecompressionSessionWaitForAsynchronousFrames"
Is it what I want ?
Decode Function
- (void)render:(CMSampleBufferRef)sampleBuffer
{
if (_isDecoding == NO) {
_isDecoding = YES;
_lastTime = [NSDate date];
}
VTDecodeFrameFlags flags = kVTDecodeFrame_EnableAsynchronousDecompression;
VTDecodeInfoFlags flagOut;
VTDecompressionSessionDecodeFrame(_decompression, sampleBuffer, flags, NULL, &flagOut);
VTDecompressionSessionWaitForAsynchronousFrames(_decompression);
if (_gotFrame == YES) {
_gotFrame = NO;
_isDecoding = NO;
}
CFRelease(sampleBuffer);
}
Decode Callback Function
void didDecompress( void *decompressionOutputRefCon, void *sourceFrameRefCon, OSStatus status, VTDecodeInfoFlags infoFlags, CVImageBufferRef imageBuffer, CMTime presentationTimeStamp, CMTime presentationDuration ){
VideoView* THIS = (__bridge VideoView*)decompressionOutputRefCon;
THIS->_gotFrame = YES;
NSDate* currentTime = [NSDate date];
NSTimeInterval runTime = currentTime.timeIntervalSince1970 - THIS->_lastTime.timeIntervalSince1970;
THIS->_totalTime += runTime;
THIS->_counts++;
THIS->_lastTime = currentTime;
}