From b5b51eba24f780f8e767a7335030394a6ea13c3d Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 26 Jun 2018 10:17:32 -0600 Subject: [PATCH] CR: make members private where possible add missing weak capture // FREEBIE --- Signal/src/call/PeerConnectionClient.swift | 60 ++++++++++++---------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/Signal/src/call/PeerConnectionClient.swift b/Signal/src/call/PeerConnectionClient.swift index 5f6e16225..ff2960ea3 100644 --- a/Signal/src/call/PeerConnectionClient.swift +++ b/Signal/src/call/PeerConnectionClient.swift @@ -387,7 +387,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD return nil } - return captureController.capturer.captureSession + return captureController.captureSession }() strongDelegate.peerConnectionClient(strongSelf, didUpdateLocalVideoCaptureSession: captureSession) @@ -1116,15 +1116,13 @@ protocol VideoCaptureSettingsDelegate: class { class VideoCaptureController { - let serialQueue = DispatchQueue(label: "org.signal.videoCaptureController") - let capturer: RTCCameraVideoCapturer - weak var settingsDelegate: VideoCaptureSettingsDelegate? - var isUsingFrontCamera: Bool = true + private let capturer: RTCCameraVideoCapturer + private weak var settingsDelegate: VideoCaptureSettingsDelegate? + private let serialQueue = DispatchQueue(label: "org.signal.videoCaptureController") + private var isUsingFrontCamera: Bool = true - func assertIsOnSerialQueue() { - if _isDebugAssertConfiguration(), #available(iOS 10.0, *) { - assertOnQueue(serialQueue) - } + public var captureSession: AVCaptureSession { + return capturer.captureSession } public init(capturer: RTCCameraVideoCapturer, settingsDelegate: VideoCaptureSettingsDelegate) { @@ -1142,6 +1140,33 @@ class VideoCaptureController { } } + public func stopCapture() { + serialQueue.sync { [weak self] in + guard let strongSelf = self else { + return + } + + strongSelf.capturer.stopCapture() + } + } + + public func switchCamera(isUsingFrontCamera: Bool) { + serialQueue.sync { [weak self] in + guard let strongSelf = self else { + return + } + + strongSelf.isUsingFrontCamera = isUsingFrontCamera + strongSelf.startCaptureSync() + } + } + + private func assertIsOnSerialQueue() { + if _isDebugAssertConfiguration(), #available(iOS 10.0, *) { + assertOnQueue(serialQueue) + } + } + private func startCaptureSync() { assertIsOnSerialQueue() @@ -1160,23 +1185,6 @@ class VideoCaptureController { capturer.startCapture(with: device, format: format, fps: fps) } - public func stopCapture() { - serialQueue.sync { [weak self] in - guard let strongSelf = self else { - return - } - - strongSelf.capturer.stopCapture() - } - } - - public func switchCamera(isUsingFrontCamera: Bool) { - serialQueue.sync { - self.isUsingFrontCamera = isUsingFrontCamera - self.startCaptureSync() - } - } - private func device(position: AVCaptureDevice.Position) -> AVCaptureDevice? { let captureDevices = RTCCameraVideoCapturer.captureDevices() guard let device = (captureDevices.first { $0.position == position }) else {