Skip to content

Commit 8f6e7aa

Browse files
authored
Set RTCCameraVideoCapturer initial zoom factor (#121)
Some devices, such as `.builtInTripleCamera`, have a zoom factor of 2.0 for the normal zoom. This adjustment changes it to 2.0 instead of 1.0. Without this adjustment, when using `.builtInTripleCamera`, it will appear zoomed out.
1 parent 9316c03 commit 8f6e7aa

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

sdk/objc/components/capturer/RTCCameraVideoCapturer.m

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ - (void)startCaptureWithDevice:(AVCaptureDevice *)device
175175

176176
NSError *error = nil;
177177
if (![self.currentDevice lockForConfiguration:&error]) {
178-
RTCLogError(@"Failed to lock device %@. Error: %@",
179-
self.currentDevice,
178+
RTCLogError(@"Failed to lock device %@. Error: %@", self.currentDevice,
180179
error.userInfo);
181180
if (completionHandler) {
182181
completionHandler(error);
@@ -187,6 +186,7 @@ - (void)startCaptureWithDevice:(AVCaptureDevice *)device
187186
[self reconfigureCaptureSessionInput];
188187
[self updateDeviceCaptureFormat:format fps:fps];
189188
[self updateVideoDataOutputPixelFormat:format];
189+
[self updateZoomFactor];
190190
[self.captureSession startRunning];
191191
[self.currentDevice unlockForConfiguration];
192192
self.isRunning = YES;
@@ -287,7 +287,7 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput
287287
RTC_OBJC_TYPE(RTCCVPixelBuffer) *rtcPixelBuffer =
288288
[[RTC_OBJC_TYPE(RTCCVPixelBuffer) alloc] initWithPixelBuffer:pixelBuffer];
289289
int64_t timeStampNs = CMTimeGetSeconds(CMSampleBufferGetPresentationTimeStamp(sampleBuffer)) *
290-
kNanosecondsPerSecond;
290+
kNanosecondsPerSecond;
291291
RTC_OBJC_TYPE(RTCVideoFrame) *videoFrame =
292292
[[RTC_OBJC_TYPE(RTCVideoFrame) alloc] initWithBuffer:rtcPixelBuffer
293293
rotation:_rotation
@@ -417,8 +417,7 @@ - (void)handleApplicationDidBecomeActive:(NSNotification *)notification {
417417
- (dispatch_queue_t)frameQueue {
418418
if (!_frameQueue) {
419419
_frameQueue = RTCDispatchQueueCreateWithTarget(
420-
"org.webrtc.cameravideocapturer.video",
421-
DISPATCH_QUEUE_SERIAL,
420+
"org.webrtc.cameravideocapturer.video", DISPATCH_QUEUE_SERIAL,
422421
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0));
423422
}
424423
return _frameQueue;
@@ -500,6 +499,18 @@ - (void)updateDeviceCaptureFormat:(AVCaptureDeviceFormat *)format fps:(NSInteger
500499
}
501500
}
502501

502+
- (void)updateZoomFactor {
503+
NSAssert([RTC_OBJC_TYPE(RTCDispatcher) isOnQueueForType:RTCDispatcherTypeCaptureSession],
504+
@"updateZoomFactor must be called on the capture queue.");
505+
506+
#if TARGET_OS_IOS || TARGET_OS_TV
507+
CGFloat firstSwitchOverZoomFactor = 1.0;
508+
NSNumber *first = _currentDevice.virtualDeviceSwitchOverVideoZoomFactors.firstObject;
509+
if (first != nil) firstSwitchOverZoomFactor = first.doubleValue;
510+
_currentDevice.videoZoomFactor = firstSwitchOverZoomFactor;
511+
#endif
512+
}
513+
503514
- (void)reconfigureCaptureSessionInput {
504515
NSAssert([RTC_OBJC_TYPE(RTCDispatcher) isOnQueueForType:RTCDispatcherTypeCaptureSession],
505516
@"reconfigureCaptureSessionInput must be called on the capture queue.");

0 commit comments

Comments
 (0)