Objective-C++ cannot initialize parameter of type id<...> with lvalue of type MyType *__strong even though it conforms to protocol -
i'm trying use avkit in osx objective-c++ application, , have videosource
class conforms avcaptureaudiodataoutputsamplebufferdelegate
, compiler won't accept parameter of type id<avcapturevideodataoutputsamplebufferdelegate>
. error: capture.mm:30:48: cannot initialize parameter of type 'id<avcapturevideodataoutputsamplebufferdelegate>' lvalue of type 'videosource *__strong'
this code:
capture.h
#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
capture.mm
#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 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]; }
i'm not sure what's this, seems videosource
should of type id<avcaptureaudiodataoutputsamplebufferdelegate>
. what's going on?
you using avcapturevideodataoutput
, you've declared conformance avcaptureaudiodataoutputsamplebufferdelegate
protocol. protocols use same method, can change name of protocol (or adopt both if desire).
Comments
Post a Comment