private void SetupGraph(Control hWin) { //streamSource = new UdpSource("127.0.0.1", 2001); streamSource = new UdpSource("224.0.0.1", 2002); //streamSource = new Core.Sources.FileSource("test.ts"); streamSource.PacketLength = Constants.TSPacketSize; streamSource.SearchMethod = TSUtils.TSPacketSearch; streamSource.Configure(); if (!streamSource.Require(10)) { throw new Exception("Source is not ready. No data is received."); } Log.Info("Identify the A/V streams"); var streamInfo = new TStreamInfo(streamSource); streamInfo.Configure(); streamSource.Reset(); filterGraph = new FilterGraph() as IFilterGraph2; Ensure.IsNotNull(Log, filterGraph, "graph is null"); if (filterGraph == null) { return; } var pVideoRender = (IBaseFilter) new VideoRendererDefault(); var hr = filterGraph.AddFilter(pVideoRender, "Video Renderer"); DsError.ThrowExceptionForHR(hr); var pAudioRender = (IBaseFilter) new DSoundRender(); hr = filterGraph.AddFilter(pAudioRender, "Audio Render"); DsError.ThrowExceptionForHR(hr); Log.Info("Configure the directshow graph."); configurator = new GraphConfigurator { Source = streamSource, StreamInfo = streamInfo, Graph = filterGraph, VideoRender = pVideoRender, AudioRender = pAudioRender, VideoGrabber = null, AudioGrabber = null }; configurator.Configure(); var videoWindow = pVideoRender as IVideoWindow; ConfigureVideoWindow(videoWindow, hWin); this.mediaControl = this.filterGraph as IMediaControl; }
private void Close() { lock (lockObject) { if (streamSource != null) { streamSource.Dispose(); streamSource = null; } if (this.configurator != null) { this.configurator.Dispose(); this.configurator = null; } if (this.mediaControl != null) { this.mediaControl.Stop(); this.mediaControl = null; } if (this.filterGraph != null) { ((IMediaEventSink)this.filterGraph).Notify(EventCode.UserAbort, IntPtr.Zero, IntPtr.Zero); Marshal.ReleaseComObject(this.filterGraph); this.filterGraph = null; } } GC.Collect(); }
private void SetupGraph(Control hWin) { //streamSource = new UdpSource("127.0.0.1", 2001); streamSource = new UdpSource("224.0.0.1", 2002); //streamSource = new Core.Sources.FileSource("test.ts"); streamSource.PacketLength = Constants.TSPacketSize; streamSource.SearchMethod = TSUtils.TSPacketSearch; streamSource.Configure(); if (!streamSource.Require(10)) { throw new Exception("Source is not ready. No data is received."); } Log.Info("Identify the A/V streams"); var streamInfo = new TStreamInfo(streamSource); streamInfo.Configure(); streamSource.Reset(); filterGraph = new FilterGraph() as IFilterGraph2; Ensure.IsNotNull(Log, filterGraph, "graph is null"); if (filterGraph == null) return; var pVideoRender = (IBaseFilter)new VideoRendererDefault(); var hr = filterGraph.AddFilter(pVideoRender, "Video Renderer"); DsError.ThrowExceptionForHR(hr); var pAudioRender = (IBaseFilter)new DSoundRender(); hr = filterGraph.AddFilter(pAudioRender, "Audio Render"); DsError.ThrowExceptionForHR(hr); Log.Info("Configure the directshow graph."); configurator = new GraphConfigurator { Source = streamSource, StreamInfo = streamInfo, Graph = filterGraph, VideoRender = pVideoRender, AudioRender = pAudioRender, VideoGrabber = null, AudioGrabber = null }; configurator.Configure(); var videoWindow = pVideoRender as IVideoWindow; ConfigureVideoWindow(videoWindow, hWin); this.mediaControl = this.filterGraph as IMediaControl; }