123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409 |
- #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<IReleasable> pData);
- virtual void OnMessage(ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData);
- };
- class CSIPPhoneSession : public PhoneService_ServerSessionBase
- {
- public:
- CSIPPhoneSession(CSIPEntity *pEntity);
- virtual void Handle_MakeCall(SpReqAnsContext<PhoneService_MakeCall_Req, PhoneService_MakeCall_Ans>::Pointer ctx);
- virtual void Handle_HangupCall(SpReqAnsContext<PhoneService_HangupCall_Req, PhoneService_HangupCall_Ans>::Pointer ctx);
- virtual void Handle_StartVideo(SpOnewayCallContext<PhoneService_StartVideo_Info>::Pointer ctx);
- virtual void Handle_StopVideo(SpOnewayCallContext<PhoneService_StopVideo_Info>::Pointer ctx);
- virtual void Handle_BeginState(SpSubscribeContext<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::Pointer ctx);
- virtual void Handle_EndState(SpOnewayCallContext<PhoneService_EndState_Info>::Pointer ctx);
- virtual void Handle_ReleaseCall(SpReqAnsContext<PhoneService_ReleaseCall_Req, PhoneService_ReleaseCall_Ans>::Pointer ctx);
- virtual void Handle_RealErrorCheck(SpOnewayCallContext<PhoneService_RealErrorCheck_Info>::Pointer ctx);
- virtual void Handle_SetCallingParam(SpOnewayCallContext<PhoneService_SetCallingParam_Info>::Pointer ctx);
- virtual void OnClose(ErrorCodeEnum eErrorCode);
- virtual void Handle_GetHandfreeOutVolume(SpReqAnsContext<PhoneService_GetHandfreeOutVolume_Req, PhoneService_GetHandfreeOutVolume_Ans>::Pointer ctx);
- virtual void Handle_SetHandfreeOutVolume(SpReqAnsContext<PhoneService_SetHandfreeOutVolume_Req, PhoneService_SetHandfreeOutVolume_Ans>::Pointer ctx);
- virtual void Handle_GetPickupOutVolume(SpReqAnsContext<PhoneService_GetPickupOutVolume_Req, PhoneService_GetPickupOutVolume_Ans>::Pointer ctx);
- virtual void Handle_SetPickupOutVolume(SpReqAnsContext<PhoneService_SetPickupOutVolume_Req, PhoneService_SetPickupOutVolume_Ans>::Pointer ctx);
- virtual void Handle_StartVideoRender(SpOnewayCallContext<PhoneService_StartVideoRender_Info>::Pointer ctx);
- virtual void Handle_StopVideoRender(SpOnewayCallContext<PhoneService_StopVideoRender_Info>::Pointer ctx);
- virtual void Handle_GetHandfreeInVolume(SpReqAnsContext<PhoneService_GetHandfreeInVolume_Req, PhoneService_GetHandfreeInVolume_Ans>::Pointer ctx);
- virtual void Handle_SetHandfreeInVolume(SpReqAnsContext<PhoneService_SetHandfreeInVolume_Req, PhoneService_SetHandfreeInVolume_Ans>::Pointer ctx);
- virtual void Handle_SetPickupInVolume(SpReqAnsContext<PhoneService_SetPickupInVolume_Req, PhoneService_SetPickupInVolume_Ans>::Pointer ctx);
- virtual void Handle_GetPickupInVolume(SpReqAnsContext<PhoneService_GetPickupInVolume_Req, PhoneService_GetPickupInVolume_Ans>::Pointer ctx);
- virtual void Handle_GetAudioDevices(SpReqAnsContext<PhoneService_GetAudioDevices_Req, PhoneService_GetAudioDevices_Ans>::Pointer ctx);
- virtual void Handle_StartCameraRender(SpReqAnsContext<PhoneService_StartCameraRender_Req, PhoneService_StartCameraRender_Ans>::Pointer ctx);
- virtual void Handle_StopCameraRender(SpReqAnsContext<PhoneService_StopCameraRender_Req, PhoneService_StopCameraRender_Ans>::Pointer ctx);
- virtual void Handle_IsCameraRender(SpReqAnsContext<PhoneService_IsCameraRender_Req, PhoneService_IsCameraRender_Ans>::Pointer ctx);
- virtual void Handle_StartBothCameraRender(SpReqAnsContext<PhoneService_StartBothCameraRender_Req, PhoneService_StartBothCameraRender_Ans>::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<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::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<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
- const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
- const CAutoArray<DWORD> &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<ITransactionContext> pTransactionContext);
- virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> 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<ITransactionContext> 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<PhoneService_StartBothCameraRender_Req, PhoneService_StartBothCameraRender_Ans>::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<CUUID> m_arrListener;
- ChannelSipphoneClient*m_pSipphoneChannel;
- HealthManagerService_ClientBase* m_pHMClient;
- bool m_bConnectedAssist;
- bool m_bFirstLaunched;
- bool m_bMessageBox;
- };
|