Пример #1
0
    /// <summary> handling the very first start of dvd playback. </summary>
    private bool FirstPlayDvd(string file)
    {
      int hr;

      try
      {
        _pendingCmd = true;
        UpdateMenu();
        CloseInterfaces();
        string path = null;
        _currentFile = file;

        if (Util.VirtualDirectory.IsImageFile(System.IO.Path.GetExtension(file)))
          file = DaemonTools.GetVirtualDrive() + @"\VIDEO_TS\VIDEO_TS.IFO";

        // Cyberlink navigator needs E:\\VIDEO_TS formatted path with double \
        path = file.Replace(@"\\", @"\").Replace(Path.GetFileName(file), "").Replace(@"\", @"\\");

        if (!GetInterfaces(path))
        {
          Log.Error("DVDPlayer:Unable getinterfaces()");
          CloseInterfaces();
          return false;
        }

        using (Settings xmlreader = new MPSettings())
        {
          _defaultAudioLanguage = xmlreader.GetValueAsString("dvdplayer", "audiolanguage", "english");
          _defaultSubtitleLanguage = xmlreader.GetValueAsString("dvdplayer", "subtitlelanguage", "english");
          _forceSubtitles = xmlreader.GetValueAsBool("dvdplayer", "showsubtitles", true);
          _showClosedCaptions = xmlreader.GetValueAsBool("dvdplayer", "showclosedcaptions", false);
        }

        SetDefaultLanguages();

        hr = _mediaEvt.SetNotifyWindow(GUIGraphicsContext.ActiveForm, WM_DVD_EVENT, IntPtr.Zero);
        if (hr != 0)
        {
          Log.Error("DVDPlayer:Unable to SetNotifyWindow 0x{0:X}", hr);
        }

        if (_videoWin != null)
        {
          if (hr == 0)
          {
            hr = _videoWin.put_Owner(GUIGraphicsContext.ActiveForm);
            if (hr != 0)
            {
              Log.Error("DVDPlayer:Unable to set window owner 0x{0:X}", hr);
            }
          }
          if (hr == 0)
          {
            hr = _videoWin.put_WindowStyle((WindowStyle)((int)WindowStyle.Child +
                                                         (int)WindowStyle.ClipChildren + (int)WindowStyle.ClipSiblings));
            if (hr != 0)
            {
              Log.Error("DVDPlayer:Unable to set window style 0x{0:X}", hr);
            }
          }
        }

        if (hr != 0)
        {
          Log.Error("DVDPlayer:Unable to set options()");
          CloseInterfaces();
          return false;
        }
        if (_basicVideo != null)
        {
          _basicVideo.SetDefaultSourcePosition();
          _basicVideo.SetDefaultDestinationPosition();
        }
        if (_videoWin != null)
        {
          _videoWin.SetWindowPosition(0, 0, GUIGraphicsContext.Width, GUIGraphicsContext.Height);
        }

        hr = _mediaCtrl.Run();
        if (hr < 0 || hr > 1)
        {
          HResult hrdebug = new HResult(hr);
          Log.Info(hrdebug.ToDXString());
          Log.Error("DVDPlayer:Unable to start playing() 0x:{0:X}", hr);
          CloseInterfaces();
          return false;
        }
        //DsUtils.DumpFilters(_graphBuilder);

        DvdDiscSide side;
        int titles, numOfVolumes, volume;
        hr = _dvdInfo.GetDVDVolumeInfo(out numOfVolumes, out volume, out side, out titles);
        if (hr < 0)
        {
          Log.Error("DVDPlayer:Unable to get dvdvolumeinfo 0x{0:X}", hr);
          CloseInterfaces();
          return false; // can't read disc
        }
        else
        {
          if (titles <= 0)
          {
            Log.Error("DVDPlayer:DVD does not contain any titles? {0}", titles);
            //return false;
          }
        }

        if (_videoWin != null)
        {
          hr = _videoWin.put_MessageDrain(GUIGraphicsContext.ActiveForm);
        }

        hr = _dvdCtrl.SelectVideoModePreference(_videoPref);
        DvdVideoAttributes videoAttr;
        hr = _dvdInfo.GetCurrentVideoAttributes(out videoAttr);
        _videoWidth = videoAttr.sourceResolutionX;
        _videoHeight = videoAttr.sourceResolutionY;

        _state = PlayState.Playing;
        VMR9Util.g_vmr9.EVRSetDVDMenuState(false);

        _pendingCmd = false;
        Log.Info("DVDPlayer:Started playing()");
        if (_currentFile == string.Empty)
        {
          for (int i = 0; i <= 26; ++i)
          {
            string dvd = String.Format("{0}:", (char)('A' + i));
            if (Util.Utils.IsDVD(dvd))
            {
              _currentFile = String.Format(@"{0}:\VIDEO_TS\VIDEO_TS.IFO", (char)('A' + i));
              if (File.Exists(_currentFile))
              {
                break;
              }
            }
          }
        }
        return true;
      }
      catch (Exception ex)
      {
        Log.Error("DVDPlayer:Could not start DVD:{0} {1} {2}", ex.Message, ex.Source, ex.StackTrace);
        CloseInterfaces();
        return false;
      }
    }
Пример #2
0
    public static IBaseFilter AddAudioRendererToGraph(IGraphBuilder graphBuilder, string strFilterName,
                                                      bool setAsReferenceClock)
    {
      try
      {
        IPin pinOut = null;
        IBaseFilter NewFilter = null;
        IEnumFilters enumFilters;
        HResult hr = new HResult(graphBuilder.EnumFilters(out enumFilters));
        Log.Info("DirectShowUtils: First try to insert new audio renderer {0} ", strFilterName);
        // next add the new one...
        foreach (Filter filter in Filters.AudioRenderers)
        {
          if (String.Compare(filter.Name, strFilterName, true) == 0)
          {
            Log.Info("DirectShowUtils: Found audio renderer");
            NewFilter = (IBaseFilter)Marshal.BindToMoniker(filter.MonikerString);
            hr.Set(graphBuilder.AddFilter(NewFilter, strFilterName));
            if (hr < 0)
            {
              Log.Error("DirectShowUtils: unable to add filter:{0} to graph", strFilterName);
              NewFilter = null;
            }
            else
            {
              Log.Debug("DirectShowUtils: added filter:{0} to graph", strFilterName);
              if (pinOut != null)
              {
                hr.Set(graphBuilder.Render(pinOut));
                if (hr == 0)
                {
                  Log.Info(" pinout rendererd");
                }
                else
                {
                  Log.Error(" failed: pinout render");
                }
              }
              if (setAsReferenceClock)
              {
                hr.Set((graphBuilder as IMediaFilter).SetSyncSource(NewFilter as IReferenceClock));
                if (hr != 0)
                {
                  Log.Warn("setAsReferenceClock sync source " + hr.ToDXString());
                }
              }
              return NewFilter;
            }
          } //if (String.Compare(filter.Name,strFilterName,true) ==0)
        } //foreach (Filter filter in filters.AudioRenderers)
        if (NewFilter == null)
        {
          Log.Error("DirectShowUtils: failed filter {0} not found", strFilterName);
        }
      }
      catch {}
      Log.Info("DirectShowUtils: First try to insert new audio renderer {0} failed ", strFilterName);

      try
      {
        IPin pinOut = null;
        IBaseFilter NewFilter = null;
        Log.Info("add filter:{0} to graph clock:{1}", strFilterName, setAsReferenceClock);

        //check first if audio renderer exists!
        bool bRendererExists = false;
        foreach (Filter filter in Filters.AudioRenderers)
        {
          if (String.Compare(filter.Name, strFilterName, true) == 0)
          {
            bRendererExists = true;
            Log.Info("DirectShowUtils: found renderer - {0}", filter.Name);
          }
        }
        if (!bRendererExists)
        {
          Log.Error("FAILED: audio renderer:{0} doesnt exists", strFilterName);
          return null;
        }

        // first remove all audio renderers
        bool bAllRemoved = false;
        bool bNeedAdd = true;
        IEnumFilters enumFilters;
        HResult hr = new HResult(graphBuilder.EnumFilters(out enumFilters));

        if (hr >= 0 && enumFilters != null)
        {
          int iFetched;
          enumFilters.Reset();
          while (!bAllRemoved)
          {
            IBaseFilter[] pBasefilter = new IBaseFilter[2];
            hr.Set(enumFilters.Next(1, pBasefilter, out iFetched));
            if (hr < 0 || iFetched != 1 || pBasefilter[0] == null)
            {
              break;
            }

            foreach (Filter filter in Filters.AudioRenderers)
            {
              Guid classId1;
              Guid classId2;

              pBasefilter[0].GetClassID(out classId1);
              //Log.Info("Filter Moniker string -  " + filter.Name);
              if (filter.Name == "ReClock Audio Renderer")
              {
                Log.Warn(
                  "Reclock is installed - if this method fails, reinstall and regsvr32 /u reclock and then uninstall");
                //   return null;
              }

              try
              {
                NewFilter = (IBaseFilter)Marshal.BindToMoniker(filter.MonikerString);
                if (NewFilter == null)
                {
                  Log.Info("NewFilter = null");
                  continue;
                }
              }
              catch (Exception e)
              {
                Log.Info("Exception in BindToMoniker({0}): {1}", filter.MonikerString, e.Message);
                continue;
              }
              NewFilter.GetClassID(out classId2);
              ReleaseComObject(NewFilter);
              NewFilter = null;

              if (classId1.Equals(classId2))
              {
                if (filter.Name == strFilterName)
                {
                  Log.Info("filter already in graph");

                  if (setAsReferenceClock)
                  {
                    hr.Set((graphBuilder as IMediaFilter).SetSyncSource(pBasefilter[0] as IReferenceClock));
                    if (hr != 0)
                    {
                      Log.Warn("setAsReferenceClock sync source " + hr.ToDXString());
                    }
                  }
                  ReleaseComObject(pBasefilter[0]);
                  pBasefilter[0] = null;
                  bNeedAdd = false;
                  break;
                }
                else
                {
                  Log.Info("remove " + filter.Name + " from graph");
                  pinOut = FindSourcePinOf(pBasefilter[0]);
                  graphBuilder.RemoveFilter(pBasefilter[0]);
                  bAllRemoved = true;
                  break;
                }
              } //if (classId1.Equals(classId2))
            } //foreach (Filter filter in filters.AudioRenderers)
            if (pBasefilter[0] != null)
            {
              ReleaseComObject(pBasefilter[0]);
            }
          } //while(!bAllRemoved)
          ReleaseComObject(enumFilters);
        } //if (hr>=0 && enumFilters!=null)
        Log.Info("DirectShowUtils: Passed removing audio renderer");
        if (!bNeedAdd)
        {
          return null;
        }
        // next add the new one...
        foreach (Filter filter in Filters.AudioRenderers)
        {
          if (String.Compare(filter.Name, strFilterName, true) == 0)
          {
            Log.Info("DirectShowUtils: Passed finding Audio Renderer");
            NewFilter = (IBaseFilter)Marshal.BindToMoniker(filter.MonikerString);
            hr.Set(graphBuilder.AddFilter(NewFilter, strFilterName));
            if (hr < 0)
            {
              Log.Error("failed:unable to add filter:{0} to graph", strFilterName);
              NewFilter = null;
            }
            else
            {
              Log.Debug("added filter:{0} to graph", strFilterName);
              if (pinOut != null)
              {
                hr.Set(graphBuilder.Render(pinOut));
                if (hr == 0)
                {
                  Log.Info(" pinout rendererd");
                }
                else
                {
                  Log.Error(" failed: pinout render");
                }
              }
              if (setAsReferenceClock)
              {
                hr.Set((graphBuilder as IMediaFilter).SetSyncSource(NewFilter as IReferenceClock));
                if (hr != 0)
                {
                  Log.Warn("setAsReferenceClock sync source " + hr.ToDXString());
                }
              }
              return NewFilter;
            }
          } //if (String.Compare(filter.Name,strFilterName,true) ==0)
        } //foreach (Filter filter in filters.AudioRenderers)
        if (NewFilter == null)
        {
          Log.Error("failed filter:{0} not found", strFilterName);
        }
      }
      catch (Exception ex)
      {
        Log.Error("DirectshowUtil. Failed to add filter:{0} to graph :{1} {2} {3}",
                  strFilterName, ex.Message, ex.Source, ex.StackTrace);
      }
      return null;
    }