From cd100aefa6973729cb4b5e0a3909b0c8e405ac98 Mon Sep 17 00:00:00 2001 From: Vladimir Morosev Date: Sat, 24 Aug 2019 15:07:05 +0200 Subject: [PATCH 1/2] Media Stream added --- ClientCore/Signalling/Conductor.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ClientCore/Signalling/Conductor.cs b/ClientCore/Signalling/Conductor.cs index 7323a59..dff0de0 100644 --- a/ClientCore/Signalling/Conductor.cs +++ b/ClientCore/Signalling/Conductor.cs @@ -53,6 +53,7 @@ using PeerConnectionClientCore.Stats; #endif using System.Text; +using UseMediaStream = Org.WebRtc.IMediaStream; using UseMediaStreamTrack = Org.WebRtc.IMediaStreamTrack; using UseRTCPeerConnectionIceEvent = Org.WebRtc.IRTCPeerConnectionIceEvent; using UseRTCTrackEvent = Org.WebRtc.IRTCTrackEvent; @@ -184,6 +185,7 @@ public static Conductor Instance /// public Signaller Signaller => _signaller; + private UseMediaStream _selfStream; private UseMediaStreamTrack _peerVideoTrack; private UseMediaStreamTrack _selfVideoTrack; private UseMediaStreamTrack _peerAudioTrack; @@ -891,7 +893,7 @@ private void VideoCapturerFactory_OnCreateCustomVideoCapturer(ICustomVideoCaptur async private Task CreatePeerConnection(CancellationToken cancelationToken) { Debug.Assert(PeerConnection == null); - if(cancelationToken.IsCancellationRequested) + if (cancelationToken.IsCancellationRequested) { return false; } @@ -1137,6 +1139,8 @@ await _uiDispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => }; #endif //ENABLE_VIDEO_PROCESSING + _selfStream = MediaStream.CreateLocalMediaStream("SELF_STREAM", _factory); + var parameters = new VideoCapturerCreationParameters(); parameters.Name = _selectedVideoDevice.Name; parameters.Id = _selectedVideoDevice.Id; @@ -1165,8 +1169,10 @@ await _uiDispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => #if !ORTCLIB Debug.WriteLine("Conductor: Adding local media tracks."); - PeerConnection.AddTrack(_selfVideoTrack); - PeerConnection.AddTrack(_selfAudioTrack); + _selfStream.AddTrack(_selfVideoTrack); + _selfStream.AddTrack(_selfAudioTrack); + PeerConnection.AddTrack(_selfVideoTrack, new List { _selfStream.Id }); + PeerConnection.AddTrack(_selfAudioTrack, new List { _selfStream.Id }); #endif OnAddLocalTrack?.Invoke(_selfVideoTrack); OnAddLocalTrack?.Invoke(_selfAudioTrack); From d43889a7aee3fdf2bcbba484e4235c67a35201aa Mon Sep 17 00:00:00 2001 From: Vladimir Morosev Date: Sun, 25 Aug 2019 22:59:23 +0200 Subject: [PATCH 2/2] Fixed camera closing issue --- ClientCore/Signalling/Conductor.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ClientCore/Signalling/Conductor.cs b/ClientCore/Signalling/Conductor.cs index dff0de0..8087ea3 100644 --- a/ClientCore/Signalling/Conductor.cs +++ b/ClientCore/Signalling/Conductor.cs @@ -1241,14 +1241,19 @@ private void ClosePeerConnection() if (null != _peerVideoTrack) _peerVideoTrack.Element = null; // Org.WebRtc.MediaElementMaker.Bind(obj); if (null != _selfVideoTrack) _selfVideoTrack.Element = null; // Org.WebRtc.MediaElementMaker.Bind(obj); #endif + PeerConnection.RemoveTrack(PeerConnection.GetSenders()[0]); + PeerConnection.RemoveTrack(PeerConnection.GetSenders()[1]); + (_peerVideoTrack as IDisposable)?.Dispose(); (_selfVideoTrack as IDisposable)?.Dispose(); (_peerAudioTrack as IDisposable)?.Dispose(); (_selfAudioTrack as IDisposable)?.Dispose(); + (_selfStream as IDisposable)?.Dispose(); _peerVideoTrack = null; _selfVideoTrack = null; _peerAudioTrack = null; _selfAudioTrack = null; + _selfStream = null; OnPeerConnectionClosed?.Invoke();