当前位置: 首页>>代码示例>>C#>>正文


C# ISampleGrabber类代码示例

本文整理汇总了C#中ISampleGrabber的典型用法代码示例。如果您正苦于以下问题:C# ISampleGrabber类的具体用法?C# ISampleGrabber怎么用?C# ISampleGrabber使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ISampleGrabber类属于命名空间,在下文中一共展示了ISampleGrabber类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Build

        /// <summary>
        /// Creates the filter.
        /// </summary>
        /// <returns>New filter instance.</returns>
        public IBaseFilter Build()
        {
            sampleGrabber = (ISampleGrabber) new SampleGrabber();
            ConfigSampleGrabber(sampleGrabber);

            sampleGrabber.SetCallback(filter, SampleGrabberCallbackMethod);

            return (IBaseFilter) sampleGrabber;
        }
开发者ID:alex-chekhachev,项目名称:WebcamCapture.NET,代码行数:13,代码来源:FilterBuilder.cs

示例2: SampleGrabberHelper

        /// <summary>
        /// Default constructor for <see cref="SampleGrabberHelper"/> class.
        /// </summary>
        /// <param name="sampleGrabber">Pointer to COM-interface ISampleGrabber.</param>
        /// <param name="buffer_samples_of_current_frame">Flag means should helper store (buffer) samples of current frame or not.</param>
        public SampleGrabberHelper(ISampleGrabber sampleGrabber, bool buffer_samples_of_current_frame)
        {
            m_SampleGrabber = sampleGrabber;

            m_bBufferSamplesOfCurrentFrame = buffer_samples_of_current_frame;

            // tell the callback to ignore new images
            m_PictureReady = new ManualResetEvent(false);
        }
开发者ID:robotsrulz,项目名称:Sardauscan,代码行数:14,代码来源:SampleGrabberHelper.cs

示例3: MainForm

        public MainForm()
        {
            InitializeComponent();
            graphbuilder = (IGraphBuilder)new FilterGraph();
            samplegrabber = (ISampleGrabber)new SampleGrabber();
            graphbuilder.AddFilter((IBaseFilter)samplegrabber, "samplegrabber");

            mt = new AMMediaType();
            mt.majorType = MediaType.Video;
            mt.subType = MediaSubType.RGB24;
            mt.formatType = FormatType.VideoInfo;
            samplegrabber.SetMediaType(mt);
            PrintSeconds();
        }
开发者ID:sasha237,项目名称:VideoAnalyser,代码行数:14,代码来源:MainForm.cs

示例4: ConfigSampleGrabber

        private static void ConfigSampleGrabber(ISampleGrabber sb)
        {
            // set the media type
            var media = new AMMediaType
                {
                    majorType = MediaType.Video,
                    subType = MediaSubType.RGB24,
                    formatType = FormatType.VideoInfo
                };

            // that's the call to the ISampleGrabber interface
            sb.SetMediaType(media);

            DsUtils.FreeAMMediaType(media);
        }
开发者ID:alex-chekhachev,项目名称:WebcamCapture.NET,代码行数:15,代码来源:FilterBuilder.cs

示例5: CaptureForm

        public CaptureForm()
        {
            InitializeComponent();

            graph_builder = (IGraphBuilder)new FilterGraph();
            media_control = (IMediaControl)graph_builder;
            events = (IMediaEventEx)graph_builder;
            grabber = (ISampleGrabber)new SampleGrabber();

            AMMediaType media_type = new AMMediaType();
            media_type.majorType = MediaType.Video;
            media_type.subType = MediaSubType.RGB24;
            grabber.SetMediaType( media_type );
            grabber.SetCallback( this, 1 );

            cbDevices.Items.AddRange( GetDevices( FilterCategory.VideoInputDevice ) );
        }
开发者ID:pbalint,项目名称:Playground,代码行数:17,代码来源:CaptureForm.cs

示例6: SaveSizeInfo

        private void SaveSizeInfo(ISampleGrabber sampGrabber)
        {
            int hr;

            // Get the media type from the SampleGrabber
            AMMediaType media = new AMMediaType();
            hr = sampGrabber.GetConnectedMediaType(media);
            DsError.ThrowExceptionForHR(hr);

            if ((media.formatType != FormatType.VideoInfo) || (media.formatPtr == IntPtr.Zero))
            {
                throw new NotSupportedException("Unknown Grabber Media Format");
            }

            // Grab the size info
            VideoInfoHeader videoInfoHeader =
                (VideoInfoHeader) Marshal.PtrToStructure(media.formatPtr, typeof (VideoInfoHeader));
            m_videoWidth = videoInfoHeader.BmiHeader.Width;
            m_videoHeight = videoInfoHeader.BmiHeader.Height;
            m_stride = m_videoWidth*(videoInfoHeader.BmiHeader.BitCount/8);
            m_avgtimeperframe = videoInfoHeader.AvgTimePerFrame;

            DsUtils.FreeAMMediaType(media);
            media = null;
        }
开发者ID:duyisu,项目名称:MissionPlanner,代码行数:25,代码来源:OSDVideo.cs

示例7: SetupGraph

        // Build the capture graph for grabber and renderer.</summary>
        // (Control to show video in, Filename to play)
        private void SetupGraph(string FileName)
        {
            int hr;

            // Get the graphbuilder object
            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);

                // 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
                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);

                // Add the null renderer to the graph
                IBaseFilter nullrenderer = new NullRenderer() as IBaseFilter;
                hr = m_FilterGraph.AddFilter(nullrenderer, "Null renderer");
                DsError.ThrowExceptionForHR(hr);

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

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

                // Grab some other interfaces
                m_mediaEvent = m_FilterGraph as IMediaEvent;
                m_mediaCtrl = m_FilterGraph as IMediaControl;
            }
            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
        }
开发者ID:hpavlov,项目名称:occurec,代码行数:66,代码来源:DxPlayer.cs

示例8: RunWorker

        /// <summary>
        /// Worker thread that captures the images
        /// </summary>
        private void RunWorker()
        {
            try
            {
                // Create the main graph
                m_igrphbldGraph = Activator.CreateInstance(Type.GetTypeFromCLSID(FilterGraph)) as IGraphBuilder;

                // Create the webcam source
                m_sourceObject = FilterInfo.CreateFilter(m_sMonikerString);

                // Create the grabber
                m_isplGrabber = Activator.CreateInstance(Type.GetTypeFromCLSID(SampleGrabber)) as ISampleGrabber;
                m_grabberObject = m_isplGrabber as IBaseFilter;

                // Add the source and grabber to the main graph
                m_igrphbldGraph.AddFilter(m_sourceObject, "source");
                m_igrphbldGraph.AddFilter(m_grabberObject, "grabber");

                using (AMMediaType mediaType = new AMMediaType())
                {
                    mediaType.MajorType = MediaTypes.Video;
                    mediaType.SubType = MediaSubTypes.RGB32;
                    m_isplGrabber.SetMediaType(mediaType);

                    if (m_igrphbldGraph.Connect(m_sourceObject.GetPin(PinDirection.Output, 0), m_grabberObject.GetPin(PinDirection.Input, 0)) >= 0)
                    {
                        if (m_isplGrabber.GetConnectedMediaType(mediaType) == 0)
                        {
                            // During startup, this code can be too fast, so try at least 3 times
                            int retryCount = 0;
                            bool succeeded = false;
                            while ((retryCount < 3) && !succeeded)
                            {
                                // Tried again
                                retryCount++;

                                try
                                {
                                    // Retrieve the grabber information
                                    VideoInfoHeader header = (VideoInfoHeader)Marshal.PtrToStructure(mediaType.FormatPtr, typeof(VideoInfoHeader));
                                    m_grbrCapGrabber.Width = header.BmiHeader.Width;
                                    m_grbrCapGrabber.Height = header.BmiHeader.Height;

                                    // Succeeded
                                    succeeded = true;
                                }
                                catch (Exception retryException)
                                {
                                    // Trace
                                    Trace.TraceInformation("Failed to retrieve the grabber information, tried {0} time(s)", retryCount);

                                    // Sleep
                                    Thread.Sleep(50);
                                }
                            }
                        }
                    }
                    m_igrphbldGraph.Render(m_grabberObject.GetPin(PinDirection.Output, 0));
                    m_isplGrabber.SetBufferSamples(false);
                    m_isplGrabber.SetOneShot(false);
                    m_isplGrabber.SetCallback(m_grbrCapGrabber, 1);

                    // Get the video window
                    IVideoWindow wnd = (IVideoWindow)m_igrphbldGraph;
                    wnd.put_AutoShow(false);
                    wnd = null;

                    // Create the control and run
                    m_imedctrlControl = (IMediaControl)m_igrphbldGraph;
                    m_imedctrlControl.Run();

                    // Wait for the stop signal
                    while (!m_rstevStopSignal.WaitOne(0, true))
                    {
                        Thread.Sleep(10);
                    }

                    // Stop when ready
                    // _control.StopWhenReady();
                    m_imedctrlControl.Stop();

                    // Wait a bit... It apparently takes some time to stop IMediaControl
                    Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                // Trace
                Trace.WriteLine(ex);
            }
            finally
            {
                // Clean up
                this.Release();
            }
        }
开发者ID:KrisJanssen,项目名称:SIS,代码行数:99,代码来源:CCDDevice.cs

示例9: ConfigureSampleGrabber

        private void ConfigureSampleGrabber(ISampleGrabber sampGrabber)
        {
            AMMediaType media = new AMMediaType
                                    {
                                        majorType = MediaType.Video,
                                        subType = MediaSubType.RGB24,
                                        formatType = FormatType.VideoInfo
                                    };

            // Set the media type to Video/RBG24
            int hr = sampGrabber.SetMediaType(media);
            DsError.ThrowExceptionForHR(hr);

            DsUtils.FreeAMMediaType(media);

            // Configure the samplegrabber
            hr = sampGrabber.SetCallback(this, 1);
            DsError.ThrowExceptionForHR(hr);
        }
开发者ID:jmaxxz,项目名称:Ares,代码行数:19,代码来源:DSCapture.cs

示例10: SetupGraph

        /// <summary>
        /// Configures the DirectShow graph to play the selected video capture
        /// device with the selected parameters
        /// </summary>
        private void SetupGraph()
        {
            /* Clean up any messes left behind */
            FreeResources();

            try
            {
                /* Create a new graph */
                m_graph = (IGraphBuilder)new FilterGraphNoThread();

            #if DEBUG
                m_rotEntry = new DsROTEntry(m_graph);
            #endif

                /* Create a capture graph builder to help
                 * with rendering a capture graph */
                var graphBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();

                /* Set our filter graph to the capture graph */
                int hr = graphBuilder.SetFiltergraph(m_graph);
                DsError.ThrowExceptionForHR(hr);

                /* Add our capture device source to the graph */
                if (m_videoCaptureSourceChanged)
                {
                    m_captureDevice = AddFilterByName(m_graph,
                                                      FilterCategory.VideoInputDevice,
                                                      VideoCaptureSource);

                    m_videoCaptureSourceChanged = false;
                }
                else if (m_videoCaptureDeviceChanged)
                {
                    m_captureDevice = AddFilterByDevicePath(m_graph,
                                                            FilterCategory.VideoInputDevice,
                                                            VideoCaptureDevice.DevicePath);

                    m_videoCaptureDeviceChanged = false;
                }

                /* If we have a null capture device, we have an issue */
                if (m_captureDevice == null)
                    throw new Exception(string.Format("Capture device {0} not found or could not be created", VideoCaptureSource));

                if (UseYuv && !EnableSampleGrabbing)
                {
                    /* Configure the video output pin with our parameters and if it fails
                     * then just use the default media subtype*/
                    if (!SetVideoCaptureParameters(graphBuilder, m_captureDevice, MediaSubType.YUY2))
                        SetVideoCaptureParameters(graphBuilder, m_captureDevice, Guid.Empty);
                }
                else
                    /* Configure the video output pin with our parameters */
                    SetVideoCaptureParameters(graphBuilder, m_captureDevice, Guid.Empty);

                var rendererType = VideoRendererType.VideoMixingRenderer9;

                /* Creates a video renderer and register the allocator with the base class */
                m_renderer = CreateVideoRenderer(rendererType, m_graph, 1);

                if (rendererType == VideoRendererType.VideoMixingRenderer9)
                {
                    var mixer = m_renderer as IVMRMixerControl9;

                    if (mixer != null && !EnableSampleGrabbing && UseYuv)
                    {
                        VMR9MixerPrefs dwPrefs;
                        mixer.GetMixingPrefs(out dwPrefs);
                        dwPrefs &= ~VMR9MixerPrefs.RenderTargetMask;
                        dwPrefs |= VMR9MixerPrefs.RenderTargetYUV;
                        /* Prefer YUV */
                        mixer.SetMixingPrefs(dwPrefs);
                    }
                }

                if (EnableSampleGrabbing)
                {
                    m_sampleGrabber = (ISampleGrabber)new SampleGrabber();
                    SetupSampleGrabber(m_sampleGrabber);
                    hr = m_graph.AddFilter(m_sampleGrabber as IBaseFilter, "SampleGrabber");
                    DsError.ThrowExceptionForHR(hr);
                }

                IBaseFilter mux = null;
                IFileSinkFilter sink = null;
                if (!string.IsNullOrEmpty(this.m_fileName))
                {
                    hr = graphBuilder.SetOutputFileName(MediaSubType.Asf, this.m_fileName, out mux, out sink);
                    DsError.ThrowExceptionForHR(hr);

                    hr = graphBuilder.RenderStream(PinCategory.Capture, MediaType.Video, m_captureDevice, null, mux);
                    DsError.ThrowExceptionForHR(hr);

                    // use the first audio device
                    var audioDevices = DsDevice.GetDevicesOfCat(FilterCategory.AudioInputDevice);

//.........这里部分代码省略.........
开发者ID:JayBeavers,项目名称:WPF-MediaKit,代码行数:101,代码来源:VideoCapturePlayer.cs

示例11: Setup

        /// <summary>
        /// グラフの生成
        /// </summary>
        /// <param name="output_file">出力ファイル</param>
        public virtual void Setup(string output_file)
        {
            this.Dispose();

            try
            {
                CxDSCameraParam param = this.Param;

                // グラフビルダー.
                // CoCreateInstance
                GraphBuilder = (IGraphBuilder)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(GUID.CLSID_FilterGraph)));

                #region フィルタ追加.
                // 画像入力フィルタ.
                IBaseFilter capture = CreateVideoCapture(param);
                if (capture == null)
                    throw new System.IO.IOException();
                this.GraphBuilder.AddFilter(capture, "CaptureFilter");
                IPin capture_out = DSLab.Axi.FindPin(capture, 0, PIN_DIRECTION.PINDIR_OUTPUT);
                this.CaptureFilter = capture;
                this.CaptureOutPin = capture_out;

                // サンプルグラバー.
                IBaseFilter grabber = (IBaseFilter)CreateSampleGrabber();
                if (grabber == null)
                    throw new System.IO.IOException();
                this.GraphBuilder.AddFilter(grabber, "SampleGrabber");
                this.SampleGrabber = (ISampleGrabber)grabber;
                #endregion

                #region キャプチャビルダー:
                {
                    int hr = 0;
                    CaptureBuilder = (ICaptureGraphBuilder2)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(GUID.CLSID_CaptureGraphBuilder2)));
                    hr = CaptureBuilder.SetFiltergraph(GraphBuilder);

                    if (string.IsNullOrEmpty(output_file))
                    {
                        // レンダラー.
                        IBaseFilter renderer = null;
                        renderer = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(GUID.CLSID_NullRenderer)));
                        if (renderer == null)
                            throw new System.IO.IOException();
                        this.GraphBuilder.AddFilter(renderer, "Renderer");
                        this.Renderer = renderer;

            #if true
                        // IGraphBuilder.Connect の代わりに ICaptureGraphBuilder2.RenderStream を使用する.
                        // fig) [capture]-out->-in-[sample grabber]-out->-in-[null render]
                        hr = CaptureBuilder.RenderStream(new Guid(GUID.PIN_CATEGORY_CAPTURE), new Guid(GUID.MEDIATYPE_Video), capture, grabber, renderer);

            #else
                        // ピンの取得.
                        IPin grabber_in = DSLab.Axi.FindPin(grabber, 0, PIN_DIRECTION.PINDIR_INPUT);
                        IPin grabber_out = DSLab.Axi.FindPin(grabber, 0, PIN_DIRECTION.PINDIR_OUTPUT);
                        IPin renderer_in = DSLab.Axi.FindPin(renderer, 0, PIN_DIRECTION.PINDIR_INPUT);

                        // ピンの接続.
                        GraphBuilder.Connect(capture_out, grabber_in);
                        GraphBuilder.Connect(grabber_out, renderer_in);

                        // ピンの保管.
                        //SampleGrabberInPin = grabber_in;
                        //SampleGrabberOutPin = grabber_out;
                        //RendererInPin = renderer_in;
            #endif
                    }
                    else
                    {
                        IBaseFilter mux = null;
                        IFileSinkFilter sync = null;
                        hr = CaptureBuilder.SetOutputFileName(new Guid(GUID.MEDIASUBTYPE_Avi), output_file, ref mux, ref sync);
                        hr = CaptureBuilder.RenderStream(new Guid(GUID.PIN_CATEGORY_CAPTURE), new Guid(GUID.MEDIATYPE_Video), capture, grabber, mux);
                        this.Mux = mux;
                        this.Sync = sync;
                    }
                }
                #endregion

                #region 保管: フレームサイズ.
                VIDEOINFOHEADER vinfo = DSLab.Axi.GetVideoInfo(SampleGrabber);
                this.SampleGrabberCB.BitmapInfo = vinfo.bmiHeader;
                this.SampleGrabberCB.FrameSize = new Size(
                    System.Math.Abs(this.SampleGrabberCB.BitmapInfo.biWidth),
                    System.Math.Abs(this.SampleGrabberCB.BitmapInfo.biHeight)
                    );
                #endregion

                #region 保管: デバイス名称.
                try
                {
                    if (string.IsNullOrEmpty(param.FilterInfo.Name) == false)
                    {
                        this.DeviceName = param.FilterInfo.Name;
                    }
                    else
//.........这里部分代码省略.........
开发者ID:cogorou,项目名称:DSLab,代码行数:101,代码来源:CxDSCamera.cs

示例12: SetupSampleGrabber

        private void SetupSampleGrabber(ISampleGrabber sampleGrabber)
        {
            var mediaType = new DirectShowLib.AMMediaType
            {
                majorType = MediaType.Video,
                subType = MediaSubType.RGB24,
                formatType = FormatType.VideoInfo
            };

            int hr = sampleGrabber.SetMediaType(mediaType);

            DsUtils.FreeAMMediaType(mediaType);
            DsError.ThrowExceptionForHR(hr);

            hr = sampleGrabber.SetCallback(this, 0);
            DsError.ThrowExceptionForHR(hr);
        }
开发者ID:JayBeavers,项目名称:WPF-MediaKit,代码行数:17,代码来源:VideoCapturePlayer.cs

示例13: ConfigureSampleGrabber

        private void ConfigureSampleGrabber(ISampleGrabber sampGrabber)
        {
            AMMediaType media;
            int hr;

            media = new AMMediaType();

            media.majorType = MediaType.Audio;
            /*media.subType = MediaSubType.WAVE;
            media.formatType = FormatType.WaveEx;*/

            hr = sampGrabber.SetMediaType(media);
            DsError.ThrowExceptionForHR(hr);

            DsUtils.FreeAMMediaType(media);
            media = null;

            // Configure the samplegrabber
            hr = sampGrabber.SetCallback(this, 1); // buffer callback (0 = Sample callback)
            DsError.ThrowExceptionForHR(hr);
        }
开发者ID:i-e-b,项目名称:HLS---Smooth-Encoder,代码行数:21,代码来源:AudioCapture.cs

示例14: Dispose

        /// <summary>
        /// 解放
        /// </summary>
        public virtual void Dispose()
        {
            try
            {
                Stop();
            }
            catch (Exception)
            {
            }

            SampleGrabberCB.FrameSize = new Size(0, 0);
            SampleGrabberCB.Notify -= SampleGrabberCB_Notify;

            CaptureFilter = null;
            CaptureOutPin = null;
            SampleGrabber = null;
            SampleGrabberInPin = null;
            SampleGrabberOutPin = null;
            Renderer = null;
            RendererInPin = null;

            if (Seeking != null)
                Marshal.ReleaseComObject(Seeking);
            Seeking = null;

            if (GraphBuilder != null)
                Marshal.ReleaseComObject(GraphBuilder);
            GraphBuilder = null;
        }
开发者ID:cogorou,项目名称:DSLab,代码行数:32,代码来源:CxDSMediaPlayer.cs

示例15: CloseInterfaces

        // Shut down capture
        private void CloseInterfaces()
        {
            int hr;

            lock (this)
            {
                if (m_State != GraphState.Exiting)
                {
                    m_State = GraphState.Exiting;

                    // Release the thread (if the thread was started)
                    if (m_mre != null)
                    {
                        m_mre.Set();
                    }
                }

                if (m_mediaCtrl != null)
                {
                    // Stop the graph
                    hr = m_mediaCtrl.Stop();
                    m_mediaCtrl = null;
                }

                if (m_sampGrabber != null)
                {
                    Marshal.ReleaseComObject(m_sampGrabber);
                    m_sampGrabber = null;
                }

                if (m_FilterGraph != null)
                {
                    Marshal.ReleaseComObject(m_FilterGraph);
                    m_FilterGraph = null;
                }
            }
            GC.Collect();
        }
开发者ID:hpavlov,项目名称:occurec,代码行数:39,代码来源:DxPlayer.cs


注:本文中的ISampleGrabber类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。