Camera freezing issue in iOS using webRTC video source

Skip to first unread message

Bhavani Chada

Sep 4, 2021, 6:47:56 AMSep 4
I have implemented video calling application using webRTC where i'm using RTCVideosource for to get the local video capturing.I'm facing freezing issue with camera while flipping and when call is coming from background.I have gone through lot of research but didn't find any solution.Here i'm posting the code for camera flipping and initialization.Can anyone please help on this.
I'm using below code for video capturing

let videoSource = self.peerConnectionFactory.videoSource()  
 self.videoCapturer = RTCCameraVideoCapturer(delegate: videoSource)  
  let videoTrack = self.peerConnectionFactory.videoTrack(with: videoSource, trackId: "video0")
and below is the code for to switch the camera

if let capturer = self.videoCapturer as? RTCCameraVideoCapturer { var targetDevice: AVCaptureDevice? var targetFormat: AVCaptureDevice.Format?

        // find target device
        let devicies = RTCCameraVideoCapturer.captureDevices()
        print("devices count is :\(devicies.count)")
        devicies.forEach { (device) in
            if device.position ==  cameraPositon{
                targetDevice = device
            else {
                print("camera position is:\(cameraPositon.rawValue)::\(device.position.rawValue):\(targetDevice)")
        // find target format
        let formats = RTCCameraVideoCapturer.supportedFormats(for: targetDevice!)
        print("supported formats are:\(formats)")
        formats.forEach { (format) in
            for _ in format.videoSupportedFrameRateRanges {
                let description = format.formatDescription as CMFormatDescription
                let dimensions = CMVideoFormatDescriptionGetDimensions(description)
                if dimensions.width == videoWidth && dimensions.height == videoHeight ?? 0{
                    targetFormat = format
                } else if dimensions.width == videoWidth {
                    targetFormat = format
        print("target format is :\(targetDevice):\(targetFormat)")
        capturer.startCapture(with: targetDevice!,
                              format: targetFormat!,
                              fps: videoFps)
Bhavani Chada
iOS Developer

John Mikelich

Sep 15, 2021, 7:02:49 PM (10 days ago) Sep 15
to discuss-webrtc
I've found that the webrtc capture session starts before the app is technically foregrounded, so then the capture session remains un-started.

Try putting in the didEnterFG notification listener, grabbing the captureSession from webrtc, and starting it again.

For example get 

RTCCameraVideoCapturer *rtcCapturer

from the setup of ARDCaptureController, then after a short wait (like a second)

[rtcCapturer.captureSession startRunning]

Bhavani Chada

Sep 23, 2021, 7:45:56 AM (2 days ago) Sep 23
Thank you so much for your help.It is resolved.


You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages