AVSampleBufferDisplayLayer hangs on creation

Hi All,

We are developing app that uses a propietray network protocol to transfer video streams.

The stream is being de-mulpliexed, audio and video decoders are created and working but we are facing a strange hang while trying to create / use AVSampleBufferDisplayLayer in order to render the vide.

It hangs on the creation of the AVSampleBufferDisplayLayer instance. This happens on an iPhone 7 Plus and iPhoneX.

When the app hangs, the only way to make it display video again is to restart the device.

It happens freqently and blocking us from continue developing the app.


We tried to use the AVSampleBufferDisplayLayer using 2 different ways

Use it as a layer class

+ (Class) layerClass
{
  return [AVSampleBufferDisplayLayer class];
}

And access [self layer] everytime we need to enqueue a decoded frame - Using this way cause the app to hangs on creation of the view

You can see a screenshot of the callstack here : https://bit.ly/2FZt43B


Hold an internal property of AVSampleBufferDisplayLayer*, allocate and initate it under initWithCoder or initWithFrame.

_videoLayer                 = [[AVSampleBufferDisplayLayer alloc] init];
_videoLayer.frame           = self.bounds;
_videoLayer.videoGravity    = AVLayerVideoGravityResizeAspect;
_videoLayer.backgroundColor = [[UIColor blackColor] CGColor];
[[self layer] addSublayer:_videoLayer];

Again, the app hangs on creation.

You can see a screenshot of the callstack here : https://bit.ly/2I1EIRA


Creation / access to the AVSampleBufferDisplayInstace is always done from the main thread


What is the correct way to work with AVSampleBufferDisplayLayer?

Any idea why it's hanging and how to prevent it?


Thanks

Replies

Seeing this also on an iPhone XS Max running ios12.0.1, it hangs on just the creation statement thus;

self.videoLayer = AVSampleBufferDisplayLayer()

I powered off the phone and turned it back on and then it worked.

We're also seeing VTDecompressionSessionCreate errors when you create and destroy a bunch of video views. We have a CameraTableView which instantantiates N Camera's in it. If you set this to 4 Camera's and push into and out of this CameraTableViewController 5 or more times the video stops displaying. The video IFrames and PFrames are fine along with SPS and PPS so nothing is wrong with the streaming video packets.

AudioToolBox also has bugs decoding an AAC frame into PCM, it basically won't convert for certain AAC frame types.

We should really file a bug against Apple on this.

alse see AVSampleBufferDisplayLayer hangs on enqueue or init or dealloc. I feel that AVSampleBufferDisplayLayer is full of holes.

I've been using AVSampleBufferDisplayLayer for a few months without problem, but recently it started to hang exactly in the same way as you. Did you manage to find the problem?

Any update here? I'm expiriencing similar issue for iOS >= 12.2

Here is what I found: https://stackoverflow.com/questions/57144196/avsampledisplaybuffer-hangs-randomly-after-device-reboot


miguel208did you manage to solve it?