#pragma once #include "SIPPhone_server_g.h" #include "SIPPhone_msg_g.h" using namespace SIPPhone; #include "SpBase.h" #include "SpIni.h" #include "endpoint.h" #if defined(RVC_OS_WIN) #include "volumekeeper.h" #else #include "Event.h" #include "EventCode.h" #endif //RVC_OS_WIN #include "video_render.h" #include "HealthManager_client_g.h" #include "HealthManager_def_g.h" using namespace HealthManager; #include "mod_assistantchannel/chan_protocol.h" #include "mod_assistantchannel/AssistantChannel_client_g.h" using namespace AssistantChannel; #include "iaudiomgrinterface.h" #ifndef MAX_LOG_LEN #define MAX_LOG_LEN 512 #endif #ifndef RVC_START_TIME #define RVC_START_TIME "00:00:00" #endif // !RVC_START_TIME #ifndef RVC_END_TIME #define RVC_END_TIME "08:00:00" #endif // !RVC_END_TIME #ifndef RVC_INTERVAL_TIME #define RVC_INTERVAL_TIME 3*60 #endif // ! RVC_INTERVAL_TIME #ifndef RVC_AUDIO_IN_DEVICE_COUNT #define RVC_AUDIO_IN_DEVICE_COUNT 2 #endif // !RVC_AUDIO_IN_DEVICE_COUNT #ifndef RVC_AUDIO_OUT_DEVICE_COUNT #define RVC_AUDIO_OUT_DEVICE_COUNT 2 #endif // !RVC_AUDIO_OUT_DEVICE_COUNT #ifndef RVC_ENTER_HOME_PAGE_TIMER #define RVC_ENTER_HOME_PAGE_TIMER 3 #endif #ifndef rvc_vsnprintf #ifdef _WIN32 #define rvc_vsnprintf _vsnprintf #else #define rvc_vsnprintf vsnprintf #endif #endif typedef enum { RVC_AUDIO_NO_ERROR = 0x0, RVC_AUDIO_HANDFREEIN_ERROR = 0x1, RVC_AUDIO_HANDFREEOUT_ERROR = 0x2, RVC_AUDIO_PICKUPIN_ERROR = 0x4, RVC_AUDIO_PICKUPOUT_ERROR = 0x8 } RVC_AudioErrorFlags; class CSIPEntity; class CSIPPhoneSession; 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; //是否显示录像人形轮廓 }; 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, eBoth_Local_Remote_Video }; enum eVideoRenderType{ eGDI, eSDL }; static const char* VideoRender_Type_Table[] = { "eGDI", "eSDL" }; typedef struct MakeCallCommand_s { CSIPPhoneSession *pSIPPhoneSession; CSimpleStringA toUri; CSimpleStringA fromUri; CSimpleStringA callId; CSimpleStringA strlocalip; int iaudio_port; int ivideo_port; }MakeCallCommand_t; typedef struct ControlVideoCommand_s { 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; int local_fresh_time; int remote_fresh_time; }ControlVideoCommand_t; typedef struct VideoRenderCommand_s { CSIPPhoneSession* pSIPPhoneSession; bool bstart; 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 local_hwd_move; int remote_hwd_move; int local_fresh_time; int remote_fresh_time; }VideoRenderCommand_t; typedef struct HangupCallCommand_s{ CSIPPhoneSession *pSIPPhoneSession; }HangupCallCommand_t; struct ChangeDevCommand{ CSIPEntity *pEntity; int dev_type; }; 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); 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); virtual void Handle_GetHandfreeOutVolume(SpReqAnsContext::Pointer ctx); virtual void Handle_SetHandfreeOutVolume(SpReqAnsContext::Pointer ctx); virtual void Handle_GetPickupOutVolume(SpReqAnsContext::Pointer ctx); virtual void Handle_SetPickupOutVolume(SpReqAnsContext::Pointer ctx); virtual void Handle_StartVideoRender(SpOnewayCallContext::Pointer ctx); virtual void Handle_StopVideoRender(SpOnewayCallContext::Pointer ctx); virtual void Handle_GetHandfreeInVolume(SpReqAnsContext::Pointer ctx); virtual void Handle_SetHandfreeInVolume(SpReqAnsContext::Pointer ctx); virtual void Handle_SetPickupInVolume(SpReqAnsContext::Pointer ctx); virtual void Handle_GetPickupInVolume(SpReqAnsContext::Pointer ctx); virtual void Handle_GetAudioDevices(SpReqAnsContext::Pointer ctx); virtual void Handle_StartCameraRender(SpReqAnsContext::Pointer ctx); virtual void Handle_StopCameraRender(SpReqAnsContext::Pointer ctx); virtual void Handle_IsCameraRender(SpReqAnsContext::Pointer ctx); virtual void Handle_StartBothCameraRender(SpReqAnsContext::Pointer ctx); public: void on_call_state(int state, const char *state_desc, const char *phrase); int make_call(MakeCallCommand_t *pCmd); void hangup_call(); void release_call(); void control_video(ControlVideoCommand_t* pCmd); int on_video_box_move(int imessagetype, int ivideotype, int ileft, int ibottom); #if defined(RVC_OS_WIN) #else void video_render(VideoRenderCommand_t* pCmd); int start_video_render(rvc_video_render_params_t* render_param, eVideoRenderMode eMode); int stop_video_render(); #endif //RVC_OS_WIN public: int m_iLastState; private: SpSubscribeContext::Pointer m_spCallbackContext; endpoint_call_t *m_pCall; CSIPEntity *m_pEntity; #if defined(RVC_OS_WIN) int m_IsLocalPlay; eShowVideoWindowType m_VideoWindowPlayType; video_session_callback_t m_cb_video_box_move; #endif //RVC_OS_WIN }; class CSIPEntity : public CEntityBase, public ILogListener, public ISysVarListener,public ITimerListener { public: CSIPEntity(); 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, const linkContext& pLinkInfo); virtual void OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName); virtual void OnSelfTest(EntityTestEnum eTestType,CSmartPointer pTransactionContext); virtual void OnPreStart(CAutoArray strArgs,CSmartPointer pTransactionContext); virtual void OnStarted(); ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError); void OnReceivePkt(int type, int sub_type, const char *buffer, int size); ErrorCodeEnum GetLocalIP(); #if defined(RVC_OS_WIN) ErrorCodeEnum StartVideoRender(); ErrorCodeEnum StopVideoRender(); #endif //RVC_OS_WIN //send audio device volume void SendAudioDeviceVolumn(int nDevice); ErrorCodeEnum SetHandfreeOutVolume(int iVolume); ErrorCodeEnum SetPickupOutVolume(int iVolume); ErrorCodeEnum SetHandfreeInVolume(int iVolume); ErrorCodeEnum SetPickupInVolume(int iVolume); virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer pTransactionContext); ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError); virtual void OnPaused(); virtual void OnContinued(); virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszClass*/); virtual bool IsService()const{return true;} virtual void OnTimeout(DWORD dwTimerID); bool IsCurrentSession(CServerSessionBase * pSession) { return m_pCurrentSession == pSession; } endpoint_t *GetEndpoint() { return m_pEndpoint; } ErrorCodeEnum InitEndpoint(); void change_dev(int dev_type); void SwitchHandFree(); void SwitchPickup(); void SetState(int state); ErrorCodeEnum RealSelfCheck(); CSimpleStringA MakeUri(const char *terminal_id); void SetMessageBoxFlag(bool bFlag); void HandleSendBroadcastMsg(bool bHandfreeError); int StartCameraRender(int icamid, int ivideoview_x, int ivideoview_y, int ivideoview_cx, int ivideoview_cy); int StopCameraRender(); int StartBothCameraRender(SpReqAnsContext::Pointer ctx); private: ErrorCodeEnum LoadConfig(endpoint_conf_t *conf); #if defined(RVC_OS_WIN) eVideoRenderType GetMediaConfig(); #else void InitFreshTimeConfig(); void HideLocalVideo(); void ShowLocalVideo(); void HideBothVideo(); void ShowBothVideo(); CSimpleStringA GetAudioDeviceJsonInfos(bool bmicro); #endif //RVC_OS_WIN void HandleHandfreeAudioDeviceErrorEvent(); //载入运行时配置 ErrorCodeEnum LoadRestartRunConfig(unsigned int& utime); //保存运行时 ErrorCodeEnum SaveRestartRunConfig(unsigned int utime); ErrorCodeEnum AudioDspFlagsUseCentersetting(endpoint_conf_t* conf); //载入运行时配置 ErrorCodeEnum LoadAudioRunConfig(int&nHandfreeout, int&nPickupout, int&nHandfreein, int&nPickupin); //保存运行时 ErrorCodeEnum SaveAudioRunConfig(int nHandfreeout, int nPickupout, int nHandfreein, int nPickupin); // we use root.ini Video section config to decide camera count ErrorCodeEnum DecideScreenCount(int &nCount); DeviceTypeEnum RvcGetDeviceType(); ErrorCodeEnum RvcGetAudioDeviceInfo(); ErrorCodeEnum RvcSetSaveAudioVolume(); ErrorCodeEnum LoadEntityConfig(); ErrorCodeEnum ConnectAssistChannel(); bool IsPostAudioConfigInfo(); uint32_t CheckAudioDevice(); ErrorCodeEnum SetSoundCardSysVar(const CSimpleStringA& newVal); void HandleCheckAudioDevice(const char* pszValue); public: int m_kept_volume_in[2]; int m_kept_volume_out[2]; IAudioMgr* m_pAudioMgr; bool m_bIsCameraRender; #ifdef RVC_OS_WIN void* m_pKeeperIn[2]; void* m_pKeeperOut[2]; eVideoRenderType m_eVideoRenderType; #endif int m_ilocalvideo_freshtime; int m_iremotevideo_freshtime; rvc_video_render_t* m_render; bool m_bAudioMgrInited; CSimpleStringA m_strStartTime; CSimpleStringA m_strEndTime; int m_itervalTime; bool m_bStopAutoRestart; CSystemStaticInfo staticInfo; char m_localip[RVC_MAX_IP_LEN]; //本地ip endpoint_conf_t conf; endpoint_t *m_pEndpoint; int m_iPickupPhoneState; ErrorCodeEnum m_SipErrorCode; DeviceTypeEnum m_eDeviceType; CallingTypeEnum m_nCallType; //呼叫模式,0:可视柜台正常呼叫,1:远程双录 volatile stVideoParam m_stVideoParam; private: CServerSessionBase *m_pCurrentSession; int m_state; CAutoArray m_arrListener; ChannelSipphoneClient*m_pSipphoneChannel; HealthManagerService_ClientBase* m_pHMClient; bool m_bConnectedAssist; bool m_bFirstLaunched; bool m_bMessageBox; };