public static bool ReConnectAll(IGraphBuilder graphBuilder, IBaseFilter filter)
 {
   bool bAllConnected = true;
   IEnumPins pinEnum;
   FilterInfo info;
   filter.QueryFilterInfo(out info);
   ReleaseComObject(info.pGraph);
   int hr = filter.EnumPins(out pinEnum);
   if ((hr == 0) && (pinEnum != null))
   {
     Log.Info("got pins");
     pinEnum.Reset();
     IPin[] pins = new IPin[1];
     int iFetched;
     int iPinNo = 0;
     do
     {
       // Get the next pin
       //Log.Info("  get pin:{0}",iPinNo);
       iPinNo++;
       hr = pinEnum.Next(1, pins, out iFetched);
       if (hr == 0)
       {
         if (iFetched == 1 && pins[0] != null)
         {
           PinInfo pinInfo = new PinInfo();
           hr = pins[0].QueryPinInfo(out pinInfo);
           DsUtils.FreePinInfo(pinInfo);
           if (hr == 0)
           {
             Log.Info("  got pin#{0}:{1}", iPinNo - 1, pinInfo.name);
           }
           else
           {
             Log.Info("  got pin:?");
           }
           PinDirection pinDir;
           pins[0].QueryDirection(out pinDir);
           if (pinDir == PinDirection.Output)
           {
             IPin other;
             hr = pins[0].ConnectedTo(out other);
             if (hr == 0 && other != null)
             {
               Log.Info("Reconnecting {0}:{1}", info.achName, pinInfo.name);
               hr = graphBuilder.Reconnect(pins[0]);
               if (hr != 0)
               {
                 Log.Warn("Reconnect failed: {0}:{1}, code: 0x{2:x}", info.achName, pinInfo.name, hr);
               }
             }
           }
           ReleaseComObject(pins[0]);
         }
         else
         {
           iFetched = 0;
           Log.Info("no pins?");
           break;
         }
       }
       else
       {
         iFetched = 0;
       }
     } while (iFetched == 1);
     ReleaseComObject(pinEnum);
   }
   return bAllConnected;
 }
示例#2
0
        /// <summary>
        /// Reconnects all filters in graph.
        /// </summary>
        /// <param name="graphBuilder">IGraphBuilder</param>
        /// <param name="filter">Current IBaseFilter in graph</param>
        static void ReConnectAll(IGraphBuilder graphBuilder, IBaseFilter filter)
        {
            IEnumPins  pinEnum;
            FilterInfo info       = FilterGraphTools.QueryFilterInfoAndFree(filter);
            IntPtr     ptrFetched = Marshal.AllocCoTaskMem(4);
            int        hr         = filter.EnumPins(out pinEnum);

            if ((hr == 0) && (pinEnum != null))
            {
                ServiceRegistration.Get <ILogger>().Info("got pins");
                IPin[] pins = new IPin[1];
                int    iFetched;
                int    iPinNo = 0;
                do
                {
                    // Get the next pin
                    iPinNo++;
                    hr = pinEnum.Next(1, pins, ptrFetched);

                    // In case of error stop the pin enumeration
                    if (hr != 0)
                    {
                        break;
                    }

                    iFetched = Marshal.ReadInt32(ptrFetched);
                    if (iFetched == 1 && pins[0] != null)
                    {
                        PinInfo pinInfo;
                        hr = pins[0].QueryPinInfo(out pinInfo);
                        if (hr == 0)
                        {
                            ServiceRegistration.Get <ILogger>().Info("  got pin#{0}:{1}", iPinNo - 1, pinInfo.name);
                            FilterGraphTools.FreePinInfo(pinInfo);
                        }
                        else
                        {
                            ServiceRegistration.Get <ILogger>().Info("  got pin:?");
                        }
                        PinDirection pinDir;
                        pins[0].QueryDirection(out pinDir);
                        if (pinDir == PinDirection.Output)
                        {
                            IntPtr other_ptr;
                            hr = pins[0].ConnectedTo(out other_ptr);
                            if (hr == 0 && other_ptr != IntPtr.Zero)
                            {
                                ServiceRegistration.Get <ILogger>().Info("Reconnecting {0}:{1}", info.achName, pinInfo.name);
                                hr = graphBuilder.Reconnect(pins[0]);
                                if (hr != 0)
                                {
                                    ServiceRegistration.Get <ILogger>().Warn("Reconnect failed: {0}:{1}, code: 0x{2:x}", info.achName, pinInfo.name, hr);
                                }
                                IPin    other = Marshal.GetObjectForIUnknown(other_ptr) as IPin;
                                PinInfo otherPinInfo;
                                other.QueryPinInfo(out otherPinInfo);
                                ReConnectAll(graphBuilder, otherPinInfo.filter);
                                FilterGraphTools.FreePinInfo(otherPinInfo);
                                Marshal.ReleaseComObject(other);
                            }
                        }
                        Marshal.ReleaseComObject(pins[0]);
                    }
                    else
                    {
                        ServiceRegistration.Get <ILogger>().Info("no pins?");
                        break;
                    }
                }while (iFetched == 1);
                FilterGraphTools.TryRelease(ref pinEnum);
                Marshal.FreeCoTaskMem(ptrFetched);
            }
        }
示例#3
0
    /// <summary>
    /// Reconnects all filters in graph.
    /// </summary>
    /// <param name="graphBuilder">IGraphBuilder</param>
    /// <param name="filter">Current IBaseFilter in graph</param>
    static void ReConnectAll(IGraphBuilder graphBuilder, IBaseFilter filter)
    {
      IEnumPins pinEnum;
      FilterInfo info = FilterGraphTools.QueryFilterInfoAndFree(filter);
      IntPtr ptrFetched = Marshal.AllocCoTaskMem(4);
      int hr = filter.EnumPins(out pinEnum);
      if ((hr == 0) && (pinEnum != null))
      {
        ServiceRegistration.Get<ILogger>().Info("got pins");
        IPin[] pins = new IPin[1];
        int iFetched;
        int iPinNo = 0;
        do
        {
          // Get the next pin
          iPinNo++;
          hr = pinEnum.Next(1, pins, ptrFetched);

          // In case of error stop the pin enumeration
          if (hr != 0)
            break;

          iFetched = Marshal.ReadInt32(ptrFetched);
          if (iFetched == 1 && pins[0] != null)
          {
            PinInfo pinInfo;
            hr = pins[0].QueryPinInfo(out pinInfo);
            if (hr == 0)
            {
              ServiceRegistration.Get<ILogger>().Info("  got pin#{0}:{1}", iPinNo - 1, pinInfo.name);
              FilterGraphTools.FreePinInfo(pinInfo);
            }
            else
            {
              ServiceRegistration.Get<ILogger>().Info("  got pin:?");
            }
            PinDirection pinDir;
            pins[0].QueryDirection(out pinDir);
            if (pinDir == PinDirection.Output)
            {
              IntPtr other_ptr;
              hr = pins[0].ConnectedTo(out other_ptr);
              if (hr == 0 && other_ptr != IntPtr.Zero)
              {
                ServiceRegistration.Get<ILogger>().Info("Reconnecting {0}:{1}", info.achName, pinInfo.name);
                hr = graphBuilder.Reconnect(pins[0]);
                if (hr != 0)
                  ServiceRegistration.Get<ILogger>().Warn("Reconnect failed: {0}:{1}, code: 0x{2:x}", info.achName, pinInfo.name, hr);
                IPin other = Marshal.GetObjectForIUnknown(other_ptr) as IPin;
                PinInfo otherPinInfo;
                other.QueryPinInfo(out otherPinInfo);
                ReConnectAll(graphBuilder, otherPinInfo.filter);
                FilterGraphTools.FreePinInfo(otherPinInfo);
                Marshal.ReleaseComObject(other);
              }
            }
            Marshal.ReleaseComObject(pins[0]);
          }
          else
          {
            ServiceRegistration.Get<ILogger>().Info("no pins?");
            break;
          }
        }
        while (iFetched == 1);
        FilterGraphTools.TryRelease(ref pinEnum);
        Marshal.FreeCoTaskMem(ptrFetched);
      }
    }