Esempio n. 1
0
        public virtual void Initialize(DeviceManager deviceManager)
        {
            lock (lockObject)
            {
                // Startup MediaManager
                MediaManager.Startup();

                // Setup multithread on the Direct3D11 device
                var multithread = deviceManager.DeviceDirect3D.QueryInterface<SharpDX.Direct3D.DeviceMultithread>();
                multithread.SetMultithreadProtected(true);

                // Create a DXGI Device Manager
                dxgiDeviceManager = new DXGIDeviceManager();
                dxgiDeviceManager.ResetDevice(deviceManager.DeviceDirect3D);

                // Setup Media Engine attributes
                var attributes = new MediaEngineAttributes
                                     {
                                         DxgiManager = dxgiDeviceManager,
                                         VideoOutputFormat = (int) SharpDX.DXGI.Format.B8G8R8A8_UNorm
                                     };

                using (var factory = new MediaEngineClassFactory())
                    mediaEngine = new MediaEngine(factory, attributes, MediaEngineCreateFlags.WaitForStableState, OnMediaEngineEvent);                
                mediaEngineEx = mediaEngine.QueryInterface<MediaEngineEx>();
            }
        }
Esempio n. 2
0
        private void PlatformInitialize()
        {
            MediaManager.Startup();

            _devManager = new DXGIDeviceManager();
            _devManager.ResetDevice(Game.Instance.GraphicsDevice._d3dDevice);

            using (var factory = new MediaEngineClassFactory())
            using (var attributes = new MediaEngineAttributes
            {
                VideoOutputFormat = (int)SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                DxgiManager = _devManager
                
            })
            {
                _mediaEngine = new MediaEngine(factory, attributes, MediaEngineCreateFlags.None, OnMediaEngineEvent);
            }
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            //this.mediaEngine.Play();
            //this.mediaEngine.Load();
            // this.mediaEngine.GetNativeVideoSize(out width, out height);

            context = new SharpDXContext();
            context.Render += context_Render;
            context.DeviceReset += context_DeviceReset;
            context.BindToControl(this.Surface);

            DeviceMultithread mt = context.D3DDevice.QueryInterface<DeviceMultithread>();
            mt.SetMultithreadProtected(true);

            deviceManager = new DXGIDeviceManager();
            deviceManager.ResetDevice(context.D3DDevice);

            MediaEngineAttributes attr = new MediaEngineAttributes();
            attr.VideoOutputFormat = (int)SharpDX.DXGI.Format.B8G8R8A8_UNorm;
            attr.DxgiManager = deviceManager;

            this.mediaFactory = new MediaEngineClassFactory();
            this.mediaEngine = new MediaEngine(this.mediaFactory, attr, MediaEngineCreateFlags.None);
            // this.mediaEngineEx = this.mediaEngine.QueryInterface<MediaEngineEx>();
            this.mediaEngine.PlaybackEvent += mediaEngine_PlaybackEvent;

            this.mediaEngine.Source = Package.Current.InstalledLocation.Path + "/Assets/keloid.mp4";
            this.mediaEngine.Load();

            ushort[] indices = new ushort[]
            {
                0, 1, 2,
                2, 3, 0,
            };

            this.indexBuffer = SharpDX.Direct3D11.Buffer.Create<ushort>(this.context.D3DDevice, BindFlags.IndexBuffer, indices);

            float[] vertices = new float[]
            {
                                      // 3D coordinates              UV Texture coordinates
                                      -1.0f, -1.0f, -1.0f, 1.0f,     0.0f, 1.0f, // Front
                                      -1.0f,  1.0f, -1.0f, 1.0f,     0.0f, 0.0f,
                                       1.0f,  1.0f, -1.0f, 1.0f,     1.0f, 0.0f,
                                      -1.0f, -1.0f, -1.0f, 1.0f,     0.0f, 1.0f,
                                       1.0f,  1.0f, -1.0f, 1.0f,     1.0f, 0.0f,
                                       1.0f, -1.0f, -1.0f, 1.0f,     1.0f, 1.0f,

                                      -1.0f, -1.0f,  1.0f, 1.0f,     1.0f, 0.0f, // BACK
                                       1.0f,  1.0f,  1.0f, 1.0f,     0.0f, 1.0f,
                                      -1.0f,  1.0f,  1.0f, 1.0f,     1.0f, 1.0f,
                                      -1.0f, -1.0f,  1.0f, 1.0f,     1.0f, 0.0f,
                                       1.0f, -1.0f,  1.0f, 1.0f,     0.0f, 0.0f,
                                       1.0f,  1.0f,  1.0f, 1.0f,     0.0f, 1.0f,

                                      -1.0f, 1.0f, -1.0f,  1.0f,     0.0f, 1.0f, // Top
                                      -1.0f, 1.0f,  1.0f,  1.0f,     0.0f, 0.0f,
                                       1.0f, 1.0f,  1.0f,  1.0f,     1.0f, 0.0f,
                                      -1.0f, 1.0f, -1.0f,  1.0f,     0.0f, 1.0f,
                                       1.0f, 1.0f,  1.0f,  1.0f,     1.0f, 0.0f,
                                       1.0f, 1.0f, -1.0f,  1.0f,     1.0f, 1.0f,

                                      -1.0f,-1.0f, -1.0f,  1.0f,     1.0f, 0.0f, // Bottom
                                       1.0f,-1.0f,  1.0f,  1.0f,     0.0f, 1.0f,
                                      -1.0f,-1.0f,  1.0f,  1.0f,     1.0f, 1.0f,
                                      -1.0f,-1.0f, -1.0f,  1.0f,     1.0f, 0.0f,
                                       1.0f,-1.0f, -1.0f,  1.0f,     0.0f, 0.0f,
                                       1.0f,-1.0f,  1.0f,  1.0f,     0.0f, 1.0f,

                                      -1.0f, -1.0f, -1.0f, 1.0f,     0.0f, 1.0f, // Left
                                      -1.0f, -1.0f,  1.0f, 1.0f,     0.0f, 0.0f,
                                      -1.0f,  1.0f,  1.0f, 1.0f,     1.0f, 0.0f,
                                      -1.0f, -1.0f, -1.0f, 1.0f,     0.0f, 1.0f,
                                      -1.0f,  1.0f,  1.0f, 1.0f,     1.0f, 0.0f,
                                      -1.0f,  1.0f, -1.0f, 1.0f,     1.0f, 1.0f,

                                       1.0f, -1.0f, -1.0f, 1.0f,     1.0f, 0.0f, // Right
                                       1.0f,  1.0f,  1.0f, 1.0f,     0.0f, 1.0f,
                                       1.0f, -1.0f,  1.0f, 1.0f,     1.0f, 1.0f,
                                       1.0f, -1.0f, -1.0f, 1.0f,     1.0f, 0.0f,
                                       1.0f,  1.0f, -1.0f, 1.0f,     0.0f, 0.0f,
                                       1.0f,  1.0f,  1.0f, 1.0f,     0.0f, 1.0f,            };

            this.vertexBuffer = SharpDX.Direct3D11.Buffer.Create<float>(this.context.D3DDevice, BindFlags.VertexBuffer, vertices);
            this.bufferBinding = new VertexBufferBinding(this.vertexBuffer, sizeof(float) * 6, 0);

            var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;

            // Loads vertex shader bytecode
            var vertexShaderByteCode = NativeFile.ReadAllBytes(path + "\\MiniCubeTexture_VS.fxo");
            this.vertexShader = new VertexShader(this.context.D3DDevice, vertexShaderByteCode);

            this.inputLayout = new InputLayout(this.context.D3DDevice, vertexShaderByteCode, new[]
                    {
                new InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32A32_Float, 0, 0),
                new InputElement("TEXCOORD", 0, SharpDX.DXGI.Format.R32G32_Float, 16, 0)
                    });

            this.pixelShader = new PixelShader(this.context.D3DDevice, NativeFile.ReadAllBytes(path + "\\MiniCubeTexture_PS.fxo"));

            this.constantBuffer = new SharpDX.Direct3D11.Buffer(this.context.D3DDevice, Utilities.SizeOf<Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            this.sampler = new SamplerState(this.context.D3DDevice, new SamplerStateDescription()
            {
                Filter = Filter.MinMagMipLinear,
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                BorderColor = Color.Black,
                ComparisonFunction = Comparison.Never,
                MaximumAnisotropy = 16,
                MipLodBias = 0,
                MinimumLod = -float.MaxValue,
                MaximumLod = float.MaxValue
            });

            base.OnNavigatedTo(e);
        }
Esempio n. 4
0
        /// <summary>
        /// Creates device with necessary flags for video processing
        /// </summary>
        /// <param name="manager">DXGI Manager, used to create media engine</param>
        /// <returns>Device with video support</returns>
        private static DXDevice CreateDeviceForVideo(out DXGIDeviceManager manager)
        {
            //Device need bgra and video support
            var device = new DXDevice(SharpDX.Direct3D.DriverType.Hardware, DeviceCreationFlags.BgraSupport | DeviceCreationFlags.VideoSupport);

            //Add multi thread protection on device
            DeviceMultithread mt = device.QueryInterface<DeviceMultithread>();
            mt.SetMultithreadProtected(true);

            //Reset device
            manager = new DXGIDeviceManager();
            manager.ResetDevice(device);

            return device;
        }