예제 #1
0
        private void Configure()
        {
            // In order to lock a profile, you have to have at least one stream
            // connected to the sink. I connect a video thru the DVVideoEnc into
            // the StreamBufferSink.
            int         hr;
            IBaseFilter pFilter;
            IBaseFilter pRender = (IBaseFilter) new VideoRendererDefault();

            ICaptureGraphBuilder2 icgb = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            m_FilterGraph = (IFilterGraph2) new FilterGraph();
            DsROTEntry ds = new DsROTEntry(m_FilterGraph);

            hr = icgb.SetFiltergraph(m_FilterGraph);
            DsError.ThrowExceptionForHR(hr);

            DsDevice [] devs = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
            hr = m_FilterGraph.AddSourceFilterForMoniker(devs[0].Mon, null, devs[0].Name, out pFilter);
            DsError.ThrowExceptionForHR(hr);

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

            hr = icgb.RenderStream(null, null, pFilter, null, pRender);
            DsError.ThrowExceptionForHR(hr);

            m_pin = DsFindPin.ByDirection(pRender, PinDirection.Input, 0);
            m_igs = (IAMGraphStreams)m_FilterGraph;

            Marshal.ReleaseComObject(pFilter);
            Marshal.ReleaseComObject(icgb);
            Marshal.ReleaseComObject(pRender);
        }
예제 #2
0
        /*
         * // This version of FindCaptureDevice is provide for education only.
         * // A second version using the DsDevice helper class is define later.
         * public IBaseFilter FindCaptureDevice()
         * {
         *      int hr = 0;
         #if USING_NET11
         * UCOMIEnumMoniker classEnum = null;
         * UCOMIMoniker[] moniker = new UCOMIMoniker[1];
         #else
         *      IEnumMoniker classEnum = null;
         *      IMoniker[] moniker = new IMoniker[1];
         #endif
         *      object source = null;
         *
         *      // Create the system device enumerator
         *      ICreateDevEnum devEnum = (ICreateDevEnum)new CreateDevEnum();
         *
         *      // Create an enumerator for the video capture devices
         *      hr = devEnum.CreateClassEnumerator( FilterCategory.VideoInputDevice, out classEnum, 0 );
         *      DsError.ThrowExceptionForHR( hr );
         *
         *      // The device enumerator is no more needed
         *      Marshal.ReleaseComObject( devEnum );
         *
         *      // If there are no enumerators for the requested type, then
         *      // CreateClassEnumerator will succeed, but classEnum will be NULL.
         *      if( classEnum == null )
         *      {
         *              throw new ApplicationException( "No video capture device was detected.\r\n\r\n" +
         *                                                                         "This sample requires a video capture device, such as a USB WebCam,\r\n" +
         *                                                                         "to be installed and working properly.  The sample will now close." );
         *      }
         *
         *      // Use the first video capture device on the device list.
         *      // Note that if the Next() call succeeds but there are no monikers,
         *      // it will return 1 (S_FALSE) (which is not a failure).  Therefore, we
         *      // check that the return code is 0 (S_OK).
         #if USING_NET11
         * int i;
         * if (classEnum.Next (moniker.Length, moniker, IntPtr.Zero) == 0)
         #else
         *      while( classEnum.Next( moniker.Length, moniker, IntPtr.Zero ) == 0 )
         #endif
         *      {
         *              // Bind Moniker to a filter object
         *              Guid iid = typeof( IBaseFilter ).GUID;
         *              moniker[0].BindToObject( null, null, ref iid, out source );
         *      }
         *      //else
         *      //{
         *      //	throw new ApplicationException( "Unable to access video capture device!" );
         *      //}
         *
         *      // Release COM objects
         *      Marshal.ReleaseComObject( moniker[0] );
         *      Marshal.ReleaseComObject( classEnum );
         *
         *      // An exception is thrown if cast fail
         *      return (IBaseFilter)source;
         * }
         */
        // Uncomment this version of FindCaptureDevice to use the DsDevice helper class
        // (and comment the first version of course)



        public void GetInterfaces()
        {
            int hr = 0;

            // An exception is thrown if cast fail
            this.graphBuilder        = (IGraphBuilder) new FilterGraph();
            this.captureGraphBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();
            this.mediaControl        = (IMediaControl)this.graphBuilder;
            this.videoWindow         = (IVideoWindow)this.graphBuilder;
            this.mediaEventEx        = (IMediaEventEx)this.graphBuilder;
            this.graph_streams       = (IAMGraphStreams)this.graphBuilder;
            this.graph_filter        = (IMediaFilter)this.graphBuilder;

            hr = this.mediaEventEx.SetNotifyWindow(this.Handle, WM_GRAPHNOTIFY, IntPtr.Zero);
            DsError.ThrowExceptionForHR(hr);
        }