に以下の設定がiOS10まで、すべての最近のiOSバージョンに取り組んできました。私は、カスタムのソースからの生フレームをレンダリングするAVSampleBufferDisplayLayer
を使用していますAVSampleBufferDisplayLayerレンダリングないフレームはもうiOS10
。
ピクセルバッファプールをCVPixelBufferPoolCreate
で設定し、kCVPixelBufferIOSurfacePropertiesKey
をAppleの指示に従って@{}
に設定しました。
私はCVPixelBufferPoolCreatePixelBuffer
を使用してプールからピクセルバッファを取得し、CVPixelBufferLockBaseAddress
とCVPixelBufferUnlockBaseAddress
を使用してデータをバッファにコピーします。
私の生フレームはNV12フォーマットkCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
を使用します。ここ
私は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
。
この次のスニペットは、私が表示層を構築する方法を示しています。私は、任意の警告またはエラーメッセージを取得していない午前
avfDisplayLayer_ = [[AVSampleBufferDisplayLayer alloc] init];
avfDisplayLayer_.videoGravity = AVLayerVideoGravityResizeAspectFill;
、表示層の状態は、失敗を示すものではありませんし、isReadyForMoreMediaData
がtrueを返しています。
問題は、フレームが画面に表示されないことです。また、レイヤーが正しく合成されていることを確認するために、表示レイヤーに背景色を設定しました。
AVSampleBufferDisplayLayerに関してiOS10では何かが変更されているに違いありませんが、それが何であるか把握することができません。
私たちもこのアプリケーションを見ています。そのため、Appleにバグレポートを提出し、OpenRadarに情報をコピーしました:https://openradar.appspot.com/radar?id=5001147395866624 –