protected void RenderPin(IBaseFilter upFilter, string upPin) { if (FilterGraphTools.RenderPin(_graphBuilder, upFilter, upPin) == false) { throw new Exception("Unable to render " + upPin); } }
public FastVDO() { SetParameters(); _captureFilter = AddFilterByName(FilterCategory.LegacyAmFilterCategory, "FastVDO-SmartCapture QBoxSplitter"); _byteStreamFilter = AddFilterByName(FilterCategory.LegacyAmFilterCategory, "H.264 Byte Stream Transform"); ConnectFilters(_captureFilter, "Video", _byteStreamFilter, "XForm In"); FilterGraphTools.RenderPin(_graphBuilder, _byteStreamFilter, "XForm Out"); }
private void RenderNetDemux() { int hr; IEnumPins enumPins; IPin[] pins = new IPin[1]; hr = _netDmx.EnumPins(out enumPins); DsError.ThrowExceptionForHR(hr); try { while (enumPins.Next(pins.Length, pins, IntPtr.Zero) == 0) { try { PinInfo pinInfo; IPin upstreamPin = pins[0]; hr = upstreamPin.QueryPinInfo(out pinInfo); DsError.ThrowExceptionForHR(hr); Console.WriteLine("rendering pin {0}", pinInfo.name); if (pinInfo.dir == PinDirection.Output) { if (pinInfo.name == "Output 01") { // FilterGraphTools.ConnectFilters(_graphBuilder, _netDmx, pinInfo.name, _textOverlayFilter, "XForm In", true); FilterGraphTools.RenderPin(_graphBuilder, _netDmx, pinInfo.name); // FilterGraphTools.RenderPin(_graphBuilder, _textOverlayFilter, "XForm Out"); } else { FilterGraphTools.RenderPin(_graphBuilder, _netDmx, pinInfo.name); } } } finally { Marshal.ReleaseComObject(pins[0]); } } } finally { Marshal.ReleaseComObject(enumPins); } }
private void BuildAndRunGraph(string url) { graphBuilder = (IGraphBuilder) new FilterGraph(); var sourceBaseFilter = (IBaseFilter) new LAVSplitterSource(); ILAVSplitterSourceSettings sourceSettings = (ILAVSplitterSourceSettings)sourceBaseFilter; var hr = sourceSettings.SetNetworkStreamAnalysisDuration(5000); DsError.ThrowExceptionForHR(hr); hr = graphBuilder.AddFilter(sourceBaseFilter, "Lav splitter source"); DsError.ThrowExceptionForHR(hr); hr = ((IFileSourceFilter)sourceBaseFilter).Load(url, new AMMediaType()); DsError.ThrowExceptionForHR(hr); IBaseFilter decoderBaseFilter; string decoderOutputPinName; if (IsVideoH264(sourceBaseFilter)) { //microsoft decoder decoderBaseFilter = FilterGraphTools.AddFilterFromClsid(graphBuilder, new Guid("{212690FB-83E5-4526-8FD7-74478B7939CD}"), "decoder"); FilterGraphTools.ConnectFilters(graphBuilder, sourceBaseFilter, "Video", decoderBaseFilter, "Video Input", useIntelligentConnect: true); decoderOutputPinName = "Video Output 1"; } else { //lav decoderBaseFilter = FilterGraphTools.AddFilterFromClsid(graphBuilder, new Guid("{EE30215D-164F-4A92-A4EB-9D4C13390F9F}"), "decoder"); FilterGraphTools.ConnectFilters(graphBuilder, sourceBaseFilter, "Video", decoderBaseFilter, "Input", useIntelligentConnect: true); decoderOutputPinName = "Output"; } IBaseFilter pEVR = (IBaseFilter) new EnhancedVideoRenderer(); hr = graphBuilder.AddFilter(pEVR, "Enhanced Video Renderer"); DsError.ThrowExceptionForHR(hr); FilterGraphTools.ConnectFilters(graphBuilder, decoderBaseFilter, decoderOutputPinName, pEVR, "EVR Input0", useIntelligentConnect: true); IMFVideoDisplayControl m_pDisplay; InitializeEVR(pEVR, 1, out m_pDisplay); //render audio from audio splitter if (IsAudioPinPresent(sourceBaseFilter)) { var audioDecoderBaseFilter = FilterGraphTools.AddFilterFromClsid(graphBuilder, new Guid("{E8E73B6B-4CB3-44A4-BE99-4F7BCB96E491}"), "audio decoder"); FilterGraphTools.ConnectFilters(graphBuilder, sourceBaseFilter, "Audio", audioDecoderBaseFilter, "Input", useIntelligentConnect: true); FilterGraphTools.RenderPin(graphBuilder, audioDecoderBaseFilter, "Output"); } mediaControl = (IMediaControl)graphBuilder; mediaEventEx = (IMediaEventEx)graphBuilder; basicVideo = graphBuilder as IBasicVideo; basicAudio = graphBuilder as IBasicAudio; // Have the graph signal event via window callbacks for performance hr = mediaEventEx.SetNotifyWindow(Handle, WMGraphNotify, IntPtr.Zero); DsError.ThrowExceptionForHR(hr); isFullScreen = false; Focus(); hr = mediaControl.Run(); DsError.ThrowExceptionForHR(hr); currentState = PlayState.Running; }
public static VideoInfoHeader2 GetSBEFrameSize(string pathToFile) { int hr = 0; IGraphBuilder graph = null; IBaseFilter capFilter = null; IBaseFilter nRender = null; try { graph = (IGraphBuilder) new FilterGraph(); hr = graph.AddSourceFilter(pathToFile, "Source", out capFilter); DsError.ThrowExceptionForHR(hr); #if DEBUG using (DsROTEntry rot = new DsROTEntry(graph)) { #endif IPin vPin = null; IBaseFilter dec = null; IPin sgIn = null; IBaseFilter mpegDec = null; try { dec = (IBaseFilter) new DTFilter(); hr = graph.AddFilter(dec, "Decrypt"); DsError.ThrowExceptionForHR(hr); nRender = (IBaseFilter) new NullRenderer(); hr = graph.AddFilter((IBaseFilter)nRender, "Video Null Renderer"); DsError.ThrowExceptionForHR(hr); IBaseFilter dec1 = FilterDefinition.AddToFilterGraph(FatAttitude.WTVTranscoder.FilterDefinitions.Decrypt.DTFilterPBDA, ref graph, "Decrypt1"); if (dec1 != null) { Marshal.ReleaseComObject(dec1); } dec1 = null; mpegDec = FilterDefinition.AddToFilterGraph(FatAttitude.WTVTranscoder.FilterDefinitions.Video.VideoDecoderMpeg, ref graph, "MS MPEG Decoder"); sgIn = DsFindPin.ByDirection(mpegDec, PinDirection.Input, 0); IEnumPins ppEnum; IPin[] pPins = new IPin[1]; hr = capFilter.EnumPins(out ppEnum); DsError.ThrowExceptionForHR(hr); try { while (ppEnum.Next(1, pPins, IntPtr.Zero) == 0) { IEnumMediaTypes emtDvr = null; AMMediaType[] amtDvr = new AMMediaType[1]; try { pPins[0].EnumMediaTypes(out emtDvr); hr = emtDvr.Next(1, amtDvr, IntPtr.Zero); DsError.ThrowExceptionForHR(hr); if (amtDvr[0].majorType == MediaType.Video) { if (graph.Connect(pPins[0], sgIn) >= 0) { vPin = pPins[0]; break; } } if (pPins[0] != null) { Marshal.ReleaseComObject(pPins[0]); } } finally { if (emtDvr != null) { Marshal.ReleaseComObject(emtDvr); } DsUtils.FreeAMMediaType(amtDvr[0]); } } } finally { if (ppEnum != null) { Marshal.ReleaseComObject(ppEnum); } } FilterGraphTools.RenderPin(graph, mpegDec, "Video Output 1"); } finally { if (vPin != null) { Marshal.ReleaseComObject(vPin); } if (dec != null) { Marshal.ReleaseComObject(dec); } if (sgIn != null) { Marshal.ReleaseComObject(sgIn); } if (mpegDec != null) { Marshal.ReleaseComObject(mpegDec); } } EventCode ec; IMediaControl mControl = graph as IMediaControl; IMediaEvent mEvent = graph as IMediaEvent; hr = mControl.Pause(); DsError.ThrowExceptionForHR(hr); hr = mControl.Run(); DsError.ThrowExceptionForHR(hr); hr = mEvent.WaitForCompletion(1000, out ec); //DsError.ThrowExceptionForHR(hr); hr = mControl.Pause(); DsError.ThrowExceptionForHR(hr); hr = mControl.Stop(); DsError.ThrowExceptionForHR(hr); IPin mpgOut = null; sgIn = null; AMMediaType mt = new AMMediaType(); try { sgIn = DsFindPin.ByDirection(nRender, PinDirection.Input, 0); if (sgIn != null) { hr = sgIn.ConnectedTo(out mpgOut); DsError.ThrowExceptionForHR(hr); hr = graph.RemoveFilter(nRender); DsError.ThrowExceptionForHR(hr); Marshal.ReleaseComObject(nRender); nRender = null; nRender = (IBaseFilter) new NullRenderer(); hr = graph.AddFilter((IBaseFilter)nRender, "Video Null Renderer"); DsError.ThrowExceptionForHR(hr); hr = graph.Render(mpgOut); DsError.ThrowExceptionForHR(hr); hr = mpgOut.ConnectionMediaType(mt); DsError.ThrowExceptionForHR(hr); if (mt.formatType == FormatType.VideoInfo2) { VideoInfoHeader2 vih = (VideoInfoHeader2)Marshal.PtrToStructure(mt.formatPtr, typeof(VideoInfoHeader2)); return(vih); } } } finally { DsUtils.FreeAMMediaType(mt); if (mpgOut != null) { Marshal.ReleaseComObject(mpgOut); } if (sgIn != null) { Marshal.ReleaseComObject(sgIn); } } #if DEBUG } #endif } finally { if (nRender != null) { Marshal.ReleaseComObject(nRender); } if (capFilter != null) { Marshal.ReleaseComObject(capFilter); } if (graph != null) { while (Marshal.ReleaseComObject(graph) > 0) { ; } } } return(null); }