【发布时间】:2016-11-16 19:22:33
【问题描述】:
以下设置一直适用于 iOS10 之前的所有最新 iOS 版本:
我正在使用 AVSampleBufferDisplayLayer 从自定义源渲染原始帧。
我使用CVPixelBufferPoolCreate 设置了一个像素缓冲池,并按照Apple 的指示将kCVPixelBufferIOSurfacePropertiesKey 设置为@{}。
我使用CVPixelBufferPoolCreatePixelBuffer 从池中获取像素缓冲区,然后使用CVPixelBufferLockBaseAddress 和CVPixelBufferUnlockBaseAddress 将我的数据复制到缓冲区。
我的原始帧使用 NV12 格式 kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange。
这里是一段代码 sn-p,展示了我如何将像素缓冲区转换为 CMSampleBufferRef 并将其排入显示层:
CMSampleTimingInfo sampleTimeinfo{
CMTimeMake(duration.count(), kOneSecond.count()),
kCMTimeInvalid,
kCMTimeInvalid};
CMFormatDescriptionRef formatDescription = nullptr;
CMVideoFormatDescriptionCreateForImageBuffer(nullptr, pixelBuffer, &formatDescription);
CMSampleBufferRef sampleBuffer = nullptr;
CMSampleBufferCreateForImageBuffer(
nullptr, pixelBuffer, true, nullptr, nullptr, formatDescription, &sampleTimeinfo, &sampleBuffer));
CFArrayRef attachmentsArray = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, YES);
const CFIndex numElementsInArray = CFArrayGetCount(attachmentsArray);
for (CFIndex i = 0; i < numElementsInArray; ++i) {
CFMutableDictionaryRef attachments = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(attachmentsArray, i);
CFDictionarySetValue(attachments, kCMSampleAttachmentKey_DisplayImmediately, kCFBooleanTrue);
}
if ([avfDisplayLayer_ isReadyForMoreMediaData]) {
[avfDisplayLayer_ enqueueSampleBuffer:sampleBuffer];
}
CFRelease(sampleBuffer);
CFRelease(formatDescription);
pixelBuffer 的类型为 CVPixelBufferRef 和 avfDisplayLayer_ AVSampleBufferDisplayLayer。
下一个 sn-p 展示了我是如何构建显示层的:
avfDisplayLayer_ = [[AVSampleBufferDisplayLayer alloc] init];
avfDisplayLayer_.videoGravity = AVLayerVideoGravityResizeAspectFill;
我没有收到任何警告或错误消息,显示层状态不表示失败,isReadyForMoreMediaData 正在返回 true。
问题是我的框架没有显示在屏幕上。我还在显示图层上设置了背景颜色,只是为了确保图层正确合成(确实如此)。
iOS10 中的 AVSampleBufferDisplayLayer 肯定发生了一些变化,但我无法弄清楚它是什么。
【问题讨论】:
-
我们在我们的应用程序中也看到了这一点,所以我向 Apple 提交了一个错误报告并将信息复制到 OpenRadar:openradar.appspot.com/radar?id=5001147395866624
标签: avfoundation calayer ios10