mod_sipphone.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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. #if defined(RVC_OS_WIN)
  8. #include "volumekeeper.h"
  9. #include "iaudiomgrinterface.h"
  10. #else
  11. #include "video_render.h"
  12. #include "Event.h"
  13. #include "EventCode.h"
  14. #endif //RVC_OS_WIN
  15. #include "SelfChecker_client_g.h"
  16. #include "SelfChecker_def_g.h"
  17. using namespace SelfChecker;
  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 RVC_DEFAULT_STUNSERVER
  23. #define RVC_DEFAULT_STUNSERVER "rvcpad.cmbchina.com"
  24. #endif
  25. #ifndef RVC_DEFAULT_STUNPORT
  26. #define RVC_DEFAULT_STUNPORT "3478"
  27. #endif
  28. #ifndef RVC_STUN_TIMEOUT
  29. #define RVC_STUN_TIMEOUT 5000
  30. #endif
  31. #ifndef MAX_LOG_LEN
  32. #define MAX_LOG_LEN 512
  33. #endif
  34. #ifndef RVC_START_TIME
  35. #define RVC_START_TIME "00:00:00"
  36. #endif // !RVC_START_TIME
  37. #ifndef RVC_END_TIME
  38. #define RVC_END_TIME "08:00:00"
  39. #endif // !RVC_END_TIME
  40. #ifndef RVC_INTERVAL_TIME
  41. #define RVC_INTERVAL_TIME 3*60
  42. #endif // ! RVC_INTERVAL_TIME
  43. class CSIPEntity;
  44. class CSIPPhoneSession;
  45. struct CVolumnValue
  46. {
  47. int nValue;
  48. void Serialize(SpBuffer &Buf)
  49. {
  50. Buf & nValue;
  51. }
  52. };
  53. struct CFpsValue
  54. {
  55. int nValue;
  56. void Serialize(SpBuffer &Buf)
  57. {
  58. Buf & nValue;
  59. }
  60. };
  61. struct stVideoParam
  62. {
  63. int nWindowState; //视频窗口显示状态,0:正常大小显示,1:放大一倍显示,2:隐藏全部窗口,3:从隐藏状态恢复为全部显示,4:显示远程窗口,隐藏本地窗口, 5:缩放显示
  64. int bShowActiveImg; //活体检测显示图片
  65. int bActiveInspect; //是否启动活体检测
  66. int iActiveCamera; // set by facetracking
  67. int iCameraSwitch; // set by agent and camerastate
  68. int nUpDynamicFps; // 当前视频上行的帧频,由后端通知前端更改频率,只有移动版才使用
  69. int iCameraState; // set by agent and camerastate
  70. int bShowPersonArea; //是否显示人形框
  71. int bShowRecordArea; //是否显示录像人形轮廓
  72. };
  73. //record video echo location
  74. typedef struct record_echo_location_s{
  75. int x;
  76. int y;
  77. int width;
  78. int height;
  79. }record_echo_location_t;
  80. enum ePickupMicrophoneState
  81. {
  82. ePickupMicrophoneState_On,
  83. ePickupMicrophoneState_Off,
  84. };
  85. /* 0:online local and remote video window, 1:only local video window, 2:both local and remote window */
  86. enum eShowVideoWindowType{
  87. eOnline_Mode_Video,
  88. eOnly_Local_Video,
  89. eBoth_Local_Remote_Video
  90. };
  91. enum eVideoRenderType{
  92. eGDI,
  93. eSDL
  94. };
  95. static const char* VideoRender_Type_Table[] = {
  96. "eGDI",
  97. "eSDL"
  98. };
  99. typedef struct MakeCallCommand_s {
  100. CSIPPhoneSession *pSIPPhoneSession;
  101. CSimpleStringA toUri;
  102. CSimpleStringA fromUri;
  103. CSimpleStringA callId;
  104. CSimpleStringA strlocalip;
  105. CSimpleStringA strmappedip;
  106. int iaudio_port;
  107. int imapped_audio_port;
  108. int ivideo_port;
  109. int imapped_video_port;
  110. }MakeCallCommand_t;
  111. struct ControlVideoCommand {
  112. CSIPPhoneSession *pSIPPhoneSession;
  113. int start;
  114. unsigned long local_ip;
  115. int local_port;
  116. unsigned long remote_ip;
  117. int remote_port;
  118. int local_view_x;
  119. int local_view_y;
  120. int local_view_cx;
  121. int local_view_cy;
  122. int remote_view_x;
  123. int remote_view_y;
  124. int remote_view_cx;
  125. int remote_view_cy;
  126. int remote_width;
  127. int remote_height;
  128. int local_hwd_move;
  129. int remote_hwd_move;
  130. int local_fresh_time;
  131. int remote_fresh_time;
  132. };
  133. typedef struct VideoRenderCommand_s
  134. {
  135. CSIPPhoneSession* pSIPPhoneSession;
  136. bool bstart;
  137. int local_view_x;
  138. int local_view_y;
  139. int local_view_cx;
  140. int local_view_cy;
  141. int remote_view_x;
  142. int remote_view_y;
  143. int remote_view_cx;
  144. int remote_view_cy;
  145. int local_hwd_move;
  146. int remote_hwd_move;
  147. int local_fresh_time;
  148. int remote_fresh_time;
  149. }VideoRenderCommand_t;
  150. struct HangupCallCommand{
  151. CSIPPhoneSession *pSIPPhoneSession;
  152. CSimpleStringA strSession_num;
  153. CSimpleStringA strBranch_server_ip;
  154. int iBranch_server_port;
  155. };
  156. struct ChangeDevCommand{
  157. CSIPEntity *pEntity;
  158. int dev_type;
  159. };
  160. class SelfChekerClient:public SelfCheckerService_ClientBase
  161. {
  162. public:
  163. SelfChekerClient(CSIPEntity*pEntity);
  164. };
  165. class ChannelSipphoneClient : public ChannelService_ClientBase
  166. {
  167. public:
  168. ChannelSipphoneClient(CSIPEntity *pEntity);
  169. virtual void OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData);
  170. virtual void OnMessage(ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData);
  171. };
  172. class CSIPPhoneSession : public PhoneService_ServerSessionBase
  173. {
  174. public:
  175. CSIPPhoneSession(CSIPEntity *pEntity);
  176. virtual void Handle_MakeCall(SpReqAnsContext<PhoneService_MakeCall_Req, PhoneService_MakeCall_Ans>::Pointer ctx);
  177. virtual void Handle_HangupCall(SpReqAnsContext<PhoneService_HangupCall_Req, PhoneService_HangupCall_Ans>::Pointer ctx);
  178. virtual void Handle_StartVideo(SpOnewayCallContext<PhoneService_StartVideo_Info>::Pointer ctx);
  179. virtual void Handle_StopVideo(SpOnewayCallContext<PhoneService_StopVideo_Info>::Pointer ctx);
  180. virtual void Handle_BeginState(SpSubscribeContext<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::Pointer ctx);
  181. virtual void Handle_EndState(SpOnewayCallContext<PhoneService_EndState_Info>::Pointer ctx);
  182. virtual void Handle_ReleaseCall(SpReqAnsContext<PhoneService_ReleaseCall_Req, PhoneService_ReleaseCall_Ans>::Pointer ctx);
  183. virtual void Handle_RealErrorCheck(SpOnewayCallContext<PhoneService_RealErrorCheck_Info>::Pointer ctx);
  184. virtual void Handle_SetCallingParam(SpOnewayCallContext<PhoneService_SetCallingParam_Info>::Pointer ctx);
  185. virtual void OnClose(ErrorCodeEnum eErrorCode);
  186. virtual void Handle_GetHandfreeOutVolume(SpReqAnsContext<PhoneService_GetHandfreeOutVolume_Req, PhoneService_GetHandfreeOutVolume_Ans>::Pointer ctx);
  187. virtual void Handle_SetHandfreeOutVolume(SpReqAnsContext<PhoneService_SetHandfreeOutVolume_Req, PhoneService_SetHandfreeOutVolume_Ans>::Pointer ctx);
  188. virtual void Handle_GetPickupOutVolume(SpReqAnsContext<PhoneService_GetPickupOutVolume_Req, PhoneService_GetPickupOutVolume_Ans>::Pointer ctx);
  189. virtual void Handle_SetPickupOutVolume(SpReqAnsContext<PhoneService_SetPickupOutVolume_Req, PhoneService_SetPickupOutVolume_Ans>::Pointer ctx);
  190. virtual void Handle_StartVideoRender(SpOnewayCallContext<PhoneService_StartVideoRender_Info>::Pointer ctx);
  191. virtual void Handle_StopVideoRender(SpOnewayCallContext<PhoneService_StopVideoRender_Info>::Pointer ctx);
  192. virtual void Handle_GetHandfreeInVolume(SpReqAnsContext<PhoneService_GetHandfreeInVolume_Req, PhoneService_GetHandfreeInVolume_Ans>::Pointer ctx);
  193. virtual void Handle_SetHandfreeInVolume(SpReqAnsContext<PhoneService_SetHandfreeInVolume_Req, PhoneService_SetHandfreeInVolume_Ans>::Pointer ctx);
  194. virtual void Handle_SetPickupInVolume(SpReqAnsContext<PhoneService_SetPickupInVolume_Req, PhoneService_SetPickupInVolume_Ans>::Pointer ctx);
  195. virtual void Handle_GetPickupInVolume(SpReqAnsContext<PhoneService_GetPickupInVolume_Req, PhoneService_GetPickupInVolume_Ans>::Pointer ctx);
  196. public:
  197. void on_call_state(int state, const char *state_desc, const char *phrase);
  198. int make_call(MakeCallCommand_t *pCmd);
  199. void hangup_call(HangupCallCommand *pCmd);
  200. void release_call();
  201. void control_video(ControlVideoCommand* pCmd);
  202. int on_video_box_move(int imessagetype, int ivideotype, int ileft, int ibottom);
  203. #if defined(RVC_OS_WIN)
  204. ErrorCodeEnum get_nat_mapped_info(char* strmapip, size_t ulen, int* ivideo_map_port, int* iaudio_map_port, int ivideo_port, int iaudio_port);
  205. #else
  206. void video_render(VideoRenderCommand_t* pCmd);
  207. int start_video_render(rvc_video_render_params_t* render_param, bool bremote);
  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 LoadStunConfig();
  240. ErrorCodeEnum StartVideoRender();
  241. ErrorCodeEnum StopVideoRender();
  242. BOOL GetStunFlag();
  243. void SetStunFlag(BOOL bFlag);
  244. int GetIpByDomain(char* poutput, size_t ulen, const char* pinput);
  245. #endif //RVC_OS_WIN
  246. //send DynamicFps
  247. void SendDynamicFps(int nFps);
  248. //send audio device volume
  249. void SendAudioDeviceVolumn(int nDevice);
  250. ErrorCodeEnum SetHandfreeOutVolume(int iVolume);
  251. ErrorCodeEnum SetPickupOutVolume(int iVolume);
  252. ErrorCodeEnum SetHandfreeInVolume(int iVolume);
  253. ErrorCodeEnum SetPickupInVolume(int iVolume);
  254. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext);
  255. ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError);
  256. virtual void OnPaused();
  257. virtual void OnContinued();
  258. virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszClass*/);
  259. virtual bool IsService()const{return true;}
  260. virtual void OnTimeout(DWORD dwTimerID);
  261. bool IsCurrentSession(CServerSessionBase * pSession) { return m_pCurrentSession == pSession; }
  262. endpoint_t *GetEndpoint() { return m_pEndpoint; }
  263. ErrorCodeEnum InitEndpoint();
  264. void change_dev(int dev_type);
  265. void SwitchHandFree();
  266. void SwitchPickup();
  267. void SetState(int state);
  268. ErrorCodeEnum RealSelfCheck();
  269. CSimpleStringA MakeUri(const char *terminal_id);
  270. void Handle_RecordVideoLocation_Info(const char* pszMessage);
  271. void Handle_AdjustVideoEchoEvent(const char* pszMessage);
  272. private:
  273. ErrorCodeEnum LoadConfig(endpoint_conf_t *conf);
  274. #if defined(RVC_OS_WIN)
  275. eVideoRenderType GetMediaConfig();
  276. void UpdateAudioConfig();
  277. void HandleAudioDeviceErrorEvent();
  278. ErrorCodeEnum AutoCorrectAudioConfig();
  279. //载入运行时配置
  280. ErrorCodeEnum LoadRestartRunConfig(unsigned int& utime);
  281. //保存运行时
  282. ErrorCodeEnum SaveRestartRunConfig(unsigned int utime);
  283. #else
  284. void InitFreshTimeConfig();
  285. void HideLocalVideo();
  286. void ShowLocalVideo();
  287. void HideBothVideo();
  288. void ShowBothVideo();
  289. #endif //RVC_OS_WIN
  290. ErrorCodeEnum AudioDspFlagsUseCentersetting(endpoint_conf_t* conf);
  291. //载入运行时配置
  292. ErrorCodeEnum LoadAudioRunConfig(int&nHandfreeout,int&nPickupout,int&nHandfreein,int&nPickupin);
  293. //保存运行时
  294. ErrorCodeEnum SaveAudioRunConfig(int nHandfreeout,int nPickupout,int nHandfreein,int nPickupin);
  295. // we use root.ini Video section config to decide camera count
  296. ErrorCodeEnum DecideCameraCount(int &nCount);
  297. ErrorCodeEnum DecideScreenCount(int &nCount);
  298. DeviceTypeEnum RvcGetDeviceType();
  299. ErrorCodeEnum RvcGetAudioDeviceInfo();
  300. ErrorCodeEnum RvcSetSaveAudioVolume();
  301. //eVideoRenderType GetMediaConfig();
  302. ErrorCodeEnum LoadEntityConfig();
  303. ErrorCodeEnum ConnectAssistChannel();
  304. bool IsPostAudioConfigInfo();
  305. public:
  306. int m_kept_volume_in[2];
  307. int m_kept_volume_out[2];
  308. IAudioMgr* m_pAudioMgr;
  309. #ifdef RVC_OS_WIN
  310. void* m_pKeeperIn[2];
  311. void* m_pKeeperOut[2];
  312. eVideoRenderType m_eVideoRenderType;
  313. CSimpleStringA m_strStunServer;
  314. CSimpleStringA m_strStunPort;
  315. int m_iStunTimeOut;
  316. BOOL m_bStunFlag;
  317. BOOL m_bAudioMgrInited;
  318. int m_AudioStopType;
  319. int m_iCapType;
  320. CSimpleStringA m_strHandfreeIn;
  321. CSimpleStringA m_strHandfreeOut;
  322. CSimpleStringA m_strPickUpIn;
  323. CSimpleStringA m_strPickUpOut;
  324. CSimpleStringA m_strStartTime;
  325. CSimpleStringA m_strEndTime;
  326. int m_itervalTime;
  327. BOOL m_bStopAutoRestart;
  328. int m_iAudioDspUseCenter;
  329. #else
  330. int m_ilocalvideo_freshtime;
  331. int m_iremotevideo_freshtime;
  332. rvc_video_render_t* m_render;
  333. int m_iAudioDspUseCenter;
  334. #endif
  335. CSystemStaticInfo staticInfo;
  336. char m_localip[RVC_MAX_IP_LEN]; //本地ip
  337. endpoint_conf_t conf;
  338. endpoint_t *m_pEndpoint;
  339. int m_iPickupPhoneState;
  340. ErrorCodeEnum m_SipErrorCode;
  341. DeviceTypeEnum m_eDeviceType;
  342. CallingTypeEnum m_nCallType; //呼叫模式,0:可视柜台正常呼叫,1:PAD主动外呼,2:PAD被动呼叫,来源PAD,3:PAD被动呼叫,来源手机端�
  343. int m_nSysCallType; //0:普通模式,1:p2p模式
  344. volatile stVideoParam m_stVideoParam;
  345. volatile int m_bIsSalesRecord;
  346. record_echo_location_t m_RecordVideoLocation;
  347. private:
  348. CServerSessionBase *m_pCurrentSession;
  349. int m_state;
  350. CAutoArray<CUUID> m_arrListener;
  351. ChannelSipphoneClient*m_pSipphoneChannel;
  352. SelfChekerClient*m_pSelfcheckClient;
  353. BOOL m_bConnectedAssist;
  354. #if defined(RVC_OS_WIN)
  355. int m_iAudioInCount;
  356. int m_iAudioOutCount;
  357. CSimpleStringA m_strAudioIn;
  358. CSimpleStringA m_strAudioOut;
  359. #endif //RVC_OS_WIN
  360. };