Beispiel #1
0
 /// <summary>
 /// Releases all resources except the reference to IBaseFilter in the PinInfo.
 /// This is because only 1 reference exists in the RCW, so if you were to query the
 /// pin info twice, and release it twice, any future touching of the original
 /// filter would explode.
 /// </summary>
 public void ReleaseExceptingFilter()
 {
     BaseDSGraph.Release(this.Pin);
     if (this.Type != null)
     {
         DsUtils.FreeAMMediaType(this.Type);
         this.Type = null;
     }
     this.Info = default(PinInfo);
 }
Beispiel #2
0
 /// <summary>
 /// Releases all refernces and memory held by this structure
 /// </summary>
 public void Dispose()
 {
     BaseDSGraph.Release(this.Pin);
     DsUtils.FreePinInfo(this.Info);
     if (this.Type != null)
     {
         DsUtils.FreeAMMediaType(this.Type);
         this.Type = null;
     }
 }
Beispiel #3
0
 /// <summary>
 /// Frees all references to IPin in this enumerable collection.
 /// </summary>
 /// <param name="pins"></param>
 public static void Release(this IEnumerable <IPin> pins)
 {
     if (pins != null)
     {
         foreach (IPin p in pins)
         {
             BaseDSGraph.Release(p);
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// Constructs a DetailPinInfo for the specified pin
        /// </summary>
        /// <param name="pin">IPin interface to get info about</param>
        public DetailPinInfo(IPin pin)
        {
            PinInfo pinInfo = new PinInfo();
            int     hr      = pin.QueryPinInfo(out pinInfo);

            DsError.ThrowExceptionForHR(hr);

            IEnumMediaTypes enumMediaTypes;

            hr = pin.EnumMediaTypes(out enumMediaTypes);
            DsError.ThrowExceptionForHR(hr);

            AMMediaType[] curMediaType = new AMMediaType[1];

            IntPtr fetched2 = Marshal.AllocCoTaskMem(4);

            try
            {
                if (enumMediaTypes.Next(1, curMediaType, fetched2) == 0)
                {
                    if (Marshal.ReadInt32(fetched2) != 1)
                    {
                        throw new Exception("Cannot enumerate media types for pin!");
                    }
                }
            }
            finally
            {
                Marshal.FreeCoTaskMem(fetched2);
            }

            this.Pin  = pin;
            this.Info = pinInfo;
            this.Type = curMediaType[0];

            BaseDSGraph.Release(enumMediaTypes);
        }
Beispiel #5
0
        /// <summary>
        /// Retreives detailed information about all pins on a given filter.
        /// Caller must release all returned data. See IEnumerable&lt;DetailPinInfo&gt;.Release()
        /// </summary>
        /// <remarks>
        /// If an exception occurs, it frees all objects that may already be enumerated
        /// </remarks>
        /// <param name="filter">filter to get information about</param>
        public static List <DetailPinInfo> EnumPinsDetails(this IBaseFilter filter)
        {
            List <DetailPinInfo> info = new List <DetailPinInfo>();

            int hr;

            IEnumPins       enumPins;
            IEnumMediaTypes enumMediaTypes = null;

            IPin[]  curPin     = new IPin[1];
            PinInfo curPinInfo = new PinInfo();

            AMMediaType[] curMediaType = new AMMediaType[1];

            hr = filter.EnumPins(out enumPins);
            DsError.ThrowExceptionForHR(hr);
            try
            {
                IntPtr fetched = Marshal.AllocCoTaskMem(4);
                try
                {
                    while (enumPins.Next(curPin.Length, curPin, fetched) == 0)
                    {
                        if (Marshal.ReadInt32(fetched) == 1)
                        {
                            info.Add(new DetailPinInfo(curPin[0]));
                        }
                    }
                }
                finally
                {
                    Marshal.FreeCoTaskMem(fetched);
                }

                return(info);
            }
            catch (Exception ex)
            {
                ErrorLogger.DumpToDebug(ex);
                try
                {
                    BaseDSGraph.Release(curPin[0]);
                    if (curMediaType[0] != null)
                    {
                        DsUtils.FreeAMMediaType(curMediaType[0]);
                    }
                    DsUtils.FreePinInfo(curPinInfo);
                    info.Release();
                }
                catch (Exception cleanUpEx)
                {
                    ErrorLogger.DumpToDebug(cleanUpEx);
                }
                throw;
            }
            finally
            {
                BaseDSGraph.Release(enumPins);
                BaseDSGraph.Release(enumMediaTypes);
            }
        }
Beispiel #6
0
 /// <summary>
 /// Frees reference to this IPin
 /// </summary>
 /// <param name="pin"></param>
 public static void Release(this IPin pin)
 {
     BaseDSGraph.Release(pin);
 }
Beispiel #7
0
 /// <summary>
 /// Decrements the COM reference count on the filter
 /// </summary>
 /// <param name="filter">filter to release</param>
 public static void Release(this IBaseFilter filter)
 {
     BaseDSGraph.Release(filter);
 }