mod_sipphone.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. #pragma once
  2. #include "SIPPhone_server_g.h"
  3. #include "SIPPhone_msg_g.h"
  4. using namespace SIPPhone;
  5. #include "SpBase.h"
  6. #include "SpIni.h"
  7. #include "endpoint.h"
  8. #if defined(RVC_OS_WIN)
  9. #include "volumekeeper.h"
  10. #else
  11. #include "Event.h"
  12. #include "EventCode.h"
  13. #endif //RVC_OS_WIN
  14. #include "video_render.h"
  15. #include "HealthManager_client_g.h"
  16. #include "HealthManager_def_g.h"
  17. using namespace HealthManager;
  18. #include "mod_assistantchannel/chan_protocol.h"
  19. #include "mod_assistantchannel/AssistantChannel_client_g.h"
  20. using namespace AssistantChannel;
  21. #include "iaudiomgrinterface.h"
  22. #ifndef MAX_LOG_LEN
  23. #define MAX_LOG_LEN 512
  24. #endif
  25. #ifndef RVC_START_TIME
  26. #define RVC_START_TIME "00:00:00"
  27. #endif // !RVC_START_TIME
  28. #ifndef RVC_END_TIME
  29. #define RVC_END_TIME "08:00:00"
  30. #endif // !RVC_END_TIME
  31. #ifndef RVC_INTERVAL_TIME
  32. #define RVC_INTERVAL_TIME 3*60
  33. #endif // ! RVC_INTERVAL_TIME
  34. #ifndef RVC_AUDIO_IN_DEVICE_COUNT
  35. #define RVC_AUDIO_IN_DEVICE_COUNT 2
  36. #endif // !RVC_AUDIO_IN_DEVICE_COUNT
  37. #ifndef RVC_AUDIO_OUT_DEVICE_COUNT
  38. #define RVC_AUDIO_OUT_DEVICE_COUNT 2
  39. #endif // !RVC_AUDIO_OUT_DEVICE_COUNT
  40. #ifndef RVC_ENTER_HOME_PAGE_TIMER
  41. #define RVC_ENTER_HOME_PAGE_TIMER 3
  42. #endif
  43. #ifndef rvc_vsnprintf
  44. #ifdef _WIN32
  45. #define rvc_vsnprintf _vsnprintf
  46. #else
  47. #define rvc_vsnprintf vsnprintf
  48. #endif
  49. #endif
  50. typedef enum
  51. {
  52. RVC_AUDIO_NO_ERROR = 0x0,
  53. RVC_AUDIO_HANDFREEIN_ERROR = 0x1,
  54. RVC_AUDIO_HANDFREEOUT_ERROR = 0x2,
  55. RVC_AUDIO_PICKUPIN_ERROR = 0x4,
  56. RVC_AUDIO_PICKUPOUT_ERROR = 0x8
  57. } RVC_AudioErrorFlags;
  58. class CSIPEntity;
  59. class CSIPPhoneSession;
  60. struct CVolumnValue
  61. {
  62. int nValue;
  63. void Serialize(SpBuffer &Buf)
  64. {
  65. Buf & nValue;
  66. }
  67. };
  68. struct CFpsValue
  69. {
  70. int nValue;
  71. void Serialize(SpBuffer &Buf)
  72. {
  73. Buf & nValue;
  74. }
  75. };
  76. struct stVideoParam
  77. {
  78. int nWindowState; //视频窗口显示状态,0:正常大小显示,1:放大一倍显示,2:隐藏全部窗口,3:从隐藏状态恢复为全部显示,4:显示远程窗口,隐藏本地窗口, 5:缩放显示
  79. int bShowActiveImg; //活体检测显示图片
  80. int bActiveInspect; //是否启动活体检测
  81. int iActiveCamera; // set by facetracking
  82. int iCameraSwitch; // set by agent and camerastate
  83. int nUpDynamicFps; // 当前视频上行的帧频,由后端通知前端更改频率,只有移动版才使用
  84. int iCameraState; // set by agent and camerastate
  85. int bShowPersonArea; //是否显示人形框
  86. int bShowRecordArea; //是否显示录像人形轮廓
  87. };
  88. enum ePickupMicrophoneState
  89. {
  90. ePickupMicrophoneState_On,
  91. ePickupMicrophoneState_Off,
  92. };
  93. /* 0:online local and remote video window, 1:only local video window, 2:both local and remote window */
  94. enum eShowVideoWindowType{
  95. eOnline_Mode_Video,
  96. eBoth_Local_Remote_Video
  97. };
  98. enum eVideoRenderType{
  99. eGDI,
  100. eSDL
  101. };
  102. static const char* VideoRender_Type_Table[] = {
  103. "eGDI",
  104. "eSDL"
  105. };
  106. typedef struct MakeCallCommand_s {
  107. CSIPPhoneSession *pSIPPhoneSession;
  108. CSimpleStringA toUri;
  109. CSimpleStringA fromUri;
  110. CSimpleStringA callId;
  111. CSimpleStringA strlocalip;
  112. int iaudio_port;
  113. int ivideo_port;
  114. }MakeCallCommand_t;
  115. typedef struct ControlVideoCommand_s {
  116. CSIPPhoneSession *pSIPPhoneSession;
  117. int start;
  118. unsigned long local_ip;
  119. int local_port;
  120. unsigned long remote_ip;
  121. int remote_port;
  122. int local_view_x;
  123. int local_view_y;
  124. int local_view_cx;
  125. int local_view_cy;
  126. int remote_view_x;
  127. int remote_view_y;
  128. int remote_view_cx;
  129. int remote_view_cy;
  130. int remote_width;
  131. int remote_height;
  132. int local_hwd_move;
  133. int remote_hwd_move;
  134. int local_fresh_time;
  135. int remote_fresh_time;
  136. }ControlVideoCommand_t;
  137. typedef struct VideoRenderCommand_s
  138. {
  139. CSIPPhoneSession* pSIPPhoneSession;
  140. bool bstart;
  141. int local_view_x;
  142. int local_view_y;
  143. int local_view_cx;
  144. int local_view_cy;
  145. int remote_view_x;
  146. int remote_view_y;
  147. int remote_view_cx;
  148. int remote_view_cy;
  149. int local_hwd_move;
  150. int remote_hwd_move;
  151. int local_fresh_time;
  152. int remote_fresh_time;
  153. }VideoRenderCommand_t;
  154. typedef struct HangupCallCommand_s{
  155. CSIPPhoneSession *pSIPPhoneSession;
  156. }HangupCallCommand_t;
  157. struct ChangeDevCommand{
  158. CSIPEntity *pEntity;
  159. int dev_type;
  160. };
  161. class ChannelSipphoneClient : public ChannelService_ClientBase
  162. {
  163. public:
  164. ChannelSipphoneClient(CSIPEntity *pEntity);
  165. virtual void OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData);
  166. virtual void OnMessage(ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData);
  167. };
  168. class CSIPPhoneSession : public PhoneService_ServerSessionBase
  169. {
  170. public:
  171. CSIPPhoneSession(CSIPEntity *pEntity);
  172. virtual void Handle_MakeCall(SpReqAnsContext<PhoneService_MakeCall_Req, PhoneService_MakeCall_Ans>::Pointer ctx);
  173. virtual void Handle_HangupCall(SpReqAnsContext<PhoneService_HangupCall_Req, PhoneService_HangupCall_Ans>::Pointer ctx);
  174. virtual void Handle_StartVideo(SpOnewayCallContext<PhoneService_StartVideo_Info>::Pointer ctx);
  175. virtual void Handle_StopVideo(SpOnewayCallContext<PhoneService_StopVideo_Info>::Pointer ctx);
  176. virtual void Handle_BeginState(SpSubscribeContext<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::Pointer ctx);
  177. virtual void Handle_EndState(SpOnewayCallContext<PhoneService_EndState_Info>::Pointer ctx);
  178. virtual void Handle_ReleaseCall(SpReqAnsContext<PhoneService_ReleaseCall_Req, PhoneService_ReleaseCall_Ans>::Pointer ctx);
  179. virtual void Handle_RealErrorCheck(SpOnewayCallContext<PhoneService_RealErrorCheck_Info>::Pointer ctx);
  180. virtual void Handle_SetCallingParam(SpOnewayCallContext<PhoneService_SetCallingParam_Info>::Pointer ctx);
  181. virtual void OnClose(ErrorCodeEnum eErrorCode);
  182. virtual void Handle_GetHandfreeOutVolume(SpReqAnsContext<PhoneService_GetHandfreeOutVolume_Req, PhoneService_GetHandfreeOutVolume_Ans>::Pointer ctx);
  183. virtual void Handle_SetHandfreeOutVolume(SpReqAnsContext<PhoneService_SetHandfreeOutVolume_Req, PhoneService_SetHandfreeOutVolume_Ans>::Pointer ctx);
  184. virtual void Handle_GetPickupOutVolume(SpReqAnsContext<PhoneService_GetPickupOutVolume_Req, PhoneService_GetPickupOutVolume_Ans>::Pointer ctx);
  185. virtual void Handle_SetPickupOutVolume(SpReqAnsContext<PhoneService_SetPickupOutVolume_Req, PhoneService_SetPickupOutVolume_Ans>::Pointer ctx);
  186. virtual void Handle_StartVideoRender(SpOnewayCallContext<PhoneService_StartVideoRender_Info>::Pointer ctx);
  187. virtual void Handle_StopVideoRender(SpOnewayCallContext<PhoneService_StopVideoRender_Info>::Pointer ctx);
  188. virtual void Handle_GetHandfreeInVolume(SpReqAnsContext<PhoneService_GetHandfreeInVolume_Req, PhoneService_GetHandfreeInVolume_Ans>::Pointer ctx);
  189. virtual void Handle_SetHandfreeInVolume(SpReqAnsContext<PhoneService_SetHandfreeInVolume_Req, PhoneService_SetHandfreeInVolume_Ans>::Pointer ctx);
  190. virtual void Handle_SetPickupInVolume(SpReqAnsContext<PhoneService_SetPickupInVolume_Req, PhoneService_SetPickupInVolume_Ans>::Pointer ctx);
  191. virtual void Handle_GetPickupInVolume(SpReqAnsContext<PhoneService_GetPickupInVolume_Req, PhoneService_GetPickupInVolume_Ans>::Pointer ctx);
  192. virtual void Handle_GetAudioDevices(SpReqAnsContext<PhoneService_GetAudioDevices_Req, PhoneService_GetAudioDevices_Ans>::Pointer ctx);
  193. virtual void Handle_StartCameraRender(SpReqAnsContext<PhoneService_StartCameraRender_Req, PhoneService_StartCameraRender_Ans>::Pointer ctx);
  194. virtual void Handle_StopCameraRender(SpReqAnsContext<PhoneService_StopCameraRender_Req, PhoneService_StopCameraRender_Ans>::Pointer ctx);
  195. virtual void Handle_IsCameraRender(SpReqAnsContext<PhoneService_IsCameraRender_Req, PhoneService_IsCameraRender_Ans>::Pointer ctx);
  196. virtual void Handle_StartBothCameraRender(SpReqAnsContext<PhoneService_StartBothCameraRender_Req, PhoneService_StartBothCameraRender_Ans>::Pointer ctx);
  197. public:
  198. void on_call_state(int state, const char *state_desc, const char *phrase);
  199. int make_call(MakeCallCommand_t *pCmd);
  200. void hangup_call();
  201. void release_call();
  202. void control_video(ControlVideoCommand_t* pCmd);
  203. int on_video_box_move(int imessagetype, int ivideotype, int ileft, int ibottom);
  204. #if defined(RVC_OS_WIN)
  205. #else
  206. void video_render(VideoRenderCommand_t* pCmd);
  207. int start_video_render(rvc_video_render_params_t* render_param, eVideoRenderMode eMode);
  208. int stop_video_render();
  209. #endif //RVC_OS_WIN
  210. public:
  211. int m_iLastState;
  212. private:
  213. SpSubscribeContext<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::Pointer m_spCallbackContext;
  214. endpoint_call_t *m_pCall;
  215. CSIPEntity *m_pEntity;
  216. #if defined(RVC_OS_WIN)
  217. int m_IsLocalPlay;
  218. eShowVideoWindowType m_VideoWindowPlayType;
  219. video_session_callback_t m_cb_video_box_move;
  220. #endif //RVC_OS_WIN
  221. };
  222. class CSIPEntity : public CEntityBase, public ILogListener, public ISysVarListener,public ITimerListener
  223. {
  224. public:
  225. CSIPEntity();
  226. virtual ~CSIPEntity() {}
  227. virtual const char *GetEntityName() const { return "SIPPhone"; }
  228. virtual void OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  229. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  230. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext& pLinkInfo);
  231. virtual void OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName);
  232. virtual void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext);
  233. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext);
  234. virtual void OnStarted();
  235. ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError);
  236. void OnReceivePkt(int type, int sub_type, const char *buffer, int size);
  237. ErrorCodeEnum GetLocalIP();
  238. #if defined(RVC_OS_WIN)
  239. ErrorCodeEnum StartVideoRender();
  240. ErrorCodeEnum StopVideoRender();
  241. #endif //RVC_OS_WIN
  242. //send audio device volume
  243. void SendAudioDeviceVolumn(int nDevice);
  244. ErrorCodeEnum SetHandfreeOutVolume(int iVolume);
  245. ErrorCodeEnum SetPickupOutVolume(int iVolume);
  246. ErrorCodeEnum SetHandfreeInVolume(int iVolume);
  247. ErrorCodeEnum SetPickupInVolume(int iVolume);
  248. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext);
  249. ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError);
  250. virtual void OnPaused();
  251. virtual void OnContinued();
  252. virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszClass*/);
  253. virtual bool IsService()const{return true;}
  254. virtual void OnTimeout(DWORD dwTimerID);
  255. bool IsCurrentSession(CServerSessionBase * pSession) { return m_pCurrentSession == pSession; }
  256. endpoint_t *GetEndpoint() { return m_pEndpoint; }
  257. ErrorCodeEnum InitEndpoint();
  258. void change_dev(int dev_type);
  259. void SwitchHandFree();
  260. void SwitchPickup();
  261. void SetState(int state);
  262. ErrorCodeEnum RealSelfCheck();
  263. CSimpleStringA MakeUri(const char *terminal_id);
  264. void SetMessageBoxFlag(bool bFlag);
  265. void HandleSendBroadcastMsg(bool bHandfreeError);
  266. int StartCameraRender(int icamid, int ivideoview_x, int ivideoview_y, int ivideoview_cx, int ivideoview_cy);
  267. int StopCameraRender();
  268. int StartBothCameraRender(SpReqAnsContext<PhoneService_StartBothCameraRender_Req, PhoneService_StartBothCameraRender_Ans>::Pointer ctx);
  269. private:
  270. ErrorCodeEnum LoadConfig(endpoint_conf_t *conf);
  271. #if defined(RVC_OS_WIN)
  272. eVideoRenderType GetMediaConfig();
  273. #else
  274. void InitFreshTimeConfig();
  275. void HideLocalVideo();
  276. void ShowLocalVideo();
  277. void HideBothVideo();
  278. void ShowBothVideo();
  279. CSimpleStringA GetAudioDeviceJsonInfos(bool bmicro);
  280. #endif //RVC_OS_WIN
  281. void HandleHandfreeAudioDeviceErrorEvent();
  282. //载入运行时配置
  283. ErrorCodeEnum LoadRestartRunConfig(unsigned int& utime);
  284. //保存运行时
  285. ErrorCodeEnum SaveRestartRunConfig(unsigned int utime);
  286. ErrorCodeEnum AudioDspFlagsUseCentersetting(endpoint_conf_t* conf);
  287. //载入运行时配置
  288. ErrorCodeEnum LoadAudioRunConfig(int&nHandfreeout, int&nPickupout, int&nHandfreein, int&nPickupin);
  289. //保存运行时
  290. ErrorCodeEnum SaveAudioRunConfig(int nHandfreeout, int nPickupout, int nHandfreein, int nPickupin);
  291. // we use root.ini Video section config to decide camera count
  292. ErrorCodeEnum DecideScreenCount(int &nCount);
  293. DeviceTypeEnum RvcGetDeviceType();
  294. ErrorCodeEnum RvcGetAudioDeviceInfo();
  295. ErrorCodeEnum RvcSetSaveAudioVolume();
  296. ErrorCodeEnum LoadEntityConfig();
  297. ErrorCodeEnum ConnectAssistChannel();
  298. bool IsPostAudioConfigInfo();
  299. uint32_t CheckAudioDevice();
  300. ErrorCodeEnum SetSoundCardSysVar(const CSimpleStringA& newVal);
  301. void HandleCheckAudioDevice(const char* pszValue);
  302. public:
  303. int m_kept_volume_in[2];
  304. int m_kept_volume_out[2];
  305. IAudioMgr* m_pAudioMgr;
  306. bool m_bIsCameraRender;
  307. #ifdef RVC_OS_WIN
  308. void* m_pKeeperIn[2];
  309. void* m_pKeeperOut[2];
  310. eVideoRenderType m_eVideoRenderType;
  311. #endif
  312. int m_ilocalvideo_freshtime;
  313. int m_iremotevideo_freshtime;
  314. rvc_video_render_t* m_render;
  315. bool m_bAudioMgrInited;
  316. CSimpleStringA m_strStartTime;
  317. CSimpleStringA m_strEndTime;
  318. int m_itervalTime;
  319. bool m_bStopAutoRestart;
  320. CSystemStaticInfo staticInfo;
  321. char m_localip[RVC_MAX_IP_LEN]; //本地ip
  322. endpoint_conf_t conf;
  323. endpoint_t *m_pEndpoint;
  324. int m_iPickupPhoneState;
  325. ErrorCodeEnum m_SipErrorCode;
  326. DeviceTypeEnum m_eDeviceType;
  327. CallingTypeEnum m_nCallType; //呼叫模式,0:可视柜台正常呼叫,1:远程双录
  328. volatile stVideoParam m_stVideoParam;
  329. private:
  330. CServerSessionBase *m_pCurrentSession;
  331. int m_state;
  332. CAutoArray<CUUID> m_arrListener;
  333. ChannelSipphoneClient*m_pSipphoneChannel;
  334. HealthManagerService_ClientBase* m_pHMClient;
  335. bool m_bConnectedAssist;
  336. bool m_bFirstLaunched;
  337. bool m_bMessageBox;
  338. };