Esempio n. 1
0
        /// <summary>
        /// Connecte le LAV Splitter Source et le renderer vidéo en créant le LAV Video Decoder.
        /// </summary>
        /// <param name="graph">Le graphe.</param>
        /// <param name="parserOutputVideoPin">Le pin de sortie vidéo</param>
        /// <param name="videoRendererInputPin">Le pin d'entrée du Renderer.</param>
        internal static void ConnectLAVSplitterAndRendererWithLAVDecoder(IGraphBuilder graph,
                                                                         IPin parserOutputVideoPin, IPin videoRendererInputPin)
        {
            Type        filterType     = null;
            IBaseFilter externalFilter = null;

            var lavVideoDecoder = LAVFilters[LAVFilterObject.VideoDecoder];

            CreateFilter(DxMediaPlayer.LAVVideo, lavVideoDecoder.CLSID, lavVideoDecoder.Name, ref filterType, ref externalFilter);

            int hr = graph.AddFilter(externalFilter, lavVideoDecoder.Name);

            DsError.ThrowExceptionForHR(hr);

            IPin externalDecoderInputPin = DsFindPin.ByDirection(externalFilter, PinDirection.Input, 0);

            hr = graph.ConnectDirect(parserOutputVideoPin, externalDecoderInputPin, null);
            DsError.ThrowExceptionForHR(hr);

            IPin externalDecoderOutputPin = DsFindPin.ByDirection(externalFilter, PinDirection.Output, 0);

            hr = graph.ConnectDirect(externalDecoderOutputPin, videoRendererInputPin, null);
            DsError.ThrowExceptionForHR(hr);

            SafeRelease(externalDecoderInputPin);
            SafeRelease(externalDecoderOutputPin);
        }
Esempio n. 2
0
        private void BuildVideoGraph(IGraphBuilder pGraph, String dstFile)
        {
            var hr = 0;

            //graph builder
            var pBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2( );

            hr = pBuilder.SetFiltergraph(pGraph);
            checkHR(hr, "Failed SetFilterGraph");

            //add LogitechHD Webcam C270
            var pLogitechHDWebcamC270 = CreateFilterByName(PreferedCaptureDevice, FilterCategory.VideoInputDevice);

            hr = pGraph.AddFilter(pLogitechHDWebcamC270, PreferedCaptureDevice ?? "Cappy");
            checkHR(hr, String.Format("Failed adding {0} to graph", PreferedCaptureDevice ?? "Cappy"));
            //add SampleGrabber
            var pSampleGrabberWithCallback = BuildSampleGrabber(pGraph);

            //connect Logitech HD Webcam C270 and SampleGrabber
            hr = (( ISampleGrabber )pSampleGrabberWithCallback).SetCallback(PhotoCallBack, 0);
            checkHR(hr, "Failed setting SampleGrabber callback");
            hr = pGraph.ConnectDirect(GetPin(pLogitechHDWebcamC270, "Capture"), GetPin(pSampleGrabberWithCallback, "Input"), null);
            checkHR(hr, String.Format("Failed connecting {0} and SampleGrabber", PreferedCaptureDevice ?? "Cappy"));

            //add File writer
            var pFilewriter = (IBaseFilter) new FileWriter( );

            hr = pGraph.AddFilter(pFilewriter, "File writer");
            checkHR(hr, "Failed adding File writer to graph");
            //set destination filename
            var pFilewriter_sink = ( IFileSinkFilter )pFilewriter;

            hr = pFilewriter_sink.SetFileName(dstFile, null);
            checkHR(hr, "Failed setting filename");

            //add AVI Mux
            var pAVIMux = (IBaseFilter) new AviDest( );

            hr = pGraph.AddFilter(pAVIMux, "AVI Mux");
            checkHR(hr, "Failed adding AVI Mux to graph");

            //connect SampleGrabber and AVI Mux
            hr = pGraph.ConnectDirect(GetPin(pSampleGrabberWithCallback, "Output"), GetPin(pAVIMux, "Input 01"), null);
            checkHR(hr, "Failed connecting SampleGrabber and AVI Mux");

            //connect AVI Mux and File writer
            hr = pGraph.ConnectDirect(GetPin(pAVIMux, "AVI Out"), GetPin(pFilewriter, "in"), null);
            checkHR(hr, "Failed connecting AVI Mux and File writer");
        }
        public static void ConnectFilters(IGraphBuilder graphBuilder, IPin sourcePin, IPin destinationPin,
                                          bool useIntelligentConnect)
        {
            int hr = 0;

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

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

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

            if (useIntelligentConnect)
            {
                hr = graphBuilder.Connect(sourcePin, destinationPin);
                DsError.ThrowExceptionForHR(hr);
            }
            else
            {
                hr = graphBuilder.ConnectDirect(sourcePin, destinationPin, null);
                DsError.ThrowExceptionForHR(hr);
            }
        }
Esempio n. 4
0
        private void BuildStillGraph(IGraphBuilder pGraph)
        {
            var hr = 0;

            //graph builder
            var pBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2( );

            hr = pBuilder.SetFiltergraph(pGraph);
            checkHR(hr, "Failed SetFilterGraph");

            //add LogitechHD Webcam C270
            var pLogitechHDWebcamC270 = CreateFilterByName(PreferedCaptureDevice, FilterCategory.VideoInputDevice);

            hr = pGraph.AddFilter(pLogitechHDWebcamC270, PreferedCaptureDevice ?? "Cappy");
            checkHR(hr, String.Format("Failed adding {0} to graph", PreferedCaptureDevice ?? "Cappy"));
            //add SampleGrabber
            var pSampleGrabberWithCallback = BuildSampleGrabber(pGraph);

            //connect Logitech HD Webcam C270 and SampleGrabber
            hr = (( ISampleGrabber )pSampleGrabberWithCallback).SetCallback(PhotoCallBack, 0);
            checkHR(hr, "Failed setting SampleGrabber callback");

            /*var stillPin = DsFindPin.ByName ( pLogitechHDWebcamC270, "Still" ) ??
             *      DsFindPin.ByName ( pLogitechHDWebcamC270, "Capture" );
             * if ( stillPin == null )
             * {
             *      checkHR ( -1, "Failed finding a capture pin" );
             * }
             * hr = pGraph.ConnectDirect ( stillPin, GetPin ( pSampleGrabberWithCallback, "Input" ), null );*/
            hr = pGraph.ConnectDirect(GetPin(pLogitechHDWebcamC270, "Capture"), GetPin(pSampleGrabberWithCallback, "Input"), null);
            checkHR(hr, String.Format("Failed connecting {0} and SampleGrabber", PreferedCaptureDevice ?? "Cappy"));
        }
        protected static void ConnectPins(IGraphBuilder graphBuilder, IPin pinOut, IBaseFilter toFilter,
                                          string toPinName)
        {
            IPin pinIn = null;

            try
            {
                pinIn = GetPin(toFilter, toPinName);
                DsError.ThrowExceptionForHR(graphBuilder.ConnectDirect(pinOut, pinIn, null));
            }
            finally
            {
                if (pinIn != null)
                {
                    Marshal.ReleaseComObject(pinIn);
                }
            }
        }
Esempio n. 6
0
        public static int ConnectFilters(IGraphBuilder graph, IBaseFilter src, IBaseFilter dest)
        {
            if ((graph == null) || (src == null) || (dest == null))
            {
                return(WinAPI.E_FAIL);
            }

            // Find an output pin on the upstream filter.
            IPin pinOut = null;
            IPin pinIn  = null;

            try
            {
                int hr = GetUnconnectedPin(src, PinDirection.Output, out pinOut);
                DsError.ThrowExceptionForHR(hr);

                // Find an input pin on the downstream filter.

                hr = GetUnconnectedPin(dest, PinDirection.Input, out pinIn);
                DsError.ThrowExceptionForHR(hr);

                // Try to connect them.
                hr = graph.ConnectDirect(pinOut, pinIn, null);
                DsError.ThrowExceptionForHR(hr);

                return(0);
            }
            catch (COMException)
            {
            }
            finally
            {
                Util.ReleaseComObject(ref pinIn);
                Util.ReleaseComObject(ref pinOut);
            }

            return(WinAPI.E_FAIL);
        }
Esempio n. 7
0
        private void BuildGraph(DirectShowLib.DsDevice dsDevice)
        {
            int hr = 0;
            pGraph = new FilterGraph() as IFilterGraph2;

            //graph builder
            ICaptureGraphBuilder2 pBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();

            try
            {
                hr = pBuilder.SetFiltergraph(pGraph);
                DsError.ThrowExceptionForHR(hr);

                // Add camera
                IBaseFilter camera;
                //hr = pGraph.FindFilterByName(dsDevice.Name, out camera);
                hr = ((IFilterGraph2)pGraph).AddSourceFilterForMoniker(dsDevice.Mon, null, dsDevice.Name, out camera);
                DsError.ThrowExceptionForHR(hr);

                hr = pGraph.AddFilter(camera, "camera");
                DsError.ThrowExceptionForHR(hr);

                // Set format for camera
                AMMediaType pmt = new AMMediaType();
                pmt.majorType = MediaType.Video;
                pmt.subType = MediaSubType.YUY2;
                pmt.formatType = FormatType.VideoInfo;
                pmt.fixedSizeSamples = true;
                pmt.formatSize = 88;
                pmt.sampleSize = 829440;
                pmt.temporalCompression = false;
                VideoInfoHeader format = new VideoInfoHeader();
                format.SrcRect = new DsRect();
                format.TargetRect = new DsRect();
                format.BitRate = 20736000;
                format.AvgTimePerFrame = 400000;
                format.BmiHeader = new BitmapInfoHeader();
                format.BmiHeader.Size = 40;
                format.BmiHeader.Width = 720;
                format.BmiHeader.Height = 576;
                format.BmiHeader.Planes = 1;
                format.BmiHeader.BitCount = 24;
                format.BmiHeader.Compression = 844715353;
                format.BmiHeader.ImageSize = 827440;
                pmt.formatPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(format));
                Marshal.StructureToPtr(format, pmt.formatPtr, false);
                hr = ((IAMStreamConfig)DsFindPin.ByCategory(camera, PinCategory.Capture, 0)).SetFormat(pmt);
                //hr = ((IAMStreamConfig)GetPin(pUSB20Camera, "Capture")).SetFormat(pmt);
                DsUtils.FreeAMMediaType(pmt);
                DsError.ThrowExceptionForHR(hr);

                IAMCrossbar crossBar = null;
                object dummy;
                hr = pBuilder.FindInterface(PinCategory.Capture, MediaType.Video, camera, typeof(IAMCrossbar).GUID, out dummy);
                if( hr >=0)
                {
                    crossBar = (IAMCrossbar)dummy;
                    int oPin, iPin;
                    int ovLink, ivLink;
                    ovLink = ivLink = 0;
                    crossBar.get_PinCounts(out oPin, out iPin);
                    int pIdxRel;
                    PhysicalConnectorType physicalConType;
                    for (int i = 0; i < iPin; i++)
                    {
                        crossBar.get_CrossbarPinInfo(true, i, out pIdxRel, out physicalConType);
                        if (physicalConType == PhysicalConnectorType.Video_Composite)
                            ivLink = i;
                    }
                    for (int i = 0; i < oPin; i++)
                    {
                        crossBar.get_CrossbarPinInfo(false, i, out pIdxRel, out physicalConType);
                        if (physicalConType == PhysicalConnectorType.Video_VideoDecoder)
                            ovLink = i;
                    }

                    try
                    {
                        crossBar.Route(ovLink, ivLink);
                    }
                    catch
                    {

                        throw new Exception("Failed to get IAMCrossbar");
                    }
                }

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

                //add color space converter
                IBaseFilter pColorSpaceConverter = (IBaseFilter)new Colour();
                hr = pGraph.AddFilter(pColorSpaceConverter, "Color space converter");
                DsError.ThrowExceptionForHR(hr);

                // Connect camera and AVI Decomp
                hr = pGraph.ConnectDirect(DsFindPin.ByCategory(camera, PinCategory.Capture, 0), DsFindPin.ByName(pAVIDecompressor, "XForm In"), null);
                DsError.ThrowExceptionForHR(hr);

                // Connect AVI Decomp and color space converter
                hr = pGraph.ConnectDirect(DsFindPin.ByName(pAVIDecompressor, "XForm Out"), DsFindPin.ByName(pColorSpaceConverter, "Input"), null);
                DsError.ThrowExceptionForHR(hr);

                //add SampleGrabber
                //IBaseFilter pSampleGrabber = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_SampleGrabber));
                //hr = pGraph.AddFilter(pSampleGrabber, "SampleGrabber");
                IBaseFilter sampleGrabber = new SampleGrabber() as IBaseFilter;
                hr = pGraph.AddFilter(sampleGrabber, "Sample grabber");
                DsError.ThrowExceptionForHR(hr);

                // Configure the samplegrabber
                AMMediaType pSampleGrabber_pmt = new AMMediaType();
                pSampleGrabber_pmt.majorType = MediaType.Video;
                pSampleGrabber_pmt.subType = MediaSubType.ARGB32;
                pSampleGrabber_pmt.formatType = FormatType.VideoInfo;
                pSampleGrabber_pmt.fixedSizeSamples = true;
                pSampleGrabber_pmt.formatSize = 88;
                pSampleGrabber_pmt.sampleSize = 1658880;
                pSampleGrabber_pmt.temporalCompression = false;
                VideoInfoHeader pSampleGrabber_format = new VideoInfoHeader();
                pSampleGrabber_format.SrcRect = new DsRect();
                pSampleGrabber_format.SrcRect.right = 720;
                pSampleGrabber_format.SrcRect.bottom = 576;
                pSampleGrabber_format.TargetRect = new DsRect();
                pSampleGrabber_format.TargetRect.right = 720;
                pSampleGrabber_format.TargetRect.bottom = 576;
                pSampleGrabber_format.BitRate = 331776000;
                pSampleGrabber_format.AvgTimePerFrame = 400000;
                pSampleGrabber_format.BmiHeader = new BitmapInfoHeader();
                pSampleGrabber_format.BmiHeader.Size = 40;
                pSampleGrabber_format.BmiHeader.Width = 720;
                pSampleGrabber_format.BmiHeader.Height = 576;
                pSampleGrabber_format.BmiHeader.Planes = 1;
                pSampleGrabber_format.BmiHeader.BitCount = 32;
                pSampleGrabber_format.BmiHeader.ImageSize = 1658880;

                pSampleGrabber_pmt.formatPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(pSampleGrabber_format));
                Marshal.StructureToPtr(pSampleGrabber_format, pSampleGrabber_pmt.formatPtr, false);
                hr = ((ISampleGrabber)sampleGrabber).SetMediaType(pSampleGrabber_pmt);
                DsError.ThrowExceptionForHR(hr);

                //connect MJPG dec and SampleGrabber
                //hr = pGraph.ConnectDirect(GetPin(pMJPGDecompressor, "XForm Out"), GetPin(pSampleGrabber, "Input"), null);
                hr = pGraph.ConnectDirect(DsFindPin.ByName(pColorSpaceConverter, "XForm Out"), DsFindPin.ByName(sampleGrabber, "Input"), null);
                DsError.ThrowExceptionForHR(hr);

                //set callback
                hr = ((ISampleGrabber)sampleGrabber).SetCallback(this, 1);
                DsError.ThrowExceptionForHR(hr);
            }
            finally
            {
                // Clean this mess up!
            }
        }
Esempio n. 8
0
        static void BuildGraph(IGraphBuilder pGraph, string dstFile1)
        {
            int hr = 0;
            //graph builder
            ICaptureGraphBuilder2 pBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            hr = pBuilder.SetFiltergraph(pGraph); checkHR(hr, "Can't SetFiltergraph");
            Guid CLSID_GenericNetworkProvider = new Guid("{B2F3A67C-29DA-4C78-8831-091ED509A475}");             //MSNP.ax

            Guid CLSID_AVerMediaBDADVBSTuner              = new Guid("{17CCA71B-ECD7-11D0-B908-00A0C9223196}"); //ksproxy.ax
            Guid CLSID_AVerMediaBDADigitalCapture         = new Guid("{17CCA71B-ECD7-11D0-B908-00A0C9223196}"); //ksproxy.ax
            Guid CLSID_MPEG2SectionsandTables             = new Guid("{C666E115-BB62-4027-A113-82D643FE2D99}"); //Mpeg2Data.ax
            Guid CLSID_BDAMPEG2TransportInformationFilter = new Guid("{FC772AB0-0C7F-11D3-8FF2-00A0C9224CF4}"); //psisrndr.ax
            Guid CLSID_MicrosoftDTVDVDAudioDecoder        = new Guid("{E1F1A0B8-BEEE-490D-BA7C-066C40B5E2B9}"); //msmpeg2adec.d11

            Guid CLSID_MicrosoftDTVDVDVideoDecoder = new Guid("{212690FB-83E5-4526-8FD7-74478B7939CD}");        //msmpeg2vdec.d11

            IBaseFilter pMicrosoftDTVDVDAudioDecoder2 = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_MicrosoftDTVDVDAudioDecoder));

            hr = pGraph.AddFilter(pMicrosoftDTVDVDAudioDecoder2, "Microsoft DTV-DVD Audio Decoder"); checkHR(hr, "Can't add Microsoft DTV-DVD Audio Decoder to graph");

            //add Generic Network Provider
            IBaseFilter pGenericNetworkProvider = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_GenericNetworkProvider));

            hr = pGraph.AddFilter(pGenericNetworkProvider, "Generic Network Provider");
            checkHR(hr, "Can't add Generic Network Provider to graph");
            //add AVerMedia BDA DVBS Tuner
            IBaseFilter pAVerMediaBDADVBSTuner = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_AVerMediaBDADVBSTuner));

            hr = pGraph.AddFilter(pAVerMediaBDADVBSTuner, "AVerMedia BDA DVBS Tuner"); checkHR(hr, "Can't add AVerMedia BDA DVBS Tuner to graph");
            //connect Generic Network Provider and AVerMedia BDA DVBS Tuner
            hr = pGraph.ConnectDirect(GetPin(pGenericNetworkProvider, "Antenna Out"), GetPin(pAVerMediaBDADVBSTuner, "Input0"), null);
            checkHR(hr, "Can't connect Generic Network Provider and AVerMedia BDA DVBS Tuner");
            //add AVerMedia BDA Digital Capture
            IBaseFilter pAVerMediaBDADigitalCapture = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_AVerMediaBDADigitalCapture));

            hr = pGraph.AddFilter(pAVerMediaBDADigitalCapture, "AVerMedia BDA Digital Capture"); checkHR(hr, "Can't add AVerMedia BDA Digital Capture to graph");
            //connect AVerMedia BDA DVBS Tuner and AVerMedia BDA Digital Capture
            hr = pGraph.ConnectDirect(GetPin(pAVerMediaBDADVBSTuner, "MPEG2 Transport"), GetPin(pAVerMediaBDADigitalCapture, "MPEG2 Transport"), null); checkHR(hr, "Can't connect AVerMedia BDA DVBS Tuner and AVerMedia BDA Digital Capture");
            //add MPEG-2 Demultiplexer
            IBaseFilter pMPEG2Demultiplexer = (IBaseFilter) new MPEG2Demultiplexer();

            hr = pGraph.AddFilter(pMPEG2Demultiplexer, "MPEG-2 Demultiplexer");
            checkHR(hr, "Can't add MPEG-2 Demultiplexer to graph");
            //connect AVerMedia BDA Digital Capture and MPEG-2 Demultiplexer
            hr = pGraph.ConnectDirect(GetPin(pAVerMediaBDADigitalCapture, "MPEG2 Transport"), GetPin(pMPEG2Demultiplexer, "MPEG-2 Stream"), null);
            checkHR(hr, "Can't connect AVerMedia BDA Digital Capture and MPEG-2 Demultiplexer");
            //add MPEG-2 Sections and Tables
            IBaseFilter pMPEG2SectionsandTables = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_MPEG2SectionsandTables));

            hr = pGraph.AddFilter(pMPEG2SectionsandTables, "MPEG-2 Sections and Tables");
            checkHR(hr, "Can't add MPEG-2 Sections and Tables to graph");
            //add BDA MPEG2 Transport Information Filter
            IBaseFilter pBDAMPEG2TransportInformationFilter = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_BDAMPEG2TransportInformationFilter));

            hr = pGraph.AddFilter(pBDAMPEG2TransportInformationFilter, "BDA MPEG2 Transport Information Filter"); checkHR(hr, "Can't add BDA MPEG2 Transport Information Filter to graph");
            //connect MPEG-2 Demultiplexer and BDA MPEG2 Transport Information Filter
            hr = pGraph.ConnectDirect(GetPin(pMPEG2Demultiplexer, "001"), GetPin(pBDAMPEG2TransportInformationFilter, "IB Input"), null);
            checkHR(hr, "Can't connect MPEG-2 Demultiplexer and BDA MPEG2 Transport Information Filter");
            //connect MPEG-2 Demultiplexer and MPEG-2 Sections and Tables
            hr = pGraph.ConnectDirect(GetPin(pMPEG2Demultiplexer, "002"), GetPin(pMPEG2SectionsandTables, "In"), null);
            checkHR(hr, "Can't connect MPEG-2 Demultiplexer and MPEG-2 Sections and Tables");



            //add Microsoft DTV-DVD Audio Decoder
            IBaseFilter pMicrosoftDTVDVDAudioDecoder = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_MicrosoftDTVDVDAudioDecoder));

            hr = pGraph.AddFilter(pMicrosoftDTVDVDAudioDecoder, "Microsoft DTV-DVD Audio Decoder"); checkHR(hr, "Can't add Microsoft DTV-DVD Audio Decoder to graph");

            //connect MPEG-2 Demultiplexer and Microsoft DTV-DVD Audio Decoder
            hr = pGraph.ConnectDirect(GetPin(pMPEG2Demultiplexer, "007"), GetPin(pMicrosoftDTVDVDAudioDecoder, "XForm In"), null);
            checkHR(hr, "Can't connect MPEG-2 Demultiplexer and Microsoft DTV-DVD Audio Decoder");

            //add WM ASF Writer
            IBaseFilter pWMASFWriter = (IBaseFilter) new WMAsfWriter();

            hr = pGraph.AddFilter(pWMASFWriter, "WM ASF Writer");
            checkHR(hr, "Can't add WM ASF Writer to graph");
            //set destination filename
            IFileSinkFilter pWMASFWriter_sink = pWMASFWriter as IFileSinkFilter;

            if (pWMASFWriter_sink == null)
            {
                checkHR(unchecked ((int)0x80004002), "Can't get IFileSinkFilter");
            }
            hr = pWMASFWriter_sink.SetFileName(dstFile1, null);
            checkHR(hr, "Can'i set filename");
            //connect Microsoft DTV-DVD Audio Decoder and WM ASF Writer
            hr = pGraph.ConnectDirect(GetPin(pMicrosoftDTVDVDAudioDecoder, "XFrom Out"), GetPin(pWMASFWriter, "Audio Input 01"), null);
            checkHR(hr, "Can't connect Microsoft DTV-DVD Audio Decoder and WM ASF Writer");
            //add Microsoft DTV-DVD Video Decoder
            IBaseFilter pMicrosoftDTVDVDVideoDecoder = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_MicrosoftDTVDVDVideoDecoder));

            hr = pGraph.AddFilter(pMicrosoftDTVDVDVideoDecoder, "Microsoft DTV-DVD Video Decoder"); checkHR(hr, "Can't add Microsoft DTV-DVD Video Decoder to graph");
            //connect MPEG-2 Demultiplexer and Microsoft DTV-DVD Video Decoder
            hr = pGraph.ConnectDirect(GetPin(pMPEG2Demultiplexer, "006"), GetPin(pMicrosoftDTVDVDVideoDecoder, "Video Input"), null);
            checkHR(hr, "Can't connect MPEG-2 Demultiplexer and Microsoft DTV-DVD Video Decoder");
            //connect Microsoft DTV-DVD Video Decoder and WM ASF Writer
            hr = pGraph.ConnectDirect(GetPin(pMicrosoftDTVDVDVideoDecoder, "Video Output 1"), GetPin(pWMASFWriter, "Video Input 01"), null);
            checkHR(hr, "Can't connect Microsoft DTV-DVD Video Decoder and WM ASF Writer");
        }
Esempio n. 9
0
        public static void ConnectFilters(IGraphBuilder graphBuilder, IPin sourcePin, IPin destinationPin,
                                          bool useIntelligentConnect)
        {
            int hr = 0;

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

            if (sourcePin == null)
                throw new ArgumentNullException("sourcePin");

            if (destinationPin == null)
                throw new ArgumentNullException("destinationPin");

            if (useIntelligentConnect)
            {
                hr = graphBuilder.Connect(sourcePin, destinationPin);
                DsError.ThrowExceptionForHR(hr);
            }
            else
            {
                hr = graphBuilder.ConnectDirect(sourcePin, destinationPin, null);
                DsError.ThrowExceptionForHR(hr);
            }
        }
    private static bool TryConnect(IGraphBuilder graphBuilder, string filtername, IPin outputPin, IBaseFilter to)
    {
      bool ret = false;
      int hr;
      FilterInfo info;
      PinInfo outputInfo;

      to.QueryFilterInfo(out info);
      ReleaseComObject(info.pGraph);

      outputPin.QueryPinInfo(out outputInfo);
      DsUtils.FreePinInfo(outputInfo);

      if (info.achName.Equals(filtername))
      {
        return false; //do not connect to self
      }
      Log.Debug("Testing filter: {0}", info.achName);

      IEnumPins enumPins;
      IPin[] pins = new IPin[1];
      to.EnumPins(out enumPins);
      do
      {
        int pinsFetched;
        hr = enumPins.Next(1, pins, out pinsFetched);
        if (hr != 0 || pinsFetched == 0)
        {
          break;
        }
        PinDirection direction;
        pins[0].QueryDirection(out direction);
        if (direction == PinDirection.Input && !HasConnection(pins[0])) // && TestMediaTypes(outputPin, pins[0]))
        {
          PinInfo pinInfo;
          pins[0].QueryPinInfo(out pinInfo);
          DsUtils.FreePinInfo(pinInfo);
          Log.Debug("Testing compatibility to {0}",
                    pinInfo.name);
          //ListMediaTypes(pins[0]);
          //hr =  outputPin.Connect(pins[0], null);
          hr = graphBuilder.ConnectDirect(outputPin, pins[0], null);
          if (hr == 0)
          {
            Log.Debug("Connection succeeded");
            if (RenderOutputPins(graphBuilder, to))
            {
              Log.Info("Successfully rendered pin {0}:{1} to {2}:{3}.",
                       filtername, outputInfo.name, info.achName, pinInfo.name);
              ret = true;
              ReleaseComObject(pins[0]);
              break;
            }
            else
            {
              Log.Debug("Rendering got stuck. Trying next filter, and disconnecting {0}!", outputInfo.name);
              outputPin.Disconnect();
              pins[0].Disconnect();
            }
          }
          else
          {
            Log.Debug("Could not connect, filters are not compatible: {0:x}", hr);
          }
        }
        ReleaseComObject(pins[0]);
      } while (true);
      ReleaseComObject(enumPins);
      if (!ret)
      {
        Log.Debug("Dead end. Could not successfully connect pin {0} to filter {1}!", outputInfo.name, info.achName);
      }
      return ret;
    }
Esempio n. 11
0
        static void BuildGraph(IGraphBuilder pGraph)
        {
            int hr = 0;

            ICaptureGraphBuilder2 pBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            hr = pBuilder.SetFiltergraph(pGraph);
            checkHR(hr, "Can't SetFilterGraph");
            Guid CLSID_WDMStreamingCaptureDevice = new Guid("{65E8773D-8F56-11D0-A3B9-00A0C9223196}");
            Guid CLSID_SampleGrabber             = new Guid("{C1F400A0-3F08-11D3-9F0B-006008039E37}");
            Guid CLSID_VidoeRenderer             = new Guid("{B87BEB7B-8D29-423F-AE4D-6582C10175AC}");

            //Инициализация Веб-камеры@"EasyCamera"

            IBaseFilter pEasyCamera = CreateFilterByName(@"EasyCamera", CLSID_WDMStreamingCaptureDevice);

            hr = pGraph.AddFilter(pEasyCamera, "EasyCamera");
            checkHR(hr, "Cant add EasyCamera at graph");

            //Инициализация филтра Smart Tee
            IBaseFilter pSmartTee = (IBaseFilter) new SmartTee();

            hr = pGraph.AddFilter(pSmartTee, "Smart Tee");
            checkHR(hr, "Can't Add Smart Tee");

            //Инициализация SampleGrabber
            IBaseFilter pSampleGrabber = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_SampleGrabber));

            hr = pGraph.AddFilter(pSampleGrabber, "SampleGrabber");
            checkHR(hr, "Can't Add SampleGrabber");
            AMMediaType pSampleGrabber_pmt = new AMMediaType();

            pSampleGrabber_pmt.majorType           = MediaType.Video;
            pSampleGrabber_pmt.subType             = MediaSubType.MJPG;
            pSampleGrabber_pmt.formatType          = FormatType.VideoInfo;
            pSampleGrabber_pmt.fixedSizeSamples    = true;
            pSampleGrabber_pmt.formatSize          = 88;
            pSampleGrabber_pmt.sampleSize          = 2764800;
            pSampleGrabber_pmt.temporalCompression = false;
            VideoInfoHeader p_sampleGrabber_format = new VideoInfoHeader();

            p_sampleGrabber_format.SrcRect               = new DsRect();
            p_sampleGrabber_format.TargetRect            = new DsRect();
            p_sampleGrabber_format.BitRate               = 442368000;
            p_sampleGrabber_format.AvgTimePerFrame       = 333333;
            p_sampleGrabber_format.BmiHeader             = new BitmapInfoHeader();
            p_sampleGrabber_format.BmiHeader.Size        = 40;
            p_sampleGrabber_format.BmiHeader.Width       = 640;
            p_sampleGrabber_format.BmiHeader.Height      = 640;
            p_sampleGrabber_format.BmiHeader.Planes      = 1;
            p_sampleGrabber_format.BmiHeader.BitCount    = 24;
            p_sampleGrabber_format.BmiHeader.Compression = 1996444237;
            p_sampleGrabber_format.BmiHeader.ImageSize   = 2764800;
            pSampleGrabber_pmt.formatPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(p_sampleGrabber_format));
            Marshal.StructureToPtr(p_sampleGrabber_format, pSampleGrabber_pmt.formatPtr, false);

            hr = ((ISampleGrabber)pSampleGrabber).SetMediaType(pSampleGrabber_pmt);
            DsUtils.FreeAMMediaType(pSampleGrabber_pmt);
            checkHR(hr, "Can't mediatype");


            IBaseFilter pMJPEGDecompressor = (IBaseFilter) new MjpegDec();

            hr = pGraph.AddFilter(pMJPEGDecompressor, "MJPEG Decompressor");

            IBaseFilter pColorSpaceConverter = (IBaseFilter) new Colour();

            hr = pGraph.AddFilter(pColorSpaceConverter, "Color Space Converter");

            IBaseFilter pVideoRenderer = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_VidoeRenderer));

            hr = pGraph.AddFilter(pVideoRenderer, "Video Renderer");


            //Соединение Графа,получение Pin через готовый метод PinDirection
            hr = pGraph.ConnectDirect(DirectShowLib.DsFindPin.ByDirection(pEasyCamera, PinDirection.Output, 0),
                                      DirectShowLib.DsFindPin.ByDirection(pSmartTee, PinDirection.Input, 0), null);


            hr = pGraph.ConnectDirect(DirectShowLib.DsFindPin.ByDirection(pSmartTee, PinDirection.Output, 0),
                                      DirectShowLib.DsFindPin.ByDirection(pSampleGrabber, PinDirection.Input, 0), null);

            hr = pGraph.ConnectDirect(DirectShowLib.DsFindPin.ByDirection(pSampleGrabber, PinDirection.Output, 0),
                                      DirectShowLib.DsFindPin.ByDirection(pMJPEGDecompressor, PinDirection.Input, 0), null);

            hr = pGraph.ConnectDirect(DirectShowLib.DsFindPin.ByDirection(pMJPEGDecompressor, PinDirection.Output, 0),
                                      DirectShowLib.DsFindPin.ByDirection(pColorSpaceConverter, PinDirection.Input, 0), null);

            hr = pGraph.ConnectDirect(DirectShowLib.DsFindPin.ByDirection(pColorSpaceConverter, PinDirection.Output, 0),
                                      DirectShowLib.DsFindPin.ByDirection(pVideoRenderer, PinDirection.Input, 0), null);
        }
Esempio n. 12
0
        private void BuildGraph(DirectShowLib.DsDevice dsDevice)
        {
            int hr = 0;
            pGraph = new FilterGraph() as IFilterGraph2;

            //graph builder
            ICaptureGraphBuilder2 pBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();

            try
            {
                hr = pBuilder.SetFiltergraph(pGraph);
                DsError.ThrowExceptionForHR(hr);

                // Add camera
                IBaseFilter camera;
                //hr = pGraph.FindFilterByName(dsDevice.Name, out camera);
                hr = ((IFilterGraph2)pGraph).AddSourceFilterForMoniker(dsDevice.Mon, null, dsDevice.Name, out camera);
                DsError.ThrowExceptionForHR(hr);

                hr = pGraph.AddFilter(camera, "camera");
                DsError.ThrowExceptionForHR(hr);

                // Set format for camera
                AMMediaType pmt = new AMMediaType();
                pmt.majorType = MediaType.Video;
                pmt.subType = MediaSubType.MJPG;
                pmt.formatType = FormatType.VideoInfo;
                pmt.fixedSizeSamples = true;
                pmt.formatSize = 88;
                pmt.sampleSize = 2764800;
                pmt.temporalCompression = false;
                VideoInfoHeader format = new VideoInfoHeader();
                format.SrcRect = new DsRect();
                format.TargetRect = new DsRect();
                format.BitRate = 663552000;
                format.AvgTimePerFrame = 333333;
                format.BmiHeader = new BitmapInfoHeader();
                format.BmiHeader.Size = 40;
                format.BmiHeader.Width = 1280;
                format.BmiHeader.Height = 720;
                format.BmiHeader.Planes = 1;
                format.BmiHeader.BitCount = 24;
                format.BmiHeader.Compression = 1196444237;
                format.BmiHeader.ImageSize = 2764800;
                pmt.formatPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(format));
                Marshal.StructureToPtr(format, pmt.formatPtr, false);
                hr = ((IAMStreamConfig)DsFindPin.ByCategory(camera, PinCategory.Capture, 0)).SetFormat(pmt);
                //hr = ((IAMStreamConfig)GetPin(pUSB20Camera, "Capture")).SetFormat(pmt);
                DsUtils.FreeAMMediaType(pmt);
                DsError.ThrowExceptionForHR(hr);

                //add MJPG Decompressor
                IBaseFilter pMJPGDecompressor = (IBaseFilter)new MjpegDec();
                hr = pGraph.AddFilter(pMJPGDecompressor, "MJPG Decompressor");
                DsError.ThrowExceptionForHR(hr);

                //add color space converter
                IBaseFilter pColorSpaceConverter = (IBaseFilter)new Colour();
                hr = pGraph.AddFilter(pColorSpaceConverter, "Color space converter");
                DsError.ThrowExceptionForHR(hr);

                // Connect camera and MJPEG Decomp
                //hr = pGraph.ConnectDirect(GetPin(pUSB20Camera, "Capture"), GetPin(pMJPGDecompressor, "XForm In"), null);
                hr = pGraph.ConnectDirect(DsFindPin.ByCategory(camera, PinCategory.Capture, 0), DsFindPin.ByName(pMJPGDecompressor, "XForm In"), null);
                DsError.ThrowExceptionForHR(hr);

                // Connect MJPG Decomp and color space converter
                hr = pGraph.ConnectDirect(DsFindPin.ByName(pMJPGDecompressor, "XForm Out"), DsFindPin.ByName(pColorSpaceConverter, "Input"), null);
                DsError.ThrowExceptionForHR(hr);

                //add SampleGrabber
                //IBaseFilter pSampleGrabber = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_SampleGrabber));
                //hr = pGraph.AddFilter(pSampleGrabber, "SampleGrabber");
                IBaseFilter sampleGrabber = new SampleGrabber() as IBaseFilter;
                hr = pGraph.AddFilter(sampleGrabber, "Sample grabber");
                DsError.ThrowExceptionForHR(hr);

                // Configure the samplegrabber
                AMMediaType pSampleGrabber_pmt = new AMMediaType();
                pSampleGrabber_pmt.majorType = MediaType.Video;
                pSampleGrabber_pmt.subType = MediaSubType.ARGB32;
                pSampleGrabber_pmt.formatType = FormatType.VideoInfo;
                pSampleGrabber_pmt.fixedSizeSamples = true;
                pSampleGrabber_pmt.formatSize = 88;
                pSampleGrabber_pmt.sampleSize = 3686400;
                pSampleGrabber_pmt.temporalCompression = false;
                VideoInfoHeader pSampleGrabber_format = new VideoInfoHeader();
                pSampleGrabber_format.SrcRect = new DsRect();
                pSampleGrabber_format.TargetRect = new DsRect();
                pSampleGrabber_format.BitRate = 884736885;
                pSampleGrabber_format.AvgTimePerFrame = 333333;
                pSampleGrabber_format.BmiHeader = new BitmapInfoHeader();
                pSampleGrabber_format.BmiHeader.Size = 40;
                pSampleGrabber_format.BmiHeader.Width = 1280;
                pSampleGrabber_format.BmiHeader.Height = 720;
                pSampleGrabber_format.BmiHeader.Planes = 1;
                pSampleGrabber_format.BmiHeader.BitCount = 32;

                //pSampleGrabber_format.BmiHeader.Compression = 1196444237;
                pSampleGrabber_format.BmiHeader.ImageSize = 3686400;
                pSampleGrabber_pmt.formatPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(pSampleGrabber_format));
                Marshal.StructureToPtr(pSampleGrabber_format, pSampleGrabber_pmt.formatPtr, false);
                hr = ((ISampleGrabber)sampleGrabber).SetMediaType(pSampleGrabber_pmt);
                DsError.ThrowExceptionForHR(hr);

                //connect MJPG dec and SampleGrabber
                //hr = pGraph.ConnectDirect(GetPin(pMJPGDecompressor, "XForm Out"), GetPin(pSampleGrabber, "Input"), null);
                hr = pGraph.ConnectDirect(DsFindPin.ByName(pColorSpaceConverter, "XForm Out"), DsFindPin.ByName(sampleGrabber, "Input"), null);
                DsError.ThrowExceptionForHR(hr);

                //set callback
                hr = ((ISampleGrabber)sampleGrabber).SetCallback(this, 1);
                DsError.ThrowExceptionForHR(hr);
            }
            finally
            {
                // Clean this mess up!
            }
        }
Esempio n. 13
0
        private void BuildGraph(DirectShowLib.DsDevice dsDevice)
        {
            int hr = 0;
            pGraph = new FilterGraph() as IFilterGraph2;

            //graph builder
            ICaptureGraphBuilder2 pBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();

            try
            {
                hr = pBuilder.SetFiltergraph(pGraph);
                DsError.ThrowExceptionForHR(hr);

                // Add camera
                IBaseFilter camera;
                //hr = pGraph.FindFilterByName(dsDevice.Name, out camera);
                hr = ((IFilterGraph2)pGraph).AddSourceFilterForMoniker(dsDevice.Mon, null, dsDevice.Name, out camera);
                DsError.ThrowExceptionForHR(hr);

                hr = pGraph.AddFilter(camera, "camera");
                DsError.ThrowExceptionForHR(hr);

                // Set format for camera
                AMMediaType pmt = new AMMediaType();
                pmt.majorType = MediaType.Video;
                pmt.subType = MediaSubType.MJPG;
                pmt.formatType = FormatType.VideoInfo;
                pmt.fixedSizeSamples = true;
                pmt.formatSize = 88;
                pmt.sampleSize = 2764800;
                pmt.temporalCompression = false;
                VideoInfoHeader format = new VideoInfoHeader();
                format.SrcRect = new DsRect();
                format.TargetRect = new DsRect();
                format.BitRate = 663552000;
                format.AvgTimePerFrame = 333333;
                format.BmiHeader = new BitmapInfoHeader();
                format.BmiHeader.Size = 40;
                format.BmiHeader.Width = 1280;
                format.BmiHeader.Height = 720;
                format.BmiHeader.Planes = 1;
                format.BmiHeader.BitCount = 24;
                format.BmiHeader.Compression = 1196444237;
                format.BmiHeader.ImageSize = 2764800;
                pmt.formatPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(format));
                Marshal.StructureToPtr(format, pmt.formatPtr, false);
                hr = ((IAMStreamConfig)DsFindPin.ByCategory(camera, PinCategory.Capture, 0)).SetFormat(pmt);
                //hr = ((IAMStreamConfig)GetPin(pUSB20Camera, "Capture")).SetFormat(pmt);
                DsUtils.FreeAMMediaType(pmt);
                DsError.ThrowExceptionForHR(hr);

                //add MJPG Decompressor
                IBaseFilter pMJPGDecompressor = (IBaseFilter)new MjpegDec();
                hr = pGraph.AddFilter(pMJPGDecompressor, "MJPG Decompressor");
                DsError.ThrowExceptionForHR(hr);

                //add color space converter
                IBaseFilter pColorSpaceConverter = (IBaseFilter)new Colour();
                hr = pGraph.AddFilter(pColorSpaceConverter, "Color space converter");
                DsError.ThrowExceptionForHR(hr);

                // Connect camera and MJPEG Decomp
                //hr = pGraph.ConnectDirect(GetPin(pUSB20Camera, "Capture"), GetPin(pMJPGDecompressor, "XForm In"), null);
                hr = pGraph.ConnectDirect(DsFindPin.ByCategory(camera, PinCategory.Capture, 0), DsFindPin.ByName(pMJPGDecompressor, "XForm In"), null);
                DsError.ThrowExceptionForHR(hr);

                // Connect MJPG Decomp and color space converter
                hr = pGraph.ConnectDirect(DsFindPin.ByName(pMJPGDecompressor, "XForm Out"), DsFindPin.ByName(pColorSpaceConverter, "Input"), null);
                DsError.ThrowExceptionForHR(hr);

                //add SampleGrabber
                //IBaseFilter pSampleGrabber = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_SampleGrabber));
                //hr = pGraph.AddFilter(pSampleGrabber, "SampleGrabber");
                IBaseFilter sampleGrabber = new SampleGrabber() as IBaseFilter;
                hr = pGraph.AddFilter(sampleGrabber, "Sample grabber");
                DsError.ThrowExceptionForHR(hr);

                // Configure the samplegrabber
                AMMediaType pSampleGrabber_pmt = new AMMediaType();
                pSampleGrabber_pmt.majorType = MediaType.Video;
                pSampleGrabber_pmt.subType = MediaSubType.ARGB32;
                pSampleGrabber_pmt.formatType = FormatType.VideoInfo;
                pSampleGrabber_pmt.fixedSizeSamples = true;
                pSampleGrabber_pmt.formatSize = 88;
                pSampleGrabber_pmt.sampleSize = 3686400;
                pSampleGrabber_pmt.temporalCompression = false;
                VideoInfoHeader pSampleGrabber_format = new VideoInfoHeader();
                pSampleGrabber_format.SrcRect = new DsRect();
                pSampleGrabber_format.TargetRect = new DsRect();
                pSampleGrabber_format.BitRate = 884736885;
                pSampleGrabber_format.AvgTimePerFrame = 333333;
                pSampleGrabber_format.BmiHeader = new BitmapInfoHeader();
                pSampleGrabber_format.BmiHeader.Size = 40;
                pSampleGrabber_format.BmiHeader.Width = 1280;
                pSampleGrabber_format.BmiHeader.Height = 720;
                pSampleGrabber_format.BmiHeader.Planes = 1;
                pSampleGrabber_format.BmiHeader.BitCount = 32;

                //pSampleGrabber_format.BmiHeader.Compression = 1196444237;
                pSampleGrabber_format.BmiHeader.ImageSize = 3686400;
                pSampleGrabber_pmt.formatPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(pSampleGrabber_format));
                Marshal.StructureToPtr(pSampleGrabber_format, pSampleGrabber_pmt.formatPtr, false);
                hr = ((ISampleGrabber)sampleGrabber).SetMediaType(pSampleGrabber_pmt);
                DsError.ThrowExceptionForHR(hr);



                //connect MJPG dec and SampleGrabber
                //hr = pGraph.ConnectDirect(GetPin(pMJPGDecompressor, "XForm Out"), GetPin(pSampleGrabber, "Input"), null);
                hr = pGraph.ConnectDirect(DsFindPin.ByName(pColorSpaceConverter, "XForm Out"), DsFindPin.ByName(sampleGrabber, "Input"), null);
                DsError.ThrowExceptionForHR(hr);

                //set callback
                hr = ((ISampleGrabber)sampleGrabber).SetCallback(this, 1);
                DsError.ThrowExceptionForHR(hr);
            }
            finally
            {
                // Clean this mess up!
            }
        }
Esempio n. 14
0
            static void BuildGraph(IGraphBuilder pGraph, string srcFile1)
            {
                int hr = 0;

                //graph builder
                ICaptureGraphBuilder2 pBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

                hr = pBuilder.SetFiltergraph(pGraph);
                checkHR(hr, "Can't SetFiltergraph");

                Guid CLSID_LAVSplitterSource = new Guid("{B98D13E7-55DB-4385-A33D-09FD1BA26338}"); //LAVSplitter.ax
                Guid CLSID_LAVAudioDecoder   = new Guid("{E8E73B6B-4CB3-44A4-BE99-4F7BCB96E491}"); //LAVAudio.ax
                Guid CLSID_LAVVideoDecoder   = new Guid("{EE30215D-164F-4A92-A4EB-9D4C13390F9F}"); //LAVVideo.ax
                Guid CLSID_VideoRenderer     = new Guid("{B87BEB7B-8D29-423F-AE4D-6582C10175AC}"); //quartz.dll

                //add LAV Splitter Source
                IBaseFilter pLAVSplitterSource = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_LAVSplitterSource));

                hr = pGraph.AddFilter(pLAVSplitterSource, "LAV Splitter Source");
                checkHR(hr, "Can't add LAV Splitter Source to graph");
                //set source filename
                IFileSourceFilter pLAVSplitterSource_src = pLAVSplitterSource as IFileSourceFilter;

                if (pLAVSplitterSource_src == null)
                {
                    checkHR(unchecked ((int)0x80004002), "Can't get IFileSourceFilter");
                }
                hr = pLAVSplitterSource_src.Load(srcFile1, null);
                checkHR(hr, "Can't load file");

                //add LAV Audio Decoder
                IBaseFilter pLAVAudioDecoder = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_LAVAudioDecoder));

                hr = pGraph.AddFilter(pLAVAudioDecoder, "LAV Audio Decoder");
                checkHR(hr, "Can't add LAV Audio Decoder to graph");

                //add LAV Video Decoder
                IBaseFilter pLAVVideoDecoder = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_LAVVideoDecoder));

                hr = pGraph.AddFilter(pLAVVideoDecoder, "LAV Video Decoder");
                checkHR(hr, "Can't add LAV Video Decoder to graph");

                //connect LAV Splitter Source and LAV Video Decoder
                hr = pGraph.ConnectDirect(GetPin(pLAVSplitterSource, "Video"), GetPin(pLAVVideoDecoder, "Input"), null);
                checkHR(hr, "Can't connect LAV Splitter Source and LAV Video Decoder");

                //connect LAV Splitter Source and LAV Audio Decoder
                hr = pGraph.ConnectDirect(GetPin(pLAVSplitterSource, "Audio"), GetPin(pLAVAudioDecoder, "Input"), null);
                checkHR(hr, "Can't connect LAV Splitter Source and LAV Audio Decoder");

                //add Video Renderer
                IBaseFilter pVideoRenderer = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_VideoRenderer));

                hr = pGraph.AddFilter(pVideoRenderer, "Video Renderer");
                checkHR(hr, "Can't add Video Renderer to graph");



                //add Default DirectSound Device
                IBaseFilter pDefaultDirectSoundDevice = (IBaseFilter) new DSoundRender();

                hr = pGraph.AddFilter(pDefaultDirectSoundDevice, "Default DirectSound Device");
                checkHR(hr, "Can't add Default DirectSound Device to graph");

                //connect LAV Video Decoder and Video Renderer
                hr = pGraph.ConnectDirect(GetPin(pLAVVideoDecoder, "Output"), GetPin(pVideoRenderer, "VMR Input0"), null);
                checkHR(hr, "Can't connect LAV Video Decoder and Video Renderer");

                //connect LAV Audio Decoder and Default DirectSound Device
                hr = pGraph.ConnectDirect(GetPin(pLAVAudioDecoder, "Output"), GetPin(pDefaultDirectSoundDevice, "Audio Input pin (rendered)"), null);
                checkHR(hr, "Can't connect LAV Audio Decoder and Default DirectSound Device");
            }
 public static bool TryConnect(IGraphBuilder graphbuilder, IBaseFilter source, Guid mediaType,
                               IBaseFilter targetFilter)
 {
   bool connected = false;
   IEnumPins enumPins;
   int hr = source.EnumPins(out enumPins);
   DsError.ThrowExceptionForHR(hr);
   IPin[] pins = new IPin[1];
   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.Output)
     {
       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)
         {
           if (
             graphbuilder.ConnectDirect(pins[0], DsFindPin.ByDirection(targetFilter, PinDirection.Input, 0), null) >=
             0)
           {
             connected = true;
             break;
           }
         }
       }
     }
     ReleaseComObject(pins[0]);
   }
   ReleaseComObject(enumPins);
   return connected;
 }
Esempio n. 16
0
        /* // TODO: We need to update this
         * WTV Files Pin Mapping (pin name between ||)
         *  Audio       -> Source Pin |DVR Out - 1| -> PBDA DT Filter |In(Enc/Tag)| |Out| -> Dump |Input|
         *  Video       -> Source Pin |DVR Out - 2| -> PBDA DT Filter |In(Enc/Tag)| |Out| -> Dump |Input|
         *  Subtitle    -> Source Pin |DVR Out - 5| -> PBDA DT Filter |In(Enc/Tag)| |Out| -> Dump |Input|
         *
         * DVRMS Files Pin Mapping (pin name between ||)
         *  Audio       -> Source Pin |DVR Out - 1| -> Decrypt/Tag Filter |In(Enc/Tag)| |Out| -> Dump |Input|
         *  Video       -> Source Pin |DVR Out - 3| -> Decrypt/Tag Filter |In(Enc/Tag)| |Out| -> Dump |Input|
         *  Subtitle    -> Source Pin |DVR Out - 2| -> Decrypt/Tag Filter |In(Enc/Tag)| |Out| -> Dump |Input|
         */
        private void ConnectDecryptedDump(string sourceOutPinName, string DumpFileName)
        {
            int         hr;
            Type        comtype;
            IBaseFilter DecryptF;
            IPin        PinOut, PinIn;

            //Create the decrypt filter
            if (_CLSI_Decryptor != MediaType.Null)
            {
                _jobLog.WriteEntry(this, "Connecting Decryption filter", Log.LogEntryType.Debug);
                comtype  = Type.GetTypeFromCLSID(_CLSI_Decryptor);
                DecryptF = (IBaseFilter)Activator.CreateInstance(comtype);
                hr       = _gb.AddFilter((IBaseFilter)DecryptF, "Decrypt" + _gbFiltersCount++.ToString(CultureInfo.InvariantCulture));
                checkHR(hr);

                DecryptF.FindPin("In(Enc/Tag)", out PinIn);     // Get the decrypt filter pinIn |In(Enc/Tag)|
                _SourceF.FindPin(sourceOutPinName, out PinOut); // Get the Source filter pinOut (name taken from sourceOutPinName)

                try
                {
                    // Try to connect the decrypt filter if it is needed
                    hr = _gb.ConnectDirect(PinOut, PinIn, null); // Connect the source filter pinOut to the decrypt filter pinIn
                    checkHR(hr);
                    DecryptF.FindPin("Out", out PinOut);         // Get the Decrypt filter pinOut |Out| (for the next filter to connect to)
                }
                catch
                {
                    // Otherwise go direct
                    _SourceF.FindPin(sourceOutPinName, out PinOut); // Otherwise, go direct and get the source filter pinOut (name taken from sourceOutPinName) for the next filter to connect to
                }
            }
            else
            {
                _SourceF.FindPin(sourceOutPinName, out PinOut);  // Otherwise, go direct and get the source filter pinOut (name taken from sourceOutPinName) for the next filter to connect to
            }
            // Check if we need a Video Subtitle decoder (Line 21) (here use the Microsoft DTV decoder) - the subtitles are embedded in the Video stream

            /*if (UseVideoSubtitleDecoder)
             * {
             *  IBaseFilter SubtitleF;
             *
             *  // TODO: We need to add TEE splitter here and a new DUMP filter here and connect the tee output to the DTV decoder and then Line21 to Dump otherwise we end up with either video or Line21, we want both
             *  _jobLog.WriteEntry(this, "Connecting Video Subtitle Extraction filter", Log.LogEntryType.Debug);
             *  comtype = Type.GetTypeFromCLSID(CLSID_SubtitleDecoder);
             *  SubtitleF = (IBaseFilter)Activator.CreateInstance(comtype);
             *  hr = _gb.AddFilter((IBaseFilter)SubtitleF, "Subtitle" + _gbFilters.Count.ToString(CultureInfo.InvariantCulture));
             *  checkHR(hr);
             *  _gbFilters.Add(SubtitleF); // Keep track of filters to be released afterwards
             *
             *  // Get the subtitle filter pinIn |Video Input|
             *  SubtitleF.FindPin("Video Input", out PinIn);
             *
             *  // Try to connect the subtitle filter pinIn to the previous filter pinOut
             *  hr = _gb.ConnectDirect(PinOut, PinIn, null);
             *  checkHR(hr);
             *  SubtitleF.FindPin("~Line21 Output", out PinOut); // Get the new pinOut |~Line21 Output| from the subtitle filter for the next filter to connect to
             * }*/

            // Create the dump filter
            DumpFilter df = new DumpFilter();

            // Add the filter to the graph
            hr = _gb.AddFilter(df, "Dump" + _gbFiltersCount++.ToString(CultureInfo.InvariantCulture));
            checkHR(hr);

            // Set destination filename
            hr = df.SetFileName(DumpFileName, null);
            checkHR(hr);

            // Connect the dump filter pinIn |Input| to the previous filter pinOut
            _jobLog.WriteEntry(this, "Connecting MCEBuddy DumpStreams filter pins", Log.LogEntryType.Debug);
            hr = df.FindPin("Input", out PinIn);
            checkHR(hr);
            hr = _gb.ConnectDirect(PinOut, PinIn, null);
            checkHR(hr);

            _jobLog.WriteEntry(this, "All filters successfully connected", Log.LogEntryType.Debug);
        }
Esempio n. 17
0
        /// <summary>
        /// Connecte le File Splitter et le renderer vidéo en créant le décodeur vidéo.
        /// </summary>
        /// <param name="graph">Le graphe.</param>
        /// <param name="filtersConfig">La configuration pour ce fichier.</param>
        /// <param name="parserOutputVideoPin">Le pin de sortie vidéo</param>
        /// <param name="videoRendererInputPin">Le pin d'entrée du Renderer.</param>
        internal static void ConnectSplitterAndRendererWithDecoder(IGraphBuilder graph, ExtensionFiltersSource filtersConfig,
                                                                   IPin parserOutputVideoPin, IPin videoRendererInputPin)
        {
            FilterSource videoFilterSource = filtersConfig.VideoDecoder;

            switch (videoFilterSource.SourceType)
            {
            case FilterSourceTypeEnum.Auto:

                int hr = graph.Connect(parserOutputVideoPin, videoRendererInputPin);
                DsError.ThrowExceptionForHR(hr);

                break;

            case FilterSourceTypeEnum.External:
                if (new Guid(videoFilterSource.ExternalCLSID) == new Guid(CLSID_VIDEO_DECODER_DMO))
                {
                    // The DMO filter is handled differently
                    DMOWrapperFilter  dmoFilter = new DMOWrapperFilter();
                    IDMOWrapperFilter wrapper   = (IDMOWrapperFilter)dmoFilter;
                    hr = wrapper.Init(new Guid(CLSID_VIDEO_DECODER_DMO), DirectShowLib.DMO.DMOCategory.VideoDecoder);

                    DsError.ThrowExceptionForHR(hr);

                    if (dmoFilter is IBaseFilter decoderFilter)
                    {
                        hr = graph.AddFilter(decoderFilter, "WMVideo Decoder DMO");
                        DsError.ThrowExceptionForHR(hr);

                        IPin wmvDecoderInputPin = DsFindPin.ByDirection(decoderFilter, PinDirection.Input, 0);
                        hr = graph.ConnectDirect(parserOutputVideoPin, wmvDecoderInputPin, null);
                        DsError.ThrowExceptionForHR(hr);

                        IPin wmvDecoderOutputPin = DsFindPin.ByDirection(decoderFilter, PinDirection.Output, 0);
                        hr = graph.ConnectDirect(wmvDecoderOutputPin, videoRendererInputPin, null);
                        DsError.ThrowExceptionForHR(hr);

                        SafeRelease(wmvDecoderInputPin);
                        SafeRelease(wmvDecoderOutputPin);
                    }
                    else
                    {
                        wrapper = null;
                        SafeRelease(dmoFilter);
                        dmoFilter = null;
                    }
                }
                else
                {
                    Type        filterType     = null;
                    IBaseFilter externalFilter = null;

                    CreateFilter(videoFilterSource.ExternalCLSID, videoFilterSource.Name, ref filterType, ref externalFilter);

                    hr = graph.AddFilter(externalFilter, videoFilterSource.Name);
                    DsError.ThrowExceptionForHR(hr);

                    IPin externalDecoderInputPin = DsFindPin.ByDirection(externalFilter, PinDirection.Input, 0);
                    hr = graph.ConnectDirect(parserOutputVideoPin, externalDecoderInputPin, null);
                    DsError.ThrowExceptionForHR(hr);

                    IPin externalDecoderOutputPin = DsFindPin.ByDirection(externalFilter, PinDirection.Output, 0);
                    hr = graph.ConnectDirect(externalDecoderOutputPin, videoRendererInputPin, null);
                    DsError.ThrowExceptionForHR(hr);

                    SafeRelease(externalDecoderInputPin);
                    SafeRelease(externalDecoderOutputPin);
                }


                break;

            default:
                throw new ArgumentOutOfRangeException($"{nameof(videoFilterSource)}.{nameof(FilterSource.SourceType)}");
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Crée le graphe DirectShow avec LAVFilters
        /// </summary>
        void SetupLAVGraph()
        {
            //System.IO.FileStream fs = null;

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

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

                    //if (_graphLogLocation != null)
                    //{
                    //    fs = System.IO.File.Create(_graphLogLocation);
                    //    int r = _graph.SetLogFile(fs.Handle);
                    //}

                    //
                    // Creating FileSource filter
                    //
                    IBaseFilter sourceFilter = GraphHelper.CreateLAVSplitterSourceFilter(_graph, _sourceFilePath, out IPin parserVideoOutputPin, out IPin parserAudioOutputPin);

                    //
                    // Creating renderer
                    //
                    Type        videoRendererFilterType = null;
                    IBaseFilter videoRenderer           = null;
                    GraphHelper.CreateFilter(NULL_RENDERER, "Null Renderer", ref videoRendererFilterType, ref videoRenderer);
                    int hr = _graph.AddFilter(videoRenderer, "Null Renderer");
                    DsError.ThrowExceptionForHR(hr);

                    IPin videoRendererInputPin = DsFindPin.ByDirection(videoRenderer, PinDirection.Input, 0);

                    //
                    // Creating Video filter
                    //

                    // Connection du sample Grabber
                    var sampleGrabberFilter = (IBaseFilter)_sampleGrabber;
                    hr = _graph.AddFilter(sampleGrabberFilter, "Sample Grabber");
                    DsError.ThrowExceptionForHR(hr);
                    IPin sampleGrabberInputPin = DsFindPin.ByDirection(sampleGrabberFilter, PinDirection.Input, 0);
                    IPin sampleGrabberOuputPin = DsFindPin.ByDirection(sampleGrabberFilter, PinDirection.Output, 0);

                    //Insertion du Color Space Converter
                    Type        filterType          = null;
                    IBaseFilter colorSpaceConverter = null;
                    GraphHelper.CreateFilter(GraphHelper.CLSID_COLOR_SPACE_CONVERTER, GraphHelper.COLOR_SPACE_CONVERTER_FRIENDLYNAME, ref filterType, ref colorSpaceConverter);
                    hr = _graph.AddFilter(colorSpaceConverter, GraphHelper.COLOR_SPACE_CONVERTER_FRIENDLYNAME);
                    DsError.ThrowExceptionForHR(hr);
                    IPin colorSpaceConverterInputPin = DsFindPin.ByDirection(colorSpaceConverter, PinDirection.Input, 0);
                    GraphHelper.ConnectLAVSplitterAndRendererWithLAVDecoder(_graph, parserVideoOutputPin, colorSpaceConverterInputPin);
                    IPin colorSpaceConverterOutputPin = DsFindPin.ByDirection(colorSpaceConverter, PinDirection.Output, 0);
                    hr = _graph.ConnectDirect(colorSpaceConverterOutputPin, sampleGrabberInputPin, null);
                    DsError.ThrowExceptionForHR(hr);

                    hr = _graph.Connect(sampleGrabberOuputPin, videoRendererInputPin);
                    DsError.ThrowExceptionForHR(hr);

                    // Removes the clock to run the graph as fast as possible
                    ((IMediaFilter)_graph).SetSyncSource(null);

                    GraphHelper.SafeRelease(parserAudioOutputPin);
                    GraphHelper.SafeRelease(parserVideoOutputPin);
                    GraphHelper.SafeRelease(videoRendererInputPin);
                    GraphHelper.SafeRelease(sampleGrabberInputPin);
                    GraphHelper.SafeRelease(sampleGrabberOuputPin);
                    GraphHelper.SafeRelease(colorSpaceConverterInputPin);
                    GraphHelper.SafeRelease(colorSpaceConverterOutputPin);

                    _mediaSeeking = _graph as IMediaSeeking;
                    _mediaControl = _graph as IMediaControl;
                    _mediaEvent   = _graph as IMediaEventEx;

                    /* Attempt to set the time format */
                    hr = _mediaSeeking.SetTimeFormat(TimeFormat.MediaTime);
                    DsError.ThrowExceptionForHR(hr);
                }
                catch (Exception ex)
                {
                    this.TraceError(ex, ex.Message);

                    /* This exection will happen usually if the media does
                     * not exist or could not open due to not having the
                     * proper filters installed */
                    FreeResources();
                }
            }
            finally
            {
                //if (_graphLogLocation != null && fs != null)
                //    fs.Close();
            }
        }
 private static void ConnectPins(IGraphBuilder graphBuilder, IPin pinOut, IBaseFilter toFilter,
     string toPinName)
 {
     IPin pinIn = null;
     try
     {
         pinIn = GetPin(toFilter, toPinName);
         DsError.ThrowExceptionForHR(graphBuilder.ConnectDirect(pinOut, pinIn, null));
     }
     finally
     {
         if (pinIn != null)
         {
             Marshal.ReleaseComObject(pinIn);
         }
     }
 }