Ejemplo n.º 1
0
        /// <summary>
        /// 开启录像
        /// </summary>
        /// <param name="IP"></param>
        /// <param name="Channel"></param>
        /// <returns></returns>
        public static int Rec(string IP, int Channel, string strDeviceID)
        {
            CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO();
            //lpPreviewInfo.hPlayWnd = handle;//预览窗口
            lpPreviewInfo.lChannel        = Channel;                                                //预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;                                                     //播放库播放缓冲区最大缓冲帧数

            CHCNetSDK.REALDATACALLBACK RealData = new CHCNetSDK.REALDATACALLBACK(RealDataCallBack); //预览实时流回调函数
            IntPtr pUser = new IntPtr();                                                            //用户数据

            if (!userIDList.ContainsKey(IP))
            {
                return(-1);
            }
            int m_lUserID = userIDList[IP];
            //打开预览 Start live view
            int m_lRealHandle = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, null /*RealData*/, pUser);

            if (m_lRealHandle < 0)
            {
            }
            else
            {
                //录像保存路径和文件名 the path and file name to save
                string   sVideoFileName;
                DateTime dt = DateTime.Now;
                sVideoFileName = IP + "_" + Channel + dt.ToString("yyyyMMddHHmmss") + "手动.mp4";
                //预览成功
                //强制I帧 Make a I frame
                int lChannel = Channel; //通道号 Channel number
                CHCNetSDK.NET_DVR_MakeKeyFrame(m_lUserID, lChannel);

                //开始录像 Start recording
                if (CHCNetSDK.NET_DVR_SaveRealData(m_lRealHandle, path + sVideoFileName))
                {
                    RealHandleList.Add(IP + "," + Channel + "_1", m_lRealHandle);
                    RecInfo info = new RecInfo(sVideoFileName, dt, "手动录像");
                    RecDataClass.recInfo.Add(IP + "," + Channel + "_1", info);

                    //写入数据库
                    RecFileList recFileList = new RecFileList();
                    recFileList.CameraID     = strDeviceID;
                    recFileList.RecName      = sVideoFileName;
                    recFileList.RecRecFile   = path + sVideoFileName;
                    recFileList.RecStartDate = dt.ToString("yyyy-MM-dd");
                    recFileList.RecStartTime = dt.ToString("HH:mm:ss");
                    recFileList.RecType      = "1";
                    RecFileClass.AddStartTime(recFileList);
                }
                else
                {
                    return(-1);
                }
            }
            return(m_lRealHandle);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加录像信息开始时间
        /// </summary>
        /// <param name="recFileList"></param>
        /// <returns></returns>
        public static bool AddStartTime(RecFileList recFileList, ref string errorInfo)
        {
            if (!Access.Connection(ref errorInfo))
            {
                return(false);
            }
            string sql = "insert into RecFileList ("
                         + "CameraID,"
                         + "LocationFlag,"
                         + "RecName,"
                         + "RecType,"
                         + "RecStartDate,"
                         + "RecStartTime,"
                         + "RecEndDate,"
                         + "RecEndTime,"
                         + "RecRecFile,"
                         + "UserName,"
                         + "RecEventName,"
                         + "RecDescription,"
                         + "Mark)"
                         + "values ('"
                         + recFileList.CameraID + "','"
                         + recFileList.LocationFlag + "','"
                         + recFileList.RecName + "','"
                         + recFileList.RecType + "','"
                         + recFileList.RecStartDate + "','"
                         + recFileList.RecStartTime + "','"
                         + recFileList.RecEndDate + "','"
                         + recFileList.RecEndTime + "','"
                         + recFileList.RecRecFile + "','"
                         + recFileList.UserName + "','"
                         + recFileList.RecEventName + "','"
                         + recFileList.RecDescription + "','"
                         + recFileList.Mark + "'"
                         + ")";
            //往表添加一条记录
            OleDbCommand oleDbCommand = new OleDbCommand(sql, Access.oleDb);
            int          i            = oleDbCommand.ExecuteNonQuery(); //返回被修改的数目

            Access.CloseConn();
            return(i > 0);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 开启录像
        /// </summary>
        /// <param name="strDeviceID"></param>
        /// <returns></returns>
        public static int Rec(string strDeviceID, ref string errorInfo)
        {
            Guid DeviceID;

            if (!Guid.TryParse(strDeviceID, out DeviceID))
            {
                errorInfo = "设备ID为" + strDeviceID;
                return(-1);
            }
            Client.Entities.CameraList device = Class1.cameraList.Find(
                delegate(Client.Entities.CameraList camera)
            {
                return(camera.DeviceID.Equals(DeviceID));
            }
                );
            if (device == null)
            {
                return(-1);
            }

            Client.Entities.StreamMediaList streamMedia = Class1.streamMediaList.Find(
                delegate(Client.Entities.StreamMediaList sm)
            {
                return(sm.DeviceID.Equals(device.StreamMedia_DeviceID));
            });
            if (streamMedia == null)
            {
                return(-1);
            }
            string IP      = streamMedia.VideoIP;
            int    Channel = device.VideoChannel;

            CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO();
            //lpPreviewInfo.hPlayWnd = handle;//预览窗口
            lpPreviewInfo.lChannel        = Channel;                                                //预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;                                                     //播放库播放缓冲区最大缓冲帧数

            CHCNetSDK.REALDATACALLBACK RealData = new CHCNetSDK.REALDATACALLBACK(RealDataCallBack); //预览实时流回调函数
            IntPtr pUser = new IntPtr();                                                            //用户数据

            if (!ManualRec.userIDList.ContainsKey(IP))
            {
                return(-1);
            }
            int m_lUserID = ManualRec.userIDList[IP];
            //打开预览 Start live view
            int m_lRealHandle = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, null /*RealData*/, pUser);

            if (m_lRealHandle < 0)
            {
            }
            else
            {
                //录像保存路径和文件名 the path and file name to save
                string   sVideoFileName;
                DateTime dt = DateTime.Now;
                sVideoFileName = IP + "_" + Channel + dt.ToString("yyyyMMddHHmmss") + "报警.mp4";
                //预览成功
                //强制I帧 Make a I frame
                int lChannel = Channel; //通道号 Channel number
                CHCNetSDK.NET_DVR_MakeKeyFrame(m_lUserID, lChannel);

                //开始录像 Start recording
                if (CHCNetSDK.NET_DVR_SaveRealData(m_lRealHandle, path + sVideoFileName))
                {
                    RealHandleList.Add(IP + "," + Channel + "_3", m_lRealHandle);
                    RecInfo info = new RecInfo(sVideoFileName, dt, "报警录像");
                    RecDataClass.recInfo.Add(IP + "," + Channel + "_3", info);

                    //写入数据库
                    RecFileList recFileList = new RecFileList();
                    recFileList.CameraID     = strDeviceID;
                    recFileList.RecName      = sVideoFileName;
                    recFileList.RecRecFile   = path + sVideoFileName;
                    recFileList.RecStartDate = dt.ToString("yyyy-MM-dd");
                    recFileList.RecStartTime = dt.ToString("HH:mm:ss");
                    recFileList.RecType      = "3";
                    if (!RecFileClass.AddStartTime(recFileList, ref errorInfo))
                    {
                        return(-1);
                    }
                }
                else
                {
                    return(-1);
                }
            }
            return(m_lRealHandle);
        }