I have a video decoder playing H264 using AVSampleBufferDisplayLayer and all works well until I scroll a UICollectionViewController on the same View Controller. This appears to block the main thread causing the app to crash. I have tried putting this code in a block on a separate queue using dispatch_async but still have the same blocking problem along with further performance issues on the decoder.
dispatch_async(sampleQueue, ^{
[sampleBufferQueue addObject:(__bridge id)(sampleBuffer)];
if ([avLayer isReadyForMoreMediaData]) {
CMSampleBufferRef buffer = (__bridge CMSampleBufferRef)([sampleBufferQueue objectAtIndex:0]);
[sampleBufferQueue removeObjectAtIndex:0];
[avLayer enqueueSampleBuffer:buffer];
buffer = NULL;
NSLog(@"I Frame");
[avLayer setNeedsDisplay];
while ([sampleBufferQueue count] > 0 && [avLayer isReadyForMoreMediaData]) {
CMSampleBufferRef buffer = (__bridge CMSampleBufferRef)([sampleBufferQueue objectAtIndex:0]);
[sampleBufferQueue removeObjectAtIndex:0];
[avLayer enqueueSampleBuffer:buffer];
buffer = NULL;
NSLog(@"I Frame from buffer");
[avLayer setNeedsDisplay];
}
}
else {
NSLog(@"AVlayer Not Accepting Data (I)");
}
});
Is there a way to give this task priority over User Interface actions like scrolling a Collection View etc? Apologies for lack of understanding I am reasonably new to IOS.
Turns out the UICollectionView was blocking the delegate calls for NSURLConnection on the main thread. This solved the problem:
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request
delegate:self];
changed to
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request
delegate:self
startImmediately:NO];
[connection scheduleInRunLoop:[NSRunLoop currentRunLoop]
forMode:NSRunLoopCommonModes];
[connection start];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With