Beispiel #1
0
 private Task getVideoSourcesAsync(CitpPeer peer, GetVideoSourcesMessagePacket requestPacket)
 {
     return
         (_networkService.SendPacketAsync(new VideoSourcesMessagePacket {
         Sources = _device.VideoSources.Values.ToList()
     }, peer, requestPacket));
 }
Beispiel #2
0
        private async Task getElementLibraryThumbnailAsync(CitpPeer peer,
                                                           GetElementLibraryThumbnailMessagePacket requestPacket)
        {
            var msexIds = requestPacket.Version == MsexVersion.Version1_0
                                ? requestPacket.LibraryNumbers.Select(n => new MsexId(n)).ToList()
                                : requestPacket.LibraryIds.Select(i => new MsexId(i)).ToList();

            var imageRequest = new CitpImageRequest(requestPacket.ThumbnailWidth, requestPacket.ThumbnailHeight,
                                                    requestPacket.ThumbnailFormat,
                                                    requestPacket.ThumbnailFlags.HasFlag(MsexThumbnailFlags.PreserveAspectRatio),
                                                    requestPacket.ThumbnailFormat == MsexImageFormat.Rgb8 && requestPacket.Version == MsexVersion.Version1_0);

            var thumbs = _device.GetElementLibraryThumbnails(imageRequest, requestPacket.LibraryType, msexIds);

            var packets = thumbs.Select(t => new ElementLibraryThumbnailMessagePacket
            {
                LibraryType     = requestPacket.LibraryType,
                LibraryNumber   = t.Item1.LibraryNumber.GetValueOrDefault(),
                LibraryId       = t.Item1.LibraryId.GetValueOrDefault(),
                ThumbnailFormat = requestPacket.ThumbnailFormat,
                ThumbnailWidth  = (ushort)t.Item2.ActualWidth,
                ThumbnailHeight = (ushort)t.Item2.ActualHeight,
                ThumbnailBuffer = t.Item2.Data,
            });

            foreach (var packet in packets)
            {
                await _networkService.SendPacketAsync(packet, peer, requestPacket).ConfigureAwait(false);
            }
        }
Beispiel #3
0
        public async Task <bool> SendPacketAsync(CitpPacket packet, CitpPeer peer, [CanBeNull] CitpPacket requestPacket = null)
        {
            if (peer.IsConnected == false)
            {
                throw new InvalidOperationException("Cannot send packet, peer is not connected");
            }

            packet.MessagePart          = 0;
            packet.MessagePartCount     = 1;
            packet.RequestResponseIndex = Convert.ToUInt16(requestPacket?.RequestResponseIndex ?? 0);

            if (packet.LayerType == CitpLayerType.MediaServerExtensionsLayer)
            {
                var msexPacket = (MsexPacket)packet;

                if (peer.MsexVersion.HasValue == false)
                {
                    throw new InvalidOperationException("Peer MSEX version is unknown");
                }

                if (msexPacket.Version.HasValue)
                {
                    if (msexPacket.Version.Value > peer.MsexVersion)
                    {
                        _log.LogWarning("Attempting to send an MSEX message with a higher version number than the peer supports");
                    }
                }
                else
                {
                    ((MsexPacket)packet).Version = peer.MsexVersion;
                }
            }

            return(await sendDataToPeerAsync(peer, packet.ToByteArray(), requestPacket?.RemoteEndpoint?.Port).ConfigureAwait(false));
        }
Beispiel #4
0
        private Task <bool> sendDataToPeerAsync(CitpPeer peer, byte[] data, int?remoteTcpPort = null)
        {
            IRemoteCitpTcpClient client;

            Debug.Assert(peer.IsConnected, "Can't send data to an unconnected peer");

            var endpoint = new IpEndpoint(peer.Ip, remoteTcpPort ?? peer.RemoteTcpPorts.First());

            return(_tcpListenService.Clients.TryGetValue(endpoint, out client)
                                ? client.SendAsync(data)
                                : Task.FromResult(false));
        }
Beispiel #5
0
        private Task getElementInformationAsync(CitpPeer peer, GetElementInformationMessagePacket requestPacket)
        {
            CitpPacket packet;

            switch (requestPacket.LibraryType)
            {
            case MsexLibraryType.Media:
                var mediaPacket = new MediaElementInformationMessagePacket
                {
                    LibraryNumber = requestPacket.LibraryNumber,
                    LibraryId     = requestPacket.LibraryId,
                    Media         = _device.GetMediaElementInformation(new MsexId(requestPacket.LibraryId, requestPacket.LibraryNumber),
                                                                       requestPacket.RequestedElementNumbers).ToList()
                };


                packet = mediaPacket;
                break;

            case MsexLibraryType.Effects:
                var effectPacket = new EffectElementInformationMessagePacket
                {
                    LibraryNumber = requestPacket.LibraryNumber,
                    LibraryId     = requestPacket.LibraryId,
                    Effects       =
                        _device.GetEffectElementInformation(new MsexId(requestPacket.LibraryId, requestPacket.LibraryNumber),
                                                            requestPacket.RequestedElementNumbers).ToList()
                };


                packet = effectPacket;
                break;

            default:
                Debug.Assert(requestPacket.LibraryId.HasValue, "Generic elements are unsupported in MSEX V1.0");

                var genericPacket = new GenericElementInformationMessagePacket
                {
                    LibraryId   = requestPacket.LibraryId.Value,
                    LibraryType = requestPacket.LibraryType,
                    Information = _device.GetGenericElementInformation(requestPacket.LibraryType,
                                                                       requestPacket.LibraryId.Value, requestPacket.RequestedElementNumbers).ToList()
                };


                packet = genericPacket;
                break;
            }

            return(_networkService.SendPacketAsync(packet, peer, requestPacket));
        }
Beispiel #6
0
        private Task getElementLibraryInformationAsync(CitpPeer peer,
                                                       GetElementLibraryInformationMessagePacket requestPacket)
        {
            var libraries = _device.GetElementLibraryInformation(requestPacket.LibraryType,
                                                                 requestPacket.Version != MsexVersion.Version1_0 ? requestPacket.LibraryParentId : null,
                                                                 requestPacket.RequestedLibraryNumbers);

            var packet = new ElementLibraryInformationMessagePacket
            {
                LibraryType = requestPacket.LibraryType,
                Elements    = libraries.ToList()
            };

            return(_networkService.SendPacketAsync(packet, peer, requestPacket));
        }
Beispiel #7
0
        private void receivedPeerLocationMessage(PeerLocationMessagePacket message, IpAddress remoteIp)
        {
            // Filter out the local CITP peer
            if (remoteIp == _nicAddress && message.Name == _device.PeerName && message.ListeningTcpPort == LocalTcpListenPort)
            {
                return;
            }

            var peer = Peers.FirstOrDefault(p => p.Ip.Equals(remoteIp) && p.Name == message.Name);

            if (peer == null)
            {
                peer = new CitpPeer(remoteIp, message.Name);
                _peers.Add(peer);
            }

            peer.Type  = message.Type;
            peer.State = message.State;
            peer.LastUpdateReceived = DateTime.Now;
        }
Beispiel #8
0
        private void receivedPeerNameMessage(PeerNameMessagePacket message, IpEndpoint remoteEndpoint)
        {
            var peer = _peers.FirstOrDefault(p => p.Ip == remoteEndpoint.Address && p.Name == message.Name);

            if (peer != null)
            {
                peer.AddTcpConnection(remoteEndpoint.Port);
                _log.LogInfo($"Known CITP Peer '{peer}' identified on TCP port {remoteEndpoint.Port}");
            }
            else
            {
                peer = new CitpPeer(remoteEndpoint.Address, message.Name);
                peer.AddTcpConnection(remoteEndpoint.Port);

                _peers.Add(peer);
                _log.LogInfo($"New CITP Peer '{peer}' identified from on TCP port {remoteEndpoint.Port}");
            }

            peer.Name = message.Name;
            peer.LastUpdateReceived = DateTime.Now;
        }
Beispiel #9
0
        private async Task getElementThumbnailAsync(CitpPeer peer, GetElementThumbnailMessagePacket requestPacket)
        {
            MsexId msexId;

            if (requestPacket.Version == MsexVersion.Version1_0)
            {
                msexId = new MsexId(requestPacket.LibraryNumber);
            }
            else
            {
                Debug.Assert(requestPacket.LibraryId.HasValue, "LibraryId must have value for MSEX 1.1 or 1.2");
                msexId = new MsexId(requestPacket.LibraryId.Value);
            }

            var imageRequest = new CitpImageRequest(requestPacket.ThumbnailWidth, requestPacket.ThumbnailHeight,
                                                    requestPacket.ThumbnailFormat,
                                                    requestPacket.ThumbnailFlags.HasFlag(MsexThumbnailFlags.PreserveAspectRatio),
                                                    requestPacket.ThumbnailFormat == MsexImageFormat.Rgb8 && requestPacket.Version == MsexVersion.Version1_0);

            var thumbs = _device.GetElementThumbnails(imageRequest, requestPacket.LibraryType, msexId,
                                                      requestPacket.ElementNumbers);

            var packets = thumbs.Select(t => new ElementThumbnailMessagePacket
            {
                LibraryType     = requestPacket.LibraryType,
                LibraryNumber   = requestPacket.LibraryNumber,
                LibraryId       = requestPacket.LibraryId,
                ElementNumber   = t.Item1,
                ThumbnailFormat = requestPacket.ThumbnailFormat,
                ThumbnailWidth  = (ushort)t.Item2.ActualWidth,
                ThumbnailHeight = (ushort)t.Item2.ActualHeight,
                ThumbnailBuffer = t.Item2.Data
            });

            foreach (var packet in packets)
            {
                await _networkService.SendPacketAsync(packet, peer, requestPacket).ConfigureAwait(false);
            }
        }
Beispiel #10
0
        private Task receivedClientInformationMessageAsync(ClientInformationMessagePacket message, CitpPeer peer)
        {
            if (!message.SupportedMsexVersions.Contains(MsexVersion.Version1_2))
            {
                return(Task.FromResult(false));
            }

            peer.MsexVersion = MsexVersion.Version1_2;

            return(SendPacketAsync(createServerInfoPacket(MsexVersion.Version1_2), peer, message));
        }