我有这个委托方法
-(void)airPlayServer:(id)server sampleBufferReceived:(CMSampleBufferRef)sampleBuffer
{
}
这给了我sampleBuffer
。
现在,我需要知道如何使用AVSampleBufferDisplayLayer
来呈现我的sampleBuffer。我知道我们必须使用-enqueueSampleBuffer
-但是我是iOS的新手,所以我们该怎么做?
我不想将sampleBuffer转换为CGImage然后绘制它。
高度赞赏示例代码:)
答案 0 :(得分:3)
像这样:
CMSampleBufferRef sampleBufferRef = ...;
// Force display as soon as possible
CFArrayRef attachments = CMSampleBufferGetSampleAttachmentsArray(sampleBufferRef, YES);
CFMutableDictionaryRef dict = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(attachments, 0);
CFDictionarySetValue(dict, kCMSampleAttachmentKey_DisplayImmediately, kCFBooleanTrue);
[sampleBufferLayer enqueueSampleBuffer:sampleBufferRef];
[sampleBufferLayer setNeedsDisplay];