title: AVSampleBufferDisplayLayer not rendering on device
body: <p>I'm struggling with AVSampleBufferDisplayLayer on iOS. I want to display a CVPixelBuffer using this layer, but i'm not able to get it work on actual iOS device. In my sample app i tried following code to display one color pixel buffer:</p>
  
  <pre><code>@implementation ViewController {
      AVSampleBufferDisplayLayer *videoLayer;
  }
  
  - (void)viewDidLoad {
      [super viewDidLoad];
  
      videoLayer = [[AVSampleBufferDisplayLayer alloc] init];
      videoLayer.frame = CGRectMake(50, 50, 300, 300);
      videoLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
  
      [self.view.layer addSublayer:videoLayer];
  }
  
  @implementation ViewController {
      AVSampleBufferDisplayLayer *videoLayer;
  }
  
  - (void)viewDidLoad {
      [super viewDidLoad];
  
      videoLayer = [[AVSampleBufferDisplayLayer alloc] init];
      videoLayer.frame = CGRectMake(50, 50, 300, 300);
      videoLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
  
      [self.view.layer addSublayer:videoLayer];
  }
  
  - (void)viewDidAppear:(BOOL)animated {
      [super viewDidAppear:animated];
      [self startVideo];
  }
  
  - (void)startVideo {
      [self drawPixelBuffer];
      [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(drawPixelBuffer) userInfo:nil repeats:YES];
  }
  
  - (void)drawPixelBuffer {
  
      int imageSize = 100;
  
      static const uint8_t pixel[] = {0x00, 0xAA, 0xFF, 0xFF};
  
      NSMutableData *frame = [NSMutableData data];
  
      for (int i = 0; i &lt; imageSize * imageSize; i++) {
          [frame appendBytes:pixel length:4];
      }
  
      CVPixelBufferRef pixelBuffer = NULL;
  
      CVPixelBufferCreateWithBytes(NULL, imageSize, imageSize, kCVPixelFormatType_32BGRA, [frame bytes], imageSize * 4, NULL, NULL, NULL, &amp;pixelBuffer);
  
      CMSampleBufferRef sampleBuffer = [self sampleBufferFromPixelBuffer:pixelBuffer];
  
      if (sampleBuffer) {
  
          [videoLayer enqueueSampleBuffer:sampleBuffer];
          CFRelease(sampleBuffer);
  
      }
  
  }
  
  - (CMSampleBufferRef)sampleBufferFromPixelBuffer:(CVPixelBufferRef)pixelBuffer {
  
      CMSampleBufferRef sampleBuffer = NULL;
      OSStatus err = noErr;
      CMVideoFormatDescriptionRef formatDesc = NULL;
      err = CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer, &amp;formatDesc);
  
      if (err != noErr) {
          return nil;
      }
  
      CMSampleTimingInfo sampleTimingInfo = kCMTimingInfoInvalid;
  
      err = CMSampleBufferCreateReadyWithImageBuffer(kCFAllocatorDefault, pixelBuffer, formatDesc, &amp;sampleTimingInfo, &amp;sampleBuffer);
  
      if (sampleBuffer) {
          CFArrayRef attachments = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, YES);
          CFMutableDictionaryRef dict = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(attachments, 0);
          CFDictionarySetValue(dict, kCMSampleAttachmentKey_DisplayImmediately, kCFBooleanTrue);
      }
  
      if (err != noErr) {
          return nil;
      }
  
      formatDesc = NULL;
  
      return sampleBuffer;
  
  }
  
  @end
  </code></pre>
  
  <p>This is working without any problem in iOS simulator but it's not working on real device (nothing is rendered). The video layer's error property is always nil and status is always equal AVQueuedSampleBufferRenderingStatusRendering.</p>
  
  <p>Thanks for any help.</p>