Beispiel #1
0
        public unsafe void RenderBitmap(IntPtr scan0, Bitmap bmp, Rectangle scanArea, Size size, PixelFormat format)
        {
            if (UnsafeCodec == null && VideoCodec == null)
            {
                return;
            }

            Stopwatch CaptureSW = Stopwatch.StartNew();

            CaptureSW.Stop();

            using (MemoryStream stream = new MemoryStream(1000000))
            {
                Stopwatch CodecSW = Stopwatch.StartNew();
                if (IsUnsafe)
                {
                    UnsafeCodec.CodeImage(scan0, scanArea, size, format, stream);
                }
                else
                {
                    VideoCodec.CodeImage(bmp, stream);
                }
                CodecSW.Stop();

                stream.Position = 0;
                Stopwatch DecodecSW    = Stopwatch.StartNew();
                Bitmap    DecodedImage = null;

                while (stream.Length > 0)
                {
                    stream.Position = 0;
                    if (IsUnsafe)
                    {
                        DecodedImage = UnsafeCodec.DecodeData(stream);
                    }
                    else
                    {
                        DecodedImage = VideoCodec.DecodeData(stream);
                    }
                }

                //DecodedImage = videoCodec.DecodeData(new IntPtr(temp), (uint)stream.Length);
                DecodecSW.Stop();

                if (UnsafeCodec as UnsafeQuickStream != null && DecodedImage != null)
                {
                    UnsafeQuickStream quickStream = UnsafeCodec as UnsafeQuickStream;
                    Graphics          g           = Graphics.FromImage(DecodedImage);
                    if (quickStream.VerifyPoints != null && quickStream.VerifyPoints.Count > 0)
                    {
                        g.DrawRectangles(new Pen(Color.Red, 1), quickStream.VerifyPoints.ToArray());
                    }
                    DecodedImage = bmp;
                }

                FrameCount++;
                _videoFPS++;
                StreamedSize += (ulong)stream.Length;
                _speedPerSec += (ulong)stream.Length;

                this.Invoke(new Invoky(() =>
                {
                    if (DecodedImage != null)
                    {
                        pictureBox1.Image = (Bitmap)DecodedImage.Clone();
                    }

                    if (MaxEncodeProcessTime < CodecSW.ElapsedMilliseconds)
                    {
                        MaxEncodeProcessTime = (int)CodecSW.ElapsedMilliseconds;
                    }
                    if (MinEncodeProcessTime > CodecSW.ElapsedMilliseconds)
                    {
                        MinEncodeProcessTime = (int)CodecSW.ElapsedMilliseconds;
                    }

                    if (MaxDecodeProcessTime < DecodecSW.ElapsedMilliseconds)
                    {
                        MaxDecodeProcessTime = (int)DecodecSW.ElapsedMilliseconds;
                    }
                    if (MinDecodeProcessTime > DecodecSW.ElapsedMilliseconds)
                    {
                        MinDecodeProcessTime = (int)DecodecSW.ElapsedMilliseconds;
                    }

                    label1.Text = "Capture time: " + CaptureSW.Elapsed.Seconds + ", " + CaptureSW.Elapsed.Milliseconds;
                    label2.Text = "Frames Processed: " + FrameCount;

                    if (IsUnsafe)
                    {
                        label3.Text  = "Buffers in codec: " + UnsafeCodec.BufferCount;
                        label4.Text  = "Codec: " + UnsafeCodec.GetType().Name;
                        label12.Text = "Cached size: " + Math.Round(((double)UnsafeCodec.CachedSize / 1000F) / 1000F, 2) + "MB";
                        label14.Text = "Image Quality: " + UnsafeCodec.ImageQuality + "%";
                    }
                    else
                    {
                        label3.Text  = "Buffers in codec: " + VideoCodec.BufferCount;
                        label4.Text  = "Codec: " + VideoCodec.GetType().Name;
                        label12.Text = "Cached size: " + Math.Round(((double)VideoCodec.CachedSize / 1000F) / 1000F, 2) + "MB";
                        label14.Text = "Image Quality: " + VideoCodec.ImageQuality + "%";
                    }

                    label6.Text  = "Stream size: " + Math.Round((float)stream.Length / 1000F, 2) + "KB";
                    label7.Text  = "Streamed size: " + Math.Round(((double)StreamedSize / 1000F) / 1000F, 2) + "MB";
                    label8.Text  = "Codec process time: " + CodecSW.Elapsed.Seconds + ", " + CodecSW.Elapsed.Milliseconds + " (FPS: " + Math.Round(1000F / CodecSW.Elapsed.Milliseconds, 0) + ")";
                    label9.Text  = "Video size: " + size.Width + " x " + size.Height;
                    label10.Text = "Decoding process time: " + DecodecSW.Elapsed.Seconds + ", " + DecodecSW.Elapsed.Milliseconds + " (FPS: " + Math.Round(1000F / DecodecSW.Elapsed.Milliseconds, 0) + ")";
                    label15.Text = "Max Encoding process time: " + MaxEncodeProcessTime;
                    label16.Text = "Min Encoding process time: " + MinEncodeProcessTime;
                    label17.Text = "Max Decoding process time: " + MaxDecodeProcessTime;
                    label18.Text = "Min Decoding process time: " + MinDecodeProcessTime;

                    if (VideoSW.ElapsedMilliseconds >= 1000)
                    {
                        VideoFPS     = _videoFPS;
                        SpeedPerSec  = _speedPerSec;
                        label5.Text  = "Video FPS: " + VideoFPS;
                        _videoFPS    = 0;
                        VideoSW      = Stopwatch.StartNew();
                        label13.Text = "Usage per second: " + Math.Round(((double)SpeedPerSec / 1000F) / 1000F, 2) + "MB";
                        _speedPerSec = 0;
                    }
                }));

                stream.Close();
                stream.Dispose();
            }
        }