bool HikNetHelper::beginRealplay(HikRealdataCallback callback,void* user) { NET_DVR_PREVIEWINFO struPlayInfo = {0}; if(_isLogin == false) { LOGOUT("Function HikNetHelper::beginRealplay -> You should login first!)"); return false; } _user = user; struPlayInfo.hPlayWnd = 0; //需要 SDK 解码时句柄设为有效值,仅取流不解码时可设为空 struPlayInfo.lChannel = 1; struPlayInfo.dwStreamType = 1; //0-主码流,1-子码流,2-码流 3,3-码流 4,以此类推 struPlayInfo.dwLinkMode = 0; //0- TCP 方式,1- UDP 方式,2- 多播方式,3- RTP 方式,4-RTP/RTSP,5-RSTP/HTTP struPlayInfo.bBlocked = 1; //0- 非阻塞取流,1- 阻塞取流 _hikRealPlayHandle = NET_DVR_RealPlay_V40(_hikNetUserId, &struPlayInfo, NULL, NULL); if (_hikRealPlayHandle < 0) { LOGOUT("Function HikNetHelper::beginRealplay -> NET_DVR_RealPlay_V40 failed!! Error Code=%d)",NET_DVR_GetLastError()); logout(); return false; } int iRet; iRet = NET_DVR_SetRealDataCallBack(_hikRealPlayHandle, callback, (DWORD)this); if (!iRet) { LOGOUT("Function HikNetHelper::beginRealplay -> NET_DVR_RealPlay_V30 failed!! ERROR=%d)",NET_DVR_GetLastError()); endRealplay(); logout(); return false; } return true; }
_XBool _XHIKCamera::init(_XCameraData &data) { if(m_isInited) return XTrue; m_cameraWidth = data.w; m_cameraHeight = data.h; //width = &m_cameraWidth; //height = & m_cameraHeight; m_buffSize = m_cameraWidth * m_cameraHeight * 3; m_cameraTexWidth = m_cameraWidth; m_cameraTexHeight = m_cameraHeight; //初始化摄像头并连接设备 NET_DVR_Init(); //初始化 m_lUserID = NET_DVR_Login_V30(data.ipAddress,data.port,data.userName,data.pwd,&m_structDeviceInfo); if(m_lUserID < 0) {//连接设备失败 printf("Login error, %d\n", NET_DVR_GetLastError()); NET_DVR_Cleanup(); return XFalse; } //下面开始连接回调函数并分配内存空间 m_dataRGB = createArrayMem<unsigned char>(m_buffSize); //分配内存空间 if(m_dataRGB == NULL) return XFalse; memset(m_dataRGB,0,m_buffSize); m_dataRGBOut = createArrayMem<unsigned char>(m_buffSize); if(m_dataRGBOut == NULL) return XFalse; haveNewFrame = &m_haveNewFrame; pOutRGB = m_dataRGB; NET_DVR_SetExceptionCallBack_V30(0,NULL,g_ExceptionCallBack,NULL); NET_DVR_CLIENTINFO ClientInfo = {0}; ClientInfo.hPlayWnd = NULL; //需要SDK解码时句柄设为有效值,仅取流不解码时可设为空 ClientInfo.lChannel = 0; //预览通道号 ClientInfo.lLinkMode = 0; //最高位(31)为0表示主码流,为1表示子码流0~30位表示连接方式:0-TCP方式;1-UDP方式;2-多播方式;3-RTP方式; ClientInfo.sMultiCastIP = NULL; //多播地址,需要多播预览时配置 //BOOL bPreviewBlock = XFalse; //请求码流过程是否阻塞,0:否,1:是 m_lRealPlayHandle = NET_DVR_RealPlay_V30(m_lUserID,&ClientInfo,NULL,NULL,XFalse); if(m_lRealPlayHandle < 0) { printf("NET_DVR_RealPlay_V30 error\n"); NET_DVR_Logout(m_lUserID); NET_DVR_Cleanup(); return XFalse; } if(!NET_DVR_SetRealDataCallBack(m_lRealPlayHandle,g_RealDataCallBack_V30,0)) { printf("NET_DVR_SetRealDataCallBack error\n"); } m_cameraTex.createTexture(m_cameraWidth,m_cameraHeight,COLOR_RGB); //不允许进行2的n次方扩展,这回造成不兼容 m_cameraSprite.init(m_cameraWidth,m_cameraHeight,0); m_haveNewFrame = XFalse; m_isInited = XTrue; return XTrue; }