From eeb4bf78199f40f810fc6dc9bf3305e41f4a9f33 Mon Sep 17 00:00:00 2001 From: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Sat, 21 Oct 2023 19:32:21 +0900 Subject: [PATCH] Fix: `CameraCapturer` report actual frame dimensions (#263) * fix * comment --- .../Track/Capturers/CameraCapturer.swift | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Sources/LiveKit/Track/Capturers/CameraCapturer.swift b/Sources/LiveKit/Track/Capturers/CameraCapturer.swift index 9bfbb7477..19f9fbd65 100644 --- a/Sources/LiveKit/Track/Capturers/CameraCapturer.swift +++ b/Sources/LiveKit/Track/Capturers/CameraCapturer.swift @@ -24,8 +24,6 @@ import ReplayKit public class CameraCapturer: VideoCapturer { - private let capturer: RTCCameraVideoCapturer - @objc public static func captureDevices() -> [AVCaptureDevice] { DispatchQueue.liveKitWebRTC.sync { RTCCameraVideoCapturer.captureDevices() } @@ -80,8 +78,12 @@ public class CameraCapturer: VideoCapturer { } } + // RTCCameraVideoCapturer used internally for now + private lazy var capturer: RTCCameraVideoCapturer = { + DispatchQueue.liveKitWebRTC.sync { RTCCameraVideoCapturer(delegate: self) } + }() + init(delegate: RTCVideoCapturerDelegate, options: CameraCaptureOptions) { - self.capturer = DispatchQueue.liveKitWebRTC.sync { RTCCameraVideoCapturer(delegate: delegate) } self.options = options super.init(delegate: delegate) @@ -205,8 +207,6 @@ public class CameraCapturer: VideoCapturer { // update internal vars self.device = device - // this will trigger to re-compute encodings for sender parameters if dimensions have updated - self.dimensions = self.options.dimensions // successfully started resolve(true) @@ -239,6 +239,16 @@ public class CameraCapturer: VideoCapturer { } } +extension CameraCapturer: RTCVideoCapturerDelegate { + + public func capturer(_ capturer: RTCVideoCapturer, didCapture frame: RTCVideoFrame) { + // Resolve real dimensions (apply frame rotation) + self.dimensions = Dimensions(width: frame.width, height: frame.height).apply(rotation: frame.rotation) + // Pass frame to video source + delegate?.capturer(capturer, didCapture: frame) + } +} + extension LocalVideoTrack { @objc