Exemplo n.º 1
0
        public void DoTests()
        {
            IDvdGraphBuilder idgb = GetDvdGraph();

            try
            {
                PopulateMembers(idgb);
                StartGraph();

                TestState();
            }
            finally
            {
                if (m_ROT != null)
                {
                    m_ROT.Dispose();
                }
                if (idgb != null)
                {
                    Marshal.ReleaseComObject(idgb);
                    idgb = null;
                }
                if (m_idi2 != null)
                {
                    Marshal.ReleaseComObject(m_idi2);
                    m_idi2 = null;
                }
                if (m_idc2 != null)
                {
                    Marshal.ReleaseComObject(m_idc2);
                    m_idc2 = null;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds the DVDNavigator filter to the graph and sets the input path.
        /// </summary>
        protected override void AddSourceFilter()
        {
            ServiceRegistration.Get <ILogger>().Debug("DvdPlayer.AddSourceFilter");
            _pendingCmd = true;

            _dvdbasefilter = (IBaseFilter) new DVDNavigator();

            if (_dvdbasefilter == null)
            {
                throw new Exception("Failed to add DVD Navigator!");
            }

            _graphBuilder.AddFilter(_dvdbasefilter, DVD_NAVIGATOR);

            _dvdInfo = _dvdbasefilter as IDvdInfo2;
            if (_dvdInfo == null)
            {
                throw new Exception("Failed to get IDvdInfo2 from DVDNavigator!");
            }

            _dvdCtrl = _dvdbasefilter as IDvdControl2;

            if (_dvdCtrl == null)
            {
                throw new Exception("Failed to get IDvdControl2 from DVDNavigator!");
            }

            if (!IsLocalFilesystemResource)
            {
                throw new IllegalCallException("The DVDPlayer can only play local file system resources");
            }
            using (((ILocalFsResourceAccessor)_resourceAccessor).EnsureLocalFileSystemAccess())
            {
                string path = ((ILocalFsResourceAccessor)_resourceAccessor).LocalFileSystemPath;

                // check if path is a drive root (like D:), otherwise append VIDEO_TS
                // MediaItem always contains the parent folder. Add the required VIDEO_TS subfolder.
                if (!String.IsNullOrEmpty(path) && !path.EndsWith(Path.VolumeSeparatorChar.ToString()))
                {
                    path = Path.Combine(path, "VIDEO_TS");
                }

                int hr = _dvdCtrl.SetDVDDirectory(path);
                if (hr != 0)
                {
                    throw new Exception("Failed to set DVD directory!");
                }
            }
            _dvdCtrl.SetOption(DvdOptionFlag.HMSFTimeCodeEvents, true); // use new HMSF timecode format
            _dvdCtrl.SetOption(DvdOptionFlag.ResetOnStop, false);

            _mediaEvt = _graphBuilder as IMediaEventEx;
            if (_mediaEvt != null)
            {
                IScreenControl screenControl = ServiceRegistration.Get <IScreenControl>();
                _mediaEvt.SetNotifyWindow(screenControl.MainWindowHandle, WM_DVD_EVENT, _instancePtr);
            }

            SetDefaultLanguages();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Associate an IDvdControl2 with it's attached Video Windows
        /// </summary>
        private void RouteDVDControl()
        {
            // reset the IDvdControl2 of VideoInternalWindows
            foreach (DaggerNode node in Graph.BottomLevelNodes)
            {
                if ((node.UINode as DSFilterNodeUI)._videoWindow != null)
                {
                    (node.UINode as DSFilterNodeUI)._videoWindow.DVDControl = null;
                }
            }

            // pass IDvdControl2 to attached VideoInternalWindows
            foreach (DaggerNode node in Graph.TopLevelNodes)
            {
                IDvdControl2 dvd = (node as DSFilterNode)._filter as IDvdControl2;
                if (dvd != null)
                {
                    foreach (DaggerNode decnode in node._descendents)
                    {
                        if ((decnode.UINode as DSFilterNodeUI)._videoWindow != null)
                        {
                            (decnode.UINode as DSFilterNodeUI)._videoWindow.DVDControl = dvd;
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void DoTests()
        {
            IDvdGraphBuilder idgb = GetDvdGraph();

            try
            {
                PopulateMembers(idgb);
                StartGraph();

                // These routines can be tested with testme.iso.  If you've got
                // nero, you can use NeroDrive to mount the iso file as a dvd drive.  Otherwise
                // burn the file to a dvd for testing.
                TestGetCurrentDomain();
                TestGetTotalTitleTime();
                TestGetCurrent();
                TestDiskInfo();
                TestTitle();
                TestButton();
                TestMisc();

                /// These routines need a fancier dvd than I can make with my dvd software.  I've tested
                /// using "The Thomas Crown Affair".  Note that TestDirectory changes the drive from MyDisk
                /// to OtherDisk.

                // Map to a different drive.  One that has multiple streams, angles, etc
                int hr;
                hr = m_imc.Stop();
                DsError.ThrowExceptionForHR(hr);
                hr = m_idc2.SetDVDDirectory(OtherDisk);
                DsError.ThrowExceptionForHR(hr);
                StartGraph();

                TestStrings();
                TestMenuLang();
                TestAudio();
                TestSubPic();
            }
            finally
            {
                if (m_ROT != null)
                {
                    m_ROT.Dispose();
                }
                if (idgb != null)
                {
                    Marshal.ReleaseComObject(idgb);
                    idgb = null;
                }
                if (m_idi2 != null)
                {
                    Marshal.ReleaseComObject(m_idi2);
                    m_idi2 = null;
                }
                if (m_idc2 != null)
                {
                    Marshal.ReleaseComObject(m_idc2);
                    m_idc2 = null;
                }
            }
        }
Exemplo n.º 5
0
        void PreviewInit()
        {
            m_dvdNav  = (IBaseFilter) new DVDNavigator();
            m_dvdCtrl = m_dvdNav as IDvdControl2;
            int hr = m_dvdCtrl.SetDVDDirectory(Disk.VIDEO_TS);

            DsError.ThrowExceptionForHR(hr);

            m_dvdInfo = m_dvdCtrl as IDvdInfo2;

            m_filterGraph = (IGraphBuilder) new FilterGraph();
            hr            = m_filterGraph.AddFilter(m_dvdNav, "DVD Navigator");
            DsError.ThrowExceptionForHR(hr);

            m_renderer = (IBaseFilter) new VideoMixingRenderer9();
            IVMRFilterConfig9 filterConfig = (IVMRFilterConfig9)m_renderer;

            hr = filterConfig.SetRenderingMode(VMR9Mode.Renderless);
            DsError.ThrowExceptionForHR(hr);

            hr = filterConfig.SetNumberOfStreams(1);
            DsError.ThrowExceptionForHR(hr);

            hr = m_filterGraph.AddFilter(m_renderer, "Video Mix 9");
            DsError.ThrowExceptionForHR(hr);

            IPin videoPin;

            hr = m_dvdNav.FindPin("Video", out videoPin);
            DsError.ThrowExceptionForHR(hr);

            IPin audioPin;

            hr = m_dvdNav.FindPin("AC3", out audioPin);
            DsError.ThrowExceptionForHR(hr);

            //hr = m_filterGraph.Render(videoPin);
            //DsError.ThrowExceptionForHR(hr);
            //hr = m_filterGraph.Render(audioPin);
            //DsError.ThrowExceptionForHR(hr);

            //IMediaControl mediaCtrl = (IMediaControl)m_filterGraph;

            //hr = mediaCtrl.Run();
            //DsError.ThrowExceptionForHR(hr);

            //hr = m_dvdCtrl.SetOption(DvdOptionFlag.EnableNonblockingAPIs, true);
            //DsError.ThrowExceptionForHR(hr);
            //m_dvdCtrl.SetOption(DvdOptionFlag.ResetOnStop, true);
        }
Exemplo n.º 6
0
        private void InitializeDvd(string path)
        {
            /* The DVDControl2 interface lets us control DVD features */
            _mDvdControl = _dvdNav as IDvdControl2;

            if (_mDvdControl == null)
            {
                throw new Exception("Could not QueryInterface the IDvdControl2 interface");
            }

            /* QueryInterface the DVDInfo2 */
            _mDvdInfo = _dvdNav as IDvdInfo2;

            var videoTsPath = Path.Combine(path, "video_ts");

            if (Directory.Exists(videoTsPath))
            {
                path = videoTsPath;
            }

            /* If a Dvd directory has been set then use it, if not, let DShow find the Dvd */
            var hr = _mDvdControl.SetDVDDirectory(path);

            DsError.ThrowExceptionForHR(hr);

            /* This gives us the DVD time in Hours-Minutes-Seconds-Frame time format, and other options */
            hr = _mDvdControl.SetOption(DvdOptionFlag.HMSFTimeCodeEvents, true);
            DsError.ThrowExceptionForHR(hr);

            /* If the graph stops, resume at the same point */
            _mDvdControl.SetOption(DvdOptionFlag.ResetOnStop, false);

            hr = m_graph.AddFilter(_dvdNav, "DVD Navigator");
            DsError.ThrowExceptionForHR(hr);

            //int uTitle = 1;
            //dma = new DvdMenuAttributes();
            //dta = new DvdTitleAttributes();
            //m_dvdInfo.GetTitleAttributes(uTitle, out dma, dta);

            //int iX = dta.VideoAttributes.aspectX;
            //int iY = dta.VideoAttributes.aspectY;
            //DvdIsLetterBoxed = dta.VideoAttributes.isSourceLetterboxed;
            //int sX = dta.VideoAttributes.sourceResolutionX;
            //int sY = dta.VideoAttributes.sourceResolutionY;
        }
Exemplo n.º 7
0
        // Grab off a couple of interface pointers
        void PopulateMembers(IDvdGraphBuilder idgb)
        {
            int    hr;
            object obj;

            hr = idgb.GetDvdInterface(typeof(IDvdInfo2).GUID, out obj);
            DsError.ThrowExceptionForHR(hr);

            // Get the IDvdGraphBuilder interface
            m_idi2 = obj as IDvdInfo2;

            hr = idgb.GetDvdInterface(typeof(IDvdControl2).GUID, out obj);
            DsError.ThrowExceptionForHR(hr);

            // Get the IDvdGraphBuilder interface
            m_idc2 = obj as IDvdControl2;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Frees any allocated or unmanaged resources
        /// </summary>
        protected override void FreeResources()
        {
            base.FreeResources();
#if DEBUG
            if (m_rot != null)
            {
                m_rot.Dispose();
            }
#endif
            if (m_dummyRendererPin != null)
            {
                Marshal.ReleaseComObject(m_dummyRendererPin);
                m_dummyRendererPin = null;
            }
            if (m_dummyRenderWindow != null)
            {
                Marshal.ReleaseComObject(m_dummyRenderWindow);
                m_dummyRenderWindow = null;
            }
            if (m_renderer != null)
            {
                Marshal.ReleaseComObject(m_renderer);
                m_renderer = null;
            }
            if (m_dvdInfo != null)
            {
                Marshal.ReleaseComObject(m_dvdInfo);
                m_dvdInfo = null;
            }
            if (m_dvdControl != null)
            {
                Marshal.ReleaseComObject(m_dvdControl);
                m_dvdControl = null;
            }
            if (m_graph != null)
            {
                Marshal.ReleaseComObject(m_graph);
                m_graph = null;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Test all IDvdControl2Test methods
        /// </summary>
        public void DoTests()
        {
            IDvdGraphBuilder idgb = GetDvdGraph();

            try
            {
                PopulateMembers(idgb);
                StartGraph();
                AllowPlay();

                TestGetClassID();
                TestIsDirty();
                TestGetSizeMax();
                TestSaveLoad();
            }
            finally
            {
                if (m_ROT != null)
                {
                    m_ROT.Dispose();
                }
                if (idgb != null)
                {
                    Marshal.ReleaseComObject(idgb);
                    idgb = null;
                }
                if (m_idi2 != null)
                {
                    Marshal.ReleaseComObject(m_idi2);
                    m_idi2 = null;
                }
                if (m_idc2 != null)
                {
                    Marshal.ReleaseComObject(m_idc2);
                    m_idc2 = null;
                }
            }
        }
Exemplo n.º 10
0
        public void DoTests()
        {
            IDvdGraphBuilder idgb = GetDvdGraph();

            try
            {
                PopulateMembers(idgb);
                StartGraph();

                // These routines can be tested with testme.iso.  If you've got
                // nero, you can use NeroDrive to mount the iso file as a dvd drive.  Otherwise
                // burn the file to a dvd for testing.
                TestWaitForStart();
                TestWaitForEnd();
            }
            finally
            {
                if (m_ROT != null)
                {
                    m_ROT.Dispose();
                }
                if (idgb != null)
                {
                    Marshal.ReleaseComObject(idgb);
                    idgb = null;
                }
                if (m_idi2 != null)
                {
                    Marshal.ReleaseComObject(m_idi2);
                    m_idi2 = null;
                }
                if (m_idc2 != null)
                {
                    Marshal.ReleaseComObject(m_idc2);
                    m_idc2 = null;
                }
            }
        }
Exemplo n.º 11
0
    /// <summary> create the used COM components and get the interfaces. </summary>
    protected virtual bool GetInterfaces(string path)
    {
      int hr;
      //Type	            comtype = null;
      object comobj = null;
      _freeNavigator = true;
      _dvdInfo = null;
      _dvdCtrl = null;

      string dvdNavigator = "";
      string aspectRatioMode = "";
      string displayMode = "";
      bool useAC3Filter = false;
      using (Settings xmlreader = new MPSettings())
      {
        dvdNavigator = xmlreader.GetValueAsString("dvdplayer", "navigator", "DVD Navigator");
        aspectRatioMode = xmlreader.GetValueAsString("dvdplayer", "armode", "").ToLower();
        if (aspectRatioMode == "crop")
        {
          arMode = AspectRatioMode.Crop;
        }
        if (aspectRatioMode == "letterbox")
        {
          arMode = AspectRatioMode.LetterBox;
        }
        if (aspectRatioMode == "stretch")
        {
          arMode = AspectRatioMode.Stretched;
        }
        //if ( aspectRatioMode == "stretch" ) arMode = AspectRatioMode.zoom14to9;
        if (aspectRatioMode == "follow stream")
        {
          arMode = AspectRatioMode.StretchedAsPrimary;
        }
        useAC3Filter = xmlreader.GetValueAsBool("dvdplayer", "ac3", false);
        displayMode = xmlreader.GetValueAsString("dvdplayer", "displaymode", "").ToLower();
        if (displayMode == "default")
        {
          _videoPref = DvdPreferredDisplayMode.DisplayContentDefault;
        }
        if (displayMode == "16:9")
        {
          _videoPref = DvdPreferredDisplayMode.Display16x9;
        }
        if (displayMode == "4:3 pan scan")
        {
          _videoPref = DvdPreferredDisplayMode.Display4x3PanScanPreferred;
        }
        if (displayMode == "4:3 letterbox")
        {
          _videoPref = DvdPreferredDisplayMode.Display4x3LetterBoxPreferred;
        }
      }

      try
      {
        _dvdGraph = (IDvdGraphBuilder)new DvdGraphBuilder();

        hr = _dvdGraph.GetFiltergraph(out _graphBuilder);
        if (hr < 0)
        {
          Marshal.ThrowExceptionForHR(hr);
        }
        _rotEntry = new DsROTEntry((IFilterGraph)_graphBuilder);

        try
        {
          _dvdbasefilter = DirectShowUtil.AddFilterToGraph(_graphBuilder, dvdNavigator);
          if (_dvdbasefilter != null)
          {
            IDvdControl2 cntl = (IDvdControl2)_dvdbasefilter;
            if (cntl != null)
            {
              _dvdInfo = (IDvdInfo2)cntl;
              _dvdCtrl = (IDvdControl2)cntl;
              if (path != null)
              {
                if (path.Length != 0)
                {
                  cntl.SetDVDDirectory(path);
                }
              }
              _dvdCtrl.SetOption(DvdOptionFlag.HMSFTimeCodeEvents, true); // use new HMSF timecode format
              _dvdCtrl.SetOption(DvdOptionFlag.ResetOnStop, false);

              AddPreferedCodecs(_graphBuilder);
              DirectShowUtil.RenderOutputPins(_graphBuilder, _dvdbasefilter);

              _videoWin = _graphBuilder as IVideoWindow;
              _freeNavigator = false;
            }

            //DirectShowUtil.ReleaseComObject( _dvdbasefilter); _dvdbasefilter = null;              
          }
        }
        catch (Exception ex)
        {
          string strEx = ex.Message;
        }

        Guid riid;

        if (useAC3Filter)
        {
          string ac3filterMonikerString =
            @"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\{A753A1EC-973E-4718-AF8E-A3F554D45C44}";
          Log.Info("DVDPlayer:Adding AC3 filter to graph");
          IBaseFilter filter = Marshal.BindToMoniker(ac3filterMonikerString) as IBaseFilter;
          if (filter != null)
          {
            hr = _graphBuilder.AddFilter(filter, "AC3 Filter");
            if (hr < 0)
            {
              Log.Info("DVDPlayer:FAILED:could not add AC3 filter to graph");
            }
          }
          else
          {
            Log.Info("DVDPlayer:FAILED:AC3 filter not installed");
          }
        }

        if (_dvdInfo == null)
        {
          riid = typeof (IDvdInfo2).GUID;
          hr = _dvdGraph.GetDvdInterface(riid, out comobj);
          if (hr < 0)
          {
            Marshal.ThrowExceptionForHR(hr);
          }
          _dvdInfo = (IDvdInfo2)comobj;
          comobj = null;
        }

        if (_dvdCtrl == null)
        {
          riid = typeof (IDvdControl2).GUID;
          hr = _dvdGraph.GetDvdInterface(riid, out comobj);
          if (hr < 0)
          {
            Marshal.ThrowExceptionForHR(hr);
          }
          _dvdCtrl = (IDvdControl2)comobj;
          comobj = null;
        }

        _mediaCtrl = (IMediaControl)_graphBuilder;
        _mediaEvt = (IMediaEventEx)_graphBuilder;
        _basicAudio = _graphBuilder as IBasicAudio;
        _mediaPos = (IMediaPosition)_graphBuilder;
        _basicVideo = _graphBuilder as IBasicVideo2;
        _videoWin = _graphBuilder as IVideoWindow;

        // disable Closed Captions!
        IBaseFilter baseFilter;
        _graphBuilder.FindFilterByName("Line 21 Decoder", out baseFilter);
        if (baseFilter == null)
        {
          _graphBuilder.FindFilterByName("Line21 Decoder", out baseFilter);
        }
        if (baseFilter != null)
        {
          _line21Decoder = (IAMLine21Decoder)baseFilter;
          if (_line21Decoder != null)
          {
            AMLine21CCState state = AMLine21CCState.Off;
            hr = _line21Decoder.SetServiceState(state);
            if (hr == 0)
            {
              Log.Info("DVDPlayer:Closed Captions disabled");
            }
            else
            {
              Log.Info("DVDPlayer:failed 2 disable Closed Captions");
            }
          }
        }
        /*
                // get video window
                if (_videoWin==null)
                {
                  riid = typeof( IVideoWindow ).GUID;
                  hr = _dvdGraph.GetDvdInterface( ref riid, out comobj );
                  if( hr < 0 )
                    Marshal.ThrowExceptionForHR( hr );
                  _videoWin = (IVideoWindow) comobj; comobj = null;
                }
          */
        // GetFrameStepInterface();

        DirectShowUtil.SetARMode(_graphBuilder, arMode);
        DirectShowUtil.EnableDeInterlace(_graphBuilder);
        //m_ovMgr = new OVTOOLLib.OvMgrClass();
        //m_ovMgr.SetGraph(_graphBuilder);

        return true;
      }
      catch (Exception)
      {
        //MessageBox.Show( this, "Could not get interfaces\r\n" + ee.Message, "DVDPlayer.NET", MessageBoxButtons.OK, MessageBoxIcon.Stop );
        CloseInterfaces();
        return false;
      }
      finally
      {
        if (comobj != null)
        {
          DirectShowUtil.ReleaseComObject(comobj);
        }
        comobj = null;
      }
    }
Exemplo n.º 12
0
        public void DoTests()
        {
            IDvdGraphBuilder idgb = GetDvdGraph();

            try
            {
                PopulateMembers(idgb);
                StartGraph();

                // These routines can be tested with testme.iso.  If you've got
                // nero, you can use NeroDrive to mount the iso file as a dvd drive.  Otherwise
                // burn the file to a dvd for testing.
                TestPlayTitle();
                TestPlayChapterInTitle();
                TestPlayAtTimeInTitle();
                TestPlayAtTime();
                TestPlayChapter();
                TestPlayPrevChapter();
                TestPlayNextChapter();
                TestReplayChapter();
                TestPlayForwards();
                TestPlayBackwards();
                TestPlayPeriodInTitleAutoStop();
                TestPlayChaptersAutoStop();
                TestMenusAndButtons();
                TestSetGPRM();
                TestPauseResume();
                TestParentalLevel();
                TestLanguage();
                TestVideoModePref();

                /// These routines need a fancier dvd than I can make with my dvd software.  I've tested
                /// using "The Thomas Crown Affair".  Note that TestDirectory changes the drive from MyDisk
                /// to OtherDisk.
                TestDirectory();
                TestSelectAudioStream();
                TestSelectSubpictureStream();
                TestSelectAngle();
                TestDefaultSubpictureLanguage();
                TestDefaultAudioLanguage();
                TestKaraokeAudioPresentationMode();
                TestState();
            }
            finally
            {
                if (m_ROT != null)
                {
                    m_ROT.Dispose();
                }
                if (idgb != null)
                {
                    Marshal.ReleaseComObject(idgb);
                    idgb = null;
                }
                if (m_idi2 != null)
                {
                    Marshal.ReleaseComObject(m_idi2);
                    m_idi2 = null;
                }
                if (m_idc2 != null)
                {
                    Marshal.ReleaseComObject(m_idc2);
                    m_idc2 = null;
                }
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// Frees any allocated or unmanaged resources
 /// </summary>
 protected override void FreeResources()
 {
     base.FreeResources();
     #if DEBUG
     if (m_rot != null)
         m_rot.Dispose();
     #endif
     if (m_dummyRendererPin != null)
     {
         Marshal.ReleaseComObject(m_dummyRendererPin);
         m_dummyRendererPin = null;
     }
     if (m_dummyRenderWindow != null)
     {
         Marshal.ReleaseComObject(m_dummyRenderWindow);
         m_dummyRenderWindow = null;
     }
     if (m_renderer != null)
     {
         Marshal.ReleaseComObject(m_renderer);
         m_renderer = null;
     }
     if (m_dvdInfo != null)
     {
         Marshal.ReleaseComObject(m_dvdInfo);
         m_dvdInfo = null;
     }
     if (m_dvdControl != null)
     {
         Marshal.ReleaseComObject(m_dvdControl);
         m_dvdControl = null;
     }
     if (m_graph != null)
     {
         Marshal.ReleaseComObject(m_graph);
         m_graph = null;
     }
 }
Exemplo n.º 14
0
        /// <summary> create the used COM components and get the interfaces. </summary>
        bool GetInterfaces()
        {
            int		hr;
            AMDvdRenderStatus status;
            object comobj = null;

            try
            {
                dvdGraph = (IDvdGraphBuilder)new DvdGraphBuilder();

                hr = dvdGraph.RenderDvdVideoVolume( null, AMDvdGraphFlags.None, out status );
                DsError.ThrowExceptionForHR( hr );

                hr = dvdGraph.GetDvdInterface( typeof( IDvdInfo2 ).GUID, out comobj );
                DsError.ThrowExceptionForHR( hr );
                dvdInfo = (IDvdInfo2) comobj;
                comobj = null;

                hr = dvdGraph.GetDvdInterface( typeof( IDvdControl2 ).GUID, out comobj );
                DsError.ThrowExceptionForHR( hr );
                dvdCtrl = (IDvdControl2) comobj;
                comobj = null;

                hr = dvdGraph.GetFiltergraph( out graphBuilder );
                DsError.ThrowExceptionForHR( hr );

                mediaCtrl	= (IMediaControl)  graphBuilder;
                mediaEvt	= (IMediaEventEx)  graphBuilder;

                hr = dvdGraph.GetDvdInterface( typeof( IVideoWindow ).GUID, out comobj );
                DsError.ThrowExceptionForHR( hr );

                videoWin = (IVideoWindow) comobj;
                comobj = null;

                GetFrameStepInterface();
                return true;
            }
            catch( Exception ee )
            {
                MessageBox.Show( this, "Could not get interfaces\r\n" + ee.Message, "DVDPlayer.NET", MessageBoxButtons.OK, MessageBoxIcon.Stop );
                CloseInterfaces();
                return false;
            }
            finally
            {
                if( comobj != null )
                {
                    Marshal.ReleaseComObject( comobj );
                    comobj = null;
                }
            }
        }
Exemplo n.º 15
0
        private void RenderDvdStreams(bool enableMadvr, bool enableMadvrExclusiveMode)
        {
            int hr;

            AMDvdGraphFlags buildFlags = AMDvdGraphFlags.DoNotClear;

            #region Video

            //add the video renderer first so we know whether to enable DXVA2 in "Auto" mode.
            if (enableMadvr)
            {
                AddMadVr();
            }
            else // Add default video renderer
            {
                buildFlags = AMDvdGraphFlags.EvrOnly | buildFlags;
                object objEvr;
                hr = _dvdGraphBuilder.GetDvdInterface(typeof(IMFVideoRenderer).GUID, out objEvr);
                DsError.ThrowExceptionForHR(hr);
                _mPEvr = objEvr as IBaseFilter;

                //we only need 2 input pins on the EVR if LAV Video isn't used for DVDs, but it doesn't hurt to have them
                InitializeEvr(_mPEvr, _isDvd ? 2 : 1);
            }

            AddVideoDecoder();

            #endregion

            #region Audio

            AddAudioRenderer();

            AddAudioDecoder();

            #endregion

            if (string.Compare(_filePath, "video_ts", true) < 0)
                _filePath = Path.Combine(_filePath, "video_ts");

            AMDvdRenderStatus buildStatus;
            hr = _dvdGraphBuilder.RenderDvdVideoVolume(_filePath, buildFlags, out buildStatus);
            DsError.ThrowExceptionForHR(hr);

            //The DVD Graph Builder won't connect LAV to the VR
            IPin lavOut = null;
            IPin vrIn = null;
            if (_lavvideo != null)
            {
                try
                {
                    lavOut = DsFindPin.ByDirection((_lavvideo as IBaseFilter), PinDirection.Output, 0);
                    if (lavOut != null)
                    {
                        hr = lavOut.ConnectedTo(out vrIn);
                        //DsError.ThrowExceptionForHR(hr);

                        if (vrIn == null)
                        {
                            if (_madvr != null)
                                vrIn = DsFindPin.ByDirection((_madvr as IBaseFilter), PinDirection.Input, 0);
                            else
                                vrIn = DsFindPin.ByDirection(_mPEvr, PinDirection.Input, 0);
                            hr = _graph.ConnectDirect(lavOut, vrIn, null);
                            DsError.ThrowExceptionForHR(hr);
                        }
                    }
                }
                finally
                {
                    if (lavOut != null)
                        Marshal.ReleaseComObject(lavOut);
                    if (vrIn != null)
                        Marshal.ReleaseComObject(vrIn);
                }
            }

            //see if we need to remove the DS renderer
            if (AudioRenderer != null)
            {
                IBaseFilter defAR = FilterGraphTools.FindFilterByClsid(_graph, typeof(DefaultAudioRenderer).GUID);
                if (defAR != null)
                {
                    try
                    {
                        hr = _graph.RemoveFilter(defAR);
                        DsError.ThrowExceptionForHR(hr);

                        DirectShowLib.IPin decOut = null;
                        DirectShowLib.IPin rendIn = null;

                        try
                        {
                            decOut = DsFindPin.ByDirection((DirectShowLib.IBaseFilter)_lavaudio,
                                PinDirection.Output, 0);

                            rendIn = DsFindPin.ByDirection(AudioRenderer, PinDirection.Input, 0);

                            if (decOut != null && rendIn != null)
                            {
                                hr = _filterGraph.ConnectDirect(decOut, rendIn, null);
                                if (hr == -2004287474 && _wasapiAR != null) //AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED
                                {
                                    IMPAudioRendererConfig arSett = _wasapiAR as IMPAudioRendererConfig;
                                    if (arSett != null)
                                    {
                                        arSett.SetInt(MPARSetting.WASAPI_MODE, (int)AUDCLNT_SHAREMODE.SHARED);
                                        _logger.Warn("WASAPI AR failed to connected in exclusive mode, check device properties");
                                        hr = _filterGraph.ConnectDirect(decOut, rendIn, null);
                                    }
                                }
                                DsError.ThrowExceptionForHR(hr);
                            }

                        }
                        finally
                        {
                            CleanUpInterface(decOut);
                            CleanUpInterface(rendIn);
                        }
                    }
                    finally
                    {
                        CleanUpInterface(defAR);
                        defAR = null;
                    }
                }
            }

            object comobj = null;
            hr = _dvdGraphBuilder.GetDvdInterface(typeof(IDvdInfo2).GUID, out comobj);
            //DsError.ThrowExceptionForHR(hr);
            if (comobj != null)
            {
                m_DvdInfo = (IDvdInfo2)comobj;
                comobj = null;
            }

            //hr = m_dvdGraphBuilder.GetDvdInterface(typeof(IAMLine21Decoder).GUID, out comobj);
            ////DsError.ThrowExceptionForHR(hr);
            //if (comobj != null)
            //{
            //    m_DvdSubtitle = (IAMLine21Decoder)comobj;
            //    comobj = null;
            //}

            hr = _dvdGraphBuilder.GetDvdInterface(typeof(IDvdControl2).GUID, out comobj);
            //DsError.ThrowExceptionForHR(hr);
            if (comobj != null)
            {
                m_DvdControl = (IDvdControl2)comobj;
                comobj = null;
            }

            hr = m_DvdControl.SetOption(DvdOptionFlag.HMSFTimeCodeEvents, true);	// use new HMSF timecode format
            DsError.ThrowExceptionForHR(hr);

            hr = m_DvdControl.SetOption(DvdOptionFlag.ResetOnStop, false);
            DsError.ThrowExceptionForHR(hr);

            //hr = m_DvdControl.SetDVDDirectory(_filePath);
            //DsError.ThrowExceptionForHR(hr);

            if (_item.IsVideo)
            {
                SetVideoWindow(enableMadvrExclusiveMode);
                if (_mPEvr != null)
                    SetEvrVppMode(_mPEvr);
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Builds the DVD DirectShow graph
        /// </summary>
        private void BuildGraph()
        {
            try
            {
                FreeResources();

                int hr;

                /* Create our new graph */
                m_graph = (IGraphBuilder) new FilterGraphNoThread();

#if DEBUG
                m_rot = new DsROTEntry(m_graph);
#endif

                /* We are going to use the VMR9 for now.  The EVR does not
                 * seem to work with the interactive menus yet.  It should
                 * play Dvds fine otherwise */
                var rendererType = VideoRendererType.VideoMixingRenderer9;

                /* Creates and initializes a new renderer ready to render to WPF */
                m_renderer = CreateVideoRenderer(rendererType, m_graph, 2);

                /* Do some VMR9 specific stuff */
                if (rendererType == VideoRendererType.VideoMixingRenderer9)
                {
                    var mixer = m_renderer as IVMRMixerControl9;

                    if (mixer != null)
                    {
                        VMR9MixerPrefs dwPrefs;
                        mixer.GetMixingPrefs(out dwPrefs);
                        dwPrefs &= ~VMR9MixerPrefs.RenderTargetMask;
                        dwPrefs |= VMR9MixerPrefs.RenderTargetYUV;

                        /* Enable this line to prefer YUV */
                        //hr = mixer.SetMixingPrefs(dwPrefs);
                    }
                }

                /* Create a new DVD Navigator. */
                var dvdNav = (IBaseFilter) new DVDNavigator();

                /* The DVDControl2 interface lets us control DVD features */
                m_dvdControl = dvdNav as IDvdControl2;

                if (m_dvdControl == null)
                {
                    throw new Exception("Could not QueryInterface the IDvdControl2 interface");
                }

                /* QueryInterface the DVDInfo2 */
                m_dvdInfo = dvdNav as IDvdInfo2;

                /* If a Dvd directory has been set then use it, if not, let DShow find the Dvd */
                if (!string.IsNullOrEmpty(DvdDirectory))
                {
                    hr = m_dvdControl.SetDVDDirectory(DvdDirectory);
                    DsError.ThrowExceptionForHR(hr);
                }

                /* This gives us the DVD time in Hours-Minutes-Seconds-Frame time format, and other options */
                hr = m_dvdControl.SetOption(DvdOptionFlag.HMSFTimeCodeEvents, true);
                DsError.ThrowExceptionForHR(hr);

                /* If the graph stops, resume at the same point */
                m_dvdControl.SetOption(DvdOptionFlag.ResetOnStop, false);

                hr = m_graph.AddFilter(dvdNav, "DVD Navigator");
                DsError.ThrowExceptionForHR(hr);

                IPin dvdVideoPin      = null;
                IPin dvdAudioPin      = null;
                IPin dvdSubPicturePin = null;

                IPin dvdNavPin;
                int  i = 0;

                /* Loop all the output pins on the DVD Navigator, trying to find which pins are which.
                 * We could more easily find the pins by name, but this is more fun...and more flexible
                 * if we ever want to use a 3rd party DVD navigator that used different pin names */
                while ((dvdNavPin = DsFindPin.ByDirection(dvdNav, PinDirection.Output, i)) != null)
                {
                    var    mediaTypes = new AMMediaType[1];
                    IntPtr pFetched   = IntPtr.Zero;

                    IEnumMediaTypes mediaTypeEnum;
                    dvdNavPin.EnumMediaTypes(out mediaTypeEnum);

                    /* Loop over each of the mediaTypes of each pin */
                    while (mediaTypeEnum.Next(1, mediaTypes, pFetched) == 0)
                    {
                        AMMediaType mediaType = mediaTypes[0];

                        /* This will be the video stream pin */
                        if (mediaType.subType == MediaSubType.Mpeg2Video)
                        {
                            /* Keep the ref and we'll work with it later */
                            dvdVideoPin = dvdNavPin;
                            break;
                        }

                        /* This will be the audio stream pin */
                        if (mediaType.subType == MediaSubType.DolbyAC3 ||
                            mediaType.subType == MediaSubType.Mpeg2Audio)
                        {
                            /* Keep the ref and we'll work with it later */
                            dvdAudioPin = dvdNavPin;
                            break;
                        }

                        /* This is the Dvd sub picture pin.  This generally
                         * shows overlays for Dvd menus and sometimes closed captions */
                        if (mediaType.subType == DVD_SUBPICTURE_TYPE)
                        {
                            /* Keep the ref and we'll work with it later */
                            dvdSubPicturePin = dvdNavPin;
                            break;
                        }
                    }

                    mediaTypeEnum.Reset();
                    Marshal.ReleaseComObject(mediaTypeEnum);
                    i++;
                }

                /* This is the windowed renderer.  This is *NEEDED* in order
                 * for interactive menus to work with the other VMR9 in renderless mode */
                var dummyRenderer = (IBaseFilter) new VideoMixingRenderer9();

                var dummyRendererConfig = (IVMRFilterConfig9)dummyRenderer;

                /* In order for this interactive menu trick to work, the VMR9
                 * must be set to Windowed.  We will make sure the window is hidden later on */
                hr = dummyRendererConfig.SetRenderingMode(VMR9Mode.Windowed);
                DsError.ThrowExceptionForHR(hr);

                hr = dummyRendererConfig.SetNumberOfStreams(1);
                DsError.ThrowExceptionForHR(hr);

                hr = m_graph.AddFilter(dummyRenderer, "Dummy Windowed");
                DsError.ThrowExceptionForHR(hr);

                if (dvdAudioPin != null)
                {
                    /* This should render out to the default audio device. We
                     * could modify this code here to go out any audio
                     * device, such as SPDIF or another sound card */
                    hr = m_graph.Render(dvdAudioPin);
                    DsError.ThrowExceptionForHR(hr);
                }

                /* Get the first input pin on our dummy renderer */
                m_dummyRendererPin = DsFindPin.ByConnectionStatus(dummyRenderer, /* Filter to search */
                                                                  PinConnectedStatus.Unconnected,
                                                                  0);

                /* Get an available pin on our real renderer */
                IPin rendererPin = DsFindPin.ByConnectionStatus(m_renderer, /* Filter to search */
                                                                PinConnectedStatus.Unconnected,
                                                                0);         /* Pin index */

                /* Connect the pin to the renderer */
                hr = m_graph.Connect(dvdVideoPin, rendererPin);
                DsError.ThrowExceptionForHR(hr);

                /* Get the next available pin on our real renderer */
                rendererPin = DsFindPin.ByConnectionStatus(m_renderer, /* Filter to search */
                                                           PinConnectedStatus.Unconnected,
                                                           0);         /* Pin index */

                /* Render the sub picture, which will connect
                 * the DVD navigator to the codec, not the renderer */
                hr = m_graph.Render(dvdSubPicturePin);
                DsError.ThrowExceptionForHR(hr);

                /* These are the subtypes most likely to be our dvd subpicture */
                var preferedSubpictureTypes = new[] { MediaSubType.ARGB4444,
                                                      MediaSubType.AI44,
                                                      MediaSubType.AYUV,
                                                      MediaSubType.ARGB32 };
                IPin dvdSubPicturePinOut = null;

                /* Find what should be the subpicture pin out */
                foreach (var guidType in preferedSubpictureTypes)
                {
                    dvdSubPicturePinOut = FindPinInGraphByMediaType(guidType, /* GUID of the media type being searched for */
                                                                    PinDirection.Output,
                                                                    m_graph); /* Our current graph */
                    if (dvdSubPicturePinOut != null)
                    {
                        break;
                    }
                }

                if (dvdSubPicturePinOut == null)
                {
                    throw new Exception("Could not find the sub picture pin out");
                }

                /* Here we connec thte Dvd sub picture pin to the video renderer.
                 * This enables the overlays on Dvd menus and some closed
                 * captions to be rendered. */
                hr = m_graph.Connect(dvdSubPicturePinOut, rendererPin);
                DsError.ThrowExceptionForHR(hr);

                /* Search for the Line21 out in the graph */
                IPin line21Out = FindPinInGraphByMediaType(MediaType.AuxLine21Data,
                                                           PinDirection.Output,
                                                           m_graph);
                if (line21Out == null)
                {
                    throw new Exception("Could not find the Line21 pin out");
                }

                /* We connect our line21Out out in to the dummy renderer
                 * this is what ultimatly makes interactive DVDs work with
                 * VMR9 in renderless (for WPF) */
                hr = m_graph.Connect(line21Out, m_dummyRendererPin);
                DsError.ThrowExceptionForHR(hr);

                /* This is the dummy renderers Win32 window. */
                m_dummyRenderWindow = dummyRenderer as IVideoWindow;

                if (m_dummyRenderWindow == null)
                {
                    throw new Exception("Could not QueryInterface for IVideoWindow");
                }

                ConfigureDummyWindow();

                /* Setup our base classes with this filter graph */
                SetupFilterGraph(m_graph);

                /* Sets the NaturalVideoWidth/Height */
                //SetNativePixelSizes(m_renderer);
            }
            catch (Exception ex)
            {
                FreeResources();
                InvokeMediaFailed(new MediaFailedEventArgs(ex.Message, ex));
                return;
            }

            InvokeMediaOpened();
        }
Exemplo n.º 17
0
    /// <summary>
    /// Adds the DVDNavigator filter to the graph and sets the input path.
    /// </summary>
    protected override void AddSourceFilter()
    {
      ServiceRegistration.Get<ILogger>().Debug("DvdPlayer.AddSourceFilter");
      _pendingCmd = true;

      _dvdbasefilter = (IBaseFilter) new DVDNavigator();
      _graphBuilder.AddFilter(_dvdbasefilter, DVD_NAVIGATOR);

      if (_dvdbasefilter == null)
        throw new Exception("Failed to add DVD Navigator!");

      _dvdInfo = _dvdbasefilter as IDvdInfo2;
      _dvdCtrl = _dvdbasefilter as IDvdControl2;

      if (_dvdCtrl == null)
        throw new Exception("Failed to access DVD Control!");

      // get a local file system path - will mount via DOKAN when resource is not on the local system
      ILocalFsResourceAccessor lfsr;
      if (!_resourceLocator.TryCreateLocalFsAccessor(out lfsr))
        throw new IllegalCallException("The DvDPlayer can only play file system resources");
      string path = lfsr.LocalFileSystemPath;

      // check if path is a drive root (like D:), otherwise append VIDEO_TS 
      // MediaItem always contains the parent folder. Add the required VIDEO_TS subfolder.
      if (!String.IsNullOrEmpty(path) && !path.EndsWith(Path.VolumeSeparatorChar.ToString()))
        path = Path.Combine(path, "VIDEO_TS");

      int hr = _dvdCtrl.SetDVDDirectory(path);
      if (hr != 0)
        throw new Exception("Failed to set DVD directory!");

      _dvdCtrl.SetOption(DvdOptionFlag.HMSFTimeCodeEvents, true); // use new HMSF timecode format
      _dvdCtrl.SetOption(DvdOptionFlag.ResetOnStop, false);

      _mediaEvt = _graphBuilder as IMediaEventEx;
      if (_mediaEvt != null)
      {
        IScreenControl screenControl = ServiceRegistration.Get<IScreenControl>();
        _mediaEvt.SetNotifyWindow(screenControl.MainWindowHandle, WM_DVD_EVENT, _instancePtr);
      }

      SetDefaultLanguages();
    }
Exemplo n.º 18
0
        private void InitMedia()
        {
            GC.Collect();

            string volumePath = string.Empty;

            if (renderMediaName.ToUpperInvariant().EndsWith("VIDEO_TS"))
            {
                volumePath = renderMediaName;
            }
            else
            {
                volumePath = System.IO.Path.Combine(renderMediaName, "VIDEO_TS");
            }

            dvdGraphBuilder =
                Activator.CreateInstance(Type.GetTypeFromCLSID(Filters.DvdGraphBuilder, true))
                as IDvdGraphBuilder;

            AMDvdRenderStatus status;

            dvdGraphBuilder.TryRenderDVD(volumePath, out status);

            if (status.bDvdVolInvalid)
            {
                throw new COMException(VideoDvdInformation.ErrDvdVolume, -1);
            }

            Logger.LogTrace("Failed to open DVD streams: {0}", status.dwFailedStreamsFlag);

            dvdInfo = GetInterface(typeof(IDvdInfo2)) as IDvdInfo2;

            dvdControl2 = GetInterface(typeof(IDvdControl2)) as IDvdControl2;

            int hr = dvdControl2.SetOption(DvdOptionFlag.HMSFTimeCodeEvents, true);     // use new HMSF timecode format

            DsError.ThrowExceptionForHR(hr);

            hr = dvdControl2.SetOption(DvdOptionFlag.ResetOnStop, false);
            DsError.ThrowExceptionForHR(hr);

            hr = dvdControl2.SetOption(DvdOptionFlag.AudioDuringFFwdRew, false);
            DsError.ThrowExceptionForHR(hr);

            //dvdControl.SelectVideoModePreference(DvdPreferredDisplayMode.DisplayContentDefault);

            dvdGraphBuilder.GetFiltergraph(out mediaControl);

            if (mediaControl == null)
            {
                throw new RenderingException("Unable to render the file: " + renderMediaName);
            }

#if HAVE_SAMPLES
            InitAudioSampleGrabber_v2();
            CompleteAudioSampleGrabberIntialization();
#else
            rotEntry = new DsROTEntry(graphBuilder as IFilterGraph);
#endif

            mediaEvent    = mediaControl as IMediaEventEx;
            mediaPosition = mediaControl as IMediaPosition;
            videoWindow   = mediaControl as IVideoWindow;
            basicVideo    = mediaControl as IBasicVideo;
            basicAudio    = mediaControl as IBasicAudio;

            renderRegion.MouseMove -= new MouseEventHandler(renderRegion_MouseMove);
            renderRegion.MouseMove += new MouseEventHandler(renderRegion_MouseMove);
            renderRegion.MouseDown -= new MouseEventHandler(renderRegion_MouseDown);
            renderRegion.MouseDown += new MouseEventHandler(renderRegion_MouseDown);
        }
        private void CloseInterfaces()
        {
            _hiddenWindow.SizeChanged -= _hiddenWindow_SizeChanged;

            int hr;

            if (_defaultAudioRenderer != null)
            {
                m_graph.RemoveFilter(_defaultAudioRenderer as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_defaultAudioRenderer);
                _defaultAudioRenderer = null;
            }

            if (_reclockAudioRenderer != null)
            {
                m_graph.RemoveFilter(_reclockAudioRenderer as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_reclockAudioRenderer);
                _reclockAudioRenderer = null;
            }

            if (_lavaudio != null)
            {
                m_graph.RemoveFilter(_lavaudio as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_lavaudio);
                _lavaudio = null;
            }

            if (_xyVsFilter != null)
            {
                m_graph.RemoveFilter(_xyVsFilter as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_xyVsFilter);
                _xyVsFilter = null;
            }

            if (_xySubFilter != null)
            {
                m_graph.RemoveFilter(_xySubFilter as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_xySubFilter);
                _xySubFilter = null;
            }

            if (_lavvideo != null)
            {
                m_graph.RemoveFilter(_lavvideo as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_lavvideo);
                _lavvideo = null;
            }

            if (_madvr != null)
            {
                m_graph.RemoveFilter(_madvr as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_madvr);
                _madvr = null;
            }

            if (_videoWindow != null)
            {
                // Relinquish ownership (IMPORTANT!) after hiding video window
                hr = _videoWindow.put_Visible(OABool.False);

                hr = _videoWindow.put_Owner(IntPtr.Zero);
            }

            if (_mediaEventEx != null)
            {
                hr = _mediaEventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);
                Marshal.ReleaseComObject(_mediaEventEx);
                _mediaEventEx = null;
            }

            if (_dvdNav != null)
            {
                Marshal.ReleaseComObject(_dvdNav);
                _dvdNav = null;
            }

            if (_mDvdInfo != null)
            {
                Marshal.ReleaseComObject(_mDvdInfo);
                _mDvdInfo = null;
            }

            if (_mDvdControl != null)
            {
                Marshal.ReleaseComObject(_mDvdControl);
                _mDvdControl = null;
            }

            if (_mPDisplay != null)
            {
                Marshal.ReleaseComObject(_mPDisplay);
                _mPDisplay = null;
            }

            if (_filterGraph != null)
            {
                Marshal.ReleaseComObject(_filterGraph);
                _filterGraph = null;
            }

            if (_mPEvr != null)
            {
                Marshal.ReleaseComObject(_mPEvr);
                _mPEvr = null;
            }

            if (_mediaEventEx != null)
            {
                Marshal.ReleaseComObject(_mediaEventEx);
                _mediaEventEx = null;
            }

            if (_mediaSeeking != null)
            {
                Marshal.ReleaseComObject(_mediaSeeking);
                _mediaSeeking = null;
            }

            if (_mediaPosition != null)
            {
                Marshal.ReleaseComObject(_mediaPosition);
                _mediaPosition = null;
            }

            if (_mediaControl != null)
            {
                Marshal.ReleaseComObject(_mediaControl);
                _mediaControl = null;
            }

            if (_basicAudio != null)
            {
                Marshal.ReleaseComObject(_basicAudio);
                _basicAudio = null;
            }

            if (_basicVideo != null)
            {
                Marshal.ReleaseComObject(_basicVideo);
                _basicVideo = null;
            }

            if (_sourceFilter != null)
            {
                Marshal.ReleaseComObject(_sourceFilter);
                _sourceFilter = null;
            }

            if (m_graph != null)
            {
                Marshal.ReleaseComObject(m_graph);
                m_graph = null;
            }

            if (_videoWindow != null)
            {
                Marshal.ReleaseComObject(_videoWindow);
                _videoWindow = null;
            }

            _mSeekCaps = 0;

            _streams = null;

            GC.Collect();
        }
Exemplo n.º 20
0
        void PreviewInit()
        {
            m_dvdNav = (IBaseFilter)new DVDNavigator();
            m_dvdCtrl = m_dvdNav as IDvdControl2;
            int hr = m_dvdCtrl.SetDVDDirectory(Disk.VIDEO_TS);
            DsError.ThrowExceptionForHR(hr);

            m_dvdInfo = m_dvdCtrl as IDvdInfo2;

            m_filterGraph = (IGraphBuilder)new FilterGraph();
            hr = m_filterGraph.AddFilter(m_dvdNav, "DVD Navigator");
            DsError.ThrowExceptionForHR(hr);

            m_renderer = (IBaseFilter)new VideoMixingRenderer9();
            IVMRFilterConfig9 filterConfig = (IVMRFilterConfig9)m_renderer;

            hr = filterConfig.SetRenderingMode(VMR9Mode.Renderless);
            DsError.ThrowExceptionForHR(hr);

            hr = filterConfig.SetNumberOfStreams(1);
            DsError.ThrowExceptionForHR(hr);

            hr = m_filterGraph.AddFilter(m_renderer, "Video Mix 9");
            DsError.ThrowExceptionForHR(hr);

            IPin videoPin;
            hr = m_dvdNav.FindPin("Video", out videoPin);
            DsError.ThrowExceptionForHR(hr);

            IPin audioPin;
            hr = m_dvdNav.FindPin("AC3", out audioPin);
            DsError.ThrowExceptionForHR(hr);

            //hr = m_filterGraph.Render(videoPin);
            //DsError.ThrowExceptionForHR(hr);
            //hr = m_filterGraph.Render(audioPin);
            //DsError.ThrowExceptionForHR(hr);

            //IMediaControl mediaCtrl = (IMediaControl)m_filterGraph;

            //hr = mediaCtrl.Run();
            //DsError.ThrowExceptionForHR(hr);

            //hr = m_dvdCtrl.SetOption(DvdOptionFlag.EnableNonblockingAPIs, true);
            //DsError.ThrowExceptionForHR(hr);
            //m_dvdCtrl.SetOption(DvdOptionFlag.ResetOnStop, true);
        }
Exemplo n.º 21
0
        private void CloseInterfaces()
        {
            _hiddenWindow.SizeChanged -= _hiddenWindow_SizeChanged;

            int hr;

            if (_defaultAudioRenderer != null)
            {
                m_graph.RemoveFilter(_defaultAudioRenderer as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_defaultAudioRenderer);
                _defaultAudioRenderer = null;
            }

            if (_reclockAudioRenderer != null)
            {
                m_graph.RemoveFilter(_reclockAudioRenderer as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_reclockAudioRenderer);
                _reclockAudioRenderer = null;
            }

            if (_lavaudio != null)
            {
                m_graph.RemoveFilter(_lavaudio as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_lavaudio);
                _lavaudio = null;
            }

            if (_xyVsFilter != null)
            {
                m_graph.RemoveFilter(_xyVsFilter as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_xyVsFilter);
                _xyVsFilter = null;
            }

            if (_xySubFilter != null)
            {
                m_graph.RemoveFilter(_xySubFilter as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_xySubFilter);
                _xySubFilter = null;
            }

            if (_lavvideo != null)
            {
                m_graph.RemoveFilter(_lavvideo as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_lavvideo);
                _lavvideo = null;
            }

            if (_madvr != null)
            {
                m_graph.RemoveFilter(_madvr as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_madvr);
                _madvr = null;
            }

            if (_videoWindow != null)
            {
                // Relinquish ownership (IMPORTANT!) after hiding video window
                hr = _videoWindow.put_Visible(OABool.False);

                hr = _videoWindow.put_Owner(IntPtr.Zero);
            }

            if (_mediaEventEx != null)
            {
                hr = _mediaEventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);
                Marshal.ReleaseComObject(_mediaEventEx);
                _mediaEventEx = null;
            }

            if (_dvdNav != null)
            {
                Marshal.ReleaseComObject(_dvdNav);
                _dvdNav = null;
            }

            if (_mDvdInfo != null)
            {
                Marshal.ReleaseComObject(_mDvdInfo);
                _mDvdInfo = null;
            }

            if (_mDvdControl != null)
            {
                Marshal.ReleaseComObject(_mDvdControl);
                _mDvdControl = null;
            }

            if (_mPDisplay != null)
            {
                Marshal.ReleaseComObject(_mPDisplay);
                _mPDisplay = null;
            }

            if (_filterGraph != null)
            {
                Marshal.ReleaseComObject(_filterGraph);
                _filterGraph = null;
            }

            if (_mPEvr != null)
            {
                Marshal.ReleaseComObject(_mPEvr);
                _mPEvr = null;
            }

            if (_mediaEventEx != null)
            {
                Marshal.ReleaseComObject(_mediaEventEx);
                _mediaEventEx = null;
            }

            if (_mediaSeeking != null)
            {
                Marshal.ReleaseComObject(_mediaSeeking);
                _mediaSeeking = null;
            }

            if (_mediaPosition != null)
            {
                Marshal.ReleaseComObject(_mediaPosition);
                _mediaPosition = null;
            }

            if (_mediaControl != null)
            {
                Marshal.ReleaseComObject(_mediaControl);
                _mediaControl = null;
            }

            if (_basicAudio != null)
            {
                Marshal.ReleaseComObject(_basicAudio);
                _basicAudio = null;
            }

            if (_basicVideo != null)
            {
                Marshal.ReleaseComObject(_basicVideo);
                _basicVideo = null;
            }

            if (_sourceFilter != null)
            {
                Marshal.ReleaseComObject(_sourceFilter);
                _sourceFilter = null;
            }

            if (m_graph != null)
            {
                Marshal.ReleaseComObject(m_graph);
                m_graph = null;
            }

            if (_videoWindow != null)
            {
                Marshal.ReleaseComObject(_videoWindow);
                _videoWindow = null;
            }

            _mSeekCaps = 0;

            _streams = null;

            GC.Collect();
        }
Exemplo n.º 22
0
    /// <summary>
    /// Adds the file source filter to the graph.
    /// </summary>
    protected override void AddFileSource()
    {
      ServiceRegistration.Get<ILogger>().Debug("DvdPlayer.AddFileSource");
      _pendingCmd = true;

      _dvdbasefilter = (IBaseFilter) new DVDNavigator();
      _graphBuilder.AddFilter(_dvdbasefilter, DVD_NAVIGATOR);

      if (_dvdbasefilter == null)
        throw new Exception("Failed to add DVD Navigator!");

      _dvdInfo = _dvdbasefilter as IDvdInfo2;
      _dvdCtrl = _dvdbasefilter as IDvdControl2;

      if (_dvdCtrl == null)
        throw new Exception("Failed to access DVD Control!");

      string path = SourcePathOrUrl;

      // check if path is a drive root (like D:), otherwise append VIDEO_TS 
      // MediaItem always contains the parent folder. Add the required VIDEO_TS subfolder.
      if (!String.IsNullOrEmpty(path) && !path.EndsWith(Path.VolumeSeparatorChar.ToString()))
        path = Path.Combine(path, "VIDEO_TS");

      int hr = _dvdCtrl.SetDVDDirectory(path);
      if (hr != 0)
        throw new Exception("Failed to set DVD directory!");

      _dvdCtrl.SetOption(DvdOptionFlag.HMSFTimeCodeEvents, true); // use new HMSF timecode format
      _dvdCtrl.SetOption(DvdOptionFlag.ResetOnStop, false);

      _mediaEvt = _graphBuilder as IMediaEventEx;
      if (_mediaEvt != null)
      {
        IScreenControl screenControl = ServiceRegistration.Get<IScreenControl>();
        _mediaEvt.SetNotifyWindow(screenControl.MainWindowHandle, WM_DVD_EVENT, _instancePtr);
      }

      SetDefaultLanguages();
    }
Exemplo n.º 23
0
        private void InitMedia()
        {
            GC.Collect();

            string volumePath = string.Empty;
            if (renderMediaName.ToUpperInvariant().EndsWith("VIDEO_TS"))
            {
                volumePath = renderMediaName;
            }
            else
            {
                volumePath = System.IO.Path.Combine(renderMediaName, "VIDEO_TS");
            }

            dvdGraphBuilder =
                Activator.CreateInstance(Type.GetTypeFromCLSID(Filters.DvdGraphBuilder, true))
                as IDvdGraphBuilder;

            AMDvdRenderStatus status;

            dvdGraphBuilder.RenderDvdVideoVolume(volumePath, AMDvdGraphFlags.VMR9Only, out status);
            

            if (status.bDvdVolInvalid)
                throw new COMException(VideoDvdInformation.ErrDvdVolume, -1);

            dvdInfo = GetInterface(typeof(IDvdInfo2)) as IDvdInfo2;

            dvdControl2 = GetInterface(typeof(IDvdControl2)) as IDvdControl2;

            int hr = dvdControl2.SetOption(DvdOptionFlag.HMSFTimeCodeEvents, true);	// use new HMSF timecode format
            DsError.ThrowExceptionForHR(hr);
            
            hr = dvdControl2.SetOption(DvdOptionFlag.ResetOnStop, false);
            DsError.ThrowExceptionForHR(hr);

            hr = dvdControl2.SetOption(DvdOptionFlag.AudioDuringFFwdRew, false);
            DsError.ThrowExceptionForHR(hr);
            
            //dvdControl.SelectVideoModePreference(DvdPreferredDisplayMode.DisplayContentDefault);

            dvdGraphBuilder.GetFiltergraph(out mediaControl);

            if (mediaControl == null)
                throw new RenderingException("Unable to render the file: " + renderMediaName);

#if HAVE_SAMPLES
            InitAudioSampleGrabber_v2();
            CompleteAudioSampleGrabberIntialization();
#endif

            mediaEvent = mediaControl as IMediaEventEx;
            mediaPosition = mediaControl as IMediaPosition;
            videoWindow = mediaControl as IVideoWindow;
            basicVideo = mediaControl as IBasicVideo;
            basicAudio = mediaControl as IBasicAudio;

            renderRegion.MouseMove -= new MouseEventHandler(renderRegion_MouseMove);
            renderRegion.MouseMove += new MouseEventHandler(renderRegion_MouseMove);
            renderRegion.MouseDown -= new MouseEventHandler(renderRegion_MouseDown);
            renderRegion.MouseDown += new MouseEventHandler(renderRegion_MouseDown);

        }
Exemplo n.º 24
0
        /// <summary> do cleanup and release DirectShow. </summary>
        protected virtual void CloseDVDInterfaces()
        {
            if (_graphBuilder == null)
            {
                return;
            }
            int hr;
            try
            {
                logger.Info("DVDPlayer:cleanup DShow graph");

                if (_mediaCtrl != null)
                {
                    hr = _mediaCtrl.Stop();
                    _mediaCtrl = null;
                }
                _state = PlayState.Stopped;

                _mediaEvt = null;
                _visible = false;
                _videoWin = null;
                //				videoStep	= null;
                _dvdCtrl = null;
                _dvdInfo = null;
                _basicVideo = null;
                _basicAudio = null;
                _mediaPos = null;
                _mediaSeek = null;
                _mediaStep = null;

                //if (_vmr7 != null)
                //{
                //    _vmr7.RemoveVMR7();
                //}
                //_vmr7 = null;

                if (_vmr9Filter != null)
                {
                    while ((hr = DirectShowUtil.ReleaseComObject(_vmr9Filter)) > 0)
                    {
                        ;
                    }
                    _vmr9Filter = null;
                }

                if (_dvdbasefilter != null)
                {
                    while ((hr = DirectShowUtil.ReleaseComObject(_dvdbasefilter)) > 0)
                    {
                        ;
                    }
                    _dvdbasefilter = null;
                }

                if (_cmdOption != null)
                {
                    DirectShowUtil.ReleaseComObject(_cmdOption);
                }
                _cmdOption = null;
                _pendingCmd = false;
                if (_line21Decoder != null)
                {
                    while ((hr = DirectShowUtil.ReleaseComObject(_line21Decoder)) > 0)
                    {
                        ;
                    }
                    _line21Decoder = null;
                }

                if (_graphBuilder != null)
                {
                    DirectShowUtil.RemoveFilters(_graphBuilder);
                    if (_rotEntry != null)
                    {
                        _rotEntry.Dispose();
                        _rotEntry = null;
                    }
                    while ((hr = DirectShowUtil.ReleaseComObject(_graphBuilder)) > 0)
                    {
                        ;
                    }
                    _graphBuilder = null;
                }

                if (_dvdGraph != null)
                {
                    while ((hr = DirectShowUtil.ReleaseComObject(_dvdGraph)) > 0)
                    {
                        ;
                    }
                    _dvdGraph = null;
                }
                _state = PlayState.Init;

            }
            catch (Exception ex)
            {
                logger.Error("DVDPlayer:exception while cleanuping DShow graph {0} {1}", ex.Message, ex.StackTrace);
            }
        }
Exemplo n.º 25
0
        /// <summary> do cleanup and release DirectShow. </summary>
        void CloseInterfaces()
        {
            int hr;
            try
            {
                if( dvdCtrl != null )
                {
                    hr = dvdCtrl.SetOption( DvdOptionFlag.ResetOnStop, true );
                }

                if( mediaCtrl != null )
                {
                    hr = mediaCtrl.Stop();
                    mediaCtrl = null;
                }
                playState = PlayState.Stopped;

                if( mediaEvt != null )
                {
                    hr = mediaEvt.SetNotifyWindow( IntPtr.Zero, WM_DVD_EVENT, IntPtr.Zero );
                    mediaEvt = null;
                }

                if( videoWin != null )
                {
                    hr = videoWin.put_Visible( OABool.False );
                    hr = videoWin.put_MessageDrain( IntPtr.Zero );
                    hr = videoWin.put_Owner( IntPtr.Zero );
                    videoWin = null;
                }

                videoStep	= null;

                if( cmdOption != null )
                {
                    Marshal.ReleaseComObject( cmdOption );
                    cmdOption = null;
                }

                pendingCmd = false;

                if( graphBuilder != null )
                {
                    Marshal.ReleaseComObject( graphBuilder );
                    graphBuilder = null;
                }

                dvdCtrl		= null;
                if( dvdInfo != null )
                {
                    Marshal.ReleaseComObject( dvdInfo );
                    dvdInfo = null;
                }

                if( dvdGraph != null )
                {
                    Marshal.ReleaseComObject( dvdGraph );
                    dvdGraph = null;
                }

                playState = PlayState.Init;
            }
            catch( Exception )
            {}
        }
        private void CloseInterfaces()
        {
            int hr;

            if (m_adecOut != null)
            {
                CleanUpInterface(m_adecOut);
                m_adecOut = null;
            }

            if (_defaultAudioRenderer != null)
            {
                m_graph.RemoveFilter(_defaultAudioRenderer as DirectShowLib.IBaseFilter);

                CleanUpInterface(_defaultAudioRenderer);
                _defaultAudioRenderer = null;
            }

            if (_reclockAudioRenderer != null)
            {
                m_graph.RemoveFilter(_reclockAudioRenderer as DirectShowLib.IBaseFilter);

                CleanUpInterface(_reclockAudioRenderer);
                _reclockAudioRenderer = null;
            }

            if (_wasapiAR != null)
            {
                m_graph.RemoveFilter(_wasapiAR as DirectShowLib.IBaseFilter);

                CleanUpInterface(_wasapiAR);
                _wasapiAR = null;
            }

            if (_lavaudio != null)
            {
                m_graph.RemoveFilter(_lavaudio as DirectShowLib.IBaseFilter);

                CleanUpInterface(_lavaudio);
                _lavaudio = null;
            }

            if (_xyVsFilter != null)
            {
                m_graph.RemoveFilter(_xyVsFilter as DirectShowLib.IBaseFilter);

                CleanUpInterface(_xyVsFilter);
                _xyVsFilter = null;
            }

            if (_xySubFilter != null)
            {
                m_graph.RemoveFilter(_xySubFilter as DirectShowLib.IBaseFilter);

                CleanUpInterface(_xySubFilter);
                _xySubFilter = null;
            }

            if (_lavvideo != null)
            {
                m_graph.RemoveFilter(_lavvideo as DirectShowLib.IBaseFilter);

                CleanUpInterface(_lavvideo);
                _lavvideo = null;
            }

            if (_madvr != null)
            {
                m_graph.RemoveFilter(_madvr as DirectShowLib.IBaseFilter);

                CleanUpInterface(_madvr);
                _madvr = null;
            }

            if (_videoWindow != null)
            {
                // Relinquish ownership (IMPORTANT!) after hiding video window
                hr = _videoWindow.put_Visible(OABool.False);

                hr = _videoWindow.put_Owner(IntPtr.Zero);
            }

            if (_mediaEventEx != null)
            {
                hr = _mediaEventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);
                //Marshal.ReleaseComObject(_mediaEventEx);
                //_mediaEventEx = null;
            }

            //if (_dvdNav != null)
            //{
            //    Marshal.ReleaseComObject(_dvdNav);
            //    _dvdNav = null;
            //}
            /* //this will double release the source filter
            if (dvdInfo != null)
            {
                Marshal.ReleaseComObject(dvdInfo);
                dvdInfo = null;
            }

            if (_mDvdControl != null)
            {
                Marshal.ReleaseComObject(_mDvdControl);                
            }
            */
            _mDvdControl = null;

            CleanUpInterface(_mPDisplay);
            _mPDisplay = null;
            CleanUpInterface(_sourceFilter);
            _sourceFilter = null;
            CleanUpInterface(_mPEvr);
            _mPEvr = null;
            CleanUpInterface(m_filterGraph);
            m_filterGraph = null;

            m_filterGraph = null;
            _mediaEventEx = null;
            _mediaSeeking = null;
            _mediaPosition = null;
            _mediaControl = null;
            _basicAudio = null;
            _basicVideo = null;
            m_graph = null;
            _videoWindow = null;
            _filterGraph = null;

            if (m_dsRot != null)
                m_dsRot.Dispose();
            m_dsRot = null;

            _mSeekCaps = 0;

            _streams = null;

            GC.Collect();
        }
Exemplo n.º 27
0
            /// <summary>
            /// DVD Code - Play DVD
            /// </summary>
            /// <param name="db1"></param>
            public void PlayDVD(DBTrackInfo db1)
            {
                DBLocalMedia mediaToPlay = db1.LocalMedia[0];

                if (mediaToPlay.State != MediaState.Online) mediaToPlay.Mount();
                while (mediaToPlay.State != MediaState.Online) { Thread.Sleep(1000); };
                string dvdNavigator = "";
                string dslibdvdnavMonikerString = @"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\{1FFD2F97-0C57-4E21-9FC1-60DF6C6D20BF}";
                Log.Info("finding dslibdvdnav filter");
                IBaseFilter filter = Marshal.BindToMoniker(dslibdvdnavMonikerString) as IBaseFilter;
                if (filter != null)
                {
                  Log.Info("dslibdvdnav filter found!");
                  DirectShowUtil.ReleaseComObject(filter);
                  filter = null;
                  using (MediaPortal.Profile.Settings xmlreader = mvCentralCore.MediaPortalSettings)
                  {
                xmlreader.SetValue("dvdplayer", "navigator", "dslibdvdnav");
                dvdNavigator = xmlreader.GetValueAsString("dvdplayer", "navigator", "DVD Navigator");
                  }
                }
                else
                  Log.Info("dslibdvdnav filter not found using mp default one!");

                MediaPortal.Player.g_Player.Play(mediaToPlay.GetVideoPath());

                // reset setting back to original
                if (dvdNavigator == "dslibdvdnav")
                  using (MediaPortal.Profile.Settings xmlreader = mvCentralCore.MediaPortalSettings)
                  {
                xmlreader.SetValue("dvdplayer", "navigator", "DVD Navigator");
                  }

                PurgeEntries();
                l1 = ROTClass.GetFilterGraphsFromROT();
                foreach (DSGrapheditROTEntry e1 in l1)
                {
                  logger.Info(e1.ToString());
                  _graphBuilder = e1.ConnectToROTEntry() as IGraphBuilder;

                  _dvdbasefilter = DirectShowUtil.GetFilterByName(_graphBuilder, dvdNavigator);

                  _dvdCtrl = _dvdbasefilter as IDvdControl2;
                  _dvdCtrl.SetOption(DvdOptionFlag.HMSFTimeCodeEvents, true); // use new HMSF timecode format
                  _dvdCtrl.SetOption(DvdOptionFlag.ResetOnStop, false);
                  _dvdCtrl.SetDVDDirectory(mediaToPlay.GetVideoPath());
                  DirectShowUtil.RenderOutputPins(_graphBuilder, _dvdbasefilter);
                  _basicVideo = _graphBuilder as IBasicVideo2;
                  _mediaCtrl = _graphBuilder as IMediaControl;
                  //hr = _mediaCtrl.Run();
                  //hr = _mediaCtrl.Pause();
                  //_offsetseek = (ulong)seekbar.Value;
                  TimeSpan t1 = TimeSpan.FromMilliseconds(0);
                  TimeSpan t2 = TimeSpan.Parse(db1.OffsetTime);
                  t1 = t1.Add(t2);
                  //                            t1 = TimeSpan.Parse(db1.PlayTime);
                  t2 = t2.Add(TimeSpan.Parse(db1.PlayTime));
                  DvdHMSFTimeCode t3 = mvCentralUtils.ConvertToDvdHMSFTimeCode(t1);
                  DvdHMSFTimeCode t4 = mvCentralUtils.ConvertToDvdHMSFTimeCode(t2);
                  //if (state == FilterState.Stopped)
                  int hr = _mediaCtrl.Run();
                  hr = _dvdCtrl.PlayAtTimeInTitle(db1.TitleID, t3, DvdCmdFlags.Flush | DvdCmdFlags.Block, out _cmdOption);
                  //                    hr = _dvdCtrl.PlayPeriodInTitleAutoStop(6, t3, t4, DvdCmdFlags.Flush | DvdCmdFlags.Block, out _cmdOption);
                  DsError.ThrowExceptionForHR(hr);
                  //int hr = _dvdCtrl.PlayChaptersAutoStop(1, db1.ChapterID, 1, 0, out _cmdOption);
                  //DsError.ThrowExceptionForHR(hr);
                }
            }
Exemplo n.º 28
0
        private void FetchDVDInformation_DS(string volumePath)
        {
            IDvdGraphBuilder dvdGraphBuilder =
                Activator.CreateInstance(Type.GetTypeFromCLSID(Filters.DvdGraphBuilder, true))
                as IDvdGraphBuilder;

            AMDvdRenderStatus status;

            dvdGraphBuilder.TryRenderDVD(volumePath, out status);

            if (status.bDvdVolInvalid)
            {
                throw new COMException(ErrDvdVolume, -1);
            }

            object comobj = null;

            dvdGraphBuilder.GetDvdInterface(typeof(IDvdInfo2).GUID, out comobj);

            IDvdInfo2    dvdInfo    = comobj as IDvdInfo2;
            IDvdControl2 dvdControl = comobj as IDvdControl2;

            dvdControl.SetOption(DvdOptionFlag.HMSFTimeCodeEvents, true);       // use new HMSF timecode format
            dvdControl.SetOption(DvdOptionFlag.ResetOnStop, false);

            // Try getting the frame rate and the video size
            dvdInfo.GetVMGAttributes(out _dma);

            this.FrameRate = new FrameRate(_dma.VideoAttributes.frameRate);
            this.VideoSize = new VSize(_dma.VideoAttributes.sourceResolutionX, _dma.VideoAttributes.sourceResolutionY);

            // Try getting the DVD volume name.
            // Stage 1: Get the number of available languages.
            int numLangs = 0;

            dvdInfo.GetDVDTextNumberOfLanguages(out numLangs);

            if (numLangs > 0)
            {
                // Stage 2: Get string count for the first language.
                int            numStrings = 0;
                int            langId     = 0;
                DvdTextCharSet charSet    = DvdTextCharSet.CharSet_Unicode;

                dvdInfo.GetDVDTextLanguageInfo(0, out numStrings, out langId, out charSet);

                // Stage 3: Iterate through the string collection and identify the volume name
                for (int i = 0; i < numStrings; i++)
                {
                    int maxSize = 4096;

                    StringBuilder     sb      = new StringBuilder(maxSize);
                    int               txtSize = 0;
                    DvdTextStringType textType;

                    dvdInfo.GetDVDTextStringAsUnicode(0, i, sb, maxSize, out txtSize, out textType);

                    // Is this the volume name ?
                    if (textType == DvdTextStringType.DVD_General_Name)
                    {
                        // Volume name was found, so exit iteration.
                        _label = sb.ToString();
                        break;
                    }
                }
            }

            // Try getting the titles, chapters and overall duration info
            int         numVolumes = 0, volumeNumber = 0, numTitles = 0;
            DvdDiscSide sideInfo;

            dvdInfo.GetDVDVolumeInfo(out numVolumes, out volumeNumber, out sideInfo, out numTitles);

            for (int i = 1; i <= numTitles; i++)
            {
                int numChapters = 0;
                try
                {
                    DvdMenuAttributes  menuAttr;
                    DvdTitleAttributes titleAttr = new DvdTitleAttributes();

                    if (i == 1)
                    {
                        dvdInfo.GetTitleAttributes(i, out menuAttr, titleAttr);

                        for (int j = 0; j < titleAttr.ulNumberOfSubpictureStreams; j++)
                        {
                            _subtitles.Add(titleAttr.SubpictureAttributes[j]);
                        }
                    }

                    dvdInfo.GetNumberOfChapters(i, out numChapters);
                    _chaptersPerTitle.Add(numChapters);
                }
                catch { }
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Builds the DVD DirectShow graph
        /// </summary>
        private void BuildGraph()
        {
            try
            {
                FreeResources();

                int hr;

                /* Create our new graph */
                m_graph = (IGraphBuilder)new FilterGraphNoThread();

            #if DEBUG
                m_rot = new DsROTEntry(m_graph);
            #endif
                /* We are going to use the VMR9 for now.  The EVR does not
                 * seem to work with the interactive menus yet.  It should
                 * play Dvds fine otherwise */
                var rendererType = VideoRendererType.VideoMixingRenderer9;

                /* Creates and initializes a new renderer ready to render to WPF */
                m_renderer = CreateVideoRenderer(rendererType, m_graph, 2);

                /* Do some VMR9 specific stuff */
                if (rendererType == VideoRendererType.VideoMixingRenderer9)
                {
                    var mixer = m_renderer as IVMRMixerControl9;

                    if(mixer != null)
                    {
                        VMR9MixerPrefs dwPrefs;
                        mixer.GetMixingPrefs(out dwPrefs);
                        dwPrefs &= ~VMR9MixerPrefs.RenderTargetMask;
                        dwPrefs |= VMR9MixerPrefs.RenderTargetYUV;

                        /* Enable this line to prefer YUV */
                        //hr = mixer.SetMixingPrefs(dwPrefs);
                    }
                }

                /* Create a new DVD Navigator. */
                var dvdNav = (IBaseFilter)new DVDNavigator();

                /* The DVDControl2 interface lets us control DVD features */
                m_dvdControl = dvdNav as IDvdControl2;

                if (m_dvdControl == null)
                    throw new Exception("Could not QueryInterface the IDvdControl2 interface");

                /* QueryInterface the DVDInfo2 */
                m_dvdInfo = dvdNav as IDvdInfo2;

                /* If a Dvd directory has been set then use it, if not, let DShow find the Dvd */
                if (!string.IsNullOrEmpty(DvdDirectory))
                {
                    hr = m_dvdControl.SetDVDDirectory(DvdDirectory);
                    DsError.ThrowExceptionForHR(hr);
                }

                /* This gives us the DVD time in Hours-Minutes-Seconds-Frame time format, and other options */
                hr = m_dvdControl.SetOption(DvdOptionFlag.HMSFTimeCodeEvents, true);
                DsError.ThrowExceptionForHR(hr);

                /* If the graph stops, resume at the same point */
                m_dvdControl.SetOption(DvdOptionFlag.ResetOnStop, false);

                hr = m_graph.AddFilter(dvdNav, "DVD Navigator");
                DsError.ThrowExceptionForHR(hr);

                IPin dvdVideoPin = null;
                IPin dvdAudioPin = null;
                IPin dvdSubPicturePin = null;

                IPin dvdNavPin;
                int i = 0;

                /* Loop all the output pins on the DVD Navigator, trying to find which pins are which.
                 * We could more easily find the pins by name, but this is more fun...and more flexible
                 * if we ever want to use a 3rd party DVD navigator that used different pin names */
                while ((dvdNavPin = DsFindPin.ByDirection(dvdNav, PinDirection.Output, i)) != null)
                {
                    var mediaTypes = new AMMediaType[1];
                    IntPtr pFetched = IntPtr.Zero;

                    IEnumMediaTypes mediaTypeEnum;
                    dvdNavPin.EnumMediaTypes(out mediaTypeEnum);

                    /* Loop over each of the mediaTypes of each pin */
                    while (mediaTypeEnum.Next(1, mediaTypes, pFetched) == 0)
                    {
                        AMMediaType mediaType = mediaTypes[0];

                        /* This will be the video stream pin */
                        if (mediaType.subType == MediaSubType.Mpeg2Video)
                        {
                            /* Keep the ref and we'll work with it later */
                            dvdVideoPin = dvdNavPin;
                            break;
                        }

                        /* This will be the audio stream pin */
                        if (mediaType.subType == MediaSubType.DolbyAC3 ||
                           mediaType.subType == MediaSubType.Mpeg2Audio)
                        {
                            /* Keep the ref and we'll work with it later */
                            dvdAudioPin = dvdNavPin;
                            break;
                        }

                        /* This is the Dvd sub picture pin.  This generally
                         * shows overlays for Dvd menus and sometimes closed captions */
                        if (mediaType.subType == DVD_SUBPICTURE_TYPE)
                        {
                            /* Keep the ref and we'll work with it later */
                            dvdSubPicturePin = dvdNavPin;
                            break;
                        }
                    }

                    mediaTypeEnum.Reset();
                    Marshal.ReleaseComObject(mediaTypeEnum);
                    i++;
                }

                /* This is the windowed renderer.  This is *NEEDED* in order
                 * for interactive menus to work with the other VMR9 in renderless mode */
                var dummyRenderer = (IBaseFilter)new VideoMixingRenderer9();
                var dummyRendererConfig = (IVMRFilterConfig9)dummyRenderer;

                /* In order for this interactive menu trick to work, the VMR9
                 * must be set to Windowed.  We will make sure the window is hidden later on */
                hr = dummyRendererConfig.SetRenderingMode(VMR9Mode.Windowed);
                DsError.ThrowExceptionForHR(hr);

                hr = dummyRendererConfig.SetNumberOfStreams(1);
                DsError.ThrowExceptionForHR(hr);

                hr = m_graph.AddFilter(dummyRenderer, "Dummy Windowed");
                DsError.ThrowExceptionForHR(hr);

                if (dvdAudioPin != null)
                {
                    /* This should render out to the default audio device. We
                     * could modify this code here to go out any audio
                     * device, such as SPDIF or another sound card */
                    hr = m_graph.Render(dvdAudioPin);
                    DsError.ThrowExceptionForHR(hr);
                }

                /* Get the first input pin on our dummy renderer */
                m_dummyRendererPin = DsFindPin.ByConnectionStatus(dummyRenderer, /* Filter to search */
                                                                  PinConnectedStatus.Unconnected,
                                                                  0);

                /* Get an available pin on our real renderer */
                IPin rendererPin = DsFindPin.ByConnectionStatus(m_renderer, /* Filter to search */
                                                                PinConnectedStatus.Unconnected,
                                                                0); /* Pin index */

                /* Connect the pin to the renderer */
                hr = m_graph.Connect(dvdVideoPin, rendererPin);
                DsError.ThrowExceptionForHR(hr);

                /* Get the next available pin on our real renderer */
                rendererPin = DsFindPin.ByConnectionStatus(m_renderer, /* Filter to search */
                                                           PinConnectedStatus.Unconnected,
                                                           0); /* Pin index */

                /* Render the sub picture, which will connect
                 * the DVD navigator to the codec, not the renderer */
                hr = m_graph.Render(dvdSubPicturePin);
                DsError.ThrowExceptionForHR(hr);

                /* These are the subtypes most likely to be our dvd subpicture */
                var preferedSubpictureTypes = new[]{MediaSubType.ARGB4444,
                                                    MediaSubType.AI44,
                                                    MediaSubType.AYUV,
                                                    MediaSubType.ARGB32};
                IPin dvdSubPicturePinOut = null;

                /* Find what should be the subpicture pin out */
                foreach (var guidType in preferedSubpictureTypes)
                {
                    dvdSubPicturePinOut = FindPinInGraphByMediaType(guidType, /* GUID of the media type being searched for */
                                                                    PinDirection.Output,
                                                                    m_graph); /* Our current graph */
                    if (dvdSubPicturePinOut != null)
                        break;
                }

                if (dvdSubPicturePinOut == null)
                    throw new Exception("Could not find the sub picture pin out");

                /* Here we connec thte Dvd sub picture pin to the video renderer.
                 * This enables the overlays on Dvd menus and some closed
                 * captions to be rendered. */
                hr = m_graph.Connect(dvdSubPicturePinOut, rendererPin);
                DsError.ThrowExceptionForHR(hr);

                /* Search for the Line21 out in the graph */
                IPin line21Out = FindPinInGraphByMediaType(MediaType.AuxLine21Data,
                                                           PinDirection.Output,
                                                           m_graph);
                if (line21Out == null)
                    throw new Exception("Could not find the Line21 pin out");

                /* We connect our line21Out out in to the dummy renderer
                 * this is what ultimatly makes interactive DVDs work with
                 * VMR9 in renderless (for WPF) */
                hr = m_graph.Connect(line21Out, m_dummyRendererPin);
                DsError.ThrowExceptionForHR(hr);

                /* This is the dummy renderers Win32 window. */
                m_dummyRenderWindow = dummyRenderer as IVideoWindow;

                if (m_dummyRenderWindow == null)
                    throw new Exception("Could not QueryInterface for IVideoWindow");

                ConfigureDummyWindow();

                /* Setup our base classes with this filter graph */
                SetupFilterGraph(m_graph);

                /* Sets the NaturalVideoWidth/Height */
                SetNativePixelSizes(m_renderer);
            }
            catch (Exception ex)
            {
                FreeResources();
                InvokeMediaFailed(new MediaFailedEventArgs(ex.Message, ex));
                return;
            }

            InvokeMediaOpened();
        }
Exemplo n.º 30
0
    /// <summary> do cleanup and release DirectShow. </summary>
    protected virtual void CloseInterfaces()
    {
      if (_graphBuilder == null)
      {
        return;
      }
      int hr;
      try
      {
        Log.Info("DVDPlayer:cleanup DShow graph");

        if (_mediaCtrl != null)
        {
          hr = _mediaCtrl.Stop();
          _mediaCtrl = null;
        }
        _state = PlayState.Stopped;
        VMR9Util.g_vmr9.EVRSetDVDMenuState(false);

        _mediaEvt = null;
        _visible = false;
        _videoWin = null;
        //				videoStep	= null;
        _dvdCtrl = null;
        _dvdInfo = null;
        _basicVideo = null;
        _basicAudio = null;
        _mediaPos = null;

        if (_dvdbasefilter != null)
        {
          while ((hr = DirectShowUtil.ReleaseComObject(_dvdbasefilter)) > 0)
          {
            ;
          }
          _dvdbasefilter = null;
        }

        if (_cmdOption != null)
        {
          DirectShowUtil.ReleaseComObject(_cmdOption);
        }
        _cmdOption = null;
        _pendingCmd = false;
        if (_line21Decoder != null)
        {
          while ((hr = DirectShowUtil.ReleaseComObject(_line21Decoder)) > 0)
          {
            ;
          }
          _line21Decoder = null;
        }


        if (_graphBuilder != null)
        {
          DirectShowUtil.RemoveFilters(_graphBuilder);
          if (_rotEntry != null)
          {
            _rotEntry.SafeDispose();
            _rotEntry = null;
          }
          while ((hr = DirectShowUtil.ReleaseComObject(_graphBuilder)) > 0)
          {
            ;
          }
          _graphBuilder = null;
        }

        if (_dvdGraph != null)
        {
          while ((hr = DirectShowUtil.ReleaseComObject(_dvdGraph)) > 0)
          {
            ;
          }
          _dvdGraph = null;
        }
        _state = PlayState.Init;

        GUIGraphicsContext.form.Invalidate(true);
        GUIGraphicsContext.form.Activate();
      }
      catch (Exception ex)
      {
        Log.Error("DVDPlayer:exception while cleanuping DShow graph {0} {1}", ex.Message, ex.StackTrace);
      }
    }
Exemplo n.º 31
0
        /// <summary> do cleanup and release DirectShow. </summary>
        protected virtual void CloseDVDInterfaces()
        {
            if (_graphBuilder == null)
            {
                return;
            }
            int hr;

            try
            {
                logger.Info("DVDPlayer:cleanup DShow graph");

                if (_mediaCtrl != null)
                {
                    hr         = _mediaCtrl.Stop();
                    _mediaCtrl = null;
                }
                _state = PlayState.Stopped;

                _mediaEvt = null;
                _visible  = false;
                _videoWin = null;
                //				videoStep	= null;
                _dvdCtrl    = null;
                _dvdInfo    = null;
                _basicVideo = null;
                _basicAudio = null;
                _mediaPos   = null;
                _mediaSeek  = null;
                _mediaStep  = null;

                //if (_vmr7 != null)
                //{
                //    _vmr7.RemoveVMR7();
                //}
                //_vmr7 = null;



                if (_vmr9Filter != null)
                {
                    while ((hr = DirectShowUtil.ReleaseComObject(_vmr9Filter)) > 0)
                    {
                        ;
                    }
                    _vmr9Filter = null;
                }

                if (_dvdbasefilter != null)
                {
                    while ((hr = DirectShowUtil.ReleaseComObject(_dvdbasefilter)) > 0)
                    {
                        ;
                    }
                    _dvdbasefilter = null;
                }

                if (_cmdOption != null)
                {
                    DirectShowUtil.ReleaseComObject(_cmdOption);
                }
                _cmdOption  = null;
                _pendingCmd = false;
                if (_line21Decoder != null)
                {
                    while ((hr = DirectShowUtil.ReleaseComObject(_line21Decoder)) > 0)
                    {
                        ;
                    }
                    _line21Decoder = null;
                }


                if (_graphBuilder != null)
                {
                    DirectShowUtil.RemoveFilters(_graphBuilder);
                    if (_rotEntry != null)
                    {
                        _rotEntry.Dispose();
                        _rotEntry = null;
                    }
                    while ((hr = DirectShowUtil.ReleaseComObject(_graphBuilder)) > 0)
                    {
                        ;
                    }
                    _graphBuilder = null;
                }

                if (_dvdGraph != null)
                {
                    while ((hr = DirectShowUtil.ReleaseComObject(_dvdGraph)) > 0)
                    {
                        ;
                    }
                    _dvdGraph = null;
                }
                _state = PlayState.Init;
            }
            catch (Exception ex)
            {
                logger.Error("DVDPlayer:exception while cleanuping DShow graph {0} {1}", ex.Message, ex.StackTrace);
            }
        }
Exemplo n.º 32
0
        private void CloseInterfaces()
        {
            int hr = 0;

            try
            {
                lock (this)
                {
                    // Relinquish ownership (IMPORTANT!) after hiding video window
                    //if (!this.isAudioOnly)
                    //{
                    //    hr = this.videoWindow.put_Visible(OABool.False);
                    //    DsError.ThrowExceptionForHR(hr);
                    //    hr = this.videoWindow.put_Owner(IntPtr.Zero);
                    //    DsError.ThrowExceptionForHR(hr);
                    //}

                    //#if DEBUG
                    try
                    {
                        if (rot != null)
                        {
                            rot.Dispose();
                            rot = null;
                        }
                    }
                    catch { }
                    //#endif

                    if (dvdSubtitle != null)
                        Marshal.ReleaseComObject(dvdSubtitle);
                    dvdSubtitle = null;

                    if (dvdCtrl != null)
                    {
                        hr = dvdCtrl.SetOption(DvdOptionFlag.ResetOnStop, true);
                    }

                    if (cmdOption != null)
                    {
                        Marshal.ReleaseComObject(cmdOption);
                        cmdOption = null;
                    }

                    pendingCmd = false;

                    dvdCtrl = null;
                    if (dvdInfo != null)
                    {
                        Marshal.ReleaseComObject(dvdInfo);
                        dvdInfo = null;
                    }

                    if (this.mediaEventEx != null)
                    {
                        if (dvdGraph != null)
                            hr = this.mediaEventEx.SetNotifyWindow(IntPtr.Zero, WM.DVD_EVENT, IntPtr.Zero);
                        else
                            hr = this.mediaEventEx.SetNotifyWindow(IntPtr.Zero, WM.NULL, IntPtr.Zero);
                        //DsError.ThrowExceptionForHR(hr);
                    }

                    if (evrDisplay != null)
                    {
                        //evrDisplay.SetVideoWindow(IntPtr.Zero);
                        Marshal.ReleaseComObject(evrDisplay);
                    }
                    evrDisplay = null;
                    if (this.evrRenderer != null)
                        Marshal.ReleaseComObject(evrRenderer);
                    evrRenderer = null;

                    // Release and zero DirectShow interfaces
                    if (this.mediaEventEx != null)
                        this.mediaEventEx = null;
                    if (this.mediaSeeking != null)
                        this.mediaSeeking = null;
                    if (this.mediaPosition != null)
                        this.mediaPosition = null;
                    if (this.mediaControl != null)
                        this.mediaControl = null;
                    if (this.basicAudio != null)
                        this.basicAudio = null;
                    if (this.basicVideo != null)
                        this.basicVideo = null;
                    //if (this.videoWindow != null)
                    //    this.videoWindow = null;
                    if (this.frameStep != null)
                        this.frameStep = null;
                    if (this.graphBuilder != null)
                        Marshal.ReleaseComObject(this.graphBuilder); this.graphBuilder = null;
                    if (this.dvdGraph != null)
                        Marshal.ReleaseComObject(dvdGraph); dvdGraph = null;

                    GC.Collect();
                }
            }
            catch
            {
            }
        }
Exemplo n.º 33
0
        /// <summary> create the used COM components and get the interfaces. </summary>
        protected virtual bool GetDVDInterfaces(string path)
        {
            int hr;
            //Type	            comtype = null;
            object comobj = null;
            _freeNavigator = true;
            _dvdInfo = null;
            _dvdCtrl = null;
            bool useAC3Filter = false;
            string dvdNavigator = "";
            string aspectRatioMode = "";
            string displayMode = "";
            _videoPref = DvdPreferredDisplayMode.DisplayContentDefault;
            using (MediaPortal.Profile.Settings xmlreader = new MPSettings())
            {
                dvdNavigator = xmlreader.GetValueAsString("dvdplayer", "navigator", "DVD Navigator");
                aspectRatioMode = xmlreader.GetValueAsString("dvdplayer", "armode", "").ToLower();

                dvdNavigator = "dslibdvdnav";

                if (aspectRatioMode == "crop")
                {
                    arMode = AspectRatioMode.Crop;
                }
                if (aspectRatioMode == "letterbox")
                {
                    arMode = AspectRatioMode.LetterBox;
                }
                if (aspectRatioMode == "stretch")
                {
                    arMode = AspectRatioMode.Stretched;
                }
                //if ( aspectRatioMode == "stretch" ) arMode = AspectRatioMode.zoom14to9;
                if (aspectRatioMode == "follow stream")
                {
                    arMode = AspectRatioMode.StretchedAsPrimary;
                }
                useAC3Filter = xmlreader.GetValueAsBool("dvdplayer", "ac3", false);
                displayMode = xmlreader.GetValueAsString("dvdplayer", "displaymode", "").ToLower();
                if (displayMode == "default")
                {
                    _videoPref = DvdPreferredDisplayMode.DisplayContentDefault;
                }
                if (displayMode == "16:9")
                {
                    _videoPref = DvdPreferredDisplayMode.Display16x9;
                }
                if (displayMode == "4:3 pan scan")
                {
                    _videoPref = DvdPreferredDisplayMode.Display4x3PanScanPreferred;
                }
                if (displayMode == "4:3 letterbox")
                {
                    _videoPref = DvdPreferredDisplayMode.Display4x3LetterBoxPreferred;
                }
            }
            try
            {
                _dvdGraph = (IDvdGraphBuilder)new DvdGraphBuilder();

                hr = _dvdGraph.GetFiltergraph(out _graphBuilder);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
                _rotEntry = new DsROTEntry((IFilterGraph)_graphBuilder);

                _vmr9Filter = (IBaseFilter)new VideoMixingRenderer9();
                IVMRFilterConfig9 config = _vmr9Filter as IVMRFilterConfig9;
                hr = config.SetNumberOfStreams(1);
                hr = config.SetRenderingMode(VMR9Mode.Windowless);
                windowlessCtrl = (IVMRWindowlessControl9)_vmr9Filter;
                windowlessCtrl.SetVideoClippingWindow(this.panVideoWin.Handle);

                //                config.SetRenderingPrefs(VMR9RenderPrefs.

                _graphBuilder.AddFilter(_vmr9Filter, "Video Mixing Renderer 9");

             //               _vmr7 = new VMR7Util();
             //               _vmr7.AddVMR7(_graphBuilder);

                try
                {
                    _dvdbasefilter = DirectShowUtil.AddFilterToGraph(_graphBuilder, dvdNavigator);
                    if (_dvdbasefilter != null)
                    {
                        IDvdControl2 cntl = (IDvdControl2)_dvdbasefilter;
                        if (cntl != null)
                        {
                            _dvdInfo = (IDvdInfo2)cntl;
                            _dvdCtrl = (IDvdControl2)cntl;
                            if (path != null)
                            {
                                if (path.Length != 0)
                                {
                                    cntl.SetDVDDirectory(path);
                                }
                            }
                            _dvdCtrl.SetOption(DvdOptionFlag.HMSFTimeCodeEvents, true); // use new HMSF timecode format
                            _dvdCtrl.SetOption(DvdOptionFlag.ResetOnStop, false);

                            AddPreferedCodecs(_graphBuilder);
                            DirectShowUtil.RenderOutputPins(_graphBuilder, _dvdbasefilter);

            //                            _videoWin = _graphBuilder as IVideoWindow;
                            _freeNavigator = false;
                        }

                        //DirectShowUtil.ReleaseComObject( _dvdbasefilter); _dvdbasefilter = null;
                    }
                }
                catch (Exception ex)
                {
                    string strEx = ex.Message;
                }

                Guid riid;

                if (_dvdInfo == null)
                {
                    riid = typeof(IDvdInfo2).GUID;
                    hr = _dvdGraph.GetDvdInterface(riid, out comobj);
                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }
                    _dvdInfo = (IDvdInfo2)comobj;
                    comobj = null;
                }

                if (_dvdCtrl == null)
                {
                    riid = typeof(IDvdControl2).GUID;
                    hr = _dvdGraph.GetDvdInterface(riid, out comobj);
                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }
                    _dvdCtrl = (IDvdControl2)comobj;
                    comobj = null;
                }

                _mediaCtrl = (IMediaControl)_graphBuilder;
                _mediaEvt = (IMediaEventEx)_graphBuilder;
                _basicAudio = _graphBuilder as IBasicAudio;
                _mediaPos = (IMediaPosition)_graphBuilder;
                _mediaSeek = (IMediaSeeking)_graphBuilder;
                _mediaStep = (IVideoFrameStep)_graphBuilder;
                _basicVideo = _graphBuilder as IBasicVideo2;
                _videoWin = _graphBuilder as IVideoWindow;

                // disable Closed Captions!
                IBaseFilter baseFilter;
                _graphBuilder.FindFilterByName("Line 21 Decoder", out baseFilter);
                if (baseFilter == null)
                {
                    _graphBuilder.FindFilterByName("Line21 Decoder", out baseFilter);
                }
                if (baseFilter != null)
                {
                    _line21Decoder = (IAMLine21Decoder)baseFilter;
                    if (_line21Decoder != null)
                    {
                        AMLine21CCState state = AMLine21CCState.Off;
                        hr = _line21Decoder.SetServiceState(state);
                        if (hr == 0)
                        {
                            logger.Info("DVDPlayer:Closed Captions disabled");
                        }
                        else
                        {
                            logger.Info("DVDPlayer:failed 2 disable Closed Captions");
                        }
                    }
                }
                /*
                        // get video window
                        if (_videoWin==null)
                        {
                          riid = typeof( IVideoWindow ).GUID;
                          hr = _dvdGraph.GetDvdInterface( ref riid, out comobj );
                          if( hr < 0 )
                            Marshal.ThrowExceptionForHR( hr );
                          _videoWin = (IVideoWindow) comobj; comobj = null;
                        }
                  */
                // GetFrameStepInterface();

                DirectShowUtil.SetARMode(_graphBuilder, arMode);
                DirectShowUtil.EnableDeInterlace(_graphBuilder);
                //m_ovMgr = new OVTOOLLib.OvMgrClass();
                //m_ovMgr.SetGraph(_graphBuilder);

                return true;
            }
            catch (Exception)
            {

                //MessageBox.Show( this, "Could not get interfaces\r\n" + ee.Message, "DVDPlayer.NET", MessageBoxButtons.OK, MessageBoxIcon.Stop );
                CloseDVDInterfaces();
                return false;
            }
            finally
            {
                if (comobj != null)
                {
                    DirectShowUtil.ReleaseComObject(comobj);
                }
                comobj = null;
            }
        }
Exemplo n.º 34
0
        /// <summary> create the used COM components and get the interfaces. </summary>
        protected virtual bool GetDVDInterfaces(string path)
        {
            int hr;
            //Type	            comtype = null;
            object comobj = null;

            _freeNavigator = true;
            _dvdInfo       = null;
            _dvdCtrl       = null;
            bool   useAC3Filter    = false;
            string dvdNavigator    = "";
            string aspectRatioMode = "";
            string displayMode     = "";

            _videoPref = DvdPreferredDisplayMode.DisplayContentDefault;
            using (MediaPortal.Profile.Settings xmlreader = new MPSettings())
            {
                dvdNavigator    = xmlreader.GetValueAsString("dvdplayer", "navigator", "DVD Navigator");
                aspectRatioMode = xmlreader.GetValueAsString("dvdplayer", "armode", "").ToLower();

                dvdNavigator = "dslibdvdnav";

                if (aspectRatioMode == "crop")
                {
                    arMode = AspectRatioMode.Crop;
                }
                if (aspectRatioMode == "letterbox")
                {
                    arMode = AspectRatioMode.LetterBox;
                }
                if (aspectRatioMode == "stretch")
                {
                    arMode = AspectRatioMode.Stretched;
                }
                //if ( aspectRatioMode == "stretch" ) arMode = AspectRatioMode.zoom14to9;
                if (aspectRatioMode == "follow stream")
                {
                    arMode = AspectRatioMode.StretchedAsPrimary;
                }
                useAC3Filter = xmlreader.GetValueAsBool("dvdplayer", "ac3", false);
                displayMode  = xmlreader.GetValueAsString("dvdplayer", "displaymode", "").ToLower();
                if (displayMode == "default")
                {
                    _videoPref = DvdPreferredDisplayMode.DisplayContentDefault;
                }
                if (displayMode == "16:9")
                {
                    _videoPref = DvdPreferredDisplayMode.Display16x9;
                }
                if (displayMode == "4:3 pan scan")
                {
                    _videoPref = DvdPreferredDisplayMode.Display4x3PanScanPreferred;
                }
                if (displayMode == "4:3 letterbox")
                {
                    _videoPref = DvdPreferredDisplayMode.Display4x3LetterBoxPreferred;
                }
            }
            try
            {
                _dvdGraph = (IDvdGraphBuilder) new DvdGraphBuilder();

                hr = _dvdGraph.GetFiltergraph(out _graphBuilder);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
                _rotEntry = new DsROTEntry((IFilterGraph)_graphBuilder);

                _vmr9Filter = (IBaseFilter) new VideoMixingRenderer9();
                IVMRFilterConfig9 config = _vmr9Filter as IVMRFilterConfig9;
                hr             = config.SetNumberOfStreams(1);
                hr             = config.SetRenderingMode(VMR9Mode.Windowless);
                windowlessCtrl = (IVMRWindowlessControl9)_vmr9Filter;
                windowlessCtrl.SetVideoClippingWindow(this.panVideoWin.Handle);


                //                config.SetRenderingPrefs(VMR9RenderPrefs.

                _graphBuilder.AddFilter(_vmr9Filter, "Video Mixing Renderer 9");

                //               _vmr7 = new VMR7Util();
                //               _vmr7.AddVMR7(_graphBuilder);

                try
                {
                    _dvdbasefilter = DirectShowUtil.AddFilterToGraph(_graphBuilder, dvdNavigator);
                    if (_dvdbasefilter != null)
                    {
                        IDvdControl2 cntl = (IDvdControl2)_dvdbasefilter;
                        if (cntl != null)
                        {
                            _dvdInfo = (IDvdInfo2)cntl;
                            _dvdCtrl = (IDvdControl2)cntl;
                            if (path != null)
                            {
                                if (path.Length != 0)
                                {
                                    cntl.SetDVDDirectory(path);
                                }
                            }
                            _dvdCtrl.SetOption(DvdOptionFlag.HMSFTimeCodeEvents, true); // use new HMSF timecode format
                            _dvdCtrl.SetOption(DvdOptionFlag.ResetOnStop, false);

                            AddPreferedCodecs(_graphBuilder);
                            DirectShowUtil.RenderOutputPins(_graphBuilder, _dvdbasefilter);


//                            _videoWin = _graphBuilder as IVideoWindow;
                            _freeNavigator = false;
                        }

                        //DirectShowUtil.ReleaseComObject( _dvdbasefilter); _dvdbasefilter = null;
                    }
                }
                catch (Exception ex)
                {
                    string strEx = ex.Message;
                }

                Guid riid;

                if (_dvdInfo == null)
                {
                    riid = typeof(IDvdInfo2).GUID;
                    hr   = _dvdGraph.GetDvdInterface(riid, out comobj);
                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }
                    _dvdInfo = (IDvdInfo2)comobj;
                    comobj   = null;
                }

                if (_dvdCtrl == null)
                {
                    riid = typeof(IDvdControl2).GUID;
                    hr   = _dvdGraph.GetDvdInterface(riid, out comobj);
                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }
                    _dvdCtrl = (IDvdControl2)comobj;
                    comobj   = null;
                }

                _mediaCtrl  = (IMediaControl)_graphBuilder;
                _mediaEvt   = (IMediaEventEx)_graphBuilder;
                _basicAudio = _graphBuilder as IBasicAudio;
                _mediaPos   = (IMediaPosition)_graphBuilder;
                _mediaSeek  = (IMediaSeeking)_graphBuilder;
                _mediaStep  = (IVideoFrameStep)_graphBuilder;
                _basicVideo = _graphBuilder as IBasicVideo2;
                _videoWin   = _graphBuilder as IVideoWindow;

                // disable Closed Captions!
                IBaseFilter baseFilter;
                _graphBuilder.FindFilterByName("Line 21 Decoder", out baseFilter);
                if (baseFilter == null)
                {
                    _graphBuilder.FindFilterByName("Line21 Decoder", out baseFilter);
                }
                if (baseFilter != null)
                {
                    _line21Decoder = (IAMLine21Decoder)baseFilter;
                    if (_line21Decoder != null)
                    {
                        AMLine21CCState state = AMLine21CCState.Off;
                        hr = _line21Decoder.SetServiceState(state);
                        if (hr == 0)
                        {
                            logger.Info("DVDPlayer:Closed Captions disabled");
                        }
                        else
                        {
                            logger.Info("DVDPlayer:failed 2 disable Closed Captions");
                        }
                    }
                }

                /*
                 *      // get video window
                 *      if (_videoWin==null)
                 *      {
                 *        riid = typeof( IVideoWindow ).GUID;
                 *        hr = _dvdGraph.GetDvdInterface( ref riid, out comobj );
                 *        if( hr < 0 )
                 *          Marshal.ThrowExceptionForHR( hr );
                 *        _videoWin = (IVideoWindow) comobj; comobj = null;
                 *      }
                 */
                // GetFrameStepInterface();

                DirectShowUtil.SetARMode(_graphBuilder, arMode);
                DirectShowUtil.EnableDeInterlace(_graphBuilder);
                //m_ovMgr = new OVTOOLLib.OvMgrClass();
                //m_ovMgr.SetGraph(_graphBuilder);

                return(true);
            }
            catch (Exception)
            {
                //MessageBox.Show( this, "Could not get interfaces\r\n" + ee.Message, "DVDPlayer.NET", MessageBoxButtons.OK, MessageBoxIcon.Stop );
                CloseDVDInterfaces();
                return(false);
            }
            finally
            {
                if (comobj != null)
                {
                    DirectShowUtil.ReleaseComObject(comobj);
                }
                comobj = null;
            }
        }
        private void InitializeDvd(string path)
        {
            int hr = m_graph.AddFilter(_sourceFilter, "DVD Navigator");
            DsError.ThrowExceptionForHR(hr);

            /* The DVDControl2 interface lets us control DVD features */
            _mDvdControl = _sourceFilter as IDvdControl2;

            if (_mDvdControl == null)
                throw new Exception("Could not QueryInterface the IDvdControl2 interface");

            var videoTsPath = Path.Combine(path, "video_ts");
            if (Directory.Exists(videoTsPath))
            {
                path = videoTsPath;
            }

            /* If a Dvd directory has been set then use it, if not, let DShow find the Dvd */
            hr = _mDvdControl.SetDVDDirectory(path);
            DsError.ThrowExceptionForHR(hr);

            /* This gives us the DVD time in Hours-Minutes-Seconds-Frame time format, and other options */
            hr = _mDvdControl.SetOption(DvdOptionFlag.HMSFTimeCodeEvents, true);
            DsError.ThrowExceptionForHR(hr);

            /* If the graph stops, resume at the same point */
            _mDvdControl.SetOption(DvdOptionFlag.ResetOnStop, false);

            /* QueryInterface the DVDInfo2 */
            //dvdInfo = _sourceFilter as IDvdInfo2;

            //int uTitle = 1;
            //dma = new DvdMenuAttributes();
            //dta = new DvdTitleAttributes();
            //m_dvdInfo.GetTitleAttributes(uTitle, out dma, dta);

            //int iX = dta.VideoAttributes.aspectX;
            //int iY = dta.VideoAttributes.aspectY;
            //DvdIsLetterBoxed = dta.VideoAttributes.isSourceLetterboxed;
            //int sX = dta.VideoAttributes.sourceResolutionX;
            //int sY = dta.VideoAttributes.sourceResolutionY;
        }
Exemplo n.º 36
0
        private void PlayDVDInWindow(string filepath)
        {
            FileLogger.Log("PlayDVDInWindow: {0}", filepath);
            int hr = 0;
            dvdGraph = new DvdGraphBuilder() as IDvdGraphBuilder;

            if (dvdGraph != null)
            {
                hr = dvdGraph.GetFiltergraph(out this.graphBuilder);
                DsError.ThrowExceptionForHR(hr);

                if (ps.PublishGraph)
                    rot = new DsROTEntry(this.graphBuilder);

                AMDvdGraphFlags buildFlags = AMDvdGraphFlags.EvrOnly;

                if (ps.PreferredDecoders != null)
                {
                    foreach (string pa in ps.PreferredDecoders)
                    {
                        string[] pvA = pa.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                        if (pvA[0].ToLower() == ".ifo")
                        {
                            for (int i = 1; i < pvA.Length; i++)
                            {
                                string strFilter = pvA[i].Trim();
                                IBaseFilter filter = null;
                                try
                                {
                                    if (Regex.IsMatch(strFilter, @"{?\w{8}-\w{4}-\w{4}-\w{4}-\w{12}}?"))
                                        filter = FilterGraphTools.AddFilterFromClsid(graphBuilder, new Guid(strFilter), strFilter);
                                    else
                                        filter = FilterGraphTools.AddFilterByName(graphBuilder, FilterCategory.LegacyAmFilterCategory, strFilter);

                                    if (filter != null)
                                    {
                                        FileLogger.Log("Added {0} to the graph", strFilter);
                                        buildFlags = AMDvdGraphFlags.EvrOnly | AMDvdGraphFlags.DoNotClear;
                                    }
                                    else
                                        FileLogger.Log("{0} not added to the graph", strFilter);
                                }
                                finally
                                {
                                    if (filter != null)
                                        Marshal.ReleaseComObject(filter);
                                    filter = null;
                                }
                            }
                        }
                    }
                }

                object objEvr;
                hr = dvdGraph.GetDvdInterface(typeof(IMFVideoRenderer).GUID, out objEvr);
                DsError.ThrowExceptionForHR(hr);

                evrRenderer = objEvr as IBaseFilter;
                SetupEvrDisplay();

                AMDvdRenderStatus buildStatus;
                hr = dvdGraph.RenderDvdVideoVolume(filepath, buildFlags, out buildStatus);
                DsError.ThrowExceptionForHR(hr);

                if (buildStatus.iNumStreamsFailed > 1)
                {
                 //   throw new ApplicationException("Could not render video_ts, try forcing a dvd decoder");
                    IBaseFilter lavVideo = FilterGraphTools.FindFilterByClsid(graphBuilder, new Guid("{EE30215D-164F-4A92-A4EB-9D4C13390F9F}"));
                    IPin lavOut = null;
                    IPin evrIn = null;

                    try
                    {
                        lavOut = DsFindPin.ByDirection(lavVideo, PinDirection.Output, 0);
                        if (lavOut != null)
                        {
                            hr = lavOut.ConnectedTo(out evrIn);
                            //DsError.ThrowExceptionForHR(hr);

                            if (evrIn == null)
                            {
                                evrIn = DsFindPin.ByDirection(evrRenderer, PinDirection.Input, 0);
                                hr = graphBuilder.ConnectDirect(lavOut, evrIn, null);
                                DsError.ThrowExceptionForHR(hr);
                            }
                        }
                    }
                    finally
                    {
                        if (lavOut != null)
                            Marshal.ReleaseComObject(lavOut);
                        if (evrIn != null)
                            Marshal.ReleaseComObject(evrIn);
                        if (lavVideo != null)
                            Marshal.ReleaseComObject(lavVideo);
                    }
                }
                SetEvrVideoMode();

                object comobj = null;

                hr = dvdGraph.GetDvdInterface(typeof(IDvdInfo2).GUID, out comobj);
                //DsError.ThrowExceptionForHR(hr);
                if (comobj != null)
                {
                    dvdInfo = (IDvdInfo2)comobj;
                    comobj = null;
                }

                hr = dvdGraph.GetDvdInterface(typeof(IDvdControl2).GUID, out comobj);
                //DsError.ThrowExceptionForHR(hr);
                if (comobj != null)
                {
                    dvdCtrl = (IDvdControl2)comobj;
                    comobj = null;
                }

                hr = dvdGraph.GetDvdInterface(typeof(IAMLine21Decoder).GUID, out comobj);
                //DsError.ThrowExceptionForHR(hr);
                if (comobj != null)
                {
                    dvdSubtitle = (IAMLine21Decoder)comobj;
                    comobj = null;
                }

                //IBaseFilter yo = dvdSubtitle as IBaseFilter;
                //IPin mama = dvdSubtitle as IPin;

                menuItemSubtitles.Checked = ToogleSubtitles();

                hr = dvdCtrl.SetOption(DvdOptionFlag.HMSFTimeCodeEvents, true);	// use new HMSF timecode format
                DsError.ThrowExceptionForHR(hr);

                hr = dvdCtrl.SetOption(DvdOptionFlag.ResetOnStop, false);
                DsError.ThrowExceptionForHR(hr);
                


                // QueryInterface for DirectShow interfaces
                this.mediaControl = (IMediaControl)this.graphBuilder;
                this.mediaEventEx = (IMediaEventEx)this.graphBuilder;
                this.mediaSeeking = (IMediaSeeking)this.graphBuilder;
                this.mediaPosition = (IMediaPosition)this.graphBuilder;

                // Query for audio interfaces, which may not be relevant for video-only files
                this.basicAudio = this.graphBuilder as IBasicAudio;

                // Is this an audio-only file (no video component)?
                CheckVisibility();

                // Have the graph signal event via window callbacks for performance
                //hr = this.mediaEventEx.SetNotifyWindow(this.Handle, WMGraphNotify, IntPtr.Zero);
                //DsError.ThrowExceptionForHR(hr);
                hr = mediaEventEx.SetNotifyWindow(this.Handle, WM.DVD_EVENT, IntPtr.Zero);
                DsError.ThrowExceptionForHR(hr);

                if (!this.isAudioOnly)
                {
                    // Setup the video window
                    //hr = this.videoWindow.put_Owner(this.Handle);
                    //DsError.ThrowExceptionForHR(hr);
                    //this.evrDisplay.SetVideoWindow(this.Handle);

                    //hr = this.videoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipSiblings | WindowStyle.ClipChildren);
                    //DsError.ThrowExceptionForHR(hr);

                    hr = InitVideoWindow();//1, 1);
                    DsError.ThrowExceptionForHR(hr);

                    GetFrameStepInterface();
                }
                else
                {
                    // Initialize the default player size and enable playback menu items
                    hr = InitPlayerWindow();
                    DsError.ThrowExceptionForHR(hr);

                    EnablePlaybackMenu(true, MediaType.Audio);
                }

                // Complete window initialization
                //CheckSizeMenu(menuFileSizeNormal);
                //this.isFullScreen = false;
                this.currentPlaybackRate = 1.0;
                UpdateMainTitle();

                this.Activate();

                //pre-roll the graph
                hr = this.mediaControl.Pause();
                DsError.ThrowExceptionForHR(hr);

                // Run the graph to play the media file
                hr = this.mediaControl.Run();
                DsError.ThrowExceptionForHR(hr);
                
                MoveToBookmark();

                this.currentState = PlayState.Running;
                if (isFullScreen)
                    tmMouseMove.Enabled = true;
            }
        }