Only PCC needs to know about the local RTCTrack

pull/1/head
Michael Kirk 7 years ago
parent afa385feae
commit 61156656aa

@ -72,7 +72,6 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
var remoteVideoView: RemoteVideoView! var remoteVideoView: RemoteVideoView!
var localVideoView: RTCCameraPreviewView! var localVideoView: RTCCameraPreviewView!
var hasShownLocalVideo = false var hasShownLocalVideo = false
weak var localVideoTrack: RTCVideoTrack?
weak var localCaptureSession: AVCaptureSession? weak var localCaptureSession: AVCaptureSession?
weak var remoteVideoTrack: RTCVideoTrack? weak var remoteVideoTrack: RTCVideoTrack?
@ -1001,16 +1000,10 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
// MARK: - Video // MARK: - Video
// MJK TODO remove localVideoTrack? internal func updateLocalVideo(captureSession: AVCaptureSession?) {
internal func updateLocalVideoTrack(localVideoTrack: RTCVideoTrack?,
captureSession: AVCaptureSession?) {
SwiftAssertIsOnMainThread(#function) SwiftAssertIsOnMainThread(#function)
guard self.localVideoTrack != localVideoTrack else {
return
}
self.localVideoTrack = localVideoTrack
localVideoView.captureSession = captureSession localVideoView.captureSession = captureSession
let isHidden = captureSession == nil let isHidden = captureSession == nil
@ -1118,14 +1111,12 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
// Do nothing. // Do nothing.
} }
// TODO remove localCaptureSession:
internal func didUpdateVideoTracks(call: SignalCall?, internal func didUpdateVideoTracks(call: SignalCall?,
localVideoTrack: RTCVideoTrack?,
localCaptureSession: AVCaptureSession?, localCaptureSession: AVCaptureSession?,
remoteVideoTrack: RTCVideoTrack?) { remoteVideoTrack: RTCVideoTrack?) {
SwiftAssertIsOnMainThread(#function) SwiftAssertIsOnMainThread(#function)
updateLocalVideoTrack(localVideoTrack: localVideoTrack, captureSession: localCaptureSession) updateLocalVideo(captureSession: localCaptureSession)
updateRemoteVideoTrack(remoteVideoTrack: remoteVideoTrack) updateRemoteVideoTrack(remoteVideoTrack: remoteVideoTrack)
} }
} }

@ -93,9 +93,7 @@ protocol CallServiceObserver: class {
/** /**
* Fired whenever the local or remote video track become active or inactive. * Fired whenever the local or remote video track become active or inactive.
*/ */
// TODO remove localCaptureSession:
func didUpdateVideoTracks(call: SignalCall?, func didUpdateVideoTracks(call: SignalCall?,
localVideoTrack: RTCVideoTrack?,
localCaptureSession: AVCaptureSession?, localCaptureSession: AVCaptureSession?,
remoteVideoTrack: RTCVideoTrack?) remoteVideoTrack: RTCVideoTrack?)
} }
@ -119,14 +117,6 @@ private class SignalCallData: NSObject {
let rejectReadyToSendIceUpdatesPromise: ((Error) -> Void) let rejectReadyToSendIceUpdatesPromise: ((Error) -> Void)
let readyToSendIceUpdatesPromise: Promise<Void> let readyToSendIceUpdatesPromise: Promise<Void>
weak var localVideoTrack: RTCVideoTrack? {
didSet {
SwiftAssertIsOnMainThread(#function)
Logger.info("\(self.logTag) \(#function)")
}
}
weak var localCaptureSession: AVCaptureSession? { weak var localCaptureSession: AVCaptureSession? {
didSet { didSet {
SwiftAssertIsOnMainThread(#function) SwiftAssertIsOnMainThread(#function)
@ -285,13 +275,6 @@ private class SignalCallData: NSObject {
return callData?.peerConnectionClient return callData?.peerConnectionClient
} }
} }
var localVideoTrack: RTCVideoTrack? {
get {
SwiftAssertIsOnMainThread(#function)
return callData?.localVideoTrack
}
}
weak var localCaptureSession: AVCaptureSession? { weak var localCaptureSession: AVCaptureSession? {
get { get {
@ -1422,7 +1405,7 @@ private class SignalCallData: NSObject {
self.handleDataChannelMessage(dataChannelMessage) self.handleDataChannelMessage(dataChannelMessage)
} }
internal func peerConnectionClient(_ peerConnectionClient: PeerConnectionClient, didUpdateLocalVideoTrack videoTrack: RTCVideoTrack?, captureSession: AVCaptureSession?) { internal func peerConnectionClient(_ peerConnectionClient: PeerConnectionClient, didUpdateLocalVideoCaptureSession captureSession: AVCaptureSession?) {
SwiftAssertIsOnMainThread(#function) SwiftAssertIsOnMainThread(#function)
guard peerConnectionClient == self.peerConnectionClient else { guard peerConnectionClient == self.peerConnectionClient else {
@ -1434,8 +1417,6 @@ private class SignalCallData: NSObject {
return return
} }
// MJK TODO remove localVideo Track?
callData.localVideoTrack = videoTrack
callData.localCaptureSession = captureSession callData.localCaptureSession = captureSession
fireDidUpdateVideoTracks() fireDidUpdateVideoTracks()
} }
@ -1639,7 +1620,6 @@ private class SignalCallData: NSObject {
// Synchronize observer with current call state // Synchronize observer with current call state
let remoteVideoTrack = self.isRemoteVideoEnabled ? self.remoteVideoTrack : nil let remoteVideoTrack = self.isRemoteVideoEnabled ? self.remoteVideoTrack : nil
observer.didUpdateVideoTracks(call: self.call, observer.didUpdateVideoTracks(call: self.call,
localVideoTrack: self.localVideoTrack,
localCaptureSession: self.localCaptureSession, localCaptureSession: self.localCaptureSession,
remoteVideoTrack: remoteVideoTrack) remoteVideoTrack: remoteVideoTrack)
} }
@ -1666,7 +1646,6 @@ private class SignalCallData: NSObject {
let remoteVideoTrack = self.isRemoteVideoEnabled ? self.remoteVideoTrack : nil let remoteVideoTrack = self.isRemoteVideoEnabled ? self.remoteVideoTrack : nil
for observer in observers { for observer in observers {
observer.value?.didUpdateVideoTracks(call: self.call, observer.value?.didUpdateVideoTracks(call: self.call,
localVideoTrack: self.localVideoTrack,
localCaptureSession: self.localCaptureSession, localCaptureSession: self.localCaptureSession,
remoteVideoTrack: remoteVideoTrack) remoteVideoTrack: remoteVideoTrack)
} }

@ -58,7 +58,7 @@ protocol PeerConnectionClientDelegate: class {
/** /**
* Fired whenever the local video track become active or inactive. * Fired whenever the local video track become active or inactive.
*/ */
func peerConnectionClient(_ peerconnectionClient: PeerConnectionClient, didUpdateLocalVideoTrack videoTrack: RTCVideoTrack?, captureSession: AVCaptureSession?) func peerConnectionClient(_ peerconnectionClient: PeerConnectionClient, didUpdateLocalVideoCaptureSession captureSession: AVCaptureSession?)
/** /**
* Fired whenever the remote video track become active or inactive. * Fired whenever the remote video track become active or inactive.
@ -235,12 +235,12 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
private var videoCaptureController: VideoCaptureController? private var videoCaptureController: VideoCaptureController?
private var videoCaptureSession: AVCaptureSession? private var videoCaptureSession: AVCaptureSession?
private var videoSender: RTCRtpSender? private var videoSender: RTCRtpSender?
private var localVideoTrack: RTCVideoTrack?
private var localVideoSource: RTCVideoSource? private var localVideoSource: RTCVideoSource?
// RTCVideoTrack is fragile and prone to throwing exceptions and/or // RTCVideoTrack is fragile and prone to throwing exceptions and/or
// causing deadlock in its destructor. Therefore we take great care // causing deadlock in its destructor. Therefore we take great care
// with this property. // with this property.
private var localVideoTrack: RTCVideoTrack?
private var remoteVideoTrack: RTCVideoTrack? private var remoteVideoTrack: RTCVideoTrack?
private var cameraConstraints: RTCMediaConstraints private var cameraConstraints: RTCMediaConstraints
@ -347,7 +347,6 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
let localVideoTrack = factory.videoTrack(with: videoSource, trackId: Identifiers.videoTrack.rawValue) let localVideoTrack = factory.videoTrack(with: videoSource, trackId: Identifiers.videoTrack.rawValue)
self.localVideoTrack = localVideoTrack self.localVideoTrack = localVideoTrack
self.videoCaptureController = VideoCaptureController(capturer: capturer, settingsDelegate: self) self.videoCaptureController = VideoCaptureController(capturer: capturer, settingsDelegate: self)
// Disable by default until call is connected. // Disable by default until call is connected.
@ -385,14 +384,12 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
guard let strongSelf = proxyCopy.get() else { return } guard let strongSelf = proxyCopy.get() else { return }
// Should these really be guards? Don't we want to pass nil when it's been disabled? // 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 videoCaptureSession = strongSelf.videoCaptureSession else { return }
guard let strongDelegate = strongSelf.delegate else { return } guard let strongDelegate = strongSelf.delegate else { return }
let videoTrack = enabled ? localVideoTrack : nil
let captureSession = enabled ? videoCaptureSession : nil let captureSession = enabled ? videoCaptureSession : nil
strongDelegate.peerConnectionClient(strongSelf, didUpdateLocalVideoTrack: videoTrack, captureSession: captureSession) strongDelegate.peerConnectionClient(strongSelf, didUpdateLocalVideoCaptureSession: captureSession)
} }
PeerConnectionClient.signalingQueue.async { PeerConnectionClient.signalingQueue.async {
@ -401,29 +398,24 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
Logger.debug("\(strongSelf.logTag) \(#function) Ignoring obsolete event in terminated client") Logger.debug("\(strongSelf.logTag) \(#function) Ignoring obsolete event in terminated client")
return return
} }
guard let localVideoTrack = strongSelf.localVideoTrack else {
guard let videoCaptureController = strongSelf.videoCaptureController else {
Logger.debug("\(strongSelf.logTag) \(#function) Ignoring obsolete event in terminated client") Logger.debug("\(strongSelf.logTag) \(#function) Ignoring obsolete event in terminated client")
return return
} }
// guard let videoCaptureSession = strongSelf.videoCaptureSession else {
// Logger.debug("\(strongSelf.logTag) \(#function) Ignoring obsolete event in terminated client")
// return
// }
guard let videoCaptureController = strongSelf.videoCaptureController else { guard let localVideoTrack = strongSelf.localVideoTrack else {
Logger.debug("\(strongSelf.logTag) \(#function) Ignoring obsolete event in terminated client") Logger.debug("\(strongSelf.logTag) \(#function) Ignoring obsolete event in terminated client")
return return
} }
localVideoTrack.isEnabled = enabled localVideoTrack.isEnabled = enabled
if enabled { if enabled {
Logger.debug("\(strongSelf.logTag) in \(#function) starting videoCaptureSession") Logger.debug("\(strongSelf.logTag) in \(#function) starting video capture")
videoCaptureController.startCapture() videoCaptureController.startCapture()
// videoCaptureSession.startRunning()
} else { } else {
Logger.debug("\(strongSelf.logTag) in \(#function) stopping videoCaptureSession") Logger.debug("\(strongSelf.logTag) in \(#function) stopping video capture")
videoCaptureController.stopCapture() videoCaptureController.stopCapture()
// videoCaptureSession.stopRunning()
} }
DispatchQueue.main.async(execute: completion) DispatchQueue.main.async(execute: completion)

@ -272,7 +272,6 @@ extension CallUIAdaptee {
} }
internal func didUpdateVideoTracks(call: SignalCall?, internal func didUpdateVideoTracks(call: SignalCall?,
localVideoTrack: RTCVideoTrack?,
localCaptureSession: AVCaptureSession?, localCaptureSession: AVCaptureSession?,
remoteVideoTrack: RTCVideoTrack?) { remoteVideoTrack: RTCVideoTrack?) {
SwiftAssertIsOnMainThread(#function) SwiftAssertIsOnMainThread(#function)

Loading…
Cancel
Save