/// <summary> Retrieve the friendly name of a connectorType. </summary>
        private string GetName(IPin pin)
        {
            string str = "Unknown pin";
            PinInfo pinInfo = new PinInfo();

            // Direction matches, so add pin name to listbox
            int errorCode = pin.QueryPinInfo(out pinInfo);
            if (errorCode == 0)
            {
                str = pinInfo.name ?? "";
            }
            else
            {
                Marshal.ThrowExceptionForHR(errorCode);
            }

            // The pininfo structure contains a reference to an IBaseFilter,
            // so you must release its reference to prevent resource a leak.
            if (pinInfo.filter != null)
            {
                Marshal.ReleaseComObject(pinInfo.filter);
            }
            pinInfo.filter = null;
            return str;
        }
        /// <summary>
        ///  Removes all filters downstream from a filter from the graph.
        ///  This is called only by derenderGraph() to remove everything
        ///  from the graph except the devices and compressors. The parameter
        ///  "removeFirstFilter" is used to keep a compressor (that should
        ///  be immediately downstream of the device) if one is begin used.
        /// </summary>
        protected void removeDownstream(IBaseFilter filter, bool removeFirstFilter)
        {
            // Get a pin enumerator off the filter
            IEnumPins pinEnum;
            int hr = filter.EnumPins(out pinEnum);
            pinEnum.Reset();
            if ((hr == 0) && (pinEnum != null))
            {
                // Loop through each pin
                IPin[] pins = new IPin[1];
                int f;
                do
                {
                    // Get the next pin
                    hr = pinEnum.Next(1, pins, out f);
                    if ((hr == 0) && (pins[0] != null))
                    {
                        // Get the pin it is connected to
                        IPin pinTo = null;
                        pins[0].ConnectedTo(out pinTo);
                        if (pinTo != null)
                        {
                            // Is this an input pin?
                            PinInfo info = new PinInfo();
                            hr = pinTo.QueryPinInfo(out info);
                            if ((hr == 0) && (info.dir == (PinDirection.Input)))
                            {
                                // Recurse down this branch
                                removeDownstream(info.filter, true);

                                // Disconnect
                                graphBuilder.Disconnect(pinTo);
                                graphBuilder.Disconnect(pins[0]);

                                // Remove this filter
                                // but don't remove the video or audio compressors
                                if ((info.filter != videoCompressorFilter) &&
                                    (info.filter != audioCompressorFilter))
                                    graphBuilder.RemoveFilter(info.filter);
                            }
                            Marshal.ReleaseComObject(info.filter);
                            Marshal.ReleaseComObject(pinTo);
                        }
                        Marshal.ReleaseComObject(pins[0]);
                    }
                }
                while (hr == 0);

                Marshal.ReleaseComObject(pinEnum); pinEnum = null;
            }
        }