Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
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;
 }
        public static byte[] CompressToLz4(byte[] buffer)
        {
#if NETSTANDARD2_0
            var inputLength   = buffer.Length;
            var maximumLength = LZ4Codec.MaximumOutputLength(inputLength);
            var outputBuffer  = new byte[maximumLength];

            var outputLength = LZ4Codec.Encode(
                buffer, 0, inputLength,
                outputBuffer, 0, maximumLength);

            if (outputLength < maximumLength)
            {
                return(outputBuffer.Take(outputLength).ToArray());
            }
            else
            {
                return(outputBuffer);
            }
#else
            var compressor = LZ4CompressorFactory.CreateNew();
            return(compressor.Compress(buffer));
#endif
        }
        public static byte[] CompressToLz4(byte[] buffer)
        {
            var compressor = LZ4CompressorFactory.CreateNew();

            return(compressor.Compress(buffer));
        }
Ejemplo n.º 6
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);
                }
            }
        }
Ejemplo n.º 7
0
 public LZ4Compressor()
 {
     _compressor   = LZ4CompressorFactory.CreateNew();
     _decompressor = LZ4DecompressorFactory.CreateNew();
 }
Ejemplo n.º 8
0
 public static byte[] Compress(byte[] source)
 {
     return(LZ4CompressorFactory.CreateNew().Compress(source));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Compress source into dest returning compressed length
 /// </summary>
 /// <param name="source">uncompressed data</param>
 /// <param name="srcOffset">offset in source array where reading will start</param>
 /// <param name="count">count of bytes in source array to compress</param>
 /// <param name="dest">array into which source will be compressed</param>
 /// <param name="dstOffset">start index in dest array where writing will start</param>
 /// <returns>compressed length</returns>
 public static int Compress(byte[] source, int srcOffset, int count, byte[] dest, int dstOffset)
 {
     return(LZ4CompressorFactory.CreateNew().Compress(source, srcOffset, count, dest, dstOffset));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Compress source into dest returning compressed length
 /// </summary>
 /// <param name="source">uncompressed data</param>
 /// <param name="dest">array into which source will be compressed</param>
 /// <returns>compressed length</returns>
 public static int Compress(byte[] source, byte[] dest)
 {
     return(LZ4CompressorFactory.CreateNew().Compress(source, dest));
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Calculate the max compressed byte[] size given the size of the uncompressed byte[]
 /// </summary>
 /// <param name="uncompressedLength">Length of the uncompressed data</param>
 /// <returns>The maximum required size in bytes of the compressed data</returns>
 public static int CalculateMaxCompressedLength(int uncompressedLength)
 {
     return(LZ4CompressorFactory.CreateNew().CalculateMaxCompressedLength(uncompressedLength));
 }