twilio / video-quickstart-ios

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

AVCaptureSession interruption event occurs when camera.startCapture(...) is called #648

Open david-podcastle opened 2 years ago

david-podcastle commented 2 years ago

Hi, Before integrating Twilio into our application we have set up audio/video recording which saves 5s length video chunks to local storage and then uploads to the remote server. Everything is classic here: first, we have var videoSession: AVCaptureSession. Then we add input and output and at the same time setting AVCaptureVideoDataOutputSampleBufferDelegate to the AVCaptureVideoDataOutput instance with setSampleBufferDelegate(...) method call. The following is easy, we just need to handle the following delegate method: captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) This gives as possibility to capture and save media chunks. Optionally we have also a video preview view setup with a video session object. The problem started to occur when we decided to integrate Twilio video into our app for video meetings. When the following Twilio method call occurs for a CameraSource object camera.startCapture(...) then we receive session interruption event with .videoDeviceInUseByAnotherClient reason and my AVCaptureVideoDataOutputSampleBufferDelegate captureOutput() method is stoping to work. If I restart AVCaptureSession then captureOutput() is starting to work but Twilio video is stopping to cast a video. This is a pretty complex situation since we are not applicable to change our video recording code based on pure AVFoundation implementation but at the same time, we should provide a video meeting feature. As soon as I could understand, a video session can have only one owner, and switching them drops the current owner. I am totally unable to find any solution as I have tried to find anything in Twilio documentation with no luck. Probably I miss something, maybe there is some way to use the existing session to broadcast the user's video? Any help is really appreciated and thank you in advance.