0

I am recording video in my app. My app crashes in iOS 7.0.x only. My application is crashing while writing the captured video in file. Below is my code to setup session & toggle camera

    - (BOOL) setupSessionWithPreview:(UIView *)preview usingFrontCamera:(BOOL)frontCamera
{
    AVCaptureDevice *videoDevice = nil;
    if (frontCamera) {
        videoDevice = [self getFrontCamera];
        self.videoDeviceType = VideoDeviceTypeFrontCamera;
    }
    else {
        videoDevice = [self getRearCamera];
        self.videoDeviceType = VideoDeviceTypeRearCamera;
    }
    AVCaptureDevice *audioDevice = [self getAudioDevice];

    self.videoInput = [[AVCaptureDeviceInput alloc] initWithDevice:videoDevice error:nil];
    AVCaptureDeviceInput *audioInput = [[AVCaptureDeviceInput alloc] initWithDevice:audioDevice error:nil];

    self.session = [[AVCaptureSession alloc] init];
    if([self.session canAddInput:self.videoInput])
        [self.session addInput:self.videoInput];

    if([self.session canAddInput:audioInput])
        [self.session addInput:audioInput];

    self.audioOutput = [[AVCaptureAudioDataOutput alloc] init];
    dispatch_queue_t audioCaptureQ = dispatch_queue_create("Audio Capture Q", DISPATCH_QUEUE_SERIAL);
    [self.audioOutput setSampleBufferDelegate:self queue:audioCaptureQ];

    if([self.session canAddOutput:self.audioOutput])
        [self.session addOutput:self.audioOutput];
    self.audioConnection = [self.audioOutput connectionWithMediaType:AVMediaTypeAudio];

    self.videoOutput = [[AVCaptureVideoDataOutput alloc] init];
    [self.videoOutput setAlwaysDiscardsLateVideoFrames:YES];

    dispatch_queue_t videoCaptureQ = dispatch_queue_create("Video Capture Q", DISPATCH_QUEUE_SERIAL);
    [self.videoOutput setSampleBufferDelegate:self queue:videoCaptureQ];

    if([self.session canAddOutput:self.videoOutput])
        [self.session addOutput:self.videoOutput];

    self.videoConnection = [self.videoOutput connectionWithMediaType:AVMediaTypeVideo];

    self.videoConnection.videoOrientation = AVCaptureVideoOrientationPortrait;
    self.videoOrientation = [self.videoConnection videoOrientation];

    movieWriterQ = dispatch_queue_create("Movie Writer Q", DISPATCH_QUEUE_SERIAL);

    self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.session];
    self.viewLayer = [preview layer];
    [self.viewLayer setMasksToBounds:YES];

    CGRect bounds = [preview bounds];
    [self.previewLayer setFrame:bounds];

    [self.previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
    [self.viewLayer insertSublayer:self.previewLayer below:[[self.viewLayer sublayers] objectAtIndex:0]];

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [self.session startRunning];
    });

    return YES;
}

// Code to toggle camera

    -(void)toggleCameraIsFront:(BOOL)isFront
{
    AVCaptureDevicePosition desiredPosition;
    if (isFront) {
        desiredPosition = AVCaptureDevicePositionFront;
        self.videoDeviceType = VideoDeviceTypeFrontCamera;
    }
    else {
        desiredPosition = AVCaptureDevicePositionBack;
        self.videoDeviceType = VideoDeviceTypeRearCamera;
    }


    NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
    for (AVCaptureDevice *device in videoDevices)
    {
        if ([device position] == desiredPosition)
        {
            AVCaptureDeviceInput *videoDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];
            [self.session beginConfiguration];
            [self.session removeInput:self.videoInput];
            if ([self.session canAddInput:videoDeviceInput])
            {
                [self.session addInput:videoDeviceInput];
                [self setVideoInput:videoDeviceInput];
            }
            else
            {
                [self.session addInput:self.videoInput];
            }

            [self.session removeOutput:self.videoOutput];

            AVCaptureVideoDataOutput *videoDeviceOutput = [[AVCaptureVideoDataOutput alloc] init];
            if ([self.session canAddOutput:videoDeviceOutput])
            {
                [self.session addOutput:videoDeviceOutput];
                [self setVideoOutput:videoDeviceOutput];
                [self.videoOutput setAlwaysDiscardsLateVideoFrames:YES];

                // How to manage previously created videoCaptureQ in setupSessionWithPreview method ???
                // or do we need create instance variable as dispatch_queue_t videoCaptureQ ???
                dispatch_queue_t videoCaptureQ = dispatch_queue_create("Video Capture Q", DISPATCH_QUEUE_SERIAL);
                [self.videoOutput setSampleBufferDelegate:self queue:videoCaptureQ];

                self.videoConnection = [self.videoOutput connectionWithMediaType:AVMediaTypeVideo];

                self.videoConnection.videoOrientation = AVCaptureVideoOrientationPortrait;
                self.videoOrientation = [self.videoConnection videoOrientation];
            }
            else
            {
                [self.session addOutput:self.videoOutput];
            }

            [self.session commitConfiguration];
            break;
        }
    }
}

// Code responsible for crashing in iOS 7.0.x ONLY, Works perfectly with iOS 6.x & iOS 7.1

@property(nonatomic, retain) AVAssetWriter *writer;
@property(nonatomic, retain) AVAssetReader *reader;
@property(nonatomic, retain) AVAssetReaderVideoCompositionOutput *videoOut;
@property(nonatomic, retain) AVAssetReaderOutput *audioOut;
@property(nonatomic, retain) AVAssetWriterInput *videoIn;
@property(nonatomic, retain) AVAssetWriterInput *audioIn;

dispatch_group_enter(self.dispatchGroup);
[self.videoIn requestMediaDataWhenReadyOnQueue:self.videoWriterQ usingBlock:^(void) {
    if(self.videoFinished)
        return;

    BOOL completedOrFailed = NO;
    while([self.videoIn isReadyForMoreMediaData] && !completedOrFailed)
    {
        // App crashes here .
        CMSampleBufferRef sample = [self.videoOut copyNextSampleBuffer];
        if(sample != NULL)
        {
            BOOL bret = [self.videoIn appendSampleBuffer:sample];
            CFRelease(sample);
            sample = NULL;
            completedOrFailed = !bret;
        }
        else
        {
            completedOrFailed = YES;
        }
    }
    if(completedOrFailed)
    {
        if(!self.videoFinished)
        {
            [self.videoIn markAsFinished];
        }
        self.videoFinished = YES;
        dispatch_group_leave(self.dispatchGroup);
    }
}];

Here is the crash log

    Date/Time:           2014-04-07 11:05:34.917 +0100
OS Version:          iOS 7.0.6 (11B651)
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x7176d7e0
Triggered by Thread:  0

Thread 0 Crashed:
0   libobjc.A.dylib                 0x3848bb26 objc_msgSend + 6
1   AVFoundation                    0x2cf78650 -[AVCaptureVideoDataOutput _applyOverridesToCaptureOptions:] + 168
2   AVFoundation                    0x2cf7081c -[AVCaptureSession _resolvedCaptureOptionsByApplyingOverridesToCaptureOptions:preset:] + 344
3   AVFoundation                    0x2cf70b2c -[AVCaptureSession _resolvedCaptureOptionsForPreset:audioDevice:videoDevice:] + 108
4   AVFoundation                    0x2cf7235c -[AVCaptureSession _buildAndRunGraph] + 312
5   AVFoundation                    0x2cf6cc3c -[AVCaptureSession removeInput:] + 1008
6   AVFoundation                    0x2cf6ae0c -[AVCaptureSession dealloc] + 172
7   Foundation                      0x2e9d1a44 NSKVODeallocate + 60
8   libobjc.A.dylib                 0x3849bb06 objc_object::sidetable_release(bool) + 170
9   libobjc.A.dylib                 0x3848d002 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 354
10  QuartzCore                      0x3043e864 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 64
11  CoreFoundation                  0x2e01b1ca __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 18
12  CoreFoundation                  0x2e018b6c __CFRunLoopDoObservers + 280
13  CoreFoundation                  0x2e018eae __CFRunLoopRun + 726
14  CoreFoundation                  0x2df83c22 CFRunLoopRunSpecific + 518
15  CoreFoundation                  0x2df83a06 CFRunLoopRunInMode + 102
16  GraphicsServices                0x32caa27e GSEventRunModal + 134
17  UIKit                           0x30827044 UIApplicationMain + 1132
18  AppName                         0x0013ed06 main (main.m:17)
19  libdyld.dylib                   0x38998ab4 start + 0

Thread 1:
0   libsystem_kernel.dylib          0x38a3c83c kevent64 + 24
1   libdispatch.dylib               0x3897d210 _dispatch_mgr_invoke + 228
2   libdispatch.dylib               0x3897cf96 _dispatch_mgr_thread$VARIANT$mp + 34

Thread 2 name:  com.apple.NSURLConnectionLoader
Thread 2:
0   libsystem_kernel.dylib          0x38a3ca8c mach_msg_trap + 20
1   libsystem_kernel.dylib          0x38a3c888 mach_msg + 44
2   CoreFoundation                  0x2e01a7be __CFRunLoopServiceMachPort + 150
3   CoreFoundation                  0x2e018ee4 __CFRunLoopRun + 780
4   CoreFoundation                  0x2df83c22 CFRunLoopRunSpecific + 518
5   CoreFoundation                  0x2df83a06 CFRunLoopRunInMode + 102
6   Foundation                      0x2e9be2f2 +[NSURLConnection(Loader) _resourceLoadLoop:] + 314
7   Foundation                      0x2ea33c82 __NSThread__main__ + 1058
8   libsystem_pthread.dylib         0x38ab7c1a _pthread_body + 138
9   libsystem_pthread.dylib         0x38ab7b8a _pthread_start + 98
10  libsystem_pthread.dylib         0x38ab5c8c thread_start + 4

Thread 3 name:  com.apple.CFSocket.private
Thread 3:
0   libsystem_kernel.dylib          0x38a4f440 __select + 20
1   CoreFoundation                  0x2e01e680 __CFSocketManager + 480
2   libsystem_pthread.dylib         0x38ab7c1a _pthread_body + 138
3   libsystem_pthread.dylib         0x38ab7b8a _pthread_start + 98
4   libsystem_pthread.dylib         0x38ab5c8c thread_start + 4

Thread 4 name:  AFNetworking
Thread 4:
0   libsystem_kernel.dylib          0x38a3ca8c mach_msg_trap + 20
1   libsystem_kernel.dylib          0x38a3c888 mach_msg + 44
2   CoreFoundation                  0x2e01a7be __CFRunLoopServiceMachPort + 150
3   CoreFoundation                  0x2e018ee4 __CFRunLoopRun + 780
4   CoreFoundation                  0x2df83c22 CFRunLoopRunSpecific + 518
5   CoreFoundation                  0x2df83a06 CFRunLoopRunInMode + 102
6   Foundation                      0x2e9713d6 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 250
7   Foundation                      0x2e9c230c -[NSRunLoop(NSRunLoop) run] + 76
8   AppName                         0x001637b6 +[AFURLConnectionOperation networkRequestThreadEntryPoint:] (AFURLConnectionOperation.m:184)
9   Foundation                      0x2ea33c82 __NSThread__main__ + 1058
10  libsystem_pthread.dylib         0x38ab7c1a _pthread_body + 138
11  libsystem_pthread.dylib         0x38ab7b8a _pthread_start + 98
12  libsystem_pthread.dylib         0x38ab5c8c thread_start + 4

Thread 5 name:  com.apple.coremedia.player.async
Thread 5:
0   libsystem_kernel.dylib          0x38a3cadc semaphore_wait_trap + 8
1   libdispatch.dylib               0x3897b428 _dispatch_semaphore_wait_slow + 172
2   MediaToolbox                    0x2f46f83c fpa_AsyncMovieControlThread + 1752
3   CoreMedia                       0x2e5ae234 figThreadMain + 192
4   libsystem_pthread.dylib         0x38ab7c1a _pthread_body + 138
5   libsystem_pthread.dylib         0x38ab7b8a _pthread_start + 98
6   libsystem_pthread.dylib         0x38ab5c8c thread_start + 4

Thread 6:
0   libsystem_kernel.dylib          0x38a3ca8c mach_msg_trap + 20
1   libsystem_kernel.dylib          0x38a3c888 mach_msg + 44
2   CoreFoundation                  0x2e01a7be __CFRunLoopServiceMachPort + 150
3   CoreFoundation                  0x2e018ee4 __CFRunLoopRun + 780
4   CoreFoundation                  0x2df83c22 CFRunLoopRunSpecific + 518
5   CoreFoundation                  0x2df83a06 CFRunLoopRunInMode + 102
6   libAVFAudio.dylib               0x2d006584 GenericRunLoopThread::Entry(void*) + 124
7   libAVFAudio.dylib               0x2cffa99c CAPThread::Entry(CAPThread*) + 176
8   libsystem_pthread.dylib         0x38ab7c1a _pthread_body + 138
9   libsystem_pthread.dylib         0x38ab7b8a _pthread_start + 98
10  libsystem_pthread.dylib         0x38ab5c8c thread_start + 4

Thread 7 name:  com.apple.coremedia.player.async
Thread 7:
0   libsystem_kernel.dylib          0x38a3cadc semaphore_wait_trap + 8
1   libdispatch.dylib               0x3897b428 _dispatch_semaphore_wait_slow + 172
2   MediaToolbox                    0x2f46f83c fpa_AsyncMovieControlThread + 1752
3   CoreMedia                       0x2e5ae234 figThreadMain + 192
4   libsystem_pthread.dylib         0x38ab7c1a _pthread_body + 138
5   libsystem_pthread.dylib         0x38ab7b8a _pthread_start + 98
6   libsystem_pthread.dylib         0x38ab5c8c thread_start + 4

Thread 8 name:  com.apple.coremedia.player.remote
Thread 8:
0   libsystem_kernel.dylib          0x38a3ca8c mach_msg_trap + 20
1   libsystem_kernel.dylib          0x38a3c888 mach_msg + 44
2   MediaToolbox                    0x2f475c58 FigExpressNotificationThread + 84
3   CoreMedia                       0x2e5ae234 figThreadMain + 192
4   libsystem_pthread.dylib         0x38ab7c1a _pthread_body + 138
5   libsystem_pthread.dylib         0x38ab7b8a _pthread_start + 98
6   libsystem_pthread.dylib         0x38ab5c8c thread_start + 4

Thread 9:
0   libsystem_kernel.dylib          0x38a3ca8c mach_msg_trap + 20
1   libsystem_kernel.dylib          0x38a3c888 mach_msg + 44
2   CoreFoundation                  0x2e01a7be __CFRunLoopServiceMachPort + 150
3   CoreFoundation                  0x2e018ee4 __CFRunLoopRun + 780
4   CoreFoundation                  0x2df83c22 CFRunLoopRunSpecific + 518
5   CoreFoundation                  0x2dfc7736 CFRunLoopRun + 94
6   CoreMotion                      0x2e63a230 ___lldb_unnamed_function1404$$CoreMotion + 724
7   libsystem_pthread.dylib         0x38ab7c1a _pthread_body + 138
8   libsystem_pthread.dylib         0x38ab7b8a _pthread_start + 98
9   libsystem_pthread.dylib         0x38ab5c8c thread_start + 4

Thread 10 name:  com.apple.coremedia.player.async
Thread 10:
0   libsystem_kernel.dylib          0x38a3cadc semaphore_wait_trap + 8
1   libdispatch.dylib               0x3897b428 _dispatch_semaphore_wait_slow + 172
2   MediaToolbox                    0x2f46f83c fpa_AsyncMovieControlThread + 1752
3   CoreMedia                       0x2e5ae234 figThreadMain + 192
4   libsystem_pthread.dylib         0x38ab7c1a _pthread_body + 138
5   libsystem_pthread.dylib         0x38ab7b8a _pthread_start + 98
6   libsystem_pthread.dylib         0x38ab5c8c thread_start + 4

Thread 11:
0   libsystem_kernel.dylib          0x38a4fc7c __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x38ab5dc6 _pthread_wqthread + 306
2   libsystem_pthread.dylib         0x38ab5c80 start_wqthread + 4

Thread 12:
0   libsystem_kernel.dylib          0x38a4fc7c __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x38ab5dc6 _pthread_wqthread + 306
2   libsystem_pthread.dylib         0x38ab5c80 start_wqthread + 4

Thread 13:
0   libsystem_kernel.dylib          0x38a3ca8c mach_msg_trap + 20
1   libsystem_kernel.dylib          0x38a3c888 mach_msg + 44
2   MediaToolbox                    0x2f588594 FigRemakerFamilyClient_ReaderExtractAndRetainNextSampleBuffer + 92
3   MediaToolbox                    0x2f5835a0 remoteReader_ExtractAndRetainNextSampleBuffer + 108
4   AVFoundation                    0x2cf2a8ba -[AVAssetReaderOutput copyNextSampleBuffer] + 222
5   AppName                         0x0016a320 __36-[MediaWriter performWrite:onError:]_block_invoke141 (MediaWriter.m:188)
6   AVFoundation                    0x2cf3d810 -[AVAssetWriterInputMediaDataRequester requestMediaDataIfNecessary] + 84
7   libdispatch.dylib               0x38973d18 _dispatch_call_block_and_release + 8
8   libdispatch.dylib               0x3897a26e _dispatch_queue_drain$VARIANT$mp + 370
9   libdispatch.dylib               0x3897a066 _dispatch_queue_invoke$VARIANT$mp + 38
10  libdispatch.dylib               0x3897acde _dispatch_root_queue_drain + 74
11  libdispatch.dylib               0x3897af54 _dispatch_worker_thread2 + 52
12  libsystem_pthread.dylib         0x38ab5dbc _pthread_wqthread + 296
13  libsystem_pthread.dylib         0x38ab5c80 start_wqthread + 4

Thread 14 name:  com.apple.coremedia.player.async
Thread 14:
0   libsystem_kernel.dylib          0x38a3cadc semaphore_wait_trap + 8
1   libdispatch.dylib               0x3897b428 _dispatch_semaphore_wait_slow + 172
2   MediaToolbox                    0x2f46f83c fpa_AsyncMovieControlThread + 1752
3   CoreMedia                       0x2e5ae234 figThreadMain + 192
4   libsystem_pthread.dylib         0x38ab7c1a _pthread_body + 138
5   libsystem_pthread.dylib         0x38ab7b8a _pthread_start + 98
6   libsystem_pthread.dylib         0x38ab5c8c thread_start + 4

Thread 15:
0   libsystem_kernel.dylib          0x38a4fc7c __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x38ab5dc6 _pthread_wqthread + 306
2   libsystem_pthread.dylib         0x38ab5c80 start_wqthread + 4

Thread 16:
0   libsystem_kernel.dylib          0x38a4fc7c __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x38ab5dc6 _pthread_wqthread + 306
2   libsystem_pthread.dylib         0x38ab5c80 start_wqthread + 4

Thread 17:
0   libsystem_kernel.dylib          0x38a3ca8c mach_msg_trap + 20
1   libsystem_kernel.dylib          0x38a3c888 mach_msg + 44
2   MediaToolbox                    0x2f5896b4 FigRemakerFamilyClient_WriterAddSampleBuffer + 112
3   MediaToolbox                    0x2f581bec remoteWriter_AddSampleBuffer + 236
4   AVFoundation                    0x2cf3c144 -[AVFigAssetWriterTrack addSampleBuffer:error:] + 84
5   AVFoundation                    0x2cf3cfcc -[AVFigAssetWriterAudioTrack addSampleBuffer:error:] + 300
6   AVFoundation                    0x2cf39afa -[AVAssetWriterInputWritingHelper appendSampleBuffer:] + 74
7   AVFoundation                    0x2cf37d62 -[AVAssetWriterInput appendSampleBuffer:] + 46
8   AppName                         0x0016a190 __36-[MediaWriter performWrite:onError:]_block_invoke (MediaWriter.m:162)
9   AVFoundation                    0x2cf3d810 -[AVAssetWriterInputMediaDataRequester requestMediaDataIfNecessary] + 84
10  libdispatch.dylib               0x38973d18 _dispatch_call_block_and_release + 8
11  libdispatch.dylib               0x3897a26e _dispatch_queue_drain$VARIANT$mp + 370
12  libdispatch.dylib               0x3897a066 _dispatch_queue_invoke$VARIANT$mp + 38
13  libdispatch.dylib               0x3897acde _dispatch_root_queue_drain + 74
14  libdispatch.dylib               0x3897af54 _dispatch_worker_thread2 + 52
15  libsystem_pthread.dylib         0x38ab5dbc _pthread_wqthread + 296
16  libsystem_pthread.dylib         0x38ab5c80 start_wqthread + 4

Thread 18:
0   libsystem_kernel.dylib          0x38a3e664 fsync + 8
1   libsqlite3.dylib                0x3876d73c ___lldb_unnamed_function199$$libsqlite3.dylib + 44
2   libsqlite3.dylib                0x387a59e8 ___lldb_unnamed_function529$$libsqlite3.dylib + 1168
3   libsqlite3.dylib                0x3876d138 ___lldb_unnamed_function197$$libsqlite3.dylib + 336
4   libsqlite3.dylib                0x38763004 ___lldb_unnamed_function156$$libsqlite3.dylib + 552
5   libsqlite3.dylib                0x38744638 ___lldb_unnamed_function56$$libsqlite3.dylib + 1496
6   libsqlite3.dylib                0x3875fc32 ___lldb_unnamed_function123$$libsqlite3.dylib + 38026
7   libsqlite3.dylib                0x38755e2c sqlite3_step + 404
8   libsqlite3.dylib                0x38734952 sqlite3_exec + 358
9   CFNetwork                       0x2dc14d30 __CFURLCache::ExecSQLStatement_NoLock(sqlite3*, char const*, int (*)(void*, int, char**, char**), void*, long) + 32
10  CFNetwork                       0x2dc84bb8 __CFURLCache::_PreProcessCacheTasks() + 108
11  CFNetwork                       0x2dc849da __CFURLCache::_CFURLCacheTimerCallback0() + 630
12  CFNetwork                       0x2dc84754 __CFURLCache::_CFURLCacheTimerCallback(void*) + 28
13  libdispatch.dylib               0x3897c7fe _dispatch_source_invoke$VARIANT$mp + 258
14  libdispatch.dylib               0x3897a232 _dispatch_queue_drain$VARIANT$mp + 310
15  libdispatch.dylib               0x3897a066 _dispatch_queue_invoke$VARIANT$mp + 38
16  libdispatch.dylib               0x3897acde _dispatch_root_queue_drain + 74
17  libdispatch.dylib               0x3897af54 _dispatch_worker_thread2 + 52
18  libsystem_pthread.dylib         0x38ab5dbc _pthread_wqthread + 296
19  libsystem_pthread.dylib         0x38ab5c80 start_wqthread + 4

Thread 0 crashed with ARM Thread State (32-bit):
    r0: 0x176f9f60    r1: 0x30daa1e8      r2: 0x2cfeb38f      r3: 0x00000000
    r4: 0x30dba133    r5: 0x18e7bde0      r6: 0x30dad051      r7: 0x27d087f8
    r8: 0x38b3fc28    r9: 0x7176d7d4     r10: 0x1903c100     r11: 0x18fdbd70
    ip: 0x38b1e868    sp: 0x27d087c4      lr: 0x2cf78655      pc: 0x3848bb26
  cpsr: 0x60000030

Can anybody tell me what's going wrong in iOS 7.0.x ONLY ? On other iOS versions its working correctly. Any kind of help is appreciated.

Thanks.

iOSAppDev
  • 2,755
  • 4
  • 39
  • 77

1 Answers1

0

Did you dealloc correctly?

Try adding these lines to your dealloc method,

[self.session removeInput:self.videoIn];
[self.session removeOutput:self.videoOut];
Rukshan
  • 7,902
  • 6
  • 43
  • 61
  • Why do I need to do this if I am using the ARC ? – iOSAppDev Apr 09 '14 at 08:23
  • This is not releasing an object. This is a clean up task. You use dealloc (with ARC) if you want to do some cleanup tasks when your view is dismissing or released. It's the best place, in such case you can implement it. Another example is to remove an observer or close a network connection down cleanly. You are therefore allowed to subclass dealloc under ARC, but you are not allowed to call [super dealloc] from within the subclassed method. – Rukshan Apr 09 '14 at 08:31