/// <summary> create the used COM components and get the interfaces. </summary>
    protected virtual bool GetInterfaces(string filename)
    {
      Log.Info("StreambufferPlayer:GetInterfaces()");
      //Type comtype = null;
      object comobj = null;
      try
      {
        _graphBuilder = (IGraphBuilder)new FilterGraph();

        _bufferSource = (IStreamBufferSource)new StreamBufferSource();

        int hr;
        m_StreamBufferConfig = new StreamBufferConfig();
        streamConfig2 = m_StreamBufferConfig as IStreamBufferConfigure2;
        if (streamConfig2 != null)
        {
          // setting the StreamBufferEngine registry key
          IntPtr HKEY = (IntPtr)unchecked((int)0x80000002L);
          IStreamBufferInitialize pTemp = (IStreamBufferInitialize)streamConfig2;
          IntPtr subKey = IntPtr.Zero;

          RegOpenKeyEx(HKEY, "SOFTWARE\\MediaPortal", 0, 0x3f, out subKey);
          hr = pTemp.SetHKEY(subKey);
          hr = streamConfig2.SetFFTransitionRates(8, 32);
          //Log.Info("set FFTransitionRates:{0:X}",hr);

          int max, maxnon;
          hr = streamConfig2.GetFFTransitionRates(out max, out maxnon);
          //Log.Info("get FFTransitionRates:{0} {1} {2:X}",max,maxnon,hr);
          streamConfig2.GetBackingFileCount(out _minBackingFiles, out _maxBackingFiles);
          streamConfig2.GetBackingFileDuration(out _backingFileDuration);
        }


        IBaseFilter filter = (IBaseFilter)_bufferSource;
        _graphBuilder.AddFilter(filter, "SBE SOURCE");

        IFileSourceFilter fileSource = (IFileSourceFilter)_bufferSource;
        hr = fileSource.Load(filename, null);

        // add preferred video & audio codecs
        string strVideoCodec = "";
        string strAudioCodec = "";
        string strAudiorenderer = "";
        int intFilters = 0; // FlipGer: count custom filters
        string strFilters = ""; // FlipGer: collect custom filters
        using (Settings xmlreader = new MPSettings())
        {
          _CodecSupportsFastSeeking = xmlreader.GetValueAsBool("debug", "CodecSupportsFastSeeking", false);
          Log.Debug("BaseStreamBufferPlayer: Codec supports fast seeking = {0}", _CodecSupportsFastSeeking);
          // FlipGer: load infos for custom filters
          int intCount = 0;
          while (xmlreader.GetValueAsString("mytv", "filter" + intCount.ToString(), "undefined") != "undefined")
          {
            if (xmlreader.GetValueAsBool("mytv", "usefilter" + intCount.ToString(), false))
            {
              strFilters += xmlreader.GetValueAsString("mytv", "filter" + intCount.ToString(), "undefined") + ";";
              intFilters++;
            }
            intCount++;
          }
          strVideoCodec = xmlreader.GetValueAsString("mytv", "videocodec", "");
          strAudioCodec = xmlreader.GetValueAsString("mytv", "audiocodec", "");
          strAudiorenderer = xmlreader.GetValueAsString("mytv", "audiorenderer", "Default DirectSound Device");
          string strValue = xmlreader.GetValueAsString("mytv", "defaultar", "Normal");
          GUIGraphicsContext.ARType = Util.Utils.GetAspectRatio(strValue);
        }
        if (strVideoCodec.Length > 0)
        {
          _videoCodecFilter = DirectShowUtil.AddFilterToGraph(_graphBuilder, strVideoCodec);
        }
        if (strAudioCodec.Length > 0)
        {
          _audioCodecFilter = DirectShowUtil.AddFilterToGraph(_graphBuilder, strAudioCodec);
        }
        if (strAudiorenderer.Length > 0)
        {
          _audioRendererFilter = DirectShowUtil.AddAudioRendererToGraph(_graphBuilder, strAudiorenderer, true);
        }
        // FlipGer: add custom filters to graph
        customFilters = new IBaseFilter[intFilters];
        string[] arrFilters = strFilters.Split(';');
        for (int i = 0; i < intFilters; i++)
        {
          customFilters[i] = DirectShowUtil.AddFilterToGraph(_graphBuilder, arrFilters[i]);
        }

        //render outputpins of SBE
        DirectShowUtil.RenderOutputPins(_graphBuilder, (IBaseFilter)fileSource);

        _mediaCtrl = (IMediaControl)_graphBuilder;
        _videoWin = _graphBuilder as IVideoWindow;
        _mediaEvt = (IMediaEventEx)_graphBuilder;
        _mediaSeeking = _bufferSource as IStreamBufferMediaSeeking;
        _mediaSeeking2 = _bufferSource as IStreamBufferMediaSeeking2;
        if (_mediaSeeking == null)
        {
          Log.Error("Unable to get IMediaSeeking interface#1");
        }
        if (_mediaSeeking2 == null)
        {
          Log.Error("Unable to get IMediaSeeking interface#2");
        }

        if (_audioRendererFilter != null)
        {
          IMediaFilter mp = _graphBuilder as IMediaFilter;
          IReferenceClock clock = _audioRendererFilter as IReferenceClock;
          hr = mp.SetSyncSource(clock);
        }
        _basicVideo = _graphBuilder as IBasicVideo2;
        _basicAudio = _graphBuilder as IBasicAudio;

        //Log.Info("StreamBufferPlayer:SetARMode");
        DirectShowUtil.SetARMode(_graphBuilder, AspectRatioMode.Stretched);

        _graphBuilder.SetDefaultSyncSource();
        //Log.Info("StreamBufferPlayer: set Deinterlace");

        //Log.Info("StreamBufferPlayer: done");
        return true;
      }
      catch (Exception ex)
      {
        Log.Error("StreamBufferPlayer:exception while creating DShow graph {0} {1}", ex.Message, ex.StackTrace);
        return false;
      }
      finally
      {
        if (comobj != null)
        {
          DirectShowUtil.ReleaseComObject(comobj);
        }
        comobj = null;
      }
    }
Exemplo n.º 2
0
        void DSGraphEditPanel_Disposed(object sender, EventArgs e)
        {
            // only stop the graph if we created it
            if (_filterGraphCreated)
            {
                Stop();
            }

            timeSliderTimer.Enabled = false;

            // remove from rot table if we added it
            if (rot != null)
            {
                rot.Dispose();
                rot = null;
            }

            try
            {
                // nix the media sink
                if (_mediaEventEx != null)
                {
                    _mediaEventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);
                }

                _graphBuilder = null;
                _mediaControl = null;
                _mediaSeeking = null;
                _basicAudio   = null;
                _basicVideo   = null;
                _videoWindow  = null;
                _mediaEventEx = null;

                // only release the filtergraph if WE created it.  If the user passed one into a constructor,
                // it's up to them to release it.
                if (_filterGraphCreated)
                {
                    int refc = Marshal.ReleaseComObject(_graph);
                }

                // if it is a connected graph, renounce all claim on the proxie's RCW
                if (_isRemoteGraph)
                {
                    Marshal.FinalReleaseComObject(_graph);
                }
            }
            catch (InvalidComObjectException ex)
            {
                // the RCW became disconnected,  This is most likely caused by connecting to a remote graph
                // in the same AppDomain.  Just ignore it.
            }
        }
Exemplo n.º 3
0
        protected override void CloseInterfaces()
        {
            if (VideoWindow != null)
            {
                VideoWindow.put_Visible(DsHlp.OAFALSE);
                VideoWindow.put_MessageDrain(IntPtr.Zero);
                VideoWindow.put_Owner(IntPtr.Zero);
                VideoWindow = null;
            }

            BasicVideo2 = null;     // both interfaces are going to be released when _pGraphBuilder is released

            base.CloseInterfaces(); // must be called to release the main pointer and all child interfaces (if any)
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initialize items common to all constructors
        /// </summary>
        private void Init()
        {
            // get interfaces
            _mediaControl = _graph as IMediaControl;
            _basicAudio   = _graph as IBasicAudio;
            _basicVideo   = _graph as IBasicVideo2;
            _graphBuilder = _graph as IGraphBuilder;

            // hook the DaggerGraph events
            dsDaggerUIGraph1.Graph.BeforeNodeRemoved      += new BeforeNodeRemoveHandler(Graph_BeforeNodeRemoved);
            dsDaggerUIGraph1.Graph.BeforePinsConnected    += new PinBeforeConnectedHandler(Graph_BeforePinsConnected);
            dsDaggerUIGraph1.Graph.BeforePinsDisconnected += new PinBeforeDisconnectedHandler(Graph_BeforePinsDisconnected);
            dsDaggerUIGraph1.BeforeSelectionDeleted       += new BeforeDeleteSelected(dsDaggerUIGraph1_BeforeSelectionDeleted);
            dsDaggerUIGraph1.Graph.OnTopologyChanged      += new EventHandler(Graph_OnTopologyChanged);
            this.Disposed += new EventHandler(DSGraphEditPanel_Disposed);
        }
Exemplo n.º 5
0
        protected override void Initialize(IGraphBuilder pGraphBuilder, IntPtr hMediaWindow)
        {
            try
            {
                BasicVideo2 = (IBasicVideo2)pGraphBuilder;
                VideoWindow = (IVideoWindow)pGraphBuilder;
            }
            catch (Exception e)
            {
                throw new FilterGraphBuilderException(GraphBuilderError.NecessaryInterfaces, e);
            }

            VideoWindow.put_Owner(hMediaWindow);
            VideoWindow.put_MessageDrain(hMediaWindow);
            VideoWindow.put_WindowStyle(WindowsManagement.WS_CHILD |
                                        WindowsManagement.WS_CLIPSIBLINGS);
        }
Exemplo n.º 6
0
        public void DoTests()
        {
            m_graphBuilder = BuildGraph(g_TestFile);
            m_ibv          = m_graphBuilder as IBasicVideo2;

            try
            {
                TestAvgTime();
                TestBitErrorRate();
                TestBitRate();
                TestVideoDim();
                TestSourceLeft();
                TestSourceTop();
                TestSourceWidth();
                TestSourceHeight();
                TestDestinationWidth();
                TestDestinationLeft();
                TestDestinationTop();
                TestDestinationHeight();
                TestSourcePos();
                TestDestinationPos();
                TestGetImage();
                TestPalette();
                TestGetPreferredAspectRatio();
            }
            finally
            {
                if (m_graphBuilder != null)
                {
                    Marshal.ReleaseComObject(m_graphBuilder);
                }

                m_graphBuilder = null;
                m_ibv          = null;
                m_dsrot.Dispose();
            }
        }
Exemplo n.º 7
0
        private void Cleanup()
        {
            if (graphBuilder == null)
            {
                return;
            }
            int hr;

            Log.Info("RTSPPlayer:cleanup DShow graph");
            try
            {
                if (_mediaCtrl != null)
                {
                    int         counter = 0;
                    FilterState state;
                    hr = _mediaCtrl.Stop();
                    hr = _mediaCtrl.GetState(10, out state);
                    while (state != FilterState.Stopped || GUIGraphicsContext.InVmr9Render)
                    {
                        Thread.Sleep(100);
                        hr = _mediaCtrl.GetState(10, out state);
                        counter++;
                        if (counter >= 30)
                        {
                            if (state != FilterState.Stopped)
                            {
                                Log.Error("RTSPPlayer: graph still running");
                            }
                            if (GUIGraphicsContext.InVmr9Render)
                            {
                                Log.Error("RTSPPlayer: in renderer");
                            }
                            break;
                        }
                    }
                    _mediaCtrl = null;
                }

                if (Vmr9 != null)
                {
                    Vmr9.Enable(false);
                }

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

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

                _mediaSeeking = null;
                mediaPos      = null;
                basicAudio    = null;
                basicVideo    = null;
                videoWin      = null;
                SubEngine.GetInstance().FreeSubtitles();

                if (graphBuilder != null)
                {
                    DirectShowUtil.RemoveFilters(graphBuilder);
                    if (_rotEntry != null)
                    {
                        _rotEntry.SafeDispose();
                        _rotEntry = null;
                    }
                    DirectShowUtil.ReleaseComObject(graphBuilder);
                    graphBuilder = null;
                }

                if (Vmr9 != null)
                {
                    Vmr9.SafeDispose();
                    Vmr9 = null;
                }

                GUIGraphicsContext.form.Invalidate(true);
                _state = PlayState.Init;

                if (_mpegDemux != null)
                {
                    Log.Info("cleanup mpegdemux");
                    while ((hr = DirectShowUtil.ReleaseComObject(_mpegDemux)) > 0)
                    {
                        ;
                    }
                    _mpegDemux = null;
                }
                if (_rtspSource != null)
                {
                    Log.Info("cleanup _rtspSource");
                    while ((hr = DirectShowUtil.ReleaseComObject(_rtspSource)) > 0)
                    {
                        ;
                    }
                    _rtspSource = null;
                }
                if (_subtitleFilter != null)
                {
                    while ((hr = DirectShowUtil.ReleaseComObject(_subtitleFilter)) > 0)
                    {
                        ;
                    }
                    _subtitleFilter = null;
                    if (this.dvbSubRenderer != null)
                    {
                        this.dvbSubRenderer.SetPlayer(null);
                    }
                    this.dvbSubRenderer = null;
                }


                if (vobSub != null)
                {
                    Log.Info("cleanup vobSub");
                    while ((hr = DirectShowUtil.ReleaseComObject(vobSub)) > 0)
                    {
                        ;
                    }
                    vobSub = null;
                }
            }
            catch (Exception ex)
            {
                Log.Error("RTSPPlayer: Exception while cleanuping DShow graph - {0} {1}", ex.Message, ex.StackTrace);
            }

            //switch back to directx windowed mode
            Log.Info("RTSPPlayer: Disabling DX9 exclusive mode");
            GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_SWITCH_FULL_WINDOWED, 0, 0, 0, 0, 0, null);

            GUIWindowManager.SendMessage(msg);
        }
    /// <summary> create the used COM components and get the interfaces. </summary>
    protected virtual bool GetInterfaces(string filename)
    {
      int hr;
      Log.Info("TSReaderPlayer:GetInterfaces()");
      //Type comtype = null;
      object comobj = null;
      try
      {
        _graphBuilder = (IGraphBuilder)new FilterGraph();
        TsReader reader = new TsReader();
        _fileSource = (IBaseFilter)reader;
        ((ITSReader)reader).SetTsReaderCallback(this);
        ((ITSReader)reader).SetRequestAudioChangeCallback(this);
        IBaseFilter filter = (IBaseFilter)_fileSource;
        _graphBuilder.AddFilter(filter, "TsReader");
        IFileSourceFilter interFaceFile = (IFileSourceFilter)_fileSource;
        interFaceFile.Load(filename, null);
        // add preferred video & audio codecs
        string strVideoCodec = "";
        string strH264VideoCodec = "";
        string strAudioCodec = "";
        string strAACAudioCodec = "";
        string strDDPLUSAudioCodec = "";
        string strAudiorenderer = "";
        int intFilters = 0; // FlipGer: count custom filters
        string strFilters = ""; // FlipGer: collect custom filters
        using (Settings xmlreader = new MPSettings())
        {
          _CodecSupportsFastSeeking = xmlreader.GetValueAsBool("debug", "CodecSupportsFastSeeking", true);
          Log.Debug("BaseTSReaderPlayer: Codec supports fast seeking = {0}", _CodecSupportsFastSeeking);
          // FlipGer: load infos for custom filters
          int intCount = 0;
          while (xmlreader.GetValueAsString("mytv", "filter" + intCount.ToString(), "undefined") != "undefined")
          {
            if (xmlreader.GetValueAsBool("mytv", "usefilter" + intCount.ToString(), false))
            {
              strFilters += xmlreader.GetValueAsString("mytv", "filter" + intCount.ToString(), "undefined") + ";";
              intFilters++;
            }
            intCount++;
          }
          strVideoCodec = xmlreader.GetValueAsString("mytv", "videocodec", "");
          strH264VideoCodec = xmlreader.GetValueAsString("mytv", "h264videocodec", "");
          strAudioCodec = xmlreader.GetValueAsString("mytv", "audiocodec", "");
          strAACAudioCodec = xmlreader.GetValueAsString("mytv", "aacaudiocodec", "");
          strDDPLUSAudioCodec = xmlreader.GetValueAsString("mytv", "ddplusaudiocodec", "");
          strAudiorenderer = xmlreader.GetValueAsString("mytv", "audiorenderer", "Default DirectSound Device");
          string strValue = xmlreader.GetValueAsString("mytv", "defaultar", "Normal");
          GUIGraphicsContext.ARType = Util.Utils.GetAspectRatio(strValue);
        }
        if (strVideoCodec.Length > 0)
        {
          DirectShowUtil.AddFilterToGraph(_graphBuilder, strVideoCodec);
        }
        if (strH264VideoCodec.Length > 0)
        {
          DirectShowUtil.AddFilterToGraph(_graphBuilder, strH264VideoCodec);
        }
        if (strAudioCodec.Length > 0)
        {
          DirectShowUtil.AddFilterToGraph(_graphBuilder, strAudioCodec);
        }
        if (strAACAudioCodec.Length > 0)
        {
          DirectShowUtil.AddFilterToGraph(_graphBuilder, strAACAudioCodec);
        }
        if (strDDPLUSAudioCodec.Length > 0)
        {
          DirectShowUtil.AddFilterToGraph(_graphBuilder, strDDPLUSAudioCodec);
        }
        if (strAudiorenderer.Length > 0)
        {
          _audioRendererFilter = DirectShowUtil.AddAudioRendererToGraph(_graphBuilder, strAudiorenderer, false);
        }
        // FlipGer: add custom filters to graph
        string[] arrFilters = strFilters.Split(';');
        for (int i = 0; i < intFilters; i++)
        {
          DirectShowUtil.AddFilterToGraph(_graphBuilder, arrFilters[i]);
        }

        DirectShowUtil.RenderOutputPins(_graphBuilder, (IBaseFilter)_fileSource);
        _mediaCtrl = (IMediaControl)_graphBuilder;
        _videoWin = _graphBuilder as IVideoWindow;
        _mediaEvt = (IMediaEventEx)_graphBuilder;
        _mediaSeeking = _graphBuilder as IMediaSeeking;
        if (_mediaSeeking == null)
        {
          Log.Error("Unable to get IMediaSeeking interface#1");
        }

        if (_audioRendererFilter != null)
        {
          IMediaFilter mp = _graphBuilder as IMediaFilter;
          IReferenceClock clock = _audioRendererFilter as IReferenceClock;
          hr = mp.SetSyncSource(clock);
        }
        _basicVideo = _graphBuilder as IBasicVideo2;
        _basicAudio = _graphBuilder as IBasicAudio;
        //Log.Info("TSReaderPlayer:SetARMode");
        DirectShowUtil.SetARMode(_graphBuilder, AspectRatioMode.Stretched);
        _graphBuilder.SetDefaultSyncSource();
        //Log.Info("TSReaderPlayer: set Deinterlace");
        //Log.Info("TSReaderPlayer: done");
        return true;
      }
      catch (Exception ex)
      {
        Log.Error("TSReaderPlayer:exception while creating DShow graph {0} {1}", ex.Message, ex.StackTrace);
        return false;
      }
      finally
      {
        if (comobj != null)
        {
          DirectShowUtil.ReleaseComObject(comobj);
        }
        comobj = null;
      }
    }
Exemplo n.º 9
0
    /// <summary> do cleanup and release DirectShow. </summary>
    protected void CloseInterfaces()
    {
      if (_graphBuilder == null)
      {
        return;
      }
      int hr;
      Log.Debug("BDPlayer: Cleanup DShow graph {0}", GUIGraphicsContext.InVmr9Render);
      try
      {
        BDOSDRenderer.Release();
        
        if (_mediaCtrl != null)
        {
          int counter = 0;
          FilterState state;
          hr = _mediaCtrl.Stop();
          hr = _mediaCtrl.GetState(10, out state);
          while (state != FilterState.Stopped || GUIGraphicsContext.InVmr9Render)
          {
            Thread.Sleep(100);
            hr = _mediaCtrl.GetState(10, out state);
            counter++;
            if (counter >= 30)
            {
              if (state != FilterState.Stopped)
                Log.Error("BDPlayer: graph still running");
              if (GUIGraphicsContext.InVmr9Render)
                Log.Error("BDPlayer: in renderer");
              break;
            }
          }
          _mediaCtrl = null;
        }

        if (_vmr9 != null)
        {
          _vmr9.Enable(false);
        }

        if (_mediaEvt != null)
        {
          hr = _mediaEvt.SetNotifyWindow(IntPtr.Zero, WM_GRAPHNOTIFY, IntPtr.Zero);
          _mediaEvt = null;
        }

        _videoWin = _graphBuilder as IVideoWindow;
        if (_videoWin != null)
        {
          hr = _videoWin.put_Visible(OABool.False);
          hr = _videoWin.put_Owner(IntPtr.Zero);
          _videoWin = null;
        }

        _mediaSeeking = null;
        _basicAudio = null;
        _basicVideo = null;
        _ireader = null;

        #region Cleanup Sebastiii

        if (VideoCodec != null)
        {
          DirectShowUtil.ReleaseComObject(VideoCodec, 5000);
          VideoCodec = null;
          Log.Info("BDPlayer: Cleanup VideoCodec");
        }

        if (AudioCodec != null)
        {
          DirectShowUtil.ReleaseComObject(AudioCodec, 5000);
          AudioCodec = null;
          Log.Info("BDPlayer: Cleanup AudioCodec");
        }

        if (_audioRendererFilter != null)
        {
          while (DirectShowUtil.ReleaseComObject(_audioRendererFilter) > 0) ;
          _audioRendererFilter = null;
          Log.Info("BDPlayer: Cleanup AudioRenderer");
        }

        //Test to ReleaseComObject from PostProcessFilter list objects.
        if (PostProcessFilterVideo.Count > 0)
        {
          foreach (var ppFilter in PostProcessFilterVideo)
          {
            if (ppFilter.Value != null) DirectShowUtil.ReleaseComObject(ppFilter.Value, 5000);
          }
          PostProcessFilterVideo.Clear();
          Log.Info("BDPlayer: Cleanup PostProcessVideo");
        }

        //Test to ReleaseComObject from PostProcessFilter list objects.
        if (PostProcessFilterAudio.Count > 0)
        {
          foreach (var ppFilter in PostProcessFilterAudio)
          {
            if (ppFilter.Value != null) DirectShowUtil.ReleaseComObject(ppFilter.Value, 5000);
          }
          PostProcessFilterAudio.Clear();
          Log.Info("BDPlayer: Cleanup PostProcessAudio");
        }

        #endregion

        if (_interfaceBDReader != null)
        {
          DirectShowUtil.ReleaseComObject(_interfaceBDReader, 5000);
          _interfaceBDReader = null;
        }

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

        if (_dvbSubRenderer != null)
        {
          _dvbSubRenderer.SetPlayer(null);
          _dvbSubRenderer = null;
        }

        if (_vmr9 != null)
        {
          _vmr9.SafeDispose();
          _vmr9 = null;
        }

        GUIGraphicsContext.form.Invalidate(true);
        _state = PlayState.Init;
      }
      catch (Exception ex)
      {
        Log.Error("BDPlayer: Exception while cleaning DShow graph - {0} {1}", ex.Message, ex.StackTrace);
      }
      //switch back to directx windowed mode
      ExclusiveMode(false);
    }
Exemplo n.º 10
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.º 11
0
    private void Cleanup()
    {
      if (graphBuilder == null)
      {
        return;
      }
      int hr;
      Log.Info("RTSPPlayer:cleanup DShow graph");
      try
      {
        if (_mediaCtrl != null)
        {
          int counter = 0;
          FilterState state;
          hr = _mediaCtrl.Stop();
          hr = _mediaCtrl.GetState(10, out state);
          while (state != FilterState.Stopped || GUIGraphicsContext.InVmr9Render)
          {
            Thread.Sleep(100);
            hr = _mediaCtrl.GetState(10, out state);
            counter++;
            if (counter >= 30)
            {
              if (state != FilterState.Stopped)
                Log.Error("RTSPPlayer: graph still running");
              if (GUIGraphicsContext.InVmr9Render)
                Log.Error("RTSPPlayer: in renderer");
              break;
            }
          }
          _mediaCtrl = null;
        }

        if (Vmr9 != null)
        {
          Vmr9.Enable(false);
        }

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

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

        _mediaSeeking = null;
        mediaPos = null;
        basicAudio = null;
        basicVideo = null;
        videoWin = null;
        SubEngine.GetInstance().FreeSubtitles();

        if (graphBuilder != null)
        {
          DirectShowUtil.RemoveFilters(graphBuilder);
          if (_rotEntry != null)
          {
            _rotEntry.SafeDispose();
            _rotEntry = null;
          }
          DirectShowUtil.ReleaseComObject(graphBuilder);
          graphBuilder = null;
        }

        if (Vmr9 != null)
        {
          Vmr9.SafeDispose();
          Vmr9 = null;
        }

        GUIGraphicsContext.form.Invalidate(true);
        _state = PlayState.Init;

        if (_mpegDemux != null)
        {
          Log.Info("cleanup mpegdemux");
          while ((hr = DirectShowUtil.ReleaseComObject(_mpegDemux)) > 0)
          {
            ;
          }
          _mpegDemux = null;
        }
        if (_rtspSource != null)
        {
          Log.Info("cleanup _rtspSource");
          while ((hr = DirectShowUtil.ReleaseComObject(_rtspSource)) > 0)
          {
            ;
          }
          _rtspSource = null;
        }
        if (_subtitleFilter != null)
        {
          while ((hr = DirectShowUtil.ReleaseComObject(_subtitleFilter)) > 0)
          {
            ;
          }
          _subtitleFilter = null;
          if (this.dvbSubRenderer != null)
          {
            this.dvbSubRenderer.SetPlayer(null);
          }
          this.dvbSubRenderer = null;
        }


        if (vobSub != null)
        {
          Log.Info("cleanup vobSub");
          while ((hr = DirectShowUtil.ReleaseComObject(vobSub)) > 0)
          {
            ;
          }
          vobSub = null;
        }
      }
      catch (Exception ex)
      {
        Log.Error("RTSPPlayer: Exception while cleanuping DShow graph - {0} {1}", ex.Message, ex.StackTrace);
      }

      //switch back to directx windowed mode
      Log.Info("RTSPPlayer: Disabling DX9 exclusive mode");
      GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_SWITCH_FULL_WINDOWED, 0, 0, 0, 0, 0, null);
      GUIWindowManager.SendMessage(msg);
    }
    /// <summary> do cleanup and release DirectShow. </summary>
    protected virtual void CloseInterfaces()
    {
      int hr;
      if (_graphBuilder == null)
      {
        Log.Info("StreamBufferPlayer:grapbuilder=null");
        return;
      }

      Log.Info("StreamBufferPlayer:cleanup DShow graph");
      try
      {
        if (_mediaCtrl != null)
        {
          hr = _mediaCtrl.Stop();

          _mediaCtrl = null;
        }

        _state = PlayState.Init;

        _mediaEvt = null;
        _isWindowVisible = false;
        _isVisible = false;
        _videoWin = null;
        _mediaSeeking = null;
        _mediaSeeking2 = null;
        _basicAudio = null;
        _basicVideo = null;
        _bufferSource = null;


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

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

        // FlipGer: release custom filters
        for (int i = 0; i < customFilters.Length; i++)
        {
          if (customFilters[i] != null)
          {
            while ((hr = DirectShowUtil.ReleaseComObject(customFilters[i])) > 0)
            {
              ;
            }
          }
          customFilters[i] = null;
        }
        if (streamConfig2 != null)
        {
          while ((hr = DirectShowUtil.ReleaseComObject(streamConfig2)) > 0)
          {
            ;
          }
          streamConfig2 = null;
        }
        m_StreamBufferConfig = null;

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

        _state = PlayState.Init;
        GUIGraphicsContext.form.Invalidate(true);
      }
      catch (Exception ex)
      {
        Log.Error("StreamBufferPlayer:exception while cleanuping DShow graph {0} {1}", ex.Message, ex.StackTrace);
      }
      //Log.Info("StreamBufferPlayer:cleanup done");
    }
Exemplo n.º 13
0
    public override bool Play(string strFile)
    {
      _endOfFileDetected = false;
      Log.Info("TSReaderPlayer play:{0} radio:{1}", strFile, _isRadio);
      if (strFile.ToLowerInvariant().StartsWith("rtsp:") == false)
      {
        if (!File.Exists(strFile))
        {
          return false;
        }
      }
      Speed = 1;
      iSpeed = 1;
      _speedRate = 10000;
      _isLive = false;
      _duration = -1d;
      if (strFile.ToLowerInvariant().IndexOf(".tsbuffer") >= 0)
      {
        Log.Info("TSReaderPlayer: live tv");
        _isLive = true;
      }
      if (strFile.ToLowerInvariant().IndexOf("rtsp") >= 0)
      {
        Log.Info("TSReaderPlayer: live tv");
        _isLive = true;
      }
      ExclusiveMode(true);
      VideoRendererStatistics.VideoState = VideoRendererStatistics.State.VideoPresent;
      _isVisible = false;
      GUIGraphicsContext.IsWindowVisible = false;
      _volume = 100;
      _state = PlayState.Init;
      _currentFile = strFile;
      _isFullscreen = false;
      _geometry = Geometry.Type.Normal;
      _updateNeeded = true;

      Log.Info("TSReaderPlayer:play {0}", strFile);
      _isStarted = false;
      if (!GetInterfaces(strFile))
      {
        Log.Error("TSReaderPlayer:GetInterfaces() failed");
        _currentFile = "";
        CloseInterfaces();
        ExclusiveMode(false);
        return false;
      }

      _basicVideo = _graphBuilder as IBasicVideo2;
      _videoWin = _graphBuilder as IVideoWindow;

      int hr = _mediaEvt.SetNotifyWindow(GUIGraphicsContext.ActiveForm, WM_GRAPHNOTIFY, IntPtr.Zero);
      if (hr < 0)
      {
        Log.Error("TSReaderPlayer:SetNotifyWindow() failed");
        _currentFile = "";
        CloseInterfaces();
        ExclusiveMode(false);
        return false;
      }

      if (_basicVideo != null)
      {
        hr = _basicVideo.GetVideoSize(out _videoWidth, out _videoHeight);
        if (hr < 0)
        {
          Log.Info("TSReaderPlayer:GetVideoSize() failed");
        }
        Log.Info("TSReaderPlayer:VideoSize:{0}x{1}", _videoWidth, _videoHeight);
      }
      GUIGraphicsContext.VideoSize = new Size(_videoWidth, _videoHeight);
      if (_mediaCtrl == null)
      {
        Log.Error("TSReaderPlayer:_mediaCtrl==null");
        _currentFile = "";
        CloseInterfaces();
        ExclusiveMode(false);
        return false;
      }
      //if (_videoWin != null)
      //{
      //  _videoWin.put_WindowStyle((WindowStyle)((int)WindowStyle.Child + (int)WindowStyle.ClipSiblings + (int)WindowStyle.ClipChildren));
      //  _videoWin.put_MessageDrain(GUIGraphicsContext.form.Handle);
      //}
      if (_isRadio)
      {
        hr = _mediaCtrl.Run();
      }
      else if (VMR9Util.g_vmr9 != null)
      {
        hr = VMR9Util.g_vmr9.StartMediaCtrl(_mediaCtrl);
      }
      if (hr < 0)
      {
        Log.Error("TSReaderPlayer: Unable to start playing");
        _currentFile = "";
        CloseInterfaces();
        ExclusiveMode(false);
        return false;
      }
      //      _interfaceTSReader = _fileSource;
      _startingUp = _isLive;
      GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_PLAYBACK_STARTED, 0, 0, 0, 0, 0, null);
      msg.Label = strFile;
      GUIWindowManager.SendThreadMessage(msg);
      _state = PlayState.Playing;
      _positionX = GUIGraphicsContext.VideoWindow.X;
      _positionY = GUIGraphicsContext.VideoWindow.Y;
      _width = GUIGraphicsContext.VideoWindow.Width;
      _height = GUIGraphicsContext.VideoWindow.Height;
      _geometry = GUIGraphicsContext.ARType;
      _updateNeeded = true;
      SetVideoWindow();
      UpdateCurrentPosition();
      UpdateDuration();
      OnInitialized();
      Log.Info("TSReaderPlayer: position:{0}, duration:{1}", CurrentPosition, Duration);
      return true;
    }
    /// <summary> do cleanup and release DirectShow. </summary>
    protected virtual void CloseInterfaces()
    {
      int hr;
      if (_graphBuilder == null)
      {
        Log.Info("TSReaderPlayer:grapbuilder=null");
        return;
      }
      Log.Info("TSReaderPlayer: Cleanup DShow graph");
      try
      {
        if (_mediaCtrl != null)
        {
          hr = _mediaCtrl.Stop();
          _mediaCtrl = null;
        }
        _state = PlayState.Init;
        _mediaEvt = null;
        _isWindowVisible = false;
        _isVisible = false;
        _videoWin = null;
        _mediaSeeking = null;
        _basicAudio = null;
        _basicVideo = null;

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

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

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

        _state = PlayState.Init;
        GUIGraphicsContext.form.Invalidate(true);
      }
      catch (Exception ex)
      {
        Log.Error("TSReaderPlayer:exception while cleanuping DShow graph {0} {1}", ex.Message, ex.StackTrace);
      }
      Log.Info("TSReaderPlayer:cleanup done");
    }
Exemplo n.º 15
0
    protected bool GetInterfaces(string filename, int titleBD)
    {
      try
      {
        Log.Debug("BDPlayer: GetInterfaces()");

        _graphBuilder = (IGraphBuilder)new FilterGraphNoThread();
        _rotEntry = new DsROTEntry(_graphBuilder as IFilterGraph);

        _basicVideo = _graphBuilder as IBasicVideo2;
        _videoWin = _graphBuilder as IVideoWindow;

        filterConfig = GetFilterConfiguration();

        if (filterConfig.AudioRenderer.Length > 0)
        {
          _audioRendererFilter = DirectShowUtil.AddAudioRendererToGraph(_graphBuilder, filterConfig.AudioRenderer, true);
        }

        BDReader reader = new BDReader();
        _interfaceBDReader = reader as IBaseFilter;
        _ireader = reader as IBDReader;

        if (_interfaceBDReader == null || _ireader == null)
        {
          // todo: add exception
          return false;
        }

        // add the BD reader
        int hr = _graphBuilder.AddFilter(_interfaceBDReader, BD_READER_GRAPH_NAME);
        DsError.ThrowExceptionForHR(hr);

        Log.Debug("BDPlayer: Add BDReader to graph");

        IFileSourceFilter interfaceFile = (IFileSourceFilter)_interfaceBDReader;

        LoadSettings(_ireader);
        _ireader.SetD3DDevice(DirectShowUtil.GetUnmanagedDevice(GUIGraphicsContext.DX9Device));
        _ireader.SetBDReaderCallback(this);

        hr = interfaceFile.Load(filename, null);

        DsError.ThrowExceptionForHR(hr);

        Log.Debug("BDPlayer: BDReader loaded: {0}", filename);

        List<TitleInfo> titles = GetTitleInfoCollection(_ireader);

        while (true)
        {
          if (g_Player.ForcePlay && g_Player.SetResumeBDTitleState < g_Player.BdDefaultTitle)
          {
            if (titles.Count == 1)
            {
              _titleToPlay = 0;
              g_Player.SetResumeBDTitleState = g_Player.BdRemuxTitle;
            }
            else
            {
              _titleToPlay = g_Player.SetResumeBDTitleState;
            }
            _forceTitle = true;
            g_Player.ForcePlay = false;
          }
          else
          {
            if (titles.Count == 1)
            {
              // BD has only one title (remux one)
              _forceTitle = true;
              _titleToPlay = 0;
              g_Player.SetResumeBDTitleState = g_Player.BdRemuxTitle;

              if (g_Player.SetResumeBDTitleState == -1)
              {
                // user cancelled dialog
                titles.Dispose();
                g_Player.Stop();
                return false;
              }
            }
            else
            {
              _titleToPlay = SelectTitle(titles);
              g_Player.SetResumeBDTitleState = _titleToPlay;
              Log.Info("BDPlayer: BDReader _titleToPlay : {0}", _titleToPlay);
              if (_titleToPlay > -1)
              {
                // a specific title was selected
                _forceTitle = true;

                if (g_Player.SetResumeBDTitleState == -1)
                {
                  // user cancelled dialog
                  titles.Dispose();
                  g_Player.Stop();
                  return false;
                }
              }
              else
              {
                if (_titleToPlay == -1)
                {
                  // user cancelled dialog
                  g_Player.Stop();
                  titles.Dispose();
                  return false;
                }

                // user choose to display menu
                _forceTitle = false;
              }
            }
          }

          _ireader.ForceTitleBasedPlayback(_forceTitle, (uint)_titleToPlay);

          Log.Debug("BDPlayer: Starting BDReader");
          eventBuffer.Clear();
          hr = _ireader.Start();
          if (hr != 0)
          {

            if (!_forceTitle)
            {
              Log.Error("BDPlayer: Failed to start file:{0} :0x{1:x}", filename, hr);
              continue;
            }

            Log.Error("BDPlayer: Failed to start in title based mode file:{0} :0x{1:x}", filename, hr);
            titles.Dispose();
            return false;
          }
          else
          {
            Log.Info("BDPlayer: BDReader started");
          }

          break;
        }

        titles.Dispose();

        #region Filters

        Log.Info("BDPlayer: Adding filters");

        _vmr9 = VMR9Util.g_vmr9 = new VMR9Util();
        bool AddVMR9 = VMR9Util.g_vmr9.AddVMR9(_graphBuilder);
        if (!AddVMR9)
        {
          Log.Error("BDPlayer: Failed to add VMR9 to graph");
          return false;
        }
        VMR9Util.g_vmr9.Enable(false);

        // Set VideoDecoder and VC1Override before adding filter in graph
        SetVideoDecoder();
        SetVC1Override();

        // Add preferred video filters
        UpdateFilters("Video");

        // Add preferred audio filters
        UpdateFilters("Audio");

        #endregion

        #region PostProcessingEngine Detection

        IPostProcessingEngine postengine = PostProcessingEngine.GetInstance(true);
        if (!postengine.LoadPostProcessing(_graphBuilder))
        {
          PostProcessingEngine.engine = new PostProcessingEngine.DummyEngine();
        }

        #endregion

        #region render BDReader output pins

        Log.Info("BDPlayer: Render BDReader outputs");

        if (_interfaceBDReader != null)
        {
          DirectShowUtil.RenderGraphBuilderOutputPins(_graphBuilder, _interfaceBDReader);
        }
        
        DirectShowUtil.RemoveUnusedFiltersFromGraph(_graphBuilder);

        #endregion

        _mediaCtrl = (IMediaControl)_graphBuilder;
        _mediaEvt = (IMediaEventEx)_graphBuilder;
        _mediaSeeking = (IMediaSeeking)_graphBuilder;

        //Sync Audio Renderer
        SyncAudioRenderer();

        if (VMR9Util.g_vmr9.IsVMR9Connected)
        {
          VMR9Util.g_vmr9.SetDeinterlaceMode();
        }

        return true;
      }
      catch (Exception ex)
      {
        Log.Error("BDPlayer: Exception while creating DShow graph {0}", ex.Message);
        CloseInterfaces();
        return false;
      }
    }
Exemplo n.º 16
0
    /// <summary> do cleanup and release DirectShow. </summary>
    protected void CloseInterfaces()
    {
      if (_graphBuilder == null)
      {
        return;
      }
      Log.Debug("BDPlayer: Cleanup DShow graph {0}", GUIGraphicsContext.InVmr9Render);
      try
      {
        BDOSDRenderer.StopRendering();

        if (VMR9Util.g_vmr9 != null)
        {
          VMR9Util.g_vmr9.Vmr9MediaCtrl(_mediaCtrl);
          VMR9Util.g_vmr9.Enable(false);
        }

        #region Cleanup

        if (VideoCodec != null)
        {
          DirectShowUtil.FinalReleaseComObject(VideoCodec);
          VideoCodec = null;
          Log.Info("BDPlayer: Cleanup VideoCodec");
        }

        if (AudioCodec != null)
        {
          DirectShowUtil.FinalReleaseComObject(AudioCodec);
          AudioCodec = null;
          Log.Info("BDPlayer: Cleanup AudioCodec");
        }

        if (_audioRendererFilter != null)
        {
          DirectShowUtil.FinalReleaseComObject(_audioRendererFilter);
          _audioRendererFilter = null;
          Log.Info("BDPlayer: Cleanup AudioRenderer");
        }

        //Test to ReleaseComObject from PostProcessFilter list objects.
        if (PostProcessFilterVideo.Count > 0)
        {
          foreach (var ppFilter in PostProcessFilterVideo)
          {
            if (ppFilter.Value != null)
            {
              DirectShowUtil.RemoveFilter(_graphBuilder, ppFilter.Value as IBaseFilter);
              DirectShowUtil.FinalReleaseComObject(ppFilter.Value);
            }
          }
          PostProcessFilterVideo.Clear();
          Log.Info("BDPlayer: Cleanup PostProcessVideo");
        }

        //Test to ReleaseComObject from PostProcessFilter list objects.
        if (PostProcessFilterAudio.Count > 0)
        {
          foreach (var ppFilter in PostProcessFilterAudio)
          {
            if (ppFilter.Value != null)
            {
              DirectShowUtil.RemoveFilter(_graphBuilder, ppFilter.Value as IBaseFilter);
              DirectShowUtil.FinalReleaseComObject(ppFilter.Value);
            }
          }
          PostProcessFilterAudio.Clear();
          Log.Info("BDPlayer: Cleanup PostProcessAudio");
        }

        if (_interfaceBDReader != null)
        {
          DirectShowUtil.FinalReleaseComObject(_interfaceBDReader);
          _interfaceBDReader = null;
        }

        if (VMR9Util.g_vmr9 != null && VMR9Util.g_vmr9._vmr9Filter != null)
        {
          //MadvrInterface.EnableExclusiveMode(false, VMR9Util.g_vmr9._vmr9Filter);
          //DirectShowUtil.DisconnectAllPins(_graphBuilder, VMR9Util.g_vmr9._vmr9Filter);
          Log.Info("BDPlayer: Cleanup VMR9");
        }

        #endregion

        _videoWin = _graphBuilder as IVideoWindow;
        if (_videoWin != null && GUIGraphicsContext.VideoRenderer != GUIGraphicsContext.VideoRendererType.madVR)
        {
          _videoWin.put_Owner(IntPtr.Zero);
          _videoWin.put_Visible(OABool.False);
        }

        if (_mediaEvt != null)
        {
          _mediaEvt.SetNotifyWindow(IntPtr.Zero, WM_GRAPHNOTIFY, IntPtr.Zero);
          _mediaEvt = null;
        }

        if (_graphBuilder != null)
        {
          DirectShowUtil.RemoveFilters(_graphBuilder);
          if (_rotEntry != null)
          {
            _rotEntry.SafeDispose();
            _rotEntry = null;
          }
          DirectShowUtil.FinalReleaseComObject(_graphBuilder);
          _graphBuilder = null;
        }

        if (_videoWin != null)
        {
          DirectShowUtil.FinalReleaseComObject(_videoWin);
        }
        if (_basicVideo != null)
        {
          DirectShowUtil.FinalReleaseComObject(_basicVideo);
        }
        _mediaCtrl = null;
        _mediaSeeking = null;
        _videoWin = null;
        _basicAudio = null;
        _basicVideo = null;
        _ireader = null;

        if (VMR9Util.g_vmr9 != null)
        {
          VMR9Util.g_vmr9.SafeDispose();
          VMR9Util.g_vmr9 = null;
        }

        _state = PlayState.Init;
      }
      catch (Exception ex)
      {
        if (VMR9Util.g_vmr9 != null)
        {
          VMR9Util.g_vmr9.RestoreGuiForMadVr();
        }
        Log.Error("BDPlayer: Exception while cleaning DShow graph - {0} {1}", ex.Message, ex.StackTrace);
      }
      //switch back to directx windowed mode
      ExclusiveMode(false);
    }
Exemplo n.º 17
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.º 18
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.º 19
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.º 20
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.º 21
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.º 22
0
    private void Cleanup()
    {
      if (graphBuilder == null)
      {
        return;
      }
      int hr;
      Log.Info("RTSPPlayer:cleanup DShow graph");
      try
      {
        if (VMR9Util.g_vmr9 != null)
        {
          VMR9Util.g_vmr9.Vmr9MediaCtrl(_mediaCtrl);
          VMR9Util.g_vmr9.Enable(false);
        }

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

        videoWin = graphBuilder as IVideoWindow;
        if (videoWin != null && GUIGraphicsContext.VideoRenderer != GUIGraphicsContext.VideoRendererType.madVR)
        {
          videoWin.put_Owner(IntPtr.Zero);
          videoWin.put_Visible(OABool.False);
        }

        _mediaCtrl = null;
        mediaEvt = null;
        _mediaSeeking = null;
        mediaPos = null;
        basicAudio = null;
        basicVideo = null;
        videoWin = null;
        SubEngine.GetInstance().FreeSubtitles();

        if (graphBuilder != null)
        {
          DirectShowUtil.RemoveFilters(graphBuilder);
          if (_rotEntry != null)
          {
            _rotEntry.SafeDispose();
            _rotEntry = null;
          }
          DirectShowUtil.FinalReleaseComObject(graphBuilder);
          graphBuilder = null;
        }

        if (VMR9Util.g_vmr9 != null)
        {
          VMR9Util.g_vmr9.SafeDispose();
          VMR9Util.g_vmr9 = null;
        }

        GUIGraphicsContext.form.Invalidate(true);
        _state = PlayState.Init;

        if (_mpegDemux != null)
        {
          Log.Info("cleanup mpegdemux");
          DirectShowUtil.FinalReleaseComObject(_mpegDemux);
          _mpegDemux = null;
        }
        if (_rtspSource != null)
        {
          Log.Info("cleanup _rtspSource");
          DirectShowUtil.FinalReleaseComObject(_rtspSource);
          _rtspSource = null;
        }
        if (_subtitleFilter != null)
        {
          DirectShowUtil.FinalReleaseComObject(_subtitleFilter);
          _subtitleFilter = null;
          if (this.dvbSubRenderer != null)
          {
            this.dvbSubRenderer.SetPlayer(null);
          }
          this.dvbSubRenderer = null;
        }


        if (vobSub != null)
        {
          Log.Info("cleanup vobSub");
          DirectShowUtil.FinalReleaseComObject(vobSub);
          vobSub = null;
        }
      }
      catch (Exception ex)
      {
        Log.Error("RTSPPlayer: Exception while cleanuping DShow graph - {0} {1}", ex.Message, ex.StackTrace);
      }

      //switch back to directx windowed mode
      Log.Info("RTSPPlayer: Disabling DX9 exclusive mode");
      GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_SWITCH_FULL_WINDOWED, 0, 0, 0, 0, 0, null);
      GUIWindowManager.SendMessage(msg);
    }
Exemplo n.º 23
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.º 24
0
        private void Cleanup()
        {
            if (graphBuilder == null)
            {
                return;
            }
            int hr;

            Log.Info("RTSPPlayer:cleanup DShow graph");
            try
            {
                if (VMR9Util.g_vmr9 != null)
                {
                    VMR9Util.g_vmr9.Vmr9MediaCtrl(_mediaCtrl);
                    VMR9Util.g_vmr9.Enable(false);
                }

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

                videoWin = graphBuilder as IVideoWindow;
                if (videoWin != null && GUIGraphicsContext.VideoRenderer != GUIGraphicsContext.VideoRendererType.madVR)
                {
                    videoWin.put_Owner(IntPtr.Zero);
                    videoWin.put_Visible(OABool.False);
                }

                _mediaCtrl    = null;
                mediaEvt      = null;
                _mediaSeeking = null;
                mediaPos      = null;
                basicAudio    = null;
                basicVideo    = null;
                videoWin      = null;
                SubEngine.GetInstance().FreeSubtitles();

                if (graphBuilder != null)
                {
                    DirectShowUtil.RemoveFilters(graphBuilder);
                    if (_rotEntry != null)
                    {
                        _rotEntry.SafeDispose();
                        _rotEntry = null;
                    }
                    DirectShowUtil.FinalReleaseComObject(graphBuilder);
                    graphBuilder = null;
                }

                if (VMR9Util.g_vmr9 != null)
                {
                    VMR9Util.g_vmr9.SafeDispose();
                    VMR9Util.g_vmr9 = null;
                }

                GUIGraphicsContext.form.Invalidate(true);
                _state = PlayState.Init;

                if (_mpegDemux != null)
                {
                    Log.Info("cleanup mpegdemux");
                    DirectShowUtil.FinalReleaseComObject(_mpegDemux);
                    _mpegDemux = null;
                }
                if (_rtspSource != null)
                {
                    Log.Info("cleanup _rtspSource");
                    DirectShowUtil.FinalReleaseComObject(_rtspSource);
                    _rtspSource = null;
                }
                if (_subtitleFilter != null)
                {
                    DirectShowUtil.FinalReleaseComObject(_subtitleFilter);
                    _subtitleFilter = null;
                    if (this.dvbSubRenderer != null)
                    {
                        this.dvbSubRenderer.SetPlayer(null);
                    }
                    this.dvbSubRenderer = null;
                }

                if (vobSub != null)
                {
                    Log.Info("cleanup vobSub");
                    DirectShowUtil.FinalReleaseComObject(vobSub);
                    vobSub = null;
                }
            }
            catch (Exception ex)
            {
                if (VMR9Util.g_vmr9 != null)
                {
                    VMR9Util.g_vmr9.RestoreGuiForMadVr();
                    VMR9Util.g_vmr9.SafeDispose();
                }
                Log.Error("RTSPPlayer: Exception while cleanuping DShow graph - {0} {1}", ex.Message, ex.StackTrace);
            }

            //switch back to directx windowed mode
            Log.Info("RTSPPlayer: Disabling DX9 exclusive mode");
            GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_SWITCH_FULL_WINDOWED, 0, 0, 0, 0, 0, null);

            GUIWindowManager.SendMessage(msg);
        }
        private bool AutoRendering(bool wmvAudio)
        {
            try
            {
                // step 1: figure out the renderer of the graph to be removed
                int          hr = graphBuilder.RenderFile(m_strCurrentFile, string.Empty);
                IEnumFilters enumFilters;
                hr = graphBuilder.EnumFilters(out enumFilters);
                do
                {
                    int           ffetched;
                    IBaseFilter[] filters = new IBaseFilter[1];
                    hr = enumFilters.Next(1, filters, out ffetched);
                    if (hr == 0 && ffetched > 0)
                    {
                        IBasicVideo2 localBasicVideo = filters[0] as IBasicVideo2;
                        if (localBasicVideo != null)
                        {
                            graphBuilder.RemoveFilter(filters[0]);
                        }
                        DirectShowUtil.ReleaseComObject(filters[0]);
                    }
                } while (hr == 0);
                DirectShowUtil.ReleaseComObject(enumFilters);

                // switch back to directx fullscreen mode
                Log.Info("VideoPlayerVMR9: Enabling DX9 exclusive mode");
                GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_SWITCH_FULL_WINDOWED, 0, 0, 0, 1, 0, null);
                GUIWindowManager.SendMessage(msg);

                // step 2: add the VMR9 in the graph
                // after enabeling exclusive mode, if done first it causes MediPortal to minimize if for example the "Windows key" is pressed while playing a video
                Vmr9 = new VMR9Util();
                Vmr9.AddVMR9(graphBuilder);
                Vmr9.Enable(false);

                // render
                DirectShowUtil.RenderGraphBuilderOutputPins(graphBuilder, null);

                if (Vmr9 == null || !Vmr9.IsVMR9Connected)
                {
                    Log.Error("VideoPlayer9: Failed to render file -> vmr9");
                    mediaCtrl = null;
                    Cleanup();
                    return(false);
                }

                mediaCtrl      = (IMediaControl)graphBuilder;
                mediaEvt       = (IMediaEventEx)graphBuilder;
                mediaSeek      = (IMediaSeeking)graphBuilder;
                mediaPos       = (IMediaPosition)graphBuilder;
                basicAudio     = (IBasicAudio)graphBuilder;
                videoWin       = (IVideoWindow)graphBuilder;
                m_iVideoWidth  = Vmr9.VideoWidth;
                m_iVideoHeight = Vmr9.VideoHeight;

                Vmr9.SetDeinterlaceMode();
                return(true);
            }
            catch (Exception ex)
            {
                Error.SetError("Unable to play movie", "Unable build graph for VMR9");
                Log.Error("VideoPlayer9: Exception while creating DShow graph {0} {1}", ex.Message, ex.StackTrace);
                Cleanup();
                return(false);
            }
        }