mod_sipphone.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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. #ifndef RVC_AUDIO_IN_DEVICE_COUNT
  45. #define RVC_AUDIO_IN_DEVICE_COUNT 2
  46. #endif // !RVC_AUDIO_IN_DEVICE_COUNT
  47. #ifndef RVC_AUDIO_OUT_DEVICE_COUNT
  48. #define RVC_AUDIO_OUT_DEVICE_COUNT 2
  49. #endif // !RVC_AUDIO_OUT_DEVICE_COUNT
  50. class CSIPEntity;
  51. class CSIPPhoneSession;
  52. struct CVolumnValue
  53. {
  54. int nValue;
  55. void Serialize(SpBuffer &Buf)
  56. {
  57. Buf & nValue;
  58. }
  59. };
  60. struct CFpsValue
  61. {
  62. int nValue;
  63. void Serialize(SpBuffer &Buf)
  64. {
  65. Buf & nValue;
  66. }
  67. };
  68. struct stVideoParam
  69. {
  70. int nWindowState; //视频窗口显示状态,0:正常大小显示,1:放大一倍显示,2:隐藏全部窗口,3:从隐藏状态恢复为全部显示,4:显示远程窗口,隐藏本地窗口, 5:缩放显示
  71. int bShowActiveImg; //活体检测显示图片
  72. int bActiveInspect; //是否启动活体检测
  73. int iActiveCamera; // set by facetracking
  74. int iCameraSwitch; // set by agent and camerastate
  75. int nUpDynamicFps; // 当前视频上行的帧频,由后端通知前端更改频率,只有移动版才使用
  76. int iCameraState; // set by agent and camerastate
  77. int bShowPersonArea; //是否显示人形框
  78. int bShowRecordArea; //是否显示录像人形轮廓
  79. };
  80. //record video echo location
  81. typedef struct record_echo_location_s{
  82. int x;
  83. int y;
  84. int width;
  85. int height;
  86. }record_echo_location_t;
  87. enum ePickupMicrophoneState
  88. {
  89. ePickupMicrophoneState_On,
  90. ePickupMicrophoneState_Off,
  91. };
  92. /* 0:online local and remote video window, 1:only local video window, 2:both local and remote window */
  93. enum eShowVideoWindowType{
  94. eOnline_Mode_Video,
  95. eOnly_Local_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. CSimpleStringA strmappedip;
  113. int iaudio_port;
  114. int imapped_audio_port;
  115. int ivideo_port;
  116. int imapped_video_port;
  117. }MakeCallCommand_t;
  118. struct ControlVideoCommand {
  119. CSIPPhoneSession *pSIPPhoneSession;
  120. int start;
  121. unsigned long local_ip;
  122. int local_port;
  123. unsigned long remote_ip;
  124. int remote_port;
  125. int local_view_x;
  126. int local_view_y;
  127. int local_view_cx;
  128. int local_view_cy;
  129. int remote_view_x;
  130. int remote_view_y;
  131. int remote_view_cx;
  132. int remote_view_cy;
  133. int remote_width;
  134. int remote_height;
  135. int local_hwd_move;
  136. int remote_hwd_move;
  137. int local_fresh_time;
  138. int remote_fresh_time;
  139. };
  140. typedef struct VideoRenderCommand_s
  141. {
  142. CSIPPhoneSession* pSIPPhoneSession;
  143. bool bstart;
  144. int local_view_x;
  145. int local_view_y;
  146. int local_view_cx;
  147. int local_view_cy;
  148. int remote_view_x;
  149. int remote_view_y;
  150. int remote_view_cx;
  151. int remote_view_cy;
  152. int local_hwd_move;
  153. int remote_hwd_move;
  154. int local_fresh_time;
  155. int remote_fresh_time;
  156. }VideoRenderCommand_t;
  157. struct HangupCallCommand{
  158. CSIPPhoneSession *pSIPPhoneSession;
  159. CSimpleStringA strSession_num;
  160. CSimpleStringA strBranch_server_ip;
  161. int iBranch_server_port;
  162. };
  163. struct ChangeDevCommand{
  164. CSIPEntity *pEntity;
  165. int dev_type;
  166. };
  167. class ChannelSipphoneClient : public ChannelService_ClientBase
  168. {
  169. public:
  170. ChannelSipphoneClient(CSIPEntity *pEntity);
  171. virtual void OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData);
  172. virtual void OnMessage(ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData);
  173. };
  174. class CSIPPhoneSession : public PhoneService_ServerSessionBase
  175. {
  176. public:
  177. CSIPPhoneSession(CSIPEntity *pEntity);
  178. virtual void Handle_MakeCall(SpReqAnsContext<PhoneService_MakeCall_Req, PhoneService_MakeCall_Ans>::Pointer ctx);
  179. virtual void Handle_HangupCall(SpReqAnsContext<PhoneService_HangupCall_Req, PhoneService_HangupCall_Ans>::Pointer ctx);
  180. virtual void Handle_StartVideo(SpOnewayCallContext<PhoneService_StartVideo_Info>::Pointer ctx);
  181. virtual void Handle_StopVideo(SpOnewayCallContext<PhoneService_StopVideo_Info>::Pointer ctx);
  182. virtual void Handle_BeginState(SpSubscribeContext<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::Pointer ctx);
  183. virtual void Handle_EndState(SpOnewayCallContext<PhoneService_EndState_Info>::Pointer ctx);
  184. virtual void Handle_ReleaseCall(SpReqAnsContext<PhoneService_ReleaseCall_Req, PhoneService_ReleaseCall_Ans>::Pointer ctx);
  185. virtual void Handle_RealErrorCheck(SpOnewayCallContext<PhoneService_RealErrorCheck_Info>::Pointer ctx);
  186. virtual void Handle_SetCallingParam(SpOnewayCallContext<PhoneService_SetCallingParam_Info>::Pointer ctx);
  187. virtual void OnClose(ErrorCodeEnum eErrorCode);
  188. virtual void Handle_GetHandfreeOutVolume(SpReqAnsContext<PhoneService_GetHandfreeOutVolume_Req, PhoneService_GetHandfreeOutVolume_Ans>::Pointer ctx);
  189. virtual void Handle_SetHandfreeOutVolume(SpReqAnsContext<PhoneService_SetHandfreeOutVolume_Req, PhoneService_SetHandfreeOutVolume_Ans>::Pointer ctx);
  190. virtual void Handle_GetPickupOutVolume(SpReqAnsContext<PhoneService_GetPickupOutVolume_Req, PhoneService_GetPickupOutVolume_Ans>::Pointer ctx);
  191. virtual void Handle_SetPickupOutVolume(SpReqAnsContext<PhoneService_SetPickupOutVolume_Req, PhoneService_SetPickupOutVolume_Ans>::Pointer ctx);
  192. virtual void Handle_StartVideoRender(SpOnewayCallContext<PhoneService_StartVideoRender_Info>::Pointer ctx);
  193. virtual void Handle_StopVideoRender(SpOnewayCallContext<PhoneService_StopVideoRender_Info>::Pointer ctx);
  194. virtual void Handle_GetHandfreeInVolume(SpReqAnsContext<PhoneService_GetHandfreeInVolume_Req, PhoneService_GetHandfreeInVolume_Ans>::Pointer ctx);
  195. virtual void Handle_SetHandfreeInVolume(SpReqAnsContext<PhoneService_SetHandfreeInVolume_Req, PhoneService_SetHandfreeInVolume_Ans>::Pointer ctx);
  196. virtual void Handle_SetPickupInVolume(SpReqAnsContext<PhoneService_SetPickupInVolume_Req, PhoneService_SetPickupInVolume_Ans>::Pointer ctx);
  197. virtual void Handle_GetPickupInVolume(SpReqAnsContext<PhoneService_GetPickupInVolume_Req, PhoneService_GetPickupInVolume_Ans>::Pointer ctx);
  198. virtual void Handle_GetAudioDevices(SpReqAnsContext<PhoneService_GetAudioDevices_Req, PhoneService_GetAudioDevices_Ans>::Pointer ctx);
  199. public:
  200. void on_call_state(int state, const char *state_desc, const char *phrase);
  201. int make_call(MakeCallCommand_t *pCmd);
  202. void hangup_call(HangupCallCommand *pCmd);
  203. void release_call();
  204. void control_video(ControlVideoCommand* pCmd);
  205. int on_video_box_move(int imessagetype, int ivideotype, int ileft, int ibottom);
  206. #if defined(RVC_OS_WIN)
  207. #else
  208. void video_render(VideoRenderCommand_t* pCmd);
  209. int start_video_render(rvc_video_render_params_t* render_param, bool bremote);
  210. int stop_video_render();
  211. #endif //RVC_OS_WIN
  212. public:
  213. int m_iLastState;
  214. private:
  215. SpSubscribeContext<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::Pointer m_spCallbackContext;
  216. endpoint_call_t *m_pCall;
  217. CSIPEntity *m_pEntity;
  218. #if defined(RVC_OS_WIN)
  219. int m_IsLocalPlay;
  220. eShowVideoWindowType m_VideoWindowPlayType;
  221. video_session_callback_t m_cb_video_box_move;
  222. #endif //RVC_OS_WIN
  223. };
  224. class CSIPEntity : public CEntityBase, public ILogListener, public ISysVarListener,public ITimerListener
  225. {
  226. public:
  227. CSIPEntity();
  228. virtual ~CSIPEntity() {}
  229. virtual const char *GetEntityName() const { return "SIPPhone"; }
  230. virtual void OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  231. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  232. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext& pLinkInfo);
  233. virtual void OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName);
  234. virtual void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext);
  235. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext);
  236. virtual void OnStarted();
  237. ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError);
  238. void OnReceivePkt(int type, int sub_type, const char *buffer, int size);
  239. ErrorCodeEnum GetLocalIP();
  240. #if defined(RVC_OS_WIN)
  241. ErrorCodeEnum StartVideoRender();
  242. ErrorCodeEnum StopVideoRender();
  243. #endif //RVC_OS_WIN
  244. //send audio device volume
  245. void SendAudioDeviceVolumn(int nDevice);
  246. ErrorCodeEnum SetHandfreeOutVolume(int iVolume);
  247. ErrorCodeEnum SetPickupOutVolume(int iVolume);
  248. ErrorCodeEnum SetHandfreeInVolume(int iVolume);
  249. ErrorCodeEnum SetPickupInVolume(int iVolume);
  250. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext);
  251. ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError);
  252. virtual void OnPaused();
  253. virtual void OnContinued();
  254. virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszClass*/);
  255. virtual bool IsService()const{return true;}
  256. virtual void OnTimeout(DWORD dwTimerID);
  257. bool IsCurrentSession(CServerSessionBase * pSession) { return m_pCurrentSession == pSession; }
  258. endpoint_t *GetEndpoint() { return m_pEndpoint; }
  259. ErrorCodeEnum InitEndpoint();
  260. void change_dev(int dev_type);
  261. void SwitchHandFree();
  262. void SwitchPickup();
  263. void SetState(int state);
  264. ErrorCodeEnum RealSelfCheck();
  265. CSimpleStringA MakeUri(const char *terminal_id);
  266. void Handle_RecordVideoLocation_Info(const char* pszMessage);
  267. void Handle_AdjustVideoEchoEvent(const char* pszMessage);
  268. private:
  269. ErrorCodeEnum LoadConfig(endpoint_conf_t *conf);
  270. #if defined(RVC_OS_WIN)
  271. eVideoRenderType GetMediaConfig();
  272. void HandleAudioDeviceErrorEvent();
  273. //载入运行时配置
  274. ErrorCodeEnum LoadRestartRunConfig(unsigned int& utime);
  275. //保存运行时
  276. ErrorCodeEnum SaveRestartRunConfig(unsigned int utime);
  277. #else
  278. void InitFreshTimeConfig();
  279. void HideLocalVideo();
  280. void ShowLocalVideo();
  281. void HideBothVideo();
  282. void ShowBothVideo();
  283. #endif //RVC_OS_WIN
  284. ErrorCodeEnum AudioDspFlagsUseCentersetting(endpoint_conf_t* conf);
  285. //载入运行时配置
  286. ErrorCodeEnum LoadAudioRunConfig(int&nHandfreeout,int&nPickupout,int&nHandfreein,int&nPickupin);
  287. //保存运行时
  288. ErrorCodeEnum SaveAudioRunConfig(int nHandfreeout,int nPickupout,int nHandfreein,int nPickupin);
  289. // we use root.ini Video section config to decide camera count
  290. ErrorCodeEnum DecideScreenCount(int &nCount);
  291. DeviceTypeEnum RvcGetDeviceType();
  292. ErrorCodeEnum RvcGetAudioDeviceInfo();
  293. ErrorCodeEnum RvcSetSaveAudioVolume();
  294. //eVideoRenderType GetMediaConfig();
  295. ErrorCodeEnum LoadEntityConfig();
  296. ErrorCodeEnum ConnectAssistChannel();
  297. bool IsPostAudioConfigInfo();
  298. public:
  299. int m_kept_volume_in[2];
  300. int m_kept_volume_out[2];
  301. IAudioMgr* m_pAudioMgr;
  302. #ifdef RVC_OS_WIN
  303. void* m_pKeeperIn[2];
  304. void* m_pKeeperOut[2];
  305. eVideoRenderType m_eVideoRenderType;
  306. bool m_bAudioMgrInited;
  307. int m_AudioStopType;
  308. int m_iCapType;
  309. CSimpleStringA m_strHandfreeIn;
  310. CSimpleStringA m_strHandfreeOut;
  311. CSimpleStringA m_strPickUpIn;
  312. CSimpleStringA m_strPickUpOut;
  313. CSimpleStringA m_strStartTime;
  314. CSimpleStringA m_strEndTime;
  315. int m_itervalTime;
  316. BOOL m_bStopAutoRestart;
  317. int m_iAudioDspUseCenter;
  318. #else
  319. int m_ilocalvideo_freshtime;
  320. int m_iremotevideo_freshtime;
  321. rvc_video_render_t* m_render;
  322. int m_iAudioDspUseCenter;
  323. #endif
  324. CSystemStaticInfo staticInfo;
  325. char m_localip[RVC_MAX_IP_LEN]; //本地ip
  326. endpoint_conf_t conf;
  327. endpoint_t *m_pEndpoint;
  328. int m_iPickupPhoneState;
  329. ErrorCodeEnum m_SipErrorCode;
  330. DeviceTypeEnum m_eDeviceType;
  331. CallingTypeEnum m_nCallType; //呼叫模式,0:可视柜台正常呼叫,1:PAD主动外呼,2:PAD被动呼叫,来源PAD,3:PAD被动呼叫,来源手机端
  332. int m_nSysCallType; //0:普通模式,1:p2p模式
  333. volatile stVideoParam m_stVideoParam;
  334. record_echo_location_t m_RecordVideoLocation;
  335. private:
  336. CServerSessionBase *m_pCurrentSession;
  337. int m_state;
  338. CAutoArray<CUUID> m_arrListener;
  339. ChannelSipphoneClient*m_pSipphoneChannel;
  340. HealthManagerService_ClientBase* m_pHMClient;
  341. bool m_bConnectedAssist;
  342. };