2011-10-21 5 views
1

iPhone用のライブラリを作成しようとしています。そのため、電話をかけてカメラを初期化しようとしています。ライブラリ内のAVCaptureVideoDataOutputを設定する方法

"[captureOutput setSampleBufferDelegate:self queue:queue];" 

コンパイラが言うので: 問題は、私はこの宣言では、「自己」を呼び出したときに来て、私は同じクラスを設定するために何をする必要がありますどのような、「自己がこのスコープで宣言されていませんでした」 " AVCaptureVideoDataOutputSampleBufferDelegate "?少なくとも正しい方向に私を向ける:P。

ありがとうございます!ここ

が完了関数です

bool VideoCamera_Init(){ 


    //Init Capute from the camera and show the camera 


    /*We setup the input*/ 
    AVCaptureDeviceInput *captureInput = [AVCaptureDeviceInput 
              deviceInputWithDevice:[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo] 
              error:nil]; 
    /*We setupt the output*/ 
    AVCaptureVideoDataOutput *captureOutput = [[AVCaptureVideoDataOutput alloc] init]; 
    /*While a frame is processes in -captureOutput:didOutputSampleBuffer:fromConnection: delegate methods no other frames are added in the queue. 
    If you don't want this behaviour set the property to NO */ 
    captureOutput.alwaysDiscardsLateVideoFrames = YES; 
    /*We specify a minimum duration for each frame (play with this settings to avoid having too many frames waiting 
    in the queue because it can cause memory issues). It is similar to the inverse of the maximum framerate. 
    In this example we set a min frame duration of 1/10 seconds so a maximum framerate of 10fps. We say that 
    we are not able to process more than 10 frames per second.*/ 
    captureOutput.minFrameDuration = CMTimeMake(1, 20); 

    /*We create a serial queue to handle the processing of our frames*/ 
    dispatch_queue_t queue; 
    queue = dispatch_queue_create("cameraQueue", NULL); 
    variableconnombrealeatorio= [[VideoCameraThread alloc] init]; 
    [captureOutput setSampleBufferDelegate:self queue:queue]; 


    dispatch_release(queue); 
    // Set the video output to store frame in BGRA (It is supposed to be faster) 
    NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey; 
    NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA]; 
    NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key]; 
    [captureOutput setVideoSettings:videoSettings]; 
    /*And we create a capture session*/ 
    AVCaptureSession * captureSession = [[AVCaptureSession alloc] init]; 
    captureSession.sessionPreset= AVCaptureSessionPresetMedium; 
    /*We add input and output*/ 
    [captureSession addInput:captureInput]; 
    [captureSession addOutput:captureOutput]; 
    /*We start the capture*/ 
    [captureSession startRunning]; 


    return TRUE; 
} 

私も次の授業をしましたが、バッファが空である:

の#import "VideoCameraThread.h"

CMSampleBufferRef bufferCamara;

@implementation VideoCameraThr EAD

  • (ボイド)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)接続 {bufferCamera = sampleBuffer。

    } 「

答えて

1

あなたはObjective Cのクラス、オブジェクトまたはself識別子の概念がないC関数を、書いている。あなたは受け入れるようにパラメータを取るためにあなたの関数を修正する必要がありますあなたが使用したいというsampleBufferDelegate:

bool VideoCamera_Init(id<AVCaptureAudioDataOutputSampleBufferDelegate> sampleBufferDelegate) { 
    ... 
    [captureOutput setSampleBufferDelegate:sampleBufferDelegate queue:queue]; 
    ... 
} 

それとも、Objective Cのオブジェクト指向のインターフェイスではなく、C形式のインターフェイスで、あなたのライブラリーを書くことができ

この機能では、メモリ管理にも問題があります。たとえば、AVCaptureSessionを割り当てて、それをローカル変数に割り当てるとします。この関数が返された後は、AVCaptureSessionを解放できるようにAVCaptureSessionを取得する方法がありません。

関連する問題