#include "stdafx.h" #include "SpBase.h" #include "SpIni.h" #include "endpoint.h" #include "SIPPhone_server_g.h" #include "SIPPhone_msg_g.h" #include "../mod_agentip/sysvar.h" #include "../mod_facetracking/sysvar.h" #include "sockutil.h" #include "rec_common.h" #include "audio_session.h" #include "video_session.h" #include "volumekeeper.h" #include "Event.h" #include "EventCode.h" #include "../mod_assistantchannel/AssistantChannel_client_g.h" using namespace AssistantChannel; #include "../mod_assistantchannel/chan_protocol.h" #include "../mod_selfchecker/SelfChecker_client_g.h" #include "../mod_selfchecker/SelfChecker_def_g.h" #include "audio_pulse.h" using namespace SelfChecker; #define EVT_CONVERTER "EventConverter" #define DEVICE_HANDFREE_OUT 0 #define DEVICE_PICKUP_OUT 1 #define DEVICE_HANDFREE_IN 2 #define DEVICE_PICKUP_IN 3 enum ePickupMicrophoneState { ePickupMicrophoneState_On, ePickupMicrophoneState_Off, }; /* 0:online local and remote video window, 1:only local video window, 2:both local and remote window */ enum eShowVideoWindowType{ eOnline_Mode_Video, eOnly_Local_Video, eBoth_Local_Remote_Video }; struct CVolumnValue { int nValue; void Serialize(SpBuffer &Buf) { Buf & nValue; } }; struct CFpsValue { int nValue; void Serialize(SpBuffer &Buf) { Buf & nValue; } }; struct stVideoParam { int nWindowState; //视频窗口显示状态,0:正常大小显示,1:放大一倍显示,2:隐藏全部窗口,3:从隐藏状态恢复为全部显示,4:显示远程窗口,隐藏本地窗口, 5:缩放显示 int bShowActiveImg; //活体检测显示图片 int bActiveInspect; //是否启动活体检测 int iActiveCamera; // set by facetracking int iCameraSwitch; // set by agent and camerastate int nUpDynamicFps; // 当前视频上行的帧频,由后端通知前端更改频率,只有移动版才使用 int iCameraState; // set by agent and camerastate int bShowPersonArea; //是否显示人形框 int bShowRecordArea; //是否显示录像人形轮廓 }; //record video echo location typedef struct record_echo_location_s{ int x; int y; int width; int height; }record_echo_location_t; #ifndef DEFAULT_RECORD_VIDEO_WIDTH #define DEFAULT_RECORD_VIDEO_WIDTH 1056 #endif #ifndef DEFAULT_RECORD_VIDEO_HEIGHT #define DEFAULT_RECORD_VIDEO_HEIGHT 595 #endif #ifndef SMALL_RECORD_VIDEO_WIDTH #define SMALL_RECORD_VIDEO_WIDTH 244 #endif #ifndef SMALL_RECORD_VIDEO_HEIGHT #define SMALL_RECORD_VIDEO_HEIGHT 138 #endif ///////////////////////////////////////////// // future roadmap // 1. 使用session timer // 2. 增强稳定性 // 3. 健康检查里面触发 主备服务器切换(switch between freeswitchs) 定时发送options ping switch server ///////////////////////////////////////////// extern BOOL g_IsExternalTerminalted; extern BOOL g_bIsSalesRecord; extern BOOL g_bEwsRecord; using namespace SIPPhone; class CSIPEntity; class SelfChekerClient:public SelfCheckerService_ClientBase { public: SelfChekerClient(CSIPEntity*pEntity); }; class ChannelSipphoneClient : public ChannelService_ClientBase { public: ChannelSipphoneClient(CSIPEntity *pEntity); virtual void OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer pData); virtual void OnMessage(ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer pData); }; class CSIPPhoneSession : public PhoneService_ServerSessionBase { public: CSIPPhoneSession(CSIPEntity *pEntity) : m_pEntity(pEntity), m_pCall(NULL), m_iLastState(0),m_IsLocalPlay(0),m_VideoWindowPlayType(eOnline_Mode_Video) { m_cb_video_box_move.on_video_box_move = &__on_video_box_move; m_cb_video_box_move.user_data = this; } virtual void Handle_MakeCall(SpReqAnsContext::Pointer ctx); virtual void Handle_HangupCall(SpReqAnsContext::Pointer ctx); virtual void Handle_StartVideo(SpOnewayCallContext::Pointer ctx); virtual void Handle_StopVideo(SpOnewayCallContext::Pointer ctx); virtual void Handle_BeginState(SpSubscribeContext::Pointer ctx); virtual void Handle_EndState(SpOnewayCallContext::Pointer ctx); virtual void Handle_ReleaseCall(SpReqAnsContext::Pointer ctx); virtual void Handle_RealErrorCheck(SpOnewayCallContext::Pointer ctx); virtual void Handle_SetCallingParam(SpOnewayCallContext::Pointer ctx); virtual void OnClose(ErrorCodeEnum eErrorCode); private: struct MakeCallCommand { CSIPPhoneSession *pSIPPhoneSession; CSimpleStringA strUri; }; struct ControlVideoCommand { CSIPPhoneSession *pSIPPhoneSession; int start; unsigned long local_ip; int local_port; unsigned long remote_ip; int remote_port; 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_width; int remote_height; int local_hwd_move; int remote_hwd_move; }; struct HangupCallCommand { CSIPPhoneSession *pSIPPhoneSession; CSimpleStringA strSession_num; CSimpleStringA strBranch_server_ip; int iBranch_server_port; }; void on_call_state(int state, const char *state_desc, const char *phrase); int make_call(const char *uri); void hangup_call(/*HangupCallCommand *pCmd*/); void release_call(); void control_video(ControlVideoCommand *pCmd); int on_video_box_move(int imessagetype, int ivideotype, int ileft, int ibottom); static void __on_video_box_move(int imessagetype, int ivideotype, int ileft, int ibottom, void *user_data) { CSIPPhoneSession *pThis = static_cast(user_data); pThis->on_video_box_move(imessagetype, ivideotype, ileft, ibottom); } static void __on_call_state(int state, const char *state_desc, const char *phrase, void *user_data) { CSIPPhoneSession *pThis = static_cast(user_data); if (pThis->m_iLastState != state) { pThis->m_iLastState = state; pThis->on_call_state(state, state_desc, phrase); } } static int __make_call(void *user_data) { MakeCallCommand *cmd = (MakeCallCommand*)user_data; int rc = cmd->pSIPPhoneSession->make_call(cmd->strUri); delete cmd; return rc; } static int __hangup_call(void *user_data) { LOG_FUNCTION(); HangupCallCommand *cmd = (HangupCallCommand*)(user_data); cmd->pSIPPhoneSession->hangup_call(/*cmd*/); delete cmd; return 0; } static int __control_video(void *arg) { ControlVideoCommand *pCmd = (ControlVideoCommand*)(arg); pCmd->pSIPPhoneSession->control_video(pCmd); delete pCmd; return 0; } static int __release_call(void *user_data) { CSIPPhoneSession *pThis = static_cast(user_data); pThis->release_call(); pThis->on_call_state(TERMINATED,"STATE:terminated","byebye"); return 0; } private: SpSubscribeContext::Pointer m_spCallbackContext; endpoint_call_t *m_pCall; CSIPEntity *m_pEntity; int m_iLastState; int m_IsLocalPlay; eShowVideoWindowType m_VideoWindowPlayType;/*add by clp 20190903 0:only remote video window, 1:only local video window, 2:both local and remote window */ video_session_callback_t m_cb_video_box_move; }; class CSIPEntity : public CEntityBase, public ILogListener, public ISysVarListener,public ITimerListener { public: CSIPEntity() : m_pCurrentSession(NULL), m_state(INIT),m_iPickupPhoneState(ePickupMicrophoneState_Off) { m_kept_volume_in[0] = m_kept_volume_in[1] = 0; m_kept_volume_out[0] = m_kept_volume_out[1] = 0; #ifdef RVC_OS_WIN m_pKeeperIn[0] = m_pKeeperIn[1] = NULL; m_pKeeperOut[0] = m_pKeeperOut[1] = NULL; #endif m_SipErrorCode = Error_Succeed; memset((void*)&m_stVideoParam,0,sizeof(stVideoParam)); } virtual ~CSIPEntity() {} virtual const char *GetEntityName() const { return "SIPPhone"; } virtual void OnLog(const CAutoArray &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel, const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID, const CAutoArray &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage) { LOG_TRACE("user_code = 0x%08x", dwUserCode); switch (dwUserCode) { case LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE: { Dbg("recv LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE"); if (m_pSipphoneChannel != NULL) { m_pSipphoneChannel->GetFunction()->CloseSession(); m_pSipphoneChannel = NULL; Dbg("Close AssistChannel Session "); } ErrorCodeEnum Error; if (m_pSipphoneChannel == NULL) { Dbg("ReConnection AssistChannel Session"); m_pSipphoneChannel = new ChannelSipphoneClient(this); Error = m_pSipphoneChannel->Connect(); if (Error != Error_Succeed) { m_pSipphoneChannel->SafeDelete(); Dbg("ChannelSipphoneClient connect fail!"); } if (Error == Error_Succeed) { ChannelService_BeginState_Sub Sub; Error = m_pSipphoneChannel->BeginState(Sub); if (Error != Error_Succeed) { LOG_TRACE("BeginState biz channel failed!"); m_pSipphoneChannel->GetFunction()->CloseSession(); m_pSipphoneChannel = NULL; } } if (Error == Error_Succeed) { ChannelService_BeginRecv_Sub Sub; Sub.type = ACM_TYPE_DEVICE; Error = m_pSipphoneChannel->BeginRecv(Sub); if (Error != Error_Succeed) { Dbg("Begin BeginRecv ACM_TYPE_DEVICE failed!"); m_pSipphoneChannel->GetFunction()->CloseSession(); m_pSipphoneChannel = NULL; } } } } break; case EVENT_MOD_CONNECT_HANDFREE_TO_PICKUP: case EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP: case EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE: case EVENT_MOD_CONNECT_PICKUP_TO_HANDFREE: case EVENT_MOD_CONNECT_PICKUP_CALL: case EVENT_MOD_CONNECT_SLV_HANDFREECALL: case EVENT_MOD_CONNECT_SLV_PICKUPCALL: case LOG_EVT_HANDFREE_MODE_REMOTE_CALL: case LOG_EVT_PICKUP_MODE_REMOTE_CALL: { int old_state = m_iPickupPhoneState; if (dwUserCode == EVENT_MOD_CONNECT_HANDFREE_TO_PICKUP) { // 免提->提机 m_iPickupPhoneState = ePickupMicrophoneState_On; } else if (dwUserCode == EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP) { //坐席控制免提->提机 m_iPickupPhoneState = ePickupMicrophoneState_On; } else if (dwUserCode == EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE) { //坐席控制提机->免提 m_iPickupPhoneState = ePickupMicrophoneState_Off; } else if (dwUserCode == EVENT_MOD_CONNECT_PICKUP_TO_HANDFREE) { // // 提机->免提 m_iPickupPhoneState = ePickupMicrophoneState_Off; } else if (dwUserCode == EVENT_MOD_CONNECT_PICKUP_CALL) { // 提机拨号 m_iPickupPhoneState = ePickupMicrophoneState_On; } else if (dwUserCode == EVENT_MOD_CONNECT_SLV_HANDFREECALL) { // 免提拨号 m_iPickupPhoneState = ePickupMicrophoneState_Off; } else if (dwUserCode == EVENT_MOD_CONNECT_SLV_PICKUPCALL) { // 通过界面拨号,但话筒未挂,进入提机拨号 m_iPickupPhoneState = ePickupMicrophoneState_On; } else if (dwUserCode == LOG_EVT_HANDFREE_MODE_REMOTE_CALL) { // 免提模式开始远程双录连线 m_iPickupPhoneState = ePickupMicrophoneState_Off; } else if (dwUserCode == LOG_EVT_PICKUP_MODE_REMOTE_CALL) { // 话筒模式开始远程双录连线 m_iPickupPhoneState = ePickupMicrophoneState_On; } LOG_TRACE("dwUserCode = 0x%08x,m_iPickupPhoneState %d", dwUserCode, m_iPickupPhoneState); Dbg("dwUserCode = 0x%08x,old_PhoneState = %d,PickupPhoneState = %d", dwUserCode,old_state, m_iPickupPhoneState); if (old_state != m_iPickupPhoneState) { if (m_iPickupPhoneState == ePickupMicrophoneState_On) { SwitchPickup(); } else { SwitchHandFree(); } } } break; case LOG_EVT_ENTER_ACM_FLOW: { Dbg("LOG_EVT_ENTER_ACM_FLOW"); m_stVideoParam.nWindowState = 1; } break; case LOG_EVT_EXIT_ACM_FLOW: { Dbg("LOG_EVT_EXIT_ACM_FLOW"); if(m_stVideoParam.nWindowState == 1) { m_stVideoParam.nWindowState = 0; } } break; case LOG_EVT_STARTLIVEDETECTDISPLAY: { Dbg("start livedetection display"); m_stVideoParam.bActiveInspect = 1; } break; case LOG_EVT_STOPLIVEDETECTDISPLAY: { Dbg("stop livedetection display and show livedetection photo %s",pszMessage); } break; case LOG_EVT_CHANGELIVEDETECTIONCAM: { if (pszMessage && strlen(pszMessage) > 0) { int i = atoi(pszMessage); Dbg("change active display camera to %d",i); m_stVideoParam.iCameraSwitch = i; } else { Dbg("change active display camera param error"); } } break; case LOG_EVT_RELEASELIVEDETECTION: { Dbg("release show active image"); m_stVideoParam.bActiveInspect = 0; m_stVideoParam.bShowActiveImg = 0; m_stVideoParam.iCameraSwitch = CAMERA_TYPE_ENV; } break; case LOG_EVT_UI_HIDEONLINEVIDEO: { Dbg("Receive UI hide online video evt!"); m_stVideoParam.nWindowState = 2; } break; case LOG_EVT_UI_SHOWONLINEVIDEO: { Dbg("Receive UI show online video evt!"); if (m_stVideoParam.nWindowState == 2) { m_stVideoParam.nWindowState = 3; } } break; case LOG_EVT_UI_STARTRECORD: case LOG_EVT_UI_STARTREMOTERECORD: { Dbg("start sales record video."); m_bIsSalesRecord = TRUE; g_bIsSalesRecord = m_bIsSalesRecord; m_bEwsRecord = FALSE; if (strlen(pszMessage)>=4&&!strnicmp(pszMessage,"ews|",4)){ m_bEwsRecord = TRUE; } g_bEwsRecord = m_bEwsRecord; } break; case LOG_EVT_UI_STARTRECORDPREVIEW: { Dbg("start sales record preview."); m_stVideoParam.bShowRecordArea = 1; Handle_RecordVideoLocation_Info(pszMessage); } break; case LOG_EVT_UI_STOPRECORD: case LOG_EVT_UI_STOPREMOTERECORD: { Dbg("stop sales record video."); m_bIsSalesRecord = FALSE; g_bIsSalesRecord = m_bIsSalesRecord; m_bEwsRecord = FALSE; //add by ly@2019/04/18 g_bEwsRecord = m_bEwsRecord; //add by ly@2019/04/18 if (m_stVideoParam.bShowRecordArea){ Dbg("stop sales record and stop preview."); m_stVideoParam.bShowRecordArea = 0; } } break; case LOG_EVT_UI_STOPRECORDPREVIEW: { Dbg("stop sales record preview."); m_stVideoParam.bShowRecordArea = 0; } break; case LOG_EVT_UI_RETURNMENU: { Dbg("return menu"); m_bIsSalesRecord = FALSE; g_bIsSalesRecord = m_bIsSalesRecord; m_bEwsRecord = FALSE; //add by ly@2019/04/18 g_bEwsRecord = m_bEwsRecord; //add by ly@2019/04/18 } break; case LOG_EVT_UI_SHOWLOCALVIDEO: { Dbg("Receive UI show all video evt!"); if (m_stVideoParam.nWindowState == 4) { m_stVideoParam.nWindowState = 3; } } break; case LOG_EVT_UI_HIDELOCALVIDEO: { Dbg("Receive UI hide local video evt!"); m_stVideoParam.nWindowState = 4; } break; case LOG_EVT_UI_HIDEPERSONAREA: { Dbg("Receive UI hide person area!"); m_stVideoParam.bShowPersonArea = 0; } break; case LOG_EVT_UI_SHOWPERSONAREA: { Dbg("Receive UI show person area!"); m_stVideoParam.bShowPersonArea = 1; } break; case EVENT_MOD_CONNECT_STOP_RECORD_BROADCAST: { Dbg("stop remote record audio broadcast."); } break; case EVENT_MOD_CONNECT_BEGAIN_RECORD_CALL: { Dbg("begin double record call."); } break; case LOG_EVT_UI_ADJUSTVIDEOECHOSIZE: { Dbg("adjust video echo size %s.", pszMessage); Handle_AdjustVideoEchoEvent(pszMessage); } break; default: { Dbg("unknown dwUserCode = %x.",dwUserCode); } break; } } virtual void OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName) { if (_stricmp(pszKey, SYSVAR_CAMERASTATE) == 0) { Dbg("camera state from : %c to %c", pszOldValue[0], pszValue[0]); if (pszValue[0] == 'E') { m_stVideoParam.iCameraState = CAMERA_TYPE_OPT; } else if (pszValue[0] == 'O') { m_stVideoParam.iCameraState = CAMERA_TYPE_ENV; } else if(pszValue[0] == 'B') ///////显示贴图 { /////////////////////////此处显示贴图////////////////////////////////// //m_stVideoParam.iCameraSwitch = CAMERA_TYPE_ERROR; m_stVideoParam.iCameraState = CAMERA_TYPE_ERROR; } else if (pszValue[0] == 'N') { m_stVideoParam.iCameraState = CAMERA_TYPE_AUTO; //m_stVideoParam.iCameraSwitch = CAMERA_TYPE_AUTO; } } else if (_stricmp(pszKey, SYSVAR_ACTIVETRACKINGCAMERA) == 0) { Dbg("active camera from : %c to %c", pszOldValue[0], pszValue[0]); if (pszValue[0] == 'E') { m_stVideoParam.iActiveCamera = CAMERA_TYPE_ENV; } else if (pszValue[0] == 'O') { m_stVideoParam.iActiveCamera = CAMERA_TYPE_OPT; } else { Dbg("warning: unknown ActiveTrackingCamera value!"); } } else if (_stricmp(pszKey, SYSVAR_AGENTCAMERASWITCH) == 0) { Dbg("agent camera switch from : %c to %c", pszOldValue[0], pszValue[0]); if((pszValue[0] == 'E')/*&&((m_iCameraState==CAMERA_TYPE_AUTO)||(m_iCameraState==CAMERA_TYPE_ENV))*/) { m_stVideoParam.iCameraSwitch = CAMERA_TYPE_ENV; } else if((pszValue[0] == 'O')/*&&((m_iCameraState==CAMERA_TYPE_AUTO)||(m_iCameraState==CAMERA_TYPE_OPT))*/) { m_stVideoParam.iCameraSwitch = CAMERA_TYPE_OPT; } else if((pszValue[0] == 'A')/*&&(m_iCameraState==CAMERA_TYPE_AUTO)*/) { m_stVideoParam.iCameraSwitch = CAMERA_TYPE_AUTO; } } else if (_stricmp(pszKey, SYSVAR_CALLTYPE) == 0) { Dbg("sys calltype from: %c to %c", pszOldValue[0], pszValue[0]); if(pszValue[0] == CALLTYPE_NORMAL) { m_nSysCallType = 0; } else if(pszValue[0] == CALLTYPE_MOBILE) { m_nSysCallType = 1; } else { m_nSysCallType =-1; } } } virtual void OnSelfTest(EntityTestEnum eTestType,CSmartPointer pTransactionContext) { if (Test_ShakeHand == eTestType) { pTransactionContext->SendAnswer(m_SipErrorCode); } } virtual void OnPreStart(CAutoArray strArgs,CSmartPointer pTransactionContext) { ErrorCodeEnum Error = __OnStart(Error_Succeed); pTransactionContext->SendAnswer(Error); } virtual void OnStarted() { ErrorCodeEnum Error = Error_Succeed; m_pSelfcheckClient = new SelfChekerClient(this); Error = m_pSelfcheckClient->Connect(); if (Error != Error_Succeed) { m_pSelfcheckClient->SafeDelete(); m_pSelfcheckClient = NULL; Dbg("SelfcheckClient connect fail!"); } else { Dbg("SelfcheckClient connect success!"); } } ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError) { ErrorCodeEnum Error; //MessageBoxA(0,0,0,0); m_nCallType = NORMAL_CALLTYPE; m_nSysCallType = 0; m_pSipphoneChannel = new ChannelSipphoneClient(this); memset(m_localip,0,256); Error = m_pSipphoneChannel->Connect(); if (Error != Error_Succeed) { m_pSipphoneChannel->SafeDelete(); Dbg("ChannelSipphoneClient connect fail!"); return Error; } { ChannelService_BeginState_Sub Sub; Error = m_pSipphoneChannel->BeginState(Sub); if (Error != Error_Succeed) { LOG_TRACE("BeginState biz channel failed!"); m_pSipphoneChannel->GetFunction()->CloseSession(); m_pSipphoneChannel = NULL; return Error; } } { ChannelService_BeginRecv_Sub Sub; Sub.type = ACM_TYPE_DEVICE; Error = m_pSipphoneChannel->BeginRecv(Sub); if (Error != Error_Succeed) { Dbg("Begin BeginRecv ACM_TYPE_DEVICE failed!"); m_pSipphoneChannel->GetFunction()->CloseSession(); m_pSipphoneChannel = NULL; return Error; } } { ChannelService_BeginRecv_Sub Sub; Sub.type = ACM_TYPE_VIDEOFREQ; Error = m_pSipphoneChannel->BeginRecv(Sub); if (Error != Error_Succeed) { Dbg("Begin BeginRecv ACM_TYPE_VIDEOFREQ failed!"); m_pSipphoneChannel->GetFunction()->CloseSession(); m_pSipphoneChannel = NULL; return Error; } } { m_pSelfcheckClient = new SelfChekerClient(this); Error = m_pSelfcheckClient->Connect(); if (Error != Error_Succeed) { m_pSelfcheckClient->SafeDelete(); m_pSelfcheckClient = NULL; Dbg("SelfcheckClient connect fail!"); } else { Dbg("SelfcheckClient connect success!"); } } #ifdef RVC_OS_WIN #else { m_pAudioMgr = new AudioPulseMgr(); if (0 == m_pAudioMgr->AudioMgrInitialize()) { Dbg("Audio Manager Initialize success!"); } else { Dbg("Audio Manager Initialize failed!"); return Error_Param; } } #endif m_eDeviceType = RvcGetDeviceType(); m_stVideoParam.bActiveInspect = 0; m_stVideoParam.bShowActiveImg = 0; m_bIsSalesRecord = FALSE; g_bIsSalesRecord = m_bIsSalesRecord; m_bEwsRecord = FALSE; g_bEwsRecord = m_bEwsRecord; m_stVideoParam.nWindowState = 0; m_RecordVideoLocation.x = 0; m_RecordVideoLocation.y = 0; m_RecordVideoLocation.width = DEFAULT_RECORD_VIDEO_WIDTH; m_RecordVideoLocation.height = DEFAULT_RECORD_VIDEO_HEIGHT; LOG_FUNCTION(); video_lib_init(); audio_lib_init(); endpoint_init_lib(); Error = GetLocalIP(); if (Error != 0) { LOG_TRACE("get local ip failed!"); return Error; } #ifdef RVC_OS_WIN #else RvcGetAudioDeviceInfo(); #endif Error = LoadConfig(&conf); if (Error != Error_Succeed) { LOG_TRACE("load config failed!"); return Error; } int nhandfreeout = 0; int npickupout = 0; int nhanfreein = 0; int npickupin = 0; Error = LoadAudioRunConfig(nhandfreeout,npickupout,nhanfreein,npickupin); if (Error == Error_Succeed) { if (nhandfreeout > 0) { m_kept_volume_out[DEV_HANDFREE] = nhandfreeout; } if (npickupout > 0) { m_kept_volume_out[DEV_PICKUP] = npickupout; } if (nhanfreein > 0) { m_kept_volume_in[DEV_HANDFREE] = nhanfreein; } if (npickupin > 0) { m_kept_volume_in[DEV_PICKUP] = npickupin; } } { CSmartPointer Func = GetFunction(); Func->GetSystemStaticInfo(staticInfo); } CSimpleStringA strUri = MakeUri(staticInfo.strTerminalID); if (strUri.GetLength() > 0) { strcpy(conf.uri, strUri); conf.media_start_port = REC_COMMON_AUDIO_PORT_START; conf.media_stop_port = REC_COMMON_AUDIO_PORT_STOP; m_pEndpoint = endpoint_create(this, &conf,DEV_HANDFREE); if (!m_pEndpoint) { LOG_TRACE("create endpoint failed!"); return Error_Unexpect; } else{ Dbg("%s:%d call uri is %s, endpoint_create m_pEndpoint addr is 0x%0x.", __FUNCTION__, __LINE__, conf.uri, m_pEndpoint); } } else { LOG_TRACE("strUri length equals zero!"); return Error_Unexpect; } { CSmartPointer Func = GetFunction(); CUUID id; int i = 0; m_arrListener.Init(32); Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANDFREE_TO_PICKUP, EVT_CONVERTER); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_PICKUP_TO_HANDFREE, EVT_CONVERTER); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_PICKUP_CALL, EVT_CONVERTER); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_SLV_HANDFREECALL,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_SLV_PICKUPCALL,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_ENTER_ACM_FLOW,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_EXIT_ACM_FLOW,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_STARTLIVEDETECTDISPLAY,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_STOPLIVEDETECTDISPLAY,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_CHANGELIVEDETECTIONCAM,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_RELEASELIVEDETECTION,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_HIDEONLINEVIDEO,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_SHOWONLINEVIDEO,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORD,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPRECORD,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RETURNMENU,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_HIDELOCALVIDEO,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_SHOWLOCALVIDEO,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_HIDEPERSONAREA,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_SHOWPERSONAREA,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_STOP_RECORD_BROADCAST,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_BEGAIN_RECORD_CALL,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTREMOTERECORD,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPREMOTERECORD,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_HANDFREE_MODE_REMOTE_CALL,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_PICKUP_MODE_REMOTE_CALL,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORDPREVIEW,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPRECORDPREVIEW,NULL,false); m_arrListener[i++] = id; Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_ADJUSTVIDEOECHOSIZE,NULL,false); m_arrListener[i++] = id; } { CSmartPointer Func = GetFunction(); CSimpleStringA strValue; Func->RegistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA, this); Func->GetSysVar(SYSVAR_ACTIVETRACKINGCAMERA, strValue); if (strValue[0] == 'E') { m_stVideoParam.iActiveCamera = CAMERA_TYPE_ENV; } else if (strValue[0] == 'O') { m_stVideoParam.iActiveCamera = CAMERA_TYPE_OPT; } else { assert(0); } } { CSmartPointer Func = GetFunction(); CSimpleStringA strValue; Func->RegistSysVarEvent(SYSVAR_CAMERASTATE, this); Func->GetSysVar(SYSVAR_CAMERASTATE, strValue); if (strValue[0] == 'E') { m_stVideoParam.iCameraState = CAMERA_TYPE_OPT; } else if (strValue[0] == 'O') { m_stVideoParam.iCameraState = CAMERA_TYPE_ENV; } else if(strValue[0] == 'B') ///////显示贴图 { /////////////////////////此处显示贴图////////////////////////////////// //m_stVideoParam.iCameraSwitch = CAMERA_TYPE_ERROR; m_stVideoParam.iCameraState = CAMERA_TYPE_ERROR; } else if (strValue[0] == 'N') { //m_stVideoParam.iCameraSwitch = CAMERA_TYPE_AUTO; m_stVideoParam.iCameraState = CAMERA_TYPE_AUTO; } } { CSmartPointer Func = GetFunction(); CSimpleStringA strValue; Func->RegistSysVarEvent(SYSVAR_AGENTCAMERASWITCH, this); Func->GetSysVar(SYSVAR_AGENTCAMERASWITCH, strValue); if((strValue[0] == 'E')/*&&((m_iCameraState == CAMERA_TYPE_AUTO)||(m_iCameraState = CAMERA_TYPE_ENV))*/) { m_stVideoParam.iCameraSwitch = CAMERA_TYPE_ENV; } else if((strValue[0] == 'O')/*&&((m_iCameraState == CAMERA_TYPE_AUTO)||(m_iCameraState = CAMERA_TYPE_OPT))*/) { m_stVideoParam.iCameraSwitch = CAMERA_TYPE_OPT; } else if ((strValue[0] == 'A')/*&&(m_iCameraState == CAMERA_TYPE_AUTO)*/) { m_stVideoParam.iCameraSwitch = CAMERA_TYPE_AUTO; } } { CSmartPointer Func = GetFunction(); CSimpleStringA strValue; Func->RegistSysVarEvent(SYSVAR_CALLTYPE, this); Func->GetSysVar(SYSVAR_CALLTYPE, strValue); if (strValue[0] == CALLTYPE_NORMAL) { m_nSysCallType = 0; } else if (strValue[0] == CALLTYPE_MOBILE) { m_nSysCallType = 1; } else { assert(0); } } #ifdef RVC_OS_WIN if (m_kept_volume_in[DEV_HANDFREE]) { m_pKeeperIn[DEV_HANDFREE] = volume_keeper_create(conf.audio_handfree_in_dev, 1, m_kept_volume_in[DEV_HANDFREE]); if (m_pKeeperIn[DEV_HANDFREE]) { Dbg("HANDFREE in volume keeper create ok! %d", m_kept_volume_in[DEV_HANDFREE]); } else { Dbg("HANDFREE in volume keeper create failed!"); } } if (m_kept_volume_out[DEV_HANDFREE]) { m_pKeeperOut[DEV_HANDFREE] = volume_keeper_create(conf.audio_handfree_out_dev, 0, m_kept_volume_out[DEV_HANDFREE]); if (m_pKeeperOut[DEV_HANDFREE]) { Dbg("HANDFREE out volume keeper create ok! %d", m_kept_volume_out[DEV_HANDFREE]); } else { Dbg("HANDFREE out volume keeper create failed!"); } } if (m_kept_volume_in[DEV_PICKUP]&&(eStand2sType == m_eDeviceType)) //pad版屏蔽pickup { m_pKeeperIn[DEV_PICKUP] = volume_keeper_create(conf.audio_pickup_in_dev, 1, m_kept_volume_in[DEV_PICKUP]); if (m_pKeeperIn[DEV_PICKUP]) { Dbg("PICKUP in volume keeper create ok! %d", m_kept_volume_in[DEV_PICKUP]); } else { Dbg("PICKUP in volume keeper create failed!"); } } if (m_kept_volume_out[DEV_PICKUP]&&(eStand2sType == m_eDeviceType)) //pad版屏蔽pickup { m_pKeeperOut[DEV_PICKUP] = volume_keeper_create(conf.audio_pickup_out_dev, 0, m_kept_volume_out[DEV_PICKUP]); if (m_pKeeperOut[DEV_PICKUP]) { Dbg("PICKUP out volume keeper create ok! %d", m_kept_volume_out[DEV_PICKUP]); } else { Dbg("PICKUP out volume keeper create failed!"); } } #else #endif // RVC_OS_WIN return Error_Succeed; } video_session_t *video_session; //volumn adjust void OnReceivePkt(int type, int sub_type, const char *buffer, int size) { if (type == ACM_TYPE_DEVICE) { if (sub_type == ACM_SET_HANDFREE_OUTVOLUMN) { CVolumnValue num; SpBuffer buf; buf.OpenRead(buffer,size); num.Serialize(buf); Dbg("recv adj handfree out volumn = %d",num.nValue); #ifdef RVC_OS_WIN if (m_pKeeperOut[DEV_HANDFREE]) { volume_keeper_change(m_pKeeperOut[DEV_HANDFREE], num.nValue); m_kept_volume_out[DEV_HANDFREE] = num.nValue; SendAudioDeviceVolumn(DEVICE_HANDFREE_OUT); SaveAudioRunConfig(m_kept_volume_out[DEV_HANDFREE], m_kept_volume_out[DEV_PICKUP], m_kept_volume_in[DEV_HANDFREE], m_kept_volume_in[DEV_PICKUP]); } else { Dbg("HANDFREE out volume keeper create failed!"); } #else if (m_pAudioMgr) { m_pAudioMgr->audio_set_device_volume(num.nValue, conf.audio_handfree_out_dev, false); m_kept_volume_out[DEV_HANDFREE] = num.nValue; SendAudioDeviceVolumn(DEVICE_HANDFREE_OUT); SaveAudioRunConfig(m_kept_volume_out[DEV_HANDFREE], m_kept_volume_out[DEV_PICKUP], m_kept_volume_in[DEV_HANDFREE], m_kept_volume_in[DEV_PICKUP]); } else { Dbg("HANDFREE out volume keeper create failed!"); } #endif } else if((sub_type == ACM_SET_PICKUP_OUTVOLUMN)&&(eStand2sType == m_eDeviceType)) { CVolumnValue num; SpBuffer buf; buf.OpenRead(buffer,size); num.Serialize(buf); Dbg("recv adj pickup out volumn = %d",num.nValue); #ifdef RVC_OS_WIN if (m_pKeeperOut[DEV_PICKUP]) { if (eStand2sType == m_eDeviceType) { volume_keeper_change(m_pKeeperOut[DEV_PICKUP], num.nValue); m_kept_volume_out[DEV_PICKUP] = num.nValue; SendAudioDeviceVolumn(DEVICE_PICKUP_OUT); SaveAudioRunConfig(m_kept_volume_out[DEV_HANDFREE], m_kept_volume_out[DEV_PICKUP], m_kept_volume_in[DEV_HANDFREE], m_kept_volume_in[DEV_PICKUP]); } else //pad版屏蔽当前PICKUP音量设置 { Dbg("PAD type, ignore pickupout volume adj"); } } else { Dbg("PICKUP out volume keeper create failed!"); } #else if (m_pAudioMgr) { if (eStand2sType == m_eDeviceType) { m_pAudioMgr->audio_set_device_volume(num.nValue, conf.audio_pickup_out_dev, false); m_kept_volume_out[DEV_PICKUP] = num.nValue; SendAudioDeviceVolumn(DEVICE_PICKUP_OUT); SaveAudioRunConfig(m_kept_volume_out[DEV_HANDFREE], m_kept_volume_out[DEV_PICKUP], m_kept_volume_in[DEV_HANDFREE], m_kept_volume_in[DEV_PICKUP]); } else //pad版屏蔽当前PICKUP音量设置 { Dbg("PAD type, ignore pickupout volume adj"); } } else { Dbg("PICKUP out volume keeper create failed!"); } #endif } else if (sub_type == ACM_SET_HANDFREE_INVOLUMN) { CVolumnValue num; SpBuffer buf; buf.OpenRead(buffer,size); num.Serialize(buf); Dbg("recv adj handfree in volumn = %d",num.nValue); #ifdef RVC_OS_WIN if (m_pKeeperIn[DEV_HANDFREE]) { volume_keeper_change(m_pKeeperIn[DEV_HANDFREE], num.nValue); m_kept_volume_in[DEV_HANDFREE] = num.nValue; SendAudioDeviceVolumn(DEVICE_HANDFREE_IN); SaveAudioRunConfig(m_kept_volume_out[DEV_HANDFREE], m_kept_volume_out[DEV_PICKUP], m_kept_volume_in[DEV_HANDFREE], m_kept_volume_in[DEV_PICKUP]); } else { Dbg("handfree in volume keeper create failed!"); } #else if (m_pAudioMgr) { m_pAudioMgr->audio_set_device_volume(num.nValue, conf.audio_handfree_in_dev, true); m_kept_volume_in[DEV_HANDFREE] = num.nValue; SendAudioDeviceVolumn(DEVICE_HANDFREE_IN); SaveAudioRunConfig(m_kept_volume_out[DEV_HANDFREE], m_kept_volume_out[DEV_PICKUP], m_kept_volume_in[DEV_HANDFREE], m_kept_volume_in[DEV_PICKUP]); } else { Dbg("handfree in volume keeper create failed!"); } #endif } else if((sub_type == ACM_SET_PICKUP_INVOLUMN)&&(eStand2sType == m_eDeviceType)) { CVolumnValue num; SpBuffer buf; buf.OpenRead(buffer,size); num.Serialize(buf); Dbg("recv adj pickup in volume = %d",num.nValue); #ifdef RVC_OS_WIN if (m_pKeeperIn[DEV_PICKUP]) { if (eStand2sType == m_eDeviceType) { volume_keeper_change(m_pKeeperIn[DEV_PICKUP], num.nValue); m_kept_volume_in[DEV_PICKUP] = num.nValue; SendAudioDeviceVolumn(DEVICE_PICKUP_IN); SaveAudioRunConfig(m_kept_volume_out[DEV_HANDFREE], m_kept_volume_out[DEV_PICKUP], m_kept_volume_in[DEV_HANDFREE], m_kept_volume_in[DEV_PICKUP]); } else //pad版屏蔽当前PICKUP音量设置 { Dbg("PAD type, ignore pickupin volume adj"); } } else { Dbg("pickup in volume keeper create failed!"); } #else if (m_pAudioMgr) { if (eStand2sType == m_eDeviceType) { m_pAudioMgr->audio_set_device_volume(num.nValue, conf.audio_pickup_in_dev, true); m_kept_volume_in[DEV_PICKUP] = num.nValue; SendAudioDeviceVolumn(DEVICE_PICKUP_IN); SaveAudioRunConfig(m_kept_volume_out[DEV_HANDFREE], m_kept_volume_out[DEV_PICKUP], m_kept_volume_in[DEV_HANDFREE], m_kept_volume_in[DEV_PICKUP]); } else //pad版屏蔽当前PICKUP音量设置 { Dbg("PAD type, ignore pickupin volume adj"); } } else { Dbg("pickup in volume keeper create failed!"); } #endif } else if (sub_type == ACM_CONTROL_PERSONAREA) //控制人形框 { CVolumnValue num; SpBuffer buf; buf.OpenRead(buffer,size); num.Serialize(buf); Dbg("recv control personarea subtype = %d",num.nValue); if (num.nValue == 0) //隐藏人形框 { //LogEvent(Severity_Middle,LOG_EVT_UI_HIDEPERSONAREA,"Agent send Hide Person area"); //if((eMobilePadType == m_eDeviceType)||(ePadtype == m_eDeviceType)||(eDesk2SType == m_eDeviceType)) //{ LogEvent(Severity_Middle,LOG_EVT_UI_HIDELOCALVIDEO,"Agent send hide local video"); LogEvent(Severity_Middle,LOG_EVT_UI_HIDEPERSONAREA,"Agent send Hide Person area"); //} } else if (num.nValue == 1) //显示人形框 { //LogEvent(Severity_Middle,LOG_EVT_UI_SHOWPERSONAREA,"Agent send Show Person area"); //if((eMobilePadType == m_eDeviceType)||(ePadtype == m_eDeviceType)||(eDesk2SType == m_eDeviceType)) //{ LogEvent(Severity_Middle,LOG_EVT_UI_SHOWLOCALVIDEO,"Agent send show local video"); LogEvent(Severity_Middle,LOG_EVT_UI_SHOWPERSONAREA,"Agent send Show Person area"); //} } else { Dbg("recv control personarea sub_type error!"); } } } else if (type == ACM_TYPE_VIDEOFREQ) { if (eMobilePadType == m_eDeviceType) { CFpsValue nFps; SpBuffer buf; buf.OpenRead(buffer,size); nFps.Serialize(buf); Dbg("adj up stream fps to %d",nFps.nValue); if((m_stVideoParam.nUpDynamicFps == 1)&&(nFps.nValue!=1)) { GetFunction()->KillTimer(1); } else if (nFps.nValue==1) { //如果1帧每秒维持20秒,停止视频 Dbg("start timer for up fps"); GetFunction()->SetTimer(1, this, 20000); } m_stVideoParam.nUpDynamicFps = nFps.nValue; } else { Dbg("not mobile pad,ignore down message!"); } } } #ifdef RVC_OS_WIN #else ErrorCodeEnum RvcGetAudioDeviceInfo() { ErrorCodeEnum Error = Error_Param; if (NULL != m_pAudioMgr) { int icountmic = m_pAudioMgr->audio_get_device_count(true); Dbg("audio input device(%d):", icountmic); int i = 0; for (; i < icountmic; i++) { char strname[MAX_PATH] = { 0 }; m_pAudioMgr->audio_get_device_name(strname, MAX_PATH, true, i); Dbg("%d = %s", i, strname); } int icountspeaker = m_pAudioMgr->audio_get_device_count(false); Dbg("audio output device(%d):", icountspeaker); for (i = 0; i < icountspeaker; i++) { char strname[MAX_PATH] = { 0 }; m_pAudioMgr->audio_get_device_name(strname, MAX_PATH, false, i); Dbg("%d = %s", i, strname); } Error = Error_Succeed; } return Error; } #endif ErrorCodeEnum GetLocalIP() { #ifdef RVC_OS_WIN char tmp[MAX_PATH] = { 0 }; gethostname(tmp, sizeof(tmp)); hostent* ent = gethostbyname(tmp); if (ent) { for (int i = 0; ent->h_addr_list[i]; ++i) { if (ent->h_addrtype == AF_INET) { struct in_addr* in = (struct in_addr*)ent->h_addr_list[i]; char* p = inet_ntoa(*in); if (p[0] != '0') { if (strstr(p, "198.168.") == NULL) { strcpy(m_localip, p); Dbg("local ip == %s", m_localip); return Error_Succeed; } } } } } return Error_Unexpect; #else ErrorCodeEnum error = Error_Unexpect; int sockfd = -1; struct ifconf ifconf; struct ifreq* ifreq = NULL; char strbuf[MAX_PATH] = {0}; ifconf.ifc_len = MAX_PATH; ifconf.ifc_buf = strbuf; if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0){ Dbg("socket error"); return error; } ioctl(sockfd, SIOCGIFCONF, &ifconf); //get all socket info ifreq = (struct ifreq*)ifconf.ifc_buf; for (int i = (ifconf.ifc_len / sizeof(struct ifreq)); i > 0; i--){ if (ifreq->ifr_flags == AF_INET) { //for ipv4 char* strIP = inet_ntoa(((struct sockaddr_in*) & (ifreq->ifr_addr))->sin_addr); Dbg("name =[%s], local addr = [%s]", ifreq->ifr_name, strIP); ifreq++; if (NULL != strIP){ if (NULL == strstr(strIP, "198.168.") && NULL == strstr(strIP, "127.0.0.1")) { strcpy(m_localip, strIP); Dbg("local ip == %s", m_localip); error = Error_Succeed; break; } } } } return error; #endif // RVC_OS_WIN } //send DynamicFps void SendDynamicFps(int nFps) { if (eMobilePadType == m_eDeviceType) { ChannelService_Send_Info Info; Info.compress = false; Info.encrypt = false; Info.type = ACM_TYPE_VIDEOFREQ; Info.id = 0; Info.sub_type = ACM_VIDEOFREQ_DOWN; Info.data.Alloc(sizeof(int)); SpBuffer buf; buf.OpenWrite(); buf & nFps; Info.data = buf.ToBlob(); m_pSipphoneChannel->Send(Info); Dbg("adj down stream fps to %d",nFps); } else { Dbg("not mobile pad,ignore up message!"); } } //send audio device volume void SendAudioDeviceVolumn(int nDevice) { if (m_nSysCallType == 0) { ChannelService_Send_Info Info; Info.compress = false; Info.encrypt = false; Info.type = ACM_TYPE_DEVICE; Info.id = 0; int nValue = 0; bool rslt = false; void*keeper = NULL; if (nDevice == DEVICE_HANDFREE_OUT) { Info.sub_type = ACM_HANDFREE_OUTVOLUMN; #ifdef RVC_OS_WIN keeper = m_pKeeperOut[DEV_HANDFREE]; #else m_pAudioMgr->audio_get_device_volume(&nValue, conf.audio_handfree_out_dev, false); rslt = true; #endif // RVC_OS_WIN } else if(nDevice == DEVICE_PICKUP_OUT) { if(eStand2sType == m_eDeviceType) { Info.sub_type = ACM_PICKUP_OUTVOLUMN; #ifdef RVC_OS_WIN keeper = m_pKeeperOut[DEV_PICKUP]; #else m_pAudioMgr->audio_get_device_volume(&nValue, conf.audio_pickup_out_dev, false); rslt = true; #endif } else //pad版屏蔽当前PICKUP音量发送 { return; } } else if(nDevice == DEVICE_HANDFREE_IN) { Info.sub_type = ACM_HANDFREE_INVOLUMN; #ifdef RVC_OS_WIN keeper = m_pKeeperIn[DEV_HANDFREE]; #else m_pAudioMgr->audio_get_device_volume(&nValue, conf.audio_handfree_in_dev, true); rslt = true; #endif } else if(nDevice == DEVICE_PICKUP_IN) { if(eStand2sType == m_eDeviceType) { Info.sub_type = ACM_PICKUP_INVOLUMN; #ifdef RVC_OS_WIN keeper = m_pKeeperIn[DEV_PICKUP]; #else m_pAudioMgr->audio_get_device_volume(&nValue, conf.audio_pickup_in_dev, true); rslt = true; #endif } else //pad版屏蔽当前PICKUP音量发送 { return; } } Info.data.Alloc(sizeof(int)); SpBuffer buf; buf.OpenWrite(); #ifdef RVC_OS_WIN if (keeper){ rslt = get_audiodevice_volumn(keeper, &nValue); } #endif if (rslt == true) { buf & nValue; Info.data = buf.ToBlob(); m_pSipphoneChannel->Send(Info); Dbg("send cur Audio device %d,value = %d",nDevice,nValue); } else { Dbg("Get cur Audio device %d volume Fail!",nDevice); } } else { Dbg("cur call type cannot send pkt"); } } virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer pTransactionContext) { ErrorCodeEnum Error = __OnClose(Error_Succeed); pTransactionContext->SendAnswer(Error); } ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError) { LOG_FUNCTION(); int i; CSmartPointer Func = GetFunction(); Func->UnregistSysVarEvent(SYSVAR_AGENTCAMERASWITCH); Func->UnregistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA); Func->UnregistSysVarEvent(SYSVAR_CAMERASTATE); Func->UnregistSysVarEvent(SYSVAR_CALLTYPE); for (i = 0; i < m_arrListener.GetCount(); ++i) { Func->UnsubscribeLog(m_arrListener[i]); } m_arrListener.Clear(); Dbg("__OnClose endpoint_destroy m_pEndpoint addr is %0x.",m_pEndpoint); endpoint_destroy(m_pEndpoint); m_pEndpoint = NULL; video_lib_deinit(); audio_lib_deinit(); endpoint_deinit_lib(); #ifdef RVC_OS_WIN if (m_pKeeperIn[DEV_HANDFREE]) { volume_keeper_destroy(m_pKeeperIn[DEV_HANDFREE]); m_pKeeperIn[DEV_HANDFREE] = NULL; } if (m_pKeeperOut[DEV_HANDFREE]) { volume_keeper_destroy(m_pKeeperOut[DEV_HANDFREE]); m_pKeeperOut[DEV_HANDFREE] = NULL; } if (m_pKeeperIn[DEV_PICKUP]) { volume_keeper_destroy(m_pKeeperIn[DEV_PICKUP]); m_pKeeperIn[DEV_PICKUP] = NULL; } if (m_pKeeperOut[DEV_PICKUP]) { volume_keeper_destroy(m_pKeeperOut[DEV_PICKUP]); m_pKeeperOut[DEV_PICKUP] = NULL; } #else if (NULL != m_pAudioMgr) { m_pAudioMgr->AudioMgrTerminate(); delete m_pAudioMgr; m_pAudioMgr = NULL; } #endif return Error_Succeed; } ///////////////////////////////////////////////////////////////////// #if 1 virtual void OnPaused() { int rc; video_session_conf_t conf = {0}; conf.bit_rate = 256*1024; conf.local_rtp_ip = htonl(INADDR_LOOPBACK); conf.local_rtp_port = 3000; conf.local_video_view_cx = 320; conf.local_video_view_cy = 240; conf.local_video_view_x = 0; conf.local_video_view_y = 0; conf.mtu = 1500; conf.remote_rtp_ip = htonl(INADDR_LOOPBACK); conf.remote_rtp_port = 3000; conf.remote_video_view_cx = 320; conf.remote_video_view_cy = 320; conf.remote_video_view_x = 0; conf.remote_video_view_y = 320; conf.video_quant = 3; conf.remote_video_width = 320; conf.remote_video_height = 320; conf.ref_active_camera = &m_stVideoParam.iActiveCamera; video_session_create(&conf, &video_session); video_session_start(video_session); } virtual void OnContinued() { video_session_stop(video_session); video_session_destroy(video_session); } #endif ///////////////////////////////////////////////////////////////////// virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszClass*/) { LOG_FUNCTION(); m_pCurrentSession = new CSIPPhoneSession(this); return m_pCurrentSession; } virtual bool IsService()const{return true;} virtual void OnTimeout(DWORD dwTimerID) { if (dwTimerID == 1) { //如果当前动态帧频不等于之前的帧频,发送当前帧频 //if (g_nDynamicFps != m_nDownDynamicFps) //{ // m_nDownDynamicFps = g_nDynamicFps; // SendDynamicFps(g_nDynamicFps); //} Dbg("stop up stream!"); GetFunction()->KillTimer(1); m_stVideoParam.nUpDynamicFps = -1; } } bool IsCurrentSession(CServerSessionBase * pSession) { return m_pCurrentSession == pSession; } endpoint_t *GetEndpoint() { return m_pEndpoint; } ErrorCodeEnum InitEndpoint() { LOG_FUNCTION(); ErrorCodeEnum eCode = Error_Param; CSmartPointer Func = GetFunction(); Func->GetSystemStaticInfo(staticInfo); CSimpleStringA strUri = MakeUri(staticInfo.strTerminalID); if (strUri.GetLength() > 0) { strcpy(conf.uri, strUri); conf.media_start_port = REC_COMMON_AUDIO_PORT_START; conf.media_stop_port = REC_COMMON_AUDIO_PORT_STOP; m_pEndpoint = endpoint_create(this, &conf,DEV_HANDFREE); if (!m_pEndpoint) { LOG_TRACE("create endpoint failed!"); eCode = Error_Unexpect; } else{ Dbg("%s:%d endpoint_create m_pEndpoint addr is 0x%0x.", __FUNCTION__, __LINE__, m_pEndpoint); eCode = Error_Succeed; } } else { LOG_TRACE("strUri length equals zero!"); eCode = Error_Unexpect; } return eCode; } struct ChangeDevCommand { CSIPEntity *pEntity; int dev_type; }; void change_dev(int dev_type) { Dbg("change_dev dev_type:%d", dev_type); if (m_pEndpoint) { Dbg("begin invoke endpoint change audio device!"); endpoint_change_audio_dev(m_pEndpoint, dev_type); Dbg("end invoke endpoint change audio device!"); } } static int __change_dev(void *arg) { ChangeDevCommand *pCmd = (ChangeDevCommand *)arg; pCmd->pEntity->change_dev(pCmd->dev_type); delete pCmd; return 0; } void SwitchHandFree() { LOG_FUNCTION(); int rc = 0; ChangeDevCommand *pCmd = new ChangeDevCommand(); pCmd->pEntity = this; pCmd->dev_type = DEV_HANDFREE; if (endpoint_invoke(m_pEndpoint, &__change_dev, pCmd, &rc) != 0) { Dbg("endpoint invoke failed!"); delete pCmd; } } void SwitchPickup() { LOG_FUNCTION(); int rc = 0; ChangeDevCommand *pCmd = new ChangeDevCommand(); pCmd->pEntity = this; pCmd->dev_type = DEV_PICKUP; if (endpoint_invoke(m_pEndpoint, &__change_dev, pCmd, &rc) != 0) { Dbg("endpoint invoke failed!"); delete pCmd; } } void SetState(int state) { m_state = state; } ErrorCodeEnum RealSelfCheck() { ErrorCodeEnum Error = Error_Succeed; if (m_pSelfcheckClient) { SelfCheckerService_RealCheck_Req req; req.name = GetEntityName(); SelfCheckerService_RealCheck_Ans ans; DWORD Timeout = 500; Error = m_pSelfcheckClient->RealCheck(req,ans,Timeout); if (Error!=Error_Succeed) { Dbg("RealSelfcheck fail!"); } else { Dbg("RealSelfcheck"); } } return Error; } CSimpleStringA MakeUri(const char *terminal_id) { CSimpleStringA str; str = CSimpleStringA::Format("sip:%s@%s;transport=UDP", terminal_id, m_localip); return str; } void Handle_RecordVideoLocation_Info(const char* pszMessage) { if (NULL == pszMessage){ return; } CSimpleStringA strMsg = pszMessage; if (strMsg.IsStartWith("ews|",true)){ strMsg = strMsg.SubString(4,strMsg.GetLength()-4); } int lxPos,lyPos,lwidth,lheight; CSimpleStringA str; sscanf(strMsg.GetData(), "%d@%d@%d@%d@%d@%s", &lxPos, &lyPos, &lwidth, &lheight, &str); Dbg("start record preview local video param : (x=%d,y=%d,width=%d,height=%d).",lxPos,lyPos,lwidth,lheight); m_RecordVideoLocation.x = lxPos; m_RecordVideoLocation.y = lyPos; m_RecordVideoLocation.width = lwidth; m_RecordVideoLocation.height = lheight; } void Handle_AdjustVideoEchoEvent(const char* pszMessage) { if (NULL == pszMessage){ return; } CSimpleStringA strMsg = pszMessage; if (strMsg.IsStartWith("ews|",true)){ strMsg = strMsg.SubString(4,strMsg.GetLength()-4); } int lxPos,lyPos,lwidth,lheight; CSimpleStringA str; sscanf(strMsg.GetData(), "%d@%d@%d@%d@%d@%s", &lxPos, &lyPos, &lwidth, &lheight, &str); Dbg("begin adjust local video param : (x=%d,y=%d,width=%d,height=%d).",lxPos,lyPos,lwidth,lheight); if (DEFAULT_RECORD_VIDEO_WIDTH == lwidth && DEFAULT_RECORD_VIDEO_HEIGHT == lheight){ m_stVideoParam.nWindowState = 0; } else if(SMALL_RECORD_VIDEO_WIDTH == lwidth && SMALL_RECORD_VIDEO_HEIGHT == lheight){ m_stVideoParam.nWindowState = 5; } else{ Dbg("not support width and height."); } m_RecordVideoLocation.x = lxPos; m_RecordVideoLocation.y = lyPos; m_RecordVideoLocation.width = lwidth; m_RecordVideoLocation.height = lheight; } private: ErrorCodeEnum LoadConfig(endpoint_conf_t *conf) { CSmartPointer spFunction = GetFunction(); CSmartPointer spRootConfig; ErrorCodeEnum Error = spFunction->OpenConfig(Config_Root, spRootConfig); if (Error == Error_Succeed) { CSimpleStringA strHandFreeIn; CSimpleStringA strHandFreeOut; CSimpleStringA strPickupIn; CSimpleStringA strPickupOut; SpIniMappingTable table; table.AddEntryString("audio", "handfree_in_dev", strHandFreeIn, "$"); table.AddEntryString("audio", "handfree_out_dev", strHandFreeOut, "$"); table.AddEntryString("audio", "pickup_in_dev", strPickupIn, "$"); table.AddEntryString("audio", "pickup_out_dev", strPickupOut, "$"); table.AddEntryBoolean("audio", "pickup_out_agc", conf->audio_pickup_out_agc, false); table.AddEntryBoolean("audio", "pickup_in_agc", conf->audio_pickup_in_agc, false); table.AddEntryBoolean("audio", "handfree_in_agc", conf->audio_handfree_in_agc, false); table.AddEntryBoolean("audio", "handfree_out_agc", conf->audio_handfree_out_agc, false); table.AddEntryBoolean("audio", "pickup_out_ns", conf->audio_pickup_out_ns, false); table.AddEntryBoolean("audio", "pickup_in_ns", conf->audio_pickup_in_ns, false); table.AddEntryBoolean("audio", "handfree_in_ns", conf->audio_handfree_in_ns, false); table.AddEntryBoolean("audio", "handfree_out_ns", conf->audio_handfree_out_ns, false); table.AddEntryBoolean("audio", "pickup_aec", conf->audio_pickup_aec, false); table.AddEntryBoolean("audio", "handfree_aec", conf->audio_handfree_aec, false); table.AddEntryInt("audio", "handfree_in_volume", m_kept_volume_in[DEV_HANDFREE], 0); table.AddEntryInt("audio", "handfree_out_volume", m_kept_volume_out[DEV_HANDFREE], 0); table.AddEntryInt("audio", "pickup_in_volume", m_kept_volume_in[DEV_PICKUP], 0); table.AddEntryInt("audio", "pickup_out_volume", m_kept_volume_out[DEV_PICKUP], 0); table.AddEntryInt("video", "quant", conf->quant, 0); table.AddEntryInt("video", "mtu", conf->mtu, 0); Error = table.Load(spRootConfig); if (Error == Error_Succeed) { int id; #ifdef RVC_OS_WIN id = capture_get_audio_device_id(true, strHandFreeIn); #else id = m_pAudioMgr->audio_get_device_id(strHandFreeIn.GetData(), true); #endif if (id == -1) { Dbg("audio handfree in device %s does not exist!", (LPCSTR)strHandFreeIn); Error = Error_Param; } strcpy(conf->audio_handfree_in_dev, strHandFreeIn); #ifdef RVC_OS_WIN id = capture_get_audio_device_id(false, strHandFreeOut); #else id = m_pAudioMgr->audio_get_device_id(strHandFreeOut.GetData(), false); #endif if (id == -1) { Dbg("audio handfree out device %s does not exist!", (LPCSTR)strHandFreeOut); Error = Error_Param; } strcpy(conf->audio_handfree_out_dev, strHandFreeOut); #ifdef RVC_OS_WIN id = capture_get_audio_device_id(true, strPickupIn); #else id = m_pAudioMgr->audio_get_device_id(strPickupIn.GetData(), true); #endif if (id == -1) { Dbg("audio pickup in device %s does not exist!", (LPCSTR)strPickupIn); Error = Error_Param; } strcpy(conf->audio_pickup_in_dev, strPickupIn); #ifdef RVC_OS_WIN id = capture_get_audio_device_id(false, strPickupOut); #else id = m_pAudioMgr->audio_get_device_id(strPickupOut.GetData(), false); #endif if (id == -1) { Dbg("audio device %s does not exist!", (LPCSTR)strPickupOut); Error = Error_Param; } strcpy(conf->audio_pickup_out_dev, strPickupOut); conf->ref_active_camera = &m_stVideoParam.iActiveCamera; conf->ref_camera_switch = &m_stVideoParam.iCameraSwitch; conf->ref_window_state = &m_stVideoParam.nWindowState; conf->ref_active_img = &m_stVideoParam.bShowActiveImg; conf->ref_Is_ActiveInspect = &m_stVideoParam.bActiveInspect; conf->ref_camera_state = &m_stVideoParam.iCameraState; conf->ref_Is_showPersonArea = &m_stVideoParam.bShowPersonArea; conf->ref_Is_showRecordArea = &m_stVideoParam.bShowRecordArea; if (eMobilePadType == m_eDeviceType) { m_stVideoParam.nUpDynamicFps = 3; } else if ((ePadtype==m_eDeviceType)||(eDesk2SType==m_eDeviceType)||(eDesk1SType==m_eDeviceType)||(eDesk2SIntegratedType==m_eDeviceType)) { m_stVideoParam.nUpDynamicFps = REC_COMMON_VIDEO_FPS_MOBILE; } else if(eStand2sType == m_eDeviceType) { m_stVideoParam.nUpDynamicFps = 0; } Dbg("init up dynamic fps to %d",m_stVideoParam.nUpDynamicFps); conf->ref_Up_Fps = &m_stVideoParam.nUpDynamicFps; if ((eMobilePadType == m_eDeviceType)||(ePadtype == m_eDeviceType)||(eDesk2SType == m_eDeviceType)||(eDesk1SType==m_eDeviceType)||(eDesk2SIntegratedType==m_eDeviceType)) { conf->camera_count = 1; } else if(eStand2sType == m_eDeviceType) { conf->camera_count = 2; } //DecideCameraCount(conf->camera_count); DecideScreenCount(conf->screen_count); } } return Error; } //载入运行时配置 ErrorCodeEnum LoadAudioRunConfig(int&nHandfreeout,int&nPickupout,int&nHandfreein,int&nPickupin) { CSmartPointer spFunction = GetFunction(); CSmartPointer spConfig; ErrorCodeEnum Error = spFunction->OpenConfig(Config_Run, spConfig); if (Error == Error_Succeed) { SpIniMappingTable table; table.AddEntryInt("Audio", "handfree_out_volume", nHandfreeout, 0); table.AddEntryInt("Audio", "pickup_out_volume", nPickupout, 0); table.AddEntryInt("Audio", "handfree_in_volume", nHandfreein, 0); table.AddEntryInt("Audio", "pickup_in_volume", nPickupin, 0); Error = table.Load(spConfig); if (Error != Error_Succeed) { LOG_TRACE("[dbg] failed to load run config."); } } else { LOG_TRACE("[dbg] failed to open run config."); } return Error; } //保存运行时 ErrorCodeEnum SaveAudioRunConfig(int nHandfreeout,int nPickupout,int nHandfreein,int nPickupin) { CSmartPointer spFunction = GetFunction();; CSmartPointer spConfig; ErrorCodeEnum Error = spFunction->OpenConfig(Config_Run, spConfig); if (Error == Error_Succeed) { Error = spConfig->WriteConfigValueInt("Audio", "handfree_out_volume", nHandfreeout); if(Error == Error_Succeed) { Error = spConfig->WriteConfigValueInt("Audio", "pickup_out_volume", nPickupout); } else { Dbg("SaveAudioRunConfig handfree_out_volume fail!"); return Error; } if(Error == Error_Succeed) { Error = spConfig->WriteConfigValueInt("Audio", "handfree_in_volume", nHandfreein); } else { Dbg("SaveAudioRunConfig pickup_out_volume fail!"); return Error; } if(Error == Error_Succeed) { Error = spConfig->WriteConfigValueInt("Audio", "pickup_in_volume", nPickupin); } else { Dbg("SaveAudioRunConfig handfree_in_volume fail!"); return Error; } if (Error != Error_Succeed) { Dbg("SaveAudioRunConfig pickup_in_volume fail!"); return Error; } } else { Dbg("SaveAudioRunConfig is fail , open sipphone.ini fail!"); } return Error; } // we use root.ini Video section config to decide camera count ErrorCodeEnum DecideCameraCount(int &nCount) { CSmartPointer spFunction = GetFunction(); CSmartPointer spConfig; ErrorCodeEnum Error = spFunction->OpenConfig(Config_Root, spConfig); if (Error == Error_Succeed) { CSimpleStringA strVideoEnv; CSimpleStringA strVideoOpt; SpIniMappingTable table; nCount = 0; table.AddEntryString("Video", "EnvCamera", strVideoEnv, "$"); table.AddEntryString("Video", "OptCamera", strVideoOpt, "$"); Error = table.Load(spConfig); if (Error == Error_Succeed) { if (strVideoEnv.GetLength() > 1) nCount++; if (strVideoOpt.GetLength() > 1) nCount++; } } return Error; } ErrorCodeEnum DecideScreenCount(int &nCount) { CSystemStaticInfo Info; CSmartPointer spFunction = GetFunction(); ErrorCodeEnum Error = spFunction->GetSystemStaticInfo(Info); if (Error == Error_Succeed) { nCount = (int)Info.eScreen; } return Error; } DeviceTypeEnum RvcGetDeviceType() { DeviceTypeEnum eType = eStand2sType; CSmartPointer 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(); Dbg("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; } if (eType >= 0 && eType < sizeof(Device_Type_Table) / sizeof(char*)) { LOG_TRACE("device type is %s.", Device_Type_Table[eType]); } return eType; } public: int m_kept_volume_in[2]; int m_kept_volume_out[2]; #ifdef RVC_OS_WIN void* m_pKeeperIn[2]; void* m_pKeeperOut[2]; #else AudioPulseMgr* m_pAudioMgr; #endif //int m_nDownDynamicFps; //当前视频下行的帧频,由前端通知后端更改频率,只有移动版才使用 CSystemStaticInfo staticInfo; char m_localip[256]; //本地ip endpoint_conf_t conf; endpoint_t *m_pEndpoint; int m_iPickupPhoneState; ErrorCodeEnum m_SipErrorCode; DeviceTypeEnum m_eDeviceType; CallingTypeEnum m_nCallType; //呼叫模式,0:可视柜台正常呼叫,1:PAD主动外呼,2:PAD被动呼叫,来源PAD,3:PAD被动呼叫,来源手机端 int m_nSysCallType;//0:普通模式,1:p2p模式 volatile stVideoParam m_stVideoParam; //视频参数,add by ch@20190424 volatile int m_bIsSalesRecord; //add by ly@20180725 volatile int m_bEwsRecord; //add by ly@2019/04/18 record_echo_location_t m_RecordVideoLocation; private: CServerSessionBase *m_pCurrentSession; int m_state; CAutoArray m_arrListener; ChannelSipphoneClient*m_pSipphoneChannel; SelfChekerClient*m_pSelfcheckClient; }; // // CSIPPhoneSession // void CSIPPhoneSession::OnClose( ErrorCodeEnum eErrorCode ) { LOG_FUNCTION(); } void CSIPPhoneSession::Handle_MakeCall( SpReqAnsContext::Pointer ctx ) { LOG_FUNCTION(); LOG_TRACE("make call [%s]", (LPCSTR)ctx->Req.call_uri); int rc; MakeCallCommand *cmd = new MakeCallCommand(); cmd->pSIPPhoneSession = this; cmd->strUri = ctx->Req.call_uri; ///////////重新初始化sip话机,防止断网导致IP改变////////////////// if (m_pEntity->m_pEndpoint) { Dbg("%s:%d m_pEndpoint is not null and it's addr is 0x%0x,destroy it.", __FUNCTION__, __LINE__, m_pEntity->m_pEndpoint); endpoint_destroy(m_pEntity->m_pEndpoint); m_pEntity->m_pEndpoint = NULL; } CSimpleStringA strUri = m_pEntity->MakeUri(m_pEntity->staticInfo.strTerminalID); if (strUri.GetLength() > 0) { strcpy(m_pEntity->conf.uri, strUri); m_pEntity->conf.media_start_port = REC_COMMON_AUDIO_PORT_START; m_pEntity->conf.media_stop_port = REC_COMMON_AUDIO_PORT_STOP; Dbg("%s:%d", __FUNCTION__, __LINE__); m_pEntity->m_pEndpoint = endpoint_create(m_pEntity, &m_pEntity->conf, m_pEntity->m_iPickupPhoneState); if (!m_pEntity->m_pEndpoint) { LOG_TRACE("create endpoint failed!"); } else { Dbg("%s:%d endpoint_create m_pEndpoint addr is 0x%0x.", __FUNCTION__, __LINE__, m_pEntity->m_pEndpoint); } } else { LOG_TRACE("strUri length equals zero!"); } ErrorCodeEnum Error = m_pEntity->GetLocalIP(); if (Error != 0) { LOG_TRACE("get local ip failed!"); } if (m_pEntity->m_eDeviceType == eMobilePadType) { m_pEntity->m_stVideoParam.nUpDynamicFps = 3; } ///////////重新初始化sip话机,防止断网导致IP改变////////////////// if (m_pEntity->GetEndpoint()) { endpoint_invoke(m_pEntity->GetEndpoint(), &__make_call, cmd, &rc); } ctx->Answer((ErrorCodeEnum)rc); } void CSIPPhoneSession::Handle_HangupCall( SpReqAnsContext::Pointer ctx ) { LOG_FUNCTION(); int rc; HangupCallCommand *cmd = new HangupCallCommand(); cmd->pSIPPhoneSession = this; cmd->strSession_num = ctx->Req.session_num; cmd->strBranch_server_ip = ctx->Req.branch_server_ip; cmd->iBranch_server_port = ctx->Req.branch_server_port; if (m_pEntity->GetEndpoint()) { endpoint_invoke(m_pEntity->GetEndpoint(), &__hangup_call, cmd, &rc); } ctx->Answer((ErrorCodeEnum)rc); } void CSIPPhoneSession::Handle_ReleaseCall( SpReqAnsContext::Pointer ctx ) { LOG_FUNCTION(); int rc = Error_Succeed; g_IsExternalTerminalted = TRUE; endpoint_invoke(m_pEntity->GetEndpoint(), &__release_call, this, &rc); Dbg("%s:%d endpoint_destroy m_pEndpoint addr is 0x%0x.", __FUNCTION__, __LINE__, m_pEntity->m_pEndpoint); if (NULL != m_pEntity->m_pEndpoint){ endpoint_destroy(m_pEntity->m_pEndpoint); m_pEntity->m_pEndpoint = NULL; } ctx->Answer((ErrorCodeEnum)rc); } void CSIPPhoneSession::Handle_SetCallingParam(SpOnewayCallContext::Pointer ctx) { LOG_FUNCTION(); Dbg("SetCallingParam CallType = %d", ctx->Info.CallType); m_pEntity->m_nCallType = (CallingTypeEnum)ctx->Info.CallType; } void CSIPPhoneSession::Handle_RealErrorCheck(SpOnewayCallContext::Pointer ctx) { LOG_FUNCTION(); m_pEntity->m_SipErrorCode = Error_InvalidState; m_pEntity->RealSelfCheck(); } void CSIPPhoneSession::Handle_StartVideo( SpOnewayCallContext::Pointer ctx ) { LOG_FUNCTION(); int rc; ControlVideoCommand *pCmd = new ControlVideoCommand(); pCmd->pSIPPhoneSession = this; pCmd->start = TRUE; pCmd->local_hwd_move = 0; pCmd->remote_hwd_move = 0; if(!(ctx->Info.remote_view_x||ctx->Info.remote_view_y||ctx->Info.remote_view_cx||ctx->Info.remote_view_cy||ctx->Info.remote_width||ctx->Info.remote_height)) { m_IsLocalPlay= TRUE; m_VideoWindowPlayType = eOnly_Local_Video; Dbg("LocalPlay Mod"); } else { m_IsLocalPlay= FALSE; m_VideoWindowPlayType = eOnline_Mode_Video; Dbg("OnlinePlay Mod"); if (0 == ctx->Info.remote_port){ m_VideoWindowPlayType = eBoth_Local_Remote_Video; m_pEntity->m_nCallType = NORMAL_CALLTYPE; Dbg("both local and remote mode."); if (NULL == m_pEntity->GetEndpoint()) { Dbg("m_pEndpoint has destroy, now new init it."); m_pEntity->InitEndpoint(); } } } pCmd->local_ip = inet_addr(m_pEntity->m_localip); pCmd->local_port = REC_COMMON_VIDEO_PORT; pCmd->remote_ip = inet_addr(ctx->Info.remote_ip); pCmd->remote_port = ctx->Info.remote_port; pCmd->local_view_x = ctx->Info.local_view_x; pCmd->local_view_y = ctx->Info.local_view_y; pCmd->local_view_cx = ctx->Info.local_view_cx; pCmd->local_view_cy = ctx->Info.local_view_cy; pCmd->remote_view_x = ctx->Info.remote_view_x; pCmd->remote_view_y = ctx->Info.remote_view_y; pCmd->remote_view_cx = ctx->Info.remote_view_cx; pCmd->remote_view_cy = ctx->Info.remote_view_cy; pCmd->remote_width = ctx->Info.remote_width; pCmd->remote_height = ctx->Info.remote_height; pCmd->local_hwd_move = ctx->Info.local_hwd_move; pCmd->remote_hwd_move = ctx->Info.remote_hwd_move; //初始化窗口参数 //m_pEntity->m_stVideoParam.nWindowState = 0; //m_pEntity->GetFunction()->SetTimer(1, m_pEntity, 1000); //m_pEntity->m_nDownDynamicFps = ctx->Info.remote_fps; //g_nDynamicFps = ctx->Info.remote_fps; //g_nSysFps = ctx->Info.remote_fps; //g_nLastRecFrameTime = GetTickCount(); endpoint_invoke(m_pEntity->GetEndpoint(), &__control_video, pCmd, &rc); } void CSIPPhoneSession::Handle_StopVideo( SpOnewayCallContext::Pointer ctx ) { int rc; ControlVideoCommand *pCmd = new ControlVideoCommand(); pCmd->pSIPPhoneSession = this; pCmd->start = FALSE; m_pEntity->GetFunction()->KillTimer(1); if (NULL != m_pEntity->GetEndpoint()){ endpoint_invoke(m_pEntity->GetEndpoint(), &__control_video, pCmd, &rc); } else{ endpoint_call_stop_double_record_broadcast_video(); } m_pEntity->m_stVideoParam.bShowActiveImg = 0; m_pEntity->m_stVideoParam.bActiveInspect = 0; //初始化窗口参数 m_pEntity->m_stVideoParam.nWindowState = 0; } void CSIPPhoneSession::Handle_BeginState( SpSubscribeContext::Pointer ctx ) { m_spCallbackContext = ctx; } void CSIPPhoneSession::Handle_EndState( SpOnewayCallContext::Pointer ctx ) { SpSubscribeContext::Pointer tmp_ctx = m_spCallbackContext; m_spCallbackContext.Clear(); } void CSIPPhoneSession::hangup_call(/*CSIPPhoneSession::HangupCallCommand* cmd*/) { if (m_pCall) { Dbg("normal hangup."); endpoint_call_hangup(m_pCall); } } void CSIPPhoneSession::release_call() { if (m_pCall){ Terminatedcall(m_pCall); } } void CSIPPhoneSession::on_call_state(int state, const char *state_desc, const char *phrase) { if (m_spCallbackContext != NULL) { PhoneService_PhoneState_Info Info; Info.state = state; Info.status = CSimpleStringA::Format("%s,%s", state_desc, phrase); m_spCallbackContext->SendMessage(Info); } if (state == TERMINATED) { if (NULL != m_pCall){ endpoint_call_destroy(m_pCall); m_pCall = NULL; } } m_pEntity->SetState(state); } int CSIPPhoneSession::make_call( const char *remote_uri ) { if (m_pCall) { LOG_TRACE("call duplicated! and endpoint destroy old call."); endpoint_call_destroy(m_pCall); m_pCall = NULL; //return Error_Duplication; } //else { endpoint_call_callback_t cb = {0}; cb.on_call_state = &__on_call_state; cb.user_data = this; m_pCall = endpoint_call_create(m_pEntity->GetEndpoint(), remote_uri, m_pEntity->m_localip,m_pEntity->m_eDeviceType,m_pEntity->m_nCallType,&cb); if (m_pCall) { g_IsExternalTerminalted = FALSE; Dbg("g_IsExternalTerminalted = FALSE"); LOG_TRACE("create call endpoint ok!"); if (endpoint_call_start(m_pCall) == 0) { LOG_TRACE("start call ok!"); return Error_Succeed; } else { LOG_TRACE("start call failed! and endpoint destroy call."); endpoint_call_destroy(m_pCall); m_pCall = NULL; return Error_Unexpect; } } else { g_IsExternalTerminalted = TRUE; Dbg("g_IsExternalTerminalted = TRUE"); LOG_TRACE("create call endpoint failed!"); m_pEntity->m_SipErrorCode = Error_InvalidState; m_pEntity->RealSelfCheck(); return Error_Unexpect; } } } void CSIPPhoneSession::control_video( ControlVideoCommand *pCmd ) { LOG_FUNCTION(); if (m_pCall) { if (pCmd->start) { endpoint_call_start_video(m_pCall, pCmd->remote_ip, pCmd->remote_port, pCmd->local_ip, pCmd->local_port, pCmd->remote_width, pCmd->remote_height, pCmd->local_view_x, pCmd->local_view_y, pCmd->local_view_cx, pCmd->local_view_cy, pCmd->remote_view_x, pCmd->remote_view_y, pCmd->remote_view_cx, pCmd->remote_view_cy, pCmd->local_hwd_move, pCmd->remote_hwd_move, &m_cb_video_box_move); } else { //双录第一阶段结束录像,销毁call资源 if ((eOnly_Local_Video == m_VideoWindowPlayType) || (eBoth_Local_Remote_Video == m_VideoWindowPlayType && m_pEntity->m_nCallType != DOUBLERECORD_CALLTYPE )) { Dbg("stop record play."); local_play_stop_video(m_pCall); m_IsLocalPlay = FALSE; endpoint_call_destroy(m_pCall); m_pCall = NULL; } else { endpoint_call_stop_video(m_pCall); } } } else { if (pCmd->start) { endpoint_call_callback_t cb = {0}; cb.on_call_state = &__on_call_state; cb.user_data = this; m_pCall = endpoint_call_create(m_pEntity->GetEndpoint(), "test",m_pEntity->m_localip,m_pEntity->m_eDeviceType,m_pEntity->m_nCallType, &cb); if (eOnly_Local_Video == m_VideoWindowPlayType){ Dbg("start local play mode record."); local_play_start_video(m_pCall,pCmd->local_view_x, pCmd->local_view_y, pCmd->local_view_cx, pCmd->local_view_cy, pCmd->local_hwd_move, &m_cb_video_box_move); } else if (eBoth_Local_Remote_Video == m_VideoWindowPlayType){ Dbg("start local and remote video play mode record."); local_remote_show_video(m_pCall,pCmd->local_view_x, pCmd->local_view_y, pCmd->local_view_cx, pCmd->local_view_cy,pCmd->remote_view_x, pCmd->remote_view_y, pCmd->remote_view_cx, pCmd->remote_view_cy, pCmd->local_hwd_move, pCmd->remote_hwd_move,&m_cb_video_box_move); } } else{ #ifdef RVC_OS_WIN Dbg("record call remote agent timeout, close video session."); endpoint_call_stop_double_record_broadcast_video(); #endif } } } int CSIPPhoneSession::on_video_box_move(int imessageType, int ivideotype, int ileft, int ibottom) { int iret = -1; if (0 == imessageType){ VideoBoxStartMove evt; evt.videoboxflag = ivideotype; evt.leftlowerx = ileft; evt.leftlowery = ibottom; iret = SpSendBroadcast(m_pEntity->GetFunction(), SP_MSG_OF(VideoBoxStartMove), SP_MSG_SIG_OF(VideoBoxStartMove), evt); Dbg("VideoBoxStartMove broadcast sent, video type is %d, left is %d, bottom is %d.", ivideotype, ileft, ibottom); } else{ VideoBoxStopMove evt; evt.videoboxflag = ivideotype; evt.leftlowerx = ileft; evt.leftlowery = ibottom; iret = SpSendBroadcast(m_pEntity->GetFunction(), SP_MSG_OF(VideoBoxStopMove), SP_MSG_SIG_OF(VideoBoxStopMove), evt); Dbg("VideoBoxStopMove broadcast sent, video type is %d, left is %d, bottom is %d.", ivideotype, ileft, ibottom); } return iret; } ChannelSipphoneClient::ChannelSipphoneClient( CSIPEntity *pEntity ) : ChannelService_ClientBase(pEntity) { } void ChannelSipphoneClient::OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer pData) { if (Error == Error_Succeed) { CSIPEntity *pEntity = static_cast(m_pEntityBase); if (Msg.state == eChannelState_Connected) { #ifdef RVC_OS_WIN if (pEntity->m_pKeeperIn[DEV_HANDFREE]) #else if (pEntity->m_pAudioMgr) #endif { pEntity->SendAudioDeviceVolumn(DEVICE_HANDFREE_IN); } #ifdef RVC_OS_WIN if (pEntity->m_pKeeperOut[DEV_HANDFREE]) #else if (pEntity->m_pAudioMgr) #endif { pEntity->SendAudioDeviceVolumn(DEVICE_HANDFREE_OUT); } #ifdef RVC_OS_WIN if (pEntity->m_pKeeperOut[DEV_PICKUP]) #else if (pEntity->m_pAudioMgr) #endif { pEntity->SendAudioDeviceVolumn(DEVICE_PICKUP_OUT); } #ifdef RVC_OS_WIN if (pEntity->m_pKeeperIn[DEV_PICKUP]) #else if (pEntity->m_pAudioMgr) #endif { pEntity->SendAudioDeviceVolumn(DEVICE_PICKUP_IN); } } } } void ChannelSipphoneClient::OnMessage( ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer pData ) { //LOG_FUNCTION(); if (Error == Error_Succeed) { CSIPEntity *pEntity = static_cast(m_pEntityBase); pEntity->OnReceivePkt(Msg.type,Msg.sub_type, (const char*)Msg.data.m_pData, Msg.data.m_iLength); } } SelfChekerClient::SelfChekerClient( CSIPEntity *pEntity ) : SelfCheckerService_ClientBase(pEntity) { } SP_BEGIN_ENTITY_MAP() SP_ENTITY(CSIPEntity) SP_END_ENTITY_MAP()