internal void SendUdpHandshake()
        {
            var payload = new Packets.UdpHandshake(ControlHandshakeType.ACK);
            var packet  = new RtpPacket(RtpPayloadType.UDPHandshake, payload);

            SendOnStreamingSocket(packet);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        private async Task SendUdpHandshakeAsync(
            ControlHandshakeType type = ControlHandshakeType.ACK)
        {
            var packet = new Packets.UdpHandshake(type)
            {
                Channel = NanoChannel.TcpBase
            };

            // FIXME: Wait for first VideoPacket
            // Currently WaitForMessage is broken and blocks VideoData
            // populating to MessageReceived events
            await _transport.SendAsync(packet);
        }
Esempio n. 3
0
        public static INanoPacket ParsePacket(byte[] data, NanoChannelContext context)
        {
            EndianReader packetReader = new EndianReader(data);
            RtpHeader    header       = new RtpHeader();

            header.Deserialize(packetReader);
            NanoPayloadType payloadType = header.PayloadType;

            // It might be NanoChannel.Unknown at this point, if ChannelCreate
            // packet was not processed yet
            // It gets processed at the end of the function
            NanoChannel channel = context.GetChannel(header.ChannelId);

            INanoPacket packet        = null;
            long        payloadOffset = packetReader.Position;

            switch (payloadType)
            {
            // FIXME: Create from Attribute is broken
            case NanoPayloadType.UDPHandshake:
                packet = new UdpHandshake();
                break;

            case NanoPayloadType.ControlHandshake:
                packet = new ControlHandshake();
                break;

            case NanoPayloadType.ChannelControl:
                // Read type to pinpoint exact payload
                ChannelControlType cct =
                    (ChannelControlType)packetReader.ReadUInt32LE();
                packet = CreateFromChannelControlType(cct);
                break;

            case NanoPayloadType.Streamer:
                packet = CreateFromStreamerHeader(packetReader, channel);
                break;

            default:
                throw new NanoPackingException(
                          $"Unknown packet type received: {payloadType}");
            }

            if (packet == null)
            {
                throw new NanoPackingException("Failed to find matching body for packet");
            }

            packetReader.Seek(payloadOffset, SeekOrigin.Begin);
            packet.Deserialize(packetReader);
            packet.Header = header;

            if (packet as ChannelCreate != null)
            {
                string channelName = ((ChannelCreate)packet).Name;
                channel = NanoChannelClass.GetIdByClassName(channelName);
            }

            if (channel == NanoChannel.Unknown)
            {
                throw new NanoPackingException("ParsePacket: INanoPacket.Channel is UNKNOWN");
            }

            packet.Channel = channel;
            return(packet);
        }