示例#1
0
        private void Config()
        {
            int hr;
            IFilterGraph gb = (IFilterGraph)new FilterGraph();
            int iDeviceIndex = 0;

            ICaptureGraphBuilder2 cgb = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;
            IMediaControl m_imc1 = gb as IMediaControl;
            hr = cgb.SetFiltergraph((IGraphBuilder)gb);

            DsDevice[] dev = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
            IBaseFilter theDevice;
            hr = ((IFilterGraph2)gb).AddSourceFilterForMoniker(dev[iDeviceIndex].Mon, null, dev[iDeviceIndex].Name, out theDevice);

            IStreamBufferSink sbs = new SBE2Sink() as IStreamBufferSink;
            hr = gb.AddFilter((IBaseFilter)sbs, "StreamBufferSink");
            DsError.ThrowExceptionForHR(hr);

            hr = cgb.RenderStream(null, null, theDevice, null, sbs as IBaseFilter);
            DsError.ThrowExceptionForHR(hr);

            hr = sbs.LockProfile(Environment.ExpandEnvironmentVariables(FILENAME));
            DsError.ThrowExceptionForHR(hr);
            SetupGraph2();

            Marshal.ReleaseComObject(cgb);
            Marshal.ReleaseComObject(theDevice);

            m_imc1.Run();
            System.Threading.Thread.Sleep(1000);
            m_imc2.Run();
            System.Threading.Thread.Sleep(1000);
        }
示例#2
0
        private void Configure()
        {
            int          hr;
            IFilterGraph gb      = (IFilterGraph) new FilterGraph();
            DsROTEntry   rot     = new DsROTEntry(gb);
            IBaseFilter  pFilter = (IBaseFilter) new MPEG2Demultiplexer();
            AMMediaType  amt     = new AMMediaType();

            amt.majorType = MediaType.Video;
            IPin pPin;

            int [] pid = new int[1];
            pid[0] = 123;

            hr = gb.AddFilter(pFilter, "fdsa");
            DsError.ThrowExceptionForHR(hr);

            IMpeg2Demultiplexer ism = (IMpeg2Demultiplexer)pFilter;

            hr = ism.CreateOutputPin(amt, "Pin1", out pPin);
            DsError.ThrowExceptionForHR(hr);

            IMPEG2PIDMap pmap = pPin as IMPEG2PIDMap;

            //hr = pmap.MapPID(1, pid, MediaSampleContent.ElementaryStream);
            //DsError.ThrowExceptionForHR(hr);
            //hr = pmap.EnumPIDMap(out m_pm);
            DsError.ThrowExceptionForHR(hr);
        }
        /// <summary>
        /// Create and add a filter from a DSFilterTreeViewNode
        /// </summary>
        /// <param name="tn"></param>
        public IBaseFilter AddFilter(DSFilterTreeViewNode tn)
        {
            int         hr     = 0;
            IBaseFilter filter = null;

            if (tn.DSFilterType == FilterType.DMO)
            {
                // create a DMO wrapper and init it with the ClassGuid
                filter = (IBaseFilter) new DMOWrapperFilter();
                IDMOWrapperFilter wrapper = (IDMOWrapperFilter)filter;
                hr = wrapper.Init(tn.ClassGuid, tn.DMOCategory);
                if (hr != 0)
                {
                    MessageBox.Show(DsError.GetErrorText(hr), "Error wrapping DMO");
                    Marshal.ReleaseComObject(filter);
                    return(null);
                }
                hr = _Graph.AddFilter(filter, tn.Text);
                if (hr != 0)
                {
                    MessageBox.Show(DsError.GetErrorText(hr), "Error Adding DMO");
                    Marshal.ReleaseComObject(filter);
                    return(null);
                }
                SyncGraphs(filter);
                return(filter);
            }
            else
            {
                // try adding it as a source filter first (this usually works for non-source filters anyway)
                hr = (_Graph as IFilterGraph2).AddSourceFilterForMoniker(tn.Moniker, null, tn.Text, out filter);

                // that didn't work.  Try AddFilterByDevicePath
                if (filter == null)
                {
                    DirectShowLib.Utils.FilterGraphTools.AddFilterByDevicePath(_Graph as IGraphBuilder, tn.DevicePath, tn.Name);
                }

                // force the DaggerGraph to reflect changes in the DS graph
                List <DSFilterNode> addedNodes = SyncGraphs(filter);

                // get the DSFilterNode that was added and give it the information
                if (addedNodes.Count == 1)
                {
                    addedNodes[0]._devicePath = tn.DevicePath;
                    addedNodes[0]._moniker    = tn.Moniker;
                }

                return(filter);
            }
        }
        private void Configure()
        {
            int          hr;
            IFilterGraph gb      = (IFilterGraph) new FilterGraph();
            DsROTEntry   rot     = new DsROTEntry(gb);
            IBaseFilter  pFilter = (IBaseFilter) new MPEG2Demultiplexer();
            AMMediaType  amt     = new AMMediaType();
            IPin         pPin;

            hr = gb.AddFilter(pFilter, "fdsa");

            IMpeg2Demultiplexer ism = (IMpeg2Demultiplexer)pFilter;

            hr = ism.CreateOutputPin(amt, "Pin1", out pPin);
            DsError.ThrowExceptionForHR(hr);

            m_sim = (IMPEG2StreamIdMap)pPin;
        }