dave on code
dave on code

Reputation: 21

AVCaptureSession start memory warnings

each time I start a AVCaptureSession I receive a memory warning leading to crashes after time.
I'm starting the session asynchronously and the Instruments tool says the application consumes about 2 MB memory. Do you have any idea how to overcome that issue? Are 2MB of allocated memory too much?

Thankx! [iOS 4.3, ARC]

@autoreleasepool {
    //Init capture session
    session = [[AVCaptureSession alloc] init];
    session.sessionPreset = AVCaptureSessionPresetPhoto;


    //Resize container view
    CGRect cameraContainerFrame = cameraContainerView.frame;
    cameraContainerFrame.size = CGSizeMake(320, 426);
    cameraContainerView.frame = cameraContainerFrame;

    CALayer *viewLayer = [cameraContainerView layer];
    [viewLayer setMasksToBounds:YES];

    //Create preview layer
    captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];

    CGRect bounds = [cameraContainerView bounds];
    [captureVideoPreviewLayer setFrame:bounds];


    if ([captureVideoPreviewLayer isOrientationSupported]) {
        [captureVideoPreviewLayer setOrientation:AVCaptureVideoOrientationPortrait];
    }    
    [captureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];

    [viewLayer addSublayer:captureVideoPreviewLayer];

    //Get input device
    captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

    if ([captureDevice lockForConfiguration:nil]){
        captureDevice.focusMode = AVCaptureFocusModeContinuousAutoFocus;
        captureDevice.whiteBalanceMode = AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance;
        [captureDevice unlockForConfiguration];
    }

    NSError *error = nil;
    AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:captureDevice error:&error];
    if (!input) {
        // Handle the error appropriately.
        DLog(@"ERROR: trying to open camera: %@", error);
    }
    //Add input to session
    [session addInput:input];

    //Output
    stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
    NSDictionary *outputSettings = [NSDictionary dictionaryWithObject:AVVideoCodecJPEG forKey:AVVideoCodecKey];
    [stillImageOutput setOutputSettings:outputSettings];
    [session addOutput:stillImageOutput];

    //Save state
    cameraSessionInitialized = YES;
    [session startRunning];
}

Upvotes: 2

Views: 1717

Answers (1)

k20
k20

Reputation: 2008

session.sessionPreset = AVCaptureSessionPresetMedium;

If you don't care about quality, this does get rid of memory warnings. I'm trying to figure out how to get it working with the AVCaptureSessionPresetPhoto.

Upvotes: 9

Related Questions