Пример #1
0
_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;
}
Пример #2
0
bool CHaikangSDK::StartPlay(int screenNo,char *name,char *sip,int nPort,int channel,
							char *user,char *psw,HWND hWnd,int subtype,int Direction)
{
	if(m_LoginHandle[screenNo] != -1)
	{
		StopPlay(screenNo);
	}
	//---------------------------------------
	// 注册设备
	m_direction[screenNo]=Direction;
	NET_DVR_DEVICEINFO_V30 struDeviceInfo;
	m_LoginHandle[screenNo] = NET_DVR_Login_V30(sip, nPort, user, psw, &struDeviceInfo);
	if (m_LoginHandle[screenNo] < 0)
	{
		DlgMain->ShowCameraMessage(name,"Login error!",FALSE);
		printf("Login error, %d\n", NET_DVR_GetLastError());
		//NET_DVR_Cleanup();
		return false;
	}

	//---------------------------------------
	//设置异常消息回调函数
	NET_DVR_SetExceptionCallBack_V30(0, NULL,g_ExceptionCallBack, NULL);

	//---------------------------------------
	//启动预览并设置回调数据流
	NET_DVR_CLIENTINFO ClientInfo = {0};
	//需要SDK解码时句柄设为有效值,仅取流不解码时可设为空
	ClientInfo.hPlayWnd = NULL;
	ClientInfo.lChannel = channel;		//预览通道号
	//最高位(31)为0表示主码流,为1表示子码流0~30位表示连接方式:0-TCP方式;1-UDP方式;2-多播方式;3-RTP方式;
	if(subtype == 0)
		ClientInfo.lLinkMode = 0;
	else
		ClientInfo.lLinkMode = 0x80000000;
	ClientInfo.sMultiCastIP = NULL;	//多播地址,需要多播预览时配置
  
	BOOL bPreviewBlock = false;       //请求码流过程是否阻塞,0:否,1:是
	m_RealHandle[screenNo] = NET_DVR_RealPlay_V30(m_LoginHandle[screenNo], &ClientInfo, g_RealDataCallBack_V30, this, 0);
	if (m_RealHandle[screenNo] < 0)
	{
		DlgMain->ShowCameraMessage(name,"Play error!",FALSE);
		printf("NET_DVR_RealPlay_V30 error\n");
		NET_DVR_Logout(m_LoginHandle[screenNo]);
	//	NET_DVR_Cleanup();
		m_LoginHandle[screenNo] = -1;
		return false;
	}

	DlgMain->ShowCameraMessage(name,"连接成功",FALSE);
	return true;
}
Пример #3
0
void MainWindow::on_pushButton_clicked()
{
    qDebug("button clicked");
    // 注册设备
    NET_DVR_DEVICEINFO_V30 struDeviceInfo;
    lUserID = NET_DVR_Login_V30("192.168.13.20", 8000, "admin", "1qaz2wsx", &struDeviceInfo);
    if (lUserID < 0)
    {
         qDebug("Login error, %d\n", NET_DVR_GetLastError());
         NET_DVR_Cleanup();
         return;
    }

    //---------------------------------------
    //设置异常消息回调函数
    NET_DVR_SetExceptionCallBack_V30(0, NULL,g_ExceptionCallBack, NULL);

    //---------------------------------------
    //启动预览并设置回调数据流
    //HWND hWnd = (HWND)ui->frame->winId();     //获取窗口句柄
    movie.hWnd = (HWND)ui->frame->winId();     //获取窗口句柄
    qDebug("hWnd:%d", movie.hWnd);
    NET_DVR_PREVIEWINFO struPlayInfo = {0};
    //struPlayInfo.hPlayWnd = hWnd;         //需要SDK解码时句柄设为有效值,仅取流不解码时可设为空
    struPlayInfo.lChannel     = 1;       //预览通道号
    struPlayInfo.dwStreamType = 0;       //0-主码流,1-子码流,2-码流3,3-码流4,以此类推
    struPlayInfo.dwLinkMode   = 0;       //0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP

    lRealPlayHandle = NET_DVR_RealPlay_V40(lUserID, &struPlayInfo, PsDataCallBack, &movie);
    if (lRealPlayHandle < 0)
    {
        DWORD error = NET_DVR_GetLastError();
        qDebug("NET_DVR_RealPlay_V40 error, %d\n" , error);
        NET_DVR_Logout(lUserID);
        NET_DVR_Cleanup();
        return;
    }

    qDebug("NET_DVR_RealPlay_V40 ok!");
    //QThread::sleep(10000);
    ////---------------------------------------
    ////关闭预览
    //NET_DVR_StopRealPlay(lRealPlayHandle);
    ////注销用户
    //NET_DVR_Logout(lUserID);
    ////释放SDK资源
    //NET_DVR_Cleanup();

    return;
}
Пример #4
0
void * HK_Store_Thread(void * para){

    /*info to login HK camera*/
    char HK_userName[] = "admin";
    char HK_password[] = "12345";
    int stopResult = 0;

    LONG lUserID = 0;

    LONG streamHandle = 0;
    //unsigned int NVR_recordHandle = 0;

    NET_DVR_DEVICEINFO_V30 struDeviceInfo;
    NET_DVR_CLIENTINFO ClientInfo = {0};
    //ClientInfo.hPlayWnd = NULL;
    ClientInfo.lChannel = 1;
    ClientInfo.lLinkMode = 0;
    ClientInfo.sMultiCastIP = NULL;


    RecordParas *t_para = (RecordParas *)para;
    HKcameraArgs hkargs;

    //hkargs.NVR_LoginID = t_para->NVR_LoginID;//nvr server loginID
    strcpy(hkargs.NAR_cameraID, t_para->cameraID);//the VolID in nvr server
    hkargs.block_flag = 0;
    hkargs.NAR_recordHandle = 0;
    hkargs.HK_streamHandle = &streamHandle;

    while(1){
    	//-----------Init
    	NET_DVR_Init();
        hkargs.block_flag = 0;

    	//------------Set Connecttime and ReconnectTime
    	NET_DVR_SetConnectTime(2000,1);
    	NET_DVR_SetReconnect(10000,TRUE);

    	//-------------HKLogin
    	lUserID = NET_DVR_Login_V30(t_para->cameraIP, t_para->cameraPort, HK_userName, HK_password, &struDeviceInfo);
    	if(lUserID < 0){
    	    syslog(LOG_ERR,"connect HK IPC %s failed! errorCode: %d\n", t_para->cameraIP, NET_DVR_GetLastError());
    	    NET_DVR_Cleanup();//clear all the info
            continue;
    	}
        syslog(LOG_ERR,"connect HK IPC %s sucess!\n", t_para->cameraIP);

	//set exception callback function
    	NET_DVR_SetExceptionCallBack_V30(0, NULL, HK_RP_Exp_Callback, &hkargs);

	//get data stream and store
   	streamHandle = NET_DVR_RealPlay_V30(lUserID, &ClientInfo, HK_Store_CallBack, &hkargs, 0);
        if(streamHandle < 0){
            NET_DVR_Logout(lUserID);//get wrong handle ,logout
            NET_DVR_Cleanup();
            continue;
    	}
    	while(!hkargs.block_flag){ 
    	}
        stopResult = NET_DVR_StopRealPlay(streamHandle);
        syslog(LOG_INFO,"(InHKTransdata) stoped real play ? result:%d\n", stopResult);
        NET_DVR_Logout_V30(lUserID);
        syslog(LOG_INFO,"(InHKTransdata) HKcamera Logout(loginID was %d)\n",lUserID);
        NET_DVR_Cleanup();
        if(hkargs.block_flag == 1){
			break;
		}
    }
	return NULL;
}