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


C# ISampleGrabber.SetCallback方法代码示例

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


在下文中一共展示了ISampleGrabber.SetCallback方法的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: 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

示例3: ConfigureSampleGrabber

 private void ConfigureSampleGrabber(ISampleGrabber sampGrabber)
 {
     AMMediaType media;
     int hr;
     // Set the media type to Video/YUY2
     media = new AMMediaType();
     media.majorType = MediaType.Video;
     media.subType = MediaSubType.YUY2;
     media.formatType = FormatType.VideoInfo;
     hr = sampGrabber.SetMediaType(media);
     DsError.ThrowExceptionForHR(hr);
     DsUtils.FreeAMMediaType(media);
     media = null;
     hr = sampGrabber.SetCallback(this, 1);
     DsError.ThrowExceptionForHR(hr);
 }
开发者ID:krisztianmukli,项目名称:RobotControlPanel,代码行数:16,代码来源:VideoHandler.cs

示例4: createGraph


//.........这里部分代码省略.........
                    videoCompressorFilter = (IBaseFilter)Marshal.BindToMoniker(VideoCompressor.MonikerString);
                    hr = graphBuilder.AddFilter(videoCompressorFilter, "Video Compressor");
                    if (hr < 0) Marshal.ThrowExceptionForHR(hr);
                }

                // Get the audio compressor and add it to the filter graph
                if (AudioCompressor != null)
                {
                    audioCompressorFilter = (IBaseFilter)Marshal.BindToMoniker(AudioCompressor.MonikerString);
                    hr = graphBuilder.AddFilter(audioCompressorFilter, "Audio Compressor");
                    if (hr < 0) Marshal.ThrowExceptionForHR(hr);
                }

                // Retrieve the stream control interface for the video device
                // FindInterface will also add any required filters
                // (WDM devices in particular may need additional
                // upstream filters to function).

                // Try looking for an interleaved media type
                object o;
                cat = PinCategory.Capture;
                med = MediaType.Interleaved;
                Guid iid = typeof(IAMStreamConfig).GUID;
                hr = captureGraphBuilder.FindInterface(
                    ref cat, ref med, videoDeviceFilter, ref iid, out o);

                if (hr != 0)
                {
                    // If not found, try looking for a video media type
                    med = MediaType.Video;
                    hr = captureGraphBuilder.FindInterface(
                        ref cat, ref med, videoDeviceFilter, ref iid, out o);

                    if (hr != 0)
                        o = null;
                }
                videoStreamConfig = o as IAMStreamConfig;

                // Retrieve the stream control interface for the audio device
                o = null;
                cat = PinCategory.Capture;
                med = MediaType.Audio;
                iid = typeof(IAMStreamConfig).GUID;
                hr = captureGraphBuilder.FindInterface(
                    ref cat, ref med, audioDeviceFilter, ref iid, out o);
                if (hr != 0)
                    o = null;
                audioStreamConfig = o as IAMStreamConfig;

                // Retreive the media control interface (for starting/stopping graph)
                mediaControl = (IMediaControl)graphBuilder;

                // Reload any video crossbars
                if (videoSources != null) videoSources.Dispose(); videoSources = null;

                // Reload any audio crossbars
                if (audioSources != null) audioSources.Dispose(); audioSources = null;

                // Reload any property pages exposed by filters
                if (propertyPages != null) propertyPages.Dispose(); propertyPages = null;

                // Reload capabilities of video device
                videoCaps = null;

                // Reload capabilities of video device
                audioCaps = null;

                // Retrieve TV Tuner if available
                o = null;
                cat = PinCategory.Capture;
                med = MediaType.Interleaved;
                iid = typeof(IAMTVTuner).GUID;
                hr = captureGraphBuilder.FindInterface(
                    ref cat, ref med, videoDeviceFilter, ref iid, out o);
                if (hr != 0)
                {
                    med = MediaType.Video;
                    hr = captureGraphBuilder.FindInterface(
                        ref cat, ref med, videoDeviceFilter, ref iid, out o);
                    if (hr != 0)
                        o = null;
                }
                IAMTVTuner t = o as IAMTVTuner;
                if (t != null)
                    tuner = new Tuner(t);

                videoInfoHeader = (VideoInfoHeader)Marshal.PtrToStructure(media.formatPtr, typeof(VideoInfoHeader));
                Marshal.FreeCoTaskMem(media.formatPtr); media.formatPtr = IntPtr.Zero;
                hr = sampGrabber.SetBufferSamples(false);
                if (hr == 0)
                    hr = sampGrabber.SetOneShot(false);
                if (hr == 0)
                    hr = sampGrabber.SetCallback(new SampleGrabberCallback(), 1);
                if (hr < 0)
                    Marshal.ThrowExceptionForHR(hr);
                // Update the state now that we are done
                graphState = GraphState.Created;

            }
        }
开发者ID:RajibTheKing,项目名称:DesktopClient,代码行数:101,代码来源:StartVideoCapture.cs

示例5: ConfigureSampleGrabber

        /// <summary>
        /// Set the options on the sample grabber
        /// </summary>
        /// <param name="sampGrabber">The samp grabber.</param>
        private void ConfigureSampleGrabber(ISampleGrabber sampGrabber)
        {
            int hr;
            AMMediaType media = new AMMediaType();

            // Set the media type to Video/ARBG32
            media.majorType = MediaType.Video;
            media.subType = MediaSubType.ARGB32;
            //obsolete:
            //media.subType = MediaSubType.RGB24;

            media.formatType = FormatType.VideoInfo;
            hr = sampGrabber.SetMediaType(media);
            DsError.ThrowExceptionForHR(hr);

            DsUtils.FreeAMMediaType(media);
            media = null;

            // Configure the samplegrabber callback
            hr = sampGrabber.SetCallback(this, 1);
            DsError.ThrowExceptionForHR(hr);
        }
开发者ID:culiniac,项目名称:quavs,代码行数:26,代码来源:VideoCapture.cs

示例6: ConfigureSampleGrabber

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

            // Set the media type
            media.majorType = MediaType.Video;
            if (bytes_per_pixel == 1)
                media.subType = MediaSubType.RGB8;
            else
                media.subType = MediaSubType.RGB24;
            media.formatType = FormatType.VideoInfo;
            hr = sampGrabber.SetMediaType(media);
            DsError.ThrowExceptionForHR(hr);

            DsUtils.FreeAMMediaType(media);
            media = null;

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

示例7: ConfigureSampleGrabber

        /// <summary> Set the options on the sample grabber </summary>
        private void ConfigureSampleGrabber(ISampleGrabber sampGrabber)
        {
            AMMediaType media;
            int hr;

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

            DsUtils.FreeAMMediaType(media);
            media = null;

            // Choose to call BufferCB instead of SampleCB
            hr = sampGrabber.SetCallback(this, 1);
            DsError.ThrowExceptionForHR(hr);
        }
开发者ID:nikolasbe,项目名称:ugent-dma-videoshotdetection,代码行数:21,代码来源:Capture.cs

示例8: 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

示例9: 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

示例10: ConfigureSampleGrabber

        /// <summary>
        /// Configures the sample grabber
        /// </summary>
        /// <param name="sampGrabber"></param>
        private void ConfigureSampleGrabber(ISampleGrabber sampGrabber)
        {
            AMMediaType media;
            int status;

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

            DsUtils.FreeAMMediaType(media);
            media = null;

            // Configure the samplegrabber
            status = sampGrabber.SetCallback(this, 1);
            DsError.ThrowExceptionForHR(status);
        }
开发者ID:deveck,项目名称:dotNetWebcamLibrary,代码行数:24,代码来源:ImageCapture.cs

示例11: InitializeCapture

        private void InitializeCapture()
        {
            graphBuilder = (IGraphBuilder)new FilterGraph();
            mediaControl = (IMediaControl)graphBuilder;

            captureGraphBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
            hr = captureGraphBuilder.SetFiltergraph(graphBuilder);
            DsError.ThrowExceptionForHR(hr);

            IBaseFilter videoInput = GetVideoInputObject();
            if (null != videoInput)
            {
                SetConfigurations(videoInput);

                sampleGrabber = new SampleGrabber() as ISampleGrabber;
                hr = graphBuilder.AddFilter((IBaseFilter)sampleGrabber, "Render");
                DsError.ThrowExceptionForHR(hr);

                hr = graphBuilder.AddFilter(videoInput, "Camera");
                DsError.ThrowExceptionForHR(hr);

                AMMediaType type = new AMMediaType() { majorType = MediaType.Video, subType = MediaSubType.ARGB32, formatType = FormatType.VideoInfo };
                hr = sampleGrabber.SetMediaType(type);
                DsError.ThrowExceptionForHR(hr);
                DsUtils.FreeAMMediaType(type);

                sampleGrabber.SetBufferSamples(false);
                sampleGrabber.SetOneShot(false);
                sampleGrabber.GetConnectedMediaType(new AMMediaType());

                sampleGrabber.SetCallback((ISampleGrabberCB)this, 1);
                hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, videoInput, null, sampleGrabber as IBaseFilter);
                DsError.ThrowExceptionForHR(hr);

                Marshal.ReleaseComObject(videoInput);
            }
        }
开发者ID:flair2005,项目名称:CameraPositioner,代码行数:37,代码来源:VideoCaptureComponent.cs

示例12: ConfigureSampleGrabber

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

            DsUtils.FreeAMMediaType(media);

            hr = sampGrabber.SetCallback(this, 1);
            DsError.ThrowExceptionForHR(hr);
        }
开发者ID:pingmeaschandru,项目名称:LiveMeeting,代码行数:16,代码来源:VideoCapture.cs

示例13: Init

        /// <summary>
        /// Worker thread that captures the images
        /// </summary>
        private void Init()
        {
            try
            {
                log.Trace("Start worker thread");
                // Create the main graph
                _graph = Activator.CreateInstance(Type.GetTypeFromCLSID(FilterGraph)) as IGraphBuilder;

                // Create the webcam source
                _sourceObject = FilterInfo.CreateFilter(_monikerString);

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

                // Add the source and grabber to the main graph
                _graph.AddFilter(_sourceObject, "source");
                _graph.AddFilter(_grabberObject, "grabber");

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

                    if (_graph.Connect(_sourceObject.GetPin(PinDirection.Output, 0), _grabberObject.GetPin(PinDirection.Input, 0)) >= 0)
                    {
                        if (_grabber.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));
                                    _capGrabber.Width = header.BmiHeader.Width;
                                    _capGrabber.Height = header.BmiHeader.Height;

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

                                    // Sleep
                                    Thread.Sleep(50);
                                }
                            }
                        }
                    }
                    _graph.Render(_grabberObject.GetPin(PinDirection.Output, 0));
                    _grabber.SetBufferSamples(false);
                    _grabber.SetOneShot(false);
                    _grabber.SetCallback(_capGrabber, 1);
                    log.Trace("_grabber set up");

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

                    // Create the control and run
                    _control = (IMediaControl)_graph;
                    _control.Run();
                    log.Trace("control runs");

                    // Wait for the stop signal
                    //while (!_stopSignal.WaitOne(0, true))
                    //{
                    //    Thread.Sleep(10);
                    //}
                }
            }catch (Exception ex)
            {
                // Trace
                log.Debug(ex);
                Release();
            }
        }
开发者ID:hunludvig,项目名称:MulticamRecorder,代码行数:90,代码来源:CapDevice.cs

示例14: SetUpForTs

        public void SetUpForTs(ISampleGrabberCB grabber, int methodToCall)
        {
            FilterGraphTools.DisconnectPins(mpeg2Demux);
            //FilterGraphTools.DisconnectPins(demodulator);
            FilterGraphTools.DisconnectPins(audioRenderer);
            FilterGraphTools.DisconnectPins(videoRenderer);
            //graphBuilder.RemoveFilter(audioRenderer);
            //graphBuilder.RemoveFilter(videoRenderer);

            sampleGrabber = (ISampleGrabber)new SampleGrabber();
            AMMediaType media = new AMMediaType();

            media.majorType = MediaType.Stream;
            media.subType = MediaSubType.Mpeg2Transport;
            media.formatType = FormatType.MpegStreams;
            sampleGrabber.SetOneShot(false);
            sampleGrabber.SetBufferSamples(true);
            int hr = sampleGrabber.SetMediaType(media);
            DsError.ThrowExceptionForHR(hr);

            graphBuilder.AddFilter((IBaseFilter)sampleGrabber, "Sample Grabber");

            nullRenderer = (IBaseFilter)new NullRenderer();
            graphBuilder.AddFilter(nullRenderer, "NULL Renderer");

            IPin pinIn = DsFindPin.ByName((IBaseFilter)sampleGrabber, "Input");
            IPin pinOut = DsFindPin.ByDirection(capture, PinDirection.Output, 0);

            IEnumMediaTypes eMedia;
            pinOut.EnumMediaTypes(out eMedia);

            AMMediaType[] mediaTypes = new AMMediaType[1];
            eMedia.Next(mediaTypes.Length, mediaTypes, IntPtr.Zero);

            hr = sampleGrabber.SetMediaType(mediaTypes[0]);
            DsError.ThrowExceptionForHR(hr);

            pinOut.Disconnect();
            PinInfo info;
            pinOut.QueryPinInfo(out info);

            hr = graphBuilder.ConnectDirect(pinOut, pinIn, mediaTypes[0]);
            //hr = graphBuilder.Connect(pinOut, pinIn);
            DsError.ThrowExceptionForHR(hr);

            // Release the Pin
            Marshal.ReleaseComObject(pinIn);

            pinIn = DsFindPin.ByName(nullRenderer, "In");
            pinOut = DsFindPin.ByName((IBaseFilter)sampleGrabber, "Output");

            hr = graphBuilder.Connect(pinOut, pinIn);
            DsError.ThrowExceptionForHR(hr);

            sampleGrabber.SetCallback(grabber, methodToCall);

            // Release the Pin
            Marshal.ReleaseComObject(pinIn);
            pinIn = null;
        }
开发者ID:sportzworld,项目名称:sky-firmware-downloader,代码行数:60,代码来源:BDAGraphBuilder.cs

示例15: RunWorker

        void RunWorker()
        {
            try
            {

                graph = Activator.CreateInstance(Type.GetTypeFromCLSID(FilterGraph)) as IGraphBuilder;

                sourceObject = FilterInfo.CreateFilter(deviceMoniker);

                grabber = Activator.CreateInstance(Type.GetTypeFromCLSID(SampleGrabber)) as ISampleGrabber;
                grabberObject = grabber as IBaseFilter;

                graph.AddFilter(sourceObject, "source");
                graph.AddFilter(grabberObject, "grabber");

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

                    if (graph.Connect(sourceObject.GetPin(PinDirection.Output, 0), grabberObject.GetPin(PinDirection.Input, 0)) >= 0)
                    {
                        if (grabber.GetConnectedMediaType(mediaType) == 0)
                        {
                            VideoInfoHeader header = (VideoInfoHeader)Marshal.PtrToStructure(mediaType.FormatPtr, typeof(VideoInfoHeader));
                            capGrabber.Width = header.BmiHeader.Width;
                            capGrabber.Height = header.BmiHeader.Height;
                        }
                    }
                    graph.Render(grabberObject.GetPin(PinDirection.Output, 0));
                    grabber.SetBufferSamples(false);
                    grabber.SetOneShot(false);
                    grabber.SetCallback(capGrabber, 1);

                    IVideoWindow wnd = (IVideoWindow)graph;
                    wnd.put_AutoShow(false);
                    wnd = null;

                    control = (IMediaControl)graph;
                    control.Run();

                    while (!stopSignal.WaitOne(0, true))
                    {
                        Thread.Sleep(10);
                    }

                    control.StopWhenReady();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
            finally
            {
                graph = null;
                sourceObject = null;
                grabberObject = null;
                grabber = null;
                capGrabber = null;
                control = null;

            }
        }
开发者ID:evilmachina,项目名称:theMachine,代码行数:65,代码来源:CapDevice.cs


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