diff --git a/Signal/src/call/CallService.swift b/Signal/src/call/CallService.swift index ae39f6f5b..83d6d92e9 100644 --- a/Signal/src/call/CallService.swift +++ b/Signal/src/call/CallService.swift @@ -1422,7 +1422,7 @@ private class SignalCallData: NSObject { self.handleDataChannelMessage(dataChannelMessage) } - internal func peerConnectionClient(_ peerConnectionClient: PeerConnectionClient, didUpdateLocal videoTrack: RTCVideoTrack?) { + internal func peerConnectionClient(_ peerConnectionClient: PeerConnectionClient, didUpdateLocalVideoTrack videoTrack: RTCVideoTrack?, captureSession: AVCaptureSession?) { SwiftAssertIsOnMainThread(#function) guard peerConnectionClient == self.peerConnectionClient else { @@ -1434,11 +1434,13 @@ private class SignalCallData: NSObject { return } + // MJK TODO remove localVideo Track? callData.localVideoTrack = videoTrack + callData.localCaptureSession = captureSession fireDidUpdateVideoTracks() } - internal func peerConnectionClient(_ peerConnectionClient: PeerConnectionClient, didUpdateRemote videoTrack: RTCVideoTrack?) { + internal func peerConnectionClient(_ peerConnectionClient: PeerConnectionClient, didUpdateRemoteVideoTrack videoTrack: RTCVideoTrack?) { SwiftAssertIsOnMainThread(#function) guard peerConnectionClient == self.peerConnectionClient else { diff --git a/Signal/src/call/PeerConnectionClient.swift b/Signal/src/call/PeerConnectionClient.swift index cb141ce30..c74e5369d 100644 --- a/Signal/src/call/PeerConnectionClient.swift +++ b/Signal/src/call/PeerConnectionClient.swift @@ -58,12 +58,12 @@ protocol PeerConnectionClientDelegate: class { /** * Fired whenever the local video track become active or inactive. */ - func peerConnectionClient(_ peerconnectionClient: PeerConnectionClient, didUpdateLocal videoTrack: RTCVideoTrack?) + func peerConnectionClient(_ peerconnectionClient: PeerConnectionClient, didUpdateLocalVideoTrack videoTrack: RTCVideoTrack?, captureSession: AVCaptureSession?) /** * Fired whenever the remote video track become active or inactive. */ - func peerConnectionClient(_ peerconnectionClient: PeerConnectionClient, didUpdateRemote videoTrack: RTCVideoTrack?) + func peerConnectionClient(_ peerconnectionClient: PeerConnectionClient, didUpdateRemoteVideoTrack videoTrack: RTCVideoTrack?) } // In Swift (at least in Swift v3.3), weak variables aren't thread safe. It @@ -383,9 +383,16 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD let proxyCopy = self.proxy let completion = { guard let strongSelf = proxyCopy.get() else { return } + + // Should these really be guards? Don't we want to pass nil when it's been disabled? guard let localVideoTrack = strongSelf.localVideoTrack else { return } + guard let videoCaptureSession = strongSelf.videoCaptureSession else { return } guard let strongDelegate = strongSelf.delegate else { return } - strongDelegate.peerConnectionClient(strongSelf, didUpdateLocal: enabled ? localVideoTrack : nil) + + let videoTrack = enabled ? localVideoTrack : nil + let captureSession = enabled ? videoCaptureSession : nil + + strongDelegate.peerConnectionClient(strongSelf, didUpdateLocalVideoTrack: videoTrack, captureSession: captureSession) } PeerConnectionClient.signalingQueue.async { @@ -398,19 +405,25 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD Logger.debug("\(strongSelf.logTag) \(#function) Ignoring obsolete event in terminated client") return } - guard let videoCaptureSession = strongSelf.videoCaptureSession else { +// guard let videoCaptureSession = strongSelf.videoCaptureSession else { +// Logger.debug("\(strongSelf.logTag) \(#function) Ignoring obsolete event in terminated client") +// return +// } + + guard let videoCaptureController = strongSelf.videoCaptureController else { Logger.debug("\(strongSelf.logTag) \(#function) Ignoring obsolete event in terminated client") return } - localVideoTrack.isEnabled = enabled if enabled { Logger.debug("\(strongSelf.logTag) in \(#function) starting videoCaptureSession") - videoCaptureSession.startRunning() + videoCaptureController.startCapture() +// videoCaptureSession.startRunning() } else { Logger.debug("\(strongSelf.logTag) in \(#function) stopping videoCaptureSession") - videoCaptureSession.stopRunning() + videoCaptureController.stopCapture() +// videoCaptureSession.stopRunning() } DispatchQueue.main.async(execute: completion) @@ -872,7 +885,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD // TODO: Consider checking for termination here. - strongDelegate.peerConnectionClient(strongSelf, didUpdateRemote: remoteVideoTrack) + strongDelegate.peerConnectionClient(strongSelf, didUpdateRemoteVideoTrack: remoteVideoTrack) } PeerConnectionClient.signalingQueue.async {