I have a video decoder playing H264 using AVSampleBufferDisplayLayer and everything works fine until I loop through the UICollectionViewController on the same view controller. This seems to block the main thread causing the application to crash. I tried to put this code in a block in a separate queue using dispatch_async, but still have the same locking problem as the additional 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 any way to give this priority tasks over user interface actions, such as scrolling through a collection, etc.? Apologies for the lack of understanding. I am new to iOS.
source share