Эх сурвалжийг харах

Z991239-4157 #comment 协助通道启动优化

80274480 2 жил өмнө
parent
commit
c946898f0c

+ 5 - 4
Module/include/EventCode.h

@@ -1047,14 +1047,15 @@ ERROR_ACCESSAUTH_CONNECT_ACS}
 #define LOG_EVT_DISTRIBUTE_ASSISTANTCHANNEL_IDLE		0x30C00001  //协助通道重置
 #define LOG_EVT_DISTRIBUTE_SIPPHONE_IDLE				0x30C00002  //sip话机重置
 
-#define LOG_EVT_DISTRIBUTE_HANGUPCALL					0x30C00005  //分布式主动挂断
-#define LOG_EVT_DISTRIBUTE_PICKUPCALL					0x30C00006  //分布式接通电话
-
-
 /*国产化新增开始*/
 #define LOG_EVT_RESOURCE_CPU_TOO_HIGH  LOG_EVT_SELFCHECK_CPU_TOO_HIGH //CPU使用率过高 (mod_ResourceWatcher)
 #define LOG_EVT_RESOURCE_MEMORY_TOO_HIGH  LOG_EVT_SELFCHECK_MEMORY_TOO_HIGH //内存使用率过高 (mod_ResourceWatcher)
 #define LOG_EVT_RESOURCE_HARDDISK_TOO_HIGH  LOG_EVT_SELFCHECK_HARDDISK_TOO_HIGH //硬盘快满 (mod_ResourceWatcher)
 /*国产化新增结束*/
 
+#define LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS		0x30C08010	//协助通道实体启动成功	
+#define LOG_EVT_MOD_SIPPHONE_STARTED_SUCCESS		0x30108280	//sipphone 实体启动成功	
+#define LOG_EVT_MOD_SALESRECORDER_STARTED_SUCCESS	0x3151000B	//salesrecorder 实体启动成功	
+#define LOG_EVT_MOD_LOCALPLAYER_STARTED_SUCCESS		0x3130010D	//localplayer 实体启动成功
+
 #endif // __EVENT_CODE_H

+ 378 - 301
Module/mod_assistantchannel/mod_assistantchannel.cpp

@@ -1,19 +1,12 @@
 #include "stdafx.h"
 #include "mod_assistantchannel.h"
-
-#include "VideoDesc.h"
-#include "AssistantChannel_server_g.h"
-#include "../../Other/rvcmediacommon/rvc_media_common.h"
-#include "chan_protocol.h"
-
-using namespace AssistantChannel;
+#include "../include/EventCode.h"
 
 static const char *__states[] = {
 	"Idle", "Connecting", "Connected", "Closing"
 };
 
 
-
 inline const char *state2str(int state)
 {
 	return __states[state];
@@ -65,321 +58,387 @@ static int MakeDesc(DWORD eScreen,DeviceTypeEnum eDevicetype)
 }
 
 
-	ErrorCodeEnum CBizChannelEntity::__OnStart(ErrorCodeEnum preOperationError)
-	{
-		//MessageBoxA(0,0,0,0);
-		bizchan_lib_init();
-		m_eState = eChannelState_Idle;
-		m_pChan = NULL;
-		m_eDeviceType = eStand2sType;
-		//is Pad Version
-		CSmartPointer<IEntityFunction> spFunction = GetFunction();
-		CSystemStaticInfo stStaticinfo;
-		spFunction->GetSystemStaticInfo(stStaticinfo);
-		if (stricmp(stStaticinfo.strMachineType,"RVC.PAD")==0)
-		{
-			if (stricmp(stStaticinfo.strSite,"CMB.FLB")==0)
-			{
-				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("the type is mobile pad");
-				m_eDeviceType = eMobilePadType;
-			}
-			else
-			{
-				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("the type is pad");
-				m_eDeviceType = ePadtype;
-			}
-		}
-		else if (stricmp(stStaticinfo.strMachineType,"RVC.Desk2S")==0)
-		{
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("the type is Desk2S");
-			m_eDeviceType = eDesk2SType;
-		}
-		else if (stricmp(stStaticinfo.strMachineType,"RPM.Stand1S")==0)
-		{
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("the type is RPM.Stand1S");
-			m_eDeviceType = eRpm1sType;
-		}
-		else
-		{
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("the type is standard");
-			m_eDeviceType = eStand2sType;
-		}
-		ListEntry_InitHead(&m_stateList);
-		ListEntry_InitHead(&m_rxpktList);
+static void __on_recv_pkt(bizchan_t *chan, int type, int sub_type, int id, const char *pkt, int pkt_size, void *user_data)
+{
+	CBizChannelEntity *pThis = static_cast<CBizChannelEntity *>(user_data);
+	pThis->_on_recv_pkt(type, sub_type, id, pkt, pkt_size);
+}
+
+static void __on_connect(bizchan_t *chan, int error, const char *remote_ip, int remote_video_rtp, int remote_video_desc, const char *remote_client_id, void *user_data)
+{
+	CBizChannelEntity *pThis = static_cast<CBizChannelEntity *>(user_data);
+	pThis->_on_connect(error, remote_ip, remote_video_rtp, remote_video_desc);
+}
 
+static void __on_close(bizchan_t *chan, void *user_data)
+{
+	CBizChannelEntity *pThis = static_cast<CBizChannelEntity *>(user_data);
+	pThis->_on_close();
+}
+
+static void __on_destroy(bizchan_t *chan, void *user_data)
+{
+
+}
 
-		//Connect("99.1.100.215", 2323, "9990", NORMAL_CALLTYPE);
-		return Error_Succeed;
+static void __dbg(void *user_data, const char *fmt, va_list arg)
+{
+	//vDbg(fmt, arg);
+	int n = _scprintf(fmt, arg);
+	if (n >= MAX_PATH) {
+		char* buf = (char*)malloc((size_t)(n + 1));
+		_snprintf(buf, n + 1, fmt, arg);
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
+		free(buf);
+	}
+	else {
+		char strlog[MAX_PATH] = { 0 };
+		_snprintf(strlog, MAX_PATH, fmt, arg);
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
 	}
+}
 
-	ErrorCodeEnum CBizChannelEntity::__OnClose(ErrorCodeEnum preOperationError)
-	{
-		//.....
-		bizchan_lib_term();
-		return Error_Succeed;
+
+
+void CBizChannelEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext) 
+{ 
+	ErrorCodeEnum Error = __OnStart(Error_Succeed);
+	pTransactionContext->SendAnswer(Error);
+}
+
+
+void CBizChannelEntity::OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext) 
+{ 
+	ErrorCodeEnum Error = __OnClose(Error_Succeed);
+	pTransactionContext->SendAnswer(Error); 
+}
+
+
+ErrorCodeEnum CBizChannelEntity::__OnStart(ErrorCodeEnum preOperationError)
+{
+	//MessageBoxA(0,0,0,0);
+	bizchan_lib_init();
+	m_eState = eChannelState_Idle;
+	m_pChan = NULL;
+	m_eDeviceType = RvcGetDeviceType();
+	ListEntry_InitHead(&m_stateList);
+	ListEntry_InitHead(&m_rxpktList);
+	return Error_Succeed;
+}
+
+void CBizChannelEntity::OnStarted()
+{
+	LogEvent(Severity_Middle, LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS, "assistant channel started successfully.");
+}
+
+DeviceTypeEnum CBizChannelEntity::RvcGetDeviceType()
+{
+	DeviceTypeEnum eType = eStand2sType;
+	CSmartPointer<IEntityFunction> spFunction = GetFunction();
+	CSystemStaticInfo stStaticinfo;
+	spFunction->GetSystemStaticInfo(stStaticinfo);
+	if (_stricmp(stStaticinfo.strMachineType,"RVC.PAD")==0){
+		if (_stricmp(stStaticinfo.strSite,"CMB.FLB")==0){
+			eType = eMobilePadType;
+		}
+		else{
+			eType = ePadtype;
+		}
+	}
+	else if (_stricmp(stStaticinfo.strMachineType,"RVC.Desk2S")==0){
+		eType = eDesk2SType;
+		WORD nMajor = stStaticinfo.MachineVersion.GetMajor();
+		WORD nMinor = stStaticinfo.MachineVersion.GetMinor();
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("MachineVersion is %d.%d", nMajor, nMinor);
+		if (2 == nMajor){
+			eType = eDesk2SIntegratedType;
+		}
+	}
+	else if (_stricmp(stStaticinfo.strMachineType,"RPM.Stand1S")==0){
+		eType = eRpm1sType;
+	}
+	else if (_stricmp(stStaticinfo.strMachineType,"RVC.Desk1S")==0){
+		eType = eDesk1SType;
+	}
+	else{
+		eType = eStand2sType;
 	}
 
-	CServerSessionBase * CBizChannelEntity::OnNewSession(const char* pszRemoteEntityName, const char * pszClass)
-	{
-		//LOG_FUNCTION();
-		//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s connected class = %s!", pszRemoteEntityName, pszClass);
-		return new ChannelServiceSession(this, m_id_seq++);
+	if (eType >= 0 && eType < sizeof(Device_Type_Table)/sizeof(char*)){
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("device type is %s.", Device_Type_Table[eType]);
 	}
+		
+	return eType;
+}
+
+
+ErrorCodeEnum CBizChannelEntity::__OnClose(ErrorCodeEnum preOperationError)
+{
+	//.....
+	bizchan_lib_term();
+	return Error_Succeed;
+}
+
+	
+CServerSessionBase* CBizChannelEntity::OnNewSession(const char* pszRemoteEntityName, const char * pszClass)
+{
+	LOG_FUNCTION();
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s connected class = %s!", pszRemoteEntityName, pszClass);
+	return new ChannelServiceSession(this, m_id_seq++);
+}
+
 
-	ErrorCodeEnum CBizChannelEntity::Connect(const char *ip, int port, const char *callno, CallingTypeEnum eType)
+ErrorCodeEnum CBizChannelEntity::Connect(const char *ip, int port, const char *callno, CallingTypeEnum eType)
+{
+	ErrorCodeEnum Error = Error_Succeed;
+	if (m_eState == eChannelState_Idle) 
 	{
-		ErrorCodeEnum Error = Error_Succeed;
-		if (m_eState == eChannelState_Idle) 
-		{
-			CSystemStaticInfo Info;
-			bizchan_config_t config = {0};
-			bizchan_callback_t cb = {0};
-			GetFunction()->GetSystemStaticInfo(Info);
-			config.proxy_server = const_cast<char*>(ip);
-			config.proxy_server_port = port;
-			if (MOBILETOPAD_CALLTYPE == eType || PADTOPAD_CALLTYPE == eType){
-				config.session_id = const_cast<char*>(callno);
-			}else{
-				config.session_id = const_cast<char*>(((const char*)Info.strTerminalID));
-			}
+		CSystemStaticInfo Info;
+		bizchan_config_t config = {0};
+		bizchan_callback_t cb = {0};
+		GetFunction()->GetSystemStaticInfo(Info);
+		config.proxy_server = const_cast<char*>(ip);
+		config.proxy_server_port = port;
+		if (MOBILETOPAD_CALLTYPE == eType || PADTOPAD_CALLTYPE == eType){
+			config.session_id = const_cast<char*>(callno);
+		}else{
+			config.session_id = const_cast<char*>(((const char*)Info.strTerminalID));
+		}
 
-			if (MOBILETOPAD_CALLTYPE == eType){
-				config.crypt_type = 1;
-			}
-			config.call_no = const_cast<char*>(callno);
-			config.client_id = "";
-			config.video.desc = MakeDesc(Info.eScreen,m_eDeviceType);
-			config.video.rtp_port = REC_COMMON_VIDEO_PORT;
-			cb.user_data = this;
-			cb.on_close = &__on_close;
-			cb.on_connect = &__on_connect;
-			cb.on_destroy = &__on_destroy;
-			cb.on_recv_pkt = &__on_recv_pkt;
-			cb.dbg = &__dbg;
-			int rc = bizchan_create(&config, &cb, &m_pChan);
-			if (rc == 0) 
-			{
-				rc = bizchan_start_connect(m_pChan);
-			}
-			if (rc != 0)
-				Error = Error_Unexpect;
-			else
-				ChangeState(eChannelState_Connecting);
-		} 
-		else 
+		if (MOBILETOPAD_CALLTYPE == eType){
+			config.crypt_type = 1;
+		}
+		config.call_no = const_cast<char*>(callno);
+		config.client_id = "";
+		config.video.desc = MakeDesc(Info.eScreen,m_eDeviceType);
+		config.video.rtp_port = REC_COMMON_VIDEO_PORT;
+		cb.user_data = this;
+		cb.on_close = &__on_close;
+		cb.on_connect = &__on_connect;
+		cb.on_destroy = &__on_destroy;
+		cb.on_recv_pkt = &__on_recv_pkt;
+		cb.dbg = &__dbg;
+		int rc = bizchan_create(&config, &cb, &m_pChan);
+		if (rc == 0) 
 		{
-			Error = Error_InvalidState;
+			rc = bizchan_start_connect(m_pChan);
 		}
-
-		//Dbg("Connect: %d", Error);
-		return Error;
+		if (rc != 0)
+			Error = Error_Unexpect;
+		else
+			ChangeState(eChannelState_Connecting);
+	} 
+	else 
+	{
+		Error = Error_InvalidState;
 	}
+	return Error;
+}
 
-	ErrorCodeEnum CBizChannelEntity::Close()
-	{
-		ErrorCodeEnum Error = Error_Succeed;
-		if (m_eState == eChannelState_Connecting || m_eState == eChannelState_Connected) {
-			int rc = bizchan_start_close(m_pChan);
-			if (rc == 0) {
-				ChangeState(eChannelState_Closing);
-			} else {
-				Error = Error_Unexpect;
-			}
+
+ErrorCodeEnum CBizChannelEntity::Close()
+{
+	ErrorCodeEnum Error = Error_Succeed;
+	if (m_eState == eChannelState_Connecting || m_eState == eChannelState_Connected) {
+		int rc = bizchan_start_close(m_pChan);
+		if (rc == 0) {
+			ChangeState(eChannelState_Closing);
 		} else {
-			Error = Error_InvalidState;
+			Error = Error_Unexpect;
 		}
-		return Error_Succeed;
+	} else {
+		Error = Error_InvalidState;
 	}
+	return Error_Succeed;
+}
 
-	ErrorCodeEnum CBizChannelEntity::RegisterState(int id, SpSubscribeContext<ChannelService_BeginState_Sub, ChannelService_State_Info>::Pointer ctx)
+
+ErrorCodeEnum CBizChannelEntity::RegisterState(int id, SpSubscribeContext<ChannelService_BeginState_Sub, ChannelService_State_Info>::Pointer ctx)
+{
+	state_entry *pos;
+	ListEntry_ForEach(pos, &m_stateList, state_entry, entry) 
 	{
-		state_entry *pos;
-		ListEntry_ForEach(pos, &m_stateList, state_entry, entry) 
+		if (pos->id == id) 
 		{
-			if (pos->id == id) 
-			{
-				return Error_AlreadyExist;
-			}
+			return Error_AlreadyExist;
 		}
-		pos = new state_entry();
-		pos->ctx = ctx;
-		pos->id = id;
-		ListEntry_AddTail(&m_stateList, &pos->entry);
-		return Error_Succeed;
 	}
+	pos = new state_entry();
+	pos->ctx = ctx;
+	pos->id = id;
+	ListEntry_AddTail(&m_stateList, &pos->entry);
+	return Error_Succeed;
+}
+
 
-	ErrorCodeEnum CBizChannelEntity::RegisterRxPkt(int id, SpSubscribeContext<ChannelService_BeginRecv_Sub, ChannelService_Packet_Info>::Pointer ctx)
+ErrorCodeEnum CBizChannelEntity::RegisterRxPkt(int id, SpSubscribeContext<ChannelService_BeginRecv_Sub, ChannelService_Packet_Info>::Pointer ctx)
+{
+	rxpkt_entry *pos;
+	ListEntry_ForEach(pos, &m_rxpktList, rxpkt_entry, entry) 
 	{
-		rxpkt_entry *pos;
-		ListEntry_ForEach(pos, &m_rxpktList, rxpkt_entry, entry) 
+		if ((pos->id == id)&&(pos->ctx->Req.type == ctx->Req.type))
 		{
-			if ((pos->id == id)&&(pos->ctx->Req.type == ctx->Req.type))
-			{
-								
-				return Error_AlreadyExist;
-			}
+			return Error_AlreadyExist;
 		}
-		//Dbg("RegisterRxPkt id = %d",id);
-		pos = new rxpkt_entry();
-		pos->id = id;
-		pos->ctx = ctx;
-		ListEntry_AddTail(&m_rxpktList, &pos->entry);
-		return Error_Succeed;
 	}
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("RegisterRxPkt id = %d",id);
+	pos = new rxpkt_entry();
+	pos->id = id;
+	pos->ctx = ctx;
+	ListEntry_AddTail(&m_rxpktList, &pos->entry);
+	return Error_Succeed;
+}
 
-	void CBizChannelEntity::UnregisterState(int id)
-	{
-		state_entry *pos,*n;
-		ListEntry_ForEachSafe(pos,n, &m_stateList, state_entry, entry) {
-			if (pos->id == id) {
-				ListEntry_DeleteNode(&pos->entry);
-				delete pos;
-			}
+
+void CBizChannelEntity::UnregisterState(int id)
+{
+	state_entry *pos,*n;
+	ListEntry_ForEachSafe(pos,n, &m_stateList, state_entry, entry) {
+		if (pos->id == id) {
+			ListEntry_DeleteNode(&pos->entry);
+			delete pos;
 		}
 	}
+}
 
-	void CBizChannelEntity::UnregisterRxpkt(int id)
+
+void CBizChannelEntity::UnregisterRxpkt(int id)
+{
+	rxpkt_entry *pos,*n;
+	//ListEntry_ForEach(pos, &m_rxpktList, rxpkt_entry, entry) 
+	ListEntry_ForEachSafe(pos, n, &m_rxpktList, rxpkt_entry, entry) 
 	{
-		rxpkt_entry *pos,*n;
-		//ListEntry_ForEach(pos, &m_rxpktList, rxpkt_entry, entry) 
-		ListEntry_ForEachSafe(pos, n, &m_rxpktList, rxpkt_entry, entry) 
+		if((pos->id == id))
 		{
-			if((pos->id == id))
-			{
-				//Dbg("UnregisterRxpkt id = %d",pos->id);
-				ListEntry_DeleteNode(&pos->entry);
-				delete pos;
-			}
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("UnregisterRxpkt id = %d",pos->id);
+			ListEntry_DeleteNode(&pos->entry);
+			delete pos;
 		}
 	}
+}
+
 
-	ErrorCodeEnum CBizChannelEntity::Send(int type, bool compress, bool encrypt, int sub_type, int id, CBlob &data)
+ErrorCodeEnum CBizChannelEntity::Send(int type, bool compress, bool encrypt, int sub_type, int id, CBlob &data)
+{
+	if (m_eState == eChannelState_Connected) {
+		//LOG_TRACE("tx pkt, %d bytes, type = %d, compress = %d, encrypt = %d, sub_type = %d, id = %d, hash=%d", data.m_iLength, type, !!compress, !!encrypt, sub_type, id, hash32_buf(data.m_pData, data.m_iLength, 0));
+		//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("tx pkt, %d bytes, type = %d, compress = %d, encrypt = %d, sub_type = %d, id = %d, hash=%d", data.m_iLength, type, !!compress, !!encrypt, sub_type, id, hash32_buf(data.m_pData, data.m_iLength, 0));
+		int rc = bizchan_post_pkt(m_pChan, type, compress, encrypt, sub_type, id, (const char*)data.m_pData, data.m_iLength);
+		return rc == 0 ? Error_Succeed : Error_NetBroken;
+	}
+	else 
 	{
-		if (m_eState == eChannelState_Connected) {
-			//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("tx pkt, %d bytes, type = %d, compress = %d, encrypt = %d, sub_type = %d, id = %d, hash=%d", data.m_iLength, type, !!compress, !!encrypt, sub_type, id, hash32_buf(data.m_pData, data.m_iLength, 0));
-			//Dbg("tx pkt, %d bytes, type = %d, compress = %d, encrypt = %d, sub_type = %d, id = %d, hash=%d", data.m_iLength, type, !!compress, !!encrypt, sub_type, id, hash32_buf(data.m_pData, data.m_iLength, 0));
-			int rc = bizchan_post_pkt(m_pChan, type, compress, encrypt, sub_type, id, (const char*)data.m_pData, data.m_iLength);
-			return rc == 0 ? Error_Succeed : Error_NetBroken;
-		}
-		else 
-		{
-			return Error_NetBroken;
-		}
+		return Error_NetBroken;
 	}
+}
 
-	void CBizChannelEntity::ChangeState(int new_state, const char *param)
-	{
-		if (m_eState != new_state) {
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("change state from %s to %s", state2str(m_eState), state2str(new_state));
-			m_eState = new_state;
-			state_entry *pos;
-			ListEntry_ForEach(pos, &m_stateList, state_entry, entry) {
-				ChannelService_State_Info State;
-				State.state = new_state;
-				State.status = state2str(new_state);
-				if (param) {
-					State.param = param;
-				}
-				pos->ctx->SendMessage(State);
+
+void CBizChannelEntity::ChangeState(int new_state, const char *param)
+{
+	if (m_eState != new_state) {
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("change state from %s to %s", state2str(m_eState), state2str(new_state));
+		m_eState = new_state;
+		state_entry *pos;
+		ListEntry_ForEach(pos, &m_stateList, state_entry, entry) {
+			ChannelService_State_Info State;
+			State.state = new_state;
+			State.status = state2str(new_state);
+			if (param) {
+				State.param = param;
 			}
+			pos->ctx->SendMessage(State);
 		}
 	}
+}
 
-	//void on_recv_pkt(int type, int sub_type, const char *pkt, int pkt_size)
-	void CBizChannelEntity::on_recv_pkt(int type, int sub_type, int id, CBlob &data)
+
+//void on_recv_pkt(int type, int sub_type, const char *pkt, int pkt_size)
+void CBizChannelEntity::on_recv_pkt(int type, int sub_type, int id, CBlob &data)
+{
+	//LOG_TRACE("rx pkt, %d bytes, type = %d, sub_type = %d, id = %d, hash = %d", data.m_iLength, type, sub_type, id, hash32_buf(data.m_pData, data.m_iLength, 0));
+	//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("rx pkt, %d bytes, type = %d, sub_type = %d, id = %d, hash = %d", data.m_iLength, type, sub_type, id, hash32_buf(data.m_pData, data.m_iLength, 0));
+	rxpkt_entry *pos;
+	ListEntry_ForEach(pos, &m_rxpktList, rxpkt_entry, entry) 
 	{
-		//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("rx pkt, %d bytes, type = %d, sub_type = %d, id = %d, hash = %d", data.m_iLength, type, sub_type, id, hash32_buf(data.m_pData, data.m_iLength, 0));
-		//Dbg("rx pkt, %d bytes, type = %d, sub_type = %d, id = %d, hash = %d", data.m_iLength, type, sub_type, id, hash32_buf(data.m_pData, data.m_iLength, 0));
-		rxpkt_entry *pos;
-		ListEntry_ForEach(pos, &m_rxpktList, rxpkt_entry, entry) 
+		if (pos->ctx->Req.type == type) 
 		{
-			if (pos->ctx->Req.type == type) 
-			{
-				ChannelService_Packet_Info pkt;
-				pkt.type = type;
-				pkt.sub_type = sub_type;
-				pkt.id = id;
-				//pkt.data.m_bManaged = true;
-				pkt.data = data;
-				//data.m_bManaged = false;
-				pos->ctx->SendMessage(pkt);
-				//break;
-			}
+			ChannelService_Packet_Info pkt;
+			pkt.type = type;
+			pkt.sub_type = sub_type;
+			pkt.id = id;
+			//pkt.data.m_bManaged = true;
+			pkt.data = data;
+			//data.m_bManaged = false;
+			pos->ctx->SendMessage(pkt);
+			//break;
 		}
 	}
-	void CBizChannelEntity::on_connect(int error, const char *remote_ip, int remote_video_rtp, int remote_video_desc)
-	{
-		if (!error) {
-			if (m_eState == eChannelState_Connecting) {
-				CSimpleStringA strValue;
-				ErrorCodeEnum Error = GetFunction()->GetSysVar("VideoWindowInitializeParam", strValue);
-				if (Error == Error_Succeed) {
-					int local_view_x;
-					int local_view_y;
-					int local_view_cx;
-					int local_view_cy;
-					int remote_view_x;
-					int remote_view_y;
-					int remote_view_cx;
-					int remote_view_cy;
-					int remote_video_width = 0;
-					int remote_video_height = 0;
+}
+
+
+void CBizChannelEntity::on_connect(int error, const char *remote_ip, int remote_video_rtp, int remote_video_desc)
+{
+	if (!error) {
+		if (m_eState == eChannelState_Connecting) {
+			CSimpleStringA strValue;
+			ErrorCodeEnum Error = GetFunction()->GetSysVar("VideoWindowInitializeParam", strValue);
+			if (Error == Error_Succeed) {
+				int local_view_x;
+				int local_view_y;
+				int local_view_cx;
+				int local_view_cy;
+				int remote_view_x;
+				int remote_view_y;
+				int remote_view_cx;
+				int remote_view_cy;
+				int remote_video_width = 0;
+				int remote_video_height = 0;
+				{
+					CSystemStaticInfo Info;
+					GetFunction()->GetSystemStaticInfo(Info);
+					if (Info.eScreen == 1) 
 					{
-						CSystemStaticInfo Info;
-						GetFunction()->GetSystemStaticInfo(Info);
-						if (Info.eScreen == 1) 
-						{
-							remote_video_width = REC_COMMON_VIDEO_SSM_AGENT_WIDTH;
-							remote_video_height = REC_COMMON_VIDEO_SSM_AGENT_HEIGHT;
-						} 
-						else 
-						{
-							remote_video_width = REC_COMMON_VIDEO_DSM_AGENT_WIDTH;
-							remote_video_height = REC_COMMON_VIDEO_DSM_AGENT_HEIGHT;
-						}
+						remote_video_width = REC_COMMON_VIDEO_SSM_AGENT_WIDTH;
+						remote_video_height = REC_COMMON_VIDEO_SSM_AGENT_HEIGHT;
+					} 
+					else 
+					{
+						remote_video_width = REC_COMMON_VIDEO_DSM_AGENT_WIDTH;
+						remote_video_height = REC_COMMON_VIDEO_DSM_AGENT_HEIGHT;
 					}
+				}
 					
-					ParseVideoViewParam((LPCSTR)strValue, local_view_x, local_view_y, local_view_cx, local_view_cy, 
+				ParseVideoViewParam((LPCSTR)strValue, local_view_x, local_view_y, local_view_cx, local_view_cy, 
+					remote_view_x, remote_view_y, remote_view_cx, remote_view_cy);
+				//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Get Video Window Initialize Param:%d,%d,%d,%d %d,%d,%d,%d",local_view_x, local_view_y, local_view_cx, local_view_cy, 
+					//remote_view_x, remote_view_y, remote_view_cx, remote_view_cy);
+				CSimpleStringA param;
+				if (eMobilePadType == m_eDeviceType)
+				{
+					param = BuildVideoDesc(remote_ip, remote_video_rtp, remote_video_width, remote_video_height, 
+						REC_COMMON_VIDEO_FPS_MOBILE_AGENT, local_view_x, local_view_y, local_view_cx, local_view_cy, 
 						remote_view_x, remote_view_y, remote_view_cx, remote_view_cy);
-					//Dbg("Get Video Window Initialize Param:%d,%d,%d,%d %d,%d,%d,%d",local_view_x, local_view_y, local_view_cx, local_view_cy, 
-					//	remote_view_x, remote_view_y, remote_view_cx, remote_view_cy);
-					CSimpleStringA param;
-					if (eMobilePadType == m_eDeviceType)
-					{
-						param = BuildVideoDesc(remote_ip, remote_video_rtp, remote_video_width, remote_video_height, 
-							REC_COMMON_VIDEO_FPS_MOBILE_AGENT, local_view_x, local_view_y, local_view_cx, local_view_cy, 
-							remote_view_x, remote_view_y, remote_view_cx, remote_view_cy);
-					}
-					else if((ePadtype == m_eDeviceType)||(eDesk2SType == m_eDeviceType))
-					{
-						param = BuildVideoDesc(remote_ip, remote_video_rtp, remote_video_width, remote_video_height, 
-							REC_COMMON_VIDEO_FPS_MOBILE, local_view_x, local_view_y, local_view_cx, local_view_cy, 
-							remote_view_x, remote_view_y, remote_view_cx, remote_view_cy);
-					}
-					else
-					{
-						param = BuildVideoDesc(remote_ip, remote_video_rtp, remote_video_width, remote_video_height, 
-							REC_COMMON_VIDEO_FPS, local_view_x, local_view_y, local_view_cx, local_view_cy, 
-							remote_view_x, remote_view_y, remote_view_cx, remote_view_cy);
-					}
-
-					ChangeState(eChannelState_Connected, (LPCSTR)param);
-				} else {
-					Dbg("get VideoWindowInitializeParam failed!");
-					bizchan_start_close(m_pChan);
 				}
+				else if((ePadtype == m_eDeviceType)||(eDesk2SType == m_eDeviceType))
+				{
+					param = BuildVideoDesc(remote_ip, remote_video_rtp, remote_video_width, remote_video_height, 
+						REC_COMMON_VIDEO_FPS_MOBILE, local_view_x, local_view_y, local_view_cx, local_view_cy, 
+						remote_view_x, remote_view_y, remote_view_cx, remote_view_cy);
+				}
+				else
+				{
+					param = BuildVideoDesc(remote_ip, remote_video_rtp, remote_video_width, remote_video_height, 
+						REC_COMMON_VIDEO_FPS, local_view_x, local_view_y, local_view_cx, local_view_cy, 
+						remote_view_x, remote_view_y, remote_view_cx, remote_view_cy);
+				}
+
+				ChangeState(eChannelState_Connected, (LPCSTR)param);
+			} else {
+				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get VideoWindowInitializeParam failed!");
+				bizchan_start_close(m_pChan);
 			}
-		} else {
-			if (m_pChan) {
-				bizchan_close(m_pChan);
-				bizchan_destroy(m_pChan);
-				m_pChan = NULL;
-			}
-			ChangeState(eChannelState_Idle);
 		}
-	}
-	void CBizChannelEntity::on_close()
-	{
+	} else {
 		if (m_pChan) {
 			bizchan_close(m_pChan);
 			bizchan_destroy(m_pChan);
@@ -387,42 +446,59 @@ static int MakeDesc(DWORD eScreen,DeviceTypeEnum eDevicetype)
 		}
 		ChangeState(eChannelState_Idle);
 	}
-	void CBizChannelEntity::_on_recv_pkt(int type, int sub_type, int id, const char *pkt, int pkt_size)
-	{
-		//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("_on rx pkt, %d bytes, type = %d, sub_type = %d, id = %d, hash = %d", pkt_size, type, sub_type, id, hash32_buf(pkt, pkt_size, 0));
-		NotifyOnRecvPkt *task = new NotifyOnRecvPkt();
-		task->m_pEntity = this;
-		task->type = type;
-		task->sub_type = sub_type;
-		task->id = id;
-		task->data.m_bManaged = true;
-		task->data.m_iLength = pkt_size;
-		if (pkt_size) 
-		{
-			task->data.m_pData = new char[pkt_size];
-			memcpy(task->data.m_pData, pkt, pkt_size);
-		} else {
-			task->data.m_pData = NULL;
-		}
-		GetFunction()->PostEntityTaskFIFO(task);
-	}
-	void CBizChannelEntity::_on_connect(int error, const char *remote_ip, int remote_video_rtp, int remote_video_desc)
-	{
-		NotifyOnConnect *task = new NotifyOnConnect();
-		task->m_pEntity = this;
-		task->error = error;
-		task->remote_rtp_ip = remote_ip;
-		task->remote_video_port = remote_video_rtp;
-		task->remote_video_desc = remote_video_desc;
-		GetFunction()->PostEntityTaskFIFO(task);
+}
+
+void CBizChannelEntity::on_close()
+{
+	if (m_pChan) {
+		bizchan_close(m_pChan);
+		bizchan_destroy(m_pChan);
+		m_pChan = NULL;
 	}
+	ChangeState(eChannelState_Idle);
+}
+
 
-	void CBizChannelEntity::_on_close()
+void CBizChannelEntity::_on_recv_pkt(int type, int sub_type, int id, const char *pkt, int pkt_size)
+{
+	//LOG_TRACE("_on rx pkt, %d bytes, type = %d, sub_type = %d, id = %d, hash = %d", pkt_size, type, sub_type, id, hash32_buf(pkt, pkt_size, 0));
+	NotifyOnRecvPkt *task = new NotifyOnRecvPkt();
+	task->m_pEntity = this;
+	task->type = type;
+	task->sub_type = sub_type;
+	task->id = id;
+	task->data.m_bManaged = true;
+	task->data.m_iLength = pkt_size;
+	if (pkt_size) 
 	{
-		NotifyOnClose * task = new NotifyOnClose();
-		task->m_pEntity = this;
-		GetFunction()->PostEntityTaskFIFO(task);
+		task->data.m_pData = new char[pkt_size];
+		memcpy(task->data.m_pData, pkt, pkt_size);
+	} else {
+		task->data.m_pData = NULL;
 	}
+	GetFunction()->PostEntityTaskFIFO(task);
+}
+
+
+void CBizChannelEntity::_on_connect(int error, const char *remote_ip, int remote_video_rtp, int remote_video_desc)
+{
+	NotifyOnConnect *task = new NotifyOnConnect();
+	task->m_pEntity = this;
+	task->error = error;
+	task->remote_rtp_ip = remote_ip;
+	task->remote_video_port = remote_video_rtp;
+	task->remote_video_desc = remote_video_desc;
+	GetFunction()->PostEntityTaskFIFO(task);
+}
+
+
+void CBizChannelEntity::_on_close()
+{
+	NotifyOnClose *task = new NotifyOnClose();
+	task->m_pEntity = this;
+	GetFunction()->PostEntityTaskFIFO(task);
+}
+
 
 
 void ChannelServiceSession::Handle_Connect( SpReqAnsContext<ChannelService_Connect_Req, ChannelService_Connect_Ans>::Pointer ctx )
@@ -477,6 +553,7 @@ void ChannelServiceSession::OnClose( ErrorCodeEnum eErrorCode )
 	m_pEntity->UnregisterState(m_id);
 }
 
+
 SP_BEGIN_ENTITY_MAP()
 	SP_ENTITY(CBizChannelEntity)
 SP_END_ENTITY_MAP()

+ 23 - 47
Module/mod_assistantchannel/mod_assistantchannel.h

@@ -4,13 +4,20 @@
 #include "SpBase.h"
 #include "SpTest.h"
 #include "modVer.h"
+#include "VideoDesc.h"
+
+#include "AssistantChannel_server_g.h"
+#include "AssistantChannel_def_g.h"
 
 #include "Common/ListEntry.h"
 #include "mod_counterconnector/CallType.h"
 #include "bizchan.h"
-#include "EventCode.h"
+#include "../../Other/rvcmediacommon/rvc_media_common.h"
+#include "chan_protocol.h"
+#include "../include/EventCode.h"
+
+#include "../mod_counterconnector/CallType.h"
 
-#include "AssistantChannel_server_g.h"
 using namespace AssistantChannel;
 
 class CBizChannelEntity : public CEntityBase
@@ -24,20 +31,11 @@ public:
 
 	ON_ENTITYT_TEST()
 
-	virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
-	{
-		ErrorCodeEnum Error = __OnStart(Error_Succeed);
-		pTransactionContext->SendAnswer(Error);
-	}
-
-	virtual void OnPreClose(EntityCloseCauseEnum eCloseCause, CSmartPointer<ITransactionContext> pTransactionContext)
-	{
-		ErrorCodeEnum Error = __OnClose(Error_Succeed);
-		pTransactionContext->SendAnswer(Error);
-	}
-
+	virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext); 
+	virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext);
 	ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError);
-
+	virtual void OnStarted();
+	DeviceTypeEnum RvcGetDeviceType();
 	ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError);
 
 	virtual CServerSessionBase* OnNewSession(const char* pszRemoteEntityName, const char* pszClass);
@@ -56,6 +54,12 @@ public:
 	void UnregisterRxpkt(int id);
 
 	ErrorCodeEnum Send(int type, bool compress, bool encrypt, int sub_type, int id, CBlob& data);
+	void on_recv_pkt(int type, int sub_type, int id, CBlob &data);
+	void on_connect(int error, const char *remote_ip, int remote_video_rtp, int remote_video_desc);
+	void on_close();
+	void _on_recv_pkt(int type, int sub_type, int id, const char *pkt, int pkt_size);
+	void _on_connect(int error, const char *remote_ip, int remote_video_rtp, int remote_video_desc);
+	void _on_close();
 
 private:
 	struct NotifyOnClose : public ITaskSp
@@ -90,41 +94,13 @@ private:
 			m_pEntity->on_connect(error, (LPCSTR)remote_rtp_ip, remote_video_port, remote_video_desc);
 		}
 	};
-	void ChangeState(int new_state, const char* param = NULL);
-	void on_recv_pkt(int type, int sub_type, int id, CBlob& data);
-	void on_connect(int error, const char* remote_ip, int remote_video_rtp, int remote_video_desc);
-	void on_close();
-	void _on_recv_pkt(int type, int sub_type, int id, const char* pkt, int pkt_size);
-	void _on_connect(int error, const char* remote_ip, int remote_video_rtp, int remote_video_desc);
-	void _on_close();
-	static void __on_recv_pkt(bizchan_t* chan, int type, int sub_type, int id, const char* pkt, int pkt_size, void* user_data)
-	{
-		CBizChannelEntity* pThis = static_cast<CBizChannelEntity*>(user_data);
-		pThis->_on_recv_pkt(type, sub_type, id, pkt, pkt_size);
-	}
-	static void __on_connect(bizchan_t* chan, int error, const char* remote_ip, int remote_video_rtp, int remote_video_desc, const char* remote_client_id, void* user_data)
-	{
-		CBizChannelEntity* pThis = static_cast<CBizChannelEntity*>(user_data);
-		pThis->_on_connect(error, remote_ip, remote_video_rtp, remote_video_desc);
-	}
-	static void __on_close(bizchan_t* chan, void* user_data)
-	{
-		CBizChannelEntity* pThis = static_cast<CBizChannelEntity*>(user_data);
-		pThis->_on_close();
-	}
-	static void __on_destroy(bizchan_t* chan, void* user_data)
-	{
-	}
-	static void __dbg(bizchan_t* chan, int level, char *msg, void* user_data)
-	{
-		CBizChannelEntity* pThis = static_cast<CBizChannelEntity*>(user_data);
-		Dbg(msg);
-	}
+
+	void ChangeState(int new_state, const char *param = NULL);
 
 private:
 	DeviceTypeEnum m_eDeviceType;
 	int m_eState;
-	bizchan_t* m_pChan;
+	bizchan_t *m_pChan;
 	int m_id_seq;
 	struct state_entry
 	{
@@ -146,7 +122,7 @@ private:
 class ChannelServiceSession : public ChannelService_ServerSessionBase
 {
 public:
-	ChannelServiceSession(CBizChannelEntity* pEntity, int id) : m_pEntity(pEntity), m_id(id) {}
+	ChannelServiceSession(CBizChannelEntity *pEntity, int id) : m_pEntity(pEntity), m_id(id) {}
 
 	virtual void Handle_Connect(SpReqAnsContext<ChannelService_Connect_Req, ChannelService_Connect_Ans>::Pointer ctx);
 

+ 52 - 82
Other/libbizchan/bizchan.cpp

@@ -16,8 +16,7 @@
 #include <netinet/in.h>
 #include <string.h>
 #include <arpa/inet.h>
-//#include "winpr/winsock.h"
-//#include "winpr/file.h"
+
 #endif
 
 #include <stdlib.h>
@@ -144,12 +143,6 @@ struct bizchan_t
 
 typedef int (*lpfn_cryptionfun)(unsigned char *  out ,int outLen,const unsigned char * in,int  inLen);
 
-//typedef int (*lpfn_decodestring)(unsigned char *  out ,int outLen,const unsigned char * in,int  inLen);
-//typedef int (*lpfn_encodestring)(unsigned char *  out ,int outLen,const unsigned char * in,int  inLen);
-//
-//typedef int (*lpfn_decodestring_mobile)(unsigned char *  out ,int outLen,const unsigned char * in,int  inLen);
-//typedef int (*lpfn_encodestring_mobile)(unsigned char *  out ,int outLen,const unsigned char * in,int  inLen);
-
 static lpfn_cryptionfun decodestring = NULL;
 static lpfn_cryptionfun encodestring = NULL;
 static lpfn_cryptionfun decodestring_mobile = NULL;
@@ -218,32 +211,19 @@ static __inline void GetTick(LARGE_INTEGER *last, LARGE_INTEGER *lt)
 }
 
 
-static void Dbg(bizchan_t *chan, int level, const char *fmt, ...)
+void bizlog(bizchan_t *chan, const char* fmt, ...)
 {
-	int n;
-	va_list arg;
-	va_start(arg, fmt);
-	if (chan->cb.dbg) {
-		n = _vscprintf(fmt, arg);
-		if (n > 0) {
-			char *buf = (char*)_alloca((size_t)(n + 3));
-			vsprintf(buf, fmt, arg);
-			(*chan->cb.dbg)(chan, level, buf, chan->cb.user_data);
-		}
-	}
-	else {
-		n = _vscprintf(fmt, arg);
-		if (n > 0) {
-			char *buf = (char*)_alloca((size_t)(n + 3));
-			vsprintf(buf, fmt, arg);
-			strcat(buf, "\r\n");
-			OutputDebugStringA((LPCSTR)buf);
-			printf(buf);
+	if (chan){
+		va_list arg;
+		va_start(arg, fmt);
+		if (chan->cb.dbg) {
+			(*chan->cb.dbg)(chan->cb.user_data, fmt, arg);
 		}
+		va_end(arg);
 	}
-	va_end(arg);
 }
 
+
 BIZCHAN_API(int) bizchan_lib_init()
 {
 #ifdef RVC_OS_WIN
@@ -492,7 +472,6 @@ static int on_recv(bizchan_t *chan, SOCKET conn)
 
 	do {
 		n = recv(conn, ri->buf+ri->offset, ri->buf_len-ri->offset, 0);
-		Dbg(chan, 0, "on_recv n:%d, ri->offset:%d, ri->buf_len:%d, sizeof(acm_hdr):%d", n, ri->offset, ri->buf_len, sizeof(acm_hdr));
 		if (n > 0) {
 			int i = 0;
 			ri->offset += n;
@@ -500,7 +479,7 @@ static int on_recv(bizchan_t *chan, SOCKET conn)
 			while (ri->offset-i >= sizeof(acm_hdr)) {
 				acm_hdr *hdr = (acm_hdr*)&ri->buf[i];
 				//Dbg(chan, "on_recv, i:%d offset:%d, recv_length:%d", i,  ri->offset, n);
-				//Dbg(chan, "on_recv, encrypt:%u, type:%u, sub_type:%u, length:%lu, compress:%u", hdr->encrypt, hdr->type, hdr->sub_type, hdr->length, hdr->compress);
+				bizlog(chan, "on_recv, encrypt:%u, type:%u, sub_type:%u, length:%lu, compress:%u", hdr->encrypt, hdr->type, hdr->sub_type, hdr->length, hdr->compress);
 				if (hdr->length == 0) {
 					printf("broken");
 				}
@@ -511,7 +490,7 @@ static int on_recv(bizchan_t *chan, SOCKET conn)
 						char *dec_buf = (char*)malloc(hdr->length);
 						int sm4_dec_result = DecStrWithSM4_ECB(chan->remote_pwd, sizeof(chan->remote_pwd), (unsigned char*)(&hdr->data[0]), hdr->length, (unsigned char*)dec_buf, &dec_length);
 						if (sm4_dec_result != 0){
-							//Dbg(chan, "DecStrWithSM4_ECB failed, type:%u, sub_type:%u, length:%lu", hdr->type, hdr->sub_type, hdr->length);
+							bizlog(chan, "DecStrWithSM4_ECB failed, type:%u, sub_type:%u, length:%lu", hdr->type, hdr->sub_type, hdr->length);
 							RC4_set_key(&chan->remote_key, sizeof(chan->remote_pwd), (unsigned char*)chan->remote_pwd);
 							RC4(&chan->remote_key, hdr->length, (const unsigned char*)(&hdr->data[0]), (unsigned char*)dec_buf);
 							dec_length = hdr->length;
@@ -526,7 +505,7 @@ static int on_recv(bizchan_t *chan, SOCKET conn)
 								invoke_on_recv_pkt(chan, hdr->type, hdr->sub_type, hdr->id, unzip_buf, len);
 							} else {
 								//OutputDebugStringA("pkt hash failed!\n");
-								Dbg(chan, 0, "encrypt compress pkt hash failed! type:%u, sub_type:%u, length:%lu, hash:%lu, unzip:%d", hdr->type, hdr->sub_type, hdr->length, hdr->hash, len);
+								bizlog(chan, "encrypt compress pkt hash failed! type:%u, sub_type:%u, length:%lu, hash:%lu, unzip:%d", hdr->type, hdr->sub_type, hdr->length, hdr->hash, len);
 							}
 							free(unzip_buf);
 						} else {
@@ -536,7 +515,7 @@ static int on_recv(bizchan_t *chan, SOCKET conn)
 							}
 							else {
 								//OutputDebugStringA("pkt hash failed!\n");
-								Dbg(chan, 0, "encrypt uncompress pkt hash failed! type:%u, sub_type:%u, length:%lu, hash:%lu", hdr->type, hdr->sub_type, hdr->length, hdr->hash);
+								bizlog(chan, "encrypt uncompress pkt hash failed! type:%u, sub_type:%u, length:%lu, hash:%lu", hdr->type, hdr->sub_type, hdr->length, hdr->hash);
 							}
 						}
 						free(dec_buf);
@@ -549,7 +528,7 @@ static int on_recv(bizchan_t *chan, SOCKET conn)
 								invoke_on_recv_pkt(chan, hdr->type, hdr->sub_type, hdr->id, unzip_buf, len);
 							} else {
 								//OutputDebugStringA("pkt hash failed!\n");
-								Dbg(chan, 0, "compress pkt hash failed! type:%u, sub_type:%u, length:%lu, hash:%lu, unzip:%d", hdr->type, hdr->sub_type, hdr->length, hdr->hash, len);
+								bizlog(chan, "compress pkt hash failed! type:%u, sub_type:%u, length:%lu, hash:%lu, unzip:%d", hdr->type, hdr->sub_type, hdr->length, hdr->hash, len);
 							}
 							free(unzip_buf);
 						} else {
@@ -557,7 +536,7 @@ static int on_recv(bizchan_t *chan, SOCKET conn)
 								invoke_on_recv_pkt(chan, hdr->type, hdr->sub_type, hdr->id, (const char*)&hdr->data[0], hdr->length);
 							} else {
 								//OutputDebugStringA("pkt hash failed!\n");
-								Dbg(chan, 0, "uncompress pkt hash failed! type:%u, sub_type:%u, length:%lu, hash:%lu", hdr->type, hdr->sub_type, hdr->length, hdr->hash);
+								bizlog(chan, "uncompress pkt hash failed! type:%u, sub_type:%u, length:%lu, hash:%lu", hdr->type, hdr->sub_type, hdr->length, hdr->hash);
 							}
 						}
 					}
@@ -587,7 +566,7 @@ static int on_recv(bizchan_t *chan, SOCKET conn)
 		result = (n < 0 || (errno == EWOULDBLOCK) || (errno == EINTR) || (errno == EAGAIN)) ? 0 : -1;
 	}
 
-	Dbg(chan, 0, "on_recv n:%d, result:%d, errno:%d", n, result, errno);
+	bizlog(chan, 0, "on_recv n:%d, result:%d, errno:%d", n, result, errno);
 	return result;
 #endif
 }
@@ -627,7 +606,7 @@ static int on_send(bizchan_t *chan, SOCKET conn)
 				t->need_encrypt = 0;
 			}
 			n = send(conn, t->buf+t->sended, t->left, 0);
-			Dbg(chan, 0, "on_send n:%d, t->sended:%d, t->left:%d", n, t->sended, t->left);
+			bizlog(chan, 0, "on_send n:%d, t->sended:%d, t->left:%d", n, t->sended, t->left);
 			if (n > 0) {
 				char tmp[32];
 				sprintf(tmp, "send out %d bytes!\n", n);
@@ -800,7 +779,7 @@ static void process(bizchan_t *chan)
                                 #if ENCRYPT_CHINA
 								EncWithSM4_ECB(seed_key, (unsigned char*)&chan->local_pwd[0], KEY_LEN / 2,
 									(unsigned char*)&hdr.encrypt_key[0], &enc_length);
-                                Dbg(chan, "use SM4 password_crypt_type");
+                                bizlog(chan, "%s","use SM4 password_crypt_type");
                                 #else
 								encodefun((unsigned char*)&hdr.encrypt_key[0], sizeof(hdr.encrypt_key), (unsigned char*)&chan->local_pwd[0], sizeof(chan->local_pwd));
                                 Dbg(chan, "use old password_crypt_type");
@@ -847,17 +826,17 @@ static void process(bizchan_t *chan)
 											int result = DecWithSM4_ECB(seed_key,
 												(unsigned char*)&ack_hdr.encrypt_key[0], sizeof(ack_hdr.encrypt_key), 
 												(unsigned char*)&chan->remote_pwd[0], &dec_length);
-											Dbg(chan, "use SM4 Decode password result:%d", result);
+											bizlog(chan, "use SM4 Decode password result:%d", result);
 											if(result != 0){
 												result = decodefun((unsigned char*)&chan->remote_pwd[0], sizeof(chan->remote_pwd), (unsigned char*)&ack_hdr.encrypt_key[0], sizeof(ack_hdr.encrypt_key));
-												Dbg(chan, "use old Decode password result:%d", result);
+												bizlog(chan, "use old Decode password result:%d", result);
 											}
 											if (check_hash(chan->remote_pwd, sizeof(chan->remote_pwd), ack_hdr.encrypt_keyhash)) {
 												chan->remote_video_rtp_port = ack_hdr.rtp_port;
 												chan->remote_video_desc = ack_hdr.media_desc;
 												memcpy(chan->remote_client_id, ack_hdr.client_id, sizeof(chan->remote_client_id));
 												chan->remote_version = ack_hdr.version;
-												Dbg(chan, "remote_acm_version:%d", chan->remote_version);
+												bizlog(chan, "remote_acm_version:%d", chan->remote_version);
 												chan->connected = TRUE;
 												break;
 											} else {
@@ -942,13 +921,13 @@ static void process(bizchan_t *chan)
 
 on_error:
 	//OutputDebugStringA("on_error");
-	Dbg(chan, "on_error");
+	bizlog(chan, "%s", "on_error");
 	if (!chan->connected) {
 		invoke_on_connect(chan, -1); // connect failed!
 	} else {
 		//....
 		//OutputDebugStringA("connected, and error!");
-		Dbg(chan, "connected, and error!");
+		bizlog(chan, "%s", "connected, and error!");
 	}
 
 	if (conn != INVALID_SOCKET)
@@ -981,7 +960,7 @@ static void do_shake_send(bizchan_t* chan, SOCKET conn, int* error) {
 #if ENCRYPT_CHINA
 	EncWithSM4_ECB(seed_key, (unsigned char*)&chan->local_pwd[0], KEY_LEN / 2,
 		(unsigned char*)&hdr.encrypt_key[0], &enc_length);
-	Dbg(chan, 0, "use SM4 password_crypt_type");
+	bizlog(chan, 0, "use SM4 password_crypt_type");
 #else
 	encodefun((unsigned char*)&hdr.encrypt_key[0], sizeof(hdr.encrypt_key), (unsigned char*)&chan->local_pwd[0], sizeof(chan->local_pwd));
 	Dbg(chan, 0, "use old password_crypt_type");
@@ -1030,23 +1009,23 @@ static void do_shake_recv(bizchan_t* chan, SOCKET conn, int* error) {
 				int result = DecWithSM4_ECB(seed_key,
 					(unsigned char*)&ack_hdr.encrypt_key[0], sizeof(ack_hdr.encrypt_key),
 					(unsigned char*)&chan->remote_pwd[0], &dec_length);
-				Dbg(chan, 0, "use SM4 Decode password result:%d", result);
+				bizlog(chan, 0, "use SM4 Decode password result:%d", result);
 				if (result != 0) {
 					result = decodefun((unsigned char*)&chan->remote_pwd[0], sizeof(chan->remote_pwd), (unsigned char*)&ack_hdr.encrypt_key[0], sizeof(ack_hdr.encrypt_key));
-					Dbg(chan, 0, "use old Decode password result:%d", result);
+					bizlog(chan, 0, "use old Decode password result:%d", result);
 				}
 				if (check_hash(chan->remote_pwd, sizeof(chan->remote_pwd), ack_hdr.encrypt_keyhash)) {
 					chan->remote_video_rtp_port = ack_hdr.rtp_port;
 					chan->remote_video_desc = ack_hdr.media_desc;
 					memcpy(chan->remote_client_id, ack_hdr.client_id, sizeof(chan->remote_client_id));
 					chan->remote_version = ack_hdr.version;
-					Dbg(chan, 0, "remote_acm_version:%d", chan->remote_version);
+					bizlog(chan, 0, "remote_acm_version:%d", chan->remote_version);
 					chan->connected = TRUE;
 					break;
 				}
 				else {
 					*error = -1;
-					Dbg(chan, 0, "do_shake_recv check_hash failed");
+					bizlog(chan, 0, "do_shake_recv check_hash failed");
 				}
 
 			}
@@ -1058,8 +1037,8 @@ static void do_shake_recv(bizchan_t* chan, SOCKET conn, int* error) {
 #else
 	if (t <= 0 && ((errno != EWOULDBLOCK) || (errno != EINTR) || (errno != EAGAIN))) {
 		*error = -1;
-		Dbg(chan, 0, "do_shake_recv errno:%d", errno);
-		Dbg(chan, 0, "do_shake_recv t<=0 failed");
+		bizlog(chan, 0, "do_shake_recv errno:%d", errno);
+		bizlog(chan, 0, "do_shake_recv t<=0 failed");
 	}
 #endif
 }
@@ -1115,7 +1094,7 @@ SOCKET connect_server(bizchan_t* chan, char* server, int port, int timeout)
 #else
 		close(m_hSocket);
 #endif
-		Dbg(chan, 0, "connect_server set_socket_noblock failed");
+		bizlog(chan, 0, "connect_server set_socket_noblock failed");
 	}
 
 	addrSrv.sin_family = AF_INET;
@@ -1123,7 +1102,7 @@ SOCKET connect_server(bizchan_t* chan, char* server, int port, int timeout)
 	addrSrv.sin_port = htons(port);
 	int ret = connect(m_hSocket, (struct sockaddr*)&addrSrv, sizeof(addrSrv));
 	if (ret == 0) {
-		Dbg(chan, 0, "connect_server connect success 1.");
+		bizlog(chan, 0, "connect_server connect success 1.");
 		return m_hSocket;
 	}
 #ifdef RVC_OS_WIN
@@ -1136,7 +1115,7 @@ SOCKET connect_server(bizchan_t* chan, char* server, int port, int timeout)
 	//linux下需要检测EINPROGRESS和EINTR  
 	if (ret < 0 && (errno != EINPROGRESS && errno != EINTR)) {
 		close(m_hSocket);
-		Dbg(chan, 0, "connect_server connect failed, errno: %d", errno);
+		bizlog(chan, 0, "connect_server connect failed, errno: %d", errno);
 		return INVALID_SOCKET;
 	}
 #endif
@@ -1154,11 +1133,11 @@ SOCKET connect_server(bizchan_t* chan, char* server, int port, int timeout)
 #else
 		close(m_hSocket);
 #endif
-		Dbg(chan, 0, "connect_server connect timeout.");
+		bizlog(chan, 0, "connect_server connect timeout.");
 		return INVALID_SOCKET;
 	}
 
-	Dbg(chan, 0, "connect_server connect success 2.");
+	bizlog(chan, 0, "connect_server connect success 2.");
 	return m_hSocket;
 }
 
@@ -1195,7 +1174,7 @@ static void process(bizchan_t* chan) {
 #else
 		do_shake_send(chan, conn, &error);
 		if (error != 0) {
-			Dbg(chan, 0, "do_shake_send failed");
+			bizlog(chan, 0, "do_shake_send failed");
 			goto on_error;
 		}
 		while (!chan->stop_flag && !chan->connected) {
@@ -1208,13 +1187,13 @@ static void process(bizchan_t* chan) {
 			int activity = select(maxfd + 1, &read_fds, NULL, &except_fds, &tv);
 			if (activity == -1) {
 				perror("select()");
-				Dbg(chan, 0, "process shake select -1");
+				bizlog(chan, 0, "process shake select -1");
 				goto on_error;
 			}
 			else if (activity == 0) {
 				// timeout
 				printf("select() returns 0.\n");
-				Dbg(chan, 0, "process shake select 0");
+				bizlog(chan, 0, "process shake select 0");
 				goto on_error;
 			}else {
 				/* All fd_set's should be checked. */
@@ -1226,7 +1205,7 @@ static void process(bizchan_t* chan) {
 					char pipe_read_buffer[4];
 					int n = read(chan->evt[0], pipe_read_buffer, 4);
 					if (n < 0) {
-						Dbg(chan, 0, "process shake pipe read < 0");
+						bizlog(chan, 0, "process shake pipe read < 0");
 					}
 				}
 				if (FD_ISSET(conn, &except_fds)) {
@@ -1258,7 +1237,7 @@ static void process(bizchan_t* chan) {
 			int activity = select(maxfd + 1, &read_fds, NULL, &except_fds, &tv);
 			if (activity == -1) {
 				perror("select()");
-				Dbg(chan, 0, "chan select() error.");
+				bizlog(chan, "chan select() error.");
 				goto on_error;
 			}
 			else if (activity == 0) {
@@ -1307,11 +1286,11 @@ static void process(bizchan_t* chan) {
 							break;
 					}
 					else {
-						Dbg(chan, 0, "pipe read < 0");
+						bizlog(chan, 0, "pipe read < 0");
 					}
 				}
 				if (FD_ISSET(conn, &except_fds)) {
-					Dbg(chan, 0, "select() except_fds set.");
+					bizlog(chan, 0, "select() except_fds set.");
 					error = -1;
 				}
 				if (error != 0) {
@@ -1324,7 +1303,7 @@ static void process(bizchan_t* chan) {
 
 on_error:
 	//OutputDebugStringA("on_error");
-	Dbg(chan, 0, "on_error");
+	bizlog(chan, 0, "on_error");
 
 	if (!chan->connected) {
 		invoke_on_connect(chan, -1); // connect failed!
@@ -1332,7 +1311,7 @@ on_error:
 	else {
 		//....
 		//OutputDebugStringA("connected, and error!");
-		Dbg(chan, 0, "connected, and error!");
+		bizlog(chan, 0, "connected, and error!");
 	}
 
 	if (conn != INVALID_SOCKET) {
@@ -1360,7 +1339,7 @@ static void* work_proc(void* arg)
 		//....
 	}
 #else
-	Dbg(chan, 0, "work_proc start");
+	bizlog(chan, 0, "work_proc start");
 	process(chan);
 #endif
 	return 0;
@@ -1419,11 +1398,8 @@ static int init_decode_func(const bizchan_config_t* config, const bizchan_callba
 		if (hInst) {
 			encodestring = (lpfn_cryptionfun)GetProcAddress(hInst, "encodestring");
 		}
-		else {
-			cb->dbg(NULL, 2, "libacmstrenc LoadLibraryA failed", cb->user_data);
-		}
+
 		if (!encodestring) {
-			cb->dbg(NULL, 2, "libacmstrenc GetProcAddress failed", cb->user_data);
 			return ret;
 		}
 
@@ -1469,22 +1445,18 @@ BIZCHAN_API(int) bizchan_create(const bizchan_config_t *config, const bizchan_ca
 	bizchan_t *chan = NULL;
 
 	if (-1 == init_decode_func(config, cb)){
-		cb->dbg(chan, 2, "init_decode_func failed", cb->user_data);
 		return -1;
 	}
 
 	if (!config || !p_chan) {
-		cb->dbg(chan, 2, "config or chan is null, failed", cb->user_data);
 		return -1;
 	}
 
 	if (config_check(config) != 0) {
-		cb->dbg(chan, 2, "config_check failed", cb->user_data);
 		return -1;
 	}
 
 	if (callback_check(cb) != 0) {
-		cb->dbg(chan, 2, "callback_check failed", cb->user_data);
 		return -1;
 	}
 
@@ -1517,12 +1489,10 @@ BIZCHAN_API(int) bizchan_create(const bizchan_config_t *config, const bizchan_ca
 #endif
 
 	*p_chan = chan;
-	cb->dbg(chan, 0, "bizchan_create success", cb->user_data);
 
 	return 0;
 
 on_error:
-	cb->dbg(chan, 2, "bizchan_create on_error", cb->user_data);
 	bizchan_destroy(chan);
 	return -1;
 }
@@ -1592,14 +1562,14 @@ BIZCHAN_API(int) bizchan_start_connect(bizchan_t *chan)
 	}
 
 	if (chan->work_thread) {
-		Dbg(chan, 2, "work_thread exsit!!!");
+		bizlog(chan, "work_thread exsit!!!");
 		return -1;
 	}
 
 #ifdef RVC_OS_WIN
 	WSAResetEvent(chan->evt);
 #endif
-	Dbg(chan, 0, "bizchan_start_connect 2");
+	bizlog(chan, "bizchan_start_connect 2");
 
 	chan->stop_flag = 0;
 	chan->connected = 0;
@@ -1612,22 +1582,22 @@ BIZCHAN_API(int) bizchan_start_connect(bizchan_t *chan)
 #else
 	int err = pthread_create(&chan->work_thread, NULL, work_proc, chan);
 	if (0 == err) {
-		Dbg(chan, 0, "create work thread success, %lu.", chan->work_thread);
+		bizlog(chan, "create work thread success, %lu.", chan->work_thread);
 	}
 	else {
-		Dbg(chan, 0, "create work thread failed.");
+		bizlog(chan, "create work thread failed.");
 	}
 #endif // RVC_OS_WIN
 
 	// we now return, when connected, on_connect will invoked in work_proc thread
-	Dbg(chan, 0, "bizchan_start_connect success");
+	bizlog(chan, "bizchan_start_connect success");
 
 	return 0;
 }
 
 BIZCHAN_API(int) bizchan_start_close(bizchan_t *chan)
 {
-	Dbg(chan, 2, "bizchan_start_close");
+	bizlog(chan, "bizchan_start_close");
 	chan->stop_flag = 1;
 #ifdef RVC_OS_WIN
 	WSASetEvent(chan->evt);

+ 4 - 1
Other/libbizchan/bizchan.h

@@ -3,6 +3,8 @@
 
 #pragma once
 
+#include <stdarg.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -38,6 +40,7 @@ typedef struct bizchan_config_t {
 	int crypt_type;
 }bizchan_config_t;
 
+
 typedef struct bizchan_callback_t  {
 	void (*on_recv_photo)(bizchan_t *chan, int id, int error, int width, int height, const char *rgb24, int size, void *user_data);
 	void (*on_recv_screen)(bizchan_t *chan, int id, int error, int width, int height, const char *rgb24, int size, void *user_data);
@@ -45,7 +48,7 @@ typedef struct bizchan_callback_t  {
 	void (*on_connect)(bizchan_t *chan, int error, const char *remote_ip, int remote_video_rtp, int remote_video_desc, const char *remote_client_id, void *user_data);
 	void (*on_close)(bizchan_t *chan, void *user_data);
 	void (*on_destroy)(bizchan_t *chan, void *user_data);
-	void (*dbg)(bizchan_t* chan, int level, char *msg, void* user_data);
+	void (*dbg)(void *user_data, const char* fmt, va_list arg);
 	void *user_data;
 }bizchan_callback_t;