我正在尝试在OSX Objective-C ++应用程序中使用AVKit,并且我有一个符合VideoSource
的{{1}}类,但编译器不接受它作为类型的参数AVCaptureAudioDataOutputSampleBufferDelegate
。我收到此错误:id<AVCaptureVideoDataOutputSampleBufferDelegate>
这是我的代码:
Capture.mm:30:48: Cannot initialize a parameter of type 'id<AVCaptureVideoDataOutputSampleBufferDelegate>' with an lvalue of type 'VideoSource *__strong'
#ifndef ThreesAI_Capture_h
#define ThreesAI_Capture_h
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
@interface VideoSource : NSObject <AVCaptureAudioDataOutputSampleBufferDelegate>
@property AVCaptureSession *s;
- (id) init;
@end
#endif
void hello();
#endif
我不确定这是什么,因为#import "Capture.h"
@implementation VideoSource
- (id) init {
if (self = [super init]) {
self.s = [[AVCaptureSession alloc] init];
AVCaptureDevice *camera = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo][0];
NSError *e;
AVCaptureInput *cameraInput = [AVCaptureDeviceInput deviceInputWithDevice:camera error:&e];
[self.s addInput:cameraInput];
AVCaptureVideoDataOutput *captureOutput = [[AVCaptureVideoDataOutput alloc] init];
captureOutput.alwaysDiscardsLateVideoFrames = YES;
dispatch_queue_t queue;
queue = dispatch_queue_create("cameraQueue", NULL);
[captureOutput setSampleBufferDelegate:self queue:queue];//Error on this line
[self.s addOutput:captureOutput];
[self.s startRunning];
}
return self;
}
- (void) captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
NSLog(@"asdasd");
}
@end
void hello() {
VideoSource *v = [[VideoSource alloc] init];
}
似乎应该是VideoSource
类型。发生了什么事?
答案 0 :(得分:1)
您正在使用AVCaptureVideoDataOutput
,但您只声明了与AVCaptureAudioDataOutputSampleBufferDelegate
协议的一致性。协议使用相同的方法,因此您只需更改协议的名称(或者如果您愿意,可以采用这两种方法)。