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


C# IMediaControl.StopWhenReady方法代码示例

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


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

示例1: RunWorker

        /// <summary>
        ///     Worker thread that captures the images
        /// </summary>
        private void RunWorker()
        {
            try
            {
                // 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 (Exception)
                                {
                                    // Trace
                                    Trace.TraceInformation(
                                        "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);

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

                    // Create the control and run
                    Control = (IMediaControl) Graph;
                    Control.Run();

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

                    // Stop when ready
                    Control.StopWhenReady();
                }
            }
            catch (Exception ex)
            {
                // Trace
                Trace.WriteLine(ex);
            }
            finally
            {
                // Clean up
                Release();
            }
        }
开发者ID:raouldc,项目名称:OptiDev,代码行数:100,代码来源:CapDevice.cs

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


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