public FVDO2FCNSink() { fastVDO = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, "FastVDO-SmartCapture QBoxSplitter"); fcsink = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, "FC Network Sink"); FilterGraphTools.ConnectFilters(_graphBuilder, fastVDO, "Video", fcsink, "Input 1", false); }
/// <summary> /// Performs the network connection /// </summary> public void Connect() { try { StatusError = null; this.Status = NetworkSourceStatus.Connecting; Debug.WriteLine("LTNetworkSource add filters"); AddLTNetSource(); AddLTNetDemux(); this.Status = NetworkSourceStatus.Buffering; Debug.WriteLine("LTNetworkSource.DoConnect"); DoConnect(ltsfUrl); FilterGraphTools.ConnectFilters(graph, netSource, "Output", netDemux, "Input 01", false); Debug.WriteLine("LTNetworkSource create controller"); controller = (IGMFBridgeController) new GMFBridgeControllerClass(); Debug.WriteLine("LTNetworkSource.RenderNetDemux"); RenderNetDemux(); Debug.WriteLine("LTNetworkSource done constructing"); this.Status = NetworkSourceStatus.Connected; } catch (Exception ex) { StatusError = ex; this.Status = NetworkSourceStatus.Faulted; throw ex; } }
public FVDO2FCNSink() { fastVDO = FilterGraphTools.AddFilterByName(graph, FilterCategory.LegacyAmFilterCategory, "FastVDO-SmartCapture QBoxSplitter"); fcsink = FilterGraphTools.AddFilterByName(graph, FilterCategory.LegacyAmFilterCategory, "FC Network Sink"); FilterGraphTools.ConnectFilters(graph, fastVDO, "Video", fcsink, "Input 1", false); FCNSinkProxy p = new FCNSinkProxy(fcsink); UInt16 basePort = 5000; for (int i = 0; i < p.StreamCount; i++) { p.Interface.SetPortAllocation(i, basePort, 0); basePort += 2; } List <RTPStreamDescription> streams = p.Streams; //System.Diagnostics.Debug.WriteLine("streams.Count"); //XmlSerializer s = new XmlSerializer(typeof(RTPStreamDescription)); //MemoryStream mem = new MemoryStream(); //s.Serialize(mem, streams[0]); }
/// <summary> /// Connects the last filter in the audio chain to the audio volume filter (if AddAudioVolumeFilter has been called), and then /// to the audio renderer /// </summary> /// <remarks> /// First call AddAudioRenderer() /// </remarks> /// <param name="audioOutPin">the audio output pin</param> /// <param name="useIntelligentConnect">true to use intelligent connect, false to not</param> protected void ConnectToAudio(IPin audioOutPin, bool useIntelligentConnect) { IPin connectToRenderPin; if (_audioVolumeFilter != null) { IPin avfIn = DsFindPin.ByName(_audioVolumeFilter, _audioVolumeFilterIn); ConnectFilters(audioOutPin, avfIn, useIntelligentConnect); connectToRenderPin = DsFindPin.ByName(_audioVolumeFilter, _audioVolumeFilterOut); } else { connectToRenderPin = audioOutPin; } IPin renderInputPin = null; try { renderInputPin = DsFindPin.ByDirection(_audioRender, PinDirection.Input, 0); if (renderInputPin != null) { FilterGraphTools.ConnectFilters(_graphBuilder, connectToRenderPin, renderInputPin, useIntelligentConnect); } } finally { ReleaseComObject(renderInputPin); } }
public void Connect(Pin outpin, Pin inpin, bool intelligent) { try { FilterGraphTools.ConnectFilters(graphBuilder, outpin.IPin, inpin.IPin, intelligent); } catch (COMException e) { ShowCOMException(e, "Can't connect pins"); return; } catch (Exception e) { MessageBox.Show(e.Message, "Exception caught while connecting pins"); return; } if (intelligent) { ReloadGraph(); } else { Connect(outpin, inpin); history.CommitAdded(); inpin.Filter.ReloadPins(); outpin.Filter.ReloadPins(); } }
public void RenderToWavDest( string outputFile, IBaseFilter audioCompressor, AMMediaType mediaType, IDESCombineCB audioCallback) { if (audioCompressor != null) { _dc.Add(audioCompressor); } int hr; if (_firstAudioGroup == null) { throw new SplicerException("No audio stream to render"); } if (outputFile == null) { throw new SplicerException("Output file name cannot be null"); } // Contains useful routines for creating the graph ICaptureGraphBuilder2 icgb = (ICaptureGraphBuilder2) new CaptureGraphBuilder2(); _dc.Add(icgb); try { hr = icgb.SetFiltergraph(_graph); DESError.ThrowExceptionForHR(hr); IBaseFilter wavDestFilter = StandardFilters.RenderWavDest(_dc, _graph); IBaseFilter fileSink = StandardFilters.RenderFileDestination(_dc, _graph, outputFile); try { RenderGroups(icgb, audioCompressor, null, wavDestFilter, audioCallback, null); FilterGraphTools.ConnectFilters(_graph, wavDestFilter, fileSink, true); // if supplied, apply the media type to the filter if (mediaType != null) { FilterGraphTools.SetFilterFormat(mediaType, audioCompressor); } } finally { Marshal.ReleaseComObject(wavDestFilter); Marshal.ReleaseComObject(fileSink); } } finally { Marshal.ReleaseComObject(icgb); } }
/// <summary> /// Determines what streams are available on the Net Demux. /// Creates channels in the GMF Bridge controller accordingly. /// Then, creates the GMF Bridge Sink, and connects the streams to their respective pins. /// </summary> private void RenderNetDemux() { List <DetailPinInfo> pins = null; try { //fetch all pins on this filter pins = netDemux.EnumPinsDetails(); //create list of pins we care about List <IPin> demuxPins = new List <IPin>(); //get output pins of type video or audio foreach (DetailPinInfo i in pins) { if (i.Info.dir == PinDirection.Output) { if (i.Type.majorType == MediaType.Video) { controller.AddStream(1, eFormatType.eAny, 1); demuxPins.Add(i.Pin); } else if (i.Type.majorType == MediaType.Audio) { controller.AddStream(0, eFormatType.eAny, 1); demuxPins.Add(i.Pin); } } } //create GMF Sink output = (IBaseFilter)controller.InsertSinkFilter(graph); //connect Demux to GMF Sink for (int i = 0; i < demuxPins.Count; i++) { IPin sinkPin; int hr = output.FindPin("Input " + (i + 1).ToString(), out sinkPin); if (hr == 0) { FilterGraphTools.ConnectFilters(graph, demuxPins[i], sinkPin, false); Marshal.ReleaseComObject(sinkPin); } } } catch (Exception ex) { Release(output); output = null; throw ex; } finally { if (pins != null) { pins.Release(); } } }
public FCNSource2VMR() { source = FilterGraphTools.AddFilterByName(graph, FilterCategory.LegacyAmFilterCategory, "FC Network Source"); xform = FilterGraphTools.AddFilterByName(graph, FilterCategory.LegacyAmFilterCategory, "H.264 Byte Stream Transform"); dec = FilterGraphTools.AddFilterByName(graph, FilterCategory.LegacyAmFilterCategory, "LEAD H264 Decoder (3.0)"); vmr = FilterGraphTools.AddFilterByDevicePath(graph, @"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\{6BC1CFFA-8FC1-4261-AC22-CFB4CC38DB50}", "VMR7"); FilterGraphTools.ConnectFilters(graph, source, "Output 1", xform, "XForm In", false); FilterGraphTools.ConnectFilters(graph, xform, "XForm Out", dec, "XForm In", false); FilterGraphTools.ConnectFilters(graph, dec, "XForm Out", vmr, "VMR Input0", false); }
/// <summary> /// Attach this graph to a source /// </summary> /// <param name="source">the source sub graph</param> public void SetSource(ISourceSubGraph source) { Debug.WriteLine("LTNetworkSink.SetSource: " + source.GetType().ToString()); List <DetailPinInfo> pins = null; try { netMux = (IBaseFilter) new LMNetMuxClass(); graph.AddFilter(netMux, @"LEAD Network Multiplexer (2.0)"); lmNetMux = (LMNetMux)netMux; lmNetMux.LiveSource = this.LiveSource; Debug.WriteLine(String.Format("LiveSource={0}", lmNetMux.LiveSource)); lmNetMux.MaxQueueDuration = this.MaxQueueDuration; netSnk = (IBaseFilter) new LMNetSnkClass(); graph.AddFilter(netSnk, "LEAD Network Sink (2.0)"); InitializeNetworkSink(); input = (IBaseFilter)source.Controller.InsertSourceFilter(source.Output, this.graph); pins = input.EnumPinsDetails(); int muxInputNumber = 1; foreach (DetailPinInfo i in pins) { IPin muxPin = null; try { muxPin = DsFindPin.ByName(netMux, "Input " + muxInputNumber.ToString("D2")); FilterGraphTools.ConnectFilters(this.graph, i.Pin, muxPin, false); } finally { if (muxPin != null) { muxPin.Release(); } } muxInputNumber++; } FilterGraphTools.ConnectFilters(this.graph, netMux, "Output 01", netSnk, "Input", false); } finally { if (pins != null) { pins.Release(); } } }
/// <summary> /// Common routine used by RenderTo* /// </summary> /// <param name="icgb">ICaptureGraphBuilder2 to use</param> /// <param name="pCallback">Callback to use (or null)</param> /// <param name="sType">string to use in creating filter graph object descriptions</param> /// <param name="pPin">Pin to connect from</param> /// <param name="ibfCompressor">Compressor to use, or null for none</param> /// <param name="pOutput">Endpoint (renderer or file writer) to connect to</param> protected void RenderHelper(ICaptureGraphBuilder2 icgb, CallbackHandler pCallback, string sType, IPin pPin, IBaseFilter ibfCompressor, IBaseFilter pOutput) { int hr; IBaseFilter ibfSampleGrabber = null; try { // If no callback was provided, don't create a samplegrabber if (pCallback != null) { ISampleGrabber isg = (ISampleGrabber) new SampleGrabber(); ibfSampleGrabber = (IBaseFilter)isg; _dc.Add(ibfSampleGrabber); hr = isg.SetCallback(pCallback, 1); DESError.ThrowExceptionForHR(hr); hr = _graph.AddFilter(ibfSampleGrabber, sType + " sample grabber"); DESError.ThrowExceptionForHR(hr); } // If a compressor was provided, add it to the graph and connect it up if (ibfCompressor != null) { // Connect the pin. hr = _graph.AddFilter(ibfCompressor, sType + " Compressor"); DESError.ThrowExceptionForHR(hr); FilterGraphTools.ConnectFilters(_graph, pPin, ibfSampleGrabber, true); FilterGraphTools.ConnectFilters(_graph, ibfSampleGrabber, ibfCompressor, true); FilterGraphTools.ConnectFilters(_graph, ibfCompressor, pOutput, true); } else { // Just connect the SampleGrabber (if any) hr = icgb.RenderStream(null, null, pPin, ibfSampleGrabber, pOutput); DESError.ThrowExceptionForHR(hr); } } finally { if (ibfSampleGrabber != null) { Marshal.ReleaseComObject(ibfSampleGrabber); } } }
public static IBaseFilter CreateAudioCompressor(DisposalCleanup dc, IGraphBuilder graph, IPin outPin, AudioFormat settings) { if (dc == null) { throw new ArgumentNullException("dc"); } if (graph == null) { throw new ArgumentNullException("graph"); } if (outPin == null) { throw new ArgumentNullException("outPin"); } if (settings == null) { throw new ArgumentNullException("settings"); } int hr = 0; using (AudioCompressor compressor = AudioCompressorFactory.Create(settings)) { IBaseFilter compressorFilter = compressor.Filter; dc.Add(compressorFilter); hr = graph.AddFilter(compressorFilter, settings.AudioCompressor); DsError.ThrowExceptionForHR(hr); FilterGraphTools.ConnectFilters(graph, outPin, compressorFilter, true); // set the media type on the output pin of the compressor if (compressor.MediaType != null) { FilterGraphTools.SetFilterFormat(compressor.MediaType, compressorFilter); } return(compressorFilter); } }
/// <summary> /// Sets the source for this graph /// </summary> /// <param name="source">source sub graph</param> public void SetSource(ISourceSubGraph source) { Debug.WriteLine("OggWriter.SetSource: " + source.GetType().ToString()); List <DetailPinInfo> pins = null; try { input = (IBaseFilter)source.Controller.InsertSourceFilter(source.Output, this.graph); pins = input.EnumPinsDetails(); int oggStreamCounter = 0; foreach (DetailPinInfo i in pins) { if (i.Info.dir == PinDirection.Output) { IPin destPin = DsFindPin.ByName(oggMux, "Stream " + oggStreamCounter.ToString()); if (destPin != null) { FilterGraphTools.ConnectFilters(this.graph, i.Pin, destPin, false); Release(destPin); oggStreamCounter++; } } } FilterGraphTools.ConnectFilters(this.graph, oggMux, "Ogg Stream", fileWriter, "in", false); } finally { if (pins != null) { pins.Release(); } } }
private void Construct(bool compressVideo) { this.Output = (IBaseFilter)this.Controller.InsertSinkFilter(this.graph); bouncingBall = FilterGraphTools.AddFilterByDevicePath(this.graph, @"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\{8D234572-35E6-495D-98AE-9A36856C49C8}", "Bouncing Ball"); if (compressVideo) { videoEncoder = FilterGraphTools.AddFilterByName(this.graph, FilterCategory.VideoCompressorCategory, "LEAD H264 Encoder (4.0)"); h264Encoder = (LMH264Encoder)videoEncoder; h264Encoder.EnableRateControl = true; h264Encoder.EnableSuperCompression = false; h264Encoder.BitRate = 10000; h264Encoder.FrameRate = -1; h264Encoder.EncodingSpeed = eH264ENCODINGSPEED.H264SPEED_1; h264Encoder.EncodingThreads = eH264ENCODINGTHREADS.H264THREAD_AUTO; FilterGraphTools.ConnectFilters(this.graph, bouncingBall, "A Bouncing Ball!", videoEncoder, "XForm In", false); FilterGraphTools.ConnectFilters(this.graph, videoEncoder, "XForm Out", this.Output, "Input 1", false); } else { FilterGraphTools.ConnectFilters(this.graph, bouncingBall, "A Bouncing Ball!", this.Output, "Input 1", false); } }
DSStreamResultCodes InitWithStreamBufferFile(WTVStreamingVideoRequest strq) { // Init variables //IPin[] pin = new IPin[1]; IBaseFilter DecFilterAudio = null; IBaseFilter DecFilterVideo = null; IBaseFilter MainAudioDecoder = null; IBaseFilter MainVideoDecoder = null; string dPin = string.Empty; string sName = string.Empty; string dName = string.Empty; string sPin = string.Empty; FileInfo fiInputFile = new FileInfo(strq.FileName); string txtOutputFNPath = fiInputFile.FullName + ".wmv"; if ( (!fiInputFile.Extension.ToLowerInvariant().Equals(".wtv")) && (!fiInputFile.Extension.ToLowerInvariant().Equals(".dvr-ms")) ) { return(DSStreamResultCodes.ErrorInvalidFileType); } int hr = 0; try { // Get the graphbuilder interface SendDebugMessage("Creating Graph Object", 0); IGraphBuilder graphbuilder = (IGraphBuilder)currentFilterGraph; // Add the DVRMS/WTV file / filter to the graph SendDebugMessage("Add SBE Source Filter", 0); hr = graphbuilder.AddSourceFilter(fiInputFile.FullName, "SBE Filter", out currentSBEfilter); // class variable DsError.ThrowExceptionForHR(hr); dc.Add(currentSBEfilter); // Get the SBE audio and video out pins IPin SBEVidOutPin, SBEAudOutPin; SBEAudOutPin = FilterGraphTools.FindPinByMediaType(currentSBEfilter, PinDirection.Output, MediaType.Audio, MediaSubType.Null); SBEVidOutPin = FilterGraphTools.FindPinByMediaType(currentSBEfilter, PinDirection.Output, MediaType.Video, MediaSubType.Null); // Set up two decrypt filters according to file extension (assume audio and video both present ) if (fiInputFile.Extension.ToLowerInvariant().Equals(".dvr-ms")) { // Add DVR-MS decrypt filters SendDebugMessage("Add DVRMS (bda) decryption", 0); DecFilterAudio = (IBaseFilter) new DTFilter(); // THESE ARE FOR DVR-MS (BDA DTFilters) DecFilterVideo = (IBaseFilter) new DTFilter(); graphbuilder.AddFilter(DecFilterAudio, "Decrypt / Tag"); graphbuilder.AddFilter(DecFilterVideo, "Decrypt / Tag 0001"); } else // Add WTV decrypt filters { SendDebugMessage("Add WTV (pbda) decryption", 0); DecFilterAudio = FilterDefinition.AddToFilterGraph(FilterDefinitions.Decrypt.DTFilterPBDA, ref graphbuilder); DecFilterVideo = FilterDefinition.AddToFilterGraph(FilterDefinitions.Decrypt.DTFilterPBDA, ref graphbuilder, "PBDA DTFilter 0001"); } dc.Add(DecFilterAudio); dc.Add(DecFilterVideo); // Make the first link in the graph: SBE => Decrypts SendDebugMessage("Connect SBE => Decrypt filters", 0); IPin DecVideoInPin = DsFindPin.ByDirection(DecFilterVideo, PinDirection.Input, 0); FilterGraphTools.ConnectFilters(graphbuilder, SBEVidOutPin, DecVideoInPin, false); IPin DecAudioInPin = DsFindPin.ByDirection(DecFilterAudio, PinDirection.Input, 0); if (DecAudioInPin == null) { SendDebugMessage("WARNING: No Audio Input to decrypt filter."); } else { FilterGraphTools.ConnectFilters(graphbuilder, SBEAudOutPin, DecAudioInPin, false); } // Get Dec Audio Out pin IPin DecAudioOutPin = DsFindPin.ByDirection(DecFilterAudio, PinDirection.Output, 0); // Examine Dec Audio out for audio format SendDebugMessage("Examining source audio", 0); AMMediaType AudioMediaType = null; getPinMediaType(DecAudioOutPin, MediaType.Audio, Guid.Empty, Guid.Empty, ref AudioMediaType); SendDebugMessage("Audio media subtype: " + AudioMediaType.subType.ToString()); SendDebugMessage("Examining Audio StreamInfo"); StreamInfo si = FileInformation.GetStreamInfo(AudioMediaType); bool AudioIsAC3 = (si.SimpleType == "AC-3"); if (AudioIsAC3) { SendDebugMessage("Audio type is AC3"); } else { SendDebugMessage("Audio type is not AC3"); } si = null; DsUtils.FreeAMMediaType(AudioMediaType); // Add an appropriate audio decoder if (AudioIsAC3) { if (!FilterGraphTools.IsThisComObjectInstalled(FilterDefinitions.Audio.AudioDecoderMPCHC.CLSID)) { SendDebugMessage("Missing AC3 Audio Decoder, and AC3 audio detected."); return(DSStreamResultCodes.ErrorAC3CodecNotFound); } else { MainAudioDecoder = FilterDefinition.AddToFilterGraph(FilterDefinitions.Audio.AudioDecoderMPCHC, ref graphbuilder); //MainAudioDecoder = FatAttitude.WTVTranscoder.FilterDefinitions.Audio.AudioDecoderFFDShow.AddToFilterGraph(ref graph); Guid tmpGuid; MainAudioDecoder.GetClassID(out tmpGuid); SendDebugMessage("Main Audio decoder CLSID is " + tmpGuid.ToString()); } } else { MainAudioDecoder = FilterDefinition.AddToFilterGraph(FilterDefinitions.Audio.AudioDecoderMSDTV, ref graphbuilder); } // Add a video decoder SendDebugMessage("Add DTV decoder", 0); MainVideoDecoder = FilterDefinition.AddToFilterGraph(FilterDefinitions.Video.VideoDecoderMSDTV, ref graphbuilder); dc.Add(MainAudioDecoder); dc.Add(MainVideoDecoder); //SetAudioDecoderOutputToPCMStereo(MainAudioDecoder); // Add a null renderer SendDebugMessage("Add null renderer", 0); NullRenderer MyNullRenderer = new NullRenderer(); dc.Add(MyNullRenderer); hr = graphbuilder.AddFilter((IBaseFilter)MyNullRenderer, @"Null Renderer"); DsError.ThrowExceptionForHR(hr); // Link up video through to null renderer SendDebugMessage("Connect video to null renderer", 0); // Make the second link: Decrypts => DTV IPin DecVideoOutPin = DsFindPin.ByDirection(DecFilterVideo, PinDirection.Output, 0); IPin DTVVideoInPin = DsFindPin.ByName(MainVideoDecoder, @"Video Input"); // IPin DTVVideoInPin = DsFindPin.ByDirection(DTVVideoDecoder, PinDirection.Input, 0); // first one should be video input? // FilterGraphTools.ConnectFilters(graphbuilder, DecVideoOutPin, DTVVideoInPin, false); // 3. DTV => Null renderer IPin NullRInPin = DsFindPin.ByDirection((IBaseFilter)MyNullRenderer, PinDirection.Input, 0); IPin DTVVideoOutPin = FilterGraphTools.FindPinByMediaType(MainVideoDecoder, PinDirection.Output, MediaType.Video, MediaSubType.Null); FilterGraphTools.ConnectFilters(graphbuilder, DTVVideoOutPin, NullRInPin, false); Marshal.ReleaseComObject(NullRInPin); NullRInPin = null; // Run graph [can use this also to get media type => see, e.g. dvrmstowmvhd by Babgvant] SendDebugMessage("Run graph for testing purposes", 0); IMediaControl tempControl = (IMediaControl)graphbuilder; IMediaEvent tempEvent = (IMediaEvent)graphbuilder; DsError.ThrowExceptionForHR(tempControl.Pause()); DsError.ThrowExceptionForHR(tempControl.Run()); EventCode pEventCode; hr = tempEvent.WaitForCompletion(1000, out pEventCode); //DsError.ThrowExceptionForHR(hr); // DO *NOT* DO THIS HERE! THERE MAY WELL BE AN ERROR DUE TO EVENTS RAISED BY THE STREAM BUFFER ENGINE, THIS IS A DELIBERATE TEST RUN OF THE GRAPH // Stop graph if necessary FilterState pFS; hr = tempControl.GetState(1000, out pFS); if (pFS == FilterState.Running) { DsError.ThrowExceptionForHR(tempControl.Stop()); } // Remove null renderer hr = graphbuilder.RemoveFilter((IBaseFilter)MyNullRenderer); // Now graph has been run and stopped we can get the video width and height from the output pin of the main video decoder AMMediaType pmt = null; getPinMediaType(DTVVideoOutPin, MediaType.Video, MediaSubType.YUY2, Guid.Empty, ref pmt); FrameSize SourceFrameSize; if (pmt.formatType == FormatType.VideoInfo2) { VideoInfoHeader2 pvih2 = new VideoInfoHeader2(); Marshal.PtrToStructure(pmt.formatPtr, pvih2); int VideoWidth = pvih2.BmiHeader.Width; int VideoHeight = pvih2.BmiHeader.Height; SourceFrameSize = new FrameSize(VideoWidth, VideoHeight); } else { SourceFrameSize = new FrameSize(320, 240); } // Free up DsUtils.FreeAMMediaType(pmt); pmt = null; // Link up audio // 2. Audio Decrypt -> Audio decoder IPin MainAudioInPin = DsFindPin.ByDirection(MainAudioDecoder, PinDirection.Input, 0); FilterGraphTools.ConnectFilters(graphbuilder, DecAudioOutPin, MainAudioInPin, false); // Add ASF Writer // Create an ASF writer filter SendDebugMessage("Creating ASF Writer", 0); WMAsfWriter asf_filter = new WMAsfWriter(); dc.Add(asf_filter); // CHECK FOR ERRORS currentOutputFilter = (IBaseFilter)asf_filter; // class variable // Add the ASF filter to the graph hr = graphbuilder.AddFilter((IBaseFilter)asf_filter, "WM Asf Writer"); DsError.ThrowExceptionForHR(hr); // Set the filename IFileSinkFilter sinkFilter = (IFileSinkFilter)asf_filter; string destPathFN = fiInputFile.FullName + ".wmv"; hr = sinkFilter.SetFileName(destPathFN, null); DsError.ThrowExceptionForHR(hr); // Make the final links: DTV => writer SendDebugMessage("Linking audio/video through to decoder and writer", 0); IPin DTVAudioOutPin = DsFindPin.ByDirection(MainAudioDecoder, PinDirection.Output, 0); IPin ASFAudioInputPin = FilterGraphTools.FindPinByMediaType((IBaseFilter)asf_filter, PinDirection.Input, MediaType.Audio, MediaSubType.Null); IPin ASFVideoInputPin = FilterGraphTools.FindPinByMediaType((IBaseFilter)asf_filter, PinDirection.Input, MediaType.Video, MediaSubType.Null); FilterGraphTools.ConnectFilters(graphbuilder, DTVAudioOutPin, ASFAudioInputPin, false); if (ASFVideoInputPin != null) { FilterGraphTools.ConnectFilters(graphbuilder, DTVVideoOutPin, ASFVideoInputPin, false); } // Configure ASFWriter ConfigureASFWriter(asf_filter, strq, SourceFrameSize); // Release pins SendDebugMessage("Releasing COM objects (pins)", 0); // dec Marshal.ReleaseComObject(DecAudioInPin); DecAudioInPin = null; Marshal.ReleaseComObject(DecVideoInPin); DecVideoInPin = null; Marshal.ReleaseComObject(DecVideoOutPin); DecVideoOutPin = null; Marshal.ReleaseComObject(DecAudioOutPin); DecAudioOutPin = null; // dtv Marshal.ReleaseComObject(MainAudioInPin); MainAudioInPin = null; Marshal.ReleaseComObject(DTVVideoInPin); DTVVideoInPin = null; Marshal.ReleaseComObject(DTVVideoOutPin); DTVVideoOutPin = null; Marshal.ReleaseComObject(DTVAudioOutPin); DTVAudioOutPin = null; // asf Marshal.ReleaseComObject(ASFAudioInputPin); ASFAudioInputPin = null; Marshal.ReleaseComObject(ASFVideoInputPin); ASFVideoInputPin = null; } catch (Exception ex) { SendDebugMessageWithException(ex.Message, ex); return(DSStreamResultCodes.ErrorExceptionOccurred); } return(DSStreamResultCodes.OK); }
public void ConnectFilters(IBaseFilter upFilter, string upPin, IBaseFilter downFilter, string downPin) { FilterGraphTools.ConnectFilters(_graphBuilder, upFilter, upPin, downFilter, downPin, true); }
protected void ConnectFilters(IPin upPin, IPin downPin, bool useIntelligentConnect) { FilterGraphTools.ConnectFilters(_graphBuilder, upPin, downPin, useIntelligentConnect); }
protected void ConnectFilters(IBaseFilter upFilter, string upPin, IBaseFilter downFilter, string downPin, bool useIntelligentConnect) { FilterGraphTools.ConnectFilters(_graphBuilder, upFilter, upPin, downFilter, downPin, useIntelligentConnect); }
public WinTV418ATSC(StreamSourceInfo sourceConfig, OpenGraphRequest openGraphRequest) : base(sourceConfig, openGraphRequest) { if (SourceConfig.TVTuner == null) { throw new SourceConfigException("TVTuner config section not found!"); } _deviceIndex = sourceConfig.TVTuner.DeviceIndex; tuningSpace = GetTuningSpace(); Guid networkType; tuningSpace.get__NetworkType(out networkType); if (networkType.Equals(Guid.Empty)) { throw new Exception("Not a digital Network Type!"); } networkProvider = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(networkType)); int hr = _graphBuilder.AddFilter(networkProvider, "Network Provider"); DsError.ThrowExceptionForHR(hr); tuner = (ITuner)networkProvider; //add MPEG2 Demux mpeg2Demux = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, "MPEG-2 Demultiplexer"); //add BDA MPEG-2 Transport Information Filter bdaTransportInfo = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.BDATransportInformationRenderersCategory, "BDA MPEG2 Transport Information Filter"); //add MPEG-2 Sections and Tables Filter mpeg2SectionsAndTables = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.BDATransportInformationRenderersCategory, "MPEG-2 Sections and Tables"); //tunerFilter = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.BDASourceFiltersCategory, "Hauppauge WinTV 418 BDA Tuner"); DsDevice tunerDevice = FindDevice(FilterCategory.BDASourceFiltersCategory, "Hauppauge WinTV 418 BDA Tuner"); tunerFilter = FilterGraphTools.AddFilterByDevicePath(_graphBuilder, tunerDevice.DevicePath, tunerDevice.Name); //captureFilter = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.BDAReceiverComponentsCategory, "Hauppauge WinTV 418 TS Capture"); DsDevice captureDevice = FindDevice(FilterCategory.BDAReceiverComponentsCategory, "Hauppauge WinTV 418 TS Capture"); captureFilter = FilterGraphTools.AddFilterByDevicePath(_graphBuilder, captureDevice.DevicePath, captureDevice.Name); //connect network provider to BDA tuner ConnectFilters(networkProvider, "Antenna Out", (IBaseFilter)tunerFilter, "Input0", false); ConnectFilters((IBaseFilter)tunerFilter, "MPEG2 Transport", captureFilter, "MPEG2 Transport", false); //These filters need to be connected via their explicit pins, // because Hauppauge saw fit to name all the pins on the capture filter the same name. IPin captureFilterOut = DsFindPin.ByDirection(captureFilter, PinDirection.Output, 0); IPin mpeg2DemuxIn = DsFindPin.ByDirection(mpeg2Demux, PinDirection.Input, 0); FilterGraphTools.ConnectFilters(_graphBuilder, captureFilterOut, mpeg2DemuxIn, false); //clean up the two pins Marshal.ReleaseComObject(captureFilterOut); Marshal.ReleaseComObject(mpeg2DemuxIn); //add and connect meta data filters and connect them to the Demux ConnectFilters(mpeg2Demux, "1", bdaTransportInfo, "Input", false); ConnectFilters(mpeg2Demux, "5", mpeg2SectionsAndTables, "In", false); //this interface must be queried after the S&T filter has been connected. mpeg2Data = (IMpeg2Data)mpeg2SectionsAndTables; _vctParser = new Parser(mpeg2Data); //build out the rest of the graph for the given source config / profile BuildForProfile(); ConnectNetMuxToNetSnk(); if (KnownChannels.Count > 0) { this.Channel = KnownChannels.Items[0]; } SaveGraphFile("WinTV418ATSC.grf"); }
protected void RenderHelper(ICaptureGraphBuilder2 graphBuilder, ISampleGrabberCB callback, string typeName, IPin pin, IBaseFilter compressor, IBaseFilter destination) { if (graphBuilder == null) { throw new ArgumentNullException(GraphBuilderParameterName); } if (pin == null) { throw new ArgumentNullException(PinParameterName); } if (destination == null) { throw new ArgumentNullException(DestinationParameterName); } int hr; IBaseFilter ibfSampleGrabber = null; try { // If no callback was provided, don't create a samplegrabber if (callback != null) { var isg = (ISampleGrabber) new SampleGrabber(); ibfSampleGrabber = (IBaseFilter)isg; _cleanup.Add(ibfSampleGrabber); hr = isg.SetCallback(callback, 1); DESError.ThrowExceptionForHR(hr); hr = Graph.AddFilter(ibfSampleGrabber, typeName + " sample grabber"); DESError.ThrowExceptionForHR(hr); } // If a compressor was provided, add it to the graph and connect it up if (compressor != null) { // Connect the pin. hr = Graph.AddFilter(compressor, typeName + " Compressor"); DESError.ThrowExceptionForHR(hr); FilterGraphTools.ConnectFilters(Graph, pin, ibfSampleGrabber, true); FilterGraphTools.ConnectFilters(Graph, ibfSampleGrabber, compressor, true); FilterGraphTools.ConnectFilters(Graph, compressor, destination, true); } else { // Just connect the SampleGrabber (if any) hr = graphBuilder.RenderStream(null, null, pin, ibfSampleGrabber, destination); DESError.ThrowExceptionForHR(hr); } } finally { if (ibfSampleGrabber != null) { Marshal.ReleaseComObject(ibfSampleGrabber); } } }
private void ConnectStreamBufferSourceFilter() { IBaseFilter videoDecoder = this.H264DecoderDevice == null ? this.videoMpeg2DecoderFilter : this.videoH264DecoderFilter; //this.streamBufferSource as IStreamBufferConfigure IPin videoDvrOut = null, videoDecoderIn = null; try { videoDvrOut = DsFindPin.ByDirection(this.streamBufferSource, PinDirection.Output, 1); //TODO Create output pin for the StreamBufferSource videoDecoderIn = DsFindPin.ByDirection(videoDecoder, PinDirection.Input, 0); //AMMediaType mediaH264 = new AMMediaType(); //mediaH264.majorType = MediaType.Video; //mediaH264.subType = new Guid(0x8d2d71cb, 0x243f, 0x45e3, 0xb2, 0xd8, 0x5f, 0xd7, 0x96, 0x7e, 0xc0, 0x9b); //mediaH264.sampleSize = 0; //mediaH264.temporalCompression = false; //mediaH264.fixedSizeSamples = false; //mediaH264.unkPtr = IntPtr.Zero; //mediaH264.formatType = FormatType.Mpeg2Video; //MPEG2VideoInfo videoH264PinFormat = GetVideoH264PinFormat(); //mediaH264.formatSize = Marshal.SizeOf(videoH264PinFormat); //mediaH264.formatPtr = Marshal.AllocHGlobal(mediaH264.formatSize); //Marshal.StructureToPtr(videoH264PinFormat, mediaH264.formatPtr, false); ////int hr = videoDvrOut.Connect(videoDecoderIn, mediaH264); //int hr = videoDecoderIn.Connect(videoDvrOut, mediaH264); //Marshal.FreeHGlobal(mediaH264.formatPtr); //DsError.ThrowExceptionForHR(hr); //if (this.H264DecoderDevice != null) //{ // AMMediaType mediaH264 = new AMMediaType(); // mediaH264.majorType = MediaType.Video; // //mediaH264.subType = new Guid(0x8d2d71cb, 0x243f, 0x45e3, 0xb2, 0xd8, 0x5f, 0xd7, 0x96, 0x7e, 0xc0, 0x9b); // mediaH264.subType = new Guid(0x34363248, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71); // mediaH264.sampleSize = 0; // mediaH264.temporalCompression = true; // false; // mediaH264.fixedSizeSamples = true; // false; // mediaH264.unkPtr = IntPtr.Zero; // mediaH264.formatType = FormatType.Mpeg2Video; // MPEG2VideoInfo videoH264PinFormat = GetVideoH264PinFormat(); // mediaH264.formatSize = Marshal.SizeOf(videoH264PinFormat); // mediaH264.formatPtr = Marshal.AllocHGlobal(mediaH264.formatSize); // Marshal.StructureToPtr(videoH264PinFormat, mediaH264.formatPtr, false); // //IPin pinDemuxerVideoH264; // //int hr = mpeg2Demultiplexer.CreateOutputPin(mediaH264, "H264", out pinDemuxerVideoH264); // //if (pinDemuxerVideoH264 != null) // //Marshal.ReleaseComObject(pinDemuxerVideoH264); // int hr = this.graphBuilder2.ConnectDirect(videoDvrOut, videoDecoderIn, mediaH264); // //hr = this.graphBuilder2.Connect(videoDvrOut, videoDecoderIn); // DsError.ThrowExceptionForHR(hr); // Marshal.FreeHGlobal(mediaH264.formatPtr); //} //else FilterGraphTools.ConnectFilters(this.graphBuilder2, videoDvrOut, videoDecoderIn, false); //int hr = this.graphBuilder2.Render(videoDvrOut); // H264 video stream cannot connect to H264 decoder (Cyberlink)!!! } finally { if (videoDvrOut != null) { Marshal.ReleaseComObject(videoDvrOut); } if (videoDecoderIn != null) { Marshal.ReleaseComObject(videoDecoderIn); } } IPin videoDecoderOut = null, videoVMRIn = null; try { videoDecoderOut = DsFindPin.ByDirection(videoDecoder, PinDirection.Output, 0); videoVMRIn = DsFindPin.ByDirection(this.videoRenderer, PinDirection.Input, 0); FilterGraphTools.ConnectFilters(this.graphBuilder2, videoDecoderOut, videoVMRIn, false); } finally { if (videoDecoderOut != null) { Marshal.ReleaseComObject(videoDecoderOut); } if (videoVMRIn != null) { Marshal.ReleaseComObject(videoVMRIn); } } IPin audioDvrOut = null, audioRendererIn = null; try { audioDvrOut = DsFindPin.ByDirection(this.streamBufferSource, PinDirection.Output, 0); audioRendererIn = DsFindPin.ByDirection(this.audioRenderer, PinDirection.Input, 0); FilterGraphTools.ConnectFilters(this.graphBuilder2, audioDvrOut, audioRendererIn, true); } finally { if (audioDvrOut != null) { Marshal.ReleaseComObject(audioDvrOut); } if (audioRendererIn != null) { Marshal.ReleaseComObject(audioRendererIn); } } }
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; }
protected void ConnectFilters(IBaseFilter upFilter, string upPin, IBaseFilter downFilter, string downPin) { FilterGraphTools.ConnectFilters(_graphBuilder, upFilter, upPin, downFilter, downPin, false); }
private void RenderToWavDest( string outputFile, IBaseFilter audioCompressor, AMMediaType mediaType, ICallbackParticipant[] audioParticipants) { if (audioCompressor != null) { Cleanup.Add(audioCompressor); } int hr; if (FirstAudioGroup == null) { throw new SplicerException(Resources.ErrorNoAudioStreamToRender); } if (outputFile == null) { throw new SplicerException(Resources.ErrorInvalidOutputFileName); } // Contains useful routines for creating the graph var graphBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2(); Cleanup.Add(graphBuilder); try { hr = graphBuilder.SetFiltergraph(Graph); DESError.ThrowExceptionForHR(hr); IBaseFilter wavDestFilter = StandardFilters.RenderWavDestination(Cleanup, Graph); IBaseFilter fileSink = StandardFilters.RenderFileDestination(Cleanup, Graph, outputFile); try { RenderGroups(graphBuilder, audioCompressor, null, wavDestFilter, audioParticipants, null); FilterGraphTools.ConnectFilters(Graph, wavDestFilter, fileSink, true); // if supplied, apply the media type to the filter if (mediaType != null) { FilterGraphTools.SetFilterFormat(mediaType, audioCompressor); } DisableClock(); } finally { if (wavDestFilter != null) { Marshal.ReleaseComObject(wavDestFilter); } if (fileSink != null) { Marshal.ReleaseComObject(fileSink); } } } finally { Marshal.ReleaseComObject(graphBuilder); } }
protected override void ConnectPins() { FilterGraphTools.ConnectFilters(filterGraph, sourceOutputPin, renderInputPin, true); }
private void ConnectFilters(IGraphBuilder gb, IBaseFilter upFilter, string upPin, IBaseFilter downFilter, string downPin, bool useIntelligentConnect) { FilterGraphTools.ConnectFilters(gb, upFilter, upPin, downFilter, downPin, useIntelligentConnect); }
/// <summary> /// Constructs the remainder of the graph (after the Demuxer) according to the source config and profile. /// </summary> private void BuildForProfile() { //Configure for specific codec / transcoding //if UseHardwareEncoder is checked, we will simply hand off the Elementry Streams from the Air if (SourceConfig.TVTuner.UseHardwareEncoder) { //connect video ConnectFilterToNetMux(mpeg2Demux, "2", "Input 01"); //connect audio ConnectFilterToNetMux(mpeg2Demux, "3", "Input 02"); } else // if they want to use software encoder, we will encode using the default profile { if (CurrentProfile.Video != null) { if (CurrentProfile.Video.CodecType != VideoCodecType.H264) { throw new NotSupportedException("H.264 is the only supported target codec in software transcoding mode!"); } if (CurrentProfile.Video.ImageSize != VideoImageSize.Undefined) { throw new NotSupportedException("Resizing is not supported!"); } videoEncoder = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, "LEAD H264 Encoder (4.0)"); if (videoEncoder == null) { throw new Exception("Could not instantiate H264 Encoder!"); } h264Encoder = (ILMH264Encoder)videoEncoder; if (h264Encoder == null) { throw new Exception("Could not query for ILMH264Encoder interface!"); } FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, "Elecard MPEG-2 Video Decoder"); FilterGraphTools.ConnectFilters(_graphBuilder, mpeg2Demux, "2", videoEncoder, "XForm In", true); h264Encoder.EncodingThreads = eH264ENCODINGTHREADS.H264THREAD_AUTO; h264Encoder.FrameRate = -1; h264Encoder.EncodingSpeed = eH264ENCODINGSPEED.H264SPEED_1; //h264Encoder.EncodingSpeed = eH264ENCODINGSPEED.H264SPEED_2; h264Encoder.EnableRateControl = true; h264Encoder.BitRate = CurrentProfile.Video.ConstantBitRate * 1024; h264Encoder.EnableSuperCompression = false; h264Encoder.SymbolMode = eH264SYMBOLMODE.H264SYMBOL_CAVLC; h264Encoder.OutputFormat = eH264OUTPUTFORMAT.H264FORMAT_STANDARD_H264; h264Encoder.IFrameInterval = CurrentProfile.Video.KeyFrameRate; h264Encoder.PFrameInterval = 0; //connect video ConnectFilterToNetMux(videoEncoder, "XForm Out", "Input 01"); } if (CurrentProfile.Audio != null) { if (CurrentProfile.Audio.CodecType != AudioCodecType.DolbyDigital) { throw new NotSupportedException("Audio transcoding is not implemented!"); } //connect audio ConnectFilterToNetMux(mpeg2Demux, "3", (CurrentProfile.Video != null) ? "Input 02" : "Input 01"); } } }
private void ConnectFilters(IGraphBuilder gb, IPin upPin, IPin downPin, bool useIntelligentConnect) { FilterGraphTools.ConnectFilters(gb, upPin, downPin, useIntelligentConnect); }
private void ConnectStreamBufferSinkFilter() { IPin audioDemuxOut = null, audioDvrIn = null; try { audioDemuxOut = DsFindPin.ByDirection(this.mpeg2Demux, PinDirection.Output, 0); audioDvrIn = DsFindPin.ByDirection(this.streamBufferSink, PinDirection.Input, 0); FilterGraphTools.ConnectFilters(this.graphBuilder, audioDemuxOut, audioDvrIn, false); } finally { if (audioDemuxOut != null) { Marshal.ReleaseComObject(audioDemuxOut); } if (audioDvrIn != null) { Marshal.ReleaseComObject(audioDvrIn); } } //if (false) //Not working anymore on Windows 7!! this.mpeg2VideoStreamAnalyzer != null) //{ // IPin videoDemuxOut = null, videoVSAIn = null; // try // { // videoDemuxOut = DsFindPin.ByName(this.mpeg2Demux, this.H264DecoderDevice == null ? "MPG2" : "H264"); // videoVSAIn = DsFindPin.ByDirection(this.mpeg2VideoStreamAnalyzer, PinDirection.Input, 0); // FilterGraphTools.ConnectFilters(this.graphBuilder, videoDemuxOut, videoVSAIn, false); // } // finally // { // if (videoDemuxOut != null) Marshal.ReleaseComObject(videoDemuxOut); // if (videoVSAIn != null) Marshal.ReleaseComObject(videoVSAIn); // } // IPin videoVSAOut = null, videoDvrIn = null; // try // { // videoVSAOut = DsFindPin.ByDirection(this.mpeg2VideoStreamAnalyzer, PinDirection.Output, 0); // videoDvrIn = DsFindPin.ByDirection(this.streamBufferSink, PinDirection.Input, 1); // FilterGraphTools.ConnectFilters(this.graphBuilder, videoVSAOut, videoDvrIn, false); // } // finally // { // if (videoVSAOut != null) Marshal.ReleaseComObject(videoVSAOut); // if (videoDvrIn != null) Marshal.ReleaseComObject(videoDvrIn); // } //} //else //{ IPin videoDemuxOut = null, videoDvrIn = null; try { videoDemuxOut = DsFindPin.ByName(this.mpeg2Demux, this.H264DecoderDevice == null ? "MPG2" : "H264"); videoDvrIn = DsFindPin.ByDirection(this.streamBufferSink, PinDirection.Input, 1); FilterGraphTools.ConnectFilters(this.graphBuilder, videoDemuxOut, videoDvrIn, false); } finally { if (videoDemuxOut != null) { Marshal.ReleaseComObject(videoDemuxOut); } if (videoDvrIn != null) { Marshal.ReleaseComObject(videoDvrIn); } } //} }