/// <summary> /// Get a specific PropertyBag value from a moniker /// </summary> /// <param name="sPropName">The name of the value to retrieve</param> /// <returns>String or null on error</returns> public string GetPropBagValue(string sPropName) { IPropertyBag bag = null; string ret = null; object bagObj = null; object val = null; try { Guid bagId = typeof(IPropertyBag).GUID; _moniker.BindToStorage(null, null, ref bagId, out bagObj); bag = (IPropertyBag)bagObj; int hr = bag.Read(sPropName, out val, null); DsError.ThrowExceptionForHR(hr); ret = val as string; } catch { ret = null; } finally { bag = null; if (bagObj != null) { DsUtils.ReleaseComObject(bagObj); bagObj = null; } } return(ret); }
/// <summary> /// Scans a filter's pins looking for a pin with the specified connection status /// </summary> /// <param name="vSource">The filter to scan</param> /// <param name="vStat">The status to find (connected/unconnected)</param> /// <param name="iIndex">Zero based index (ie 2 will return the third pin with the specified status)</param> /// <returns>The matching pin, or null if not found</returns> public static IPin ByConnectionStatus(IBaseFilter vSource, PinConnectedStatus vStat, int iIndex) { int hr; IEnumPins ppEnum; IPin pRet = null; IPin pOutPin; IPin[] pPins = new IPin[1]; if (vSource == null) { return(null); } // Get the pin enumerator hr = vSource.EnumPins(out ppEnum); DsError.ThrowExceptionForHR(hr); try { // Walk the pins looking for a match int fetched; while (ppEnum.Next(1, pPins, out fetched) >= 0 && fetched == 1) { // Read the connected status hr = pPins[0].ConnectedTo(out pOutPin); // Check for VFW_E_NOT_CONNECTED. Anything else is bad. if (hr != DsResults.E_NotConnected) { DsError.ThrowExceptionForHR(hr); // The ConnectedTo call succeeded, release the interface DsUtils.ReleaseComObject(pOutPin); } // Is it the right status? if ((hr == 0 && vStat == PinConnectedStatus.Connected) || (hr == DsResults.E_NotConnected && vStat == PinConnectedStatus.Unconnected)) { // Is is the right index? if (iIndex == 0) { pRet = pPins[0]; break; } iIndex--; } DsUtils.ReleaseComObject(pPins[0]); } } finally { DsUtils.ReleaseComObject(ppEnum); } return(pRet); }
/// <inheritdoc/> public void Dispose() { if (Mon != null) { DsUtils.ReleaseComObject(Mon); _moniker = null; GC.SuppressFinalize(this); } _name = null; }
/// <summary> /// Scans a filter's pins looking for a pin in the specified direction /// </summary> /// <param name="vSource">The filter to scan</param> /// <param name="vDir">The direction to find</param> /// <param name="iIndex">Zero based index (ie 2 will return the third pin in the specified direction)</param> /// <returns>The matching pin, or null if not found</returns> public static IPin ByDirection(IBaseFilter vSource, PinDirection vDir, int iIndex) { int hr; IEnumPins ppEnum; PinDirection ppindir; IPin pRet = null; IPin[] pPins = new IPin[1]; if (vSource == null) { return(null); } // Get the pin enumerator hr = vSource.EnumPins(out ppEnum); DsError.ThrowExceptionForHR(hr); try { // Walk the pins looking for a match int fetched; while (ppEnum.Next(1, pPins, out fetched) >= 0 && (fetched == 1)) { // Read the direction hr = pPins[0].QueryDirection(out ppindir); DsError.ThrowExceptionForHR(hr); // Is it the right direction? if (ppindir == vDir) { // Is is the right index? if (iIndex == 0) { pRet = pPins[0]; break; } iIndex--; } DsUtils.ReleaseComObject(pPins[0]); } } finally { DsUtils.ReleaseComObject(ppEnum); } return(pRet); }
/// <summary> /// Scans a filter's pins looking for a pin with the specified name /// </summary> /// <param name="vSource">The filter to scan</param> /// <param name="vPinName">The pin name to find</param> /// <returns>The matching pin, or null if not found</returns> public static IPin ByName(IBaseFilter vSource, string vPinName) { int hr; IEnumPins ppEnum; PinInfo ppinfo; IPin pRet = null; IPin[] pPins = new IPin[1]; if (vSource == null) { return(null); } // Get the pin enumerator hr = vSource.EnumPins(out ppEnum); DsError.ThrowExceptionForHR(hr); try { // Walk the pins looking for a match int fetched; while (ppEnum.Next(1, pPins, out fetched) >= 0 && fetched == 1) { // Read the info hr = pPins[0].QueryPinInfo(out ppinfo); DsError.ThrowExceptionForHR(hr); // Is it the right name? if (ppinfo.name == vPinName) { DsUtils.FreePinInfo(ppinfo); pRet = pPins[0]; break; } DsUtils.ReleaseComObject(pPins[0]); DsUtils.FreePinInfo(ppinfo); } } finally { DsUtils.ReleaseComObject(ppEnum); } return(pRet); }
/// <summary> /// Scan's a filter's pins looking for a pin with the specified category /// </summary> /// <param name="vSource">The filter to scan</param> /// <param name="guidPinCat">The guid from PinCategory to scan for</param> /// <param name="iIndex">Zero based index (ie 2 will return the third pin of the specified category)</param> /// <returns>The matching pin, or null if not found</returns> public static IPin ByCategory(IBaseFilter vSource, Guid PinCategory, int iIndex) { int hr; IEnumPins ppEnum; IPin pRet = null; IPin[] pPins = new IPin[1]; if (vSource == null) { return(null); } // Get the pin enumerator hr = vSource.EnumPins(out ppEnum); DsError.ThrowExceptionForHR(hr); try { // Walk the pins looking for a match int fetched; while (ppEnum.Next(1, pPins, out fetched) >= 0 && fetched == 1) { // Is it the right category? if (DsUtils.GetPinCategory(pPins[0]) == PinCategory) { // Is is the right index? if (iIndex == 0) { pRet = pPins[0]; break; } iIndex--; } DsUtils.ReleaseComObject(pPins[0]); } } finally { DsUtils.ReleaseComObject(ppEnum); } return(pRet); }
/// <summary> /// Initializes new instance of the <see cref="DsROTEntry"/> with graph /// </summary> /// <param name="graph">The filter graph</param> public DsROTEntry(IFilterGraph graph) { int hr = 0; IRunningObjectTable rot = null; IMoniker mk = null; try { // First, get a pointer to the running object table hr = GetRunningObjectTable(0, out rot); DsError.ThrowExceptionForHR(hr); // Build up the object to add to the table int id = Process.GetCurrentProcess().Id; IntPtr iuPtr = Marshal.GetIUnknownForObject(graph); string s; try { s = iuPtr.ToString("x"); } catch { s = ""; } finally { Marshal.Release(iuPtr); } string item = string.Format("FilterGraph {0} pid {1:x8}", s, id); hr = CreateItemMoniker("!", item, out mk); DsError.ThrowExceptionForHR(hr); // Add the object to the table _cookie = rot.Register((int)ROTFlags.RegistrationKeepsAlive, graph, mk); } finally { DsUtils.ReleaseComObject(mk); DsUtils.ReleaseComObject(rot); } }
/// <inheritdoc/> public void Dispose() { if (_cookie != 0) { GC.SuppressFinalize(this); IRunningObjectTable rot; // Get a pointer to the running object table int hr = GetRunningObjectTable(0, out rot); DsError.ThrowExceptionForHR(hr); try { // Remove our entry rot.Revoke(_cookie); _cookie = 0; } finally { DsUtils.ReleaseComObject(rot); } } }
/// <summary> /// Returns an array of DsDevices of type devcat. /// </summary> /// <param name="filterCategory">Any one of FilterCategory</param> public static DsDevice[] GetDevicesOfCat(Guid filterCategory) { // Use arrayList to build the retun list since it is easily resizable DsDevice[] devret; ArrayList devs = new ArrayList(); IEnumMoniker enumMon; ICreateDevEnum enumDev = (ICreateDevEnum) new CreateDevEnum(); var hr = enumDev.CreateClassEnumerator(filterCategory, out enumMon, 0); DsError.ThrowExceptionForHR(hr); // CreateClassEnumerator returns null for enumMon if there are no entries if (hr != 1) { try { try { IMoniker[] mon = new IMoniker[1]; while ((enumMon.Next(1, mon, IntPtr.Zero) == 0)) { try { // The devs array now owns this object. Don't // release it if we are going to be successfully // returning the devret array devs.Add(new DsDevice(mon[0])); } catch { DsUtils.ReleaseComObject(mon[0]); throw; } } } finally { DsUtils.ReleaseComObject(enumMon); } // Copy the ArrayList to the DsDevice[] devret = new DsDevice[devs.Count]; devs.CopyTo(devret); } catch { foreach (DsDevice d in devs) { d.Dispose(); } throw; } } else { devret = new DsDevice[0]; } return(devret); }