mod_sipphone.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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. #include "iaudiomgrinterface.h"
  11. #else
  12. #include "video_render.h"
  13. #include "Event.h"
  14. #include "EventCode.h"
  15. #endif //RVC_OS_WIN
  16. #include "HealthManager_client_g.h"
  17. #include "HealthManager_def_g.h"
  18. using namespace HealthManager;
  19. #include "mod_assistantchannel/chan_protocol.h"
  20. #include "mod_assistantchannel/AssistantChannel_client_g.h"
  21. using namespace AssistantChannel;
  22. #include "iaudiomgrinterface.h"
  23. #ifndef RVC_DEFAULT_STUNSERVER
  24. #define RVC_DEFAULT_STUNSERVER "rvcpad.cmbchina.com"
  25. #endif
  26. #ifndef RVC_DEFAULT_STUNPORT
  27. #define RVC_DEFAULT_STUNPORT "3478"
  28. #endif
  29. #ifndef RVC_STUN_TIMEOUT
  30. #define RVC_STUN_TIMEOUT 5000
  31. #endif
  32. #ifndef MAX_LOG_LEN
  33. #define MAX_LOG_LEN 512
  34. #endif
  35. #ifndef RVC_START_TIME
  36. #define RVC_START_TIME "00:00:00"
  37. #endif // !RVC_START_TIME
  38. #ifndef RVC_END_TIME
  39. #define RVC_END_TIME "08:00:00"
  40. #endif // !RVC_END_TIME
  41. #ifndef RVC_INTERVAL_TIME
  42. #define RVC_INTERVAL_TIME 3*60
  43. #endif // ! RVC_INTERVAL_TIME
  44. class CSIPEntity;
  45. class CSIPPhoneSession;
  46. struct CVolumnValue
  47. {
  48. int nValue;
  49. void Serialize(SpBuffer &Buf)
  50. {
  51. Buf & nValue;
  52. }
  53. };
  54. struct CFpsValue
  55. {
  56. int nValue;
  57. void Serialize(SpBuffer &Buf)
  58. {
  59. Buf & nValue;
  60. }
  61. };
  62. struct stVideoParam
  63. {
  64. int nWindowState; //视频窗口显示状态,0:正常大小显示,1:放大一倍显示,2:隐藏全部窗口,3:从隐藏状态恢复为全部显示,4:显示远程窗口,隐藏本地窗口, 5:缩放显示
  65. int bShowActiveImg; //活体检测显示图片
  66. int bActiveInspect; //是否启动活体检测
  67. int iActiveCamera; // set by facetracking
  68. int iCameraSwitch; // set by agent and camerastate
  69. int nUpDynamicFps; // 当前视频上行的帧频,由后端通知前端更改频率,只有移动版才使用
  70. int iCameraState; // set by agent and camerastate
  71. int bShowPersonArea; //是否显示人形框
  72. int bShowRecordArea; //是否显示录像人形轮廓
  73. };
  74. //record video echo location
  75. typedef struct record_echo_location_s{
  76. int x;
  77. int y;
  78. int width;
  79. int height;
  80. }record_echo_location_t;
  81. enum ePickupMicrophoneState
  82. {
  83. ePickupMicrophoneState_On,
  84. ePickupMicrophoneState_Off,
  85. };
  86. /* 0:online local and remote video window, 1:only local video window, 2:both local and remote window */
  87. enum eShowVideoWindowType{
  88. eOnline_Mode_Video,
  89. eOnly_Local_Video,
  90. eBoth_Local_Remote_Video
  91. };
  92. enum eVideoRenderType{
  93. eGDI,
  94. eSDL
  95. };
  96. static const char* VideoRender_Type_Table[] = {
  97. "eGDI",
  98. "eSDL"
  99. };
  100. typedef struct MakeCallCommand_s {
  101. CSIPPhoneSession *pSIPPhoneSession;
  102. CSimpleStringA toUri;
  103. CSimpleStringA fromUri;
  104. CSimpleStringA callId;
  105. CSimpleStringA strlocalip;
  106. CSimpleStringA strmappedip;
  107. int iaudio_port;
  108. int imapped_audio_port;
  109. int ivideo_port;
  110. int imapped_video_port;
  111. }MakeCallCommand_t;
  112. struct ControlVideoCommand {
  113. CSIPPhoneSession *pSIPPhoneSession;
  114. int start;
  115. unsigned long local_ip;
  116. int local_port;
  117. unsigned long remote_ip;
  118. int remote_port;
  119. int local_view_x;
  120. int local_view_y;
  121. int local_view_cx;
  122. int local_view_cy;
  123. int remote_view_x;
  124. int remote_view_y;
  125. int remote_view_cx;
  126. int remote_view_cy;
  127. int remote_width;
  128. int remote_height;
  129. int local_hwd_move;
  130. int remote_hwd_move;
  131. int local_fresh_time;
  132. int remote_fresh_time;
  133. };
  134. typedef struct VideoRenderCommand_s
  135. {
  136. CSIPPhoneSession* pSIPPhoneSession;
  137. bool bstart;
  138. int local_view_x;
  139. int local_view_y;
  140. int local_view_cx;
  141. int local_view_cy;
  142. int remote_view_x;
  143. int remote_view_y;
  144. int remote_view_cx;
  145. int remote_view_cy;
  146. int local_hwd_move;
  147. int remote_hwd_move;
  148. int local_fresh_time;
  149. int remote_fresh_time;
  150. }VideoRenderCommand_t;
  151. struct HangupCallCommand{
  152. CSIPPhoneSession *pSIPPhoneSession;
  153. CSimpleStringA strSession_num;
  154. CSimpleStringA strBranch_server_ip;
  155. int iBranch_server_port;
  156. };
  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. public:
  194. void on_call_state(int state, const char *state_desc, const char *phrase);
  195. int make_call(MakeCallCommand_t *pCmd);
  196. void hangup_call(HangupCallCommand *pCmd);
  197. void release_call();
  198. void control_video(ControlVideoCommand* pCmd);
  199. int on_video_box_move(int imessagetype, int ivideotype, int ileft, int ibottom);
  200. #if defined(RVC_OS_WIN)
  201. #else
  202. void video_render(VideoRenderCommand_t* pCmd);
  203. int start_video_render(rvc_video_render_params_t* render_param, bool bremote);
  204. int stop_video_render();
  205. #endif //RVC_OS_WIN
  206. public:
  207. int m_iLastState;
  208. private:
  209. SpSubscribeContext<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::Pointer m_spCallbackContext;
  210. endpoint_call_t *m_pCall;
  211. CSIPEntity *m_pEntity;
  212. #if defined(RVC_OS_WIN)
  213. int m_IsLocalPlay;
  214. eShowVideoWindowType m_VideoWindowPlayType;
  215. video_session_callback_t m_cb_video_box_move;
  216. #endif //RVC_OS_WIN
  217. };
  218. class CSIPEntity : public CEntityBase, public ILogListener, public ISysVarListener,public ITimerListener
  219. {
  220. public:
  221. CSIPEntity();
  222. virtual ~CSIPEntity() {}
  223. virtual const char *GetEntityName() const { return "SIPPhone"; }
  224. virtual void OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  225. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  226. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext& pLinkInfo);
  227. virtual void OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName);
  228. virtual void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext);
  229. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext);
  230. virtual void OnStarted();
  231. ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError);
  232. void OnReceivePkt(int type, int sub_type, const char *buffer, int size);
  233. ErrorCodeEnum GetLocalIP();
  234. #if defined(RVC_OS_WIN)
  235. ErrorCodeEnum StartVideoRender();
  236. ErrorCodeEnum StopVideoRender();
  237. #endif //RVC_OS_WIN
  238. //send audio device volume
  239. void SendAudioDeviceVolumn(int nDevice);
  240. ErrorCodeEnum SetHandfreeOutVolume(int iVolume);
  241. ErrorCodeEnum SetPickupOutVolume(int iVolume);
  242. ErrorCodeEnum SetHandfreeInVolume(int iVolume);
  243. ErrorCodeEnum SetPickupInVolume(int iVolume);
  244. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext);
  245. ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError);
  246. virtual void OnPaused();
  247. virtual void OnContinued();
  248. virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszClass*/);
  249. virtual bool IsService()const{return true;}
  250. virtual void OnTimeout(DWORD dwTimerID);
  251. bool IsCurrentSession(CServerSessionBase * pSession) { return m_pCurrentSession == pSession; }
  252. endpoint_t *GetEndpoint() { return m_pEndpoint; }
  253. ErrorCodeEnum InitEndpoint();
  254. void change_dev(int dev_type);
  255. void SwitchHandFree();
  256. void SwitchPickup();
  257. void SetState(int state);
  258. ErrorCodeEnum RealSelfCheck();
  259. CSimpleStringA MakeUri(const char *terminal_id);
  260. void Handle_RecordVideoLocation_Info(const char* pszMessage);
  261. void Handle_AdjustVideoEchoEvent(const char* pszMessage);
  262. private:
  263. ErrorCodeEnum LoadConfig(endpoint_conf_t *conf);
  264. #if defined(RVC_OS_WIN)
  265. eVideoRenderType GetMediaConfig();
  266. void HandleAudioDeviceErrorEvent();
  267. //载入运行时配置
  268. ErrorCodeEnum LoadRestartRunConfig(unsigned int& utime);
  269. //保存运行时
  270. ErrorCodeEnum SaveRestartRunConfig(unsigned int utime);
  271. #else
  272. void InitFreshTimeConfig();
  273. void HideLocalVideo();
  274. void ShowLocalVideo();
  275. void HideBothVideo();
  276. void ShowBothVideo();
  277. #endif //RVC_OS_WIN
  278. ErrorCodeEnum AudioDspFlagsUseCentersetting(endpoint_conf_t* conf);
  279. //载入运行时配置
  280. ErrorCodeEnum LoadAudioRunConfig(int&nHandfreeout,int&nPickupout,int&nHandfreein,int&nPickupin);
  281. //保存运行时
  282. ErrorCodeEnum SaveAudioRunConfig(int nHandfreeout,int nPickupout,int nHandfreein,int nPickupin);
  283. // we use root.ini Video section config to decide camera count
  284. ErrorCodeEnum DecideScreenCount(int &nCount);
  285. DeviceTypeEnum RvcGetDeviceType();
  286. ErrorCodeEnum RvcGetAudioDeviceInfo();
  287. ErrorCodeEnum RvcSetSaveAudioVolume();
  288. //eVideoRenderType GetMediaConfig();
  289. ErrorCodeEnum LoadEntityConfig();
  290. ErrorCodeEnum ConnectAssistChannel();
  291. bool IsPostAudioConfigInfo();
  292. public:
  293. int m_kept_volume_in[2];
  294. int m_kept_volume_out[2];
  295. IAudioMgr* m_pAudioMgr;
  296. #ifdef RVC_OS_WIN
  297. void* m_pKeeperIn[2];
  298. void* m_pKeeperOut[2];
  299. eVideoRenderType m_eVideoRenderType;
  300. CSimpleStringA m_strStunServer;
  301. CSimpleStringA m_strStunPort;
  302. int m_iStunTimeOut;
  303. BOOL m_bStunFlag;
  304. BOOL m_bAudioMgrInited;
  305. int m_AudioStopType;
  306. int m_iCapType;
  307. CSimpleStringA m_strHandfreeIn;
  308. CSimpleStringA m_strHandfreeOut;
  309. CSimpleStringA m_strPickUpIn;
  310. CSimpleStringA m_strPickUpOut;
  311. CSimpleStringA m_strStartTime;
  312. CSimpleStringA m_strEndTime;
  313. int m_itervalTime;
  314. BOOL m_bStopAutoRestart;
  315. int m_iAudioDspUseCenter;
  316. #else
  317. int m_ilocalvideo_freshtime;
  318. int m_iremotevideo_freshtime;
  319. rvc_video_render_t* m_render;
  320. int m_iAudioDspUseCenter;
  321. #endif
  322. CSystemStaticInfo staticInfo;
  323. char m_localip[RVC_MAX_IP_LEN]; //本地ip
  324. endpoint_conf_t conf;
  325. endpoint_t *m_pEndpoint;
  326. int m_iPickupPhoneState;
  327. ErrorCodeEnum m_SipErrorCode;
  328. DeviceTypeEnum m_eDeviceType;
  329. CallingTypeEnum m_nCallType; //呼叫模式,0:可视柜台正常呼叫,1:PAD主动外呼,2:PAD被动呼叫,来源PAD,3:PAD被动呼叫,来源手机端
  330. int m_nSysCallType; //0:普通模式,1:p2p模式
  331. volatile stVideoParam m_stVideoParam;
  332. record_echo_location_t m_RecordVideoLocation;
  333. private:
  334. CServerSessionBase *m_pCurrentSession;
  335. int m_state;
  336. CAutoArray<CUUID> m_arrListener;
  337. ChannelSipphoneClient*m_pSipphoneChannel;
  338. HealthManagerService_ClientBase* m_pHMClient;
  339. BOOL m_bConnectedAssist;
  340. };