Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MediaStream added #28

Open
wants to merge 2 commits into
base: releases/m71
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions ClientCore/Signalling/Conductor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -184,6 +185,7 @@ public static Conductor Instance
/// </summary>
public Signaller Signaller => _signaller;

private UseMediaStream _selfStream;
private UseMediaStreamTrack _peerVideoTrack;
private UseMediaStreamTrack _selfVideoTrack;
private UseMediaStreamTrack _peerAudioTrack;
Expand Down Expand Up @@ -891,7 +893,7 @@ private void VideoCapturerFactory_OnCreateCustomVideoCapturer(ICustomVideoCaptur
async private Task<bool> CreatePeerConnection(CancellationToken cancelationToken)
{
Debug.Assert(PeerConnection == null);
if(cancelationToken.IsCancellationRequested)
if (cancelationToken.IsCancellationRequested)
{
return false;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> { _selfStream.Id });
PeerConnection.AddTrack(_selfAudioTrack, new List<String> { _selfStream.Id });
#endif
OnAddLocalTrack?.Invoke(_selfVideoTrack);
OnAddLocalTrack?.Invoke(_selfAudioTrack);
Expand Down Expand Up @@ -1235,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();

Expand Down