Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ViXSATSC"/> class.
        /// </summary>
        /// <param name="tunerFilter">The tuner filter.</param>
        public ViXSATSC(IBaseFilter tunerFilter)
        {
            IPin pin = DsFindPin.ByName(tunerFilter, "MPEG2 Transport");

            if (pin != null)
            {
                _propertySet = tunerFilter as IKsPropertySet;
                if (_propertySet != null)
                {
                    KSPropertySupport supported;
                    _propertySet.QuerySupported(guidViXSTunerExtention, (int)BdaDigitalModulator.MODULATION_TYPE, out supported);
                    if ((supported & KSPropertySupport.Set) != 0)
                    {
                        Log.Log.Debug("ViXS ATSC: DVB-S card found!");
                        _tempValue  = Marshal.AllocCoTaskMem(1024);
                        _isViXSATSC = true;
                    }
                    else
                    {
                        Log.Log.Debug("ViXS ATSC: card NOT found!");
                        _isViXSATSC = false;
                    }
                }
            }
            else
            {
                Log.Log.Info("ViXS ATSC: could not find MPEG2 Transport pin!");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GenericBDAS"/> class.
        /// </summary>
        /// <param name="tunerFilter">The tuner filter.</param>
        public GenericBDAS(IBaseFilter tunerFilter)
        {
            _TunerDevice = (IBDA_Topology)tunerFilter;
            //check if the BDA driver supports DiSEqC
            IPin pin = DsFindPin.ByName(tunerFilter, "MPEG2 Transport");

            if (pin != null)
            {
                _propertySet = pin as IKsPropertySet;
                if (_propertySet != null)
                {
                    KSPropertySupport supported;
                    _propertySet.QuerySupported(guidBdaDigitalDemodulator, (int)BdaDigitalModulator.MODULATION_TYPE, out supported);
                    if ((supported & KSPropertySupport.Set) != 0)
                    {
                        Log.Log.Debug(FormatMessage("DiSEqC capable card found!"));
                        _isGenericBDAS = true;
                    }
                }
            }
            else
            {
                Log.Log.Info(FormatMessage("tuner pin not found!"));
            }
        }
Ejemplo n.º 3
0
        public SRM314(StreamSourceInfo sourceConfig, OpenGraphRequest openGraphRequest)
            : base(sourceConfig, openGraphRequest)
        {
            InitializeNetworkSink();

            _currentVideoSettings = new VideoSettings();

            _crossbar      = AddFilterByName(FilterCategory.AMKSCrossbar, "Sensoray 314 Crossbar");
            _captureFilter = AddFilterByName(FilterCategory.AMKSCapture, "Sensoray 314 A/V Capture");

            //instantiate BDA VES and get reference to capture pin
            _ves           = AddFilterByName(FilterCategory.WDMStreamingEncoderDevices, "Sensoray 314 BDA MPEG VES Encoder");
            _vesCapturePin = DsFindPin.ByName(_ves, "Capture");

            //instantiate frame rate filter and get control interface
            _frameRateFilter = AddFilterByName(FilterCategory.LegacyAmFilterCategory, "FC Frame Rate Filter");
            _frameRate       = (IFCFrameRateAPI)_frameRateFilter;



            SetInputAndSystem();

            _frameRate.set_InputFramerate(15.0);

            ChangeProfile(CurrentProfile);

            ConnectFilters(_crossbar, "0: Video Decoder Out", _captureFilter, "Analog Video In", false);
            ConnectFilters(_captureFilter, "Analog ITU Video", _ves, "Analog ITU Video", false);
            // ConnectFilterToNetMux(_ves, "Capture", "Input 01");
            ConnectFilters(_ves, "Capture", _frameRateFilter, "Input", false);
            ConnectFilterToNetMux(_frameRateFilter, "Output", "Input 01");
            ConnectNetMuxToNetSnk();
        }
Ejemplo n.º 4
0
        public static bool RenderPin(IGraphBuilder graphBuilder, IBaseFilter source, string pinName)
        {
            int hr = 0;

            if (graphBuilder == null)
            {
                throw new ArgumentNullException("graphBuilder");
            }

            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            IPin pin = DsFindPin.ByName(source, pinName);

            if (pin != null)
            {
                hr = graphBuilder.Render(pin);
                Marshal.ReleaseComObject(pin);

                return(hr >= 0);
            }

            return(false);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the ICodecAPI interface for whichever pin is in use for the current codec
        /// </summary>
        /// <returns>a reference to the ICodecAPI on the current pin</returns>
        private ICodecAPI GetCodecAPI()
        {
            string pinName;

            if (_currentVideoSettings.CodecType == VideoCodecType.H264)
            {
                pinName = "H264";
            }
            else
            {
                throw new NotImplementedException("GetCodecAPI not implemented for codectype " + _currentVideoSettings.CodecType.ToString());
            }
            IPin pin = DsFindPin.ByName(_captureFilter, pinName);

            if (pin == null)
            {
                throw new Exception(pinName + " pin not found on MangoCapture filter.");
            }
            ICodecAPI codecAPI = (ICodecAPI)pin;

            if (codecAPI == null)
            {
                throw new Exception("ICodecAPI interface not found on pin " + pinName);
            }
            return(codecAPI);
        }
Ejemplo n.º 6
0
        protected override void ConnectFilters()
        {
            int hr;

            m_form.Invoke((MethodInvoker) delegate()
            {
                try
                {
                    AddElecardAVCDecoder();

                    IPin pinUdpOut         = DsFindPin.ByName(m_UdpFilter, "Out");
                    IPin pinDecoderXInput  = DsFindPin.ByName(m_ElecardAVCDecoderFilter, "XForm In");
                    IPin pinDecoderXOutput = DsFindPin.ByName(m_ElecardAVCDecoderFilter, "XForm Out");

                    hr = m_graphBuilder.Connect(pinUdpOut, pinDecoderXInput);
                    DsError.ThrowExceptionForHR(hr);

                    hr = m_graphBuilder.Render((DirectShowLib.IPin)pinDecoderXOutput);
                    SetVideoWindow();
                    pCallback(10, "start");
                    return;
                }
                catch (Exception err)
                {
                }
            });
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GenericATSC"/> class.
        /// </summary>
        /// <param name="tunerFilter">The tuner filter.</param>
        public GenericATSC(IBaseFilter tunerFilter)
        {
            IPin pin = DsFindPin.ByName(tunerFilter, "MPEG2 Transport");

            if (pin != null)
            {
                _propertySet = pin as IKsPropertySet;
                if (_propertySet != null)
                {
                    KSPropertySupport supported;
                    _propertySet.QuerySupported(guidBdaDigitalDemodulator, (int)BdaDigitalModulator.MODULATION_TYPE, out supported);
                    if ((supported & KSPropertySupport.Set) != 0)
                    {
                        Log.Log.Debug("GenericATSC: QAM capable card found!");
                        _isGenericATSC = true;
                        _tempValue     = Marshal.AllocCoTaskMem(1024);
                        _tempInstance  = Marshal.AllocCoTaskMem(1024);
                    }
                    else
                    {
                        Log.Log.Debug("GenericATSC: QAM card NOT found!");
                        _isGenericATSC = false;
                    }
                }
            }
            else
            {
                Log.Log.Info("GenericATSC: tuner pin not found!");
            }
        }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Connects pins of graph
        /// </summary>
        private void GraphBuilding_ConnectPins()
        {
            // Pins used in graph
            IPin pinSourceCapture      = null;
            IPin pinTeeInput           = null;
            IPin pinTeePreview         = null;
            IPin pinTeeCapture         = null;
            IPin pinSampleGrabberInput = null;
            IPin pinRendererInput      = null;

            try
            {
                // Collect pins
                pinSourceCapture = DsFindPin.ByDirection(CaptureFilter, PinDirection.Output, 0);
                pinTeeInput      = DsFindPin.ByDirection(SmartTee, PinDirection.Input, 0);
                pinTeePreview    = DsFindPin.ByName(SmartTee, "Preview");
                pinTeeCapture    = DsFindPin.ByName(SmartTee, "Capture");

                pinSampleGrabberInput = DsFindPin.ByDirection(SampleGrabberFilter, PinDirection.Input, 0);
                pinRendererInput      = DsFindPin.ByDirection(VMRenderer, PinDirection.Input, 0);

                // Connect source to tee splitter
                int hr = FilterGraph.Connect(pinSourceCapture, pinTeeInput);
                DsError.ThrowExceptionForHR(hr);

                // Connect samplegrabber on preview-pin of tee splitter
                hr = FilterGraph.Connect(pinTeePreview, pinSampleGrabberInput);
                DsError.ThrowExceptionForHR(hr);

                // Connect the capture-pin of tee splitter to the renderer
                hr = FilterGraph.Connect(pinTeeCapture, pinRendererInput);
                DsError.ThrowExceptionForHR(hr);
            }
            catch
            {
                throw;
            }
            finally
            {
                SafeReleaseComObject(pinSourceCapture);
                pinSourceCapture = null;

                SafeReleaseComObject(pinTeeInput);
                pinTeeInput = null;

                SafeReleaseComObject(pinTeePreview);
                pinTeePreview = null;

                SafeReleaseComObject(pinTeeCapture);
                pinTeeCapture = null;

                SafeReleaseComObject(pinSampleGrabberInput);
                pinSampleGrabberInput = null;

                SafeReleaseComObject(pinRendererInput);
                pinRendererInput = null;
            }
            return;
        }
Ejemplo n.º 10
0
        protected static IPin GetPin(IBaseFilter filter, string pinName)
        {
            var pin = DsFindPin.ByName(filter, pinName);

            if (pin == null)
            {
                throw new Exception("Failed to get DirectShow filter pin " + pinName);
            }
            return(pin);
        }
Ejemplo n.º 11
0
            public YouTubeSource(IGraphBuilder graph, string filename)
            {
                m_Filter   = (IBaseFilter) new YouTubeSourceFilter();
                m_Splitter = (IBaseFilter) new LavSplitter();

                var fileSourceFilter = (IFileSourceFilter)m_Filter;

                DsError.ThrowExceptionForHR(fileSourceFilter.Load(filename, null));

                DsError.ThrowExceptionForHR(graph.AddFilter(m_Filter, "3DYD YouTube Source"));
                DsError.ThrowExceptionForHR(graph.AddFilter(m_Splitter, "LAV Splitter"));

                var outpins = GetPins(m_Filter, "Output");

                try
                {
                    switch (outpins.Length)
                    {
                    case 0:
                        throw new Exception("3DYD YouTube Source outpins.Length = 0 - Not expected!");

                    case 1:
                        ConnectPins(graph, outpins[0], m_Splitter, "Input");
                        VideoOutputPin = DsFindPin.ByName(m_Splitter, "Video");
                        AudioOutputPin = DsFindPin.ByName(m_Splitter, "Audio");
                        break;

                    case 2:
                        m_Splitter2 = (IBaseFilter) new LavSplitter();
                        DsError.ThrowExceptionForHR(graph.AddFilter(m_Splitter2, "LAV Splitter 2"));
                        ConnectPins(graph, outpins[0], m_Splitter, "Input");
                        ConnectPins(graph, outpins[1], m_Splitter2, "Input");
                        // Assume the first "Output" pin is video and the second is audio
                        VideoOutputPin = DsFindPin.ByName(m_Splitter, "Video");
                        AudioOutputPin = DsFindPin.ByName(m_Splitter2, "Audio");
                        break;

                    default:
                        throw new NotSupportedException(
                                  "Not supported: More than 2 output pins from 3DYD YouTube Source!");
                    }
                    SubtitleOutputPins   = GetPins(m_Filter, "OutputSS");
                    ExtendedSeeking      = (IAMExtendedSeeking)m_Splitter;
                    VideoStreamSelect    = (IAMStreamSelect)m_Splitter;
                    AudioStreamSelect    = (IAMStreamSelect)m_Splitter;
                    SubtitleStreamSelect = null;
                }
                finally
                {
                    foreach (var pin in outpins)
                    {
                        Marshal.ReleaseComObject(pin);
                    }
                }
            }
Ejemplo n.º 12
0
        private IPin GetPin(IBaseFilter filter, String pinName)
        {
            var pin = DsFindPin.ByName(filter, pinName);

            if (pin == null)
            {
                checkHR(-1, String.Format("Pin: {0} not found", pinName));
                return(null);
            }
            return(pin);
        }
Ejemplo n.º 13
0
        /// <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();
                }
            }
        }
Ejemplo n.º 14
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 AddAudioVolumeFilter() and AddAudioRenderer()
        /// </remarks>
        /// <param name="audioFilter">a filter in the graph that will be delivering the audio</param>
        /// <param name="audioOutPin">the pin on said filter that the audio stream comes from</param>
        /// <param name="useIntelligentConnect">true to use intelligent connect, false otherwise</param>
        protected void ConnectToAudio(IBaseFilter audioFilter, string audioOutPin, bool useIntelligentConnect)
        {
            IPin theAudioOutPin = null;

            try
            {
                theAudioOutPin = DsFindPin.ByName(audioFilter, audioOutPin);
                ConnectToAudio(theAudioOutPin, useIntelligentConnect);
            }
            finally
            {
                theAudioOutPin.Release();
            }
        }
Ejemplo n.º 15
0
        public static void ConnectFilters(IGraphBuilder graphBuilder, IBaseFilter upFilter, string sourcePinName,
                                          IBaseFilter downFilter, string destinationPinName, bool useIntelligentConnect)
        {
            if (graphBuilder == null)
            {
                throw new ArgumentNullException("graphBuilder");
            }

            if (upFilter == null)
            {
                throw new ArgumentNullException("upFilter");
            }

            if (downFilter == null)
            {
                throw new ArgumentNullException("downFilter");
            }

            IPin sourcePin, destPin;

            sourcePin = DsFindPin.ByName(upFilter, sourcePinName);
            if (sourcePin == null)
            {
                throw new ArgumentException("The source filter has no pin called : " + sourcePinName, sourcePinName);
            }

            destPin = DsFindPin.ByName(downFilter, destinationPinName);
            if (destPin == null)
            {
                throw new ArgumentException("The downstream filter has no pin called : " + destinationPinName,
                                            destinationPinName);
            }

            try
            {
                ConnectFilters(graphBuilder, sourcePin, destPin, useIntelligentConnect);
            }
            finally
            {
                Marshal.ReleaseComObject(sourcePin);
                Marshal.ReleaseComObject(destPin);
            }
        }
Ejemplo n.º 16
0
        private void GraphBuilding_ConnectPins()
        {
            IPin ppinOut = null;
            IPin ppinIn  = null;
            IPin pin3    = null;
            IPin pin4    = null;
            IPin pin5    = null;
            IPin pin6    = null;

            try
            {
                ppinOut = DsFindPin.ByDirection(this.DX.CaptureFilter, PinDirection.Output, 0);
                ppinIn  = DsFindPin.ByDirection(this.DX.SmartTee, PinDirection.Input, 0);
                pin3    = DsFindPin.ByName(this.DX.SmartTee, "Preview");
                pin4    = DsFindPin.ByName(this.DX.SmartTee, "Capture");
                pin5    = DsFindPin.ByDirection(this.DX.SampleGrabberFilter, PinDirection.Input, 0);
                pin6    = DsFindPin.ByDirection(this.DX.VMRenderer, PinDirection.Input, 0);
                DsError.ThrowExceptionForHR(this.DX.FilterGraph.Connect(ppinOut, ppinIn));
                DsError.ThrowExceptionForHR(this.DX.FilterGraph.Connect(pin3, pin5));
                DsError.ThrowExceptionForHR(this.DX.FilterGraph.Connect(pin4, pin6));
            }
            catch
            {
                throw;
            }
            finally
            {
                SafeReleaseComObject(ppinOut);
                ppinOut = null;
                SafeReleaseComObject(ppinIn);
                ppinIn = null;
                SafeReleaseComObject(pin3);
                pin3 = null;
                SafeReleaseComObject(pin4);
                pin4 = null;
                SafeReleaseComObject(pin5);
                pin5 = null;
                SafeReleaseComObject(pin6);
                pin6 = null;
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Initializes a new instance of the GenericDiseqcHandler class.
        /// </summary>
        /// <param name="tunerFilter">The tuner filter.</param>
        internal GenericDiseqcHandler(IBaseFilter tunerFilter)
        {
            this.tunerFilter = tunerFilter;

            IPin pin = DsFindPin.ByName(tunerFilter, "MPEG2 Transport");

            if (pin != null)
            {
                IKsPropertySet propertySet = pin as IKsPropertySet;
                if (propertySet != null)
                {
                    KSPropertySupport supported;
                    reply = propertySet.QuerySupported(guidBdaDigitalDemodulator, (int)BdaDigitalModulator.MODULATION_TYPE, out supported);

                    if (reply == 0 && (supported & KSPropertySupport.Set) != 0)
                    {
                        cardCapable = true;
                    }
                }
            }
        }
Ejemplo n.º 18
0
        /// <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();
                }
            }
        }
Ejemplo n.º 19
0
            public RarFileSource(RarFileSourceFilter rarFileSourceFilter, IGraphBuilder graph, string filename)
            {
                m_Filter   = rarFileSourceFilter.CreateInstance();
                m_Splitter = (IBaseFilter) new LavSplitter();

                var sourceFilter = (IFileSourceFilter)m_Filter;

                DsError.ThrowExceptionForHR(sourceFilter.Load(filename, null));

                DsError.ThrowExceptionForHR(graph.AddFilter(m_Filter, "RAR File Source Filter"));
                DsError.ThrowExceptionForHR(graph.AddFilter(m_Splitter, "LAV Splitter"));

                var outpins = GetPins(m_Filter, "Output");

                ConnectPins(graph, outpins[0], m_Splitter, "Input");
                VideoOutputPin     = DsFindPin.ByName(m_Splitter, "Video");
                AudioOutputPin     = DsFindPin.ByName(m_Splitter, "Audio");
                SubtitleOutputPins = GetPins(m_Splitter, "Subtitle");

                ExtendedSeeking      = (IAMExtendedSeeking)m_Splitter;
                VideoStreamSelect    = (IAMStreamSelect)m_Splitter;
                AudioStreamSelect    = (IAMStreamSelect)m_Splitter;
                SubtitleStreamSelect = null;
            }
        protected override void ConnectFilters()
        {
            int hr;

            m_form.Invoke((MethodInvoker) delegate()
            {
                try
                {
                    IPin pinUdpOut      = DsFindPin.ByName(m_UdpFilter, "Out");
                    IPin pinPushDemuxIn = DsFindPin.ByName(m_ElecardPushMPEGDemuxFilter, "Input");

                    hr = m_graphBuilder.Connect(pinUdpOut, pinPushDemuxIn);
                    DsError.ThrowExceptionForHR(hr);


                    IPin pinPushDemuxOut = null;
                    while (m_running && pinPushDemuxOut == null)
                    {
                        pinPushDemuxOut = DsFindPin.ByName(m_ElecardPushMPEGDemuxFilter, "AVC");
                        Thread.Sleep(400);
                    }
                    if (m_running == false)
                    {
                        return;
                    }
                    AddElecardAVCDecoder();
                    hr = m_graphBuilder.Render((DirectShowLib.IPin)pinPushDemuxOut);
                    SetVideoWindow();
                    pCallback(10, "start");
                    return;
                }
                catch (Exception err)
                {
                }
            });
        }
        private void StartCapture()
        {
            int hr;

            ISampleGrabber        sampGrabber = null;
            IBaseFilter           capFilter   = null;
            ICaptureGraphBuilder2 capGraph    = null;

            if (System.IO.File.Exists(txtAviFileName.Text))
            {
                // Get the graphbuilder object
                m_FilterGraph = (IFilterGraph2) new FilterGraph();
                m_mediaCtrl   = m_FilterGraph as IMediaControl;

                // Get the ICaptureGraphBuilder2
                capGraph = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

                // Get the SampleGrabber interface
                sampGrabber = (ISampleGrabber) new SampleGrabber();

                // Start building the graph
                hr = capGraph.SetFiltergraph(m_FilterGraph);
                DsError.ThrowExceptionForHR(hr);

                // Add the video source
                hr = m_FilterGraph.AddSourceFilter(txtAviFileName.Text, "File Source (Async.)", out capFilter);
                DsError.ThrowExceptionForHR(hr);

                //add AVI Decompressor
                IBaseFilter pAVIDecompressor = (IBaseFilter) new AVIDec();
                hr = m_FilterGraph.AddFilter(pAVIDecompressor, "AVI Decompressor");
                DsError.ThrowExceptionForHR(hr);

                IBaseFilter ffdshow;
                try
                {
                    // Create Decoder filter COM object (ffdshow video decoder)
                    Type comtype = Type.GetTypeFromCLSID(new Guid("{04FE9017-F873-410E-871E-AB91661A4EF7}"));
                    if (comtype == null)
                    {
                        throw new NotSupportedException("Creating ffdshow video decoder COM object fails.");
                    }
                    object comobj = Activator.CreateInstance(comtype);
                    ffdshow = (IBaseFilter)comobj;  // error ocurrs! raised exception
                    comobj  = null;
                }
                catch
                {
                    CustomMessageBox.Show("Please install/reinstall ffdshow");
                    return;
                }

                hr = m_FilterGraph.AddFilter(ffdshow, "ffdshow");
                DsError.ThrowExceptionForHR(hr);

                //
                IBaseFilter baseGrabFlt = (IBaseFilter)sampGrabber;
                ConfigureSampleGrabber(sampGrabber);

                // Add the frame grabber to the graph
                hr = m_FilterGraph.AddFilter(baseGrabFlt, "Ds.NET Grabber");
                DsError.ThrowExceptionForHR(hr);


                IBaseFilter vidrender = (IBaseFilter) new VideoRenderer();
                hr = m_FilterGraph.AddFilter(vidrender, "Render");
                DsError.ThrowExceptionForHR(hr);


                IPin captpin = DsFindPin.ByDirection(capFilter, PinDirection.Output, 0);

                IPin ffdpinin = DsFindPin.ByName(ffdshow, "In");

                IPin ffdpinout = DsFindPin.ByName(ffdshow, "Out");

                IPin samppin = DsFindPin.ByName(baseGrabFlt, "Input");

                hr = m_FilterGraph.Connect(captpin, ffdpinin);
                DsError.ThrowExceptionForHR(hr);
                hr = m_FilterGraph.Connect(ffdpinout, samppin);
                DsError.ThrowExceptionForHR(hr);

                FileWriter      filewritter = new FileWriter();
                IFileSinkFilter filemux     = (IFileSinkFilter)filewritter;
                //filemux.SetFileName("test.avi",);

                //hr = capGraph.RenderStream(null, MediaType.Video, capFilter, null, vidrender);
                // DsError.ThrowExceptionForHR(hr);

                SaveSizeInfo(sampGrabber);

                // setup buffer
                if (m_handle == IntPtr.Zero)
                {
                    m_handle = Marshal.AllocCoTaskMem(m_stride * m_videoHeight);
                }

                // tell the callback to ignore new images
                m_PictureReady = new ManualResetEvent(false);
                m_bGotOne      = false;
                m_bRunning     = false;

                timer1 = new Thread(timer);
                timer1.IsBackground = true;
                timer1.Start();

                m_mediaextseek = m_FilterGraph as IAMExtendedSeeking;
                m_mediapos     = m_FilterGraph as IMediaPosition;
                m_mediaseek    = m_FilterGraph as IMediaSeeking;
                double length = 0;
                m_mediapos.get_Duration(out length);
                trackBar_mediapos.Minimum = 0;
                trackBar_mediapos.Maximum = (int)length;

                Start();
            }
            else
            {
                MessageBox.Show("File does not exist");
            }
        }
Ejemplo n.º 22
0
        /// <summary> build the capture graph for grabber. </summary>
        private void SetupGraph(DsDevice dev, int iWidth, int iHeight, short iBPP, Control hControl)
        {
            int hr;

            ISampleGrabber sampGrabber = null;
            IBaseFilter    capFilter   = null;
            IPin           pCaptureOut = null;
            IPin           pSampleIn   = null;
            IPin           pRenderIn   = null;

            // Get the graphbuilder object
            m_FilterGraph = new FilterGraph() as IFilterGraph2;

            try
            {
#if DEBUG
                m_rot = new DsROTEntry(m_FilterGraph);
#endif
                // add the video input device
                hr = m_FilterGraph.AddSourceFilterForMoniker(dev.Mon, null, dev.Name, out capFilter);
                DsError.ThrowExceptionForHR(hr);

                // Find the still pin
                m_pinStill = DsFindPin.ByCategory(capFilter, PinCategory.Still, 0);

                // Didn't find one.  Is there a preview pin?
                if (m_pinStill == null)
                {
                    m_pinStill = DsFindPin.ByCategory(capFilter, PinCategory.Preview, 0);
                }

                // Still haven't found one.  Need to put a splitter in so we have
                // one stream to capture the bitmap from, and one to display.  Ok, we
                // don't *have* to do it that way, but we are going to anyway.
                if (m_pinStill == null)
                {
                    IPin pRaw   = null;
                    IPin pSmart = null;

                    // There is no still pin
                    m_VidControl = null;

                    // Add a splitter
                    IBaseFilter iSmartTee = (IBaseFilter) new SmartTee();

                    try
                    {
                        hr = m_FilterGraph.AddFilter(iSmartTee, "SmartTee");
                        DsError.ThrowExceptionForHR(hr);

                        // Find the find the capture pin from the video device and the
                        // input pin for the splitter, and connnect them
                        pRaw   = DsFindPin.ByCategory(capFilter, PinCategory.Capture, 0);
                        pSmart = DsFindPin.ByDirection(iSmartTee, PinDirection.Input, 0);

                        hr = m_FilterGraph.Connect(pRaw, pSmart);
                        DsError.ThrowExceptionForHR(hr);

                        // Now set the capture and still pins (from the splitter)
                        m_pinStill  = DsFindPin.ByName(iSmartTee, "Preview");
                        pCaptureOut = DsFindPin.ByName(iSmartTee, "Capture");

                        // If any of the default config items are set, perform the config
                        // on the actual video device (rather than the splitter)
                        if (iHeight + iWidth + iBPP > 0)
                        {
                            SetConfigParms(pRaw, iWidth, iHeight, iBPP);
                        }
                    }
                    finally
                    {
                        if (pRaw != null)
                        {
                            Marshal.ReleaseComObject(pRaw);
                        }
                        if (pRaw != pSmart)
                        {
                            Marshal.ReleaseComObject(pSmart);
                        }
                        if (pRaw != iSmartTee)
                        {
                            Marshal.ReleaseComObject(iSmartTee);
                        }
                    }
                }
                else
                {
                    // Get a control pointer (used in Click())
                    m_VidControl = capFilter as IAMVideoControl;

                    pCaptureOut = DsFindPin.ByCategory(capFilter, PinCategory.Capture, 0);

                    // If any of the default config items are set
                    if (iHeight + iWidth + iBPP > 0)
                    {
                        SetConfigParms(m_pinStill, iWidth, iHeight, iBPP);
                    }
                }

                // Get the SampleGrabber interface
                sampGrabber = new SampleGrabber() as ISampleGrabber;

                // Configure the sample grabber
                IBaseFilter baseGrabFlt = sampGrabber as IBaseFilter;
                ConfigureSampleGrabber(sampGrabber);
                pSampleIn = DsFindPin.ByDirection(baseGrabFlt, PinDirection.Input, 0);

                // Get the default video renderer
                IBaseFilter pRenderer = new VideoRendererDefault() as IBaseFilter;
                hr = m_FilterGraph.AddFilter(pRenderer, "Renderer");
                DsError.ThrowExceptionForHR(hr);

                pRenderIn = DsFindPin.ByDirection(pRenderer, PinDirection.Input, 0);

                // Add the sample grabber to the graph
                hr = m_FilterGraph.AddFilter(baseGrabFlt, "Ds.NET Grabber");
                DsError.ThrowExceptionForHR(hr);

                if (m_VidControl == null)
                {
                    // Connect the Still pin to the sample grabber
                    hr = m_FilterGraph.Connect(m_pinStill, pSampleIn);
                    DsError.ThrowExceptionForHR(hr);

                    // Connect the capture pin to the renderer
                    hr = m_FilterGraph.Connect(pCaptureOut, pRenderIn);
                    DsError.ThrowExceptionForHR(hr);
                }
                else
                {
                    // Connect the capture pin to the renderer
                    hr = m_FilterGraph.Connect(pCaptureOut, pRenderIn);
                    DsError.ThrowExceptionForHR(hr);

                    // Connect the Still pin to the sample grabber
                    hr = m_FilterGraph.Connect(m_pinStill, pSampleIn);
                    DsError.ThrowExceptionForHR(hr);
                }

                // Learn the video properties
                SaveSizeInfo(sampGrabber);
                ConfigVideoWindow(hControl);

                // Start the graph
                IMediaControl mediaCtrl = m_FilterGraph as IMediaControl;
                hr = mediaCtrl.Run();
                DsError.ThrowExceptionForHR(hr);
            }
            finally
            {
                if (sampGrabber != null)
                {
                    Marshal.ReleaseComObject(sampGrabber);
                    sampGrabber = null;
                }
                if (pCaptureOut != null)
                {
                    Marshal.ReleaseComObject(pCaptureOut);
                    pCaptureOut = null;
                }
                if (pRenderIn != null)
                {
                    Marshal.ReleaseComObject(pRenderIn);
                    pRenderIn = null;
                }
                if (pSampleIn != null)
                {
                    Marshal.ReleaseComObject(pSampleIn);
                    pSampleIn = null;
                }
            }
        }
Ejemplo n.º 23
0
        /// <summary> create the used COM components and get the interfaces. </summary>
        protected bool GetInterfaces()
        {
            VMR9Util.g_vmr9 = null;
            if (IsRadio == false)
            {
                Vmr9 = VMR9Util.g_vmr9 = new VMR9Util();

                // switch back to directx fullscreen mode
                Log.Info("RTSPPlayer: Enabling DX9 exclusive mode");
                GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_SWITCH_FULL_WINDOWED, 0, 0, 0, 1, 0, null);
                GUIWindowManager.SendMessage(msg);
            }
            //Type comtype = null;
            //object comobj = null;

            DsRect rect = new DsRect();

            rect.top    = 0;
            rect.bottom = GUIGraphicsContext.form.Height;
            rect.left   = 0;
            rect.right  = GUIGraphicsContext.form.Width;


            try
            {
                graphBuilder = (IGraphBuilder) new FilterGraph();

                Log.Info("RTSPPlayer: add source filter");
                if (IsRadio == false)
                {
                    bool AddVMR9 = VMR9Util.g_vmr9 != null && VMR9Util.g_vmr9.AddVMR9(graphBuilder);
                    if (!AddVMR9)
                    {
                        Log.Error("RTSPPlayer:Failed to add VMR9 to graph");
                        return(false);
                    }
                    VMR9Util.g_vmr9.Enable(false);
                }

                _mpegDemux = (IBaseFilter) new MPEG2Demultiplexer();
                graphBuilder.AddFilter(_mpegDemux, "MPEG-2 Demultiplexer");

                _rtspSource = (IBaseFilter) new RtpSourceFilter();
                int hr = graphBuilder.AddFilter((IBaseFilter)_rtspSource, "RTSP Source Filter");
                if (hr != 0)
                {
                    Log.Error("RTSPPlayer:unable to add RTSP source filter:{0:X}", hr);
                    return(false);
                }

                // add preferred video & audio codecs
                Log.Info("RTSPPlayer: add video/audio codecs");
                string strVideoCodec               = "";
                string strAudioCodec               = "";
                string strAudiorenderer            = "";
                int    intFilters                  = 0;  // FlipGer: count custom filters
                string strFilters                  = ""; // FlipGer: collect custom filters
                string postProcessingFilterSection = "mytv";
                using (Settings xmlreader = new MPSettings())
                {
                    if (_mediaType == g_Player.MediaType.Video)
                    {
                        strVideoCodec               = xmlreader.GetValueAsString("movieplayer", "mpeg2videocodec", "");
                        strAudioCodec               = xmlreader.GetValueAsString("movieplayer", "mpeg2audiocodec", "");
                        strAudiorenderer            = xmlreader.GetValueAsString("movieplayer", "audiorenderer", "Default DirectSound Device");
                        postProcessingFilterSection = "movieplayer";
                    }
                    else
                    {
                        strVideoCodec               = xmlreader.GetValueAsString("mytv", "videocodec", "");
                        strAudioCodec               = xmlreader.GetValueAsString("mytv", "audiocodec", "");
                        strAudiorenderer            = xmlreader.GetValueAsString("mytv", "audiorenderer", "Default DirectSound Device");
                        postProcessingFilterSection = "mytv";
                    }
                    enableDvbSubtitles = xmlreader.GetValueAsBool("tvservice", "dvbsubtitles", false);
                    // FlipGer: load infos for custom filters
                    int intCount = 0;
                    while (xmlreader.GetValueAsString(postProcessingFilterSection, "filter" + intCount.ToString(), "undefined") !=
                           "undefined")
                    {
                        if (xmlreader.GetValueAsBool(postProcessingFilterSection, "usefilter" + intCount.ToString(), false))
                        {
                            strFilters +=
                                xmlreader.GetValueAsString(postProcessingFilterSection, "filter" + intCount.ToString(), "undefined") +
                                ";";
                            intFilters++;
                        }
                        intCount++;
                    }
                }
                string extension = Path.GetExtension(m_strCurrentFile).ToLowerInvariant();
                if (IsRadio == false)
                {
                    if (strVideoCodec.Length > 0)
                    {
                        DirectShowUtil.AddFilterToGraph(graphBuilder, strVideoCodec);
                    }
                }
                if (strAudioCodec.Length > 0)
                {
                    DirectShowUtil.AddFilterToGraph(graphBuilder, strAudioCodec);
                }

                if (enableDvbSubtitles == true)
                {
                    try
                    {
                        _subtitleFilter = SubtitleRenderer.GetInstance().AddSubtitleFilter(graphBuilder);
                        SubtitleRenderer.GetInstance().SetPlayer(this);
                        dvbSubRenderer = SubtitleRenderer.GetInstance();
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }

                Log.Debug("Is subtitle fitler null? {0}", (_subtitleFilter == null));
                // FlipGer: add custom filters to graph
                string[] arrFilters = strFilters.Split(';');
                for (int i = 0; i < intFilters; i++)
                {
                    DirectShowUtil.AddFilterToGraph(graphBuilder, arrFilters[i]);
                }
                if (strAudiorenderer.Length > 0)
                {
                    audioRendererFilter = DirectShowUtil.AddAudioRendererToGraph(graphBuilder, strAudiorenderer, false);
                }

                Log.Info("RTSPPlayer: load:{0}", m_strCurrentFile);
                IFileSourceFilter interfaceFile = (IFileSourceFilter)_rtspSource;
                if (interfaceFile == null)
                {
                    Log.Error("RTSPPlayer:Failed to get IFileSourceFilter");
                    return(false);
                }

                //Log.Info("RTSPPlayer: open file:{0}",filename);
                hr = interfaceFile.Load(m_strCurrentFile, null);
                if (hr != 0)
                {
                    Log.Error("RTSPPlayer:Failed to open file:{0} :0x{1:x}", m_strCurrentFile, hr);
                    return(false);
                }

                #region connect rtspsource->demux

                Log.Info("RTSPPlayer:connect rtspsource->mpeg2 demux");
                IPin pinTsOut = DsFindPin.ByDirection((IBaseFilter)_rtspSource, PinDirection.Output, 0);
                if (pinTsOut == null)
                {
                    Log.Info("RTSPPlayer:failed to find output pin of tsfilesource");
                    return(false);
                }
                IPin pinDemuxIn = DsFindPin.ByDirection(_mpegDemux, PinDirection.Input, 0);
                if (pinDemuxIn == null)
                {
                    Log.Info("RTSPPlayer:failed to find output pin of tsfilesource");
                    return(false);
                }

                hr = graphBuilder.Connect(pinTsOut, pinDemuxIn);
                if (hr != 0)
                {
                    Log.Info("RTSPPlayer:failed to connect rtspsource->mpeg2 demux:{0:X}", hr);
                    return(false);
                }
                DirectShowUtil.ReleaseComObject(pinTsOut);
                DirectShowUtil.ReleaseComObject(pinDemuxIn);

                #endregion

                #region render demux output pins

                if (IsRadio)
                {
                    Log.Info("RTSPPlayer:render audio demux outputs");
                    IEnumPins enumPins;
                    _mpegDemux.EnumPins(out enumPins);
                    IPin[] pins    = new IPin[2];
                    int    fetched = 0;
                    while (enumPins.Next(1, pins, out fetched) == 0)
                    {
                        if (fetched != 1)
                        {
                            break;
                        }
                        PinDirection direction;
                        pins[0].QueryDirection(out direction);
                        if (direction == PinDirection.Input)
                        {
                            continue;
                        }
                        IEnumMediaTypes enumMediaTypes;
                        pins[0].EnumMediaTypes(out enumMediaTypes);
                        AMMediaType[] mediaTypes = new AMMediaType[20];
                        int           fetchedTypes;
                        enumMediaTypes.Next(20, mediaTypes, out fetchedTypes);
                        for (int i = 0; i < fetchedTypes; ++i)
                        {
                            if (mediaTypes[i].majorType == MediaType.Audio)
                            {
                                graphBuilder.Render(pins[0]);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    Log.Info("RTSPPlayer:render audio/video demux outputs");
                    IEnumPins enumPins;
                    _mpegDemux.EnumPins(out enumPins);
                    IPin[] pins    = new IPin[2];
                    int    fetched = 0;
                    while (enumPins.Next(1, pins, out fetched) == 0)
                    {
                        if (fetched != 1)
                        {
                            break;
                        }
                        PinDirection direction;
                        pins[0].QueryDirection(out direction);
                        if (direction == PinDirection.Input)
                        {
                            continue;
                        }
                        graphBuilder.Render(pins[0]);
                    }
                }

                #endregion

                // Connect DVB subtitle filter pins in the graph
                if (_mpegDemux != null && enableDvbSubtitles == true)
                {
                    IMpeg2Demultiplexer demuxer = _mpegDemux as IMpeg2Demultiplexer;
                    hr = demuxer.CreateOutputPin(GetTSMedia(), "Pcr", out _pinPcr);

                    if (hr == 0)
                    {
                        Log.Info("RTSPPlayer:_pinPcr OK");

                        IPin pDemuxerPcr  = DsFindPin.ByName(_mpegDemux, "Pcr");
                        IPin pSubtitlePcr = DsFindPin.ByName(_subtitleFilter, "Pcr");
                        hr = graphBuilder.Connect(pDemuxerPcr, pSubtitlePcr);
                    }
                    else
                    {
                        Log.Info("RTSPPlayer:Failed to create _pinPcr in demuxer:{0:X}", hr);
                    }

                    hr = demuxer.CreateOutputPin(GetTSMedia(), "Subtitle", out _pinSubtitle);
                    if (hr == 0)
                    {
                        Log.Info("RTSPPlayer:_pinSubtitle OK");

                        IPin pDemuxerSubtitle = DsFindPin.ByName(_mpegDemux, "Subtitle");
                        IPin pSubtitle        = DsFindPin.ByName(_subtitleFilter, "In");
                        hr = graphBuilder.Connect(pDemuxerSubtitle, pSubtitle);
                    }
                    else
                    {
                        Log.Info("RTSPPlayer:Failed to create _pinSubtitle in demuxer:{0:X}", hr);
                    }

                    hr = demuxer.CreateOutputPin(GetTSMedia(), "PMT", out _pinPMT);
                    if (hr == 0)
                    {
                        Log.Info("RTSPPlayer:_pinPMT OK");

                        IPin pDemuxerSubtitle = DsFindPin.ByName(_mpegDemux, "PMT");
                        IPin pSubtitle        = DsFindPin.ByName(_subtitleFilter, "PMT");
                        hr = graphBuilder.Connect(pDemuxerSubtitle, pSubtitle);
                    }
                    else
                    {
                        Log.Info("RTSPPlayer:Failed to create _pinPMT in demuxer:{0:X}", hr);
                    }
                }


                if (IsRadio == false)
                {
                    if (!VMR9Util.g_vmr9.IsVMR9Connected)
                    {
                        //VMR9 is not supported, switch to overlay
                        Log.Info("RTSPPlayer: vmr9 not connected");
                        _mediaCtrl = null;
                        Cleanup();
                        return(false);
                    }
                    VMR9Util.g_vmr9.SetDeinterlaceMode();
                }

                _mediaCtrl    = (IMediaControl)graphBuilder;
                mediaEvt      = (IMediaEventEx)graphBuilder;
                _mediaSeeking = (IMediaSeeking)graphBuilder;
                mediaPos      = (IMediaPosition)graphBuilder;
                basicAudio    = graphBuilder as IBasicAudio;
                //DirectShowUtil.SetARMode(graphBuilder,AspectRatioMode.Stretched);
                DirectShowUtil.EnableDeInterlace(graphBuilder);
                if (VMR9Util.g_vmr9 != null)
                {
                    m_iVideoWidth  = VMR9Util.g_vmr9.VideoWidth;
                    m_iVideoHeight = VMR9Util.g_vmr9.VideoHeight;
                }
                if (audioRendererFilter != null)
                {
                    Log.Info("RTSPPlayer9:set reference clock");
                    IMediaFilter    mp    = graphBuilder as IMediaFilter;
                    IReferenceClock clock = audioRendererFilter as IReferenceClock;
                    hr = mp.SetSyncSource(null);
                    hr = mp.SetSyncSource(clock);
                    Log.Info("RTSPPlayer9:set reference clock:{0:X}", hr);
                }
                Log.Info("RTSPPlayer: graph build successfull");
                return(true);
            }
            catch (Exception ex)
            {
                Error.SetError("Unable to play movie", "Unable build graph for VMR9");
                Log.Error("RTSPPlayer:exception while creating DShow graph {0} {1}", ex.Message, ex.StackTrace);
                CloseInterfaces();
                return(false);
            }
        }
Ejemplo n.º 24
0
        void BuildGraph()
        {
            int hr;

            m_graphBuilder = (IGraphBuilder) new FilterGraph();


            //Create the media control for controlling the graph
            mediaControl = (IMediaControl)m_graphBuilder;


            Guid gBouncingBall = new Guid("fd5010418ebe11ce818300aa00577da1");
            Guid gShapeGuid    = new Guid("E52BEAB445FB4D5ABC9E2381E61DCC47");

            Type comtype;
            Type comtypeShapes;

            comtype            = Type.GetTypeFromCLSID(gBouncingBall);
            comtypeShapes      = Type.GetTypeFromCLSID(gShapeGuid);
            BouncingBallFilter = (IBaseFilter)Activator.CreateInstance(comtype);
            hr = m_graphBuilder.AddFilter(BouncingBallFilter, "Bouncing ball");
            DsError.ThrowExceptionForHR(hr);

            ShapesFilter = (IBaseFilter)Activator.CreateInstance(comtypeShapes);
            hr           = m_graphBuilder.AddFilter(ShapesFilter, "Shapes Filter");
            DsError.ThrowExceptionForHR(hr);

            if (m_saveCrossToFile == true)
            {
                AddPinTeeFilter();
                AddDumpFilter();
                AddElecardAVCVideoEncoder();

                DumpCom dump = new DumpCom(DumpFilter);
                if (dump.SetFileName("c:\\dump1.asf") != 0)
                {
                    MessageBox.Show("Error set file");
                }
            }



            int j = 0;

            for (int i = 0; i < m_cross.Length * 2; i += 2)
            {
                m_cross[j] = new CrossMx(i, i + 1, ShapesFilter);
                m_cross[j].Init(2000);
                j++;
            }


            if (m_saveCrossToFile)
            {
                IPin pinInfinteInput   = DsFindPin.ByName(InfiniteTeeFilter, "Input");
                IPin pinInfinteOutput1 = DsFindPin.ByName(InfiniteTeeFilter, "Output1");
                IPin pinSourceOut      = DsFindPin.ByName(BouncingBallFilter, "Out");
                IPin pinAVCInput       = DsFindPin.ByName(ElecardAVCFilter, "Input");
                IPin pinAVCOutput      = DsFindPin.ByName(ElecardAVCFilter, "Output");

                IPin pinShapeIn  = DsFindPin.ByName(ShapesFilter, "Input");
                IPin pinShapeOut = DsFindPin.ByName(ShapesFilter, "Output");

                IPin pinDumpIn = DsFindPin.ByName(DumpFilter, "Input");

                hr = m_graphBuilder.Connect(pinSourceOut, pinShapeIn);
                DsError.ThrowExceptionForHR(hr);
                hr = m_graphBuilder.Connect(pinShapeOut, pinInfinteInput);
                DsError.ThrowExceptionForHR(hr);

                //hr = m_graphBuilder.Connect(pinInfinteOutput1, pinDumpIn);
                hr = m_graphBuilder.Connect(pinInfinteOutput1, pinAVCInput);
                DsError.ThrowExceptionForHR(hr);
                hr = m_graphBuilder.Connect(pinAVCOutput, pinDumpIn);
                DsError.ThrowExceptionForHR(hr);

                IPin pinInfinteOutput2 = DsFindPin.ByName(InfiniteTeeFilter, "Output2");

                // let DirectShow connects the front and back
                hr = m_graphBuilder.Render((DirectShowLib.IPin)pinInfinteOutput2);
                DsError.ThrowExceptionForHR(hr);
            }
            else
            {
                IPin pinSourceOut = DsFindPin.ByName(BouncingBallFilter, "Out");

                IPin pinShapeIn = DsFindPin.ByName(ShapesFilter, "Input");

                hr = m_graphBuilder.Connect(pinSourceOut, pinShapeIn);
                DsError.ThrowExceptionForHR(hr);
                IPin pinShapeOut = DsFindPin.ByName(ShapesFilter, "Output");
                // let DirectShow connects the front and back
                hr = m_graphBuilder.Render((DirectShowLib.IPin)pinShapeOut);
                DsError.ThrowExceptionForHR(hr);
            }
        }
Ejemplo n.º 25
0
        public void SetUpForTs(ISampleGrabberCB grabber, int methodToCall)
        {
            FilterGraphTools.DisconnectPins(mpeg2Demux);
            //FilterGraphTools.DisconnectPins(demodulator);
            FilterGraphTools.DisconnectPins(audioRenderer);
            FilterGraphTools.DisconnectPins(videoRenderer);
            //graphBuilder.RemoveFilter(audioRenderer);
            //graphBuilder.RemoveFilter(videoRenderer);

            sampleGrabber = (ISampleGrabber) new SampleGrabber();
            AMMediaType media = new AMMediaType();

            media.majorType  = MediaType.Stream;
            media.subType    = MediaSubType.Mpeg2Transport;
            media.formatType = FormatType.MpegStreams;
            sampleGrabber.SetOneShot(false);
            sampleGrabber.SetBufferSamples(true);
            int hr = sampleGrabber.SetMediaType(media);

            DsError.ThrowExceptionForHR(hr);

            graphBuilder.AddFilter((IBaseFilter)sampleGrabber, "Sample Grabber");

            nullRenderer = (IBaseFilter) new NullRenderer();
            graphBuilder.AddFilter(nullRenderer, "NULL Renderer");


            IPin pinIn  = DsFindPin.ByName((IBaseFilter)sampleGrabber, "Input");
            IPin pinOut = DsFindPin.ByDirection(capture, PinDirection.Output, 0);

            IEnumMediaTypes eMedia;

            pinOut.EnumMediaTypes(out eMedia);

            AMMediaType[] mediaTypes = new AMMediaType[1];
            eMedia.Next(mediaTypes.Length, mediaTypes, IntPtr.Zero);

            hr = sampleGrabber.SetMediaType(mediaTypes[0]);
            DsError.ThrowExceptionForHR(hr);

            pinOut.Disconnect();
            PinInfo info;

            pinOut.QueryPinInfo(out info);


            hr = graphBuilder.ConnectDirect(pinOut, pinIn, mediaTypes[0]);
            //hr = graphBuilder.Connect(pinOut, pinIn);
            DsError.ThrowExceptionForHR(hr);

            // Release the Pin
            Marshal.ReleaseComObject(pinIn);

            pinIn  = DsFindPin.ByName(nullRenderer, "In");
            pinOut = DsFindPin.ByName((IBaseFilter)sampleGrabber, "Output");

            hr = graphBuilder.Connect(pinOut, pinIn);
            DsError.ThrowExceptionForHR(hr);

            sampleGrabber.SetCallback(grabber, methodToCall);

            // Release the Pin
            Marshal.ReleaseComObject(pinIn);
            pinIn = null;
        }
Ejemplo n.º 26
0
        private void StartCapture()
        {
            int hr;

            ISampleGrabber        sampGrabber = null;
            IBaseFilter           capFilter   = null;
            ICaptureGraphBuilder2 capGraph    = null;

            if (System.IO.File.Exists(txtAviFileName.Text))
            {
                // Get the graphbuilder object
                m_FilterGraph = (IFilterGraph2) new FilterGraph();
                m_mediaCtrl   = m_FilterGraph as IMediaControl;

                // Get the ICaptureGraphBuilder2
                capGraph = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

                // Get the SampleGrabber interface
                sampGrabber = (ISampleGrabber) new SampleGrabber();

                // Start building the graph
                hr = capGraph.SetFiltergraph(m_FilterGraph);
                DsError.ThrowExceptionForHR(hr);

                // Add the video source
                hr = m_FilterGraph.AddSourceFilter(txtAviFileName.Text, "File Source (Async.)", out capFilter);
                DsError.ThrowExceptionForHR(hr);

                //add AVI Decompressor
                IBaseFilter pAVIDecompressor = (IBaseFilter) new AVIDec();
                hr = m_FilterGraph.AddFilter(pAVIDecompressor, "AVI Decompressor");
                DsError.ThrowExceptionForHR(hr);


                //
                IBaseFilter baseGrabFlt = (IBaseFilter)sampGrabber;
                ConfigureSampleGrabber(sampGrabber);

                // Add the frame grabber to the graph
                hr = m_FilterGraph.AddFilter(baseGrabFlt, "Ds.NET Grabber");
                DsError.ThrowExceptionForHR(hr);


                IBaseFilter vidrender = (IBaseFilter) new VideoRenderer();
                hr = m_FilterGraph.AddFilter(vidrender, "Render");
                DsError.ThrowExceptionForHR(hr);

                IPin captpin = DsFindPin.ByDirection(capFilter, PinDirection.Output, 0);

                IPin samppin = DsFindPin.ByName(baseGrabFlt, "Input");

                hr = m_FilterGraph.Connect(captpin, samppin);
                DsError.ThrowExceptionForHR(hr);

                FileWriter      filewritter = new FileWriter();
                IFileSinkFilter filemux     = (IFileSinkFilter)filewritter;
                //filemux.SetFileName("test.avi",);

                //hr = capGraph.RenderStream(null, MediaType.Video, capFilter, null, vidrender);
                // DsError.ThrowExceptionForHR(hr);

                SaveSizeInfo(sampGrabber);

                // setup buffer
                if (m_handle == IntPtr.Zero)
                {
                    m_handle = Marshal.AllocCoTaskMem(m_stride * m_videoHeight);
                }

                // tell the callback to ignore new images
                m_PictureReady = new ManualResetEvent(false);
                m_bGotOne      = false;
                m_bRunning     = false;

                timer1 = new Thread(timer);
                timer1.IsBackground = true;
                timer1.Start();

                m_mediaextseek = m_FilterGraph as IAMExtendedSeeking;
                m_mediapos     = m_FilterGraph as IMediaPosition;
                m_mediaseek    = m_FilterGraph as IMediaSeeking;
                double length = 0;
                m_mediapos.get_Duration(out length);
                trackBar_mediapos.Minimum = 0;
                trackBar_mediapos.Maximum = (int)length;

                Start();
            }
            else
            {
                MessageBox.Show("File does not exist");
            }
        }
Ejemplo n.º 27
0
        private IPin FindPin(IBaseFilter filter, PinDirection direction, Guid mediaType, Guid pinCategory, string preferredName)
        {
            if (Guid.Empty != pinCategory)
            {
                int idx = 0;

                do
                {
                    IPin pinByCategory = DsFindPin.ByCategory(filter, pinCategory, idx);

                    if (pinByCategory != null)
                    {
                        if (IsMatchingPin(pinByCategory, direction, mediaType))
                        {
                            return(pinByCategory);
                        }

                        Marshal.ReleaseComObject(pinByCategory);
                    }
                    else
                    {
                        break;
                    }

                    idx++;
                }while (true);
            }

            if (!string.IsNullOrEmpty(preferredName))
            {
                IPin pinByName = DsFindPin.ByName(filter, preferredName);
                if (pinByName != null && IsMatchingPin(pinByName, direction, mediaType))
                {
                    return(pinByName);
                }

                Marshal.ReleaseComObject(pinByName);
            }

            IEnumPins pinsEnum;

            IPin[] pins = new IPin[1];

            int hr = filter.EnumPins(out pinsEnum);

            DsError.ThrowExceptionForHR(hr);

            while (pinsEnum.Next(1, pins, IntPtr.Zero) == 0)
            {
                IPin pin = pins[0];
                if (pin != null)
                {
                    if (IsMatchingPin(pin, direction, mediaType))
                    {
                        return(pin);
                    }

                    Marshal.ReleaseComObject(pin);
                }
            }

            return(null);
        }
Ejemplo n.º 28
0
        private bool oldOpenSource()
        {
            /* Make sure we clean up any remaining mess */
            FreeResources();

            string fileSource = FileSource;

            if (string.IsNullOrEmpty(fileSource))
            {
                return(false);
            }

            try
            {
                /* Creates the GraphBuilder COM object */
                m_graph = new FilterGraphNoThread() as IGraphBuilder;

                if (m_graph == null)
                {
                    throw new WPFMediaKitException("Could not create a graph");
                }

                // use prefered audio renderer
                try
                {
                    InsertAudioRenderer(AudioRenderer);
                }
                catch (Exception ex)
                {
                    log.Error(ex, "Cannot add audio render: {0}", AudioRenderer);
                }

                IBaseFilter renderer = CreateVideoRenderer(VideoRenderer, m_graph, 2);

                var filterGraph = m_graph as IFilterGraph2;

                if (filterGraph == null)
                {
                    throw new WPFMediaKitException("Could not QueryInterface for the IFilterGraph2");
                }

                IBaseFilter sourceFilter;

                /* Have DirectShow find the correct source filter for the Uri */
                int hr = filterGraph.AddSourceFilter(fileSource, fileSource, out sourceFilter);
                DsError.ThrowExceptionForHR(hr);

                /* Check for video stream*/
                var videoPinFrom = DsFindPin.ByName(sourceFilter, "Video");
                if (videoPinFrom != null)
                {
                    Marshal.ReleaseComObject(videoPinFrom);
                    HasVideo = true;
                }
                else
                {
                    HasVideo = false;
                }

                /* We will want to enum all the pins on the source filter */
                IEnumPins pinEnum;

                hr = sourceFilter.EnumPins(out pinEnum);
                DsError.ThrowExceptionForHR(hr);

                IntPtr fetched = IntPtr.Zero;
                IPin[] pins    = { null };

                /* Counter for how many pins successfully rendered */
                int pinsRendered = 0;

                if (VideoRenderer == VideoRendererType.VideoMixingRenderer9)
                {
                    var mixer = renderer as IVMRMixerControl9;

                    if (mixer != null)
                    {
                        VMR9MixerPrefs dwPrefs;
                        mixer.GetMixingPrefs(out dwPrefs);
                        dwPrefs &= ~VMR9MixerPrefs.RenderTargetMask;
                        dwPrefs |= VMR9MixerPrefs.RenderTargetRGB;
                        //mixer.SetMixingPrefs(dwPrefs);
                    }
                }


                /* Loop over each pin of the source filter */
                while (pinEnum.Next(pins.Length, pins, fetched) == 0)
                {
                    if (filterGraph.RenderEx(pins[0],
                                             AMRenderExFlags.RenderToExistingRenderers,
                                             IntPtr.Zero) >= 0)
                    {
                        pinsRendered++;
                    }

                    Marshal.ReleaseComObject(pins[0]);
                }

                Marshal.ReleaseComObject(pinEnum);
                Marshal.ReleaseComObject(sourceFilter);

                if (pinsRendered == 0)
                {
                    throw new WPFMediaKitException("Could not render any streams from the source Uri");
                }

#if DEBUG
                /* Adds the GB to the ROT so we can view
                 * it in graphedit */
                m_dsRotEntry = new DsROTEntry(m_graph);
#endif
                /* Configure the graph in the base class */
                SetupFilterGraph(m_graph);

                /* Sets the NaturalVideoWidth/Height */
                //SetNativePixelSizes(renderer);
            }
            catch (Exception ex)
            {
                /* This exection will happen usually if the media does
                 * not exist or could not open due to not having the
                 * proper filters installed */
                FreeResources();

                /* Fire our failed event */
                InvokeMediaFailed(new MediaFailedEventArgs(ex.Message, ex));

                return(false);
            }

            InvokeMediaOpened();

            return(true);
        }
Ejemplo n.º 29
0
        private void SetupGraph(DsDevice dev, int iWidth, int iHeight, short iBPP)
        {
            int hr;

            ISampleGrabber sampGrabber = null;
            IBaseFilter    capFilter   = null;
            IPin           pCaptureOut = null;
            IPin           pSampleIn   = null;
            IPin           pRenderIn   = null;

            m_FilterGraph = new FilterGraph() as IFilterGraph2;

            try
            {
#if DEBUG
                m_rot = new DsROTEntry(m_FilterGraph);
#endif
                hr = m_FilterGraph.AddSourceFilterForMoniker(dev.Mon, null, dev.Name, out capFilter);
                DsError.ThrowExceptionForHR(hr);

                m_pinStill = DsFindPin.ByCategory(capFilter, PinCategory.Still, 0);

                if (m_pinStill == null)
                {
                    m_pinStill = DsFindPin.ByCategory(capFilter, PinCategory.Preview, 0);
                }

                if (m_pinStill == null)
                {
                    IPin pRaw   = null;
                    IPin pSmart = null;

                    m_VidControl = null;

                    IBaseFilter iSmartTee = (IBaseFilter) new SmartTee();

                    try
                    {
                        hr = m_FilterGraph.AddFilter(iSmartTee, "SmartTee");
                        DsError.ThrowExceptionForHR(hr);

                        pRaw   = DsFindPin.ByCategory(capFilter, PinCategory.Capture, 0);
                        pSmart = DsFindPin.ByDirection(iSmartTee, PinDirection.Input, 0);

                        hr = m_FilterGraph.Connect(pRaw, pSmart);
                        DsError.ThrowExceptionForHR(hr);

                        m_pinStill  = DsFindPin.ByName(iSmartTee, "Preview");
                        pCaptureOut = DsFindPin.ByName(iSmartTee, "Capture");

                        if (iHeight + iWidth + iBPP > 0)
                        {
                            SetConfigParms(pRaw, iWidth, iHeight, iBPP);
                        }
                    }
                    finally
                    {
                        if (pRaw != null)
                        {
                            Marshal.ReleaseComObject(pRaw);
                        }
                        if (pRaw != pSmart)
                        {
                            Marshal.ReleaseComObject(pSmart);
                        }
                        if (pRaw != iSmartTee)
                        {
                            Marshal.ReleaseComObject(iSmartTee);
                        }
                    }
                }
                else
                {
                    m_VidControl = capFilter as IAMVideoControl;

                    pCaptureOut = DsFindPin.ByCategory(capFilter, PinCategory.Capture, 0);

                    if (iHeight + iWidth + iBPP > 0)
                    {
                        SetConfigParms(m_pinStill, iWidth, iHeight, iBPP);
                    }
                }

                sampGrabber = new SampleGrabber() as ISampleGrabber;

                IBaseFilter baseGrabFlt = sampGrabber as IBaseFilter;
                ConfigureSampleGrabber(sampGrabber);
                pSampleIn = DsFindPin.ByDirection(baseGrabFlt, PinDirection.Input, 0);

                IBaseFilter pRenderer = new VideoRendererDefault() as IBaseFilter;
                hr = m_FilterGraph.AddFilter(pRenderer, "Renderer");
                DsError.ThrowExceptionForHR(hr);

                pRenderIn = DsFindPin.ByDirection(pRenderer, PinDirection.Input, 0);

                hr = m_FilterGraph.AddFilter(baseGrabFlt, "Ds.NET Grabber");
                DsError.ThrowExceptionForHR(hr);

                if (m_VidControl == null)
                {
                    hr = m_FilterGraph.Connect(m_pinStill, pSampleIn);
                    DsError.ThrowExceptionForHR(hr);

                    hr = m_FilterGraph.Connect(pCaptureOut, pRenderIn);
                    DsError.ThrowExceptionForHR(hr);
                }
                else
                {
                    hr = m_FilterGraph.Connect(pCaptureOut, pRenderIn);
                    DsError.ThrowExceptionForHR(hr);

                    hr = m_FilterGraph.Connect(m_pinStill, pSampleIn);
                    DsError.ThrowExceptionForHR(hr);
                }

                SaveSizeInfo(sampGrabber);

                IMediaControl mediaCtrl = m_FilterGraph as IMediaControl;
                hr = mediaCtrl.Run();
                DsError.ThrowExceptionForHR(hr);
            }
            finally
            {
                if (sampGrabber != null)
                {
                    Marshal.ReleaseComObject(sampGrabber);
                    sampGrabber = null;
                }
                if (pCaptureOut != null)
                {
                    Marshal.ReleaseComObject(pCaptureOut);
                    pCaptureOut = null;
                }
                if (pRenderIn != null)
                {
                    Marshal.ReleaseComObject(pRenderIn);
                    pRenderIn = null;
                }
                if (pSampleIn != null)
                {
                    Marshal.ReleaseComObject(pSampleIn);
                    pSampleIn = null;
                }
            }
        }
Ejemplo n.º 30
0
        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);
        }