Esempio n. 1
0
        /// <summary>
        /// 登出设备
        /// </summary>
        /// <param name="info">所有操作使用的UseInfo对象</param>
        /// <returns>true:操作成功,false:操作失败</returns>
        public bool Logout(ref DvrUseInfo info)
        {
            bool b = false;

            //停止回放 Stop playback
            if (info.PlaybackId >= 0)
            {
                b = HikVideoApi.NET_DVR_StopPlayBack(info.PlaybackId);
                info.PlaybackId = -1;
            }

            //停止下载 Stop download
            if (info.DownId >= 0)
            {
                b           = HikVideoApi.NET_DVR_StopGetFile(info.DownId);
                info.DownId = -1;
            }

            //注销登录 Logout the device
            if (info.UserId >= 0)
            {
                b           = HikApi.NET_DVR_Logout(info.UserId);
                info.UserId = -1;
            }
            return(b);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取回放进度
        /// </summary>
        /// <param name="info">执行回放时的UseInfo对象</param>
        /// <returns>true:获取成功,false:获取失败,网络异常,或者当完成回放时结束回放失败</returns>
        public bool GetPlaybackProgress(ref DvrUseInfo info)
        {
            uint   iOutValue   = 0;
            int    iPos        = 0;
            IntPtr lpOutBuffer = Marshal.AllocHGlobal(4);

            //获取回放进度
            if (!HikVideoApi.NET_DVR_PlayBackControl_V40(info.PlaybackId, (uint)PlayBackControlCmd.NET_DVR_PLAYGETPOS, IntPtr.Zero, 0, lpOutBuffer, ref iOutValue))
            {
                return(false);
            }

            iPos = (int)Marshal.PtrToStructure(lpOutBuffer, typeof(int));

            info.PlaybackProgress = iPos;
            if (iPos == 100)  //回放结束
            {
                if (!HikVideoApi.NET_DVR_StopPlayBack(info.PlaybackId))
                {
                    return(false);
                }
            }
            if (iPos == 200) //网络异常,回放失败
            {
                return(false);
            }
            Marshal.FreeHGlobal(lpOutBuffer);
            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// 抓图(在预览时)
        /// </summary>
        /// <param name="info">登录设备时的UseInfo对象</param>
        /// <returns>true:抓图保存成功,false:抓图保存失败</returns>
        public bool GetBMPImage(ref DvrUseInfo info)
        {
            if (info.PlaybackId < 0)
            {
                return(false);
            }

            //BMP抓图 Capture a BMP picture
            return(HikVideoApi.NET_DVR_PlayBackCaptureFile(info.PlaybackId, info.SaveBMPPath));
        }
Esempio n. 4
0
        /// <summary>
        /// 停止回放
        /// </summary>
        /// <param name="info">执行回放时使用的UseInfo对象</param>
        /// <returns>true:操作成功,false:操作失败</returns>
        public bool StopPlayBack(ref DvrUseInfo info)
        {
            bool b = false;

            //停止回放 Stop playback
            if (info.PlaybackId >= 0)
            {
                b = HikVideoApi.NET_DVR_StopPlayBack(info.PlaybackId);
                info.PlaybackId = -1;
            }
            return(b);
        }
Esempio n. 5
0
 /// <summary>
 /// 停止录像下载
 /// </summary>
 /// <param name="info">执行下载时的UseInfo对象</param>
 /// <returns>true:停止下载执行成功,false:操作执行失败</returns>
 private bool StopDownload(ref DvrUseInfo info)
 {
     if (info.DownId < 0)
     {
         return(false);
     }
     if (!HikVideoApi.NET_DVR_StopGetFile(info.DownId))
     {
         return(false);
     }
     info.DownId = -1;
     return(true);
 }
Esempio n. 6
0
        /// <summary>
        /// 按时间回放录像
        /// </summary>
        /// <param name="info">登录设备时的UseInfo对象</param>
        /// <param name="channel">通道号</param>
        /// <param name="Handle">显示图像控件句柄,如PictureBox</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <returns>true:执行成功,false:执行失败</returns>
        public bool PlaybackByTime(ref DvrUseInfo info, int channel, IntPtr Handle, DateTime startTime, DateTime endTime)
        {
            if (info.PlaybackId >= 0)
            {
                //如果已经正在回放,先停止回放
                if (!HikVideoApi.NET_DVR_StopPlayBack(info.PlaybackId))
                {
                    return(false);
                }
                info.PlaybackId = -1;
            }

            NET_DVR_VOD_PARA struVodPara = new NET_DVR_VOD_PARA();

            struVodPara.dwSize = (uint)Marshal.SizeOf(struVodPara);
            struVodPara.struIDInfo.dwChannel = (uint)iChannelNum[(int)channel]; //通道号 Channel number
            struVodPara.hWnd = Handle;                                          //回放窗口句柄

            //设置回放的开始时间 Set the starting time to search video files
            struVodPara.struBeginTime.dwYear   = (uint)startTime.Year;
            struVodPara.struBeginTime.dwMonth  = (uint)startTime.Month;
            struVodPara.struBeginTime.dwDay    = (uint)startTime.Day;
            struVodPara.struBeginTime.dwHour   = (uint)startTime.Hour;
            struVodPara.struBeginTime.dwMinute = (uint)startTime.Minute;
            struVodPara.struBeginTime.dwSecond = (uint)startTime.Second;

            //设置回放的结束时间 Set the stopping time to search video files
            struVodPara.struEndTime.dwYear   = (uint)endTime.Year;
            struVodPara.struEndTime.dwMonth  = (uint)endTime.Month;
            struVodPara.struEndTime.dwDay    = (uint)endTime.Day;
            struVodPara.struEndTime.dwHour   = (uint)endTime.Hour;
            struVodPara.struEndTime.dwMinute = (uint)endTime.Minute;
            struVodPara.struEndTime.dwSecond = (uint)endTime.Second;


            //按时间回放 Playback by time
            info.PlaybackId = HikVideoApi.NET_DVR_PlayBackByTime_V40(info.UserId, ref struVodPara);
            if (info.PlaybackId < 0)
            {
                return(false);
            }

            uint iOutValue = 0;

            return(HikVideoApi.NET_DVR_PlayBackControl_V40(info.PlaybackId, (uint)PlayBackControlCmd.NET_DVR_PLAYSTART, IntPtr.Zero, 0, IntPtr.Zero, ref iOutValue));
        }
Esempio n. 7
0
        /// <summary>
        /// 根据文件名称下载录像
        /// </summary>
        /// <param name="info">登陆设备时的UseInfo对象</param>
        /// <param name="savePath">保存全路径</param>
        /// <returns>true:下载执行成功,false:操作执行失败</returns>
        public bool DownloadFileByName(ref DvrUseInfo info, string savePath)
        {
            //if (info.DownId >= 0)
            //{
            //    //正在下载,请先停止下载
            //    return false;
            //}

            //string sVideoFileName;  //录像文件保存路径和文件名 the path and file name to save
            //sVideoFileName = "Downtest_" + sPlayBackFileName + ".mp4";

            //按文件名下载 Download by file name
            info.DownId = HikVideoApi.NET_DVR_GetFileByName(info.UserId, info.DownName, savePath);
            if (info.DownId < 0)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 8
0
        /// <summary>
        /// 根据时间下载录像文件
        /// </summary>
        /// <param name="info">登陆设备时的UseInfo对象</param>
        /// <param name="channel">通道号</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <param name="savePath">保存全路径</param>
        /// <returns>true:执行成功,false:执行失败</returns>
        public bool DownloadFileByTime(ref DvrUseInfo info, int channel, DateTime startTime, DateTime endTime, string savePath)
        {
            //if (info.DownId >= 0)
            //    return false;//(uint)iChannelNum[channel]
            NET_DVR_PLAYCOND struDownPara = new NET_DVR_PLAYCOND()
            {
                dwChannel = (uint)channel /*通道号 Channel number  */, byDrawFrame = 0, byStreamType = 0
            };

            //设置下载的开始时间 Set the starting time
            struDownPara.struStartTime.dwYear   = (uint)startTime.Year;
            struDownPara.struStartTime.dwMonth  = (uint)startTime.Month;
            struDownPara.struStartTime.dwDay    = (uint)startTime.Day;
            struDownPara.struStartTime.dwHour   = (uint)startTime.Hour;
            struDownPara.struStartTime.dwMinute = (uint)startTime.Minute;
            struDownPara.struStartTime.dwSecond = (uint)startTime.Second;

            //设置下载的结束时间 Set the stopping time
            struDownPara.struStopTime.dwYear   = (uint)endTime.Year;
            struDownPara.struStopTime.dwMonth  = (uint)endTime.Month;
            struDownPara.struStopTime.dwDay    = (uint)endTime.Day;
            struDownPara.struStopTime.dwHour   = (uint)endTime.Hour;
            struDownPara.struStopTime.dwMinute = (uint)endTime.Minute;
            struDownPara.struStopTime.dwSecond = (uint)endTime.Second;

            //按时间下载 Download by time
            info.DownId = HikVideoApi.NET_DVR_GetFileByTime_V40(info.UserId, savePath, ref struDownPara);

            if (info.DownId < 0)
            {
                return(false);
            }

            uint iOutValue = 0;

            if (!HikVideoApi.NET_DVR_PlayBackControl_V40(info.DownId, (uint)PlayBackControlCmd.NET_DVR_PLAYSTART, IntPtr.Zero, 0, IntPtr.Zero, ref iOutValue))
            {
                int x = HikOperate.GetLastError();
                return(false);
            }
            return(true);
        }
Esempio n. 9
0
        /// <summary>
        /// 按时文件名放录像
        /// </summary>
        /// <param name="info">登录设备时的UseInfo对象</param>
        /// <param name="Handle">显示图像控件句柄,如PictureBox</param>
        /// <returns>true:执行成功,false:执行失败</returns>
        public bool PlaybackByName(ref DvrUseInfo info, IntPtr Handle)
        {
            if (info.PlaybackId >= 0)
            {
                //如果已经正在回放,先停止回放
                if (!HikVideoApi.NET_DVR_StopPlayBack(info.PlaybackId))
                {
                    return(false);
                }
                info.PlaybackId = -1;
            }

            //按文件名回放
            info.PlaybackId = HikVideoApi.NET_DVR_PlayBackByName(info.UserId, info.PlaybackName, Handle);
            if (info.PlaybackId < 0)
            {
                return(false);
            }
            uint iOutValue = 0;

            return(HikVideoApi.NET_DVR_PlayBackControl_V40(info.PlaybackId, (uint)PlayBackControlCmd.NET_DVR_PLAYSTART, IntPtr.Zero, 0, IntPtr.Zero, ref iOutValue));
        }
Esempio n. 10
0
 /// <summary>
 /// 获取下载进度
 /// </summary>
 /// <param name="downId">下载id</param>
 /// <param name="iPos">下载进度</param>
 /// <returns>true:获取成功,false:获取失败,网络异常,或者当完成下载时结束下载失败</returns>
 public bool GetDownProgress(int downId, ref int iPos)
 {
     //获取下载进度
     iPos = HikVideoApi.NET_DVR_GetDownloadPos(downId);
     //info.DownProgress = iPos;
     if (iPos == 100)                             //下载完成
     {
         HikVideoApi.NET_DVR_StopGetFile(downId); //停止异常
         //info.DownId = -1;
         //if (!HikDvrApi.NET_DVR_StopGetFile(info.DownId))//停止异常
         //    return false;
     }
     else if (iPos == 200 || iPos == -1)          //网络异常,下载失败
     {
         HikVideoApi.NET_DVR_StopGetFile(downId); //停止异常
         //info.DownId = -1;
         return(false);
     }
     //else
     //    return false;
     return(true);
 }
Esempio n. 11
0
        //private void Preview(DvrUseInfo info)
        //{
        //    HikVideoApi.NET_DVR_StopRealPlay(info.RealId);
        //    var hwnd = ptzImage.Handle;
        //    NET_DVR_PREVIEWINFO lpPreviewInfo = new NET_DVR_PREVIEWINFO();
        //    lpPreviewInfo.hPlayWnd = hwnd;//预览窗口
        //    lpPreviewInfo.lChannel = cbxPTZChannel.SelectedIndex + 1;//预te览的设备通道
        //    lpPreviewInfo.dwStreamType = 0;//码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推
        //    lpPreviewInfo.dwLinkMode = 0;//连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP
        //    lpPreviewInfo.bBlocked = true; //0- 非阻塞取流,1- 阻塞取流
        //    lpPreviewInfo.dwDisplayBufNum = 15; //播放库播放缓冲区最大缓冲帧数
        //    REALDATACALLBACK RealData = new REALDATACALLBACK(RealDataCallBack);//预览实时流回调函数
        //    IntPtr pUser = new IntPtr();//用户数据
        //    打开预览 Start live view
        //    info.RealId = HikVideoApi.NET_DVR_RealPlay_V40(info.UserId, ref lpPreviewInfo, null/*RealData*/, pUser);
        //    realId = info.RealId;
        //    dvrUseInfos.Find(o => o.DvrIp == cbxPTZIp.Text).RealId = info.RealId;
        //    TxtPTZMsg(AppLogHelper.GetLogStr(string.Format("DvrIp:{0} 端口:{1} 名称:{2} {3} ({4})", info.DvrIp, info.DvrPoint, info.DvrName, realId >= 0 ? "预览图像成功" : "预览图像失败:" + HikOperate.GetLastError(), DateTime.Now), "图像预览"));
        //}

        #endregion

        #region 录像查找
        /// <summary>
        /// 录像文件查找
        /// </summary>
        /// <param name="info">登录设备时的UseInfo对象</param>
        /// <param name="channel">通道号</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <param name="useCardNo">是否带ATM信息进行查询</param>
        /// <param name="fileType">录象文件类型(根据dwUseCardNo参数是否带卡号查找分为两类,参考枚举 NocardSelectFileType 和 UseCardSelectFileType)</param>
        /// <param name="isLocked">是否锁定:0-未锁定文件,1-锁定文件,0xff表示所有文件(包括锁定和未锁定)</param>
        /// <returns>返回文件列表</returns>
        public List <BackFile> SearchBackFile(ref DvrUseInfo info, int channel, DateTime startTime, DateTime endTime, uint useCardNo = (uint)UseCardSelectWay.带ATM信息, uint fileType = 0xff, uint isLocked = 0xff)
        {
            List <BackFile> files = new List <BackFile>();

            NET_DVR_FILECOND_V40 struFileCond_V40 = new NET_DVR_FILECOND_V40()
            {
                lChannel = channel, /*通道号 Channel number*/ dwFileType = fileType, /*0xff-全部,0-定时录像,1-移动侦测,2-报警触发,...*/ dwIsLocked = isLocked /*0-未锁定文件,1-锁定文件,0xff表示所有文件(包括锁定和未锁定)*/, dwUseCardNo = useCardNo
            };

            //设置录像查找的开始时间 Set the starting time to search video files
            struFileCond_V40.struStartTime.dwYear   = (uint)startTime.Year;
            struFileCond_V40.struStartTime.dwMonth  = (uint)startTime.Month;
            struFileCond_V40.struStartTime.dwDay    = (uint)startTime.Day;
            struFileCond_V40.struStartTime.dwHour   = (uint)startTime.Hour;
            struFileCond_V40.struStartTime.dwMinute = (uint)startTime.Minute;
            struFileCond_V40.struStartTime.dwSecond = (uint)startTime.Second;

            //设置录像查找的结束时间 Set the stopping time to search video files
            struFileCond_V40.struStopTime.dwYear   = (uint)endTime.Year;
            struFileCond_V40.struStopTime.dwMonth  = (uint)endTime.Month;
            struFileCond_V40.struStopTime.dwDay    = (uint)endTime.Day;
            struFileCond_V40.struStopTime.dwHour   = (uint)endTime.Hour;
            struFileCond_V40.struStopTime.dwMinute = (uint)endTime.Minute;
            struFileCond_V40.struStopTime.dwSecond = (uint)endTime.Second;

            //开始录像文件查找 Start to search video files
            int m_lFindHandle = HikVideoApi.NET_DVR_FindFile_V40(info.UserId, ref struFileCond_V40);

            if (m_lFindHandle >= 0)
            {
                NET_DVR_FINDDATA_V30 struFileData = new NET_DVR_FINDDATA_V30();;
                while (true)
                {
                    //逐个获取查找到的文件信息 Get file information one by one.
                    int result = HikVideoApi.NET_DVR_FindNextFile_V30(m_lFindHandle, ref struFileData);

                    if (result == (int)SelectFileState.NET_DVR_ISFINDING)  //正在查找请等待 Searching, please wait
                    {
                        continue;
                    }
                    else if (result == (int)SelectFileState.NET_DVR_FILE_SUCCESS) //获取文件信息成功 Get the file information successfully
                    {
                        files.Add(new BackFile()
                        {
                            FileName = struFileData.sFileName, StartTime = new DateTime((int)struFileData.struStartTime.dwYear, (int)struFileData.struStartTime.dwMonth, (int)struFileData.struStartTime.dwDay, (int)struFileData.struStartTime.dwHour, (int)struFileData.struStartTime.dwMinute, (int)struFileData.struStartTime.dwSecond), EndTime = new DateTime((int)struFileData.struStopTime.dwYear, (int)struFileData.struStopTime.dwMonth, (int)struFileData.struStopTime.dwDay, (int)struFileData.struStopTime.dwHour, (int)struFileData.struStopTime.dwMinute, (int)struFileData.struStopTime.dwSecond), FileSize = (int)struFileData.dwFileSize, FileType = (int)struFileData.byFileType, Locked = (int)struFileData.byLocked, CardNum = struFileData.sCardNum
                        });
                    }
                    else if (result == (int)SelectFileState.NET_DVR_FILE_NOFIND || result == (int)SelectFileState.NET_DVR_NOMOREFILE)
                    {
                        break; //未查找到文件或者查找结束,退出   No file found or no more file found, search is finished
                    }
                    else
                    {
                        break;
                    }
                }
                HikVideoApi.NET_DVR_FindClose_V30(m_lFindHandle);
            }
            else
            {
                int error = HikOperate.GetLastError();
                if (error == 19 || error == 4)
                {
                    HikVideoApi.NET_DVR_FindClose_V30(m_lFindHandle);
                    return(files);
                }
                if (error == 7 || error == 73)
                {
                    return(null);
                }
            }
            return(files);
        }
Esempio n. 12
0
        /// <summary>
        /// 控制录像回放状态
        /// </summary>
        /// <param name="info">执行回放时的UseInfo对象</param>
        /// <param name="cmd">控制录像回放状态命令</param>
        /// <returns>true:执行成功,false:执行失败</returns>
        public bool PlaybackControl(ref DvrUseInfo info, PlayBackControlCmd cmd)
        {
            uint iOutValue = 0;

            return(HikVideoApi.NET_DVR_PlayBackControl_V40(info.PlaybackId, (uint)cmd, IntPtr.Zero, 0, IntPtr.Zero, ref iOutValue));
        }
Esempio n. 13
0
        /// <summary>
        /// 恢复播放
        /// </summary>
        /// <param name="info">执行回放时的UseInfo对象</param>
        /// <returns>true:执行成功,false:执行失败</returns>
        public bool PlayReStart(ref DvrUseInfo info)
        {
            uint iOutValue = 0;

            return(HikVideoApi.NET_DVR_PlayBackControl_V40(info.PlaybackId, (uint)PlayBackControlCmd.NET_DVR_PLAYRESTART, IntPtr.Zero, 0, IntPtr.Zero, ref iOutValue));
        }
Esempio n. 14
0
        /// <summary>
        /// 倒放切为正放
        /// </summary>
        /// <param name="info">执行回放时的UseInfo对象</param>
        /// <returns>true:执行成功,false:执行失败</returns>
        public bool PlaybackForWard(ref DvrUseInfo info)
        {
            uint iOutValue = 0;

            return(HikVideoApi.NET_DVR_PlayBackControl_V40(info.PlaybackId, (uint)PlayBackControlCmd.NET_DVR_PLAY_FORWARD, IntPtr.Zero, 0, IntPtr.Zero, ref iOutValue));
        }
Esempio n. 15
0
        /// <summary>
        /// 正放切为倒放
        /// </summary>
        /// <param name="info">执行回放时的UseInfo对象</param>
        /// <returns>true:执行成功,false:执行失败</returns>
        public bool PlaybackReverse(ref DvrUseInfo info)
        {
            uint iOutValue = 0;

            return(HikVideoApi.NET_DVR_PlayBackControl_V40(info.PlaybackId, (uint)PlayBackControlCmd.NET_DVR_PLAY_REVERSE, IntPtr.Zero, 0, IntPtr.Zero, ref iOutValue));
        }