twilio / video-quickstart-ios

Twilio Video Quickstart for iOS
https://www.twilio.com/docs/api/video
MIT License
460 stars 178 forks source link

Frozen video after coming to foreground from background (similar to 445) #477

Closed jigar007 closed 4 years ago

jigar007 commented 4 years ago

Description

[Description of the issue] Local camera freezes after we send app in the background and take back to the foreground.

I'm getting following errors (similar to https://github.com/twilio/video-quickstart-ios/issues/445) ERROR:Twilio:Platform: Fatal runtime capture error: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12780), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x282d3a160 {Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"}}, code -11800

Camera source failed with error: The operation could not be completed

Also

[BackgroundTask] Background Task 38 ("Called by TwilioVideo, from -[TVICameraCapturePipeline videoPipelineWillStartRunning]"), was created over 30 seconds ago. In applications running in the background, this creates a risk of termination. Remember to call UIApplication.endBackgroundTask(_:) for your task in a timely manner to avoid this.

Code

Same as an example app

Reproduces How Often

Each time

Video iOS SDK

TwilioVideo (3.2.3) via CocoaPods

Xcode

Version 11.4.1 (11E503a)

iOS Version

13.4.1

iOS Device

iPhone XS MAX Iphone 6s

Tried solution

deinit {
    // We are done with camera
    if let camera = self.camera {
        camera.stopCapture()
        self.camera = nil
    }
} 
jigar007 commented 4 years ago

@piyushtank @ceaglest Can you please help asap, as App is in production.

ceaglest commented 4 years ago

Hi @jigar007,

It sounds like you have more than one TVICameraSource. Two questions to help:

  1. Can you use Xcode's memory graph debugger to confirm if there is more than one AVCaptureSession / TVICameraSource / TVICameraCapturePipleline active?
  2. Can you confirm with Xcode's debugger that the deinit code you provided is actually being called?

Thanks, Chris

jigar007 commented 4 years ago

Hi @ceaglest ,

I think the problem is solved now. deinit was not being called. What I did was, I put below code in buttonAction before going to another VC, where I was using CameraSource again.

if let camera = self.camera {
        camera.stopCapture()
        self.camera = nil
}

But thank you for commenting, I got this idea from your answer only.

Jigar

ceaglest commented 4 years ago

HI @jigar007,

Awesome news! It sounds like the issue is resolved, let us know if you need any more help in the future.

Cheers, Chris