j_result_t CXlChannel::InputData(const j_int32_t nType, const CXlHostRespData *respData) { J_StreamHeader streamHeader = {0}; streamHeader.dataLen = respData->respHeader.length + sizeof(CXlProtocol::CmdHeader) + sizeof(CXlProtocol::CmdTail); if (nType == CXlProtocol::xlc_real_play) { //J_StreamHeader streamHeader; //m_parser.InputData((const char *)respData.pData + 79, respData.respHeader.length - 79); //j_result_t nResult = m_parser.GetOnePacket(m_pDataBuff, streamHeader); //while (nResult == J_OK) //{ // streamHeader.dataLen -= 4; // TLock(m_vecLocker); // std::vector<CRingBuffer *>::iterator it = m_vecRingBuffer.begin(); // for (; it != m_vecRingBuffer.end(); it++) // { // (*it)->PushBuffer((char *)m_pDataBuff + 4, streamHeader); // } // TUnlock(m_vecLocker); // nResult = m_parser.GetOnePacket(m_pDataBuff, streamHeader); //} //J_OS::LOGINFO("CXlChannel::InputData send len = %d", streamHeader.dataLen); TLock(m_vecLocker); std::vector<CXlProtocol::CmdHeader>::iterator it = m_vecCmdHeader.begin(); for (; it != m_vecCmdHeader.end(); it++) { CXlClientRespData *response = (CXlClientRespData *)respData; response->respHeader.seq = it->seq; JoDataBus->Response(*response); } TUnlock(m_vecLocker); } else { //TLock(m_mapLocker); //std::map<j_guid_t, CRingBuffer *>::iterator it = m_mapRingBuffer.find(respData.respVodData.sessionId); //if (it != m_mapRingBuffer.end()) //{ // it->second->PushBuffer((char *)&respData, streamHeader); //} //TUnlock(m_mapLocker); //J_OS::LOGINFO("CXlChannel::InputData send len = %d", streamHeader.dataLen); TLock(m_vecLocker); std::vector<CXlProtocol::CmdHeader>::iterator it = m_vecCmdHeader.begin(); for (; it != m_vecCmdHeader.end(); it++) { CXlClientRespData *response = (CXlClientRespData *)respData; response->respHeader.seq = it->seq; JoDataBus->Response(*response); } TUnlock(m_vecLocker); } return J_OK; }
j_result_t CXlClient::SendMsgInfo(j_string_t strHostId, j_int32_t nType, j_int32_t nNo, j_int32_t nChannel) { if (nType == xlc_msg_host) { J_OS::LOGINFO("CXlClient::SendMsgInfo xlc_msg_host sub = %d", nNo); if (nNo == xlc_host_broken) { TLock(m_vecLocker); VideoInfoVec::iterator it = m_videoInfoVec.begin(); for (; it!=m_videoInfoVec.end(); ++it) { if (it->strHost == strHostId) { it->bConnected = false; } } TUnlock(m_vecLocker); } else if (nNo == xlc_host_connected) { TLock(m_vecLocker); VideoInfoVec::iterator it = m_videoInfoVec.begin(); for (; it!=m_videoInfoVec.end(); ++it) { if (!it->bConnected) { CliRealPlay realPlay = {0}; strcpy(realPlay.hostId, it->strHost.c_str()); realPlay.channel = it->nChanId; if (StartView(realPlay, NULL) == J_OK) { it->bConnected = true; } } } TUnlock(m_vecLocker); } } else { struct MessageBody { CmdHeader header; CliMessage data; CmdTail tial; } messageBody; memset (&messageBody, 0, sizeof(MessageBody)); messageBody.data.uiType = nType; messageBody.data.uiNO = nNo; messageBody.data.nChannelID = nChannel; strcpy(messageBody.data.hostID, strHostId.c_str()); CXlHelper::MakeResponse(xlc_message, (j_char_t *)&messageBody.data, sizeof(CliMessage), (j_char_t *)&messageBody); m_socket.Write_n((j_char_t *)&messageBody, sizeof(CmdHeader) + sizeof(CliMessage) + sizeof(CmdTail)); J_OS::LOGINFO("CXlClient::SendMessage %d-%d", nType, nNo); } return J_OK; }
void CJorFileReader::OnWork() { int nRet = J_OK; J_StreamHeader streamHeader; char *pBuffer = new char[1024 * 1024 * 5]; int nfd = 0; while (m_bRun) { if (m_lastTime == 0) { TLock(m_mux); m_cond.Wait(m_mux); //m_jorHelper.ReadFile(m_recvSocket, m_resid.c_str(), 0, 2*60*1000); //m_lastTime += 2*60*1000; //nfd = m_recvSocket->GetHandle(); TUnlock(m_mux); } if (m_buffer->GetIdleLength() != RECORD_BUFF_SIZE) { j_sleep(10); continue; } TLock(m_locker); J_DataHead head = {0}; j_sleep(39); int nLen = m_recvSocket->Read_n((char *)&head, sizeof(head)); if (nLen < 0) { J_OS::LOGERROR("CJorFileReader::OnRead recv data error"); //TUnlock(m_locker); //return J_SOCKET_ERROR; //未处理 m_bRun = false; TUnlock(m_locker); break; } int nLength = ntohl(head.data_len); nLen = m_recvSocket->Read_n(pBuffer, nLength); if (nLen > 0) { int nRet = 0; J_StreamHeader streamHeader = {0}; streamHeader.timeStamp = ntohll(head.time_stamp); streamHeader.frameType = ntohl(head.frame_type); streamHeader.dataLen = nLength; streamHeader.frameNum = ntohl(head.frame_seq); if (nRet == J_OK) { m_buffer->PushBuffer(pBuffer, streamHeader); m_lastTime -= 40; } } TUnlock(m_locker); } delete pBuffer; }
LOCAL TBOOL rfb_getimsg(RFBDISPLAY *mod, RFBWINDOW *v, TIMSG **msgptr, TUINT type) { TAPTR TExecBase = TGetExecBase(mod); TIMSG *msg; TLock(mod->rfb_InstanceLock); msg = (TIMSG *) TRemHead(&mod->rfb_IMsgPool); TUnlock(mod->rfb_InstanceLock); if (msg == TNULL) msg = TAllocMsg(sizeof(TIMSG)); *msgptr = msg; if (msg) { memset(msg, 0, sizeof(TIMSG)); msg->timsg_Instance = v; msg->timsg_UserData = v->userdata; msg->timsg_Type = type; msg->timsg_Qualifier = mod->rfb_KeyQual; msg->timsg_MouseX = mod->rfb_MouseX; msg->timsg_MouseY = mod->rfb_MouseY; TGetSystemTime(&msg->timsg_TimeStamp); return TTRUE; } return TFALSE; }
j_result_t CDeviceManager::AddDevice(J_Host *pHost, j_socket_t sock) { if (pHost != NULL) { j_string_t strDevId; if (pHost->GetHostId(strDevId) == J_OK) { DeviceMap::iterator hostIt = m_devMap.find(strDevId); if (hostIt != m_devMap.end()) { j_close_socket(hostIt->second.sock.sock); ReleaseDevObj(hostIt->second.sock); } TLock(m_devLocker); //设备添加成功 LocalHostInfo info = {0}; info.pHost = pHost; info.sock = sock; m_devMap[strDevId] = info; TUnlock(m_devLocker); } } return J_OK; }
j_result_t CXlClient::StartVod(const CliStartVod &startVod, J_AsioDataBase *pAsioData) { J_Host *pHost = JoDeviceManager->GetDeviceObj(startVod.hostId); if (pHost != NULL) { J_Obj *pObj = NULL; pHost->MakeChannel(startVod.channel, pObj); if (pObj != NULL) { J_Vod *pVod = dynamic_cast<J_Vod *>(pObj); if (pVod != NULL) pVod->OpenVod(startVod.sessionId, &m_ringBuffer); } pAsioData->ioRead.buf = m_readBuff; pAsioData->ioRead.bufLen = pAsioData->ioRead.finishedLen + sizeof(CmdHeader); pHost->ParserRequest(pAsioData); TLock(m_vodLocker); VodInfo info = {0}; info.sessionId = startVod.sessionId; info.nChanId = startVod.channel; info.strHost = startVod.hostId; m_vodInfoVec.push_back(info); TUnlock(m_vodLocker); } return J_OK; }
j_result_t CXlClient::StopVod(const CliStopVod &stopVod, J_AsioDataBase *pAsioData) { J_Host *pHost = JoDeviceManager->GetDeviceObj(stopVod.hostId); if (pHost != NULL) { pAsioData->ioRead.buf = m_readBuff; pAsioData->ioRead.bufLen = pAsioData->ioRead.finishedLen + sizeof(CmdHeader); pHost->ParserRequest(pAsioData); J_Obj *pObj = NULL; pHost->MakeChannel(stopVod.channel, pObj); if (pObj != NULL) { J_Vod *pVod = dynamic_cast<J_Vod *>(pObj); if (pVod != NULL) pVod->CloseVod(stopVod.sessionId, &m_ringBuffer); } TLock(m_vodLocker); VodInfoVec::iterator it = m_vodInfoVec.begin(); for (; it!=m_vodInfoVec.end(); ++it) { if (it->sessionId == stopVod.sessionId) { m_vodInfoVec.erase(it); break; } } TUnlock(m_vodLocker); } return J_OK; }
J_Host *CDeviceManager::CreateDevObj(j_int32_t nHostType, j_socket_t nSock) { J_Host *pHost = NULL; try { switch (nHostType) { case 1://XlHost pHost = new CXlHost(nSock); break; default: break; } } catch(...) { J_OS::LOGINFO("CDeviceManager::CreateDevObj Error"); } if (pHost != NULL) { NetHostInfo info = {0}; info.pHost = pHost; info.bRegister = false; TLock(m_locker); m_connMap[nSock] = info; TUnlock(m_locker); } return pHost; }
j_result_t CXlClient::EnableAlarm(const CXlClientCmdData &cmdData, j_boolean_t bEnable) { TLock(m_locker); AlarmEnableMap::iterator it = m_alarmEnableMap.find(cmdData.cmdRealAlarm.hostId); if (it != m_alarmEnableMap.end()) { if (bEnable == false) { m_alarmEnableMap.erase(it); CXlClientRespData::RespErrorCode data = { 0 }; data.code = 0x00; CXlHelper::MakeResponse(CXlProtocol::xlc_real_alarm, cmdData.cmdHeader.flag, cmdData.cmdHeader.seq, (j_char_t *)&data, sizeof(CXlClientRespData::RespLogout), m_dataBuff); J_StreamHeader streamHeader = { 0 }; streamHeader.dataLen = sizeof(CXlProtocol::CmdHeader) + sizeof(CXlClientRespData::RespErrorCode) + sizeof(CXlProtocol::CmdTail); m_ringBuffer.PushBuffer(m_dataBuff, streamHeader); } } else { if (bEnable == true) { m_alarmEnableMap[cmdData.cmdRealAlarm.hostId] = true; } } TUnlock(m_locker); return J_OK; }
int CHikStream::Startup() { if (m_bStartup) return J_OK; TLock(m_locker); m_bStartup = true; //JoXAsio->Init(); JoXAsio->AddUser(m_nSocket, this); //读取4字节头信息 memset(m_asioData, 0, sizeof(J_AsioDataBase)); m_asioData->ioUser = this; m_asioData->ioRead.buf = m_pRecvBuff; m_asioData->ioRead.bufLen = 4; m_asioData->ioRead.whole = true; m_asioData->ioCall = J_AsioDataBase::j_read_e; m_nState = HIK_READ_HEAD; m_nOffset = 0; m_asioData->ioRead.shared = true; JoXAsio->Read(m_nSocket, m_asioData); TUnlock(m_locker); J_OS::LOGINFO("CHikStream::Startup Startup this = %d", m_nSocket.sock); return J_OK; }
J_Decoder *CDecoderFactory::GetDecoder(j_wnd_t hWindow, const char *pType) { TLock(m_lock); J_Obj *protocolDecoder = NULL; DecoderMap::iterator it = m_decMap.find(hWindow); if (it == m_decMap.end()) { DecoderRegistMap::iterator itDecoder = m_decRegistMap.find(pType); if (itDecoder == m_decRegistMap.end()) { J_OS::LOGINFO("CDecoderFactory::GetDecoder Decoder not registed, decType = %s", pType); } else { itDecoder->second(protocolDecoder); } if (protocolDecoder != NULL) m_decMap[hWindow] = dynamic_cast<J_Decoder *>(protocolDecoder); } else protocolDecoder = it->second; TUnlock(m_lock); return dynamic_cast<J_Decoder *>(protocolDecoder); }
int CNvrFileReader::GetPacket(char *pBuffer, J_StreamHeader &streamHeader) { TLock(m_locker); if (!m_bRun) { TUnlock(m_locker); return J_UNKNOW; } TUnlock(m_locker); int nRet = J_OK; if (m_bPaused) { streamHeader.dataLen = 0; streamHeader.frameType = jo_media_unknow; streamHeader.timeStamp = 0; streamHeader.frameNum = 0; } else { nRet = m_buffer->PopBuffer(pBuffer, streamHeader); if (nRet != J_OK) { streamHeader.dataLen = 0; streamHeader.frameType = jo_media_unknow; streamHeader.timeStamp = 0; streamHeader.frameNum = 0; } } return J_OK; }
J_JoManager *CManagerFactory::GetManager(const char *pManagerType) { TLock(m_lock); J_Obj *pManager = NULL; ManagerMap::iterator it = m_managerMap.find(pManagerType); if (it == m_managerMap.end()) { ManagerRegistMap::iterator itManager = m_managerRegistMap.find(pManagerType); if (itManager == m_managerRegistMap.end()) { J_OS::LOGINFO("CManagerFactory::GetManager Manager not registed, managerType = %s", pManagerType); TUnlock(m_lock); return NULL; } else { itManager->second(pManager); } if (pManager != NULL) m_managerMap[pManagerType] = dynamic_cast<J_JoManager *>(pManager); } else pManager = it->second; TUnlock(m_lock); return dynamic_cast<J_JoManager *>(pManager); }
void CDeviceManager::CheckDevice() { TLock(m_locker); ConnectMap::iterator it = m_connMap.begin(); for (; it!=m_connMap.end(); ++it) { J_Host *pHost = it->second.pHost; if (pHost->IsReady()) { if (!it->second.bRegister) { pHost->GetDeviceInfo(); pHost->SetTime(time(0)); AddDevice(pHost, it->first); it->second.bRegister = true; } } else { if (it->second.bRegister) { DelDevice(pHost); j_close_socket(it->first.sock); m_connMap.erase(it); TUnlock(m_locker); break; } } } TUnlock(m_locker); }
LOCAL TBOOL fb_getimsg(WINDISPLAY *mod, WINWINDOW *win, TIMSG **msgptr, TUINT type) { struct TExecBase *TExecBase = TGetExecBase(mod); TIMSG *msg; TBOOL res = TFALSE; TLock(mod->fbd_Lock); msg = (TIMSG *) TRemHead(&mod->fbd_IMsgPool); if (msg == TNULL) msg = TAllocMsg0(sizeof(TIMSG)); if (msg) { msg->timsg_Instance = win; msg->timsg_UserData = win->fbv_UserData; msg->timsg_Type = type; msg->timsg_Qualifier = win->fbv_KeyQual; msg->timsg_MouseX = win->fbv_MouseX; msg->timsg_MouseY = win->fbv_MouseY; TGetSystemTime(&msg->timsg_TimeStamp); *msgptr = msg; res = TTRUE; } else *msgptr = TNULL; TUnlock(mod->fbd_Lock); return res; }
static void fb_dowindow(TAPTR task) { struct TExecBase *TExecBase = TGetExecBase(task); WINWINDOW *win = TGetTaskData(task); WINDISPLAY *mod = win->fbv_Display; MSG msg; TUINT sig; TDBPRINTF(TDB_INFO,("DoWindow...\n")); do { WaitMessage(); while (PeekMessage(&msg, win->fbv_HWnd, 0,0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } // PostMessage(win->fbv_HWnd, WM_USER, 0, 0); sig = TSetSignal(0, TTASK_SIG_ABORT); } while (!(sig & TTASK_SIG_ABORT)); TDBPRINTF(TDB_INFO,("Window Done\n")); TLock(mod->fbd_Lock); TRemove(&win->fbv_Node); TUnlock(mod->fbd_Lock); fb_closeall(mod, win, TTRUE); }
LOCAL void rfb_putbackmsg(struct rfb_Display *mod, TIMSG *msg) { TAPTR TExecBase = TGetExecBase(mod); TLock(mod->rfb_InstanceLock); TAddTail(&mod->rfb_IMsgPool, &msg->timsg_Node); TUnlock(mod->rfb_InstanceLock); }
j_result_t CXlClient::StopAllReal() { J_Host *pHost = NULL; J_AsioDataBase asioData; struct RealPlayBody { CmdHeader head; DevRealPlay data; CmdTail tail; } realPlayBody; TLock(m_vecLocker); J_OS::LOGINFO("CXlClient::StopAllReal There is %d real video channel", m_videoInfoVec.size()); VideoInfoVec::iterator it = m_videoInfoVec.begin(); for (; it!=m_videoInfoVec.end(); ++it) { pHost = JoDeviceManager->GetDeviceObj(it->strHost.c_str()); if (pHost != NULL) { memset(&realPlayBody, 0, sizeof(RealPlayBody)); memcpy(realPlayBody.data.hostId, it->strHost.c_str(), strlen(it->strHost.c_str())); realPlayBody.data.channel = it->nChanId; CXlHelper::MakeRequest(xlc_stop_real_view, (char *)&realPlayBody.data, sizeof(DevRealPlay), (char *)&realPlayBody); asioData.ioType = J_AsioDataBase::j_command_e; asioData.ioRead.buf = (j_char_t *)&realPlayBody; asioData.ioRead.bufLen = sizeof(CmdHeader) + sizeof(DevRealPlay) + sizeof(CmdTail); pHost->ParserRequest(&asioData); J_Obj *pObj = NULL; pHost->MakeChannel(it->nChanId, pObj); if (pObj != NULL) { J_Channel *pChannel = dynamic_cast<J_Channel *>(pObj); if (pChannel != NULL) { pChannel->CloseStream(&m_ringBuffer); } else { J_OS::LOGINFO("CXlClient::StopAllReal channel obj issue"); } } else { J_OS::LOGINFO("CXlClient::StopAllReal channel not found, channel_num = %d", it->nChanId); } } else { J_OS::LOGINFO("CXlClient::StopAllReal host not found, host_id = %s", it->strHost.c_str()); } } m_videoInfoVec.clear(); TUnlock(m_vecLocker); return J_OK; }
int CNvrFileReader::GetMediaData(j_uint64_t beginTime, j_int32_t nIval) { TLock(m_locker); m_lastTime += nIval; m_cond.Single(); TUnlock(m_locker); return J_OK; }
int CJorFileReader::GetMediaData(j_uint64_t beginTime, int nIval) { TLock(m_locker); m_lastTime += 24*60*60*1000; m_cond.Single(); TUnlock(m_locker); return J_OK; }
void CHostManager::DelHost(const j_string_t &strHostId) { TLock(m_locker); HostMap::iterator it = m_hostMap.find(strHostId); if (it != m_hostMap.end()) { m_hostMap.erase(strHostId); } TUnlock(m_locker); }
static void fb_modclose(WINDISPLAY *mod) { struct TExecBase *TExecBase = TGetExecBase(mod); TDBPRINTF(TDB_TRACE,("Device close\n")); TLock(mod->fbd_Lock); if (--mod->fbd_RefCount == 0) fb_exit(mod); TUnlock(mod->fbd_Lock); }
void CManagerFactory::DelManager(const char *pManagerType) { TLock(m_lock); ManagerMap::iterator it = m_managerMap.find(pManagerType); if (it != m_managerMap.end()) { delete it->second; m_managerMap.erase(it); } TUnlock(m_lock); }
void CDecoderFactory::DelDecoder(j_wnd_t hWindow) { TLock(m_lock); DecoderMap::iterator it = m_decMap.find(hWindow); if (it != m_decMap.end()) { delete it->second; m_decMap.erase(it); } TUnlock(m_lock); }
static TBOOL rfb_passevent_to_focus(RFBDISPLAY *mod, TIMSG *omsg) { TAPTR TExecBase = TGetExecBase(mod); TBOOL sent = TFALSE; TLock(mod->rfb_InstanceLock); RFBWINDOW *v = mod->rfb_FocusWindow; if (v) sent = rfb_passevent(mod, v, omsg); TUnlock(mod->rfb_InstanceLock); return sent; }
void CDeviceManager::ReleaseDevObj(j_socket_t nSock) { TLock(m_locker); ConnectMap::iterator it = m_connMap.find(nSock); if (it != m_connMap.end()) { DelDevice(it->second.pHost); m_connMap.erase(it); } TUnlock(m_locker); }
j_result_t CHikStream::OnBroken(const J_AsioDataBase *pAsioData, int nRet) { J_OS::LOGINFO("CHikStream::OnBroken"); TLock(m_locker); J_StreamHeader streamHeader = {0}; streamHeader.frameType = jo_media_broken; streamHeader.timeStamp = JoTime->GetLocalTime(0); TLock(m_vecLocker); std::vector<CRingBuffer *>::iterator it = m_vecRingBuffer.begin(); for (; it != m_vecRingBuffer.end(); it++) { //J_OS::LOGINFO("nDataLen > 0 socket = %d", m_nSocket); (*it)->PushBuffer(m_pRecvBuff, streamHeader); } TUnlock(m_vecLocker); JoXAsio->DelUser(m_nSocket); TUnlock(m_locker); return J_OK; }
j_result_t CXlChannel::CloseVod(const j_guid_t &sessionId, CRingBuffer *pRingBuffer) { TLock(m_mapLocker); std::map<j_guid_t, CRingBuffer *>::iterator it = m_mapRingBuffer.find(sessionId); if (it != m_mapRingBuffer.end()) { m_mapRingBuffer.erase(it); } TUnlock(m_mapLocker); return J_OK; }
J_Host *CDeviceManager::GetDeviceObj(j_socket_t nSock) { J_Host *pHost = NULL; TLock(m_locker); ConnectMap::iterator it = m_connMap.find(nSock); if (it != m_connMap.end()) { pHost = it->second.pHost; } TUnlock(m_locker); return pHost; }
J_Host *CDeviceManager::GetDeviceObj(j_string_t strDevId) { TLock(m_devLocker); DeviceMap::iterator it = m_devMap.find(strDevId); if (it != m_devMap.end()) { TUnlock(m_devLocker); return it->second.pHost; } TUnlock(m_devLocker); return NULL; }