1

我有这个委托方法

-(void)airPlayServer:(id)server sampleBufferReceived:(CMSampleBufferRef)sampleBuffer
{
}

这给了我sampleBuffer

现在我需要知道如何使用它AVSampleBufferDisplayLayer来渲染我的 sampleBuffer。我知道我们必须使用 - enqueueSampleBuffer- 但我是 iOS 新手,所以我们该怎么做?

我不想将 sampleBuffer 转换为 CGImage 然后绘制它。

代码示例受到高度赞赏:)

4

1 回答 1

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];
于 2019-01-31T06:20:31.033 回答