예제 #1
0
        public void OnPreviewFrame(byte[] data, Android.Hardware.Camera camera)
        {
            try
            {
                noFrames = 0;
                YuvImage yi = new YuvImage(data, camera.GetParameters().PreviewFormat, camera.GetParameters().PreviewSize.Width, camera.GetParameters().PreviewSize.Height, null);

                byte[][] frames = new byte[fragmentation][];

                using MemoryStream ms = new MemoryStream();

                yi.CompressToJpeg(new Rect(0, 0, yi.Width, yi.Height), 20, ms);

                byte[]   jpegBytes = ms.ToArray();
                UdpFrame frame     = new UdpFrame(jpegBytes);

                FrameRefreshed?.Invoke(frame.packages);
            }
            catch (Exception e)
            {
                start();
            }
        }
예제 #2
0
        public virtual bool PublicInput(IPFrame packet)
        {
            if (packet == null)
            {
                return(false);
            }
            switch (packet.ProtocolType)
            {
            case ProtocolType.Udp:
            {
                UdpFrame frame = UdpLayer.ParseFrame(packet, true);
                if (frame == null)
                {
                    return(false);
                }
                NATContext context = this.m_contextsUdp.PublicInput(frame.Source, frame.Destination);
                if (context == null)
                {
                    return(false);
                }
                var convertional = new UdpFrame(frame.Source, context.Sources, frame.Payload)
                {
                    Ttl = frame.Ttl,
                };
                IPFrame ip = CopyFrameHeaderParts(UdpLayer.ToIPFrame(convertional), packet);
                if (ip == null)
                {
                    return(false);
                }
                return(this.OnPrivateOutput(ip));
            }

            case ProtocolType.Tcp:
            {
                TcpFrame frame = TcpLayer.ParseFrame(packet, true);
                if (frame == null)
                {
                    return(false);
                }
                NATContext context = this.m_contextsTcp.PublicInput(frame.Source, frame.Destination);
                if (context == null)
                {
                    return(false);
                }
                else
                {
                    TraceTcpNatContext(context, frame);
                }
                var convertional = new TcpFrame(frame.Source, context.Sources, frame.Payload)
                {
                    Ttl           = frame.Ttl,
                    AcknowledgeNo = frame.AcknowledgeNo,
                    Flags         = frame.Flags,
                    SequenceNo    = frame.SequenceNo,
                    WindowSize    = frame.WindowSize,
                    Options       = frame.Options,
                    UrgentPointer = frame.UrgentPointer,
                };
                IPFrame ip = CopyFrameHeaderParts(TcpLayer.ToIPFrame(convertional), packet);
                if (ip == null)
                {
                    return(false);
                }
                return(this.OnPrivateOutput(ip));
            }

            case ProtocolType.Icmp:
                return(this.PublicIcmpInput(packet));

            default:
                return(false);
            }
        }