This class will draw a video texture onscreen when using VMR9 renderless Its controlled by the allocator wrapper Example on how to use: PlaneScene scene = new PlaneScene(GUIGraphicsContext.RenderGUI) scene.Init() ... allocate direct3d texture scene.SetSrcRect(1.0f,1.0f); //change this depending on the texture dimensions scene.SetSurface(texture); //change this depending on the texture dimensions while (playingMovie) { scene.Render(GUIGraphicsContext.DX9Device, videoTextre, videoSize) } scene.ReleaseSurface(texture) scene.Stop(); scene.DeInit();
Inheritance: IVMR9PresentCallback, IRenderLayer
Exemple #1
0
        /// <summary>
        /// removes the vmr9 filter from the graph and free up all unmanaged resources
        /// </summary>
        public void Dispose()
        {
            Log.Debug("VMR9: Dispose");
            if (false == _isVmr9Initialized)
            {
                return;
            }
            if (_threadId != Thread.CurrentThread.ManagedThreadId)
            {
                Log.Error("VMR9: Dispose() from wrong thread");
                //return;
            }
            if (_vmr9Filter == null)
            {
                Log.Error("VMR9: Dispose() no filter");
                return;
            }

            if (_scene != null)
            {
                _scene.Stop();
                _instanceCounter--;
                _scene.Deinit();
                GUIGraphicsContext.Vmr9Active   = false;
                GUIGraphicsContext.Vmr9FPS      = 0f;
                GUIGraphicsContext.InVmr9Render = false;
                currentVmr9State = Vmr9PlayState.Playing;
            }

            _vmr9MixerBitmapInterface = null;

            _qualityInterface = null;

            if (GUIGraphicsContext.IsEvr)
            {
                EvrDeinit();
            }
            else
            {
                Vmr9Deinit();
            }

            DirectShowUtil.ReleaseComObject(_vmr9Filter);
            _vmr9Filter            = null;
            _graphBuilderInterface = null;
            _scene             = null;
            g_vmr9             = null;
            _isVmr9Initialized = false;
        }
Exemple #2
0
    //public bool IsVMR9Connected

    #endregion

    #region public members

    /// <summary>
    /// Add VMR9 filter to graph and configure it
    /// </summary>
    /// <param name="graphBuilder"></param>
    public bool AddVMR9(IGraphBuilder graphBuilder)
    {
      if (!_useVmr9)
      {
        Log.Debug("VMR9: addvmr9 - vmr9 is deactivated");
        return false;
      }
      if (_isVmr9Initialized)
      {
        Log.Debug("VMR9: addvmr9: vmr9 has already been initialized");
        return false;
      }

      bool _useEvr = GUIGraphicsContext.IsEvr;

      if (_instanceCounter != 0)
      {
        Log.Error("VMR9: Multiple instances of VMR9 running!!!");
        throw new Exception("VMR9Helper: Multiple instances of VMR9 running!!!");
      }

      HResult hr;
      IntPtr hMonitor = Manager.GetAdapterMonitor(GUIGraphicsContext.DX9Device.DeviceCaps.AdapterOrdinal);
      IntPtr upDevice = DirectShowUtil.GetUnmanagedDevice(GUIGraphicsContext.DX9Device);

      _scene = new PlaneScene(this);
      _scene.Init();

      if (_useEvr)
      {
        EvrInit(_scene, (uint)upDevice.ToInt32(), ref _vmr9Filter, (uint)hMonitor.ToInt32());
        hr = new HResult(graphBuilder.AddFilter(_vmr9Filter, "Enhanced Video Renderer"));
        Log.Info("VMR9: added EVR Renderer to graph");
      }
      else
      {
        _vmr9Filter = (IBaseFilter)new VideoMixingRenderer9();
        Log.Info("VMR9: added Video Mixing Renderer 9 to graph");

        Vmr9Init(_scene, (uint)upDevice.ToInt32(), _vmr9Filter, (uint)hMonitor.ToInt32());
        hr = new HResult(graphBuilder.AddFilter(_vmr9Filter, "Video Mixing Renderer 9"));
      }

      if (_vmr9Filter == null)
      {
        Error.SetError("Unable to play movie", "Renderer could not be added");
        Log.Error("VMR9: Renderer not installed / cannot be used!");
        return false;
      }

      if (hr != 0)
      {
        if (_useEvr)
        {
          EvrDeinit();
        }
        else
        {
          Vmr9Deinit();
        }
        _scene.Stop();
        _scene.Deinit();
        _scene = null;

        DirectShowUtil.ReleaseComObject(_vmr9Filter);
        _vmr9Filter = null;
        Error.SetError("Unable to play movie", "Unable to initialize Renderer");
        Log.Error("VMR9: Failed to add Renderer to filter graph");
        return false;
      }

      _qualityInterface = _vmr9Filter as IQualProp;
      _vmr9MixerBitmapInterface = _vmr9Filter as IVMRMixerBitmap9;
      _graphBuilderInterface = graphBuilder;
      _instanceCounter++;
      _isVmr9Initialized = true;
      if (!_useEvr)
      {
        SetDeinterlacePrefs();

        IVMRMixerControl9 mixer = _vmr9Filter as IVMRMixerControl9;
        if (mixer != null)
        {
          VMR9MixerPrefs dwPrefs;
          mixer.GetMixingPrefs(out dwPrefs);
          dwPrefs &= ~VMR9MixerPrefs.RenderTargetMask;

          dwPrefs |= VMR9MixerPrefs.RenderTargetYUV;
          // YUV saves graphics bandwith  http://msdn2.microsoft.com/en-us/library/ms788177(VS.85).aspx
          hr.Set(mixer.SetMixingPrefs(dwPrefs));
          Log.Debug("VMR9: Enabled YUV mixing - " + hr.ToDXString());

          using (Settings xmlreader = new MPSettings())
          {
            //Enable nonsquaremixing
            if (xmlreader.GetValueAsBool("general", "nonsquare", true))
            {
              mixer.GetMixingPrefs(out dwPrefs);
              dwPrefs |= VMR9MixerPrefs.NonSquareMixing;
              hr.Set(mixer.SetMixingPrefs(dwPrefs));
              Log.Debug("VRM9: Turning on nonsquare mixing - " + hr.ToDXString());
              hr.Set(mixer.SetMixingPrefs(dwPrefs));
            }

            // Enable DecimateMask - this will effectively use only half of the input width & length
            if (xmlreader.GetValueAsBool("general", "dx9decimatemask", false))
            {
              mixer.GetMixingPrefs(out dwPrefs);
              dwPrefs &= ~VMR9MixerPrefs.DecimateMask;
              dwPrefs |= VMR9MixerPrefs.DecimateOutput;
              hr.Set(mixer.SetMixingPrefs(dwPrefs));
              Log.Debug("VRM9: Enable decimatemask - " + hr.ToDXString());
              hr.Set(mixer.SetMixingPrefs(dwPrefs));
            }

            // see  D3DTEXTUREFILTERTYPE Enumerated Type documents for further information
            // MixerPref9_PointFiltering
            // MixerPref9_BiLinearFiltering
            // MixerPref9_AnisotropicFiltering
            // MixerPref9_PyramidalQuadFiltering
            // MixerPref9_GaussianQuadFiltering

            mixer.SetMixingPrefs(dwPrefs);
            mixer.GetMixingPrefs(out dwPrefs);
            dwPrefs &= ~VMR9MixerPrefs.FilteringMask;
            string filtermode9 = xmlreader.GetValueAsString("general", "dx9filteringmode", "Gaussian Quad Filtering");
            if (filtermode9 == "Point Filtering")
            {
              dwPrefs |= VMR9MixerPrefs.PointFiltering;
            }
            else if (filtermode9 == "Bilinear Filtering")
            {
              dwPrefs |= VMR9MixerPrefs.BiLinearFiltering;
            }
            else if (filtermode9 == "Anisotropic Filtering")
            {
              dwPrefs |= VMR9MixerPrefs.AnisotropicFiltering;
            }
            else if (filtermode9 == "Pyrimidal Quad Filtering")
            {
              dwPrefs |= VMR9MixerPrefs.PyramidalQuadFiltering;
            }
            else
            {
              dwPrefs |= VMR9MixerPrefs.GaussianQuadFiltering;
            }

            hr.Set(mixer.SetMixingPrefs(dwPrefs));
            Log.Debug("VRM9: Set filter mode - " + filtermode9 + " " + hr.ToDXString());
          }
        }
      }
      _threadId = Thread.CurrentThread.ManagedThreadId;
      GUIGraphicsContext.Vmr9Active = true;
      g_vmr9 = this;
      Log.Debug("VMR9: Renderer successfully added");
      return true;
    }
Exemple #3
0
    /// <summary>
    /// removes the vmr9 filter from the graph and free up all unmanaged resources
    /// </summary>
    public void Dispose()
    {
      Log.Debug("VMR9: Dispose");
      if (false == _isVmr9Initialized)
      {
        return;
      }
      if (_threadId != Thread.CurrentThread.ManagedThreadId)
      {
        Log.Error("VMR9: Dispose() from wrong thread");
        //return;
      }
      if (_vmr9Filter == null)
      {
        Log.Error("VMR9: Dispose() no filter");
        return;
      }

      if (_scene != null)
      {
        _scene.Stop();
        _instanceCounter--;
        _scene.Deinit();
        GUIGraphicsContext.Vmr9Active = false;
        GUIGraphicsContext.Vmr9FPS = 0f;
        GUIGraphicsContext.InVmr9Render = false;
        currentVmr9State = Vmr9PlayState.Playing;
      }

      _vmr9MixerBitmapInterface = null;

      _qualityInterface = null;

      if (GUIGraphicsContext.IsEvr)
      {
        EvrDeinit();
      }
      else
      {
        Vmr9Deinit();
      }

      DirectShowUtil.ReleaseComObject(_vmr9Filter);
      _vmr9Filter = null;
      _graphBuilderInterface = null;
      _scene = null;
      g_vmr9 = null;
      _isVmr9Initialized = false;
    }
Exemple #4
0
        //public bool IsVMR9Connected

        #endregion

        #region public members

        /// <summary>
        /// Add VMR9 filter to graph and configure it
        /// </summary>
        /// <param name="graphBuilder"></param>
        public bool AddVMR9(IGraphBuilder graphBuilder)
        {
            if (!_useVmr9)
            {
                Log.Debug("VMR9: addvmr9 - vmr9 is deactivated");
                return(false);
            }
            if (_isVmr9Initialized)
            {
                Log.Debug("VMR9: addvmr9: vmr9 has already been initialized");
                return(false);
            }

            bool _useEvr = GUIGraphicsContext.IsEvr;

            if (_instanceCounter != 0)
            {
                Log.Error("VMR9: Multiple instances of VMR9 running!!!");
                throw new Exception("VMR9Helper: Multiple instances of VMR9 running!!!");
            }

            HResult hr;
            IntPtr  hMonitor = Manager.GetAdapterMonitor(GUIGraphicsContext.DX9Device.DeviceCaps.AdapterOrdinal);
            IntPtr  upDevice = DirectShowUtil.GetUnmanagedDevice(GUIGraphicsContext.DX9Device);

            _scene = new PlaneScene(this);
            _scene.Init();

            if (_useEvr)
            {
                EvrInit(_scene, (uint)upDevice.ToInt32(), ref _vmr9Filter, (uint)hMonitor.ToInt32());
                hr = new HResult(graphBuilder.AddFilter(_vmr9Filter, "Enhanced Video Renderer"));
                Log.Info("VMR9: added EVR Renderer to graph");
            }
            else
            {
                _vmr9Filter = (IBaseFilter) new VideoMixingRenderer9();
                Log.Info("VMR9: added Video Mixing Renderer 9 to graph");

                Vmr9Init(_scene, (uint)upDevice.ToInt32(), _vmr9Filter, (uint)hMonitor.ToInt32());
                hr = new HResult(graphBuilder.AddFilter(_vmr9Filter, "Video Mixing Renderer 9"));
            }

            if (_vmr9Filter == null)
            {
                Error.SetError("Unable to play movie", "Renderer could not be added");
                Log.Error("VMR9: Renderer not installed / cannot be used!");
                return(false);
            }

            if (hr != 0)
            {
                if (_useEvr)
                {
                    EvrDeinit();
                }
                else
                {
                    Vmr9Deinit();
                }
                _scene.Stop();
                _scene.Deinit();
                _scene = null;

                DirectShowUtil.ReleaseComObject(_vmr9Filter);
                _vmr9Filter = null;
                Error.SetError("Unable to play movie", "Unable to initialize Renderer");
                Log.Error("VMR9: Failed to add Renderer to filter graph");
                return(false);
            }

            _qualityInterface         = _vmr9Filter as IQualProp;
            _vmr9MixerBitmapInterface = _vmr9Filter as IVMRMixerBitmap9;
            _graphBuilderInterface    = graphBuilder;
            _instanceCounter++;
            _isVmr9Initialized = true;
            if (!_useEvr)
            {
                SetDeinterlacePrefs();

                IVMRMixerControl9 mixer = _vmr9Filter as IVMRMixerControl9;
                if (mixer != null)
                {
                    VMR9MixerPrefs dwPrefs;
                    mixer.GetMixingPrefs(out dwPrefs);
                    dwPrefs &= ~VMR9MixerPrefs.RenderTargetMask;

                    dwPrefs |= VMR9MixerPrefs.RenderTargetYUV;
                    // YUV saves graphics bandwith  http://msdn2.microsoft.com/en-us/library/ms788177(VS.85).aspx
                    hr.Set(mixer.SetMixingPrefs(dwPrefs));
                    Log.Debug("VMR9: Enabled YUV mixing - " + hr.ToDXString());

                    using (Settings xmlreader = new MPSettings())
                    {
                        //Enable nonsquaremixing
                        if (xmlreader.GetValueAsBool("general", "nonsquare", true))
                        {
                            mixer.GetMixingPrefs(out dwPrefs);
                            dwPrefs |= VMR9MixerPrefs.NonSquareMixing;
                            hr.Set(mixer.SetMixingPrefs(dwPrefs));
                            Log.Debug("VRM9: Turning on nonsquare mixing - " + hr.ToDXString());
                            hr.Set(mixer.SetMixingPrefs(dwPrefs));
                        }

                        // Enable DecimateMask - this will effectively use only half of the input width & length
                        if (xmlreader.GetValueAsBool("general", "dx9decimatemask", false))
                        {
                            mixer.GetMixingPrefs(out dwPrefs);
                            dwPrefs &= ~VMR9MixerPrefs.DecimateMask;
                            dwPrefs |= VMR9MixerPrefs.DecimateOutput;
                            hr.Set(mixer.SetMixingPrefs(dwPrefs));
                            Log.Debug("VRM9: Enable decimatemask - " + hr.ToDXString());
                            hr.Set(mixer.SetMixingPrefs(dwPrefs));
                        }

                        // see  D3DTEXTUREFILTERTYPE Enumerated Type documents for further information
                        // MixerPref9_PointFiltering
                        // MixerPref9_BiLinearFiltering
                        // MixerPref9_AnisotropicFiltering
                        // MixerPref9_PyramidalQuadFiltering
                        // MixerPref9_GaussianQuadFiltering

                        mixer.SetMixingPrefs(dwPrefs);
                        mixer.GetMixingPrefs(out dwPrefs);
                        dwPrefs &= ~VMR9MixerPrefs.FilteringMask;
                        string filtermode9 = xmlreader.GetValueAsString("general", "dx9filteringmode", "Gaussian Quad Filtering");
                        if (filtermode9 == "Point Filtering")
                        {
                            dwPrefs |= VMR9MixerPrefs.PointFiltering;
                        }
                        else if (filtermode9 == "Bilinear Filtering")
                        {
                            dwPrefs |= VMR9MixerPrefs.BiLinearFiltering;
                        }
                        else if (filtermode9 == "Anisotropic Filtering")
                        {
                            dwPrefs |= VMR9MixerPrefs.AnisotropicFiltering;
                        }
                        else if (filtermode9 == "Pyrimidal Quad Filtering")
                        {
                            dwPrefs |= VMR9MixerPrefs.PyramidalQuadFiltering;
                        }
                        else
                        {
                            dwPrefs |= VMR9MixerPrefs.GaussianQuadFiltering;
                        }

                        hr.Set(mixer.SetMixingPrefs(dwPrefs));
                        Log.Debug("VRM9: Set filter mode - " + filtermode9 + " " + hr.ToDXString());
                    }
                }
            }
            _threadId = Thread.CurrentThread.ManagedThreadId;
            GUIGraphicsContext.Vmr9Active = true;
            g_vmr9 = this;
            Log.Debug("VMR9: Renderer successfully added");
            return(true);
        }
Exemple #5
0
    /// <summary>
    /// Add VMR9 filter to graph and configure it
    /// </summary>
    /// <param name="graphBuilder"></param>
    public bool AddVMR9(IGraphBuilder graphBuilder)
    {
      try
      {
        // Read settings
        using (Settings xmlreader = new MPSettings())
        {
          UseMadVideoRenderer = xmlreader.GetValueAsBool("general", "useMadVideoRenderer", false);
          UseEVRMadVRForTV = xmlreader.GetValueAsBool("general", "useEVRMadVRForTV", false);
          UseMadVideoRenderer3D = xmlreader.GetValueAsBool("general", "useMadVideoRenderer3D", false);
        }
        Log.Debug("VMR9: addvmr9 - thread : {0}", Thread.CurrentThread.Name);
        if (!_useVmr9)
        {
          Log.Debug("VMR9: addvmr9 - vmr9 is deactivated");
          return false;
        }
        if (_isVmr9Initialized)
        {
          Log.Debug("VMR9: addvmr9: vmr9 has already been initialized");
          return false;
        }

        if (_instanceCounter != 0)
        {
          Log.Error("VMR9: Multiple instances of VMR9 running!!!");
          throw new Exception("VMR9Helper: Multiple instances of VMR9 running!!!");
        }

        HResult hr;
        IntPtr hMonitor = Manager.GetAdapterMonitor(GUIGraphicsContext.DX9Device.DeviceCaps.AdapterOrdinal);
        IntPtr upDevice = DirectShowUtil.GetUnmanagedDevice(GUIGraphicsContext.DX9Device);

        _scene = new PlaneScene(this);

        // Check if need to set EVR for LiveTV when using madVR
        if (UseMadVideoRenderer)
        {
          if (UseEVRMadVRForTV && g_Player.IsTimeShifting)
          {
            GUIGraphicsContext.VideoRenderer = GUIGraphicsContext.VideoRendererType.EVR;
          }
          else
          {
            GUIGraphicsContext.VideoRenderer = GUIGraphicsContext.VideoRendererType.madVR;
          }
        }

        if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.madVR)
        {
          // Process frames to clear D3D dialog window
          GUIWindowManager.MadVrProcess();
          //_scene.MadVrRenderTarget = GUIGraphicsContext.DX9Device.GetRenderTarget(0);
          //MadVrRenderTargetVMR9 = GUIGraphicsContext.DX9Device.GetRenderTarget(0);
        }
        _scene.Init();

        if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.EVR)
        {
          // Fix RDP Screen out of bound (force to use AdapterOrdinal to 0 if adapter number are out of bounds)
          int AdapterOrdinal = GUIGraphicsContext.DX9Device.DeviceCaps.AdapterOrdinal;
          if (AdapterOrdinal >= Screen.AllScreens.Length)
          {
            AdapterOrdinal = Screen.AllScreens.Length - 1;
            Log.Info("VMR9: adapter number out of bounds");
          }
          if (GUIGraphicsContext.currentMonitorIdx != -1)
          {
            if ((OSInfo.OSInfo.Win7OrLater() &&
                 Screen.AllScreens[AdapterOrdinal].Primary) || OSInfo.OSInfo.Win8OrLater())
            {
              EvrInit(_scene, (uint) upDevice.ToInt32(), ref _vmr9Filter, (uint) hMonitor.ToInt32(),
                GUIGraphicsContext.currentMonitorIdx, false, false);
            }
            else
            {
              EvrInit(_scene, (uint) upDevice.ToInt32(), ref _vmr9Filter, (uint) hMonitor.ToInt32(),
                GUIGraphicsContext.currentMonitorIdx, true, true);
              Log.Debug("VMR9: force disable vsync and bias correction for Win7 or lower - current primary is : {0}",
                Screen.AllScreens[AdapterOrdinal].Primary);
            }
          }
          else
          {
            if ((OSInfo.OSInfo.Win7OrLater() &&
                 Screen.AllScreens[AdapterOrdinal].Primary) || OSInfo.OSInfo.Win8OrLater())
            {
              EvrInit(_scene, (uint) upDevice.ToInt32(), ref _vmr9Filter, (uint) hMonitor.ToInt32(),
                AdapterOrdinal, false, false);
            }
            else
            {
              EvrInit(_scene, (uint) upDevice.ToInt32(), ref _vmr9Filter, (uint) hMonitor.ToInt32(),
                AdapterOrdinal, true, true);
              Log.Debug("VMR9: force disable vsync and bias correction for Win7 or lower - current primary is : {0}",
                Screen.AllScreens[AdapterOrdinal].Primary);
            }
          }
          hr = new HResult(graphBuilder.AddFilter(_vmr9Filter, "Enhanced Video Renderer"));

          // Adding put_Owner here.
          IVideoWindow videoWin = (IVideoWindow)graphBuilder;
          videoWin.put_Owner(GUIGraphicsContext.ActiveForm);

          Log.Info("VMR9: added EVR Renderer to graph");
        }
        else if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.madVR)
        {
          GUIGraphicsContext.MadVrOsd = false;
          GUIGraphicsContext.MadVrStop = false;
          IMediaControl mPMediaControl = (IMediaControl) graphBuilder;
          var backbuffer = GUIGraphicsContext.DX9Device.PresentationParameters;
          MadInit(_scene, backbuffer.BackBufferWidth, backbuffer.BackBufferHeight, (uint) upDevice.ToInt32(),
            (uint) GUIGraphicsContext.ActiveForm.ToInt32(), ref _vmr9Filter, mPMediaControl);
          hr = new HResult(graphBuilder.AddFilter(_vmr9Filter, "madVR"));
          Log.Info("VMR9: added madVR Renderer to graph");
          backbuffer.SafeDispose();
          //IVideoWindow videoWin = (IVideoWindow)graphBuilder;
          //videoWin.put_Owner(GUIGraphicsContext.ActiveForm);
          //videoWin.put_WindowStyle((WindowStyle)((int)WindowStyle.Child + (int)WindowStyle.ClipChildren + (int)WindowStyle.ClipSiblings));
          //videoWin.put_MessageDrain(GUIGraphicsContext.ActiveForm);
        }
        else
        {
          _vmr9Filter = (IBaseFilter) new VideoMixingRenderer9();
          Log.Info("VMR9: added Video Mixing Renderer 9 to graph");

          Vmr9Init(_scene, (uint) upDevice.ToInt32(), _vmr9Filter, (uint) hMonitor.ToInt32());
          hr = new HResult(graphBuilder.AddFilter(_vmr9Filter, "Video Mixing Renderer 9"));
        }

        if (_vmr9Filter == null)
        {
          Error.SetError("Unable to play movie", "Renderer could not be added");
          Log.Error("VMR9: Renderer not installed / cannot be used!");
          _scene.Stop();
          _scene.Deinit();
          _scene = null;
          return false;
        }

        if (hr != 0)
        {
          if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.EVR)
          {
            EvrDeinit();
          }
          else if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.madVR)
          {
            Log.Error("VMR9: MadDeinit - thread : {0}", Thread.CurrentThread.Name);
            GC.Collect();
            MadDeinit();
            GC.Collect();
            DirectShowUtil.FinalReleaseComObject(_vmr9Filter);
            Thread.Sleep(200);
            RestoreGuiForMadVr();
          }
          else
          {
            Vmr9Deinit();
          }

          _scene.Stop();
          _scene.Deinit();
          _scene = null;

          DirectShowUtil.FinalReleaseComObject(_vmr9Filter);
          _vmr9Filter = null;
          Error.SetError("Unable to play movie", "Unable to initialize Renderer");
          Log.Error("VMR9: Failed to add Renderer to filter graph");
          return false;
        }

        _graphBuilder = graphBuilder;
        _instanceCounter++;
        _isVmr9Initialized = true;
        if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.VMR9)
        {
          _qualityInterface = _vmr9Filter as IQualProp;
          _vmr9MixerBitmapInterface = _vmr9Filter as IVMRMixerBitmap9;

          Log.Debug("VMR9: SetDeinterlacePrefs() for VMR9 mode");
          SetDeinterlacePrefs();

          IVMRMixerControl9 mixer = _vmr9Filter as IVMRMixerControl9;
          if (mixer != null)
          {
            VMR9MixerPrefs dwPrefs;
            mixer.GetMixingPrefs(out dwPrefs);
            dwPrefs &= ~VMR9MixerPrefs.RenderTargetMask;

            dwPrefs |= VMR9MixerPrefs.RenderTargetYUV;
            // YUV saves graphics bandwith  http://msdn2.microsoft.com/en-us/library/ms788177(VS.85).aspx
            hr.Set(mixer.SetMixingPrefs(dwPrefs));
            Log.Debug("VMR9: Enabled YUV mixing - " + hr.ToDXString());

            using (Settings xmlreader = new MPSettings())
            {
              //Enable nonsquaremixing
              if (xmlreader.GetValueAsBool("general", "nonsquare", true))
              {
                mixer.GetMixingPrefs(out dwPrefs);
                dwPrefs |= VMR9MixerPrefs.NonSquareMixing;
                hr.Set(mixer.SetMixingPrefs(dwPrefs));
                Log.Debug("VRM9: Turning on nonsquare mixing - " + hr.ToDXString());
                hr.Set(mixer.SetMixingPrefs(dwPrefs));
              }

              // Enable DecimateMask - this will effectively use only half of the input width & length
              if (xmlreader.GetValueAsBool("general", "dx9decimatemask", false))
              {
                mixer.GetMixingPrefs(out dwPrefs);
                dwPrefs &= ~VMR9MixerPrefs.DecimateMask;
                dwPrefs |= VMR9MixerPrefs.DecimateOutput;
                hr.Set(mixer.SetMixingPrefs(dwPrefs));
                Log.Debug("VRM9: Enable decimatemask - " + hr.ToDXString());
                hr.Set(mixer.SetMixingPrefs(dwPrefs));
              }

              // see  D3DTEXTUREFILTERTYPE Enumerated Type documents for further information
              // MixerPref9_PointFiltering
              // MixerPref9_BiLinearFiltering
              // MixerPref9_AnisotropicFiltering
              // MixerPref9_PyramidalQuadFiltering
              // MixerPref9_GaussianQuadFiltering

              mixer.SetMixingPrefs(dwPrefs);
              mixer.GetMixingPrefs(out dwPrefs);
              dwPrefs &= ~VMR9MixerPrefs.FilteringMask;
              string filtermode9 = xmlreader.GetValueAsString("general", "dx9filteringmode", "Gaussian Quad Filtering");
              if (filtermode9 == "Point Filtering")
              {
                dwPrefs |= VMR9MixerPrefs.PointFiltering;
              }
              else if (filtermode9 == "Bilinear Filtering")
              {
                dwPrefs |= VMR9MixerPrefs.BiLinearFiltering;
              }
              else if (filtermode9 == "Anisotropic Filtering")
              {
                dwPrefs |= VMR9MixerPrefs.AnisotropicFiltering;
              }
              else if (filtermode9 == "Pyrimidal Quad Filtering")
              {
                dwPrefs |= VMR9MixerPrefs.PyramidalQuadFiltering;
              }
              else
              {
                dwPrefs |= VMR9MixerPrefs.GaussianQuadFiltering;
              }

              hr.Set(mixer.SetMixingPrefs(dwPrefs));
              Log.Debug("VRM9: Set filter mode - " + filtermode9 + " " + hr.ToDXString());
            }
          }
        }
        _threadId = Thread.CurrentThread.ManagedThreadId;
        GUIGraphicsContext.Vmr9Active = true;
        g_vmr9 = this;
        Log.Debug("VMR9: Renderer successfully added");
      }
      catch (Exception)
      {
        _scene.Stop();
        _scene.Deinit();
        _scene = null;
        return false;
      }
      return true;
    }
Exemple #6
0
    /// <summary>
    /// removes the vmr9 filter from the graph and free up all unmanaged resources
    /// </summary>
    public void Dispose()
    {
      try
      {
        Log.Debug("VMR9: Dispose");
        if (false == _isVmr9Initialized)
        {
          Log.Debug("VMR9: Dispose 0");
          return;
        }
        if (_threadId != Thread.CurrentThread.ManagedThreadId)
        {
          Log.Error("VMR9: Dispose() from wrong thread");
          //return;
        }
        if (_vmr9Filter == null)
        {
          Log.Error("VMR9: Dispose() no filter");
          return;
        }

        if (_scene != null)
        {
          _scene.Stop();
          _instanceCounter--;
          _scene.Deinit();
          GUIGraphicsContext.Vmr9Active = false;
          GUIGraphicsContext.Vmr9FPS = 0f;
          GUIGraphicsContext.InVmr9Render = false;
          currentVmr9State = Vmr9PlayState.Playing;
          Log.Debug("VMR9: Dispose 1");
        }

        _vmr9MixerBitmapInterface = null;

        _qualityInterface = null;

        if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.EVR)
        {
          EvrDeinit();
        }
        else if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.madVR)
        {
          Log.Debug("VMR9: Dispose MadDeinit - thread : {0}", Thread.CurrentThread.Name);
          GC.Collect();
          MadDeinit();
          GC.Collect();
          MadvrInterface.restoreDisplayModeNow(_vmr9Filter);
          DirectShowUtil.FinalReleaseComObject(_vmr9Filter);
          Log.Debug("VMR9: Dispose 2");
        }
        else
        {
          Vmr9Deinit();
        }

        if (_vmr9Filter != null)
        {
          DirectShowUtil.RemoveFilter(_graphBuilder, _vmr9Filter);
          DirectShowUtil.ReleaseComObject(_vmr9Filter);
          Log.Debug("VMR9: Dispose 3");
        }
        g_vmr9.Enable(false);
        _scene = null;
        g_vmr9 = null;
        _isVmr9Initialized = false;
        GUIGraphicsContext.DX9DeviceMadVr = null;
        Log.Debug("VMR9: Dispose 4");
      }
      catch (Exception)
      {
        _vmr9Filter = null;
        _scene = null;
        g_vmr9 = null;
        _isVmr9Initialized = false;
        GUIGraphicsContext.DX9DeviceMadVr = null;
      }
      finally
      {
        RestoreGuiForMadVr();
        DirectShowUtil.TryRelease(ref _vmr9Filter);
        GUIWindowManager.MadVrProcess();
        _vmr9Filter = null;
        Log.Debug("VMR9: Dispose done");
      }
    }