Ejemplo n.º 1
0
        public void OnAcceleratedPaint(CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr sharedHandle)
        {
            try
            {
                if (sharedHandle == IntPtr.Zero)
                {
                    return;
                }

                var d3dDevice = SharpDXInterop.GetNativeDevice(GraphicsDevice) as Device;
                if (d3dDevice is null)
                {
                    return;
                }

                var d3dTexture = d3dDevice.OpenSharedResource <Texture2D>(sharedHandle);
                if (d3dTexture is null)
                {
                    return;
                }

                var strideTexture = SharpDXInterop.CreateTextureFromNative(GraphicsDevice, d3dTexture, takeOwnership: true);
                lock (syncRoot)
                {
                    surface?.Dispose();
                    surface = strideTexture;
                }
                needsConversion = true;
            }
            catch (Exception e)
            {
                RuntimeGraph.ReportException(e);
            }
        }
Ejemplo n.º 2
0
        public VideoPlayer(NodeContext nodeContext)
        {
            renderDrawContextHandle = nodeContext.GetGameProvider()
                                      .Bind(g => RenderContext.GetShared(g.Services).GetThreadContext())
                                      .GetHandle() ?? throw new ServiceNotFoundException(typeof(IResourceProvider <Game>));

            colorSpaceConverter = new ColorSpaceConverter(renderDrawContextHandle.Resource);

            // Initialize MediaFoundation
            MediaManagerService.Initialize();

            using var mediaEngineAttributes = new MediaEngineAttributes()
                  {
                      // _SRGB doesn't work :/ Getting invalid argument exception later in TransferVideoFrame
                      AudioCategory     = SharpDX.Multimedia.AudioStreamCategory.GameMedia,
                      AudioEndpointRole = SharpDX.Multimedia.AudioEndpointRole.Multimedia,
                      VideoOutputFormat = (int)SharpDX.DXGI.Format.B8G8R8A8_UNorm
                  };

            var graphicsDevice = renderDrawContextHandle.Resource.GraphicsDevice;
            var device         = SharpDXInterop.GetNativeDevice(graphicsDevice) as Device;

            if (device != null)
            {
                // Add multi thread protection on device (MF is multi-threaded)
                using var deviceMultithread = device.QueryInterface <DeviceMultithread>();
                deviceMultithread.SetMultithreadProtected(true);


                // Reset device
                using var manager = new DXGIDeviceManager();
                manager.ResetDevice(device);
                mediaEngineAttributes.DxgiManager = manager;
            }

            using var classFactory = new MediaEngineClassFactory();
            engine = new MediaEngine(classFactory, mediaEngineAttributes);
            engine.PlaybackEvent += Engine_PlaybackEvent;
        }