【问题标题】:AVSampleBufferDisplayLayer not rendering frames anymore in iOS10AVSampleBufferDisplayLayer 在 iOS10 中不再渲染帧
【发布时间】:2016-11-16 19:22:33
【问题描述】:

以下设置一直适用于 iOS10 之前的所有最新 iOS 版本:

我正在使用 AVSampleBufferDisplayLayer 从自定义源渲染原始帧。

我使用CVPixelBufferPoolCreate 设置了一个像素缓冲池,并按照Apple 的指示将kCVPixelBufferIOSurfacePropertiesKey 设置为@{}

我使用CVPixelBufferPoolCreatePixelBuffer 从池中获取像素缓冲区,然后使用CVPixelBufferLockBaseAddressCVPixelBufferUnlockBaseAddress 将我的数据复制到缓冲区。

我的原始帧使用 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 的类型为 CVPixelBufferRefavfDisplayLayer_ AVSampleBufferDisplayLayer

下一个 sn-p 展示了我是如何构建显示层的:

  avfDisplayLayer_ = [[AVSampleBufferDisplayLayer alloc] init];
  avfDisplayLayer_.videoGravity = AVLayerVideoGravityResizeAspectFill;

我没有收到任何警告或错误消息,显示层状态不表示失败,isReadyForMoreMediaData 正在返回 true。

问题是我的框架没有显示在屏幕上。我还在显示图层上设置了背景颜色,只是为了确保图层正确合成(确实如此)。

iOS10 中的 AVSampleBufferDisplayLayer 肯定发生了一些变化,但我无法弄清楚它是什么。

【问题讨论】:

标签: avfoundation calayer ios10


【解决方案1】:

事实证明,在 iOS10 中,CMSampleTimingInfo 的值显然被更严格地解析了。

为了让渲染再次正常工作,上面的代码改成了下面的代码:

  CMSampleTimingInfo sampleTimeinfo{
      CMTimeMake(duration.count(), kOneSecond.count()),
      kCMTimeZero,
      kCMTimeInvalid};

请注意kCMTimeZero 字段的presentationTimeStamp

@Sterling Archer:您可能想尝试一下,看看它是否也解决了您的问题。

【讨论】:

  • 确实这也解决了我们的问题。我们不一定有一个恒定的帧速率,所以我们的CMSampleTimingInfo 结构有kCMTimeIndefinite 用于duration 成员。感谢您的跟进!
  • 这似乎在 iOS 10 Beta 4 [14A5322e] 中得到解决。 kCMTimeInvalid as presentationTimeStamp 据我所知,kCMSampleAttachmentKey_DisplayImmediately 不再中断渲染。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多