Ejemplo n.º 1
0
        private bool _Draw(byte[] buffer)
        {
            var rgb = _scale.Convert(buffer);

            if (_image == null)
            {
                _image = new Bitmap(_width, _height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            }

            BitmapData imageData = _image.LockBits(new Rectangle(0, 0, _width, _height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            Marshal.Copy(rgb, 0, imageData.Scan0, rgb.Length);

            _image.UnlockBits(imageData);
            try {
                if (_control.IsHandleCreated && !_control.IsDisposed)
                {
                    var g = _control.CreateGraphics();
                    g.DrawImage(_image, new Rectangle(0, 0, _control.Width, _control.Height));
                    g.Dispose();
                }
            } catch (Exception e) {
                if (_control.IsHandleCreated && !_control.IsDisposed)
                {
                }
                else
                {
                    throw;
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        private byte[] Capture()
        {
            try
            {
                Bitmap bitmap = new Bitmap(this.Canvas.Size.Width, this.Canvas.Size.Height);
                using (GraphicsBase g = GraphicsGDIPuls.FromImage(bitmap))
                {
                    this.Canvas.Draw(g);
                }
                BitmapData imageData = bitmap.LockBits(new Rectangle(0, 0, _width, _height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                byte[]     bs        = new byte[_width * _height * 3];
                Marshal.Copy(imageData.Scan0, bs, 0, bs.Length);
                bitmap.UnlockBits(imageData);
                bitmap.Dispose();
                var @out = _ffscale.Convert(bs);
                return(@out);
            }
            catch (Exception e)
            {
                //if (AppConfig._D)
                //    throw;

                return(null);
            }
        }
Ejemplo n.º 3
0
        private void YUVFrame(object sender, AForge.Video.DirectShow.RGBRawFrameEventArgs e)
        {
            byte[] buffer = FunctionEx.IntPtrToBytes(e.Buffer, 0, e.Len);
            buffer = _ffscale.Convert(buffer);

            if (_callBack != null)
            {
                _callBack(buffer);
            }
        }
Ejemplo n.º 4
0
        private byte[] Capture()
        {
            //if (AppConfig._D)
            //    return Capture_D();

            try
            {
                int _CX = 0, _CY = 0;
                var dt = DateTime.Now;

                Bitmap bmp = new Bitmap(GetSystemMetrics(0), GetSystemMetrics(1));
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    g.CopyFromScreen(0, 0, 0, 0, bmp.Size);
                    //var bmp_tmp = CaptureCursor(ref _CX, ref _CY);
                    //g.DrawImage(bmp_tmp, _CX, _CY);
                    g.Dispose();
                }
                var bmp1 = KiResizeImage(bmp, _width, _height);

                bmp.Dispose();

                bmp = bmp1;

                BitmapData imageData = bmp.LockBits(new Rectangle(0, 0, _width, _height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                byte[]     bs        = new byte[_width * _height * 3];
                Marshal.Copy(imageData.Scan0, bs, 0, bs.Length);
                bmp.UnlockBits(imageData);
                var @out = _ffscale.Convert(bs);
                return(@out);
            }
            catch (Exception e)
            {
                //if (AppConfig._D)
                //    throw;

                return(null);
            }
        }
Ejemplo n.º 5
0
        //回调函数
        private void SampleGrabber_Callback(double SampleTime, IntPtr pBuf, int len)
        {
            if (_isDisoseing || _isDisosed)
            {
                return;
            }

            if (!_isworking)
            {
                return;
            }

            var buf = FunctionEx.IntPtrToBytes(pBuf, 0, len);

            buf = _ffscale.Convert(buf);

            if (_callBack != null)
            {
                _callBack(buf);
            }
        }
Ejemplo n.º 6
0
        protected void CameraCapturer_CallBack(byte[] yuv)
        {
            if (!_isworking)
            {
                return;
            }
            try
            {
                Draw(yuv);

                if ((Environment.TickCount - _lastTick) < 1000 / _fps)
                {
                    return;
                }

                _lastTick = Environment.TickCount;

                var yv12 = _ffscale.Convert(yuv);

                if (_needForceIDRFrame)
                {
                    _needForceIDRFrame = false;
                    _x264.ForceIDRFrame();
                }

                var enc = _x264.Encode(yv12);



                var mf = new MediaFrame()
                {
                    nWidth            = _cfgVideo.width,
                    nHeight           = _cfgVideo.height,
                    nEx               = 1,
                    nIsAudio          = 0,
                    nEncoder          = MediaFrame.H264Encoder,
                    nIsKeyFrame       = (byte)(_x264.IsKeyFrame() ? 1 : 0),
                    MediaFrameVersion = 0,
                    nPPSLen           = 0,
                    nSPSLen           = 0,
                    Data              = enc,
                    nSize             = enc.Length,
                    nTimetick         = Environment.TickCount,
                };

                if (mf.nIsKeyFrame == 1)
                {
                    var sps_pps = SS.ClientBase.Media.MediaSteamConverter.GetSPS_PPS(enc);
                    mf.nSPSLen = (short)sps_pps[0].Length;
                    mf.nPPSLen = (short)sps_pps[1].Length;
                }
                mf.MediaFrameVersion = mf.nIsKeyFrame;



                if (_needClearVideoTransportBuffer)
                {
                    _needClearVideoTransportBuffer = false;
                    var frame = CreateClearVideoTransportBufferMediaFrame(mf);
                    if (_callBack != null)
                    {
                        _callBack(frame);
                    }
                }

                if (_isFirstKeyFrame)
                {
                    if (mf.nIsKeyFrame == 1)
                    {
                        mf.nEx = 0;
                    }
                    _isFirstKeyFrame = false;
                    var frame = CreateResetCodecMediaFrame(mf);
                    if (_callBack != null)
                    {
                        _callBack(frame);
                    }
                }

                if (_callBack != null)
                {
                    _callBack(mf);
                }
            }
            catch (Exception e)
            {
                if (_isworking)
                {
                    throw;
                }
            }
        }