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