- (void)captureOutput:(AVCaptureOutput )captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection )connection
这个代理方法偶尔会发生crash
相关代码
// - (AVCaptureVideoDataOutput *)captureDataOutput {
if (!_captureDataOutput) {
_captureDataOutput = [[AVCaptureVideoDataOutput alloc] init];
_captureDataOutput.alwaysDiscardsLateVideoFrames = YES;
_sessionQueue = dispatch_queue_create("cameraQueue", NULL);
[_captureDataOutput setSampleBufferDelegate:self queue:_sessionQueue];
NSString* formatKey = (NSString*)kCVPixelBufferPixelFormatTypeKey;
NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA];
NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:formatKey];
[_captureDataOutput setVideoSettings:videoSettings];
}
return _captureDataOutput;
}
这个问题困扰我很长时间了 但是就是不知道问题根源 望大神搭救