首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何准确计算iOS 8上硬件解码的FPS?

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

Stack Overflow用户
提问于 2014-09-15 03:35:56
回答 1查看 957关注 0票数 3

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

我们可以用"VTDecompressionSessionDecodeFrame“从iOS8中解码h264,

我试着编写一个程序来打印硬件解码的fps,

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

那么,如何准确地计算fp呢?

我找到了一种方法"VTDecompressionSessionWaitForAsynchronousFrames

是我想要的吗?

解码函数

代码语言:javascript
复制
- (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);
}

解码回调函数

代码语言:javascript
复制
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;

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-15 07:27:05

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

void * sourceFrameRefCon in VTDecompressionSessionDecodeFrame

代码语言:javascript
复制
VTDecompressionSessionDecodeFrame(
    VTDecompressionSessionRef       session,
    CMSampleBufferRef               sampleBuffer,
    VTDecodeFrameFlags              decodeFlags, // bit 0 is enableAsynchronousDecompression
    void *                          sourceFrameRefCon,
    VTDecodeInfoFlags               *infoFlagsOut /* may be NULL */ )

译码方法

代码语言:javascript
复制
- (void)render:(CMSampleBufferRef)sampleBuffer
{
    VTDecodeFrameFlags flags = kVTDecodeFrame_EnableAsynchronousDecompression;

    VTDecodeInfoFlags flagOut;

    NSDate* currentTime = [NSDate date];

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

    CFRelease(sampleBuffer);
}

解码回调方法

代码语言:javascript
复制
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

    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25840482

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档