Exemplo n.º 1
0
        public void TestVideoClientHandshake()
        {
            VideoClientHandshake packet = NanoPacketFactory
                                          .ParsePacket(ResourcesProvider.GetBytes("tcp_video_client_handshake.bin", ResourceType.Nano), _context)
                                          as VideoClientHandshake;

            Assert.NotNull(packet);
            Assert.NotNull(packet.Header);

            Assert.Equal <NanoChannel>(NanoChannel.Video, packet.Channel);
            Assert.Equal <NanoPayloadType>(NanoPayloadType.Streamer, packet.Header.PayloadType);

            Assert.Equal <VideoPayloadType>(VideoPayloadType.ClientHandshake,
                                            (VideoPayloadType)packet.StreamerHeader.PacketType);
            Assert.Equal <StreamerFlags>(StreamerFlags.GotSeqAndPrev | StreamerFlags.Unknown1,
                                         packet.StreamerHeader.Flags);
            Assert.Equal <uint>(1, packet.StreamerHeader.SequenceNumber);
            Assert.Equal <uint>(0, packet.StreamerHeader.PreviousSequenceNumber);

            Assert.Equal <uint>(3715731054, packet.InitialFrameId);
            Assert.Equal <uint>(30, packet.RequestedFormat.FPS);
            Assert.Equal <uint>(1280, packet.RequestedFormat.Width);
            Assert.Equal <uint>(720, packet.RequestedFormat.Height);
            Assert.Equal <VideoCodec>(VideoCodec.H264, packet.RequestedFormat.Codec);
        }
Exemplo n.º 2
0
        public void TestAudioServerHandshake()
        {
            AudioServerHandshake packet = NanoPacketFactory
                                          .ParsePacket(ResourcesProvider.GetBytes("tcp_audio_server_handshake.bin", ResourceType.Nano), _context)
                                          as AudioServerHandshake;

            Assert.NotNull(packet);
            Assert.NotNull(packet.Header);

            Assert.Equal <NanoChannel>(NanoChannel.Audio, packet.Channel);
            Assert.Equal <NanoPayloadType>(NanoPayloadType.Streamer, packet.Header.PayloadType);

            Assert.Equal <AudioPayloadType>(AudioPayloadType.ServerHandshake,
                                            (AudioPayloadType)packet.StreamerHeader.PacketType);
            Assert.Equal <StreamerFlags>(StreamerFlags.GotSeqAndPrev | StreamerFlags.Unknown1,
                                         packet.StreamerHeader.Flags);
            Assert.Equal <uint>(1, packet.StreamerHeader.SequenceNumber);
            Assert.Equal <uint>(0, packet.StreamerHeader.PreviousSequenceNumber);

            Assert.Equal <uint>(4, packet.ProtocolVersion);
            Assert.Equal <ulong>(1495315092424, packet.ReferenceTimestamp);
            Assert.Single(packet.Formats);

            Assert.Equal <uint>(2, packet.Formats[0].Channels);
            Assert.Equal <uint>(48000, packet.Formats[0].SampleRate);
            Assert.Equal <AudioCodec>(AudioCodec.AAC, packet.Formats[0].Codec);
        }
Exemplo n.º 3
0
        public void TestInputServerHandshake()
        {
            InputServerHandshake packet = NanoPacketFactory
                                          .ParsePacket(ResourcesProvider.GetBytes("tcp_input_server_handshake.bin", ResourceType.Nano), _context)
                                          as InputServerHandshake;

            Assert.NotNull(packet);
            Assert.NotNull(packet.Header);

            Assert.Equal <NanoChannel>(NanoChannel.Input, packet.Channel);
            Assert.Equal <NanoPayloadType>(NanoPayloadType.Streamer, packet.Header.PayloadType);

            Assert.Equal <InputPayloadType>(InputPayloadType.ServerHandshake,
                                            (InputPayloadType)packet.StreamerHeader.PacketType);
            Assert.Equal <StreamerFlags>(StreamerFlags.GotSeqAndPrev | StreamerFlags.Unknown1,
                                         packet.StreamerHeader.Flags);
            Assert.Equal <uint>(1, packet.StreamerHeader.SequenceNumber);
            Assert.Equal <uint>(0, packet.StreamerHeader.PreviousSequenceNumber);

            Assert.Equal <uint>(3, packet.ProtocolVersion);
            Assert.Equal <uint>(1280, packet.DesktopWidth);
            Assert.Equal <uint>(720, packet.DesktopHeight);
            Assert.Equal <uint>(0, packet.MaxTouches);
            Assert.Equal <uint>(672208545, packet.InitialFrameId);
        }
Exemplo n.º 4
0
        public void TestUdpHandshake()
        {
            UdpHandshake packet = NanoPacketFactory
                                  .ParsePacket(ResourcesProvider.GetBytes("udp_handshake.bin", ResourceType.Nano), _context)
                                  as UdpHandshake;

            Assert.NotNull(packet);
            Assert.NotNull(packet.Header);
            Assert.Equal <NanoChannel>(NanoChannel.TcpBase, packet.Channel);
            Assert.Equal <ControlHandshakeType>(ControlHandshakeType.ACK, packet.Type);
        }
Exemplo n.º 5
0
        public void TestUnknownChannelParse()
        {
            // Create channel context without any registered channels
            NanoChannelContext localContext = new NanoChannelContext();

            byte[] packetData = ResourcesProvider.GetBytes("tcp_channel_open_no_flags.bin", ResourceType.Nano);
            Assert.Throws <NanoPackingException>(() =>
            {
                NanoPacketFactory
                .ParsePacket(packetData, localContext);
            });
        }
Exemplo n.º 6
0
        public void TestControlHandshake()
        {
            ControlHandshake packet = NanoPacketFactory
                                      .ParsePacket(ResourcesProvider.GetBytes("tcp_control_handshake.bin", ResourceType.Nano), _context)
                                      as ControlHandshake;

            Assert.NotNull(packet);
            Assert.NotNull(packet.Header);
            Assert.Equal <NanoChannel>(NanoChannel.TcpBase, packet.Channel);
            Assert.Equal <ControlHandshakeType>(ControlHandshakeType.SYN, packet.Type);
            Assert.Equal <ushort>(40084, packet.ConnectionId);
        }
Exemplo n.º 7
0
        public void TestChannelOpenNoFlags()
        {
            ChannelOpen packet = NanoPacketFactory
                                 .ParsePacket(ResourcesProvider.GetBytes("tcp_channel_open_no_flags.bin", ResourceType.Nano), _context)
                                 as ChannelOpen;

            Assert.NotNull(packet);
            Assert.NotNull(packet.Header);
            Assert.Equal <NanoChannel>(NanoChannel.Video, packet.Channel);
            Assert.Equal <ChannelControlType>(ChannelControlType.Open, packet.Type);
            Assert.Equal <byte[]>(new byte[0], packet.Flags);
        }
        private Task SendAsyncStreaming(INanoPacket message)
        {
            if (RemoteConnectionId == 0)
            {
                throw new NanoException(
                          "ControlHandshake was not registered inside NanoChannelContext");
            }

            message.Header.ConnectionId = RemoteConnectionId;
            byte[] packet = NanoPacketFactory.AssemblePacket(message, ChannelContext);
            return(_streamingProtoClient.SendAsync(packet, packet.Length));
        }
Exemplo n.º 9
0
        public void TestChannelClose()
        {
            ChannelClose packet = NanoPacketFactory
                                  .ParsePacket(ResourcesProvider.GetBytes("tcp_channel_close.bin", ResourceType.Nano), _context)
                                  as ChannelClose;

            Assert.NotNull(packet);
            Assert.NotNull(packet.Header);
            Assert.Equal <NanoChannel>(NanoChannel.Audio, packet.Channel);
            Assert.Equal <ChannelControlType>(ChannelControlType.Close, packet.Type);
            Assert.Equal <uint>(0, packet.Flags);
        }
Exemplo n.º 10
0
        public void TestVideoServerHandshake()
        {
            VideoServerHandshake packet = NanoPacketFactory
                                          .ParsePacket(ResourcesProvider.GetBytes("tcp_video_server_handshake.bin", ResourceType.Nano), _context)
                                          as VideoServerHandshake;

            Assert.NotNull(packet);
            Assert.NotNull(packet.Header);
            Assert.Equal <NanoChannel>(NanoChannel.Video, packet.Channel);

            Assert.Equal <NanoPayloadType>(NanoPayloadType.Streamer, packet.Header.PayloadType);

            Assert.Equal <StreamerFlags>(StreamerFlags.GotSeqAndPrev | StreamerFlags.Unknown1,
                                         packet.StreamerHeader.Flags);
            Assert.Equal <uint>(1, packet.StreamerHeader.SequenceNumber);
            Assert.Equal <uint>(0, packet.StreamerHeader.PreviousSequenceNumber);
            Assert.Equal <VideoPayloadType>(VideoPayloadType.ServerHandshake,
                                            (VideoPayloadType)packet.StreamerHeader.PacketType);

            Assert.Equal <uint>(5, packet.ProtocolVersion);
            Assert.Equal <uint>(1280, packet.Width);
            Assert.Equal <uint>(720, packet.Height);
            Assert.Equal <uint>(30, packet.FPS);
            Assert.Equal <ulong>(1495315092425, packet.ReferenceTimestamp);
            Assert.Equal <int>(4, packet.Formats.Length);

            Assert.Equal <uint>(30, packet.Formats[0].FPS);
            Assert.Equal <uint>(1280, packet.Formats[0].Width);
            Assert.Equal <uint>(720, packet.Formats[0].Height);
            Assert.Equal <VideoCodec>(VideoCodec.H264, packet.Formats[0].Codec);

            Assert.Equal <uint>(30, packet.Formats[1].FPS);
            Assert.Equal <uint>(960, packet.Formats[1].Width);
            Assert.Equal <uint>(540, packet.Formats[1].Height);
            Assert.Equal <VideoCodec>(VideoCodec.H264, packet.Formats[1].Codec);

            Assert.Equal <uint>(30, packet.Formats[2].FPS);
            Assert.Equal <uint>(640, packet.Formats[2].Width);
            Assert.Equal <uint>(360, packet.Formats[2].Height);
            Assert.Equal <VideoCodec>(VideoCodec.H264, packet.Formats[2].Codec);

            Assert.Equal <uint>(30, packet.Formats[3].FPS);
            Assert.Equal <uint>(320, packet.Formats[3].Width);
            Assert.Equal <uint>(180, packet.Formats[3].Height);
            Assert.Equal <VideoCodec>(VideoCodec.H264, packet.Formats[3].Codec);
        }
Exemplo n.º 11
0
        public void TestInputFrameAck()
        {
            InputFrameAck packet = NanoPacketFactory
                                   .ParsePacket(ResourcesProvider.GetBytes("udp_input_frame_ack.bin", ResourceType.Nano), _context)
                                   as InputFrameAck;

            Assert.NotNull(packet);
            Assert.NotNull(packet.Header);

            Assert.Equal <NanoChannel>(NanoChannel.Input, packet.Channel);
            Assert.Equal <NanoPayloadType>(NanoPayloadType.Streamer, packet.Header.PayloadType);

            Assert.Equal <InputPayloadType>(InputPayloadType.FrameAck,
                                            (InputPayloadType)packet.StreamerHeader.PacketType);
            Assert.Equal <StreamerFlags>((StreamerFlags)0, packet.StreamerHeader.Flags);

            Assert.Equal <uint>(672208545, packet.AckedFrame);
        }
Exemplo n.º 12
0
        public void TestInputFrame()
        {
            InputFrame packet = NanoPacketFactory
                                .ParsePacket(ResourcesProvider.GetBytes("udp_input_frame.bin", ResourceType.Nano), _context)
                                as InputFrame;

            Assert.NotNull(packet);
            Assert.NotNull(packet.Header);

            Assert.Equal <NanoChannel>(NanoChannel.Input, packet.Channel);
            Assert.Equal <NanoPayloadType>(NanoPayloadType.Streamer, packet.Header.PayloadType);

            Assert.Equal <InputPayloadType>(InputPayloadType.Frame,
                                            (InputPayloadType)packet.StreamerHeader.PacketType);
            Assert.Equal <StreamerFlags>((StreamerFlags)0, packet.StreamerHeader.Flags);

            Assert.Equal <ulong>(583706495, packet.CreatedTimestamp);
            Assert.Equal <ulong>(583706515, packet.Timestamp);
            Assert.Equal <uint>(672208564, packet.FrameId);
        }
Exemplo n.º 13
0
        public void TestAudioControl()
        {
            AudioControl packet = NanoPacketFactory
                                  .ParsePacket(ResourcesProvider.GetBytes("tcp_audio_control.bin", ResourceType.Nano), _context)
                                  as AudioControl;

            Assert.NotNull(packet);
            Assert.NotNull(packet.Header);

            Assert.Equal <NanoChannel>(NanoChannel.Audio, packet.Channel);
            Assert.Equal <NanoPayloadType>(NanoPayloadType.Streamer, packet.Header.PayloadType);

            Assert.Equal <AudioPayloadType>(AudioPayloadType.Control,
                                            (AudioPayloadType)packet.StreamerHeader.PacketType);
            Assert.Equal <StreamerFlags>(StreamerFlags.GotSeqAndPrev | StreamerFlags.Unknown1,
                                         packet.StreamerHeader.Flags);
            Assert.Equal <uint>(2, packet.StreamerHeader.SequenceNumber);
            Assert.Equal <uint>(1, packet.StreamerHeader.PreviousSequenceNumber);

            Assert.Equal <AudioControlFlags>(AudioControlFlags.StartStream, packet.Flags);
        }
Exemplo n.º 14
0
        public void TestAudioData()
        {
            AudioData packet = NanoPacketFactory
                               .ParsePacket(ResourcesProvider.GetBytes("udp_audio_data.bin", ResourceType.Nano), _context)
                               as AudioData;

            Assert.NotNull(packet);
            Assert.NotNull(packet.Header);

            Assert.Equal <NanoChannel>(NanoChannel.Audio, packet.Channel);
            Assert.Equal <NanoPayloadType>(NanoPayloadType.Streamer, packet.Header.PayloadType);

            Assert.Equal <AudioPayloadType>(AudioPayloadType.Data,
                                            (AudioPayloadType)packet.StreamerHeader.PacketType);
            Assert.Equal <StreamerFlags>((StreamerFlags)0, packet.StreamerHeader.Flags);

            Assert.Equal <uint>(4, packet.Flags);
            Assert.Equal <uint>(0, packet.FrameId);
            Assert.Equal <ulong>(3365588462, packet.Timestamp);
            Assert.Equal <int>(357, packet.Data.Length);
        }
Exemplo n.º 15
0
        public void TestInputClientHandshake()
        {
            InputClientHandshake packet = NanoPacketFactory
                                          .ParsePacket(ResourcesProvider.GetBytes("tcp_input_client_handshake.bin", ResourceType.Nano), _context)
                                          as InputClientHandshake;

            Assert.NotNull(packet);
            Assert.NotNull(packet.Header);

            Assert.Equal <NanoChannel>(NanoChannel.Input, packet.Channel);
            Assert.Equal <NanoPayloadType>(NanoPayloadType.Streamer, packet.Header.PayloadType);

            Assert.Equal <InputPayloadType>(InputPayloadType.ClientHandshake,
                                            (InputPayloadType)packet.StreamerHeader.PacketType);
            Assert.Equal <StreamerFlags>(StreamerFlags.GotSeqAndPrev | StreamerFlags.Unknown1,
                                         packet.StreamerHeader.Flags);
            Assert.Equal <uint>(1, packet.StreamerHeader.SequenceNumber);
            Assert.Equal <uint>(0, packet.StreamerHeader.PreviousSequenceNumber);

            Assert.Equal <uint>(10, packet.MaxTouches);
            Assert.Equal <ulong>(1498690645999, packet.ReferenceTimestamp);
        }
Exemplo n.º 16
0
        public void TestStreamerControlChangeVideoQuality()
        {
            ChangeVideoQuality packet = NanoPacketFactory
                                        .ParsePacket(ResourcesProvider.GetBytes("tcp_control_msg_with_header_change_video_quality.bin", ResourceType.Nano), _context)
                                        as ChangeVideoQuality;

            Assert.NotNull(packet);
            Assert.NotNull(packet.Header);

            Assert.Equal <NanoChannel>(NanoChannel.Control, packet.Channel);
            Assert.Equal <NanoPayloadType>(NanoPayloadType.Streamer, packet.Header.PayloadType);

            Assert.Equal <uint>(0, packet.StreamerHeader.PacketType);
            Assert.Equal <StreamerFlags>(StreamerFlags.GotSeqAndPrev | StreamerFlags.Unknown1,
                                         packet.StreamerHeader.Flags);
            Assert.Equal <uint>(1, packet.StreamerHeader.SequenceNumber);
            Assert.Equal <uint>(0, packet.StreamerHeader.PreviousSequenceNumber);

            Assert.Equal <uint>(0, packet.ControlHeader.PreviousSequence);
            Assert.Equal <ushort>(1, packet.ControlHeader.Unknown1);
            Assert.Equal <ushort>(1406, packet.ControlHeader.Unknown2);
            Assert.Equal <ControlOpCode>(ControlOpCode.ChangeVideoQuality, packet.ControlHeader.OpCode);
        }
Exemplo n.º 17
0
        public void TestAudioClientHandshake()
        {
            AudioClientHandshake packet = NanoPacketFactory
                                          .ParsePacket(ResourcesProvider.GetBytes("tcp_audio_client_handshake.bin", ResourceType.Nano), _context)
                                          as AudioClientHandshake;

            Assert.NotNull(packet);
            Assert.NotNull(packet.Header);

            Assert.Equal <NanoChannel>(NanoChannel.Audio, packet.Channel);
            Assert.Equal <NanoPayloadType>(NanoPayloadType.Streamer, packet.Header.PayloadType);

            Assert.Equal <AudioPayloadType>(AudioPayloadType.ClientHandshake,
                                            (AudioPayloadType)packet.StreamerHeader.PacketType);
            Assert.Equal <StreamerFlags>(StreamerFlags.GotSeqAndPrev | StreamerFlags.Unknown1,
                                         packet.StreamerHeader.Flags);
            Assert.Equal <uint>(1, packet.StreamerHeader.SequenceNumber);
            Assert.Equal <uint>(0, packet.StreamerHeader.PreviousSequenceNumber);

            Assert.Equal <uint>(693041842, packet.InitialFrameID);
            Assert.Equal <uint>(2, packet.RequestedFormat.Channels);
            Assert.Equal <uint>(48000, packet.RequestedFormat.SampleRate);
            Assert.Equal <AudioCodec>(AudioCodec.AAC, packet.RequestedFormat.Codec);
        }
Exemplo n.º 18
0
        public void TestVideoData()
        {
            VideoData packet = NanoPacketFactory
                               .ParsePacket(ResourcesProvider.GetBytes("udp_video_data.bin", ResourceType.Nano), _context)
                               as VideoData;

            Assert.NotNull(packet);
            Assert.NotNull(packet.Header);

            Assert.Equal <NanoChannel>(NanoChannel.Video, packet.Channel);
            Assert.Equal <NanoPayloadType>(NanoPayloadType.Streamer, packet.Header.PayloadType);

            Assert.Equal <VideoPayloadType>(VideoPayloadType.Data,
                                            (VideoPayloadType)packet.StreamerHeader.PacketType);
            Assert.Equal <StreamerFlags>((StreamerFlags)0, packet.StreamerHeader.Flags);

            Assert.Equal <uint>(4, packet.Flags);
            Assert.Equal <uint>(3715731054, packet.FrameId);
            Assert.Equal <ulong>(3365613642, packet.Timestamp);
            Assert.Equal <uint>(5594, packet.TotalSize);
            Assert.Equal <uint>(5, packet.PacketCount);
            Assert.Equal <uint>(0, packet.Offset);
            Assert.Equal <int>(1119, packet.Data.Length);
        }
        public NanoRdpTransport(string address, int tcpPort, int udpPort)
        {
            _address = address;
            _tcpPort = tcpPort;
            _udpPort = udpPort;

            _cancellationTokenSource = new CancellationTokenSource();
            IPAddress hostAddr = IPAddress.Parse(address);

            _controlProtoEp   = new IPEndPoint(hostAddr, _tcpPort);
            _streamingProtoEp = new IPEndPoint(hostAddr, _udpPort);

            _controlProtoClient   = new TcpClient(AddressFamily.InterNetwork);
            _streamingProtoClient = new UdpClient(AddressFamily.InterNetwork);

            _controlProtoClient.Client.Bind(new IPEndPoint(IPAddress.Any, 0));
            _streamingProtoClient.Client.Bind(new IPEndPoint(IPAddress.Any, 0));

            _controlProtoClient.Connect(_controlProtoEp);
            _streamingProtoClient.Connect(_streamingProtoEp);

            ChannelContext = new NanoChannelContext();

            void ProcessPacket(byte[] packetData)
            {
                try
                {
                    EndianReader reader = new EndianReader(packetData);
                    INanoPacket  packet = NanoPacketFactory.ParsePacket(packetData, ChannelContext);

                    if (packet.Header.PayloadType == NanoPayloadType.ChannelControl &&
                        packet as ChannelCreate != null)
                    {
                        ChannelContext.RegisterChannel((ChannelCreate)packet);
                    }
                    else if (packet.Header.PayloadType == NanoPayloadType.ChannelControl &&
                             packet as ChannelClose != null)
                    {
                        ChannelContext.UnregisterChannel((ChannelClose)packet);
                    }
                    else if (RemoteConnectionId == 0 && packet as ControlHandshake != null)
                    {
                        RemoteConnectionId = ((ControlHandshake)packet).ConnectionId;
                    }

                    bool success = _receiveQueue.TryAdd(packet);
                    if (!success)
                    {
                        LogTool.Log($"Failed to add message to receive queue");
                    }
                }
                catch (NanoPackingException e)
                {
                    LogTool.LogError($"Failed to parse nano packet: {e.Message}", e);
                }
            }

            _controlProtoClient.ConsumeReceivedPrefixed(
                receiveResult => ProcessPacket(receiveResult),
                _cancellationTokenSource.Token
                );

            _streamingProtoClient.ConsumeReceived(
                receiveResult => ProcessPacket(receiveResult.Buffer),
                _cancellationTokenSource.Token
                );

            Task.Run(() =>
            {
                while (!_receiveQueue.IsCompleted)
                {
                    try
                    {
                        var message = _receiveQueue.Take();
                        MessageReceived?.Invoke(this, new MessageReceivedEventArgs <INanoPacket>(message));
                    }
                    catch (Exception e)
                    {
                        LogTool.LogError(
                            e, "Calling Nano MessageReceived failed!");
                    }
                }
            }, _cancellationTokenSource.Token);
        }
 private Task SendAsyncControl(INanoPacket message)
 {
     byte[] packet = NanoPacketFactory.AssemblePacket(message, ChannelContext);
     return(_controlProtoClient.SendAsyncPrefixed(packet));
 }