Esempio n. 1
0
            /// <summary>

            /// 指定したフィルタから指定した条件を満たすピンを探し、最初に見つかったピンを返す。
            /// </summary>
            /// <param name="filter">フィルタ</param>
            /// <param name="pred">条件</param>
            /// <returns>最初に見つかったピン</returns>
            public static IPin FindPin(IBaseFilter filter, Predicate <IPin> pred)
            {
                IPin result = null;

                IEnumPins enumerator = null;

                try
                {
                    filter.EnumPins(out enumerator);
                    enumerator.Reset();

                    IPin pin = null;
                    try
                    {
                        while (enumerator.Next(1, out pin, IntPtr.Zero) == S_OK)
                        {
                            if (pin != null)
                            {
                                if (pred(pin))
                                {
                                    result = pin;
                                    pin    = null;
                                    break;
                                }
                                Marshal.ReleaseComObject(pin);
                                pin = null;
                            }
                        }
                    }
                    finally
                    {
                        if (pin != null)
                        {
                            Marshal.ReleaseComObject(pin);
                        }
                    }
                }
                finally
                {
                    if (enumerator != null)
                    {
                        Marshal.ReleaseComObject(enumerator);
                    }
                    enumerator = null;
                }
                return(result);
            }
Esempio n. 2
0
        public void TestReset()
        {
            int hr;

            IPin[] pPins = new IPin[1];

            IEnumPins ppEnum = GetTestEnum();

            hr = ppEnum.Next(1, pPins, IntPtr.Zero);
            DsError.ThrowExceptionForHR(hr);

            hr = ppEnum.Reset();
            DsError.ThrowExceptionForHR(hr);

            hr = ppEnum.Next(1, pPins, IntPtr.Zero);
            DsError.ThrowExceptionForHR(hr);

            Marshal.ReleaseComObject(ppEnum);
        }
Esempio n. 3
0
        /// <inheritdoc />
        public IEnumerable <Pin> GetPins()
        {
            IEnumPins pins = null;

            try
            {
                var hr = Object.EnumPins(out pins);
                DsError.ThrowExceptionForHR(hr);
                hr = pins.Reset();
                DsError.ThrowExceptionForHR(hr);
                var pin = new IPin[1];
                while (pins.Next(1, pin, out _) == 0)
                {
                    yield return(new Pin(pin[0]));
                }
            }
            finally
            {
                if (pins != null)
                {
                    Marshal.ReleaseComObject(pins);
                }
            }
        }
Esempio n. 4
0
        // Tear down everything downstream of a given filter
        public static int NukeDownstream(IFilterGraph graph, IBaseFilter filter)
        {
            if (filter == null)
            {
                return(WinAPI.E_FAIL);
            }

            IEnumPins enumPins = null;

            IPin[] pins = new IPin[1] {
                null
            };

            try
            {
                int hr = filter.EnumPins(out enumPins);
                DsError.ThrowExceptionForHR(hr);
                enumPins.Reset(); // start at the first pin

                while (enumPins.Next(1, pins, IntPtr.Zero) == 0)
                {
                    if (pins[0] != null)
                    {
                        PinDirection pindir;
                        pins[0].QueryDirection(out pindir);
                        if (pindir == PinDirection.Output)
                        {
                            IPin pTo = null;
                            pins[0].ConnectedTo(out pTo);
                            if (pTo != null)
                            {
                                PinInfo pi;
                                hr = pTo.QueryPinInfo(out pi);

                                if (hr == 0)
                                {
                                    NukeDownstream(graph, pi.filter);

                                    graph.Disconnect(pTo);
                                    graph.Disconnect(pins[0]);
                                    graph.RemoveFilter(pi.filter);

                                    Util.ReleaseComObject(ref pi.filter);
                                    DsUtils.FreePinInfo(pi);
                                }
                                Marshal.ReleaseComObject(pTo);
                            }
                        }
                        Marshal.ReleaseComObject(pins[0]);
                    }
                }

                return(0);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
            finally
            {
                Marshal.ReleaseComObject(enumPins);
            }

            return(WinAPI.E_FAIL);
        }