Exemple #1
0
 private void KillGraph()
 {
     if (Graph != null)
     {
         Graph.Dispose();
         Graph = null;
     }
 }
Exemple #2
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);
 }
Exemple #3
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;
     }
 }
Exemple #4
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);
         }
     }
 }
Exemple #5
0
        public static void Stash(string sourceName, BaseDSGraph graph)
        {
            lock (GraphStash)
            {
                if (GraphStash.ContainsKey(sourceName))
                {
                    throw new Exception("graph already stashed for " + sourceName);
                }

                GraphStash[sourceName]    = graph;
                GraphStashAge[sourceName] = DateTime.Now;
            }
        }
Exemple #6
0
        public static BaseDSGraph UnStash(string sourceName)
        {
            lock (GraphStash)
            {
                if (GraphStash.ContainsKey(sourceName))
                {
                    BaseDSGraph graph = GraphStash[sourceName];
                    GraphStash.Remove(sourceName);
                    GraphStashAge.Remove(sourceName);

                    return(graph);
                }
                else
                {
                    return(null);
                }
            }
        }
Exemple #7
0
        private void spawn_Click(object sender, EventArgs e)
        {
            try
            {
                Type t = (Type)cbGraphTypes.SelectedItem;

                KillGraph();
                Graph = (BaseDSGraph)Activator.CreateInstance(t);

                MessageBox.Show(this, "Spawn Successful");
            }
            catch (TargetInvocationException ex)
            {
                if (ex.InnerException != null)
                {
                    MessageBox.Show(this, ex.InnerException.ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message);
            }
        }
Exemple #8
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);
        }
Exemple #9
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);
            }
        }
Exemple #10
0
 /// <summary>
 /// Frees reference to this IPin
 /// </summary>
 /// <param name="pin"></param>
 public static void Release(this IPin pin)
 {
     BaseDSGraph.Release(pin);
 }
Exemple #11
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);
 }