VideoToolBox解码图像显示在Yosemite OSX中闪烁

时间:2017-10-13 05:17:46

标签: objective-c cocoa avfoundation encode video-toolbox

我使用videoToolBox来编码和解码数据, 所以一旦我们直接得到解码数据,我们就会转到AVSampleBufferDisplayLayer

这是代码段

 -(CVPixelBufferRef)decode:(AVPacket*)vp {

    CVPixelBufferRef outputPixelBuffer = NULL;

    CMBlockBufferRef blockBuffer = NULL;
    OSStatus status  = CMBlockBufferCreateWithMemoryBlock(kCFAllocatorDefault,
                                                          (void*)vp->data, vp->size,
                                                          kCFAllocatorNull,
                                                          NULL, 0, vp->size,
                                                          0, &blockBuffer);


    //NSLog(@"status is for CMBlockBufferCreateWithMemoryBlock is %d",(int)status);
    if(status == kCMBlockBufferNoErr) {
        CMSampleBufferRef sampleBuffer = NULL;
        const size_t sampleSizeArray[] = {vp->size};
        status = CMSampleBufferCreateReady(kCFAllocatorDefault,
                                           blockBuffer,
                                           formatDesc ,
                                           1, 0, NULL, 1, sampleSizeArray,
                                           &sampleBuffer);
       // NSLog(@"status is for formatdesc is %d",(int)status);
        if (status == kCMBlockBufferNoErr && sampleBuffer) {
            CFArrayRef attachments = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, YES);
            CFMutableDictionaryRef dict = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(attachments, 0);
            CFDictionarySetValue(dict, kCMSampleAttachmentKey_DisplayImmediately, kCFBooleanTrue);
            [displayLayer flush];
            if([displayLayer isReadyForMoreMediaData])
            {
                [displayLayer enqueueSampleBuffer:sampleBuffer];
            }

            [displayLayer setNeedsDisplay];

            [self performSelectorOnMainThread:@selector(setView:) withObject:[[RPCViewerAppInitializer sharedRPCViewerAppInitializer] rpcView] waitUntilDone:NO];
            CFRelease(blockBuffer);
            CFRelease(sampleBuffer);

        }
    }
    return outputPixelBuffer;
}

上面的代码在10.10 osx中工作正常,但在10.10中我在屏幕上闪烁。

任何帮助都会很明显。

1 个答案:

答案 0 :(得分:0)

这个问题已经解决了:

我将AVSampleBufferDisplayLayer的controlTimebase属性设置为nil,这是原因,现在根本没有设置此属性