예제 #1
0
        private void Config2()
        {
            Guid g = typeof(IBaseFilter).GUID;

            DsDevice[]  devs;
            IBaseFilter ibf, ibf2;
            object      o;

            int           hr;
            IFilterGraph2 ifg = new FilterGraph() as IFilterGraph2;

            ibf = m_rs as IBaseFilter;
            hr  = ifg.AddFilter(ibf, "resizer");
            DsError.ThrowExceptionForHR(hr);

            devs = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
            devs[1].Mon.BindToObject(null, null, ref g, out o);
            ibf2 = o as IBaseFilter;
            hr   = ifg.AddFilter(ibf2, "camera");
            DsError.ThrowExceptionForHR(hr);

            ICaptureGraphBuilder2 cgb = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;

            hr = cgb.SetFiltergraph(ifg);
            DsError.ThrowExceptionForHR(hr);

            hr = cgb.RenderStream(null, null, ibf2, null, ibf);
            DsError.ThrowExceptionForHR(hr);
        }
예제 #2
0
        private IFilterGraph2 BuildGraph(string sFileName)
        {
            int         hr;
            IBaseFilter ibfRenderer  = null;
            IBaseFilter ibfAVISource = null;
            IPin        IPinIn       = null;
            IPin        IPinOut      = null;

            IFilterGraph2 graphBuilder = new FilterGraph() as IFilterGraph2;

            m_dsrot = new DsROTEntry(graphBuilder);

            try
            {
                // Get the file source filter
                ibfAVISource = new AsyncReader() as IBaseFilter;

                // Add it to the graph
                hr = graphBuilder.AddFilter(ibfAVISource, "Ds.NET AsyncReader");
                Marshal.ThrowExceptionForHR(hr);

                // Set the file name
                IFileSourceFilter fsf = ibfAVISource as IFileSourceFilter;
                hr = fsf.Load(sFileName, null);
                Marshal.ThrowExceptionForHR(hr);

                IPinOut = DsFindPin.ByDirection(ibfAVISource, PinDirection.Output, 0);

                // Get the default video renderer
                ibfRenderer = (IBaseFilter) new VideoRendererDefault();

                // Add it to the graph
                hr = graphBuilder.AddFilter(ibfRenderer, "Ds.NET VideoRendererDefault");
                Marshal.ThrowExceptionForHR(hr);
                IPinIn = DsFindPin.ByDirection(ibfRenderer, PinDirection.Input, 0);

                hr = graphBuilder.Connect(IPinOut, IPinIn);
                Marshal.ThrowExceptionForHR(hr);
            }
            catch
            {
                Marshal.ReleaseComObject(graphBuilder);
                throw;
            }
            finally
            {
                Marshal.ReleaseComObject(ibfAVISource);
                Marshal.ReleaseComObject(ibfRenderer);
                Marshal.ReleaseComObject(IPinIn);
                Marshal.ReleaseComObject(IPinOut);
            }

            return(graphBuilder);
        }
        private IFilterGraph2 BuildGraph(string sFileName)
        {
            int hr;

            IFilterGraph2 graphBuilder = new FilterGraph() as IFilterGraph2;

            m_dsrot = new DsROTEntry(graphBuilder);

            try
            {
                // Get the file source filter
                m_Source = new AsyncReader() as IBaseFilter;

                // Add it to the graph
                hr = graphBuilder.AddFilter(m_Source, "Ds.NET AsyncReader");
                Marshal.ThrowExceptionForHR(hr);

                // Set the file name
                IFileSourceFilter fsf = m_Source as IFileSourceFilter;
                hr = fsf.Load(sFileName, null);
                Marshal.ThrowExceptionForHR(hr);

                // Get the interface we are testing
                m_icgb2 = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;
            }
            catch
            {
                Marshal.ReleaseComObject(graphBuilder);
                throw;
            }

            return(graphBuilder);
        }
        private void TestEm()
        {
            int hr;
            AllocatorProperties prop = new AllocatorProperties();
            Guid grf = typeof(IBaseFilter).GUID;

            prop.cbAlign  = 1;
            prop.cbBuffer = 3000000;
            prop.cbPrefix = 0;
            prop.cBuffers = 12;

            hr = m_ibn.SuggestAllocatorProperties(prop);
            DsError.ThrowExceptionForHR(hr);

            IGraphBuilder ifg = new FilterGraph() as IGraphBuilder;
            DsROTEntry    rot = new DsROTEntry(ifg);

            hr = ifg.AddFilter(m_ibf, "Device");
            DsError.ThrowExceptionForHR(hr);

            ICaptureGraphBuilder2 icgb2 = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;

            hr = icgb2.SetFiltergraph(ifg);
            DsError.ThrowExceptionForHR(hr);

            hr = icgb2.RenderStream(null, null, m_ibf, null, null);
            DsError.ThrowExceptionForHR(hr);

            // Returns E_FAIL for all my devices, so I wrote my own filter
            // that implements it for a test.  Note: You CANNOT use "out" here.
            hr = m_ibn.GetAllocatorProperties(prop);
            //DsError.ThrowExceptionForHR(hr);
            rot.Dispose();
        }
        private void Config2()
        {
            int           hr;
            IFilterGraph2 fg;
            ISBE2Crossbar iSBE2Crossbar;

            fg = new FilterGraph() as IFilterGraph2;
            DsROTEntry rot = new DsROTEntry(fg);

            IBaseFilter streamBuffer = (IBaseFilter) new StreamBufferSource();

            m_se = streamBuffer as ISBE2SpanningEvent;
            m_mc = fg as IMediaControl;

            hr = fg.AddFilter(streamBuffer, "SBS");
            DsError.ThrowExceptionForHR(hr);

            IFileSourceFilter fs = streamBuffer as IFileSourceFilter;

            hr = fs.Load(@"C:\Users\Public\Recorded TV\Sample Media\win7_scenic-demoshort_raw.wtv", null);
            DsError.ThrowExceptionForHR(hr);

            iSBE2Crossbar = streamBuffer as ISBE2Crossbar;
            hr            = iSBE2Crossbar.EnableDefaultMode(CrossbarDefaultFlags.None);
            DsError.ThrowExceptionForHR(hr);

            HookupGraphEventService(fg);
            RegisterForSBEGlobalEvents();
        }
예제 #6
0
        private void Config()
        {
            IFilterGraph2 fg;
            ISBE2Crossbar iSBE2Crossbar;

            fg = new FilterGraph() as IFilterGraph2;
            IBaseFilter streamBuffer = (IBaseFilter) new StreamBufferSource();
            int         hr;

            hr = fg.AddFilter(streamBuffer, "SBS");
            DsError.ThrowExceptionForHR(hr);

            IFileSourceFilter fs = streamBuffer as IFileSourceFilter;

            hr = fs.Load(@"C:\Users\Public\Recorded TV\Sample Media\win7_scenic-demoshort_raw.wtv", null);
            DsError.ThrowExceptionForHR(hr);

            iSBE2Crossbar = streamBuffer as ISBE2Crossbar;
            hr            = iSBE2Crossbar.EnableDefaultMode(CrossbarDefaultFlags.None);
            DsError.ThrowExceptionForHR(hr);

            IMediaControl mc = fg as IMediaControl;

            hr = mc.Run();
            DsError.ThrowExceptionForHR(hr);

            System.Threading.Thread.Sleep(10);

            hr = iSBE2Crossbar.EnumStreams(out m_es);
            DsError.ThrowExceptionForHR(hr);

            Debug.Assert(m_es != null);
        }
예제 #7
0
 public FrameGrabber(DsDevice camDevice)
 {
     IFilterGraph2 filterGraph;
     ICaptureGraphBuilder2 graphBuilder;
     IBaseFilter camBase, nullRenderer;
     ISampleGrabber sampleGrabber;
     filterGraph = new FilterGraph() as IFilterGraph2;
     mediaCtrl = filterGraph as IMediaControl;
     graphBuilder = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;
     HRCheck(graphBuilder.SetFiltergraph(filterGraph));
     // Add camera
     HRCheck(filterGraph.AddSourceFilterForMoniker(
         camDevice.Mon, null, camDevice.Name, out camBase));
     // Add sample grabber
     sampleGrabber = new SampleGrabber() as ISampleGrabber;
     var mType = new AMMediaType()
     {
         majorType = MediaType.Video,
         subType = MediaSubType.RGB24,
         formatType = FormatType.VideoInfo
     };
     HRCheck(sampleGrabber.SetMediaType(mType));
     DsUtils.FreeAMMediaType(mType);
     HRCheck(sampleGrabber.SetCallback(this, 1));
     HRCheck(filterGraph.AddFilter(sampleGrabber as IBaseFilter, "CamGrabber"));
     // Add null renderer
     nullRenderer = new NullRenderer() as IBaseFilter;
     HRCheck(filterGraph.AddFilter(nullRenderer, "Null renderer"));
     // Render the webcam through the grabber and the renderer
     HRCheck(graphBuilder.RenderStream(PinCategory.Capture, MediaType.Video,
         camBase, sampleGrabber as IBaseFilter, nullRenderer));
     // Get resulting picture size
     mType = new AMMediaType();
     HRCheck(sampleGrabber.GetConnectedMediaType(mType));
     if (mType.formatType != FormatType.VideoInfo || mType.formatPtr == IntPtr.Zero)
     {
         throw new NotSupportedException("Unknown grabber media format");
     }
     var videoInfoHeader = Marshal.PtrToStructure(mType.formatPtr,
         typeof(VideoInfoHeader)) as VideoInfoHeader;
     width = videoInfoHeader.BmiHeader.Width;
     height = videoInfoHeader.BmiHeader.Height;
     Console.WriteLine("{0} x {1}", width, height); 
     stride = width * (videoInfoHeader.BmiHeader.BitCount / 8);
     DsUtils.FreeAMMediaType(mType);
     HRCheck(mediaCtrl.Run());
 }
        private void Config()
        {
            int           hr;
            ISBE2Crossbar ISBE2Crossbar;
            IFilterGraph2 fg;

            fg = new FilterGraph() as IFilterGraph2;
            IBaseFilter streamBuffer = (IBaseFilter) new StreamBufferSource();

            hr = fg.AddFilter(streamBuffer, "SBS");

            IFileSourceFilter fs = streamBuffer as IFileSourceFilter;

            hr = fs.Load(@"C:\Users\Public\Recorded TV\Sample Media\win7_scenic-demoshort_raw.wtv", null);

            ISBE2Crossbar = streamBuffer as ISBE2Crossbar;

            hr = ISBE2Crossbar.EnableDefaultMode(CrossbarDefaultFlags.None);
            DsError.ThrowExceptionForHR(hr);

            hr = ISBE2Crossbar.GetInitialProfile(out m_pProfile);
            DsError.ThrowExceptionForHR(hr);
        }
예제 #9
0
        public void TestConnectDisconnectConnectedToConnectionMediaType()
        {
            int         hr;
            IBaseFilter aviSplitter  = null;
            IBaseFilter ibfAVISource = null;
            IPin        pinIn        = null;
            IPin        pinOut       = null;

            IFilterGraph2 graphBuilder = new FilterGraph() as IFilterGraph2;

            try
            {
                ibfAVISource = new AsyncReader() as IBaseFilter;

                // Add it to the graph
                hr = graphBuilder.AddFilter(ibfAVISource, "Ds.NET AsyncReader");
                Marshal.ThrowExceptionForHR(hr);

                // Set the file name
                IFileSourceFilter fsf = ibfAVISource as IFileSourceFilter;
                hr = fsf.Load(@"foo.avi", null);
                Marshal.ThrowExceptionForHR(hr);
                pinOut = DsFindPin.ByDirection(ibfAVISource, PinDirection.Output, 0);

                // Get the avi splitter
                aviSplitter = (IBaseFilter) new AviSplitter();

                // Add it to the graph
                hr = graphBuilder.AddFilter(aviSplitter, "Ds.NET AviSplitter");
                Marshal.ThrowExceptionForHR(hr);
                pinIn = DsFindPin.ByDirection(aviSplitter, PinDirection.Input, 0);

                Assert.IsNotNull(pinOut);
                Assert.IsNotNull(pinIn);

                // Test Connect
                hr = pinOut.Connect(pinIn, null);
                Marshal.ThrowExceptionForHR(hr);


                // Test ConnectedTo
                IPin pinConnect;
                hr = pinOut.ConnectedTo(out pinConnect);
                Marshal.ThrowExceptionForHR(hr);
                Assert.AreEqual(pinIn, pinConnect);


                // Test ConnectionMediaType
                AMMediaType mediaType = new AMMediaType();
                hr = pinIn.ConnectionMediaType(mediaType);
                Marshal.ThrowExceptionForHR(hr);
                Assert.IsNotNull(mediaType);
                Assert.IsNotNull(mediaType.majorType);

                // Test Disconnect
                hr = pinOut.Disconnect();
                Marshal.ThrowExceptionForHR(hr);
            }
            finally
            {
                Marshal.ReleaseComObject(graphBuilder);
            }
        }
예제 #10
0
        private IFilterGraph2 BuildGraph(string sFileName)
        {
            int           hr;
            IBaseFilter   ibfRenderer  = null;
            IBaseFilter   ibfAVISource = null;
            IPin          IPinIn       = null;
            IPin          IPinOut      = null;
            IPin          iSampleIn    = null;
            IPin          iSampleOut   = null;
            SampleGrabber sg           = null;

            IFilterGraph2 graphBuilder = new FilterGraph() as IFilterGraph2;

            try
            {
                // Get the file source filter
                ibfAVISource = new AsyncReader() as IBaseFilter;

                // Add it to the graph
                hr = graphBuilder.AddFilter(ibfAVISource, "Ds.NET AsyncReader");
                Marshal.ThrowExceptionForHR(hr);

                // Set the file name
                IFileSourceFilter fsf = ibfAVISource as IFileSourceFilter;
                hr = fsf.Load(sFileName, null);
                Marshal.ThrowExceptionForHR(hr);

                IPinOut = DsFindPin.ByDirection(ibfAVISource, PinDirection.Output, 0);

                // Get a SampleGrabber
                sg = new SampleGrabber();
                IBaseFilter grabFilt = sg as IBaseFilter;
                m_isg = sg as ISampleGrabber;

                // Set the media type to Video/RBG24
                AMMediaType media;
                media            = new AMMediaType();
                media.majorType  = MediaType.Video;
                media.subType    = MediaSubType.RGB24;
                media.formatType = FormatType.VideoInfo;
                hr = m_isg.SetMediaType(media);
                Marshal.ThrowExceptionForHR(hr);

                // Add the sample grabber to the graph
                hr = graphBuilder.AddFilter(grabFilt, "Ds.NET SampleGrabber");
                Marshal.ThrowExceptionForHR(hr);

                iSampleIn  = DsFindPin.ByDirection(grabFilt, PinDirection.Input, 0);
                iSampleOut = DsFindPin.ByDirection(grabFilt, PinDirection.Output, 0);

                // Get the default video renderer
                ibfRenderer = (IBaseFilter) new VideoRendererDefault();

                // Add it to the graph
                hr = graphBuilder.AddFilter(ibfRenderer, "Ds.NET VideoRendererDefault");
                Marshal.ThrowExceptionForHR(hr);
                IPinIn = DsFindPin.ByDirection(ibfRenderer, PinDirection.Input, 0);

                // Connect the file to the sample grabber
                hr = graphBuilder.Connect(IPinOut, iSampleIn);
                Marshal.ThrowExceptionForHR(hr);

                // Connect the sample grabber to the renderer
                hr = graphBuilder.Connect(iSampleOut, IPinIn);
                Marshal.ThrowExceptionForHR(hr);
            }
            catch
            {
                Marshal.ReleaseComObject(graphBuilder);
                throw;
            }
            finally
            {
                Marshal.ReleaseComObject(ibfRenderer);
                Marshal.ReleaseComObject(ibfAVISource);
                Marshal.ReleaseComObject(IPinIn);
                Marshal.ReleaseComObject(IPinOut);
                Marshal.ReleaseComObject(iSampleIn);
                Marshal.ReleaseComObject(iSampleOut);
            }

            return(graphBuilder);
        }
예제 #11
0
        private IFilterGraph2 BuildGraph(string sFileName)
        {
            int           hr;
            IBaseFilter   ibfRenderer  = null;
            IBaseFilter   ibfAVISource = null;
            IPin          IPinIn       = null;
            IPin          IPinOut      = null;
            IPin          iSampleIn    = null;
            IPin          iSampleOut   = null;
            SampleGrabber sg           = null;

            IFilterGraph2 graphBuilder = new FilterGraph() as IFilterGraph2;

            try
            {
                // Get the file source filter
                ibfAVISource = new AsyncReader() as IBaseFilter;

                // Add it to the graph
                hr = graphBuilder.AddFilter(ibfAVISource, "Ds.NET AsyncReader");
                Marshal.ThrowExceptionForHR(hr);

                // Set the file name
                IFileSourceFilter fsf = ibfAVISource as IFileSourceFilter;
                hr = fsf.Load(sFileName, null);
                Marshal.ThrowExceptionForHR(hr);

                IPinOut = DsFindPin.ByDirection(ibfAVISource, PinDirection.Output, 0);

                // Get a SampleGrabber
                sg = new SampleGrabber();
                IBaseFilter    grabFilt = sg as IBaseFilter;
                ISampleGrabber isg      = sg as ISampleGrabber;

                // Add the sample grabber to the graph
                hr = graphBuilder.AddFilter(grabFilt, "Ds.NET SampleGrabber");
                Marshal.ThrowExceptionForHR(hr);

                iSampleIn  = DsFindPin.ByDirection(grabFilt, PinDirection.Input, 0);
                iSampleOut = DsFindPin.ByDirection(grabFilt, PinDirection.Output, 0);

                // Get the default video renderer
                ibfRenderer = (IBaseFilter) new VideoRendererDefault();

                // Add it to the graph
                hr = graphBuilder.AddFilter(ibfRenderer, "Ds.NET VideoRendererDefault");
                Marshal.ThrowExceptionForHR(hr);
                IPinIn = DsFindPin.ByDirection(ibfRenderer, PinDirection.Input, 0);

                // Connect the file to the sample grabber
                hr = graphBuilder.Connect(IPinOut, iSampleIn);
                Marshal.ThrowExceptionForHR(hr);

                // Connect the sample grabber to the renderer
                hr = graphBuilder.Connect(iSampleOut, IPinIn);
                Marshal.ThrowExceptionForHR(hr);

                // Configure the sample grabber
                ConfigureSampleGrabber(isg);

                // Grab a copy of the mediatype being used.  Needed
                // in one of the tests
                m_MediaType = new AMMediaType();
                hr          = IPinOut.ConnectionMediaType(m_MediaType);
                Marshal.ThrowExceptionForHR(hr);
            }
            catch
            {
                Marshal.ReleaseComObject(graphBuilder);
                throw;
            }
            finally
            {
                Marshal.ReleaseComObject(ibfRenderer);
                Marshal.ReleaseComObject(ibfAVISource);
                Marshal.ReleaseComObject(IPinIn);
                Marshal.ReleaseComObject(IPinOut);
                Marshal.ReleaseComObject(iSampleIn);
                Marshal.ReleaseComObject(iSampleOut);
                Marshal.ReleaseComObject(sg);
            }

            return(graphBuilder);
        }
예제 #12
0
        private bool IsVideoHaveAudio(Control hWin, string FileName)
        {
            int hr = 0;

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

            // Get a ICaptureGraphBuilder2 to help build the graph
            ICaptureGraphBuilder2 icgb2 = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;

            try
            {
                // Link the ICaptureGraphBuilder2 to the IFilterGraph2
                hr = icgb2.SetFiltergraph(m_FilterGraph);
                DsError.ThrowExceptionForHR(hr);

//#if DEBUG
//                // Allows you to view the graph with GraphEdit File/Connect
//                m_DsRot = new DsROTEntry(m_FilterGraph);
//#endif
                // Add the filters necessary to render the file.  This function will
                // work with a number of different file types.
                IBaseFilter sourceFilter = null;
                hr = m_FilterGraph.AddSourceFilter(FileName, FileName, out sourceFilter);
                DsError.ThrowExceptionForHR(hr);

                // Get the SampleGrabber interface
                ISampleGrabber m_sampGrabber = (ISampleGrabber) new SampleGrabber();
                IBaseFilter    baseGrabFlt   = (IBaseFilter)m_sampGrabber;



                // Configure the Sample Grabber
                ConfigureSampleGrabber(m_sampGrabber);

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



                // Connect the pieces together, use the default renderer
                hr = icgb2.RenderStream(null, null, sourceFilter, baseGrabFlt, null);

                DsError.ThrowExceptionForHR(hr);

                // Now that the graph is built, read the dimensions of the bitmaps we'll be getting
                SaveSizeInfo(m_sampGrabber);

                // Configure the Video Window
                IVideoWindow m_videoWindow = m_FilterGraph as IVideoWindow;
                ConfigureVideoWindow(m_videoWindow, hWin);

                // Grab some other interfaces
                IMediaEvent   m_mediaEvent   = m_FilterGraph as IMediaEvent;
                IMediaControl m_mediaCtrl    = m_FilterGraph as IMediaControl;
                IMediaSeeking m_mediaSeeking = m_FilterGraph as IMediaSeeking;

                try
                {
                    IBaseFilter pAudioRenderer = (IBaseFilter) new DSoundRender();
                    hr = m_FilterGraph.AddFilter(pAudioRenderer, "Audio Renderer");
                    DsError.ThrowExceptionForHR(hr);

                    hr = icgb2.RenderStream(null, MediaType.Audio, sourceFilter, null, pAudioRenderer);
                    //     DsError.ThrowExceptionForHR(hr);
                    // hr = m_mediaSeeking.SetRate(0.5);
                }
                catch
                {
                }
            }
            finally
            {
                if (icgb2 != null)
                {
                    Marshal.ReleaseComObject(icgb2);
                    icgb2 = null;
                }
            }
#if DEBUG
            // Double check to make sure we aren't releasing something
            // important.
            GC.Collect();
            GC.WaitForPendingFinalizers();
#endif

            CloseInterfaces();
            return(hr == 0);
        }
예제 #13
0
        /// <summary>
        ///     Build the filter graph
        /// </summary>
        /// <param name="hWin">Window to draw into</param>
        private void SetupGraph(Control hWin)
        {
            // Get the graphbuilder object
            m_FilterGraph = new FilterGraph() as IFilterGraph2;

            // Get a ICaptureGraphBuilder2 to help build the graph
            var captureGraphBuilder = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;

            try
            {
                // Link the ICaptureGraphBuilder2 to the IFilterGraph2
                var hr = captureGraphBuilder.SetFiltergraph(m_FilterGraph);
                DsError.ThrowExceptionForHR(hr);

#if DEBUG
                // Allows you to view the graph with GraphEdit File/Connect
                m_DsRot = new DsROTEntry(m_FilterGraph);
#endif

                // Our data source
                var source = new GenericSampleSourceFilter() as IBaseFilter;

                try
                {
                    // Get the pin from the filter so we can configure it
                    var ipin = DsFindPin.ByDirection(source, PinDirection.Output, 0);

                    // x264vfw
                    // {D76E2820-1563-11CF-AC98-00AA004C0FA9}
                    // MediaType_Video
                    // Pins: input(0), output(0)

                    // DirectVobSub
                    // {93A22E7A-5091-45EF-BA61-6DA26156A5D0}
                    // Pins:
                    //      Input - Name: Video, Id: In
                    //      Input - Name: Input, id: Input,
                    //                  majortype: MEDIATYPE_Subtitle {E487EB08-6B26-4BE9-9DD3-993434D313FD}
                    //                  subtype: MEDIASUBTYPE_ASS {326444F7-686F-47FF-A4B2-C8C96307B4C2}
                    //                  formattype: FORMAT_SubtitleInfo {A33D2F7D-96BC-4337-B23B-A8B9FBC295E9}
                    //      Output - Name: Output, Id: Out
                    // Interfaces: IAMStreamSelect, IBaseFilter, IMediaFilter, IPersist, ISpecifyPropertyPages, IUnknown

                    // IMemInputPin
                    // {56A8689D-0AD4-11CE-B03A-0020AF0BA770}

                    try
                    {
                        // Configure the pin using the provided BitmapInfo
                        //this.ConfigurePusher(ipin as IGenericSampleConfig);


                        var genericSampleConfig = ipin as IGenericSampleConfig;
                        m_ImageHandler.SetMediaType(genericSampleConfig);

                        // Specify the callback routine to call with each sample
                        hr = genericSampleConfig.SetBitmapCB(m_ImageHandler);
                        DsError.ThrowExceptionForHR(hr);
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(ipin);
                    }

                    // Add the filter to the graph
                    hr = m_FilterGraph.AddFilter(source, "GenericSampleSourceFilter");
                    Marshal.ThrowExceptionForHR(hr);

                    // IFileSourceFilter
                    // {56A868A6-0AD4-11CE-B03A-0020AF0BA770}

                    // Connect the filters together, use the default renderer
                    hr = captureGraphBuilder.RenderStream(null, null, source, null, null);
                    // DsError.ThrowExceptionForHR( hr );  // Ignore any error.  Blindly assume there is no video

                    hr = captureGraphBuilder.RenderStream(null, MediaType.Audio, source, null, null);
                    // DsError.ThrowExceptionForHR( hr ); // Ignore any error.  Blindly assume there is no audio
                }
                finally
                {
                    Marshal.ReleaseComObject(source);
                }

                // Configure the Video Window
                var videoWindow = m_FilterGraph as IVideoWindow;
                ConfigureVideoWindow(videoWindow, hWin);

                // Grab some other interfaces
                m_mediaCtrl = m_FilterGraph as IMediaControl;
            }
            finally
            {
                Marshal.ReleaseComObject(captureGraphBuilder);
            }
        }
예제 #14
0
        private void SetupGraph(DsDevice dev, int iWidth, int iHeight, short iBPP, Control hControl)
        {
            int hr;

            IAMVideoControl m_VidControl  = null;
            IFilterGraph2   m_FilterGraph = null;
            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
                DsROTEntry 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
                IPin 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;
                }
            }
        }