Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set RTCCameraVideoCapturer initial zoom factor #121

Merged
merged 4 commits into from
May 28, 2024
Merged
Changes from 3 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
20 changes: 15 additions & 5 deletions sdk/objc/components/capturer/RTCCameraVideoCapturer.m
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ - (void)startCaptureWithDevice:(AVCaptureDevice *)device

NSError *error = nil;
if (![self.currentDevice lockForConfiguration:&error]) {
RTCLogError(@"Failed to lock device %@. Error: %@",
self.currentDevice,
RTCLogError(@"Failed to lock device %@. Error: %@", self.currentDevice,
error.userInfo);
if (completionHandler) {
completionHandler(error);
Expand All @@ -187,6 +186,7 @@ - (void)startCaptureWithDevice:(AVCaptureDevice *)device
[self reconfigureCaptureSessionInput];
[self updateDeviceCaptureFormat:format fps:fps];
[self updateVideoDataOutputPixelFormat:format];
[self updateZoomFactor];
[self.captureSession startRunning];
[self.currentDevice unlockForConfiguration];
self.isRunning = YES;
Expand Down Expand Up @@ -287,7 +287,7 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput
RTC_OBJC_TYPE(RTCCVPixelBuffer) *rtcPixelBuffer =
[[RTC_OBJC_TYPE(RTCCVPixelBuffer) alloc] initWithPixelBuffer:pixelBuffer];
int64_t timeStampNs = CMTimeGetSeconds(CMSampleBufferGetPresentationTimeStamp(sampleBuffer)) *
kNanosecondsPerSecond;
kNanosecondsPerSecond;
RTC_OBJC_TYPE(RTCVideoFrame) *videoFrame =
[[RTC_OBJC_TYPE(RTCVideoFrame) alloc] initWithBuffer:rtcPixelBuffer
rotation:_rotation
Expand Down Expand Up @@ -417,8 +417,7 @@ - (void)handleApplicationDidBecomeActive:(NSNotification *)notification {
- (dispatch_queue_t)frameQueue {
if (!_frameQueue) {
_frameQueue = RTCDispatchQueueCreateWithTarget(
"org.webrtc.cameravideocapturer.video",
DISPATCH_QUEUE_SERIAL,
"org.webrtc.cameravideocapturer.video", DISPATCH_QUEUE_SERIAL,
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0));
}
return _frameQueue;
Expand Down Expand Up @@ -500,6 +499,17 @@ - (void)updateDeviceCaptureFormat:(AVCaptureDeviceFormat *)format fps:(NSInteger
}
}

- (void)updateZoomFactor {
NSAssert([RTC_OBJC_TYPE(RTCDispatcher) isOnQueueForType:RTCDispatcherTypeCaptureSession],
@"updateZoomFactor must be called on the capture queue.");

#if TARGET_OS_IOS || TARGET_OS_TV
double firstSwitchOverZoomFactor =
_currentDevice.virtualDeviceSwitchOverVideoZoomFactors.firstObject.doubleValue ?: 1.0;
_currentDevice.videoZoomFactor = firstSwitchOverZoomFactor;
#endif
}

- (void)reconfigureCaptureSessionInput {
NSAssert([RTC_OBJC_TYPE(RTCDispatcher) isOnQueueForType:RTCDispatcherTypeCaptureSession],
@"reconfigureCaptureSessionInput must be called on the capture queue.");
Expand Down