mod_sipphone.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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 "SelfChecker_client_g.h"
  17. #include "SelfChecker_def_g.h"
  18. using namespace SelfChecker;
  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 SelfChekerClient:public SelfCheckerService_ClientBase
  162. {
  163. public:
  164. SelfChekerClient(CSIPEntity*pEntity);
  165. };
  166. class ChannelSipphoneClient : public ChannelService_ClientBase
  167. {
  168. public:
  169. ChannelSipphoneClient(CSIPEntity *pEntity);
  170. virtual void OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData);
  171. virtual void OnMessage(ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData);
  172. };
  173. class CSIPPhoneSession : public PhoneService_ServerSessionBase
  174. {
  175. public:
  176. CSIPPhoneSession(CSIPEntity *pEntity);
  177. virtual void Handle_MakeCall(SpReqAnsContext<PhoneService_MakeCall_Req, PhoneService_MakeCall_Ans>::Pointer ctx);
  178. virtual void Handle_HangupCall(SpReqAnsContext<PhoneService_HangupCall_Req, PhoneService_HangupCall_Ans>::Pointer ctx);
  179. virtual void Handle_StartVideo(SpOnewayCallContext<PhoneService_StartVideo_Info>::Pointer ctx);
  180. virtual void Handle_StopVideo(SpOnewayCallContext<PhoneService_StopVideo_Info>::Pointer ctx);
  181. virtual void Handle_BeginState(SpSubscribeContext<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::Pointer ctx);
  182. virtual void Handle_EndState(SpOnewayCallContext<PhoneService_EndState_Info>::Pointer ctx);
  183. virtual void Handle_ReleaseCall(SpReqAnsContext<PhoneService_ReleaseCall_Req, PhoneService_ReleaseCall_Ans>::Pointer ctx);
  184. virtual void Handle_RealErrorCheck(SpOnewayCallContext<PhoneService_RealErrorCheck_Info>::Pointer ctx);
  185. virtual void Handle_SetCallingParam(SpOnewayCallContext<PhoneService_SetCallingParam_Info>::Pointer ctx);
  186. virtual void OnClose(ErrorCodeEnum eErrorCode);
  187. virtual void Handle_GetHandfreeOutVolume(SpReqAnsContext<PhoneService_GetHandfreeOutVolume_Req, PhoneService_GetHandfreeOutVolume_Ans>::Pointer ctx);
  188. virtual void Handle_SetHandfreeOutVolume(SpReqAnsContext<PhoneService_SetHandfreeOutVolume_Req, PhoneService_SetHandfreeOutVolume_Ans>::Pointer ctx);
  189. virtual void Handle_GetPickupOutVolume(SpReqAnsContext<PhoneService_GetPickupOutVolume_Req, PhoneService_GetPickupOutVolume_Ans>::Pointer ctx);
  190. virtual void Handle_SetPickupOutVolume(SpReqAnsContext<PhoneService_SetPickupOutVolume_Req, PhoneService_SetPickupOutVolume_Ans>::Pointer ctx);
  191. virtual void Handle_StartVideoRender(SpOnewayCallContext<PhoneService_StartVideoRender_Info>::Pointer ctx);
  192. virtual void Handle_StopVideoRender(SpOnewayCallContext<PhoneService_StopVideoRender_Info>::Pointer ctx);
  193. virtual void Handle_GetHandfreeInVolume(SpReqAnsContext<PhoneService_GetHandfreeInVolume_Req, PhoneService_GetHandfreeInVolume_Ans>::Pointer ctx);
  194. virtual void Handle_SetHandfreeInVolume(SpReqAnsContext<PhoneService_SetHandfreeInVolume_Req, PhoneService_SetHandfreeInVolume_Ans>::Pointer ctx);
  195. virtual void Handle_SetPickupInVolume(SpReqAnsContext<PhoneService_SetPickupInVolume_Req, PhoneService_SetPickupInVolume_Ans>::Pointer ctx);
  196. virtual void Handle_GetPickupInVolume(SpReqAnsContext<PhoneService_GetPickupInVolume_Req, PhoneService_GetPickupInVolume_Ans>::Pointer ctx);
  197. virtual void Handle_GetAudioDevices(SpReqAnsContext<PhoneService_GetAudioDevices_Req, PhoneService_GetAudioDevices_Ans>::Pointer ctx);
  198. public:
  199. void on_call_state(int state, const char *state_desc, const char *phrase);
  200. int make_call(MakeCallCommand_t *pCmd);
  201. void hangup_call(HangupCallCommand *pCmd);
  202. void release_call();
  203. void control_video(ControlVideoCommand* pCmd);
  204. int on_video_box_move(int imessagetype, int ivideotype, int ileft, int ibottom);
  205. #if defined(RVC_OS_WIN)
  206. ErrorCodeEnum get_nat_mapped_info(char* strmapip, size_t ulen, int* ivideo_map_port, int* iaudio_map_port, int ivideo_port, int iaudio_port);
  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 LoadStunConfig();
  242. ErrorCodeEnum StartVideoRender();
  243. ErrorCodeEnum StopVideoRender();
  244. BOOL GetStunFlag();
  245. void SetStunFlag(BOOL bFlag);
  246. int GetIpByDomain(char* poutput, size_t ulen, const char* pinput);
  247. #endif //RVC_OS_WIN
  248. //send DynamicFps
  249. void SendDynamicFps(int nFps);
  250. //send audio device volume
  251. void SendAudioDeviceVolumn(int nDevice);
  252. ErrorCodeEnum SetHandfreeOutVolume(int iVolume);
  253. ErrorCodeEnum SetPickupOutVolume(int iVolume);
  254. ErrorCodeEnum SetHandfreeInVolume(int iVolume);
  255. ErrorCodeEnum SetPickupInVolume(int iVolume);
  256. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext);
  257. ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError);
  258. virtual void OnPaused();
  259. virtual void OnContinued();
  260. virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszClass*/);
  261. virtual bool IsService()const{return true;}
  262. virtual void OnTimeout(DWORD dwTimerID);
  263. bool IsCurrentSession(CServerSessionBase * pSession) { return m_pCurrentSession == pSession; }
  264. endpoint_t *GetEndpoint() { return m_pEndpoint; }
  265. ErrorCodeEnum InitEndpoint();
  266. void change_dev(int dev_type);
  267. void SwitchHandFree();
  268. void SwitchPickup();
  269. void SetState(int state);
  270. ErrorCodeEnum RealSelfCheck();
  271. CSimpleStringA MakeUri(const char *terminal_id);
  272. void Handle_RecordVideoLocation_Info(const char* pszMessage);
  273. void Handle_AdjustVideoEchoEvent(const char* pszMessage);
  274. private:
  275. ErrorCodeEnum LoadConfig(endpoint_conf_t *conf);
  276. #if defined(RVC_OS_WIN)
  277. eVideoRenderType GetMediaConfig();
  278. void UpdateAudioConfig();
  279. void HandleAudioDeviceErrorEvent();
  280. ErrorCodeEnum AutoCorrectAudioConfig();
  281. //载入运行时配置
  282. ErrorCodeEnum LoadRestartRunConfig(unsigned int& utime);
  283. //保存运行时
  284. ErrorCodeEnum SaveRestartRunConfig(unsigned int utime);
  285. #else
  286. void InitFreshTimeConfig();
  287. void HideLocalVideo();
  288. void ShowLocalVideo();
  289. void HideBothVideo();
  290. void ShowBothVideo();
  291. #endif //RVC_OS_WIN
  292. ErrorCodeEnum AudioDspFlagsUseCentersetting(endpoint_conf_t* conf);
  293. //载入运行时配置
  294. ErrorCodeEnum LoadAudioRunConfig(int&nHandfreeout,int&nPickupout,int&nHandfreein,int&nPickupin);
  295. //保存运行时
  296. ErrorCodeEnum SaveAudioRunConfig(int nHandfreeout,int nPickupout,int nHandfreein,int nPickupin);
  297. // we use root.ini Video section config to decide camera count
  298. ErrorCodeEnum DecideCameraCount(int &nCount);
  299. ErrorCodeEnum DecideScreenCount(int &nCount);
  300. DeviceTypeEnum RvcGetDeviceType();
  301. ErrorCodeEnum RvcGetAudioDeviceInfo();
  302. ErrorCodeEnum RvcSetSaveAudioVolume();
  303. //eVideoRenderType GetMediaConfig();
  304. ErrorCodeEnum LoadEntityConfig();
  305. ErrorCodeEnum ConnectAssistChannel();
  306. bool IsPostAudioConfigInfo();
  307. public:
  308. int m_kept_volume_in[2];
  309. int m_kept_volume_out[2];
  310. IAudioMgr* m_pAudioMgr;
  311. #ifdef RVC_OS_WIN
  312. void* m_pKeeperIn[2];
  313. void* m_pKeeperOut[2];
  314. eVideoRenderType m_eVideoRenderType;
  315. CSimpleStringA m_strStunServer;
  316. CSimpleStringA m_strStunPort;
  317. int m_iStunTimeOut;
  318. BOOL m_bStunFlag;
  319. BOOL m_bAudioMgrInited;
  320. int m_AudioStopType;
  321. int m_iCapType;
  322. CSimpleStringA m_strHandfreeIn;
  323. CSimpleStringA m_strHandfreeOut;
  324. CSimpleStringA m_strPickUpIn;
  325. CSimpleStringA m_strPickUpOut;
  326. CSimpleStringA m_strStartTime;
  327. CSimpleStringA m_strEndTime;
  328. int m_itervalTime;
  329. BOOL m_bStopAutoRestart;
  330. int m_iAudioDspUseCenter;
  331. #else
  332. int m_ilocalvideo_freshtime;
  333. int m_iremotevideo_freshtime;
  334. rvc_video_render_t* m_render;
  335. int m_iAudioDspUseCenter;
  336. #endif
  337. CSystemStaticInfo staticInfo;
  338. char m_localip[RVC_MAX_IP_LEN]; //本地ip
  339. endpoint_conf_t conf;
  340. endpoint_t *m_pEndpoint;
  341. int m_iPickupPhoneState;
  342. ErrorCodeEnum m_SipErrorCode;
  343. DeviceTypeEnum m_eDeviceType;
  344. CallingTypeEnum m_nCallType; //呼叫模式,0:可视柜台正常呼叫,1:PAD主动外呼,2:PAD被动呼叫,来源PAD,3:PAD被动呼叫,来源手机端�
  345. int m_nSysCallType; //0:普通模式,1:p2p模式
  346. volatile stVideoParam m_stVideoParam;
  347. volatile int m_bIsSalesRecord;
  348. record_echo_location_t m_RecordVideoLocation;
  349. private:
  350. CServerSessionBase *m_pCurrentSession;
  351. int m_state;
  352. CAutoArray<CUUID> m_arrListener;
  353. ChannelSipphoneClient*m_pSipphoneChannel;
  354. SelfChekerClient*m_pSelfcheckClient;
  355. BOOL m_bConnectedAssist;
  356. #if defined(RVC_OS_WIN)
  357. int m_iAudioInCount;
  358. int m_iAudioOutCount;
  359. CSimpleStringA m_strAudioIn;
  360. CSimpleStringA m_strAudioOut;
  361. #endif //RVC_OS_WIN
  362. };