From 58b58621d7c57494b28b1ede928ff5cc57fe4d58 Mon Sep 17 00:00:00 2001 From: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Tue, 28 May 2024 16:31:53 +0900 Subject: [PATCH 1/4] implement --- .../capturer/RTCCameraVideoCapturer.m | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sdk/objc/components/capturer/RTCCameraVideoCapturer.m b/sdk/objc/components/capturer/RTCCameraVideoCapturer.m index 018c1d41cf..3db5db15e6 100644 --- a/sdk/objc/components/capturer/RTCCameraVideoCapturer.m +++ b/sdk/objc/components/capturer/RTCCameraVideoCapturer.m @@ -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); @@ -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; @@ -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 @@ -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; @@ -500,6 +499,14 @@ - (void)updateDeviceCaptureFormat:(AVCaptureDeviceFormat *)format fps:(NSInteger } } +- (void)updateZoomFactor { + NSAssert([RTC_OBJC_TYPE(RTCDispatcher) isOnQueueForType:RTCDispatcherTypeCaptureSession], + @"updateZoomFactor must be called on the capture queue."); + double firstSwitchOverZoomFactor = + _currentDevice.virtualDeviceSwitchOverVideoZoomFactors.firstObject.doubleValue ?: 1.0; + _currentDevice.videoZoomFactor = firstSwitchOverZoomFactor; +} + - (void)reconfigureCaptureSessionInput { NSAssert([RTC_OBJC_TYPE(RTCDispatcher) isOnQueueForType:RTCDispatcherTypeCaptureSession], @"reconfigureCaptureSessionInput must be called on the capture queue."); From f19f921f6fd06a5e9f03009458a045d793275e50 Mon Sep 17 00:00:00 2001 From: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Tue, 28 May 2024 16:36:57 +0900 Subject: [PATCH 2/4] only for ios --- sdk/objc/components/capturer/RTCCameraVideoCapturer.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sdk/objc/components/capturer/RTCCameraVideoCapturer.m b/sdk/objc/components/capturer/RTCCameraVideoCapturer.m index 3db5db15e6..8f0adebeb4 100644 --- a/sdk/objc/components/capturer/RTCCameraVideoCapturer.m +++ b/sdk/objc/components/capturer/RTCCameraVideoCapturer.m @@ -502,9 +502,15 @@ - (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 double firstSwitchOverZoomFactor = _currentDevice.virtualDeviceSwitchOverVideoZoomFactors.firstObject.doubleValue ?: 1.0; _currentDevice.videoZoomFactor = firstSwitchOverZoomFactor; +#else + // Fallback code for macOS or other platforms + _currentDevice.videoZoomFactor = 1.0; +#endif } - (void)reconfigureCaptureSessionInput { From 9cfbbb2e06ebe70f29ba8f69aee6ea39ee51aea2 Mon Sep 17 00:00:00 2001 From: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Tue, 28 May 2024 16:41:35 +0900 Subject: [PATCH 3/4] only for ios & tvos --- sdk/objc/components/capturer/RTCCameraVideoCapturer.m | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/sdk/objc/components/capturer/RTCCameraVideoCapturer.m b/sdk/objc/components/capturer/RTCCameraVideoCapturer.m index 8f0adebeb4..2b3cd4f44b 100644 --- a/sdk/objc/components/capturer/RTCCameraVideoCapturer.m +++ b/sdk/objc/components/capturer/RTCCameraVideoCapturer.m @@ -503,13 +503,10 @@ - (void)updateZoomFactor { NSAssert([RTC_OBJC_TYPE(RTCDispatcher) isOnQueueForType:RTCDispatcherTypeCaptureSession], @"updateZoomFactor must be called on the capture queue."); -#if TARGET_OS_IOS +#if TARGET_OS_IOS || TARGET_OS_TV double firstSwitchOverZoomFactor = _currentDevice.virtualDeviceSwitchOverVideoZoomFactors.firstObject.doubleValue ?: 1.0; _currentDevice.videoZoomFactor = firstSwitchOverZoomFactor; -#else - // Fallback code for macOS or other platforms - _currentDevice.videoZoomFactor = 1.0; #endif } From c6bbd06f9f71c46c3728380927ee29b02e8c7fc1 Mon Sep 17 00:00:00 2001 From: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Wed, 29 May 2024 02:26:37 +0900 Subject: [PATCH 4/4] tweak --- sdk/objc/components/capturer/RTCCameraVideoCapturer.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sdk/objc/components/capturer/RTCCameraVideoCapturer.m b/sdk/objc/components/capturer/RTCCameraVideoCapturer.m index 2b3cd4f44b..f743fb8e0d 100644 --- a/sdk/objc/components/capturer/RTCCameraVideoCapturer.m +++ b/sdk/objc/components/capturer/RTCCameraVideoCapturer.m @@ -504,8 +504,9 @@ - (void)updateZoomFactor { @"updateZoomFactor must be called on the capture queue."); #if TARGET_OS_IOS || TARGET_OS_TV - double firstSwitchOverZoomFactor = - _currentDevice.virtualDeviceSwitchOverVideoZoomFactors.firstObject.doubleValue ?: 1.0; + CGFloat firstSwitchOverZoomFactor = 1.0; + NSNumber *first = _currentDevice.virtualDeviceSwitchOverVideoZoomFactors.firstObject; + if (first != nil) firstSwitchOverZoomFactor = first.doubleValue; _currentDevice.videoZoomFactor = firstSwitchOverZoomFactor; #endif }