Example #1
0
        /// <summary>
        /// 获取所有窗口号
        /// </summary>
        /// <param name="lUserID">用户id</param>
        /// <param name="byWallNo">电视墙号</param>
        /// <param name="dwWinNo">输出分屏数量</param>
        /// <returns>返回窗口信息数组</returns>
        public static NET_DVR_VIDEOWALLWINDOWPOSITION[] GetAllWinInfo(int lUserID, int byWallNo, ref uint[] dwWinNo)
        {
            dwWinNo = new uint[MAX_VM_WIN_NUM * 16];
            int iWinCount = 0;
            int iRet      = 0;
            NET_DVR_VIDEOWALLWINDOWPOSITION pTemp = new NET_DVR_VIDEOWALLWINDOWPOSITION();//[MAX_WALL_WIN_COUNT * Marshal.SizeOf(new NET_DVR_VIDEOWALLWINDOWPOSITION())];
            Int32  nSize       = 4 + Marshal.SizeOf(pTemp);
            IntPtr lpOutBuffer = Marshal.AllocHGlobal(nSize);

            Marshal.StructureToPtr(pTemp, lpOutBuffer, false);
            IntPtr pt       = new IntPtr();
            uint   dwCount  = (uint)(4 + MAX_WALL_WIN_COUNT * Marshal.SizeOf(new NET_DVR_VIDEOWALLWINDOWPOSITION()));
            int    dwWallNo = byWallNo;

            dwWallNo <<= 24;
            if (!NET_DVR_GetDeviceConfig(lUserID, NET_DVR_GET_VIDEOWALLWINDOWPOSITION, 0xffffffff, (IntPtr)dwWallNo, 4, IntPtr.Zero, lpOutBuffer, (UInt32)nSize))
            {
                iRet = HikOperate.GetLastError();
                return(new NET_DVR_VIDEOWALLWINDOWPOSITION[0]);
            }
            else
            {
                NET_DVR_VIDEOWALLWINDOWPOSITION   lpWinPos1 = (NET_DVR_VIDEOWALLWINDOWPOSITION)Marshal.PtrToStructure(lpOutBuffer, typeof(NET_DVR_VIDEOWALLWINDOWPOSITION));
                NET_DVR_VIDEOWALLWINDOWPOSITION[] lpWinPos  = (NET_DVR_VIDEOWALLWINDOWPOSITION[])Marshal.PtrToStructure(pt, typeof(NET_DVR_VIDEOWALLWINDOWPOSITION[]));
                int dwWinCount = lpWinPos.Length;
                //= pt;
                for (int i = 0; i < dwWinCount; i++)
                {
                    int iSubMode = GetSubWinInfo(lUserID, lpWinPos[i].dwWindowNo);
                    if (iSubMode == -1)
                    {
                        dwWinNo[iWinCount++] = lpWinPos[i].dwWindowNo;
                        continue;
                    }
                    for (int j = 0; j < iSubMode; j++)
                    {
                        dwWinNo[iWinCount++] = (uint)(((j + 1) << 16) + lpWinPos[i].dwWindowNo);
                    }
                    ;
                }
                iRet = iWinCount;
            }
            return(null);
        }
Example #2
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);
        }
Example #3
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);
        }