/// <summary> /// Add or remove DaggerBasePins depending on the IPins in the filter /// </summary> public void SyncPins() { bool altered = false; // get the pins and convert to DaggerBasePins if they dont exisit yet _pins = GetPins(); foreach (IPin pin in _pins) { PinDirection pd; pin.QueryDirection(out pd); if (pd == PinDirection.Input) { if (GetDaggerPin(pin) == null) { DSInputPin inpin = new DSInputPin(pin); InputPins.Add(inpin); altered = true; } } else { if (GetDaggerPin(pin) == null) { DSOutputPin outpin = new DSOutputPin(pin); OutputPins.Add(outpin); altered = true; } } } // remove any DaggerDSPins that may have vanished for (int i = InputPins.Count - 1; i > -1; i--) { if (!_pins.Contains((InputPins[i] as DSInputPin)._pin)) { // force the disconnect InputPins[i].Disconnect(true); Marshal.ReleaseComObject((InputPins[i] as DSInputPin)._pin); (InputPins[i] as DSInputPin)._pin = null; InputPins.Remove(InputPins[i]); altered = true; } // check the major media format of the pin and set it's data type Type majorType = typeof(PinDataTypes.Unknown); bool whoops = false; try { majorType = GetPinMajorMediaType((InputPins[i] as DSInputPin)._pin); } catch { // the pin was removed by directshow, ignore changing the data type whoops = true; } finally { if (!whoops) { if (InputPins[i].DataType != majorType) { InputPins[i].DataType = majorType; altered = true; } } } } for (int i = OutputPins.Count - 1; i > -1; i--) { if (!_pins.Contains((OutputPins[i] as DSOutputPin)._pin)) { // force the disconnect OutputPins[i].Disconnect(true); Marshal.ReleaseComObject((OutputPins[i] as DSOutputPin)._pin); (OutputPins[i] as DSOutputPin)._pin = null; OutputPins.Remove(OutputPins[i]); altered = true; } // check the major media format of the pin and set it's data type Type majorType = typeof(PinDataTypes.Unknown); bool whoops = false; try { majorType = GetPinMajorMediaType((OutputPins[i] as DSOutputPin)._pin); } catch { // the pin was removed by directshow, ignore changing the data type whoops = true; } finally { if (!whoops) { if (OutputPins[i].DataType != majorType) { OutputPins[i].DataType = majorType; altered = true; } } } } // if we altered anything, update the filter's ui elements and redraw the graph if (altered) { if (this.UINode != null) { UINode.CalculateLayout(); if ((UINode as DaggerUINode).Parent != null) { // update the graph ui if the uinode is still part of a uigraph (UINode as DaggerUINode).Parent.Invalidate(); } } } // tell the ui node to update any pin property pages if (UINode != null && UINode is DSFilterNodeUI) { (UINode as DSFilterNodeUI).SyncPinPropertyPages(null); } }