mod_sipphone.h 13 KB

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