Пример #1
0
        protected override bool InitMonitor()
        {
            IVisionMonitorConfig vmConfig = VisionMonitorConfig;

            if (vmConfig != null)
            {
                string       vsName = vmConfig.Watcher.ActiveVSName;
                IVideoSource vs     = SystemContext.VideoSourceManager.GetVideoSource(vsName);
                if (vs == null)
                {
                    vs = SystemContext.VideoSourceManager.Open(vsName, IntPtr.Zero);
                }

                if (vs != null)
                {
                    IKernelVideoSource kvs = vs as IKernelVideoSource;
                    kvs.KernelInit();

                    vs.Play();

                    return(true);
                }
            }
            return(false);
        }
Пример #2
0
        private Image GetFrame(IVideoSourceConfig config, int delay)
        {
            Image image = null;

            if (config != null)
            {
                IVideoSource vs = config.SystemContext.VideoSourceManager.GetVideoSource(config.Name);
                if (vs != null && vs.IsPlay)
                {
                    image = vs.GetFrame();
                }
                else
                {
                    IVideoSourceConfig tempVSConfig = config.Clone() as IVideoSourceConfig;
                    if (tempVSConfig != null)
                    {
                        tempVSConfig.ACEnabled = false;

                        ((CVideoSourceConfig)tempVSConfig).Name += ("_" + tempVSConfig.Handle);

                        vs = config.SystemContext.VideoSourceManager.Open(tempVSConfig, IntPtr.Zero);
                        if (vs != null)
                        {
                            vs.Play();

                            if (delay > 0)
                            {
                                Thread.Sleep(delay);
                            }

                            int n = 3;
                            image = vs.GetFrame();
                            while (image == null)
                            {
                                n--;
                                if (n < 0)
                                {
                                    break;
                                }

                                Thread.Sleep(100);
                                image = vs.GetFrame();
                            }
                            config.SystemContext.VideoSourceManager.Close(vs.Name);
                        }
                    }
                }
            }

            if (image != null)
            {
                label_imageSize.Text = string.Format("ͼÏñ³ß´ç£º{0}X{1}", image.Width, image.Height);
            }

            return(image);
        }
Пример #3
0
        public bool Play(string name)
        {
            IVideoSource vs = GetVideoSource(name);

            if (vs != null)
            {
                return(vs.Play());
            }
            return(false);
        }
Пример #4
0
        public bool Play()
        {
            if (mVideoSource == null)
            {
                Open();
            }

            if (mVideoSource != null)
            {
                return(mVideoSource.Play());
            }
            return(false);
        }
Пример #5
0
        public void PlayVideo(string vsName)
        {
            if (mVS != null && mVS.Name.Equals(vsName) && mVS.IsPlay)
            {
                return;
            }

            StopVideo();

            if (IsEnabled)
            {
                IVideoSourceConfig vsConfig = SystemContext.VideoSourceConfigManager.GetConfig(vsName);

                mVS = SystemContext.VideoSourceManager.Open(vsConfig, pictureBox_preview.Handle);
                if (mVS != null)
                {
                    mVS.Play();
                }
            }
        }
Пример #6
0
        public bool Preview()
        {
            if (mRealPlayVS != null && mRealPlayVS.IsOpen)
            {
                mRealPlayVS.SystemContext.VideoSourceManager.Close(mRealPlayVS.Name);
            }
            else
            {
                CFuncNode node = mLinkObj as CFuncNode;
                if (node != null)
                {
                    IVisionMonitorConfig config = node.ExtConfigObj as IVisionMonitorConfig;
                    if (config != null)
                    {
                        IVideoSourceConfig vsConfig = config.SystemContext.VideoSourceConfigManager.GetConfig(config.VisionParamConfig.VSName);

                        CVideoSourceConfig newVSConfig = vsConfig.Clone() as CVideoSourceConfig;
                        if (newVSConfig != null)
                        {
                            newVSConfig.Name    = vsConfig.Name + "_RealPlay_" + newVSConfig.Handle;
                            newVSConfig.Enabled = true;

                            if (mRealPlayVS != null)
                            {
                                mRealPlayVS.SystemContext.VideoSourceManager.Close(mRealPlayVS.Name);
                                mRealPlayVS = null;
                            }

                            mRealPlayVS = config.SystemContext.VideoSourceManager.Open(newVSConfig, HWnd);
                            if (mRealPlayVS != null)
                            {
                                mRealPlayVS.OnPlayStatusChanged += new PLAYSTATUS_CHANGED(DoPlayStausChanged);
                                return(mRealPlayVS.Play());
                            }
                        }
                    }
                }
            }
            return(false);
        }
Пример #7
0
        public bool Playback()
        {
            if (mBackPlayVS != null && mBackPlayVS.IsOpen)
            {
                mBackPlayVS.SystemContext.VideoSourceManager.Close(mBackPlayVS.Name);
            }
            else if (mCurIndex >= 0 && mCurIndex < Count)
            {
                IVisionMonitorAlarm visionAlarm = Goto(mCurIndex) as IVisionMonitorAlarm;
                if (visionAlarm != null)
                {
                    IVisionMonitor monitor = visionAlarm.Monitor as IVisionMonitor;
                    if (monitor != null)
                    {
                        IVisionMonitorConfig config = monitor.Config as IVisionMonitorConfig;
                        if (config != null)
                        {
                            IVideoSourceConfig vsConfig = monitor.SystemContext.VideoSourceConfigManager.GetConfig(config.VisionParamConfig.VSName);
                            if (vsConfig != null)
                            {
                                if (!vsConfig.IsRecord)
                                {
                                    IVideoSourceType vsType = vsConfig.SystemContext.VideoSourceTypeManager.GetConfig(vsConfig.Type);
                                    if (vsType != null)
                                    {
                                        string backPlayType = vsType.BackPlayType;

                                        if (backPlayType.Equals(""))
                                        {
                                            backPlayType = vsConfig.Type;
                                        }

                                        if (!backPlayType.Equals(""))
                                        {
                                            CVideoSourceConfig newVSConfig = vsConfig.Clone() as CVideoSourceConfig;
                                            if (newVSConfig != null)
                                            {
                                                newVSConfig.Name      = vsConfig.Name + "_BackPlay_" + newVSConfig.Handle;
                                                newVSConfig.Type      = backPlayType;
                                                newVSConfig.StartTime = visionAlarm.AlarmTime.AddSeconds(-10);
                                                newVSConfig.StopTime  = visionAlarm.AlarmTime;

                                                if (!backPlayType.Equals("FileVideoSource"))
                                                {
                                                    newVSConfig.FileName = "";
                                                }

                                                newVSConfig.IsRecord = false;
                                                newVSConfig.IsCycle  = false;
                                                newVSConfig.Enabled  = true;

                                                if (mBackPlayVS != null)
                                                {
                                                    mBackPlayVS.SystemContext.VideoSourceManager.Close(mBackPlayVS.Name);
                                                    mBackPlayVS = null;
                                                }

                                                mBackPlayVS = vsType.SystemContext.VideoSourceManager.Open(newVSConfig, HWnd);
                                                if (mBackPlayVS != null)
                                                {
                                                    mBackPlayVS.OnPlayStatusChanged += new PLAYSTATUS_CHANGED(DoPlayStausChanged);
                                                    if (!mBackPlayVS.Play())
                                                    {
                                                        MessageBox.Show("回放失败,可能是回放录像还未生成,请稍后再试!", "回放错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                                    }
                                                }
                                                else
                                                {
                                                    MessageBox.Show("打开录像失败,可能是回放录像还未生成,请稍后再试!", "回放错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                                }
                                            }
                                        }
                                    }
                                    return(true);
                                }
                            }
                        }
                    }

                    if (!visionAlarm.IsRecord && !visionAlarm.IsPlay)
                    {
                        return(visionAlarm.PlayAlarmRecord(HWnd));
                    }
                }
            }
            return(false);
        }