Esempio n. 1
0
        void OnVideoSourceAdded(Client client, VideoSource videoSource, MediaQuality mediaQuality)
        {
            _signallingThread.EnsureCurrentThread();

            // As new video source is added,
            // we'll have to connect this source to any existing sending-PeerConnection
            foreach (var otherClients in _clients
                     .OtherThan(client)
                     .Where(other => other.DesiredMediaQuality == mediaQuality && other.PeerConnections.Count > 0))
            {
                var localVideoLink = new LocalVideoLink(
                    this,
                    videoSource,
                    otherClients.PeerConnections[0]);
                _localVideoLinks.Add(localVideoLink);
                _logger.Debug($"Added {localVideoLink} into {_localVideoLinks}");
            }
        }
Esempio n. 2
0
        public void AddPeerConnection(IRemoteDevice remoteDevice, IPeerConnection peerConnection)
        {
            Require.NotNull(peerConnection);
            _signallingThread.EnsureCurrentThread();

            // Add PeerConnection into VideoClient
            var client = _clients.GetOrThrow(remoteDevice.Id);

            if (client.PeerConnections.Contains(peerConnection))
            {
                throw new InvalidProgramException($"{peerConnection} already added into {client}");
            }
            client.PeerConnections.Add(peerConnection);
            _logger.Info($"Added {peerConnection} into {client}, total PeerConnections for this client={client.PeerConnections.Count}");

            // If this PeerConnetion has some existing transceivers,
            // add them.
            // TODO: listen for future transceivers and add them too, too lazy to implement this for now.
            var currenTransceivers = peerConnection.Native.GetTransceivers();

            foreach (var transceiver in currenTransceivers)
            {
                OnRemoteTrackAdded(client, peerConnection, transceiver);
            }

            // Link this PeerConnection with any existing local VideoSources
            foreach (var other in _clients
                     .OtherThan(client)
                     .Where(other => other.VideoSources.ContainsKey(client.DesiredMediaQuality)))
            {
                var localVideoLink = new LocalVideoLink(
                    this,
                    other.VideoSources[client.DesiredMediaQuality],
                    peerConnection);
                _localVideoLinks.Add(localVideoLink);
                _logger.Debug($"Added {localVideoLink} into {_localVideoLinks}");
            }
        }
Esempio n. 3
0
 public void Add(LocalVideoLink link)
 {
     _indexByVideoSource.Add(link.VideoSource, link);
     _indexByPeerConnection.Add(link.TargetPeerConnection, link);
 }