[AVCapture] Torch is not turning off instantly, after called device.torchMode = .off and getting dim images after torch

Describe the bug What we want is, we wanna capture image, after torched for few seconds. It's working fine from lowest to iPhoneX. Start from iPhone 11 to latest the torch is not turning off instantly, when the function called the torched off. It's turning off after a few milliseconds I guess, kind of delay in turning off. And after flash, few images are dim and dark. Trigger the torch method is look like below.

Steps To Reproduce Steps to reproduce the behavior:

  1. Trigger torch for 2 seconds
  2. Turn off the torch
  3. Then, check the images from the preview stream.

**Note: It's only happen from iPhone11 to higher model . ** ...

Expected behavior A clear and concise description of what you expected to happen. The torch supposed to stop instantly after we turn off, like we want the same behavior from iPhoneX to lower model.

Screenshots This is the first image that we got after we stop the torch

And the second image looks dark and dim, it supposed to be same because we locked the exposure, white balance, other staff

Environment (please fill out the following information)

  • OS: M1 pro
  • Xcode Version/Tag/Branch: Version 13.4.1 (13F100)

Additional context trigger flash code snippet

public func triggerFlash() {
        sessionQueue.async {
            if let device = self.device {
                let milliseconds = 2000
                let seconds: Double = Double(milliseconds / 1000)
                
                if device.hasTorch {
                    do {
                        try device.lockForConfiguration()
                        // Set Torch brightness to max
                        try device.setTorchModeOn(level:  AVCaptureDevice.maxAvailableTorchLevel)
                        device.torchMode = .on
                        device.unlockForConfiguration()
                        Logger.log("Torch On")
                        self.sessionQueue.asyncAfter(deadline: .now() + seconds) {
                            do {
                                let device = self.device!
                                try device.lockForConfiguration()
                                device.torchMode = .off
                                device.unlockForConfiguration()
                                Logger.log("Torch Off")
                            } catch {
                                Error.throwNative(result, "try device.lockForConfiguration() Failed in triggerFlash() \(error)")
                            }
                        }
                    } catch {
                        Error.throwNative(result, "try device.lockForConfiguration() Failed in triggerFlash() \(error)")
                    }
                } else {
                    result(false)
                }
            } else {
                Error.throwNative(result, "First select and start the camera")
                return
            }
        }
    }
[AVCapture] Torch is not turning off instantly, after called device.torchMode = .off and getting dim images after torch
 
 
Q