使用AVCaptureSession时的内存警告

时间:2012-06-11 17:38:53

标签: ios xcode avcapturesession

我使用默认的AVCaptureSession捕获摄像机视图。一切正常。但它运行几秒钟并在调试器中记录消息内存警告并继续工作几秒钟然后应用程序终止。这可能是我实现的代码中的内存泄漏。但我不知道,为什么会这样, 除此之外,我在行中收到警告(将“ViewController * const_strong”发送到不兼容类型'id'的参数

[outputsetSampleBufferDelegate:selfqueue:queue];

............................................... .......... 我实施的代码,

-(void)setupCaptureSession
{
NSError *error=nil;
AVCaptureSession *session =[[AVCaptureSessionalloc]init];
self.captureSession=session;


self.captureSession.sessionPreset=AVCaptureSessionPresetMedium;

AVCaptureDevice *device =[AVCaptureDevicedefaultDeviceWithMediaType:AVMediaTypeVideo];

AVCaptureDeviceInput *Input=[AVCaptureDeviceInputdeviceInputWithDevice:deviceerror:&error];
if(!Input){
    }

    [[selfcaptureSession] addInput:Input];
AVCaptureVideoDataOutput *output =[[AVCaptureVideoDataOutputalloc]init];

    [[selfcaptureSession]addOutput:output];
dispatch_queue_t queue =dispatch_queue_create("myQueue", NULL);
    [outputsetSampleBufferDelegate:selfqueue:queue];
dispatch_release(queue);

output.videoSettings =[NSDictionarydictionaryWithObjectsAndKeys:[NSNumbernumberWithUnsignedInt:kCVPixelFormatType_32BGRA],(id)kCVPixelBufferPixelFormatTypeKey,nil];

AVCaptureConnection *connection =[output connectionWithMediaType:AVMediaTypeVideo];
    [connectionsetVideoMinFrameDuration:CMTimeMake(1,15)];

[sessionstartRunning];

    [selfsetSession:session];


}

-(UIImage *)imageFromSampleBuffer:(CMSampleBufferRef)sampleBuffer
{
CVImageBufferRefimageBuffer =CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(imageBuffer,0);

void *baseAddress =CVPixelBufferGetBaseAddress(imageBuffer);

size_tbytesPerRow =CVPixelBufferGetBytesPerRow(imageBuffer);
size_t width =CVPixelBufferGetWidth(imageBuffer);
size_t height=CVPixelBufferGetHeight(imageBuffer);

CGColorSpaceRefcolorSpace =CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(baseAddress,width,height,8,bytesPerRow,colorSpace,kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedLast);

CGImageRefquartzImage =CGBitmapContextCreateImage(context);
CVPixelBufferUnlockBaseAddress(imageBuffer,0);

CGContextRelease(context);
CGColorSpaceRelease(colorSpace);

UIImage *image =[UIImageimageWithCGImage:quartzImage];
CGImageRelease(quartzImage);

return image;
}
////////////////////

-(void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBufferfromConnection:(AVCaptureConnection *)connection{


UIImage *image = [selfimageFromSampleBuffer:sampleBuffer];
//Here i do my processing with image and display a count, Counter updates for few seconds and
  Log memory warning and then works again, Then application get terminates

}
-(void)setSession:(AVCaptureSession *)session
{
self.captureSession=session;
}

0 个答案:

没有答案