Skip to content

Commit

Permalink
Fix: CameraCapturer report actual frame dimensions (livekit#263)
Browse files Browse the repository at this point in the history
* fix

* comment
  • Loading branch information
hiroshihorie authored Oct 21, 2023
1 parent cc56faa commit eeb4bf7
Showing 1 changed file with 15 additions and 5 deletions.
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

0 comments on commit eeb4bf7

Please sign in to comment.