Exemplo n.º 1
0
        private static unsafe void TestEmpty(ILZ4Compressor compressor, ILZ4Decompressor decompressor)
        {
            var bytes = new byte[50];

            byte[] dst    = compressor.Compress(bytes);
            var    result = decompressor.Decompress(dst);
        }
Exemplo n.º 2
0
        private static void Test(string directory, ILZ4Compressor compressor, ILZ4Decompressor decompressor)
        {
            var w = new Stopwatch();
            var dw = new Stopwatch();
            long compressedTotal = 0;
            long uncompressedTotal = 0;

            for(int j=0;j<10;j++)
            foreach (var bytes in Read(directory))
            {
                uncompressedTotal += bytes.Length;
                byte[] compressed = new byte[compressor.CalculateMaxCompressedLength(bytes.Length)];
                w.Start();
                int compressedLength = compressor.Compress(bytes, compressed);
                compressedTotal += compressedLength;
                w.Stop();

                byte[] uncompressed = new byte[bytes.Length];

                dw.Start();
                decompressor.DecompressKnownSize(compressed, uncompressed, uncompressed.Length);
                dw.Stop();

                for (int i = 0; i < uncompressed.Length; i++)
                {
                    if (uncompressed[i] != bytes[i])
                        throw new Exception("Original bytes and decompressed bytes differ starting at byte " + i);
                }
            }

            Console.WriteLine("Ratio = " + compressedTotal * 1.0 / uncompressedTotal);
            Console.WriteLine("Compression Time (MB / sec) = " + uncompressedTotal / 1024.0 / 1024.0 / w.Elapsed.TotalSeconds);
            Console.WriteLine("Uncompression Time (MB / sec) = " + uncompressedTotal / 1024.0 / 1024.0 / dw.Elapsed.TotalSeconds);
        }
Exemplo n.º 3
0
 public LZ4Compressor()
 {
     if (IntPtr.Size == 4)
     {
         compressor = new LZ4Compressor32();
     }
     else
     {
         compressor = new LZ4Compressor64();
     }
 }
Exemplo n.º 4
0
 public LZ4Compressor()
 {
     if (IntPtr.Size == 4)
     {
         compressor = new LZ4Compressor32();
     }
     else
     {
         compressor = new LZ4Compressor64();
     }
 }
Exemplo n.º 5
0
 private static void TestUnknownSize(string directory, ILZ4Compressor compressor, ILZ4Decompressor decompressor)
 {
     foreach (var file in Directory.GetFiles(directory))
     {
         var bytes        = File.ReadAllBytes(file);
         var compressed   = compressor.Compress(bytes);
         var decompressed = decompressor.Decompress(compressed);
         if (!bytes.SequenceEqual(decompressed))
         {
             throw new Exception("Compressing/Decompressing " + file + " failed.");
         }
     }
 }
Exemplo n.º 6
0
 public ScapCapture(bool RecordMic, int NumberofThreads, int FramesPerSecond, ScapVideoFormats VideoFormat, ScapImageFormats ImageFormat, int Xcoord, int Ycoord, int CaptureWidth, int CaptureHeight, string CaptureDirectory, string ImageFilename, string VideoFilename, int Runtime)
 {
     IsSoundEnabled  = RecordMic;
     IsMultiThreaded = true;
     Sw           = new Stopwatch();
     Compressor   = LZ4CompressorFactory.CreateNew();
     Decompressor = LZ4DecompressorFactory.CreateNew();
     Imgext       = "";
     Vidext       = "";
     if (!Directory.Exists(CaptureDirectory))
     {
         Directory.CreateDirectory(CaptureDirectory);
         Dir = CaptureDirectory + "\\";
     }
     else
     {
         Dir = CaptureDirectory + "\\";
     }
     Imgname            = ImageFilename;
     Vidname            = VideoFilename;
     Vidform            = VideoFormat;
     Imgform            = ImageFormat;
     NumThreads         = 1;
     X                  = Xcoord;
     Y                  = Ycoord;
     W                  = CaptureWidth;
     H                  = CaptureHeight;
     Rtime              = Runtime;
     Frames             = 0;
     Capture            = 0;
     FPS                = FramesPerSecond;
     FBegin             = 0;
     FEnd               = -1;
     Length             = 0;
     DecompProgress     = 0;
     EncodeProgress     = 0;
     CompressedDataList = new List <Databank>();
     MainDataLists      = new List <Databank> [NumThreads];
     CompressorBools    = new bool[NumThreads];
     for (int c = 0; c < NumThreads; c++)
     {
         MainDataLists[c]          = new List <Databank>();
         MainDataLists[c].Capacity = 25;
         CompressorBools[c]        = false;
     }
     IsInitialized   = true;
     IsDecompressed  = false;
     IsEncoded       = false;
     IsMultiThreaded = false;
     HasCaptured     = false;
 }
Exemplo n.º 7
0
 public ScapCapture(bool RecordMic, int NumberofThreads, int FramesPerSecond, ScapVideoFormats VideoFormat, ScapImageFormats ImageFormat, int Xcoord, int Ycoord, int CaptureWidth, int CaptureHeight)
 {
     IsSoundEnabled  = RecordMic;
     IsMultiThreaded = true;
     Sw                 = new Stopwatch();
     Compressor         = LZ4CompressorFactory.CreateNew();
     Decompressor       = LZ4DecompressorFactory.CreateNew();
     Imgext             = ".bmp";
     Vidext             = ".avi";
     Dir                = Directory.GetCurrentDirectory() + "\\";
     Imgname            = "";
     Vidname            = "Vid";
     Vidform            = VideoFormat;
     Imgform            = ImageFormat;
     NumThreads         = NumberofThreads;
     X                  = Xcoord;
     Y                  = Ycoord;
     W                  = CaptureWidth;
     H                  = CaptureHeight;
     Rtime              = -1;
     Frames             = 0;
     Capture            = 0;
     FPS                = FramesPerSecond;
     FBegin             = 0;
     FEnd               = -1;
     Length             = 0;
     DecompProgress     = 0;
     EncodeProgress     = 0;
     CompressedDataList = new List <Databank>();
     MainDataLists      = new List <Databank> [NumThreads];
     CompressorBools    = new bool[NumThreads];
     for (int c = 0; c < NumThreads; c++)
     {
         MainDataLists[c]          = new List <Databank>();
         MainDataLists[c].Capacity = 25;
         CompressorBools[c]        = false;
     }
     IsInitialized   = true;
     IsDecompressed  = false;
     IsEncoded       = false;
     IsMultiThreaded = false;
     HasCaptured     = false;
 }
Exemplo n.º 8
0
 public ScapCapture(bool RecordMic, int NumberofThreads)
 {
     IsSoundEnabled  = RecordMic;
     IsMultiThreaded = true;
     Sw                 = new Stopwatch();
     Compressor         = LZ4CompressorFactory.CreateNew();
     Decompressor       = LZ4DecompressorFactory.CreateNew();
     Imgext             = ".bmp";
     Vidext             = ".avi";
     Dir                = Directory.GetCurrentDirectory() + "\\";
     Imgname            = "";
     Vidname            = "Vid";
     Vidform            = ScapVideoFormats.Default;
     Imgform            = ScapImageFormats.Bmp;
     NumThreads         = NumberofThreads;
     X                  = 0;
     Y                  = 0;
     W                  = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
     H                  = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
     Rtime              = -1;
     Frames             = 0;
     Capture            = 0;
     FPS                = 50;
     FBegin             = 0;
     FEnd               = -1;
     Length             = 0;
     DecompProgress     = 0;
     EncodeProgress     = 0;
     CompressedDataList = new List <Databank>();
     MainDataLists      = new List <Databank> [NumThreads];
     CompressorBools    = new bool[NumThreads];
     for (int c = 0; c < NumThreads; c++)
     {
         MainDataLists[c]          = new List <Databank>();
         MainDataLists[c].Capacity = 25;
         CompressorBools[c]        = false;
     }
     IsInitialized   = true;
     IsDecompressed  = false;
     IsEncoded       = false;
     IsMultiThreaded = false;
     HasCaptured     = false;
 }
Exemplo n.º 9
0
        private static void Test(string directory, ILZ4Compressor compressor, ILZ4Decompressor decompressor)
        {
            var  w  = new Stopwatch();
            var  dw = new Stopwatch();
            long compressedTotal   = 0;
            long uncompressedTotal = 0;

            for (int j = 0; j < 10; j++)
            {
                foreach (var bytes in Read(directory))
                {
                    uncompressedTotal += bytes.Length;
                    byte[] compressed = new byte[compressor.CalculateMaxCompressedLength(bytes.Length)];
                    w.Start();
                    int compressedLength = compressor.Compress(bytes, compressed);
                    compressedTotal += compressedLength;
                    w.Stop();

                    byte[] uncompressed = new byte[bytes.Length];

                    dw.Start();
                    decompressor.DecompressKnownSize(compressed, uncompressed, uncompressed.Length);
                    dw.Stop();

                    for (int i = 0; i < uncompressed.Length; i++)
                    {
                        if (uncompressed[i] != bytes[i])
                        {
                            throw new Exception("Original bytes and decompressed bytes differ starting at byte " + i);
                        }
                    }
                }
            }

            Console.WriteLine("Ratio = " + compressedTotal * 1.0 / uncompressedTotal);
            Console.WriteLine("Compression Time (MB / sec) = " + uncompressedTotal / 1024.0 / 1024.0 / w.Elapsed.TotalSeconds);
            Console.WriteLine("Uncompression Time (MB / sec) = " + uncompressedTotal / 1024.0 / 1024.0 / dw.Elapsed.TotalSeconds);
        }
Exemplo n.º 10
0
 private static void TestUnknownSize(string directory, ILZ4Compressor compressor, ILZ4Decompressor decompressor)
 {
     foreach (var file in Directory.GetFiles(directory))
     {
         var bytes = File.ReadAllBytes(file);
         var compressed = compressor.Compress(bytes);
         var decompressed = decompressor.Decompress(compressed);
         if (!bytes.SequenceEqual(decompressed))
             throw new Exception("Compressing/Decompressing " + file + " failed.");
     }
 }
Exemplo n.º 11
0
 public void SetCompressor(ILZ4Compressor compressor)
 {
     this.compressor = compressor;
 }
Exemplo n.º 12
0
        // closes all sensor net servers
        private void CloseNetServers()
        {
            try
            {
                if (controlFrameServer != null)
                {
                    controlFrameServer.ReceivedMessage -= new ReceivedMessageEventHandler(ControlFrameReceived);
                    controlFrameServer.Close();
                    controlFrameServer     = null;
                    controlFrameCompressor = null;
                }

                if (colorFrameServer != null)
                {
                    colorFrameServer.Close();
                    colorFrameServer = null;
                }

                if (depthFrameServer != null)
                {
                    depthFrameServer.Close();
                    depthFrameServer     = null;
                    depthFrameCompressor = null;
                }

                if (infraredFrameServer != null)
                {
                    infraredFrameServer.Close();
                    infraredFrameServer = null;
                }

                if (bodyDataFrameServer != null)
                {
                    bodyDataFrameServer.Close();
                    bodyDataFrameServer = null;
                }

                if (bodyIndexFrameServer != null)
                {
                    bodyIndexFrameServer.Close();
                    bodyIndexFrameServer     = null;
                    bodyIndexFrameCompressor = null;
                }

                if (poseFrameServer != null)
                {
                    poseFrameServer.Close();
                    poseFrameServer = null;
                }

                if (depth2colorFrameServer != null)
                {
                    depth2colorFrameServer.Close();
                    depth2colorFrameServer = null;
                }

                if (color2depthFrameServer != null)
                {
                    color2depthFrameServer.Close();
                    color2depthFrameServer     = null;
                    color2depthFrameCompressor = null;
                }

                if (color2bodyIndexFrameServer != null)
                {
                    color2bodyIndexFrameServer.Close();
                    color2bodyIndexFrameServer     = null;
                    color2bodyIndexFrameCompressor = null;
                }

                if (serverStatusText)
                {
                    serverStatusText.text = "NetServer closed.";
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogError("Error closing NetServer: " + ex.Message);
                Debug.Log(ex);

                if (serverStatusText)
                {
                    serverStatusText.text = string.Format("Error closing NetServer: {0}", ex.Message);
                }
            }
        }
Exemplo n.º 13
0
        // initializes the sensor net servers
        private void InitNetServers(KinectInterop.FrameSource dwFlags)
        {
            try
            {
                lastKeepAliveFrameTime = 0;
                lastSensorPoseStr      = string.Empty;
                int minPort = int.MaxValue, maxPort = int.MinValue;

                controlFrameServer = new TcpNetServer(baseListenPort + (int)NetMessageType.Control, "ControlServer", sbConsole);
                controlFrameServer.ReceivedMessage += new ReceivedMessageEventHandler(ControlFrameReceived);
                minPort = Mathf.Min(minPort, controlFrameServer.serverPort); maxPort = Mathf.Max(maxPort, controlFrameServer.serverPort);

                if (compressRawFrames)
                {
                    controlFrameCompressor = LZ4CompressorFactory.CreateNew();
                }

                if ((dwFlags & KinectInterop.FrameSource.TypeColor) != 0 && sensorData.colorImageTexture != null)
                {
                    colorFrameServer = new TcpNetServer(baseListenPort + (int)NetMessageType.Color, "ColorServer", sbConsole);
                    minPort          = Mathf.Min(minPort, colorFrameServer.serverPort); maxPort = Mathf.Max(maxPort, colorFrameServer.serverPort);
                }

                if ((dwFlags & KinectInterop.FrameSource.TypeDepth) != 0)
                {
                    depthFrameServer = new TcpNetServer(baseListenPort + (int)NetMessageType.Depth, "DepthServer", sbConsole);
                    minPort          = Mathf.Min(minPort, depthFrameServer.serverPort); maxPort = Mathf.Max(maxPort, depthFrameServer.serverPort);

                    if (compressRawFrames)
                    {
                        depthFrameCompressor = LZ4CompressorFactory.CreateNew();
                    }
                }

                if ((dwFlags & KinectInterop.FrameSource.TypeInfrared) != 0)
                {
                    infraredTex2d       = new Texture2D(sensorData.depthImageWidth, sensorData.depthImageHeight, TextureFormat.ARGB32, false);
                    infraredFrameServer = new TcpNetServer(baseListenPort + (int)NetMessageType.Infrared, "InfraredServer", sbConsole);
                    minPort             = Mathf.Min(minPort, infraredFrameServer.serverPort); maxPort = Mathf.Max(maxPort, infraredFrameServer.serverPort);
                }

                if ((dwFlags & KinectInterop.FrameSource.TypeBody) != 0)
                {
                    bodyDataFrameServer = new TcpNetServer(baseListenPort + (int)NetMessageType.BodyData, "BodyDataServer", sbConsole);
                    minPort             = Mathf.Min(minPort, bodyDataFrameServer.serverPort); maxPort = Mathf.Max(maxPort, bodyDataFrameServer.serverPort);
                }

                if ((dwFlags & KinectInterop.FrameSource.TypeBodyIndex) != 0 && serveBodyIndexFrames)
                {
                    bodyIndexFrameServer = new TcpNetServer(baseListenPort + (int)NetMessageType.BodyIndex, "BodyIndexServer", sbConsole);
                    minPort = Mathf.Min(minPort, bodyIndexFrameServer.serverPort); maxPort = Mathf.Max(maxPort, bodyIndexFrameServer.serverPort);

                    if (compressRawFrames)
                    {
                        bodyIndexFrameCompressor = LZ4CompressorFactory.CreateNew();
                    }
                }

                if ((dwFlags & KinectInterop.FrameSource.TypePose) != 0)
                {
                    poseFrameServer = new TcpNetServer(baseListenPort + (int)NetMessageType.Pose, "PoseServer", sbConsole);
                    minPort         = Mathf.Min(minPort, poseFrameServer.serverPort); maxPort = Mathf.Max(maxPort, poseFrameServer.serverPort);
                }

                if ((dwFlags & KinectInterop.FrameSource.TypeColor) != 0 && (dwFlags & KinectInterop.FrameSource.TypeDepth) != 0)
                {
                    depth2colorFrameServer = new TcpNetServer(baseListenPort + (int)NetMessageType.Depth2Color, "TColorServer", sbConsole);
                    minPort = Mathf.Min(minPort, depth2colorFrameServer.serverPort); maxPort = Mathf.Max(maxPort, depth2colorFrameServer.serverPort);
                }

                if ((dwFlags & KinectInterop.FrameSource.TypeColor) != 0 && (dwFlags & KinectInterop.FrameSource.TypeDepth) != 0)
                {
                    color2depthFrameServer = new TcpNetServer(baseListenPort + (int)NetMessageType.Color2Depth, "TDepthServer", sbConsole);
                    minPort = Mathf.Min(minPort, color2depthFrameServer.serverPort); maxPort = Mathf.Max(maxPort, color2depthFrameServer.serverPort);

                    if (compressRawFrames)
                    {
                        color2depthFrameCompressor = LZ4CompressorFactory.CreateNew();
                    }
                }

                if ((dwFlags & KinectInterop.FrameSource.TypeColor) != 0 && (dwFlags & KinectInterop.FrameSource.TypeDepth) != 0 && (dwFlags & KinectInterop.FrameSource.TypeBodyIndex) != 0)
                {
                    color2bodyIndexFrameServer = new TcpNetServer(baseListenPort + (int)NetMessageType.Color2BodyIndex, "TBodyIndex", sbConsole);
                    minPort = Mathf.Min(minPort, color2bodyIndexFrameServer.serverPort); maxPort = Mathf.Max(maxPort, color2bodyIndexFrameServer.serverPort);

                    if (compressRawFrames)
                    {
                        color2bodyIndexFrameCompressor = LZ4CompressorFactory.CreateNew();
                    }
                }

                if (serverStatusText)
                {
                    string localName = GetLocalNameOrIP();
                    serverStatusText.text = string.Format("NetServer listens on {0}:{1}-{2}", localName, minPort, maxPort);
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogError("Error initing NetServer: " + ex.Message);
                Debug.Log(ex);

                if (serverStatusText)
                {
                    serverStatusText.text = string.Format("Error initing NetServer: {0}", ex.Message);
                }
            }
        }
Exemplo n.º 14
0
 public LZ4Compressor()
 {
     _compressor   = LZ4CompressorFactory.CreateNew();
     _decompressor = LZ4DecompressorFactory.CreateNew();
 }
Exemplo n.º 15
0
 private static unsafe void TestEmpty(ILZ4Compressor compressor, ILZ4Decompressor decompressor)
 {
     var bytes = new byte[50];
     byte[] dst = compressor.Compress(bytes);
     var result = decompressor.Decompress(dst);
 }
Exemplo n.º 16
0
 public LZ4Compressor()
 {
     _compressor = LZ4CompressorFactory.CreateNew();
     _decompressor = LZ4DecompressorFactory.CreateNew();
 }
Exemplo n.º 17
0
 public LZ4Protection()
     : base()
 {
     this.Lz4Compressor   = new LZ4Compressor32();
     this.Lz4Decompressor = new LZ4Decompressor32();
 }