Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk/objc/components/capturer/RTCCameraVideoCapturer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<AVCaptureDeviceFormat *> *)supportedFormatsForDevice:(AVCaptureDevice *)device;

+ (CGFloat)defaultZoomFactorForDeviceType:(AVCaptureDeviceType)deviceType;

// Returns the most efficient supported output pixel format for this capturer.
- (FourCharCode)preferredOutputPixelFormat;

Expand Down
29 changes: 24 additions & 5 deletions sdk/objc/components/capturer/RTCCameraVideoCapturer.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
}

Expand Down