2017-05-02 66 views
0

未調用DidOutputSampleBuffer委託,但在設置攝像頭代碼中找不到任何問題。在github代碼:Demo code未調用AVCaptureVideoDataOutput委託

我在我的會議打印輸入輸出,他們有價值觀,預設也設置,任何人都可以幫助我嗎?

#import "DMVideoCamera.h" 
#import <UIKit/UIKit.h> 

@interface DMVideoCamera()<AVCaptureVideoDataOutputSampleBufferDelegate> 
@implementation DMVideoCamera 

- (instancetype)init { 
if (self = [super init]) { 
    [self setupCamera]; 
} 
return self; 
} 

- (void)setupCamera { 
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 
    return; 
} 
if([self isAVCaptureActive]) { 
    _captureQueue = dispatch_queue_create("com.dmall.ScanQueue", DISPATCH_QUEUE_SERIAL); 
    NSError *error = nil; 
    _device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 

    _session = [[AVCaptureSession alloc] init]; 
    [self configSessionPreset]; 

    _output = [[AVCaptureVideoDataOutput alloc] init]; 
    [_output setVideoSettings:@{ 
           (NSString *)kCVPixelBufferPixelFormatTypeKey : [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA] 
           }]; 
    [_output setAlwaysDiscardsLateVideoFrames:YES]; 
    [_output setSampleBufferDelegate:self queue:_captureQueue]; 

    _input = [AVCaptureDeviceInput deviceInputWithDevice:_device error:&error]; 
    if ([_session canAddInput:_input]) { 
     [_session addInput:_input]; 
    } 
    if ([_session canAddOutput:_output]) { 
     [_session addOutput:_output]; 
    } 

} 
else { 
    [self showAccessAlert]; 
} 
} 

而在的viewController,我這樣設置:Demo code

- (void)viewDidLoad { 
[super viewDidLoad]; 
DMVideoCamera *camera = [DMVideoCamera new]; 
AVCaptureVideoPreviewLayer *previewLayer =[AVCaptureVideoPreviewLayer layerWithSession:camera.session]; 
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; 
previewLayer.frame = self.view.bounds; 
[self.view.layer addSublayer:previewLayer]; 
camera.zoomFactor = 1.6; 
[camera start]; 
} 

如果要運行該項目,請從我的github上下載代碼。

非常感謝!

回答