Exemple #1
0
        void videoPanelViewModel_VideoOpened(Object sender, EventArgs e)
        {
            for (int i = 0; i < nrTextures; i++)
            {
                Disposer.RemoveAndDispose(ref this.yuvTexture[i]);
                Disposer.RemoveAndDispose(ref this.textureView[i]);
            }

            if (videoPlayerViewModel.DecodedVideoFormat == VideoLib.VideoPlayer.DecodedVideoFormat.YUV420P)
            {
                int width  = videoPlayerViewModel.Width;
                int height = videoPlayerViewModel.Height;

                yuvTexture[0] = createTexture(width, height, Format.R8_UNorm);
                yuvTexture[1] = createTexture(width / 2, height / 2, Format.R8_UNorm);
                yuvTexture[2] = createTexture(width / 2, height / 2, Format.R8_UNorm);

                nrTextures = 3;
            }
            else
            {
                yuvTexture[0] = createTexture(videoPlayerViewModel.Width, videoPlayerViewModel.Height, Format.B8G8R8A8_UNorm);

                nrTextures = 1;
            }

            Device device = Host.Device;

            for (int i = 0; i < nrTextures; i++)
            {
                ShaderResourceViewDescription desc = new ShaderResourceViewDescription();
                desc.Format                    = yuvTexture[i].Description.Format;
                desc.Dimension                 = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D;
                desc.Texture2D.MipLevels       = yuvTexture[i].Description.MipLevels;
                desc.Texture2D.MostDetailedMip = yuvTexture[i].Description.MipLevels - 1;

                textureView[i] = new ShaderResourceView(device, yuvTexture[i], desc);
            }

            viewport = setupViewport(videoPlayerViewModel.Width, videoPlayerViewModel.Height);

            device.Flush();

            DPFCanvas canvas = (DPFCanvas)Host;

            canvas.StartRendering();
        }
Exemple #2
0
        Viewport setupViewport(int videoWidth, int videoHeight)
        {
            DPFCanvas canvas       = (DPFCanvas)Host;
            double    screenWidth  = canvas.ActualWidth;
            double    screenHeight = canvas.ActualHeight;

            System.Drawing.Rectangle screenRect = new System.Drawing.Rectangle(0, 0, (int)screenWidth, (int)screenHeight);

            System.Drawing.Rectangle videoRect = Utils.ImageUtils.stretchRectangle(new System.Drawing.Rectangle(0, 0, videoWidth, videoHeight),
                                                                                   screenRect);

            videoRect = Utils.ImageUtils.centerRectangle(screenRect, videoRect);

            Viewport viewport = new Viewport(new DrawingRectangle(videoRect.X, videoRect.Y, videoRect.Width, videoRect.Height));

            return(viewport);
        }
Exemple #3
0
        private void videoPanelViewModel_VideoClosed(object sender, EventArgs e)
        {
            DPFCanvas canvas = (DPFCanvas)Host;

            canvas.StopRendering();
        }