From 118402520fec3bb1e05349d40c70c28f0b232a06 Mon Sep 17 00:00:00 2001 From: tkchin Date: Wed, 24 Aug 2016 12:05:56 -0700 Subject: [PATCH] Restart capture session if needed on active. We've seen some cases of nonrecoverable runtime error when entering the foreground. This is a theoretical fix to see if we can restart after willEnterForeground in didBecomeActive instead. NOTRY=True BUG= Review-Url: https://codereview.webrtc.org/2258583004 Cr-Commit-Position: refs/heads/master@{#13903} --- .../Classes/avfoundationvideocapturer.mm | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm b/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm index ddeedb5ab6..7025d888ec 100644 --- a/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm +++ b/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm @@ -137,6 +137,10 @@ static NSString *GetSessionPresetForVideoFormat( selector:@selector(handleCaptureSessionInterruptionEnded:) name:AVCaptureSessionInterruptionEndedNotification object:_captureSession]; + [center addObserver:self + selector:@selector(handleApplicationDidBecomeActive:) + name:UIApplicationDidBecomeActiveNotification + object:[UIApplication sharedApplication]]; #endif [center addObserver:self selector:@selector(handleCaptureSessionRuntimeError:) @@ -378,6 +382,22 @@ static NSString *GetSessionPresetForVideoFormat( }]; } +#if TARGET_OS_IPHONE + +#pragma mark - UIApplication notifications + +- (void)handleApplicationDidBecomeActive:(NSNotification *)notification { + [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeCaptureSession + block:^{ + if (self.hasStarted && !self.captureSession.isRunning) { + RTCLog(@"Restarting capture session on active."); + [self.captureSession startRunning]; + } + }]; +} + +#endif // TARGET_OS_IPHONE + #pragma mark - Private - (BOOL)setupCaptureSession {