ios - 如何准确计算 iOS 8 上硬件解码的 FPS?

标签 ios ios8

这里有来自iOS8的新硬件解码方法,

我们可以使用“VTDecompressionSessionDecodeFrame”从 iOS8 解码 h264,

我尝试编写一个能够打印硬件解码 fps 的程序,

但是这里有个问题,回调是异步的,

那么我怎样才能准确计算 fps?

我找到了一个方法“VTDecompressionSessionWaitForAsynchronousFrames

这是我想要的吗?

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;

}

最佳答案

我们可以将 NSDate 设置为 sourceRefCon,然后从回调中访问时间戳以获取准确的解码时间。

void * sourceFrameRefCon in VTDecompressionSessionDecodeFrame

VTDecompressionSessionDecodeFrame(
    VTDecompressionSessionRef       session,
    CMSampleBufferRef               sampleBuffer,
    VTDecodeFrameFlags              decodeFlags, // bit 0 is enableAsynchronousDecompression
    void *                          sourceFrameRefCon,
    VTDecodeInfoFlags               *infoFlagsOut /* may be NULL */ )

Decode Method

- (void)render:(CMSampleBufferRef)sampleBuffer
{
    VTDecodeFrameFlags flags = kVTDecodeFrame_EnableAsynchronousDecompression;

    VTDecodeInfoFlags flagOut;

    NSDate* currentTime = [NSDate date];

    VTDecompressionSessionDecodeFrame(_decompression, sampleBuffer, flags, (void*)CFBridgingRetain(currentTime), &flagOut);

    CFRelease(sampleBuffer);
}

Decode Callback Method

void didDecompress( void *decompressionOutputRefCon, void *sourceFrameRefCon, OSStatus status, VTDecodeInfoFlags infoFlags, CVImageBufferRef imageBuffer, CMTime presentationTimeStamp, CMTime presentationDuration ){

    NSDate* currentTime = (__bridge NSDate *)sourceFrameRefCon;

    if (currentTime != nil) {

        //Do something

    }
}

关于ios - 如何准确计算 iOS 8 上硬件解码的 FPS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25840482/

相关文章:

swift - 将 TableView 嵌套到分组 TableView 中

ios - 一个 View Controller 中的两个 TableView

ios - 将 selectedTextRange UITextRange 转换为 NSRange

android - 使用 url 打开移动应用程序 - 试图找到在 IoS Android 和 Win Phone 8 上打开应用程序的单一方法

iOS :visited link showing default purple color

ios - 在自定义 UIPrintPageRenderer 中使用 UIFont 绘制字符串对象

ios - 使用应用组在应用之间通信和保存数据

ios - 当我们从 testflight 或 diawi iOS 下载构建时,推送通知不会出现

ios - 使用源类型相机控制 UIImagePickerController 中的修剪搜索栏

ios - UITableView Swift 2 中的自定义单元格