mod_sipphone.h 13 KB

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