int IBaseFilter.QueryFilterInfo(out FilterInfo pInfo)
 {
     pInfo.achName = name;
     pInfo.pGraph = filterGraph;
     return S_OK;
 }
    public bool AnalyseStreams()
    {
      try
      {
        if (FStreams == null)
        {
          FStreams = new FilterStreams();
        }
        FStreams.DeleteAllStreams();
        //RETRIEVING THE CURRENT SPLITTER
        string filter;
        IBaseFilter[] foundfilter = new IBaseFilter[2];
        int fetched = 0;
        IEnumFilters enumFilters;
        graphBuilder.EnumFilters(out enumFilters);
        if (enumFilters != null)
        {
          enumFilters.Reset();
          while (enumFilters.Next(1, foundfilter, out fetched) == 0)
          {
            if (foundfilter[0] != null && fetched == 1)
            {
              if (chapters == null)
              {
                IAMExtendedSeeking pEs = foundfilter[0] as IAMExtendedSeeking;
                if (pEs != null)
                {
                  int markerCount = 0;
                  if (pEs.get_MarkerCount(out markerCount) == 0 && markerCount > 0)
                  {
                    chapters = new double[markerCount];
                    chaptersname = new string[markerCount];
                    for (int i = 1; i <= markerCount; i++)
                    {
                      double markerTime = 0;
                      pEs.GetMarkerTime(i, out markerTime);
                      chapters[i - 1] = markerTime;
                      //fill up chapter names
                      string name = null;
                      pEs.GetMarkerName(i, out name);
                      chaptersname[i - 1] = name;
                    }
                  }
                }
              }
              IAMStreamSelect pStrm = foundfilter[0] as IAMStreamSelect;
              if (pStrm != null)
              {
                FilterInfo foundfilterinfos = new FilterInfo();
                foundfilter[0].QueryFilterInfo(out foundfilterinfos);
                filter = foundfilterinfos.achName;
                int cStreams = 0;
                pStrm.Count(out cStreams);
                if (cStreams < 2)
                {
                  continue;
                }
                //GET STREAMS
                for (int istream = 0; istream < cStreams; istream++)
                {
                  AMMediaType sType;
                  AMStreamSelectInfoFlags sFlag;
                  int sPDWGroup, sPLCid;
                  string sName;
                  object pppunk, ppobject;
                  //STREAM INFO
                  pStrm.Info(istream, out sType, out sFlag, out sPLCid,
                             out sPDWGroup, out sName, out pppunk, out ppobject);
                  FilterStreamInfos FSInfos = new FilterStreamInfos();
                  FSInfos.Current = false;
                  FSInfos.Filter = filter;
                  FSInfos.Name = sName;
                  FSInfos.LCID = sPLCid;
                  FSInfos.Id = istream;
                  FSInfos.Type = StreamType.Unknown;
                  //Avoid listing ffdshow video filter's plugins amongst subtitle and audio streams and editions.
                  if ((FSInfos.Filter == "ffdshow DXVA Video Decoder" || FSInfos.Filter == "ffdshow Video Decoder" ||
                       FSInfos.Filter == "ffdshow raw video filter") &&
                      ((sPDWGroup == 1) || (sPDWGroup == 2) || (sPDWGroup == 18) || (sPDWGroup == 4)))
                  {
                    FSInfos.Type = StreamType.Unknown;
                  }
                  //VIDEO
                  else if (sPDWGroup == 0)
                  {
                    FSInfos.Type = StreamType.Video;
                  }
                  //AUDIO
                  else if (sPDWGroup == 1)
                  {
                    FSInfos.Type = StreamType.Audio;
                  }
                  //SUBTITLE
                  else if (sPDWGroup == 2 && sName.LastIndexOf("off") == -1 && sName.LastIndexOf("Hide ") == -1 &&
                           sName.LastIndexOf("No ") == -1 && sName.LastIndexOf("Miscellaneous ") == -1)
                  {
                    FSInfos.Type = StreamType.Subtitle;
                  }
                  //NO SUBTITILE TAG
                  else if ((sPDWGroup == 2 && (sName.LastIndexOf("off") != -1 || sName.LastIndexOf("No ") != -1)) ||
                           (sPDWGroup == 6590033 && sName.LastIndexOf("Hide ") != -1))
                  {
                    FSInfos.Type = StreamType.Subtitle_hidden;
                  }
                  //DirectVobSub SHOW SUBTITLE TAG
                  else if (sPDWGroup == 6590033 && sName.LastIndexOf("Show ") != -1)
                  {
                    FSInfos.Type = StreamType.Subtitle_shown;
                  }
                  //EDITION
                  else if (sPDWGroup == 18)
                  {
                    FSInfos.Type = StreamType.Edition;
                  }
                  else if (sPDWGroup == 4) //Subtitle file
                  {
                    FSInfos.Type = StreamType.Subtitle_file;
                  }
                  else if (sPDWGroup == 10) //Postprocessing filter
                  {
                    FSInfos.Type = StreamType.PostProcessing;
                  }
                  Log.Debug("VideoPlayer: FoundStreams: Type={0}; Name={1}, Filter={2}, Id={3}, PDWGroup={4}, LCID={5}",
                            FSInfos.Type.ToString(), FSInfos.Name, FSInfos.Filter, FSInfos.Id.ToString(),
                            sPDWGroup.ToString(), sPLCid.ToString());

                  switch (FSInfos.Type)
                  {
                    case StreamType.Unknown:
                    case StreamType.Subtitle:
                    case StreamType.Subtitle_file:
                      break;
                    case StreamType.Video:
                    case StreamType.Audio:
                    case StreamType.Edition:
                    case StreamType.PostProcessing:
                      if (FSInfos.Type == StreamType.Audio && FSInfos.Filter == MEDIAPORTAL_AUDIOSWITCHER_FILTER && FSInfos.Name == "Audio " && !AutoRenderingCheck && GetInterface)
                      {
                        FStreams.AddStreamInfosEx(FSInfos);
                        break;
                      }
                      if (FStreams.GetStreamCount(FSInfos.Type) == 0)
                      {
                        FSInfos.Current = true;
                        pStrm.Enable(FSInfos.Id, 0);
                        pStrm.Enable(FSInfos.Id, AMStreamSelectEnableFlags.Enable);
                        /*if (FSInfos.Type == StreamType.Audio && FSInfos.Filter != MEDIAPORTAL_AUDIOSWITCHER_FILTER && GetInterface && !AutoRenderingCheck)
                        {
                          iChangedMediaTypes = 1;
                          //DoGraphRebuild();
                        }*/
                      }
                      goto default;
                    default:
                      FStreams.AddStreamInfos(FSInfos);
                      break;
                  }
                }
              }
              DirectShowUtil.ReleaseComObject(foundfilter[0]);
            }
          }
          DirectShowUtil.ReleaseComObject(enumFilters);
        }
      }
      catch { }
      return true;
    }
 protected void RebuildRelease(PinInfo pInfo, FilterInfo fInfo, IPin pinTo, IPin pPin)
 {
   DsUtils.FreePinInfo(pInfo);
   DirectShowUtil.ReleaseComObject(fInfo.pGraph);
   DirectShowUtil.ReleaseComObject(pinTo);
   pinTo = null;
   DirectShowUtil.ReleaseComObject(pPin);
   pPin = null;
 }
 public static IBaseFilter GetFilterByName(IGraphBuilder graphBuilder, string name)
 {
   int hr = 0;
   IEnumFilters ienumFilt = null;
   IBaseFilter[] foundfilter = new IBaseFilter[2];
   int iFetched = 0;
   try
   {
     hr = graphBuilder.EnumFilters(out ienumFilt);
     if (hr == 0 && ienumFilt != null)
     {
       ienumFilt.Reset();
       do
       {
         hr = ienumFilt.Next(1, foundfilter, out iFetched);
         if (hr == 0 && iFetched == 1)
         {
           FilterInfo filter_infos = new FilterInfo();
           foundfilter[0].QueryFilterInfo(out filter_infos);
           ReleaseComObject(filter_infos.pGraph);
           Log.Debug("GetFilterByName: {0}, {1}", name, filter_infos.achName);
           if (filter_infos.achName.LastIndexOf(name) != -1)
           {
             ReleaseComObject(ienumFilt);
             ienumFilt = null;
             return foundfilter[0];
           }
           ReleaseComObject(foundfilter[0]);
         }
       } while (iFetched == 1 && hr == 0);
       if (ienumFilt != null)
       {
         ReleaseComObject(ienumFilt);
       }
       ienumFilt = null;
     }
   }
   catch (Exception) {}
   finally
   {
     if (ienumFilt != null)
     {
       ReleaseComObject(ienumFilt);
     }
   }
   return null;
 }
        public int Connect(IPin pReceivePin, AMMediaType pmt)
        {
            Monitor.Enter(this);
            int hr = S_OK;
            pin = null;
            pintype = null;
            allocator = null;
            string id = "Unnamed pin";
            pReceivePin.QueryId(out id);
            PinInfo pi = new PinInfo();
            hr = pReceivePin.QueryPinInfo(out pi);
            if (hr == S_OK)
            {
                FilterInfo fi = new FilterInfo();
                hr = pi.filter.QueryFilterInfo(out fi);
                if (hr == S_OK)
                {
                    id += (" (" + fi.achName);
                }
                Guid guid;
                hr = pi.filter.GetClassID(out guid);
                if (hr == S_OK)
                {
                    id += (", " + guid.ToString());
                }
                id += ")";
            }
            try
            {
                AMMediaType amt = null;
                if (pmt != null)
                {
                    amt = pmt;
                }
                else
            #if false
                {
                    IEnumMediaTypes ie;
                    hr = pReceivePin.EnumMediaTypes(out ie);
                    int fetched;
                    int alloc = Marshal.SizeOf(typeof(AMMediaType));
                    IntPtr mtypePtr = Marshal.AllocCoTaskMem(alloc);
                    while (ie.Next(1, mtypePtr, out fetched) == S_OK)
                    {
                        amt = new AMMediaType();
                        Marshal.PtrToStructure(mtypePtr, amt);
                        hr = pReceivePin.QueryAccept(amt);
                        if (hr == S_OK)
                        {
                            break;
                        }
                        DsUtils.FreeAMMediaType(amt);
                        amt = null;
                    }
                    if (fetched == 0)
                    {
                        amt = null;
                    }
                    Marshal.FreeCoTaskMem(mtypePtr);
                }
                if (amt == null)
            #endif
                {
                    amt = mediatype;
                }
                hr = pReceivePin.QueryAccept(amt);
                if (hr == S_FALSE)
                {
                    log.InfoFormat("No media type for pin '{0}'", id);
                    Monitor.Exit(this);
                    return VFW_E_NO_ACCEPTABLE_TYPES;
                }

                hr = pReceivePin.ReceiveConnection(this, amt);
                if (hr == VFW_E_TYPE_NOT_ACCEPTED)
                {
                    log.InfoFormat("No connection to pin '{0}'", id);
                    Monitor.Exit(this);
                    return VFW_E_NO_ACCEPTABLE_TYPES;
                }
                DsError.ThrowExceptionForHR(hr);

                pin = pReceivePin;
                pintype = amt;
            }
            catch (Exception e)
            {
                LogUtil.ExceptionLog.ErrorFormat("Caught exception in connect ({0}): {1}{2}", id, e.Message, e.StackTrace);
                pin = null;
                pintype = null;
                allocator = null;
                Monitor.Exit(this);
                return VFW_E_NO_TRANSPORT;
            }
            Monitor.Exit(this);
            log.InfoFormat("Connected to pin '{0}'", id);
            return S_OK;
        }
 public int QueryFilterInfo(out FilterInfo pInfo)
 {
     pInfo.achName = FILTER_NAME;
     pInfo.pGraph = graph;
     return S_OK;
 }