Переглянути джерело

Z991239-5647 #comment 优化gettickcount跨平台实现方式

80274480 1 рік тому
батько
коміт
3491b67eff

+ 3 - 13
Module/mod_counterconnector/ConnectorFSM.cpp

@@ -45,16 +45,6 @@ static const char* connect_failed_rtamsg_table[] = {
 };
 
 
-#ifdef RVC_OS_LINUX
-static unsigned long GetTickCount()
-{
-	struct timespec ts;
-	clock_gettime(CLOCK_MONOTONIC, &ts);
-	return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
-}
-#endif
-
-
 class  SyncServiceClient:public SyncService_ClientBase
 {
 public:
@@ -877,7 +867,7 @@ void ACMCallFSM::s11_on_entry()
 	LogWarn(Severity_Low, Error_Debug, LOG_WARN_COUNTERCONNECT_MAKECALL,"begin make call");
 	m_uConnectTime = y2k_time_now();
 	m_bConnected = false;
-	m_lConnectCostTime = GetTickCount();
+	m_lConnectCostTime = SP::Module::Comm::RVCGetTickCount();
 	
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402304Z80101")("begin remote video call");
 
@@ -1454,7 +1444,7 @@ void ACMCallFSM::s3_on_entry()
 		unsigned int unowtime = y2k_time_now();
 		LogWarn(Severity_Low, Error_Debug, LOG_WARN_COUNTERCONNECT_CALL_CONNECTING_TIME, CSimpleStringA::Format("handfree call connecting time is %us.", unowtime - m_uConnectTime).GetData());
 		m_uConnectTime = unowtime;
-		long lnowtime = GetTickCount();
+		long lnowtime = SP::Module::Comm::RVCGetTickCount();
 		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("RemoteVideoCall::Connecting").setCostTime(lnowtime - m_lConnectCostTime)("RemoteVideoCall::Connecting");
 		m_lConnectCostTime = lnowtime;
 	}
@@ -1507,7 +1497,7 @@ void ACMCallFSM::s4_on_entry()
 		unsigned int unowtime = y2k_time_now();
 		LogWarn(Severity_Low, Error_Debug, LOG_WARN_COUNTERCONNECT_CALL_CONNECTING_TIME, CSimpleStringA::Format("pickup call connecting time is %us.", unowtime - m_uConnectTime).GetData());
 		m_uConnectTime = unowtime;
-		long lnowtime = GetTickCount();
+		long lnowtime = SP::Module::Comm::RVCGetTickCount();
 		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("RemoteVideoCall::Connecting").setCostTime(lnowtime - m_lConnectCostTime)("RemoteVideoCall::Connecting");
 		m_lConnectCostTime = lnowtime;
 	}

+ 1 - 0
Module/mod_counterconnector/ConnectorFSM.h

@@ -8,6 +8,7 @@
 #include "Event.h"
 #include "../include/EventCode.h"
 #include "y2k_time.h"
+#include "CommEntityUtil.hpp"
 
 #ifdef _WIN32
 #include "resource.h"

+ 3 - 19
Module/mod_recorder/recordinfo.cpp

@@ -1,7 +1,7 @@
 #include "recordinfo.h"
 #include "strutil.h"
 #include "Event.h"
-
+#include "CommEntityUtil.hpp"
 
 void HttpsLogCallBack(const char* logtxt) {
 	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI("HttpsLogCallBack")("HttpsLogCallBack: %s.", logtxt);
@@ -67,13 +67,13 @@ int post_video_recordinfo_list(unsigned int& uposttime, CSimpleStringA& errormsg
 
 	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("begin http get request, timeout is %d, printdbg flag is %s.", req.m_timeOut, req.m_printDbg ? "true" : "false");
 
-	unsigned int ustarttime = get_millisec_time();
+	unsigned int ustarttime = SP::Module::Comm::RVCGetTickCount();
 
 	RecordInfoHTTPRet ret;
 	if (client->Post(req, ret)) {
 		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("post result is %s, returnCode:%s, code:%s, errorMsg:%s, message:%s.",
 			ret.m_success ? "success" : "failed", ret.m_returnCode.c_str(), ret.m_code.c_str(), ret.m_errorMsg.c_str(), ret.m_message.c_str());
-		uposttime = get_millisec_time() - ustarttime;
+		uposttime = SP::Module::Comm::RVCGetTickCount() - ustarttime;
 		iret = 0;
 	}
 	else {
@@ -83,19 +83,3 @@ int post_video_recordinfo_list(unsigned int& uposttime, CSimpleStringA& errormsg
 	return iret;
 }
 
-
-unsigned int get_millisec_time()
-{
-#ifdef RVC_OS_LINUX
-	unsigned int uptime = 0;
-	struct timespec on;
-	if (clock_gettime(CLOCK_MONOTONIC, &on) == 0) {
-		uptime = on.tv_sec * 1000 + on.tv_nsec / 1000000;
-	}
-		
-	return uptime;
-
-# else
-	return GetTickCount();
-#endif
-}

+ 0 - 2
Module/mod_recorder/recordinfo.h

@@ -99,6 +99,4 @@ struct RecordInfoHTTPRet : CHTTPRet {
 
 int post_video_recordinfo_list(unsigned int& uposttime, CSimpleStringA& errormsg, video_record_info_t* pinfo, int itimeout, bool bprintdbg);
 
-unsigned int get_millisec_time();
-
 #endif

+ 2 - 11
Module/mod_sipphone/endpoint.cpp

@@ -1153,15 +1153,6 @@ static int __endpoint_break(void *arg)
 	return 0;
 }
 
-#ifdef RVC_OS_WIN
-#else
-static unsigned long GetTickCount()
-{
-	struct timespec ts;
-	clock_gettime(CLOCK_MONOTONIC, &ts);
-	return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
-}
-#endif
 
 static endpoint_t *__endpoint_create(CEntityBase *pEntity, const endpoint_conf_t *conf,int nDev)
 {
@@ -1173,10 +1164,10 @@ static endpoint_t *__endpoint_create(CEntityBase *pEntity, const endpoint_conf_t
 
 	memcpy(&ep->conf, conf, sizeof(endpoint_conf_t));
 
-	ep->media_port_seq = (conf->media_start_port + (GetTickCount() % (conf->media_stop_port - conf->media_start_port))) & 0xfffc;
+	ep->media_port_seq = (conf->media_start_port + (SP::Module::Comm::RVCGetTickCount() % (conf->media_stop_port - conf->media_start_port))) & 0xfffc;
 	
 	ep->entity = pEntity;
-	ep->call_seq = GetTickCount();
+	ep->call_seq = SP::Module::Comm::RVCGetTickCount();
 	ep->curr_audio_dev_type = nDev;
 	INIT_LIST_HEAD(&ep->call_list);
 

+ 1 - 0
Module/mod_sipphone/endpoint.h

@@ -4,6 +4,7 @@
 #pragma once
 #include "EventCode.h"
 #include "mod_counterconnector/CallType.h"
+#include "CommEntityUtil.hpp"
 
 #ifdef _WIN32
 #else

+ 2 - 12
Module/mod_sipphone/mod_sipphone.cpp

@@ -249,16 +249,6 @@ static int tovalidwidth(int iwidth)
 }
 
 
-#ifdef RVC_OS_WIN
-#else
-static unsigned long GetTickCount()
-{
-	struct timespec ts;
-	clock_gettime(CLOCK_MONOTONIC, &ts);
-	return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
-}
-#endif
-
 CSIPEntity::CSIPEntity() : m_pCurrentSession(NULL), m_state(INIT),m_iPickupPhoneState(ePickupMicrophoneState_Off) 
 {
 	m_kept_volume_in[0] = m_kept_volume_in[1] = 0;
@@ -570,10 +560,10 @@ void CSIPEntity::OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionC
 
 void CSIPEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext) 
 { 
-	long lstarttime = GetTickCount();
+	long lstarttime = SP::Module::Comm::RVCGetTickCount();
 	ErrorCodeEnum Error = __OnStart(Error_Succeed);
 	pTransactionContext->SendAnswer(Error);
-	long lcosttime = GetTickCount() - lstarttime;
+	long lcosttime = SP::Module::Comm::RVCGetTickCount() - lstarttime;
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("Sipphone::Starting").setCostTime(lcosttime)("Sipphone::Starting");
 	LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_ENTITY_STARTING_COST, CSimpleStringA::Format("sipphone entity starting cost time is %dms.", lcosttime));
 }