mod_sipphone.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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. CSIPPhoneSession *pSIPPhoneSession;
  67. CSimpleStringA toUri;
  68. CSimpleStringA fromUri;
  69. CSimpleStringA callId;
  70. CSimpleStringA strlocalip;
  71. CSimpleStringA strmappedip;
  72. int iaudio_port;
  73. int imapped_audio_port;
  74. int ivideo_port;
  75. int imapped_video_port;
  76. }MakeCallCommand_t;
  77. struct ControlVideoCommand{
  78. CSIPPhoneSession *pSIPPhoneSession;
  79. int start;
  80. unsigned long local_ip;
  81. int local_port;
  82. unsigned long remote_ip;
  83. int remote_port;
  84. int local_view_x;
  85. int local_view_y;
  86. int local_view_cx;
  87. int local_view_cy;
  88. int remote_view_x;
  89. int remote_view_y;
  90. int remote_view_cx;
  91. int remote_view_cy;
  92. int remote_width;
  93. int remote_height;
  94. int local_hwd_move;
  95. int remote_hwd_move;
  96. int local_fresh_time;
  97. int remote_fresh_time;
  98. };
  99. typedef struct VideoRenderCommand_s
  100. {
  101. CSIPPhoneSession* pSIPPhoneSession;
  102. bool bstart;
  103. int local_view_x;
  104. int local_view_y;
  105. int local_view_cx;
  106. int local_view_cy;
  107. int remote_view_x;
  108. int remote_view_y;
  109. int remote_view_cx;
  110. int remote_view_cy;
  111. int local_hwd_move;
  112. int remote_hwd_move;
  113. int local_fresh_time;
  114. int remote_fresh_time;
  115. }VideoRenderCommand_t;
  116. struct HangupCallCommand{
  117. CSIPPhoneSession *pSIPPhoneSession;
  118. CSimpleStringA strSession_num;
  119. CSimpleStringA strBranch_server_ip;
  120. int iBranch_server_port;
  121. };
  122. struct ChangeDevCommand{
  123. CSIPEntity *pEntity;
  124. int dev_type;
  125. };
  126. class SelfChekerClient:public SelfCheckerService_ClientBase
  127. {
  128. public:
  129. SelfChekerClient(CSIPEntity*pEntity);
  130. };
  131. class ChannelSipphoneClient : public ChannelService_ClientBase
  132. {
  133. public:
  134. ChannelSipphoneClient(CSIPEntity *pEntity);
  135. virtual void OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData);
  136. virtual void OnMessage(ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData);
  137. };
  138. class CSIPPhoneSession : public PhoneService_ServerSessionBase
  139. {
  140. public:
  141. CSIPPhoneSession(CSIPEntity *pEntity);
  142. virtual void Handle_MakeCall(SpReqAnsContext<PhoneService_MakeCall_Req, PhoneService_MakeCall_Ans>::Pointer ctx);
  143. virtual void Handle_HangupCall(SpReqAnsContext<PhoneService_HangupCall_Req, PhoneService_HangupCall_Ans>::Pointer ctx);
  144. virtual void Handle_StartVideo(SpOnewayCallContext<PhoneService_StartVideo_Info>::Pointer ctx);
  145. virtual void Handle_StopVideo(SpOnewayCallContext<PhoneService_StopVideo_Info>::Pointer ctx);
  146. virtual void Handle_BeginState(SpSubscribeContext<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::Pointer ctx);
  147. virtual void Handle_EndState(SpOnewayCallContext<PhoneService_EndState_Info>::Pointer ctx);
  148. virtual void Handle_ReleaseCall(SpReqAnsContext<PhoneService_ReleaseCall_Req, PhoneService_ReleaseCall_Ans>::Pointer ctx);
  149. virtual void Handle_RealErrorCheck(SpOnewayCallContext<PhoneService_RealErrorCheck_Info>::Pointer ctx);
  150. virtual void Handle_SetCallingParam(SpOnewayCallContext<PhoneService_SetCallingParam_Info>::Pointer ctx);
  151. virtual void OnClose(ErrorCodeEnum eErrorCode);
  152. virtual void Handle_GetHandfreeOutVolume(SpReqAnsContext<PhoneService_GetHandfreeOutVolume_Req, PhoneService_GetHandfreeOutVolume_Ans>::Pointer ctx);
  153. virtual void Handle_SetHandfreeOutVolume(SpReqAnsContext<PhoneService_SetHandfreeOutVolume_Req, PhoneService_SetHandfreeOutVolume_Ans>::Pointer ctx);
  154. virtual void Handle_GetPickupOutVolume(SpReqAnsContext<PhoneService_GetPickupOutVolume_Req, PhoneService_GetPickupOutVolume_Ans>::Pointer ctx);
  155. virtual void Handle_SetPickupOutVolume(SpReqAnsContext<PhoneService_SetPickupOutVolume_Req, PhoneService_SetPickupOutVolume_Ans>::Pointer ctx);
  156. virtual void Handle_StartVideoRender(SpOnewayCallContext<PhoneService_StartVideoRender_Info>::Pointer ctx);
  157. virtual void Handle_StopVideoRender(SpOnewayCallContext<PhoneService_StopVideoRender_Info>::Pointer ctx);
  158. virtual void Handle_GetHandfreeInVolume(SpReqAnsContext<PhoneService_GetHandfreeInVolume_Req, PhoneService_GetHandfreeInVolume_Ans>::Pointer ctx);
  159. virtual void Handle_SetHandfreeInVolume(SpReqAnsContext<PhoneService_SetHandfreeInVolume_Req, PhoneService_SetHandfreeInVolume_Ans>::Pointer ctx);
  160. virtual void Handle_SetPickupInVolume(SpReqAnsContext<PhoneService_SetPickupInVolume_Req, PhoneService_SetPickupInVolume_Ans>::Pointer ctx);
  161. virtual void Handle_GetPickupInVolume(SpReqAnsContext<PhoneService_GetPickupInVolume_Req, PhoneService_GetPickupInVolume_Ans>::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. ErrorCodeEnum SetHandfreeInVolume(int iVolume);
  202. ErrorCodeEnum SetPickupInVolume(int iVolume);
  203. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext);
  204. ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError);
  205. virtual void OnPaused();
  206. virtual void OnContinued();
  207. virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszClass*/);
  208. virtual bool IsService()const{return true;}
  209. virtual void OnTimeout(DWORD dwTimerID);
  210. bool IsCurrentSession(CServerSessionBase * pSession) { return m_pCurrentSession == pSession; }
  211. endpoint_t *GetEndpoint() { return m_pEndpoint; }
  212. ErrorCodeEnum InitEndpoint();
  213. void change_dev(int dev_type);
  214. void SwitchHandFree();
  215. void SwitchPickup();
  216. void SetState(int state);
  217. ErrorCodeEnum RealSelfCheck();
  218. CSimpleStringA MakeUri(const char *terminal_id);
  219. void Handle_RecordVideoLocation_Info(const char* pszMessage);
  220. void Handle_AdjustVideoEchoEvent(const char* pszMessage);
  221. private:
  222. ErrorCodeEnum LoadConfig(endpoint_conf_t *conf);
  223. void InitFreshTimeConfig();
  224. //载入运行时配置
  225. ErrorCodeEnum LoadAudioRunConfig(int&nHandfreeout,int&nPickupout,int&nHandfreein,int&nPickupin);
  226. //保存运行时
  227. ErrorCodeEnum SaveAudioRunConfig(int nHandfreeout,int nPickupout,int nHandfreein,int nPickupin);
  228. // we use root.ini Video section config to decide camera count
  229. ErrorCodeEnum DecideCameraCount(int &nCount);
  230. ErrorCodeEnum DecideScreenCount(int &nCount);
  231. DeviceTypeEnum RvcGetDeviceType();
  232. ErrorCodeEnum RvcGetAudioDeviceInfo();
  233. ErrorCodeEnum RvcSetSaveAudioVolume();
  234. //eVideoRenderType GetMediaConfig();
  235. ErrorCodeEnum LoadEntityConfig();
  236. ErrorCodeEnum ConnectAssistChannel();
  237. void HideLocalVideo();
  238. void ShowLocalVideo();
  239. void HideBothVideo();
  240. void ShowBothVideo();
  241. ErrorCodeEnum AudioDspFlagsUseCentersetting(endpoint_conf_t* conf);
  242. bool IsPostAudioConfigInfo();
  243. public:
  244. int m_kept_volume_in[2];
  245. int m_kept_volume_out[2];
  246. #ifdef RVC_OS_WIN
  247. void* m_pKeeperIn[2];
  248. void* m_pKeeperOut[2];
  249. #else
  250. IAudioMgr* m_pAudioMgr;
  251. #endif
  252. //int m_nDownDynamicFps; //当前视频下行的帧频,由前端通知后端更改频率,只有移动版才使用
  253. CSystemStaticInfo staticInfo;
  254. char m_localip[RVC_MAX_IP_LEN]; //本地ip
  255. endpoint_conf_t conf;
  256. endpoint_t *m_pEndpoint;
  257. int m_iPickupPhoneState;
  258. ErrorCodeEnum m_SipErrorCode;
  259. DeviceTypeEnum m_eDeviceType;
  260. CallingTypeEnum m_nCallType; //呼叫模式,0:可视柜台正常呼叫,1:PAD主动外呼,2:PAD被动呼叫,来源PAD,3:PAD被动呼叫,来源手机端
  261. int m_nSysCallType;//0:普通模式,1:p2p模式
  262. volatile stVideoParam m_stVideoParam;
  263. volatile int m_bIsSalesRecord;
  264. record_echo_location_t m_RecordVideoLocation;
  265. int m_ilocalvideo_freshtime;
  266. int m_iremotevideo_freshtime;
  267. rvc_video_render_t* m_render;
  268. int m_iAudioDspUseCenter;
  269. private:
  270. CServerSessionBase *m_pCurrentSession;
  271. int m_state;
  272. CAutoArray<CUUID> m_arrListener;
  273. ChannelSipphoneClient*m_pSipphoneChannel;
  274. SelfChekerClient*m_pSelfcheckClient;
  275. BOOL m_bConnectedAssist;
  276. };