void Arch_TimerTask(void * arg) { #if TIMER_TEST uint32 tick1; uint32 tick2; #endif Arch* pArch = (Arch*)arg; uint32 ticks = GET_TICKS(); TimerManager_ResetTimer(&pArch->m_TimerManager, ticks); while(1) { ticks = GET_TICKS(); TimerManager_Run(&pArch->m_TimerManager, ticks); #if TIMER_TEST tick1 = GET_TICKS(); #endif SLEEP(TIMER_TASK_INTERVAL); #if TIMER_TEST tick2 = GET_TICKS(); Printf("tick2=%d, tick1=%d, INTERVAL(%d) = tick2-tick1=%d\n", tick2, tick1, TIMER_TASK_INTERVAL, tick2-tick1); #endif } }
int vsnprintfEx(char* buffer, int bufLen, const char* lpszFormat, va_list ptr) { if(DL_SHOW_TICKS & g_dwDebugLevel) { int i = 0; int nLen = 0; static Bool isNewLine = True; if(isNewLine) { if('\n' == lpszFormat[0]) { buffer[0] = '\n'; i = 1; } nLen = sprintf(&buffer[i], "[%08x]:", GET_TICKS()) + i; } if(strlen(lpszFormat) >= 1) { isNewLine = (lpszFormat[strlen(lpszFormat) - 1] == '\n'); } nLen = vsnprintf(&buffer[nLen], bufLen - nLen, &lpszFormat[i], ptr) + nLen; return nLen; } else { return vsnprintf(buffer, bufLen, lpszFormat, ptr); } }
S32 CNetObj::SndMsg(ADP::Msg_t& Msg, S32 mSec) { CAutoDoT<CLock> Auto(m_SndMsgLock); if (m_SndBuf.DataLen() > 0) { S32 Sent = SndData(m_SndBuf.GetRdPos(), m_SndBuf.DataLen(), 0); if (Sent < 0) { DEBUG_ERROR("%s(err)[ %s(%d)]\n", __FUNCTION__, __FILE__, __LINE__); } m_SndBuf.Clear(); } Msg.Magic = ADP_MSG_MAGIC; Msg.Live = GET_TICKS(); Msg.Id = m_SndBuf.FreeLen(); S32 Size = m_pAdapter->Fill(Msg, m_SndBuf.GetWrPos(), Msg.Id); if (Size < 0) { DEBUG_ERROR("Snd msg cmd = %d failed, adapter fill", Msg.Type); return Size; } m_SndBuf.IncLen(Size); Size = SndData(m_SndBuf.GetRdPos(), m_SndBuf.DataLen(), 300); if (Size < 0) { m_SndBuf.Clear(); DEBUG_ERROR("Snd msg cmd = %d failed, senddata", Msg.Type); return NET_MSG_SEND_ERR; } m_SndBuf.DecLen(Size); return MW_SUCC; }
S32 CNetObj::SndData(S8 *Buf, S32 Len, S32 Times) { S32 Timeout = 0, Sent = 0, SndSize = Len; while (SndSize > 0 && m_bRuning) { Sent = m_Sock.Send(Buf + (Len - SndSize), SndSize, 0); if (Sent == SOCK_HANDLE_ERROR) { //if (m_bClient) //{ // ResetSock(); //} //else //{ // Stop(); //} if (m_ObjInitInfo.MsgCb) { ADP::Msg_t Msg; Msg.Magic = ADP_MSG_MAGIC; Msg.Type = ADP::ADP_MSG_NET_STOP; Msg.Live = GET_TICKS(); Msg.Body.rVal = Sent; m_ObjInitInfo.MsgCb(Msg, m_ObjInitInfo.pMsgCbParam); } Stop(); DEBUG_ERROR("[ %s:%d Sock err:%d ] \n", __FILE__, __LINE__, Sent); return MW_FAILED; } else if (Sent == SOCK_HANDLE_BUFFULL) { if (Times == 0) // send all { continue; } if (Timeout++ > Times) { return (Len - SndSize); } continue; } Timeout = 0; SndSize -= Sent; } return (Len - SndSize); }
S32 CNetObj::RcvData(S8 *Buf, S32 Len, S32 Times) { S32 Cnt = 0, Size = SOCK_HANDLE_NODATA, rVal = 0; while (Cnt++ < Times && m_bRuning) { Size = m_Sock.Recv(Buf, Len, 0); if (SOCK_HANDLE_NODATA == Size) { continue; } else if (SOCK_HANDLE_CLOSE == Size || SOCK_HANDLE_ERROR == Size) { //if (m_bClient) //{ // ResetSock(); //} //else //{ // Stop(); //} if (m_ObjInitInfo.MsgCb) { ADP::Msg_t Msg; Msg.Magic = ADP_MSG_MAGIC; Msg.Type = ADP::ADP_MSG_NET_STOP; Msg.Live = GET_TICKS(); Msg.Body.rVal = Size; m_ObjInitInfo.MsgCb(Msg, m_ObjInitInfo.pMsgCbParam); } Stop(); rVal = MW_FAILED; DEBUG_ERROR("[ %s:%d Sock err:%d ] \n", __FILE__, __LINE__, Size); break; } else if (Size > 0) { rVal = Size; break; } } return rVal; }
// Initializes and "pings" the LDP/VLDP and returns true if the player is online and detected // or false if the LDP could not be initialized bool ldp::pre_init() { bool result = true; // assume everything works until we find out otherwise bool temp = true; // needed to make && work the way we want below // If we are controlling a real LDP, // or if we are controlling a combo and DVD initialized properly, // then initialize the serial port here if (need_serial) { printline("NOTE : You are attempting to use DAPHNE with a real laserdisc player!"); printline("If you don't have DAPHNE plugged into a real laserdisc player,"); printline("you should be using VLDP instead."); serial_initialized = serial_init(get_serial_port(), get_baud_rate()); temp = serial_initialized; } player_initialized = init_player(); result = temp && player_initialized; m_start_time = GET_TICKS(); m_uElapsedMsSincePlay = 0; m_uBlockedMsSincePlay = 0; m_uElapsedMsSinceStart = 0; m_uMsVblankBoundary = 0; m_bPreInitCalled = true; m_bWaitingForVblankToPlay = false; m_iSkipOffsetSincePlay = 0; m_uMsFrameBoundary = 0; m_uVblankCount = 0; m_uVblankMiniCount = 0; m_uFramesToSkipPerFrame = 0; m_uFramesToStallPerFrame = 0; m_uStallFrames = 0; m_bVerbose = true; return(result); }
S32 CNetObj::ParseData() { ADP::Msg_t Msg; BOOL bGoOn = false; //memset(&Msg, 0x00, sizeof(ADP::Msg_t)); Msg.Magic = ADP_MSG_MAGIC; //DEBUG_INFO("parse socktag = %d func=%s line=%d\n", tag, __func__, __LINE__ ); do { bGoOn = m_pAdapter->Parser(Msg); switch (Msg.Type) { case ADP::ADP_CMD_REQ_LOGIN: Msg.Type = ADP::ADP_CMD_RSP_LOGIN; Msg.Body.RspLogin.rVal = MW_SUCC; Msg.Body.RspLogin.Token = GET_TICKS(); SndMsg(Msg); break; case ADP::ADP_CMD_RSP_LOGIN: break; case ADP::ADP_CMD_REQ_LOGOUT: break; case ADP::ADP_CMD_RSP_HEART_BEAT: // break; case ADP::ADP_CMD_REQ_STREAM_OPEN: m_StrUrl = Msg.Body.ReqStreamOpen.URL; Msg.Body.RspStreamOpen.rVal = m_pStream->Open(GetUrl(m_StrUrl).c_str(), AV_STREAM_MODE); if ( MW_SUCC != Msg.Body.RspStreamOpen.rVal ) { m_pStream->Close(); Msg.Body.RspStreamOpen.rVal = NET_MSG_OPEN_FILE_ERR; } else { m_bAvStreamSnd = true; // AudioHead_t a; VideoHead_t v; // m_pStream->GetAHead(a); m_pStream->GetVHead(v); // Msg.Body.RspStreamOpen.aSampleRate = a.SampleRate; // Msg.Body.RspStreamOpen.aBitsPerSample = a.BitsPerSample; Msg.Body.RspStreamOpen.vWidth = v.VWidth; Msg.Body.RspStreamOpen.vHeight = v.VHeight; Msg.Body.RspStreamOpen.vBitRate = v.VBitRate; Msg.Body.RspStreamOpen.vFrameRate = v.VFrameRate; Msg.Body.RspStreamOpen.Token = (m_Token = GET_TICKS()); Msg.Body.RspStreamOpen.Frames = m_pStream->GetFrames(); Msg.Body.RspStreamOpen.FrameIntValmSec = m_pStream->GetIntVal(); } Msg.Type = ADP::ADP_CMD_RSP_STREAM_OPEN; SndMsg(Msg); break; case ADP::ADP_CMD_REQ_STREAM_CLOSE: m_bAvStreamSnd = false; //Msg.Type = ADP::ADP_CMD_RSP_STREAM_CLOSE; //Msg.Body.RspStreamClose.rVal = MW_SUCC; //SndMsg(Msg); m_pStream->Close(); Stop(); break; case ADP::ADP_CMD_REQ_STREAM_SEEK: Msg.Body.RspStreamSeek.rVal = m_pStream->Seek(Msg.Body.ReqStreamSeek.Offset); Msg.Type = ADP::ADP_CMD_RSP_STREAM_SEEK; SndMsg(Msg); break; case ADP::ADP_CMD_REQ_STREAM_MODE: Msg.Body.RspStreamMode.rVal = m_pStream->SetRdMode(Msg.Body.ReqStreamMode.Mode); Msg.Type = ADP::ADP_CMD_RSP_STREAM_MODE; SndMsg(Msg); break; case ADP::ADP_CMD_AV_FRAME: if (m_ObjInitInfo.AvFrameCb) { m_ObjInitInfo.AvFrameCb(Msg.Body.pFrame, m_ObjInitInfo.pAvFrameCbParam); } break; case ADP::ADP_CMD_AV_EOF: if (m_ObjInitInfo.MsgCb) { m_ObjInitInfo.MsgCb(Msg, m_ObjInitInfo.pMsgCbParam); } break; case ADP::ADP_CMD_RSP_STREAM_OPEN: case ADP::ADP_CMD_RSP_STREAM_CLOSE: case ADP::ADP_CMD_RSP_STREAM_SEEK: case ADP::ADP_CMD_RSP_STREAM_MODE: PutMsg(Msg); break; default: break; } m_RcvBuf.Update(); } while (bGoOn && m_bRuning); return MW_SUCC; }
unsigned int GetTicksFunc() { return GET_TICKS(); }
// returns the elapsed time (in milliseconds) since the current // time and previous_time (which is also in milliseconds) unsigned int elapsed_ms_time(unsigned int previous_time) { return (GET_TICKS() - previous_time); }