Question

Possible duplicate of iPhone: AVCaptureSession capture output crashing (AVCaptureVideoDataOutput)

I am created a app with custom camera whih is used for video recording. With the use of AVCaptureSession and AVCaptureVideoDataOutput, i got recorded video file. Every thing works fine for IOS 6 and lower version. but When i run the same app on device with IOS7 application is crash while deallocating the camera class with this issue...

thread #1: tid = 0x7994, 0x3b1eab26 libobjc.A.dylib`objc_msgSend + 6, stop reason = EXC_BAD_ACCESS (code=1, address=0x7000000c)
    frame #0: 0x3b1eab26 libobjc.A.dylib`objc_msgSend + 6
    frame #1: 0x2fa46654 AVFoundation`-[AVCaptureVideoDataOutput _applyOverridesToCaptureOptions:] + 172
    frame #2: 0x3387b050 UIKit` stub helpers + 27224 

The code which i am using for setting up the video data output --

[_captureSession beginConfiguration];

        if([_captureSession canAddInput:_captureDeviceInputAudio])
            [_captureSession addInput:_captureDeviceInputAudio];

         _captureOutputAudio = [[AVCaptureAudioDataOutput alloc] init] ;
        if([_captureSession canAddOutput:_captureOutputAudio])
            [_captureSession addOutput:_captureOutputAudio];


        _captureDeviceVideo = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
        _captureDeviceInputVideo = [AVCaptureDeviceInput deviceInputWithDevice:_captureDeviceVideo error:&error];


        if([_captureSession canAddInput:_captureDeviceInputVideo])
            [_captureSession addInput:_captureDeviceInputVideo];

        _captureOutputVideo = [[AVCaptureVideoDataOutput alloc] init] ;

        if([_captureSession canAddOutput:_captureOutputVideo])
             [_captureSession addOutput:_captureOutputVideo];




            [_captureOutputAudio setSampleBufferDelegate:self queue:_captureVideoDispatchQueue];
            [_captureOutputVideo setSampleBufferDelegate:self queue:_captureVideoDispatchQueue];
            dispatch_release(_captureSessionDispatchQueue);
            dispatch_release(_captureVideoDispatchQueue);



            NSString *sessionPreset = [_captureSession sessionPreset];
            AVCaptureConnection *videoConnection = [_captureOutputVideo connectionWithMediaType:AVMediaTypeAudio];

            [self _setOrientationForConnection:videoConnection];

            // setup stabilization, if available
            if ([videoConnection isVideoStabilizationSupported])
                [videoConnection setEnablesVideoStabilizationWhenAvailable:YES];

            // setup pixel format
            NSDictionary *videoSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
                                           [NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange], (id)kCVPixelBufferPixelFormatTypeKey,
                                           nil];
            [_captureOutputVideo setVideoSettings:videoSettings];

            // discard late frames
            [_captureOutputVideo setAlwaysDiscardsLateVideoFrames:NO];

            // setup video to use 640 x 480 for the hightest quality touch-to-record
            if ( [_captureSession canSetSessionPreset:AVCaptureSessionPreset640x480] )
                sessionPreset = AVCaptureSessionPreset640x480;

            // set the framerate and preset
            CMTime frameDuration = CMTimeMake( 1, 30 );
            if ( videoConnection.supportsVideoMinFrameDuration )
                videoConnection.videoMinFrameDuration = frameDuration; // needs to be applied to session in iOS 7
            if ( videoConnection.supportsVideoMaxFrameDuration )
                videoConnection.videoMaxFrameDuration = frameDuration;

I didn't get why it is happening for IOS7 while on lower version it works fine. Need help you guys. Thanks in advance.

Was it helpful?

Solution

For me, I remove all audio and video inputs and outputs which i added on session in viewDidUnload method before any line in this method. Now it is working fine in all iOS versions.

For removing inputs/outputs:

[_captureSession removeInput:_captureDeviceInputAudio];
[_captureSession removeOutput:_captureOutputAudio];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top