How can we use AVSampleBufferDisplayLayer to render CMSampleBufferRef?

1.2k views Asked by At

I have this delegate method

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

which gives me sampleBuffer.

Now I need to know how can I use AVSampleBufferDisplayLayer to render my sampleBuffer. I know we have to use - enqueueSampleBuffer - but I am new to iOS so how can we do it?

I don't want to convert sampleBuffer to CGImage and then draw it.

Code example is highly appreciated :)

1

There are 1 answers

0
MoDJ On BEST ANSWER

Like so:

   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];