0
我已經使用videoToolBox用於編碼和解碼數據, 所以一旦我們得到了解碼數據直接我們傳遞到AVSampleBufferDisplayLayer
VideoToolBox解碼圖像顯示在約塞米蒂flickring OSX
這裏是代碼片段
-(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我在屏幕上閃爍。
任何幫助將是可觀的。
能夠將此屬性設置爲得到回答自己:) –
謎底到底是什麼? !將它添加到此處並將其標記爲已回答! –
我將AVSampleBufferDisplayLayer的controlTimebase屬性設置爲零,這是原因,現在我根本沒有設置此屬性 –