/// <summary> /// Frees all unmanaged memory and resets the object back /// to its initial state /// </summary> protected override void FreeResources() { #if DEBUG /* Remove us from the ROT */ if (m_dsRotEntry != null) { m_dsRotEntry.Dispose(); m_dsRotEntry = null; } #endif /* We run the StopInternal() to avoid any * Dispatcher VeryifyAccess() issues because * this may be called from the GC */ StopInternal(); if (m_graph != null) { DirectShowUtil.RemoveFilters(m_graph); Marshal.ReleaseComObject(m_graph); m_graph = null; base.FreeResources(); /* Only run the media closed if we have an * initialized filter graph */ InvokeMediaClosed(new EventArgs()); } else { base.FreeResources(); } }
private bool DoesItHaveVideo(string filename) { if (string.IsNullOrEmpty(filename)) { return(false); } bool result; IGraphBuilder temp_graph = new FilterGraphNoThread() as IGraphBuilder; try { if (temp_graph == null) { throw new WPFMediaKitException("Could not create a graph"); } var filterGraph = temp_graph as IFilterGraph2; if (filterGraph == null) { throw new WPFMediaKitException("Could not QueryInterface for the IFilterGraph2"); } IBaseFilter sourceFilter; int hr; sourceFilter = DirectShowUtil.AddFilterToGraph(temp_graph, SplitterSource, LAVFilterDirectory, Guid.Empty); if (sourceFilter == null) { throw new WPFMediaKitException("Could not add SplitterSource to graph."); } IFileSourceFilter interfaceFile = (IFileSourceFilter)sourceFilter; hr = interfaceFile.Load(filename, null); DsError.ThrowExceptionForHR(hr); // Set Video Codec // Remove Pin var videoPinFrom = DirectShowLib.DsFindPin.ByName(sourceFilter, "Video"); IPin videoPinTo; if (videoPinFrom != null) { hr = videoPinFrom.ConnectedTo(out videoPinTo); if (hr >= 0 && videoPinTo != null) { PinInfo pInfo; videoPinTo.QueryPinInfo(out pInfo); FilterInfo fInfo; pInfo.filter.QueryFilterInfo(out fInfo); DirectShowUtil.DisconnectAllPins(temp_graph, pInfo.filter); temp_graph.RemoveFilter(pInfo.filter); DsUtils.FreePinInfo(pInfo); Marshal.ReleaseComObject(fInfo.pGraph); Marshal.ReleaseComObject(videoPinTo); videoPinTo = null; } Marshal.ReleaseComObject(videoPinFrom); videoPinFrom = null; result = true; } else { result = false; } DirectShowUtil.RemoveFilters(temp_graph, SplitterSource.Name); Marshal.FinalReleaseComObject(sourceFilter); } catch { result = false; } finally { Marshal.ReleaseComObject(temp_graph); } return(result); }