mod_sipphone.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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 "video_render.h"
  8. #include "../mod_selfchecker/SelfChecker_client_g.h"
  9. #include "../mod_selfchecker/SelfChecker_def_g.h"
  10. using namespace SelfChecker;
  11. #include "Event.h"
  12. #include "EventCode.h"
  13. #include "../mod_assistantchannel/chan_protocol.h"
  14. #include "../mod_assistantchannel/AssistantChannel_client_g.h"
  15. #include "../../Other/libaudiomgr/iaudiomgrinterface.h"
  16. using namespace AssistantChannel;
  17. class CSIPEntity;
  18. class CSIPPhoneSession;
  19. struct CVolumnValue
  20. {
  21. int nValue;
  22. void Serialize(SpBuffer &Buf)
  23. {
  24. Buf & nValue;
  25. }
  26. };
  27. struct CFpsValue
  28. {
  29. int nValue;
  30. void Serialize(SpBuffer &Buf)
  31. {
  32. Buf & nValue;
  33. }
  34. };
  35. struct stVideoParam
  36. {
  37. int nWindowState; //视频窗口显示状态,0:正常大小显示,1:放大一倍显示,2:隐藏全部窗口,3:从隐藏状态恢复为全部显示,4:显示远程窗口,隐藏本地窗口, 5:缩放显示
  38. int bShowActiveImg; //活体检测显示图片
  39. int bActiveInspect; //是否启动活体检测
  40. int iActiveCamera; // set by facetracking
  41. int iCameraSwitch; // set by agent and camerastate
  42. int nUpDynamicFps; // 当前视频上行的帧频,由后端通知前端更改频率,只有移动版才使用
  43. int iCameraState; // set by agent and camerastate
  44. int bShowPersonArea; //是否显示人形框
  45. int bShowRecordArea; //是否显示录像人形轮廓
  46. };
  47. //record video echo location
  48. typedef struct record_echo_location_s{
  49. int x;
  50. int y;
  51. int width;
  52. int height;
  53. }record_echo_location_t;
  54. enum ePickupMicrophoneState
  55. {
  56. ePickupMicrophoneState_On,
  57. ePickupMicrophoneState_Off,
  58. };
  59. /* 0:online local and remote video window, 1:only local video window, 2:both local and remote window */
  60. //enum eShowVideoWindowType{
  61. // eOnline_Mode_Video,
  62. // eOnly_Local_Video,
  63. // eBoth_Local_Remote_Video
  64. //};
  65. typedef struct MakeCallCommand_s
  66. {
  67. CSIPPhoneSession *pSIPPhoneSession;
  68. CSimpleStringA toUri;
  69. CSimpleStringA fromUri;
  70. CSimpleStringA callId;
  71. CSimpleStringA strlocalip;
  72. CSimpleStringA strmappedip;
  73. int iaudio_port;
  74. int imapped_audio_port;
  75. int ivideo_port;
  76. int imapped_video_port;
  77. }MakeCallCommand_t;
  78. struct ControlVideoCommand
  79. {
  80. CSIPPhoneSession *pSIPPhoneSession;
  81. int start;
  82. unsigned long local_ip;
  83. int local_port;
  84. unsigned long remote_ip;
  85. int remote_port;
  86. int local_view_x;
  87. int local_view_y;
  88. int local_view_cx;
  89. int local_view_cy;
  90. int remote_view_x;
  91. int remote_view_y;
  92. int remote_view_cx;
  93. int remote_view_cy;
  94. int remote_width;
  95. int remote_height;
  96. int local_hwd_move;
  97. int remote_hwd_move;
  98. int local_fresh_time;
  99. int remote_fresh_time;
  100. };
  101. typedef struct VideoRenderCommand_s
  102. {
  103. CSIPPhoneSession* pSIPPhoneSession;
  104. bool bstart;
  105. int local_view_x;
  106. int local_view_y;
  107. int local_view_cx;
  108. int local_view_cy;
  109. int remote_view_x;
  110. int remote_view_y;
  111. int remote_view_cx;
  112. int remote_view_cy;
  113. int local_hwd_move;
  114. int remote_hwd_move;
  115. int local_fresh_time;
  116. int remote_fresh_time;
  117. }VideoRenderCommand_t;
  118. struct HangupCallCommand
  119. {
  120. CSIPPhoneSession *pSIPPhoneSession;
  121. CSimpleStringA strSession_num;
  122. CSimpleStringA strBranch_server_ip;
  123. int iBranch_server_port;
  124. };
  125. struct ChangeDevCommand
  126. {
  127. CSIPEntity *pEntity;
  128. int dev_type;
  129. };
  130. class SelfChekerClient:public SelfCheckerService_ClientBase
  131. {
  132. public:
  133. SelfChekerClient(CSIPEntity*pEntity);
  134. };
  135. class ChannelSipphoneClient : public ChannelService_ClientBase
  136. {
  137. public:
  138. ChannelSipphoneClient(CSIPEntity *pEntity);
  139. virtual void OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData);
  140. virtual void OnMessage(ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData);
  141. };
  142. class CSIPPhoneSession : public PhoneService_ServerSessionBase
  143. {
  144. public:
  145. CSIPPhoneSession(CSIPEntity *pEntity);
  146. virtual void Handle_MakeCall(SpReqAnsContext<PhoneService_MakeCall_Req, PhoneService_MakeCall_Ans>::Pointer ctx);
  147. virtual void Handle_HangupCall(SpReqAnsContext<PhoneService_HangupCall_Req, PhoneService_HangupCall_Ans>::Pointer ctx);
  148. virtual void Handle_StartVideo(SpOnewayCallContext<PhoneService_StartVideo_Info>::Pointer ctx);
  149. virtual void Handle_StopVideo(SpOnewayCallContext<PhoneService_StopVideo_Info>::Pointer ctx);
  150. virtual void Handle_BeginState(SpSubscribeContext<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::Pointer ctx);
  151. virtual void Handle_EndState(SpOnewayCallContext<PhoneService_EndState_Info>::Pointer ctx);
  152. virtual void Handle_ReleaseCall(SpReqAnsContext<PhoneService_ReleaseCall_Req, PhoneService_ReleaseCall_Ans>::Pointer ctx);
  153. virtual void Handle_RealErrorCheck(SpOnewayCallContext<PhoneService_RealErrorCheck_Info>::Pointer ctx);
  154. virtual void Handle_SetCallingParam(SpOnewayCallContext<PhoneService_SetCallingParam_Info>::Pointer ctx);
  155. virtual void OnClose(ErrorCodeEnum eErrorCode);
  156. virtual void Handle_GetHandfreeOutVolume(SpReqAnsContext<PhoneService_GetHandfreeOutVolume_Req, PhoneService_GetHandfreeOutVolume_Ans>::Pointer ctx);
  157. virtual void Handle_SetHandfreeOutVolume(SpReqAnsContext<PhoneService_SetHandfreeOutVolume_Req, PhoneService_SetHandfreeOutVolume_Ans>::Pointer ctx);
  158. virtual void Handle_GetPickupOutVolume(SpReqAnsContext<PhoneService_GetPickupOutVolume_Req, PhoneService_GetPickupOutVolume_Ans>::Pointer ctx);
  159. virtual void Handle_SetPickupOutVolume(SpReqAnsContext<PhoneService_SetPickupOutVolume_Req, PhoneService_SetPickupOutVolume_Ans>::Pointer ctx);
  160. virtual void Handle_StartVideoRender(SpOnewayCallContext<PhoneService_StartVideoRender_Info>::Pointer ctx);
  161. virtual void Handle_StopVideoRender(SpOnewayCallContext<PhoneService_StopVideoRender_Info>::Pointer ctx);
  162. public:
  163. void on_call_state(int state, const char *state_desc, const char *phrase);
  164. int make_call(MakeCallCommand_t *pCmd);
  165. void hangup_call(HangupCallCommand *pCmd);
  166. void release_call();
  167. void control_video(ControlVideoCommand *pCmd);
  168. void video_render(VideoRenderCommand_t* pCmd);
  169. int on_video_box_move(int imessagetype, int ivideotype, int ileft, int ibottom);
  170. int start_video_render(rvc_video_render_params_t* render_param, bool bremote);
  171. int stop_video_render();
  172. public:
  173. int m_iLastState;
  174. private:
  175. SpSubscribeContext<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::Pointer m_spCallbackContext;
  176. endpoint_call_t *m_pCall;
  177. CSIPEntity *m_pEntity;
  178. };
  179. class CSIPEntity : public CEntityBase, public ILogListener, public ISysVarListener,public ITimerListener
  180. {
  181. public:
  182. CSIPEntity();
  183. virtual ~CSIPEntity() {}
  184. virtual const char *GetEntityName() const { return "SIPPhone"; }
  185. virtual void OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  186. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  187. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext& pLinkInfo);
  188. virtual void OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName);
  189. virtual void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext);
  190. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext);
  191. virtual void OnStarted();
  192. ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError);
  193. void OnReceivePkt(int type, int sub_type, const char *buffer, int size);
  194. ErrorCodeEnum GetLocalIP();
  195. //send DynamicFps
  196. void SendDynamicFps(int nFps);
  197. //send audio device volume
  198. void SendAudioDeviceVolumn(int nDevice);
  199. ErrorCodeEnum SetHandfreeOutVolume(int iVolume);
  200. ErrorCodeEnum SetPickupOutVolume(int iVolume);
  201. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext);
  202. ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError);
  203. virtual void OnPaused();
  204. virtual void OnContinued();
  205. virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszClass*/);
  206. virtual bool IsService()const{return true;}
  207. virtual void OnTimeout(DWORD dwTimerID);
  208. bool IsCurrentSession(CServerSessionBase * pSession) { return m_pCurrentSession == pSession; }
  209. endpoint_t *GetEndpoint() { return m_pEndpoint; }
  210. ErrorCodeEnum InitEndpoint();
  211. void change_dev(int dev_type);
  212. void SwitchHandFree();
  213. void SwitchPickup();
  214. void SetState(int state);
  215. ErrorCodeEnum RealSelfCheck();
  216. CSimpleStringA MakeUri(const char *terminal_id);
  217. void Handle_RecordVideoLocation_Info(const char* pszMessage);
  218. void Handle_AdjustVideoEchoEvent(const char* pszMessage);
  219. private:
  220. ErrorCodeEnum LoadConfig(endpoint_conf_t *conf);
  221. void InitFreshTimeConfig();
  222. //载入运行时配置
  223. ErrorCodeEnum LoadAudioRunConfig(int&nHandfreeout,int&nPickupout,int&nHandfreein,int&nPickupin);
  224. //保存运行时
  225. ErrorCodeEnum SaveAudioRunConfig(int nHandfreeout,int nPickupout,int nHandfreein,int nPickupin);
  226. // we use root.ini Video section config to decide camera count
  227. ErrorCodeEnum DecideCameraCount(int &nCount);
  228. ErrorCodeEnum DecideScreenCount(int &nCount);
  229. DeviceTypeEnum RvcGetDeviceType();
  230. ErrorCodeEnum RvcGetAudioDeviceInfo();
  231. ErrorCodeEnum RvcSetSaveAudioVolume();
  232. void HideLocalVideo();
  233. void ShowLocalVideo();
  234. void HideBothVideo();
  235. void ShowBothVideo();
  236. public:
  237. int m_kept_volume_in[2];
  238. int m_kept_volume_out[2];
  239. #ifdef RVC_OS_WIN
  240. void* m_pKeeperIn[2];
  241. void* m_pKeeperOut[2];
  242. #else
  243. IAudioMgr* m_pAudioMgr;
  244. #endif
  245. //int m_nDownDynamicFps; //当前视频下行的帧频,由前端通知后端更改频率,只有移动版才使用
  246. CSystemStaticInfo staticInfo;
  247. char m_localip[256]; //本地ip
  248. endpoint_conf_t conf;
  249. endpoint_t *m_pEndpoint;
  250. int m_iPickupPhoneState;
  251. ErrorCodeEnum m_SipErrorCode;
  252. DeviceTypeEnum m_eDeviceType;
  253. CallingTypeEnum m_nCallType; //呼叫模式,0:可视柜台正常呼叫,1:PAD主动外呼,2:PAD被动呼叫,来源PAD,3:PAD被动呼叫,来源手机端
  254. int m_nSysCallType;//0:普通模式,1:p2p模式
  255. volatile stVideoParam m_stVideoParam; //视频参数,add by ch@20190424
  256. volatile int m_bIsSalesRecord; //add by ly@20180725
  257. volatile int m_bEwsRecord; //add by ly@2019/04/18
  258. record_echo_location_t m_RecordVideoLocation;
  259. int m_ilocalvideo_freshtime;
  260. int m_iremotevideo_freshtime;
  261. rvc_video_render_t* m_render;
  262. private:
  263. CServerSessionBase *m_pCurrentSession;
  264. int m_state;
  265. CAutoArray<CUUID> m_arrListener;
  266. ChannelSipphoneClient*m_pSipphoneChannel;
  267. SelfChekerClient*m_pSelfcheckClient;
  268. };