Exemplo n.º 1
0
        private void VideoDragDropHandling(object sender, VideoSourceInfo video)
        {
            VideoPanel panel = sender as VideoPanel;

            if (panel != null)
            {
                int index = _Videoes.FindIndex(vp => vp == panel);
                if (index >= 0)
                {
                    RemoveVideoPanel(panel);

                    //视频类型不同的,重新创建视频
                    VideoPanel p = CreateVideoPanel(video.VideoSourceType, panel.Name, panel.Visible);
                    p.Left          = panel.Left;
                    p.Top           = panel.Top;
                    p.Width         = panel.Width;
                    p.Height        = panel.Height;
                    _Videoes[index] = p;

                    int aIndex = _ActiveVideoes.FindIndex(vp => vp == panel);
                    if (aIndex >= 0)
                    {
                        _ActiveVideoes[aIndex] = p;
                    }

                    p.VideoSource = video;
                    p.Play(true);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 抓拍图片
        /// </summary>
        /// <param name="video">要抓拍的摄像机</param>
        /// <param name="path">抓拍图片路径,如摄像机自动抓拍,返回抓拍到的图片路径</param>
        /// <param name="optimized">如果启用优化,则发现视频没有打开时不再尝试打开视频,而是直接返回</param>
        /// <returns></returns>
        public bool SnapShotTo(VideoSourceInfo video, ref string path, bool optimized, bool force)
        {
            bool       success = false;
            VideoPanel vp      = videoGrid.VideoPanelCollection.SingleOrDefault(v => (v.VideoSource == video));

            if (vp != null)
            {
                //如果没有启用视频抓拍性能优化功能,则在抓拍时如果视频没有打开,会先尝试打开视频,启用优化后,视频由地感检测车到时打开,在抓拍时就不负责打开视频
                //这样的话如果系统中存在有问题的视频,也不会影响软件的处理速度
                if (!vp.IsReadyForSnapshot && !optimized)
                {
                    vp.OpenForSnapshot(false);
                }
                if (vp.IsReadyForSnapshot)
                {
                    success = vp.SnapShotTo(ref path, 1000, force);
                    if (optimized)
                    {
                        lock (_TagLocker)
                        {
                            vp.Tag = success ? path : "fail"; //抓拍失败时也要通知下一次不要再继续抓拍了
                        }
                    }
                }
            }
            return(success);
        }
Exemplo n.º 3
0
        public bool StartPreview(CameraInfo camera, VideoSourceInfo videoSourceInfo, VideoControl vc, int streamIndex = 0)
        {
            if (vc.Locked == true)//图像被锁定
            {
                return(false);
            }

            vc.ErrorMessage = "";

            this.LogModule?.Debug($"准备打开实时预览: ({camera.ID}){camera.Name} 设备:{videoSourceInfo.IP}:{videoSourceInfo.Port} 连接码:{camera.CameraCode}");

            //关闭已经打开的视频
            if (vc.Mode != ShowMode.Stop)
            {
                this.StopVideo(vc);
            }

            VideoSourceBase vs = this.getVideoSourceByType(videoSourceInfo.Type);

            if (vs == null)
            {
                this.LogModule?.Error("未支持的设备类型");
                return(false);
            }
            camera.VideoSourceInfo = videoSourceInfo;
            bool ret = vs.StartPreview(camera, vc, streamIndex);

            if (ret == true)
            {
                vc.Mode = ShowMode.Real;
                this.m_VideoControlTable[vc] = vs;
                vc.CurrentCamera             = camera;
            }
            return(ret);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 抓拍图片
        /// </summary>
        /// <param name="video">要抓拍的摄像机</param>
        /// <param name="optimized">如果启用优化,则发现视频没有打开时不再尝试打开视频,而是直接返回</param>
        /// <returns></returns>
        public bool SnapShotTo(VideoSourceInfo video, string path, bool optimized)
        {
            bool       success = false;
            VideoPanel vp      = videoGrid.VideoPanelCollection.SingleOrDefault(v => (v.VideoSource == video));

            if (vp != null)
            {
                //如果没有启用视频抓拍性能优化功能,则在抓拍时如果视频没有打开,会先尝试打开视频,启用优化后,视频由地感检测车到时打开,在抓拍时就不负责打开视频
                //这样的话如果系统中存在有问题的视频,也不会影响软件的处理速度
                if (vp.Status != VideoStatus.Playing && !optimized)
                {
                    vp.Play(false);
                }
                if (vp.Status == VideoStatus.Playing)
                {
                    success = vp.SnapShotTo(path);
                    if (optimized)
                    {
                        lock (_TagLocker)
                        {
                            vp.Tag = success ? path : "fail"; //抓拍失败时也要通知下一次不要再继续抓拍了
                        }
                    }
                }
            }
            return(success);
        }
Exemplo n.º 5
0
        public bool StartPlayback(CameraInfo camera, VideoSourceInfo videoSourceInfo, VideoControl vc, DateTime start, DateTime end)
        {
            if (vc.Locked == true)//图像被锁定
            {
                return(false);
            }
            this.LogModule?.Debug($"准备打开回放: ({camera.ID}){camera.Name} 设备:{videoSourceInfo.IP}:{videoSourceInfo.Port} 连接码:{camera.CameraCode} 时间:{start}--{end}");

            vc.ErrorMessage = "";
            //关闭已经打开的视频
            if (vc.Mode != ShowMode.Stop)
            {
                this.StopVideo(vc);
            }

            VideoSourceBase vs = this.getVideoSourceByType(videoSourceInfo.Type);

            if (vs == null)
            {
                this.LogModule?.Error("未支持的设备类型");
                return(false);
            }
            camera.VideoSourceInfo = videoSourceInfo;
            bool ret = vs.StartPlaybackByTime(camera, vc, start, end);

            if (ret == true)
            {
                vc.Mode = ShowMode.Playback;
                this.m_VideoControlTable[vc] = vs;
                vc.CurrentCamera             = camera;
                vc.PBStatus = VideoControl.PB_Status.Play;
            }
            return(ret);
        }
Exemplo n.º 6
0
        private void procVideo_StartPlayback(WSRequest request)
        {
            var req = JsonConvert.DeserializeObject <WSVideoRequest_StartPlayback>(request.Params.ToString());

            VideoSourceInfo videoSourceInfo = new VideoSourceInfo()
            {
                ID       = req.SourceID,
                IP       = req.SourceIP,
                Port     = req.SourcePort,
                User     = req.SourceUser,
                Password = req.SourcePassword,
                Type     = (VideoSourceType)req.SourceType,
                Name     = req.SourceName
            };

            CameraInfo cameraInfo = new CameraInfo()
            {
                ID         = req.CameraID,
                CameraCode = req.CameraCode,
                Name       = req.CameraName
            };

            VideoControl vc = this.VideoManager.GetVideoControl(req.PanelID, req.VCIndex);

            if (vc == null)
            {
                this.LogModule.Error("找不到指定控件");
                return;
            }
            this.VideoManager.StartPlayback(cameraInfo, videoSourceInfo, vc, req.StartTime, req.EndTime);
        }
Exemplo n.º 7
0
        protected override object GetItemFromInput()
        {
            VideoSourceInfo info = null;

            if (IsAdding)
            {
                info = new VideoSourceInfo();
            }
            else
            {
                info = UpdatingItem as VideoSourceInfo;
            }
            info.VideoName      = this.txtName.Text.Trim();
            info.MediaSource    = this.txtMediaSource.Text.Trim();
            info.Channel        = this.txtChannel.IntergerValue;
            info.UserName       = this.txtUserName.Text.Trim();
            info.Password       = this.txtPassword.Text.Trim();
            info.IsForCarPlate  = this.chkForCarPlate.Checked;
            info.ConnectTimeOut = this.txtConnectTimeOut.IntergerValue;
            info.ControlPort    = this.txtControlPort.IntergerValue;
            info.StreamPort     = this.txtStreamPort.IntergerValue;
            if (Entrance != null)
            {
                info.EntranceID = Entrance.EntranceID;
            }
            return(info);
        }
Exemplo n.º 8
0
 /// <summary>
 /// 显示视频节点
 /// </summary>
 /// <param name="node"></param>
 /// <param name="info"></param>
 public void RenderVideoSource(TreeNode node, VideoSourceInfo info)
 {
     node.Tag  = info;
     node.Text = info.VideoName;
     node.SelectedImageIndex = 3;
     node.ImageIndex         = 3;
 }
Exemplo n.º 9
0
        public override bool StartPreview(CameraInfo camera, VideoControl vc, int StreamIndex = 0)
        {
            VideoSourceInfo videoSourceInfo = camera.VideoSourceInfo;
            int             loginID         = Hik_Open8200API.GetLoginID(videoSourceInfo.IP, (int)videoSourceInfo.Port, videoSourceInfo.User, videoSourceInfo.Password);

            if (loginID == -1)
            {
                string error = Hik_Open8200API.GetLastError();
                this.LogModule.Error($"初始化登录服务器失败, 错误码:{error}, 设备{videoSourceInfo.IP}:{videoSourceInfo.Port} ");
                return(false);
            }

            int playHandle = Hik_Open8200API.Std_StartRealPlay(loginID, camera.CameraCode, vc.VControl.Handle, StreamIndex, null, IntPtr.Zero);

            if (playHandle < 0)
            {
                string error = Hik_Open8200API.GetLastError();
                Hik_Open8200API.Std_StopRealPlay(playHandle);
                vc.VControl.Refresh();
                this.LogModule.Error($"打开图像失败: 错误码:{error}, 摄像机标识: {camera.CameraCode}");
                Hik_Open8200API.Std_StopRealPlay(playHandle);
                return(false);
            }

            ControlInfo_Preview cm = new ControlInfo_Preview()
            {
                LoginHandle = loginID, Camera = camera, PlayHandle = playHandle, VideoSource = videoSourceInfo, VC = vc, StreamIndex = StreamIndex
            };

            this.m_ControlTable[vc] = cm;
            return(true);
        }
Exemplo n.º 10
0
        //获取空闲的视频
        private VideoPanel GetFreeVideoPanel(VideoSourceInfo video)
        {
            if (video != null)
            {
                VideoPanel panel = _Videoes.FirstOrDefault(vp => vp.VideoSource == null);
                if (panel != null)
                {
                    if (video.VideoSourceType != panel.VideoType)
                    {
                        int index = _Videoes.FindIndex(vp => vp == panel);
                        if (index >= 0)
                        {
                            RemoveVideoPanel(panel);

                            //视频类型不同的,重新创建视频
                            VideoPanel p = CreateVideoPanel(video.VideoSourceType, panel.Name, panel.Visible);
                            p.Left          = panel.Left;
                            p.Top           = panel.Top;
                            p.Width         = panel.Width;
                            p.Height        = panel.Height;
                            _Videoes[index] = p;

                            return(p);
                        }
                    }
                }
                return(panel);
            }
            return(null);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 增加一个视频节点
        /// </summary>
        /// <param name="entrance"></param>
        /// <param name="video"></param>
        /// <returns></returns>
        public TreeNode AddVideoSourceNode(TreeNode entrance, VideoSourceInfo video)
        {
            TreeNode node = new TreeNode();

            entrance.Nodes.Add(node);
            allVideoNodes.Add(node);
            RenderVideoSource(node, video);
            return(node);
        }
Exemplo n.º 12
0
        /// <summary>
        /// 清除最近保存的抓拍图片信息
        /// </summary>
        /// <param name="video">摄像机</param>
        public void ClearSnapShot(VideoSourceInfo video)
        {
            VideoPanel vp = videoGrid.VideoPanelCollection.SingleOrDefault(v => (v.VideoSource == video));

            if (vp != null)
            {
                vp.ClearSnapShot();
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// 获取视频节点
 /// </summary>
 /// <param name="videoID"></param>
 /// <returns></returns>
 public TreeNode GetVideoNode(int videoID)
 {
     foreach (TreeNode node in allVideoNodes)
     {
         VideoSourceInfo video = node.Tag as VideoSourceInfo;
         if (video != null && video.VideoID == videoID)
         {
             return(node);
         }
     }
     return(null);
 }
Exemplo n.º 14
0
        public bool Run(string url, string username, string password)
        {
            var t = new VideoSourceInfo();

            t.ConnectionString    = "rtsp://192.168.1.120";
            t.Login               = "******";
            t.Password            = "******";
            t.DesiredMaxFrameRate = 10;
            var ss = AS.Video.Sources.Basic.OpenCv.OpenCvVideoSourceCreator.TryToCreateVideoSource(t);

            ss.NewFrame += Ss_NewFrame;
            ss.Start();
            return(true);
        }
Exemplo n.º 15
0
        protected override void ItemShowing()
        {
            VideoSourceInfo info = (VideoSourceInfo)UpdatingItem;

            this.txtName.Text             = info.VideoName;
            this.txtMediaSource.Text      = info.MediaSource;
            this.txtChannel.IntergerValue = info.Channel;
            this.txtUserName.Text         = info.UserName;
            this.txtPassword.Text         = info.Password;
            this.txtControlPort.Text      = info.ControlPort.ToString();
            this.txtStreamPort.Text       = info.StreamPort.ToString();
            this.txtConnectTimeOut.Text   = info.ConnectTimeOut.ToString();
            this.chkForCarPlate.Checked   = info.IsForCarPlate;
            this.Text = info.VideoName;
        }
Exemplo n.º 16
0
 /// <summary>
 /// 抓拍图片
 /// </summary>
 /// <param name="info">摄像机</param>
 /// <param name="force">是否强制重新抓拍,不管之前有没有抓拍到图片</param>
 /// <returns>抓拍图片的地址,返回空时表示抓拍失败</returns>
 public string CapturePicture(VideoSourceInfo info, bool force)
 {
     try
     {
         CarPlateDevice device = _Devices.FirstOrDefault(item => item.IP == info.MediaSource);
         if (SnapShotTo(device, force))
         {
             return(device.SnapPath);
         }
     }
     catch (Exception ex)
     {
         Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
     }
     return(string.Empty);
 }
Exemplo n.º 17
0
        /// <summary>
        /// 更新控制板,如没有视频,则新插入视频记录
        /// </summary>
        /// <param name="info"></param>
        /// <param name="withPrimaryKey">是否插入主键值</param>
        /// <returns></returns>
        public CommandResult UpdateOrInsert(VideoSourceInfo info, bool withPrimaryKey)
        {
            VideoSourceInfo original = provider.GetByID(info.VideoID).QueryObject;

            if (original != null)
            {
                return(provider.Update(info, original));
            }
            else if (withPrimaryKey)
            {
                return(provider.InsertWithPrimaryKey(info));
            }
            else
            {
                return(provider.Insert(info));
            }
        }
Exemplo n.º 18
0
 /// <summary>
 /// 清除抓拍图片信息
 /// </summary>
 /// <param name="info">摄像机</param>
 public void ClearCapture(VideoSourceInfo info)
 {
     try
     {
         CarPlateDevice device = _Devices.FirstOrDefault(item => item.IP == info.MediaSource);
         if (device != null)
         {
             lock (device)
             {
                 device.ResetResult();
             }
         }
     }
     catch (Exception ex)
     {
         Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
     }
 }
Exemplo n.º 19
0
        /// <summary>
        /// 显示并播放视频,如果视频已经在网格中,则播放它.如果已经打开的视频大于网格可以显示的最大视频数量,则超出的视频不会显示出来
        /// </summary>
        /// <param name="video"></param>
        public void RenderAndPlayVideo(VideoSourceInfo video)
        {
            VideoPanel p = _Videoes.SingleOrDefault(vp => vp.VideoSource == video);

            if (p != null)
            {
                p.Play(true);
            }
            else
            {
                p = _Videoes.FirstOrDefault(vp => vp.VideoSource == null);
                if (p != null)
                {
                    p.VideoSource = video;
                    p.Play(true);
                }
            }
        }
Exemplo n.º 20
0
        public void ProcessReport(ReportBase r)
        {
            ParkInfo park = ParkBuffer.Current.GetPark(r.ParkID);

            foreach (DataGridViewRow row in this.dataGridView1.Rows)
            {
                CarPlateDevice device = row.Tag as CarPlateDevice;
                if (device.EntranceID == r.EntranceID)
                {
                    if (r is CardEventReport)
                    {
                        CardEventReport cardEvent = r as CardEventReport;
                        if (cardEvent.EventStatus == CardEventStatus.Valid && !string.IsNullOrEmpty(device.SnapPath))
                        {
                            EntranceInfo entrace       = ParkBuffer.Current.GetEntrance(r.EntranceID);
                            int          videoSourceID = -1;
                            if (entrace != null)
                            {
                                VideoSourceInfo videoSource = entrace.VideoSources.FirstOrDefault(item => item.MediaSource == device.IP && item.Channel == device.VideoID);
                                if (videoSource != null)
                                {
                                    videoSourceID = videoSource.VideoID;
                                }
                            }
                            if (videoSourceID == -1)
                            {
                                videoSourceID = r.EntranceID * 1000 + device.VideoID;                     //没有找到视频ID的,手动生成一个,通道id*1000+视频路数
                            }
                            SnapShot      shot    = new SnapShot(cardEvent.EventDateTime, videoSourceID, cardEvent.CardID, device.SnapPath);
                            string        master  = AppSettings.CurrentSetting.CurrentMasterConnect;
                            string        standby = AppSettings.CurrentSetting.CurrentStandbyConnect;
                            CommandResult result  = (new SnapShotBll(master)).Insert(shot);
                            if (result.Result != ResultCode.Successful && !string.IsNullOrEmpty(standby))
                            {
                                (new SnapShotBll(standby)).Insert(shot);
                            }
                            //(new SnapShotBll(AppSettings.CurrentSetting.ParkConnect)).Insert(shot);
                        }
                    }
                }
            }
        }
Exemplo n.º 21
0
        private void DragDrop_Handler(object sender, DragEventArgs e)
        {
            string[] s = e.Data.GetFormats();
            if (s.Length > 0)
            {
                object o = e.Data.GetData(s[0]);
                if (o is VideoSourceInfo)
                {
                    VideoSourceInfo video = o as VideoSourceInfo;

                    if (video.VideoSourceType == this.VideoType)
                    {
                        //只有视频类型相同的才处理
                        this.Close();
                        this.VideoSource = video;
                        this.Play(true);
                    }
                    else if (this.VideoDragDropHandling != null)
                    {
                        this.VideoDragDropHandling(this, video);
                    }
                }
            }
        }
Exemplo n.º 22
0
        public override bool StartPlaybackByTime(CameraInfo camera, VideoControl vc, DateTime Start, DateTime End)
        {
            VideoSourceInfo videoSourceInfo = camera.VideoSourceInfo;
            int             loginID         = Hik_Open8200API.GetLoginID(videoSourceInfo.IP, (int)videoSourceInfo.Port, videoSourceInfo.User, videoSourceInfo.Password);

            if (loginID < 0)
            {
                string error = Hik_Open8200API.GetLastError();
                vc.ErrorMessage = $"初始化登录服务器失败, 错误码:{error}, 设备{videoSourceInfo.IP}:{videoSourceInfo.Port} ";
                this.LogModule.Error(vc.ErrorMessage);
                return(false);
            }
            int playHandle = Hik_Open8200API.Std_StreamReplayByTime(loginID, camera.CameraCode, this.getTimeString(Start), this.getTimeString(End), 0, vc.VControl.Handle, null, IntPtr.Zero);

            if (playHandle < 0)
            {
                string error = Hik_Open8200API.GetLastError();
                vc.ErrorMessage = $"回放图像失败: 错误码:{error}, 摄像机标识: {camera.CameraCode}";
                this.LogModule.Error(vc.ErrorMessage);
                return(false);
            }

            ControlInfo_Playback cm = new ControlInfo_Playback()
            {
                Camera      = camera,
                VideoSource = videoSourceInfo,
                Start       = Start,
                End         = End,
                LoginHandle = loginID,
                PlayHandle  = playHandle,
                VC          = vc, Speed = (int)Hik_Open8200API.ReplayMode.PLAYMODE_1_FORWARD, Running = true
            };

            this.m_ControlTable[vc] = cm;
            return(true);
        }
Exemplo n.º 23
0
 /// <summary>
 /// 插入包括主键值的视频记录
 /// </summary>
 /// <param name="info"></param>
 /// <returns></returns>
 public CommandResult InsertWithPrimaryKey(VideoSourceInfo info)
 {
     return(provider.InsertWithPrimaryKey(info));
 }
Exemplo n.º 24
0
 public CommandResult Delete(VideoSourceInfo info)
 {
     return(provider.Delete(info));
 }
Exemplo n.º 25
0
        public CommandResult Update(VideoSourceInfo info)
        {
            VideoSourceInfo original = GetVideoSourceByID(info.VideoID).QueryObject;

            return(provider.Update(info, original));
        }
Exemplo n.º 26
0
 public CommandResult Insert(VideoSourceInfo info)
 {
     return(provider.Insert(info));
 }
Exemplo n.º 27
0
        /// <summary>
        /// 在视频列表中显示一系列图片
        /// </summary>
        /// <param name="imgs"></param>
        public void ShowVideoes(List <VideoSourceInfo> videoes)
        {
            this.btnLeft.Visible  = !(videoes == null || videoes.Count <= 1);
            this.btnRight.Visible = !(videoes == null || videoes.Count <= 1);

            _ActiveVideoes.Clear();
            if (videoes != null)
            {
                for (int i = _Videoes.Count; i < videoes.Count; i++)
                {
                    //VideoPanel video = VideoPanelFactory.CreatePanel();
                    //video.AllowDrop = true;
                    //video.Name = "actiVideoPanel" + i.ToString();
                    //video.ShowTitle = true;
                    //video.StretchToFit = true;
                    //video.VideoSource = null;
                    //this.videoPanel.Controls.Add(video);
                    VideoSourceInfo videoinfo = videoes[i];
                    VideoPanel      video     = CreateVideoPanel(videoinfo.VideoSourceType, "actiVideoPanel" + i.ToString(), true);
                    _Videoes.Add(video);
                }
                foreach (VideoPanel vp in _Videoes)
                {
                    if (!videoes.Exists(v => v == vp.VideoSource))
                    {
                        if (vp.Status == VideoStatus.Playing)
                        {
                            vp.Close();
                        }
                        vp.VideoSource = null;
                    }
                }

                foreach (VideoSourceInfo vs in videoes)
                {
                    VideoPanel video = _Videoes.FirstOrDefault(vp => vp.VideoSource == vs);
                    if (video == null)
                    {
                        VideoPanel p = _Videoes.FirstOrDefault(vp => vp.VideoSource == null);
                        if (p != null)
                        {
                            if (vs.VideoSourceType != p.VideoType)
                            {
                                int index = _Videoes.FindIndex(vp => vp == p);
                                if (index >= 0)
                                {
                                    RemoveVideoPanel(p);

                                    //视频类型不同的,重新创建视频
                                    VideoPanel panel = CreateVideoPanel(vs.VideoSourceType, p.Name, p.Visible);
                                    panel.Left      = p.Left;
                                    panel.Top       = p.Top;
                                    panel.Width     = p.Width;
                                    panel.Height    = p.Height;
                                    _Videoes[index] = panel;

                                    p = panel;
                                }
                            }

                            p.VideoSource = vs;
                            _ActiveVideoes.Add(p);
                        }
                    }
                    else
                    {
                        _ActiveVideoes.Add(video);
                    }
                }
            }

            if (_ActiveVideoes.Count > 0)
            {
                _CurImageIndex = 0;
                ShowVideo(_CurImageIndex);
            }
            else
            {
                _CurImageIndex = -1;
                ShowVideo(_CurImageIndex);
            }
        }