diff --git a/sdk/objc/components/capturer/RTCCameraVideoCapturer.h b/sdk/objc/components/capturer/RTCCameraVideoCapturer.h index 370bfa70f0..74f0b39925 100644 --- a/sdk/objc/components/capturer/RTCCameraVideoCapturer.h +++ b/sdk/objc/components/capturer/RTCCameraVideoCapturer.h @@ -30,6 +30,8 @@ NS_EXTENSION_UNAVAILABLE_IOS("Camera not available in app extensions.") // Returns list of formats that are supported by this class for this device. + (NSArray *)supportedFormatsForDevice:(AVCaptureDevice *)device; ++ (CGFloat)defaultZoomFactorForDeviceType:(AVCaptureDeviceType)deviceType; + // Returns the most efficient supported output pixel format for this capturer. - (FourCharCode)preferredOutputPixelFormat; diff --git a/sdk/objc/components/capturer/RTCCameraVideoCapturer.m b/sdk/objc/components/capturer/RTCCameraVideoCapturer.m index f743fb8e0d..626c83f855 100644 --- a/sdk/objc/components/capturer/RTCCameraVideoCapturer.m +++ b/sdk/objc/components/capturer/RTCCameraVideoCapturer.m @@ -136,6 +136,26 @@ - (void)dealloc { return device.formats; } ++ (CGFloat)defaultZoomFactorForDeviceType:(AVCaptureDeviceType)deviceType { + // AVCaptureDeviceTypeBuiltInTripleCamera, Virtual, switchOver: [2, 6], default: 2 + // AVCaptureDeviceTypeBuiltInDualCamera, Virtual, switchOver: [3], default: 1 + // AVCaptureDeviceTypeBuiltInDualWideCamera, Virtual, switchOver: [2], default: 2 + // AVCaptureDeviceTypeBuiltInWideAngleCamera, Physical, General purpose use + // AVCaptureDeviceTypeBuiltInTelephotoCamera, Physical + // AVCaptureDeviceTypeBuiltInUltraWideCamera, Physical +#if TARGET_OS_IOS || TARGET_OS_TV + if (@available(iOS 13.0, tvOS 17.0, *)) { + if ([deviceType isEqualToString:AVCaptureDeviceTypeBuiltInTripleCamera] || + [deviceType isEqualToString:AVCaptureDeviceTypeBuiltInDualWideCamera]) + // For AVCaptureDeviceTypeBuiltInTripleCamera and AVCaptureDeviceTypeBuiltInDualWideCamera, + // it will switch over from ultra-wide to wide on 2.0, so to prefer wide by default. + return 2.0; + } +#endif + + return 1.0; +} + - (FourCharCode)preferredOutputPixelFormat { return _preferredOutputPixelFormat; } @@ -187,8 +207,9 @@ - (void)startCaptureWithDevice:(AVCaptureDevice *)device [self updateDeviceCaptureFormat:format fps:fps]; [self updateVideoDataOutputPixelFormat:format]; [self updateZoomFactor]; - [self.captureSession startRunning]; [self.currentDevice unlockForConfiguration]; + + [self.captureSession startRunning]; self.isRunning = YES; if (completionHandler) { completionHandler(nil); @@ -504,10 +525,8 @@ - (void)updateZoomFactor { @"updateZoomFactor must be called on the capture queue."); #if TARGET_OS_IOS || TARGET_OS_TV - CGFloat firstSwitchOverZoomFactor = 1.0; - NSNumber *first = _currentDevice.virtualDeviceSwitchOverVideoZoomFactors.firstObject; - if (first != nil) firstSwitchOverZoomFactor = first.doubleValue; - _currentDevice.videoZoomFactor = firstSwitchOverZoomFactor; + CGFloat videoZoomFactor = [[self class] defaultZoomFactorForDeviceType:_currentDevice.deviceType]; + [_currentDevice setVideoZoomFactor:videoZoomFactor]; #endif }