Example #1
0
        public CaptureEncode(IDirect3DDevice device, GraphicsCaptureItem item)
        {
            _device      = device; _lastSize = item.Size;
            _d3dDevice   = Direct3D11Helpers.CreateSharpDXDevice(device);
            _captureItem = item;
            _isRecording = false;
            //_multithread = _d3dDevice.QueryInterface<SharpDX.Direct3D11.Multithread>();
            //_multithread.SetMultithreadProtected(true);
            //_frameEvent = new ManualResetEvent(false);
            //_closedEvent = new ManualResetEvent(false);
            //_events = new[] { _closedEvent, _frameEvent };

            CreateMediaObjects();
        }
        public CapturePreview(IDirect3DDevice device, GraphicsCaptureItem item)
        {
            _item      = item;
            _device    = device;
            _d3dDevice = Direct3D11Helpers.CreateSharpDXDevice(device);

            var dxgiDevice = _d3dDevice.QueryInterface <SharpDX.DXGI.Device>();
            var adapter    = dxgiDevice.GetParent <SharpDX.DXGI.Adapter>();
            var factory    = adapter.GetParent <SharpDX.DXGI.Factory2>();

            var description = new SharpDX.DXGI.SwapChainDescription1 {
                Width             = item.Size.Width,
                Height            = item.Size.Height,
                Format            = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                Usage             = SharpDX.DXGI.Usage.RenderTargetOutput,
                SampleDescription = new SharpDX.DXGI.SampleDescription()
                {
                    Count   = 1,
                    Quality = 0
                },
                BufferCount = 2,
                Scaling     = SharpDX.DXGI.Scaling.Stretch,
                SwapEffect  = SharpDX.DXGI.SwapEffect.FlipSequential,
                AlphaMode   = SharpDX.DXGI.AlphaMode.Premultiplied
            };

            _swapChain = new SharpDX.DXGI.SwapChain1(factory, dxgiDevice, ref description);

            _framePool = Direct3D11CaptureFramePool.CreateFreeThreaded(
                _device,
                DirectXPixelFormat.B8G8R8A8UIntNormalized,
                2,
                item.Size);
            _session  = _framePool.CreateCaptureSession(item);
            _lastSize = item.Size;

            _framePool.FrameArrived += OnFrameArrived;//新帧到达事件
        }