我们如何使用 AVSampleBufferDisplayLayer 来渲染 CMSampleBufferRef?
How can we use AVSampleBufferDisplayLayer to render CMSampleBufferRef?
我有这个委托方法
-(void)airPlayServer:(id)server sampleBufferReceived:(CMSampleBufferRef)sampleBuffer
{
}
这给了我 sampleBuffer
.
现在我需要知道如何使用 AVSampleBufferDisplayLayer
渲染我的 sampleBuffer。我知道我们必须使用 - enqueueSampleBuffer
- 但我是 iOS 的新手,所以我们该怎么做?
我不想将sampleBuffer转为CGImage再绘制。
非常感谢代码示例:)
像这样:
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];
我有这个委托方法
-(void)airPlayServer:(id)server sampleBufferReceived:(CMSampleBufferRef)sampleBuffer
{
}
这给了我 sampleBuffer
.
现在我需要知道如何使用 AVSampleBufferDisplayLayer
渲染我的 sampleBuffer。我知道我们必须使用 - enqueueSampleBuffer
- 但我是 iOS 的新手,所以我们该怎么做?
我不想将sampleBuffer转为CGImage再绘制。
非常感谢代码示例:)
像这样:
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];