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

Fix: CameraCapturer report actual frame dimensions #263

Merged
merged 2 commits into from
Oct 21, 2023
Merged
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
20 changes: 15 additions & 5 deletions Sources/LiveKit/Track/Capturers/CameraCapturer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down