mod_sipphone.cpp 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406
  1. #include "stdafx.h"
  2. #include "SpBase.h"
  3. #include "SpIni.h"
  4. #include "endpoint.h"
  5. #include "SIPPhone_server_g.h"
  6. #include "SIPPhone_msg_g.h"
  7. #include "../mod_agentip/sysvar.h"
  8. #include "../mod_facetracking/sysvar.h"
  9. #include "sockutil.h"
  10. #include "rec_common.h"
  11. #include "audio_session.h"
  12. #include "video_session.h"
  13. #include "volumekeeper.h"
  14. #include "Event.h"
  15. #include "EventCode.h"
  16. #include "../mod_assistantchannel/AssistantChannel_client_g.h"
  17. using namespace AssistantChannel;
  18. #include "../mod_assistantchannel/chan_protocol.h"
  19. #include "../mod_selfchecker/SelfChecker_client_g.h"
  20. #include "../mod_selfchecker/SelfChecker_def_g.h"
  21. using namespace SelfChecker;
  22. #define EVT_CONVERTER "EventConverter"
  23. #define DEVICE_HANDFREE_OUT 0
  24. #define DEVICE_PICKUP_OUT 1
  25. #define DEVICE_HANDFREE_IN 2
  26. #define DEVICE_PICKUP_IN 3
  27. enum ePickupMicrophoneState
  28. {
  29. ePickupMicrophoneState_On,
  30. ePickupMicrophoneState_Off,
  31. };
  32. /* 0:online local and remote video window, 1:only local video window, 2:both local and remote window */
  33. enum eShowVideoWindowType{
  34. eOnline_Mode_Video,
  35. eOnly_Local_Video,
  36. eBoth_Local_Remote_Video
  37. };
  38. struct CVolumnValue
  39. {
  40. int nValue;
  41. void Serialize(SpBuffer &Buf)
  42. {
  43. Buf & nValue;
  44. }
  45. };
  46. struct CFpsValue
  47. {
  48. int nValue;
  49. void Serialize(SpBuffer &Buf)
  50. {
  51. Buf & nValue;
  52. }
  53. };
  54. struct stVideoParam
  55. {
  56. int nWindowState; //视频窗口显示状态,0:正常大小显示,1:放大一倍显示,2:隐藏全部窗口,3:从隐藏状态恢复为全部显示,4:显示远程窗口,隐藏本地窗口, 5:缩放显示
  57. int bShowActiveImg; //活体检测显示图片
  58. int bActiveInspect; //是否启动活体检测
  59. int iActiveCamera; // set by facetracking
  60. int iCameraSwitch; // set by agent and camerastate
  61. int nUpDynamicFps; // 当前视频上行的帧频,由后端通知前端更改频率,只有移动版才使用
  62. int iCameraState; // set by agent and camerastate
  63. int bShowPersonArea; //是否显示人形框
  64. int bShowRecordArea; //是否显示录像人形轮廓
  65. };
  66. //record video echo location
  67. typedef struct record_echo_location_s{
  68. int x;
  69. int y;
  70. int width;
  71. int height;
  72. }record_echo_location_t;
  73. #ifndef DEFAULT_RECORD_VIDEO_WIDTH
  74. #define DEFAULT_RECORD_VIDEO_WIDTH 1056
  75. #endif
  76. #ifndef DEFAULT_RECORD_VIDEO_HEIGHT
  77. #define DEFAULT_RECORD_VIDEO_HEIGHT 595
  78. #endif
  79. #ifndef SMALL_RECORD_VIDEO_WIDTH
  80. #define SMALL_RECORD_VIDEO_WIDTH 244
  81. #endif
  82. #ifndef SMALL_RECORD_VIDEO_HEIGHT
  83. #define SMALL_RECORD_VIDEO_HEIGHT 138
  84. #endif
  85. /////////////////////////////////////////////
  86. // future roadmap
  87. // 1. 使用session timer
  88. // 2. 增强稳定性
  89. // 3. 健康检查里面触发 主备服务器切换(switch between freeswitchs) 定时发送options ping switch server
  90. /////////////////////////////////////////////
  91. extern BOOL g_IsExternalTerminalted;
  92. extern BOOL g_bIsSalesRecord;
  93. extern BOOL g_bEwsRecord;
  94. using namespace SIPPhone;
  95. class CSIPEntity;
  96. class SelfChekerClient:public SelfCheckerService_ClientBase
  97. {
  98. public:
  99. SelfChekerClient(CSIPEntity*pEntity);
  100. };
  101. class ChannelSipphoneClient : public ChannelService_ClientBase
  102. {
  103. public:
  104. ChannelSipphoneClient(CSIPEntity *pEntity);
  105. virtual void OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData);
  106. virtual void OnMessage(ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData);
  107. };
  108. class CSIPPhoneSession : public PhoneService_ServerSessionBase
  109. {
  110. public:
  111. CSIPPhoneSession(CSIPEntity *pEntity) : m_pEntity(pEntity), m_pCall(NULL), m_iLastState(0),m_IsLocalPlay(0),m_VideoWindowPlayType(eOnline_Mode_Video)
  112. {
  113. m_cb_video_box_move.on_video_box_move = &__on_video_box_move;
  114. m_cb_video_box_move.user_data = this;
  115. }
  116. virtual void Handle_MakeCall(SpReqAnsContext<PhoneService_MakeCall_Req, PhoneService_MakeCall_Ans>::Pointer ctx);
  117. virtual void Handle_HangupCall(SpReqAnsContext<PhoneService_HangupCall_Req, PhoneService_HangupCall_Ans>::Pointer ctx);
  118. virtual void Handle_StartVideo(SpOnewayCallContext<PhoneService_StartVideo_Info>::Pointer ctx);
  119. virtual void Handle_StopVideo(SpOnewayCallContext<PhoneService_StopVideo_Info>::Pointer ctx);
  120. virtual void Handle_BeginState(SpSubscribeContext<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::Pointer ctx);
  121. virtual void Handle_EndState(SpOnewayCallContext<PhoneService_EndState_Info>::Pointer ctx);
  122. virtual void Handle_ReleaseCall(SpReqAnsContext<PhoneService_ReleaseCall_Req, PhoneService_ReleaseCall_Ans>::Pointer ctx);
  123. virtual void Handle_RealErrorCheck(SpOnewayCallContext<PhoneService_RealErrorCheck_Info>::Pointer ctx);
  124. virtual void Handle_SetCallingParam(SpOnewayCallContext<PhoneService_SetCallingParam_Info>::Pointer ctx);
  125. virtual void OnClose(ErrorCodeEnum eErrorCode);
  126. private:
  127. struct MakeCallCommand
  128. {
  129. CSIPPhoneSession *pSIPPhoneSession;
  130. CSimpleStringA strUri;
  131. };
  132. struct ControlVideoCommand
  133. {
  134. CSIPPhoneSession *pSIPPhoneSession;
  135. int start;
  136. unsigned long local_ip;
  137. int local_port;
  138. unsigned long remote_ip;
  139. int remote_port;
  140. int local_view_x;
  141. int local_view_y;
  142. int local_view_cx;
  143. int local_view_cy;
  144. int remote_view_x;
  145. int remote_view_y;
  146. int remote_view_cx;
  147. int remote_view_cy;
  148. int remote_width;
  149. int remote_height;
  150. int local_hwd_move;
  151. int remote_hwd_move;
  152. };
  153. struct HangupCallCommand
  154. {
  155. CSIPPhoneSession *pSIPPhoneSession;
  156. CSimpleStringA strSession_num;
  157. CSimpleStringA strBranch_server_ip;
  158. int iBranch_server_port;
  159. };
  160. void on_call_state(int state, const char *state_desc, const char *phrase);
  161. int make_call(const char *uri);
  162. void hangup_call(HangupCallCommand *pCmd);
  163. void release_call();
  164. void control_video(ControlVideoCommand *pCmd);
  165. int on_video_box_move(int imessagetype, int ivideotype, int ileft, int ibottom);
  166. static void __on_video_box_move(int imessagetype, int ivideotype, int ileft, int ibottom, void *user_data)
  167. {
  168. CSIPPhoneSession *pThis = static_cast<CSIPPhoneSession*>(user_data);
  169. pThis->on_video_box_move(imessagetype, ivideotype, ileft, ibottom);
  170. }
  171. static void __on_call_state(int state, const char *state_desc, const char *phrase, void *user_data)
  172. {
  173. LOG_FUNCTION();
  174. CSIPPhoneSession *pThis = static_cast<CSIPPhoneSession*>(user_data);
  175. if (pThis->m_iLastState != state) {
  176. pThis->m_iLastState = state;
  177. pThis->on_call_state(state, state_desc, phrase);
  178. }
  179. }
  180. static int __make_call(void *user_data)
  181. {
  182. MakeCallCommand *cmd = (MakeCallCommand*)user_data;
  183. int rc = cmd->pSIPPhoneSession->make_call(cmd->strUri);
  184. delete cmd;
  185. return rc;
  186. }
  187. static int __hangup_call(void *user_data)
  188. {
  189. HangupCallCommand *cmd = (HangupCallCommand*)(user_data);
  190. cmd->pSIPPhoneSession->hangup_call(cmd);
  191. delete cmd;
  192. return 0;
  193. }
  194. static int __control_video(void *arg)
  195. {
  196. ControlVideoCommand *pCmd = (ControlVideoCommand*)(arg);
  197. pCmd->pSIPPhoneSession->control_video(pCmd);
  198. delete pCmd;
  199. return 0;
  200. }
  201. static int __release_call(void *user_data)
  202. {
  203. CSIPPhoneSession *pThis = static_cast<CSIPPhoneSession*>(user_data);
  204. pThis->release_call();
  205. pThis->on_call_state(TERMINATED,"STATE:terminated","byebye");
  206. return 0;
  207. }
  208. private:
  209. SpSubscribeContext<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::Pointer m_spCallbackContext;
  210. endpoint_call_t *m_pCall;
  211. CSIPEntity *m_pEntity;
  212. int m_iLastState;
  213. int m_IsLocalPlay;
  214. eShowVideoWindowType m_VideoWindowPlayType;/*add by clp 20190903 0:only remote video window, 1:only local video window, 2:both local and remote window */
  215. video_session_callback_t m_cb_video_box_move;
  216. };
  217. class CSIPEntity : public CEntityBase, public ILogListener, public ISysVarListener,public ITimerListener
  218. {
  219. public:
  220. CSIPEntity() : m_pCurrentSession(NULL), m_state(INIT),m_iPickupPhoneState(ePickupMicrophoneState_Off)
  221. {
  222. m_kept_volume_in[0] = m_kept_volume_in[1] = 0;
  223. m_kept_volume_out[0] = m_kept_volume_out[1] = 0;
  224. m_pKeeperIn[0] = m_pKeeperIn[1] = NULL;
  225. m_pKeeperOut[0] = m_pKeeperOut[1] = NULL;
  226. m_SipErrorCode = Error_Succeed;
  227. memset((void*)&m_stVideoParam,0,sizeof(stVideoParam));
  228. }
  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)
  234. {
  235. LOG_TRACE("user_code = %08x", dwUserCode);
  236. switch (dwUserCode)
  237. {
  238. case LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE:
  239. {
  240. Dbg("recv LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE");
  241. if (m_pSipphoneChannel != NULL)
  242. {
  243. m_pSipphoneChannel->GetFunction()->CloseSession();
  244. m_pSipphoneChannel->SafeDelete();
  245. m_pSipphoneChannel = NULL;
  246. Dbg("Close AssistChannel Session ");
  247. }
  248. ErrorCodeEnum Error;
  249. if (m_pSipphoneChannel == NULL)
  250. {
  251. Dbg("ReConnection AssistChannel Session");
  252. m_pSipphoneChannel = new ChannelSipphoneClient(this);
  253. Error = m_pSipphoneChannel->Connect();
  254. if (Error != Error_Succeed)
  255. {
  256. m_pSipphoneChannel->SafeDelete();
  257. Dbg("ChannelSipphoneClient connect fail!");
  258. }
  259. if (Error == Error_Succeed)
  260. {
  261. ChannelService_BeginState_Sub Sub;
  262. Error = m_pSipphoneChannel->BeginState(Sub);
  263. if (Error != Error_Succeed)
  264. {
  265. LOG_TRACE("BeginState biz channel failed!");
  266. m_pSipphoneChannel->GetFunction()->CloseSession();
  267. m_pSipphoneChannel->SafeDelete();
  268. m_pSipphoneChannel = NULL;
  269. }
  270. }
  271. if (Error == Error_Succeed)
  272. {
  273. ChannelService_BeginRecv_Sub Sub;
  274. Sub.type = ACM_TYPE_DEVICE;
  275. Error = m_pSipphoneChannel->BeginRecv(Sub);
  276. if (Error != Error_Succeed)
  277. {
  278. Dbg("Begin BeginRecv ACM_TYPE_DEVICE failed!");
  279. m_pSipphoneChannel->GetFunction()->CloseSession();
  280. m_pSipphoneChannel->SafeDelete();
  281. m_pSipphoneChannel = NULL;
  282. }
  283. }
  284. }
  285. }
  286. break;
  287. case EVENT_MOD_CONNECT_HANDFREE_TO_PICKUP:
  288. case EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP:
  289. case EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE:
  290. case EVENT_MOD_CONNECT_PICKUP_TO_HANDFREE:
  291. case EVENT_MOD_CONNECT_PICKUP_CALL:
  292. case EVENT_MOD_CONNECT_SLV_HANDFREECALL:
  293. case EVENT_MOD_CONNECT_SLV_PICKUPCALL:
  294. case LOG_EVT_HANDFREE_MODE_REMOTE_CALL:
  295. case LOG_EVT_PICKUP_MODE_REMOTE_CALL:
  296. {
  297. int old_state = m_iPickupPhoneState;
  298. if (dwUserCode == EVENT_MOD_CONNECT_HANDFREE_TO_PICKUP) { // 免提->提机
  299. m_iPickupPhoneState = ePickupMicrophoneState_On;
  300. }
  301. else if (dwUserCode == EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP) { //坐席控制免提->提机
  302. m_iPickupPhoneState = ePickupMicrophoneState_On;
  303. }
  304. else if (dwUserCode == EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE) { //坐席控制提机->免提
  305. m_iPickupPhoneState = ePickupMicrophoneState_Off;
  306. }
  307. else if (dwUserCode == EVENT_MOD_CONNECT_PICKUP_TO_HANDFREE)
  308. { // // 提机->免提
  309. m_iPickupPhoneState = ePickupMicrophoneState_Off;
  310. }
  311. else if (dwUserCode == EVENT_MOD_CONNECT_PICKUP_CALL)
  312. { // 提机拨号
  313. m_iPickupPhoneState = ePickupMicrophoneState_On;
  314. }
  315. else if (dwUserCode == EVENT_MOD_CONNECT_SLV_HANDFREECALL)
  316. { // 免提拨号
  317. m_iPickupPhoneState = ePickupMicrophoneState_Off;
  318. }
  319. else if (dwUserCode == EVENT_MOD_CONNECT_SLV_PICKUPCALL)
  320. {
  321. // 通过界面拨号,但话筒未挂,进入提机拨号
  322. m_iPickupPhoneState = ePickupMicrophoneState_On;
  323. }
  324. else if (dwUserCode == LOG_EVT_HANDFREE_MODE_REMOTE_CALL)
  325. { // 免提模式开始远程双录连线
  326. m_iPickupPhoneState = ePickupMicrophoneState_Off;
  327. }
  328. else if (dwUserCode == LOG_EVT_PICKUP_MODE_REMOTE_CALL)
  329. {
  330. // 话筒模式开始远程双录连线
  331. m_iPickupPhoneState = ePickupMicrophoneState_On;
  332. }
  333. LOG_TRACE("dwUserCode = 0x%08x,m_iPickupPhoneState %d", dwUserCode, m_iPickupPhoneState);
  334. Dbg("dwUserCode = 0x%08x,old_PhoneState = %d,PickupPhoneState = %d", dwUserCode,old_state, m_iPickupPhoneState);
  335. if (old_state != m_iPickupPhoneState)
  336. {
  337. if (m_iPickupPhoneState == ePickupMicrophoneState_On)
  338. {
  339. SwitchPickup();
  340. }
  341. else
  342. {
  343. SwitchHandFree();
  344. }
  345. }
  346. }
  347. break;
  348. case LOG_EVT_ENTER_ACM_FLOW:
  349. {
  350. Dbg("LOG_EVT_ENTER_ACM_FLOW");
  351. m_stVideoParam.nWindowState = 1;
  352. }
  353. break;
  354. case LOG_EVT_EXIT_ACM_FLOW:
  355. {
  356. Dbg("LOG_EVT_EXIT_ACM_FLOW");
  357. if(m_stVideoParam.nWindowState == 1)
  358. {
  359. m_stVideoParam.nWindowState = 0;
  360. }
  361. }
  362. break;
  363. case LOG_EVT_STARTLIVEDETECTDISPLAY:
  364. {
  365. Dbg("start livedetection display");
  366. m_stVideoParam.bActiveInspect = 1;
  367. }
  368. break;
  369. case LOG_EVT_STOPLIVEDETECTDISPLAY:
  370. {
  371. Dbg("stop livedetection display and show livedetection photo %s",pszMessage);
  372. }
  373. break;
  374. case LOG_EVT_CHANGELIVEDETECTIONCAM:
  375. {
  376. if (pszMessage && strlen(pszMessage) > 0)
  377. {
  378. int i = atoi(pszMessage);
  379. Dbg("change active display camera to %d",i);
  380. m_stVideoParam.iCameraSwitch = i;
  381. }
  382. else
  383. {
  384. Dbg("change active display camera param error");
  385. }
  386. }
  387. break;
  388. case LOG_EVT_RELEASELIVEDETECTION:
  389. {
  390. Dbg("release show active image");
  391. m_stVideoParam.bActiveInspect = 0;
  392. m_stVideoParam.bShowActiveImg = 0;
  393. m_stVideoParam.iCameraSwitch = CAMERA_TYPE_ENV;
  394. }
  395. break;
  396. case LOG_EVT_UI_HIDEONLINEVIDEO:
  397. {
  398. Dbg("Receive UI hide online video evt!");
  399. m_stVideoParam.nWindowState = 2;
  400. }
  401. break;
  402. case LOG_EVT_UI_SHOWONLINEVIDEO:
  403. {
  404. Dbg("Receive UI show online video evt!");
  405. if (m_stVideoParam.nWindowState == 2)
  406. {
  407. m_stVideoParam.nWindowState = 3;
  408. }
  409. }
  410. break;
  411. case LOG_EVT_UI_STARTRECORD:
  412. case LOG_EVT_UI_STARTREMOTERECORD:
  413. {
  414. Dbg("start sales record video.");
  415. m_bIsSalesRecord = TRUE;
  416. g_bIsSalesRecord = m_bIsSalesRecord;
  417. m_bEwsRecord = FALSE;
  418. if (strlen(pszMessage)>=4&&!strnicmp(pszMessage,"ews|",4)){
  419. m_bEwsRecord = TRUE;
  420. }
  421. g_bEwsRecord = m_bEwsRecord;
  422. }
  423. break;
  424. case LOG_EVT_UI_STARTRECORDPREVIEW:
  425. {
  426. Dbg("start sales record preview.");
  427. m_stVideoParam.bShowRecordArea = 1;
  428. Handle_RecordVideoLocation_Info(pszMessage);
  429. }
  430. break;
  431. case LOG_EVT_UI_STOPRECORD:
  432. case LOG_EVT_UI_STOPREMOTERECORD:
  433. {
  434. Dbg("stop sales record video.");
  435. m_bIsSalesRecord = FALSE;
  436. g_bIsSalesRecord = m_bIsSalesRecord;
  437. m_bEwsRecord = FALSE; //add by ly@2019/04/18
  438. g_bEwsRecord = m_bEwsRecord; //add by ly@2019/04/18
  439. if (m_stVideoParam.bShowRecordArea){
  440. Dbg("stop sales record and stop preview.");
  441. m_stVideoParam.bShowRecordArea = 0;
  442. }
  443. }
  444. break;
  445. case LOG_EVT_UI_STOPRECORDPREVIEW:
  446. {
  447. Dbg("stop sales record preview.");
  448. m_stVideoParam.bShowRecordArea = 0;
  449. }
  450. break;
  451. case LOG_EVT_UI_RETURNMENU:
  452. {
  453. Dbg("return menu");
  454. m_bIsSalesRecord = FALSE;
  455. g_bIsSalesRecord = m_bIsSalesRecord;
  456. m_bEwsRecord = FALSE; //add by ly@2019/04/18
  457. g_bEwsRecord = m_bEwsRecord; //add by ly@2019/04/18
  458. }
  459. break;
  460. case LOG_EVT_UI_SHOWLOCALVIDEO:
  461. {
  462. Dbg("Receive UI show all video evt!");
  463. if (m_stVideoParam.nWindowState == 4)
  464. {
  465. m_stVideoParam.nWindowState = 3;
  466. }
  467. }
  468. break;
  469. case LOG_EVT_UI_HIDELOCALVIDEO:
  470. {
  471. Dbg("Receive UI hide local video evt!");
  472. m_stVideoParam.nWindowState = 4;
  473. }
  474. break;
  475. case LOG_EVT_UI_HIDEPERSONAREA:
  476. {
  477. Dbg("Receive UI hide person area!");
  478. m_stVideoParam.bShowPersonArea = 0;
  479. }
  480. break;
  481. case LOG_EVT_UI_SHOWPERSONAREA:
  482. {
  483. Dbg("Receive UI show person area!");
  484. m_stVideoParam.bShowPersonArea = 1;
  485. }
  486. break;
  487. case EVENT_MOD_CONNECT_STOP_RECORD_BROADCAST:
  488. {
  489. Dbg("stop remote record audio broadcast.");
  490. }
  491. break;
  492. case EVENT_MOD_CONNECT_BEGAIN_RECORD_CALL:
  493. {
  494. Dbg("begin double record call.");
  495. }
  496. break;
  497. case LOG_EVT_UI_ADJUSTVIDEOECHOSIZE:
  498. {
  499. Dbg("adjust video echo size %s.", pszMessage);
  500. Handle_AdjustVideoEchoEvent(pszMessage);
  501. }
  502. break;
  503. default:
  504. {
  505. Dbg("unknown dwUserCode = %x.",dwUserCode);
  506. }
  507. break;
  508. }
  509. }
  510. virtual void OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName)
  511. {
  512. if (_stricmp(pszKey, SYSVAR_CAMERASTATE) == 0)
  513. {
  514. Dbg("camera state from : %c to %c", pszOldValue[0], pszValue[0]);
  515. if (pszValue[0] == 'E')
  516. {
  517. m_stVideoParam.iCameraState = CAMERA_TYPE_OPT;
  518. }
  519. else if (pszValue[0] == 'O')
  520. {
  521. m_stVideoParam.iCameraState = CAMERA_TYPE_ENV;
  522. }
  523. else if(pszValue[0] == 'B') ///////显示贴图
  524. {
  525. /////////////////////////此处显示贴图//////////////////////////////////
  526. //m_stVideoParam.iCameraSwitch = CAMERA_TYPE_ERROR;
  527. m_stVideoParam.iCameraState = CAMERA_TYPE_ERROR;
  528. }
  529. else if (pszValue[0] == 'N')
  530. {
  531. m_stVideoParam.iCameraState = CAMERA_TYPE_AUTO;
  532. //m_stVideoParam.iCameraSwitch = CAMERA_TYPE_AUTO;
  533. }
  534. }
  535. else if (_stricmp(pszKey, SYSVAR_ACTIVETRACKINGCAMERA) == 0)
  536. {
  537. Dbg("active camera from : %c to %c", pszOldValue[0], pszValue[0]);
  538. if (pszValue[0] == 'E')
  539. {
  540. m_stVideoParam.iActiveCamera = CAMERA_TYPE_ENV;
  541. }
  542. else if (pszValue[0] == 'O')
  543. {
  544. m_stVideoParam.iActiveCamera = CAMERA_TYPE_OPT;
  545. }
  546. else
  547. {
  548. Dbg("warning: unknown ActiveTrackingCamera value!");
  549. }
  550. }
  551. else if (_stricmp(pszKey, SYSVAR_AGENTCAMERASWITCH) == 0)
  552. {
  553. Dbg("agent camera switch from : %c to %c", pszOldValue[0], pszValue[0]);
  554. if((pszValue[0] == 'E')/*&&((m_iCameraState==CAMERA_TYPE_AUTO)||(m_iCameraState==CAMERA_TYPE_ENV))*/)
  555. {
  556. m_stVideoParam.iCameraSwitch = CAMERA_TYPE_ENV;
  557. }
  558. else if((pszValue[0] == 'O')/*&&((m_iCameraState==CAMERA_TYPE_AUTO)||(m_iCameraState==CAMERA_TYPE_OPT))*/)
  559. {
  560. m_stVideoParam.iCameraSwitch = CAMERA_TYPE_OPT;
  561. }
  562. else if((pszValue[0] == 'A')/*&&(m_iCameraState==CAMERA_TYPE_AUTO)*/)
  563. {
  564. m_stVideoParam.iCameraSwitch = CAMERA_TYPE_AUTO;
  565. }
  566. }
  567. else if (_stricmp(pszKey, SYSVAR_CALLTYPE) == 0)
  568. {
  569. Dbg("sys calltype from: %c to %c", pszOldValue[0], pszValue[0]);
  570. if(pszValue[0] == CALLTYPE_NORMAL)
  571. {
  572. m_nSysCallType = 0;
  573. }
  574. else if(pszValue[0] == CALLTYPE_MOBILE)
  575. {
  576. m_nSysCallType = 1;
  577. }
  578. else
  579. {
  580. m_nSysCallType =-1;
  581. }
  582. }
  583. }
  584. virtual void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  585. {
  586. if (Test_ShakeHand == eTestType)
  587. {
  588. pTransactionContext->SendAnswer(m_SipErrorCode);
  589. }
  590. }
  591. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  592. {
  593. ErrorCodeEnum Error = __OnStart(Error_Succeed);
  594. pTransactionContext->SendAnswer(Error);
  595. }
  596. virtual void OnStarted()
  597. {
  598. ErrorCodeEnum Error = Error_Succeed;
  599. m_pSelfcheckClient = new SelfChekerClient(this);
  600. Error = m_pSelfcheckClient->Connect();
  601. if (Error != Error_Succeed)
  602. {
  603. m_pSelfcheckClient->SafeDelete();
  604. m_pSelfcheckClient = NULL;
  605. Dbg("SelfcheckClient connect fail!");
  606. }
  607. else
  608. {
  609. Dbg("SelfcheckClient connect success!");
  610. }
  611. }
  612. ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError)
  613. {
  614. ErrorCodeEnum Error;
  615. //MessageBoxA(0,0,0,0);
  616. m_nCallType = NORMAL_CALLTYPE;
  617. m_nSysCallType = 0;
  618. m_pSipphoneChannel = new ChannelSipphoneClient(this);
  619. memset(m_localip,0,256);
  620. Error = m_pSipphoneChannel->Connect();
  621. if (Error != Error_Succeed)
  622. {
  623. m_pSipphoneChannel->SafeDelete();
  624. Dbg("ChannelSipphoneClient connect fail!");
  625. return Error;
  626. }
  627. {
  628. ChannelService_BeginState_Sub Sub;
  629. Error = m_pSipphoneChannel->BeginState(Sub);
  630. if (Error != Error_Succeed)
  631. {
  632. LOG_TRACE("BeginState biz channel failed!");
  633. m_pSipphoneChannel->GetFunction()->CloseSession();
  634. m_pSipphoneChannel->SafeDelete();
  635. m_pSipphoneChannel = NULL;
  636. return Error;
  637. }
  638. }
  639. {
  640. ChannelService_BeginRecv_Sub Sub;
  641. Sub.type = ACM_TYPE_DEVICE;
  642. Error = m_pSipphoneChannel->BeginRecv(Sub);
  643. if (Error != Error_Succeed)
  644. {
  645. Dbg("Begin BeginRecv ACM_TYPE_DEVICE failed!");
  646. m_pSipphoneChannel->GetFunction()->CloseSession();
  647. m_pSipphoneChannel->SafeDelete();
  648. m_pSipphoneChannel = NULL;
  649. return Error;
  650. }
  651. }
  652. {
  653. ChannelService_BeginRecv_Sub Sub;
  654. Sub.type = ACM_TYPE_VIDEOFREQ;
  655. Error = m_pSipphoneChannel->BeginRecv(Sub);
  656. if (Error != Error_Succeed)
  657. {
  658. Dbg("Begin BeginRecv ACM_TYPE_VIDEOFREQ failed!");
  659. m_pSipphoneChannel->GetFunction()->CloseSession();
  660. m_pSipphoneChannel->SafeDelete();
  661. m_pSipphoneChannel = NULL;
  662. return Error;
  663. }
  664. }
  665. {
  666. m_pSelfcheckClient = new SelfChekerClient(this);
  667. Error = m_pSelfcheckClient->Connect();
  668. if (Error != Error_Succeed)
  669. {
  670. m_pSelfcheckClient->SafeDelete();
  671. m_pSelfcheckClient = NULL;
  672. Dbg("SelfcheckClient connect fail!");
  673. }
  674. else
  675. {
  676. Dbg("SelfcheckClient connect success!");
  677. }
  678. }
  679. m_eDeviceType = RvcGetDeviceType();
  680. m_stVideoParam.bActiveInspect = 0;
  681. m_stVideoParam.bShowActiveImg = 0;
  682. m_bIsSalesRecord = FALSE;
  683. g_bIsSalesRecord = m_bIsSalesRecord;
  684. m_bEwsRecord = FALSE;
  685. g_bEwsRecord = m_bEwsRecord;
  686. m_stVideoParam.nWindowState = 0;
  687. m_RecordVideoLocation.x = 0;
  688. m_RecordVideoLocation.y = 0;
  689. m_RecordVideoLocation.width = DEFAULT_RECORD_VIDEO_WIDTH;
  690. m_RecordVideoLocation.height = DEFAULT_RECORD_VIDEO_HEIGHT;
  691. LOG_FUNCTION();
  692. video_lib_init();
  693. audio_lib_init();
  694. endpoint_init_lib();
  695. Error = GetLocalIP();
  696. if (Error != 0)
  697. {
  698. LOG_TRACE("get local ip failed!");
  699. return Error;
  700. }
  701. Error = LoadConfig(&conf);
  702. if (Error != Error_Succeed)
  703. {
  704. LOG_TRACE("load config failed!");
  705. return Error;
  706. }
  707. int nhandfreeout = 0;
  708. int npickupout = 0;
  709. int nhanfreein = 0;
  710. int npickupin = 0;
  711. Error = LoadAudioRunConfig(nhandfreeout,npickupout,nhanfreein,npickupin);
  712. if (Error == Error_Succeed)
  713. {
  714. if (nhandfreeout > 0)
  715. {
  716. m_kept_volume_out[DEV_HANDFREE] = nhandfreeout;
  717. }
  718. if (npickupout > 0)
  719. {
  720. m_kept_volume_out[DEV_PICKUP] = npickupout;
  721. }
  722. if (nhanfreein > 0)
  723. {
  724. m_kept_volume_in[DEV_HANDFREE] = nhanfreein;
  725. }
  726. if (npickupin > 0)
  727. {
  728. m_kept_volume_in[DEV_PICKUP] = npickupin;
  729. }
  730. }
  731. {
  732. CSmartPointer<IEntityFunction> Func = GetFunction();
  733. Func->GetSystemStaticInfo(staticInfo);
  734. }
  735. CSimpleStringA strUri = MakeUri(staticInfo.strTerminalID);
  736. if (strUri.GetLength() > 0)
  737. {
  738. strcpy(conf.uri, strUri);
  739. conf.media_start_port = REC_COMMON_AUDIO_PORT_START;
  740. conf.media_stop_port = REC_COMMON_AUDIO_PORT_STOP;
  741. m_pEndpoint = endpoint_create(this, &conf,DEV_HANDFREE);
  742. if (!m_pEndpoint) {
  743. LOG_TRACE("create endpoint failed!");
  744. return Error_Unexpect;
  745. }
  746. else{
  747. Dbg("__OnStart call uri is %s, endpoint_create m_pEndpoint addr is %0x.",conf.uri, m_pEndpoint);
  748. }
  749. }
  750. else
  751. {
  752. LOG_TRACE("strUri length equals zero!");
  753. return Error_Unexpect;
  754. }
  755. {
  756. CSmartPointer<IEntityFunction> Func = GetFunction();
  757. CUUID id;
  758. int i = 0;
  759. m_arrListener.Init(32);
  760. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANDFREE_TO_PICKUP, EVT_CONVERTER);
  761. m_arrListener[i++] = id;
  762. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_PICKUP_TO_HANDFREE, EVT_CONVERTER);
  763. m_arrListener[i++] = id;
  764. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_PICKUP_CALL, EVT_CONVERTER);
  765. m_arrListener[i++] = id;
  766. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_SLV_HANDFREECALL,NULL,false);
  767. m_arrListener[i++] = id;
  768. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_SLV_PICKUPCALL,NULL,false);
  769. m_arrListener[i++] = id;
  770. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP,NULL,false);
  771. m_arrListener[i++] = id;
  772. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE,NULL,false);
  773. m_arrListener[i++] = id;
  774. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE,NULL,false);
  775. m_arrListener[i++] = id;
  776. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_ENTER_ACM_FLOW,NULL,false);
  777. m_arrListener[i++] = id;
  778. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_EXIT_ACM_FLOW,NULL,false);
  779. m_arrListener[i++] = id;
  780. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_STARTLIVEDETECTDISPLAY,NULL,false);
  781. m_arrListener[i++] = id;
  782. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_STOPLIVEDETECTDISPLAY,NULL,false);
  783. m_arrListener[i++] = id;
  784. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_CHANGELIVEDETECTIONCAM,NULL,false);
  785. m_arrListener[i++] = id;
  786. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_RELEASELIVEDETECTION,NULL,false);
  787. m_arrListener[i++] = id;
  788. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_HIDEONLINEVIDEO,NULL,false);
  789. m_arrListener[i++] = id;
  790. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_SHOWONLINEVIDEO,NULL,false);
  791. m_arrListener[i++] = id;
  792. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORD,NULL,false);
  793. m_arrListener[i++] = id;
  794. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPRECORD,NULL,false);
  795. m_arrListener[i++] = id;
  796. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RETURNMENU,NULL,false);
  797. m_arrListener[i++] = id;
  798. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_HIDELOCALVIDEO,NULL,false);
  799. m_arrListener[i++] = id;
  800. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_SHOWLOCALVIDEO,NULL,false);
  801. m_arrListener[i++] = id;
  802. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_HIDEPERSONAREA,NULL,false);
  803. m_arrListener[i++] = id;
  804. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_SHOWPERSONAREA,NULL,false);
  805. m_arrListener[i++] = id;
  806. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_STOP_RECORD_BROADCAST,NULL,false);
  807. m_arrListener[i++] = id;
  808. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_BEGAIN_RECORD_CALL,NULL,false);
  809. m_arrListener[i++] = id;
  810. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTREMOTERECORD,NULL,false);
  811. m_arrListener[i++] = id;
  812. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPREMOTERECORD,NULL,false);
  813. m_arrListener[i++] = id;
  814. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_HANDFREE_MODE_REMOTE_CALL,NULL,false);
  815. m_arrListener[i++] = id;
  816. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_PICKUP_MODE_REMOTE_CALL,NULL,false);
  817. m_arrListener[i++] = id;
  818. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORDPREVIEW,NULL,false);
  819. m_arrListener[i++] = id;
  820. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPRECORDPREVIEW,NULL,false);
  821. m_arrListener[i++] = id;
  822. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_ADJUSTVIDEOECHOSIZE,NULL,false);
  823. m_arrListener[i++] = id;
  824. }
  825. {
  826. CSmartPointer<IEntityFunction> Func = GetFunction();
  827. CSimpleStringA strValue;
  828. Func->RegistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA, this);
  829. Func->GetSysVar(SYSVAR_ACTIVETRACKINGCAMERA, strValue);
  830. if (strValue[0] == 'E')
  831. {
  832. m_stVideoParam.iActiveCamera = CAMERA_TYPE_ENV;
  833. }
  834. else if (strValue[0] == 'O')
  835. {
  836. m_stVideoParam.iActiveCamera = CAMERA_TYPE_OPT;
  837. }
  838. else
  839. {
  840. assert(0);
  841. }
  842. }
  843. {
  844. CSmartPointer<IEntityFunction> Func = GetFunction();
  845. CSimpleStringA strValue;
  846. Func->RegistSysVarEvent(SYSVAR_CAMERASTATE, this);
  847. Func->GetSysVar(SYSVAR_CAMERASTATE, strValue);
  848. if (strValue[0] == 'E')
  849. {
  850. m_stVideoParam.iCameraState = CAMERA_TYPE_OPT;
  851. }
  852. else if (strValue[0] == 'O')
  853. {
  854. m_stVideoParam.iCameraState = CAMERA_TYPE_ENV;
  855. }
  856. else if(strValue[0] == 'B') ///////显示贴图
  857. {
  858. /////////////////////////此处显示贴图//////////////////////////////////
  859. //m_stVideoParam.iCameraSwitch = CAMERA_TYPE_ERROR;
  860. m_stVideoParam.iCameraState = CAMERA_TYPE_ERROR;
  861. }
  862. else if (strValue[0] == 'N')
  863. {
  864. //m_stVideoParam.iCameraSwitch = CAMERA_TYPE_AUTO;
  865. m_stVideoParam.iCameraState = CAMERA_TYPE_AUTO;
  866. }
  867. }
  868. {
  869. CSmartPointer<IEntityFunction> Func = GetFunction();
  870. CSimpleStringA strValue;
  871. Func->RegistSysVarEvent(SYSVAR_AGENTCAMERASWITCH, this);
  872. Func->GetSysVar(SYSVAR_AGENTCAMERASWITCH, strValue);
  873. if((strValue[0] == 'E')/*&&((m_iCameraState == CAMERA_TYPE_AUTO)||(m_iCameraState = CAMERA_TYPE_ENV))*/)
  874. {
  875. m_stVideoParam.iCameraSwitch = CAMERA_TYPE_ENV;
  876. }
  877. else if((strValue[0] == 'O')/*&&((m_iCameraState == CAMERA_TYPE_AUTO)||(m_iCameraState = CAMERA_TYPE_OPT))*/)
  878. {
  879. m_stVideoParam.iCameraSwitch = CAMERA_TYPE_OPT;
  880. }
  881. else if ((strValue[0] == 'A')/*&&(m_iCameraState == CAMERA_TYPE_AUTO)*/)
  882. {
  883. m_stVideoParam.iCameraSwitch = CAMERA_TYPE_AUTO;
  884. }
  885. }
  886. {
  887. CSmartPointer<IEntityFunction> Func = GetFunction();
  888. CSimpleStringA strValue;
  889. Func->RegistSysVarEvent(SYSVAR_CALLTYPE, this);
  890. Func->GetSysVar(SYSVAR_CALLTYPE, strValue);
  891. if (strValue[0] == CALLTYPE_NORMAL)
  892. {
  893. m_nSysCallType = 0;
  894. }
  895. else if (strValue[0] == CALLTYPE_MOBILE)
  896. {
  897. m_nSysCallType = 1;
  898. }
  899. else
  900. {
  901. assert(0);
  902. }
  903. }
  904. #ifdef RVC_OS_WIN
  905. if (m_kept_volume_in[DEV_HANDFREE])
  906. {
  907. m_pKeeperIn[DEV_HANDFREE] = volume_keeper_create(conf.audio_handfree_in_dev, 1, m_kept_volume_in[DEV_HANDFREE]);
  908. if (m_pKeeperIn[DEV_HANDFREE])
  909. {
  910. Dbg("HANDFREE in volume keeper create ok! %d", m_kept_volume_in[DEV_HANDFREE]);
  911. }
  912. else
  913. {
  914. Dbg("HANDFREE in volume keeper create failed!");
  915. }
  916. }
  917. if (m_kept_volume_out[DEV_HANDFREE])
  918. {
  919. m_pKeeperOut[DEV_HANDFREE] = volume_keeper_create(conf.audio_handfree_out_dev, 0, m_kept_volume_out[DEV_HANDFREE]);
  920. if (m_pKeeperOut[DEV_HANDFREE])
  921. {
  922. Dbg("HANDFREE out volume keeper create ok! %d", m_kept_volume_out[DEV_HANDFREE]);
  923. }
  924. else
  925. {
  926. Dbg("HANDFREE out volume keeper create failed!");
  927. }
  928. }
  929. if (m_kept_volume_in[DEV_PICKUP]&&(eStand2sType == m_eDeviceType)) //pad版屏蔽pickup
  930. {
  931. m_pKeeperIn[DEV_PICKUP] = volume_keeper_create(conf.audio_pickup_in_dev, 1, m_kept_volume_in[DEV_PICKUP]);
  932. if (m_pKeeperIn[DEV_PICKUP])
  933. {
  934. Dbg("PICKUP in volume keeper create ok! %d", m_kept_volume_in[DEV_PICKUP]);
  935. }
  936. else
  937. {
  938. Dbg("PICKUP in volume keeper create failed!");
  939. }
  940. }
  941. if (m_kept_volume_out[DEV_PICKUP]&&(eStand2sType == m_eDeviceType)) //pad版屏蔽pickup
  942. {
  943. m_pKeeperOut[DEV_PICKUP] = volume_keeper_create(conf.audio_pickup_out_dev, 0, m_kept_volume_out[DEV_PICKUP]);
  944. if (m_pKeeperOut[DEV_PICKUP])
  945. {
  946. Dbg("PICKUP out volume keeper create ok! %d", m_kept_volume_out[DEV_PICKUP]);
  947. }
  948. else
  949. {
  950. Dbg("PICKUP out volume keeper create failed!");
  951. }
  952. }
  953. #else
  954. #endif // RVC_OS_WIN
  955. return Error_Succeed;
  956. }
  957. video_session_t *video_session;
  958. //volumn adjust
  959. void OnReceivePkt(int type, int sub_type, const char *buffer, int size)
  960. {
  961. if (type == ACM_TYPE_DEVICE)
  962. {
  963. if (sub_type == ACM_SET_HANDFREE_OUTVOLUMN)
  964. {
  965. CVolumnValue num;
  966. SpBuffer buf;
  967. buf.OpenRead(buffer,size);
  968. num.Serialize(buf);
  969. Dbg("recv adj handfree out volumn = %d",num.nValue);
  970. if (m_pKeeperOut[DEV_HANDFREE])
  971. {
  972. volume_keeper_change(m_pKeeperOut[DEV_HANDFREE],num.nValue);
  973. m_kept_volume_out[DEV_HANDFREE] = num.nValue;
  974. SendAudioDeviceVolumn(DEVICE_HANDFREE_OUT);
  975. SaveAudioRunConfig(m_kept_volume_out[DEV_HANDFREE],m_kept_volume_out[DEV_PICKUP],m_kept_volume_in[DEV_HANDFREE],m_kept_volume_in[DEV_PICKUP]);
  976. }
  977. else
  978. {
  979. Dbg("HANDFREE out volume keeper create failed!");
  980. }
  981. }
  982. else if((sub_type == ACM_SET_PICKUP_OUTVOLUMN)&&(eStand2sType == m_eDeviceType))
  983. {
  984. CVolumnValue num;
  985. SpBuffer buf;
  986. buf.OpenRead(buffer,size);
  987. num.Serialize(buf);
  988. Dbg("recv adj pickup out volumn = %d",num.nValue);
  989. if (m_pKeeperOut[DEV_PICKUP])
  990. {
  991. if(eStand2sType == m_eDeviceType)
  992. {
  993. volume_keeper_change(m_pKeeperOut[DEV_PICKUP],num.nValue);
  994. m_kept_volume_out[DEV_PICKUP] = num.nValue;
  995. SendAudioDeviceVolumn(DEVICE_PICKUP_OUT);
  996. SaveAudioRunConfig(m_kept_volume_out[DEV_HANDFREE],m_kept_volume_out[DEV_PICKUP],m_kept_volume_in[DEV_HANDFREE],m_kept_volume_in[DEV_PICKUP]);
  997. }
  998. else //pad版屏蔽当前PICKUP音量设置
  999. {
  1000. Dbg("PAD type, ignore pickupout volume adj");
  1001. }
  1002. }
  1003. else
  1004. {
  1005. Dbg("PICKUP out volume keeper create failed!");
  1006. }
  1007. }
  1008. else if (sub_type == ACM_SET_HANDFREE_INVOLUMN)
  1009. {
  1010. CVolumnValue num;
  1011. SpBuffer buf;
  1012. buf.OpenRead(buffer,size);
  1013. num.Serialize(buf);
  1014. Dbg("recv adj handfree in volumn = %d",num.nValue);
  1015. if (m_pKeeperIn[DEV_HANDFREE])
  1016. {
  1017. volume_keeper_change(m_pKeeperIn[DEV_HANDFREE],num.nValue);
  1018. m_kept_volume_in[DEV_HANDFREE] = num.nValue;
  1019. SendAudioDeviceVolumn(DEVICE_HANDFREE_IN);
  1020. SaveAudioRunConfig(m_kept_volume_out[DEV_HANDFREE],m_kept_volume_out[DEV_PICKUP],m_kept_volume_in[DEV_HANDFREE],m_kept_volume_in[DEV_PICKUP]);
  1021. }
  1022. else
  1023. {
  1024. Dbg("handfree in volume keeper create failed!");
  1025. }
  1026. }
  1027. else if((sub_type == ACM_SET_PICKUP_INVOLUMN)&&(eStand2sType == m_eDeviceType))
  1028. {
  1029. CVolumnValue num;
  1030. SpBuffer buf;
  1031. buf.OpenRead(buffer,size);
  1032. num.Serialize(buf);
  1033. Dbg("recv adj pickup in volume = %d",num.nValue);
  1034. if (m_pKeeperIn[DEV_PICKUP])
  1035. {
  1036. if(eStand2sType == m_eDeviceType)
  1037. {
  1038. volume_keeper_change(m_pKeeperIn[DEV_PICKUP],num.nValue);
  1039. m_kept_volume_in[DEV_PICKUP] = num.nValue;
  1040. SendAudioDeviceVolumn(DEVICE_PICKUP_IN);
  1041. SaveAudioRunConfig(m_kept_volume_out[DEV_HANDFREE],m_kept_volume_out[DEV_PICKUP],m_kept_volume_in[DEV_HANDFREE],m_kept_volume_in[DEV_PICKUP]);
  1042. }
  1043. else //pad版屏蔽当前PICKUP音量设置
  1044. {
  1045. Dbg("PAD type, ignore pickupin volume adj");
  1046. }
  1047. }
  1048. else
  1049. {
  1050. Dbg("pickup in volume keeper create failed!");
  1051. }
  1052. }
  1053. else if (sub_type == ACM_CONTROL_PERSONAREA) //控制人形框
  1054. {
  1055. CVolumnValue num;
  1056. SpBuffer buf;
  1057. buf.OpenRead(buffer,size);
  1058. num.Serialize(buf);
  1059. Dbg("recv control personarea subtype = %d",num.nValue);
  1060. if (num.nValue == 0) //隐藏人形框
  1061. {
  1062. //LogEvent(Severity_Middle,LOG_EVT_UI_HIDEPERSONAREA,"Agent send Hide Person area");
  1063. //if((eMobilePadType == m_eDeviceType)||(ePadtype == m_eDeviceType)||(eDesk2SType == m_eDeviceType))
  1064. //{
  1065. LogEvent(Severity_Middle,LOG_EVT_UI_HIDELOCALVIDEO,"Agent send hide local video");
  1066. LogEvent(Severity_Middle,LOG_EVT_UI_HIDEPERSONAREA,"Agent send Hide Person area");
  1067. //}
  1068. }
  1069. else if (num.nValue == 1) //显示人形框
  1070. {
  1071. //LogEvent(Severity_Middle,LOG_EVT_UI_SHOWPERSONAREA,"Agent send Show Person area");
  1072. //if((eMobilePadType == m_eDeviceType)||(ePadtype == m_eDeviceType)||(eDesk2SType == m_eDeviceType))
  1073. //{
  1074. LogEvent(Severity_Middle,LOG_EVT_UI_SHOWLOCALVIDEO,"Agent send show local video");
  1075. LogEvent(Severity_Middle,LOG_EVT_UI_SHOWPERSONAREA,"Agent send Show Person area");
  1076. //}
  1077. }
  1078. else
  1079. {
  1080. Dbg("recv control personarea sub_type error!");
  1081. }
  1082. }
  1083. }
  1084. else if (type == ACM_TYPE_VIDEOFREQ)
  1085. {
  1086. if (eMobilePadType == m_eDeviceType)
  1087. {
  1088. CFpsValue nFps;
  1089. SpBuffer buf;
  1090. buf.OpenRead(buffer,size);
  1091. nFps.Serialize(buf);
  1092. Dbg("adj up stream fps to %d",nFps.nValue);
  1093. if((m_stVideoParam.nUpDynamicFps == 1)&&(nFps.nValue!=1))
  1094. {
  1095. GetFunction()->KillTimer(1);
  1096. }
  1097. else if (nFps.nValue==1)
  1098. {
  1099. //如果1帧每秒维持20秒,停止视频
  1100. Dbg("start timer for up fps");
  1101. GetFunction()->SetTimer(1, this, 20000);
  1102. }
  1103. m_stVideoParam.nUpDynamicFps = nFps.nValue;
  1104. }
  1105. else
  1106. {
  1107. Dbg("not mobile pad,ignore down message!");
  1108. }
  1109. }
  1110. }
  1111. ErrorCodeEnum GetLocalIP()
  1112. {
  1113. #ifdef RVC_OS_WIN
  1114. char tmp[MAX_PATH] = { 0 };
  1115. gethostname(tmp, sizeof(tmp));
  1116. hostent* ent = gethostbyname(tmp);
  1117. if (ent) {
  1118. for (int i = 0; ent->h_addr_list[i]; ++i) {
  1119. if (ent->h_addrtype == AF_INET) {
  1120. struct in_addr* in = (struct in_addr*)ent->h_addr_list[i];
  1121. char* p = inet_ntoa(*in);
  1122. if (p[0] != '0')
  1123. {
  1124. if (strstr(p, "198.168.") == NULL)
  1125. {
  1126. strcpy(m_localip, p);
  1127. Dbg("local ip == %s", m_localip);
  1128. return Error_Succeed;
  1129. }
  1130. }
  1131. }
  1132. }
  1133. }
  1134. return Error_Unexpect;
  1135. #else
  1136. ErrorCodeEnum error = Error_Unexpect;
  1137. int sockfd = -1;
  1138. struct ifconf ifconf;
  1139. struct ifreq* ifreq = NULL;
  1140. char strbuf[MAX_PATH] = {0};
  1141. ifconf.ifc_len = MAX_PATH;
  1142. ifconf.ifc_buf = strbuf;
  1143. if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
  1144. Dbg("socket error");
  1145. return error;
  1146. }
  1147. ioctl(sockfd, SIOCGIFCONF, &ifconf); //get all socket info
  1148. ifreq = (struct ifreq*)ifconf.ifc_buf;
  1149. for (int i = (ifconf.ifc_len / sizeof(struct ifreq)); i > 0; i--){
  1150. if (ifreq->ifr_flags == AF_INET) { //for ipv4
  1151. char* strIP = inet_ntoa(((struct sockaddr_in*) & (ifreq->ifr_addr))->sin_addr);
  1152. Dbg("name =[%s], local addr = [%s]", ifreq->ifr_name, strIP);
  1153. ifreq++;
  1154. if (NULL != strIP){
  1155. if (NULL == strstr(strIP, "198.168.") && NULL == strstr(strIP, "127.0.0.1"))
  1156. {
  1157. strcpy(m_localip, strIP);
  1158. Dbg("local ip == %s", m_localip);
  1159. error = Error_Succeed;
  1160. break;
  1161. }
  1162. }
  1163. }
  1164. }
  1165. return error;
  1166. #endif // RVC_OS_WIN
  1167. }
  1168. //send DynamicFps
  1169. void SendDynamicFps(int nFps)
  1170. {
  1171. if (eMobilePadType == m_eDeviceType)
  1172. {
  1173. ChannelService_Send_Info Info;
  1174. Info.compress = false;
  1175. Info.encrypt = false;
  1176. Info.type = ACM_TYPE_VIDEOFREQ;
  1177. Info.id = 0;
  1178. Info.sub_type = ACM_VIDEOFREQ_DOWN;
  1179. Info.data.Alloc(sizeof(int));
  1180. SpBuffer buf;
  1181. buf.OpenWrite();
  1182. buf & nFps;
  1183. Info.data = buf.ToBlob();
  1184. m_pSipphoneChannel->Send(Info);
  1185. Dbg("adj down stream fps to %d",nFps);
  1186. }
  1187. else
  1188. {
  1189. Dbg("not mobile pad,ignore up message!");
  1190. }
  1191. }
  1192. //send audio device volume
  1193. void SendAudioDeviceVolumn(int nDevice)
  1194. {
  1195. if (m_nSysCallType == 0)
  1196. {
  1197. ChannelService_Send_Info Info;
  1198. Info.compress = false;
  1199. Info.encrypt = false;
  1200. Info.type = ACM_TYPE_DEVICE;
  1201. Info.id = 0;
  1202. void*keeper = NULL;
  1203. if (nDevice == DEVICE_HANDFREE_OUT)
  1204. {
  1205. Info.sub_type = ACM_HANDFREE_OUTVOLUMN;
  1206. keeper = m_pKeeperOut[DEV_HANDFREE];
  1207. }
  1208. else if(nDevice == DEVICE_PICKUP_OUT)
  1209. {
  1210. if(eStand2sType == m_eDeviceType)
  1211. {
  1212. Info.sub_type = ACM_PICKUP_OUTVOLUMN;
  1213. keeper = m_pKeeperOut[DEV_PICKUP];
  1214. }
  1215. else //pad版屏蔽当前PICKUP音量发送
  1216. {
  1217. return;
  1218. }
  1219. }
  1220. else if(nDevice == DEVICE_HANDFREE_IN)
  1221. {
  1222. Info.sub_type = ACM_HANDFREE_INVOLUMN;
  1223. keeper = m_pKeeperIn[DEV_HANDFREE];
  1224. }
  1225. else if(nDevice == DEVICE_PICKUP_IN)
  1226. {
  1227. if(eStand2sType == m_eDeviceType)
  1228. {
  1229. Info.sub_type = ACM_PICKUP_INVOLUMN;
  1230. keeper = m_pKeeperIn[DEV_PICKUP];
  1231. }
  1232. else //pad版屏蔽当前PICKUP音量发送
  1233. {
  1234. return;
  1235. }
  1236. }
  1237. Info.data.Alloc(sizeof(int));
  1238. SpBuffer buf;
  1239. buf.OpenWrite();
  1240. int nValue = 0;
  1241. bool rslt = false;
  1242. if (keeper)
  1243. {
  1244. rslt = get_audiodevice_volumn(keeper,&nValue);
  1245. }
  1246. if (rslt == true)
  1247. {
  1248. buf & nValue;
  1249. Info.data = buf.ToBlob();
  1250. m_pSipphoneChannel->Send(Info);
  1251. Dbg("send cur Audio device %d,value = %d",nDevice,nValue);
  1252. }
  1253. else
  1254. {
  1255. Dbg("Get cur Audio device %d volume Fail!",nDevice);
  1256. }
  1257. }
  1258. else
  1259. {
  1260. Dbg("cur call type cannot send pkt");
  1261. }
  1262. }
  1263. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  1264. {
  1265. ErrorCodeEnum Error = __OnClose(Error_Succeed);
  1266. pTransactionContext->SendAnswer(Error);
  1267. }
  1268. ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError)
  1269. {
  1270. LOG_FUNCTION();
  1271. int i;
  1272. if (m_pKeeperIn[DEV_HANDFREE]) {
  1273. volume_keeper_destroy(m_pKeeperIn[DEV_HANDFREE]);
  1274. m_pKeeperIn[DEV_HANDFREE] = NULL;
  1275. }
  1276. if (m_pKeeperOut[DEV_HANDFREE]) {
  1277. volume_keeper_destroy(m_pKeeperOut[DEV_HANDFREE]);
  1278. m_pKeeperOut[DEV_HANDFREE] = NULL;
  1279. }
  1280. if (m_pKeeperIn[DEV_PICKUP]) {
  1281. volume_keeper_destroy(m_pKeeperIn[DEV_PICKUP]);
  1282. m_pKeeperIn[DEV_PICKUP] = NULL;
  1283. }
  1284. if (m_pKeeperOut[DEV_PICKUP]) {
  1285. volume_keeper_destroy(m_pKeeperOut[DEV_PICKUP]);
  1286. m_pKeeperOut[DEV_PICKUP] = NULL;
  1287. }
  1288. CSmartPointer<IEntityFunction> Func = GetFunction();
  1289. Func->UnregistSysVarEvent(SYSVAR_AGENTCAMERASWITCH);
  1290. Func->UnregistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA);
  1291. Func->UnregistSysVarEvent(SYSVAR_CAMERASTATE);
  1292. Func->UnregistSysVarEvent(SYSVAR_CALLTYPE);
  1293. for (i = 0; i < m_arrListener.GetCount(); ++i) {
  1294. Func->UnsubscribeLog(m_arrListener[i]);
  1295. }
  1296. m_arrListener.Clear();
  1297. Dbg("__OnClose endpoint_destroy m_pEndpoint addr is %0x.",m_pEndpoint);
  1298. endpoint_destroy(m_pEndpoint);
  1299. m_pEndpoint = NULL;
  1300. video_lib_deinit();
  1301. audio_lib_deinit();
  1302. endpoint_deinit_lib();
  1303. return Error_Succeed;
  1304. }
  1305. /////////////////////////////////////////////////////////////////////
  1306. #if 1
  1307. virtual void OnPaused()
  1308. {
  1309. int rc;
  1310. video_session_conf_t conf = {0};
  1311. conf.bit_rate = 256*1024;
  1312. conf.local_rtp_ip = htonl(INADDR_LOOPBACK);
  1313. conf.local_rtp_port = 3000;
  1314. conf.local_video_view_cx = 320;
  1315. conf.local_video_view_cy = 240;
  1316. conf.local_video_view_x = 0;
  1317. conf.local_video_view_y = 0;
  1318. conf.mtu = 1500;
  1319. conf.remote_rtp_ip = htonl(INADDR_LOOPBACK);
  1320. conf.remote_rtp_port = 3000;
  1321. conf.remote_video_view_cx = 320;
  1322. conf.remote_video_view_cy = 320;
  1323. conf.remote_video_view_x = 0;
  1324. conf.remote_video_view_y = 320;
  1325. conf.video_quant = 3;
  1326. conf.remote_video_width = 320;
  1327. conf.remote_video_height = 320;
  1328. conf.ref_active_camera = &m_stVideoParam.iActiveCamera;
  1329. video_session_create(&conf, &video_session);
  1330. video_session_start(video_session);
  1331. }
  1332. virtual void OnContinued()
  1333. {
  1334. video_session_stop(video_session);
  1335. video_session_destroy(video_session);
  1336. }
  1337. #endif
  1338. /////////////////////////////////////////////////////////////////////
  1339. virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszClass*/)
  1340. {
  1341. LOG_FUNCTION();
  1342. m_pCurrentSession = new CSIPPhoneSession(this);
  1343. return m_pCurrentSession;
  1344. }
  1345. virtual bool IsService()const{return true;}
  1346. virtual void OnTimeout(DWORD dwTimerID)
  1347. {
  1348. if (dwTimerID == 1)
  1349. {
  1350. //如果当前动态帧频不等于之前的帧频,发送当前帧频
  1351. //if (g_nDynamicFps != m_nDownDynamicFps)
  1352. //{
  1353. // m_nDownDynamicFps = g_nDynamicFps;
  1354. // SendDynamicFps(g_nDynamicFps);
  1355. //}
  1356. Dbg("stop up stream!");
  1357. GetFunction()->KillTimer(1);
  1358. m_stVideoParam.nUpDynamicFps = -1;
  1359. }
  1360. }
  1361. bool IsCurrentSession(CServerSessionBase * pSession) { return m_pCurrentSession == pSession; }
  1362. endpoint_t *GetEndpoint() { return m_pEndpoint; }
  1363. ErrorCodeEnum InitEndpoint()
  1364. {
  1365. ErrorCodeEnum eCode = Error_Param;
  1366. CSmartPointer<IEntityFunction> Func = GetFunction();
  1367. Func->GetSystemStaticInfo(staticInfo);
  1368. CSimpleStringA strUri = MakeUri(staticInfo.strTerminalID);
  1369. if (strUri.GetLength() > 0)
  1370. {
  1371. strcpy(conf.uri, strUri);
  1372. conf.media_start_port = REC_COMMON_AUDIO_PORT_START;
  1373. conf.media_stop_port = REC_COMMON_AUDIO_PORT_STOP;
  1374. m_pEndpoint = endpoint_create(this, &conf,DEV_HANDFREE);
  1375. if (!m_pEndpoint) {
  1376. LOG_TRACE("create endpoint failed!");
  1377. eCode = Error_Unexpect;
  1378. }
  1379. else{
  1380. Dbg("__OnStart endpoint_create m_pEndpoint addr is %0x.", m_pEndpoint);
  1381. eCode = Error_Succeed;
  1382. }
  1383. }
  1384. else
  1385. {
  1386. LOG_TRACE("strUri length equals zero!");
  1387. eCode = Error_Unexpect;
  1388. }
  1389. return eCode;
  1390. }
  1391. struct ChangeDevCommand
  1392. {
  1393. CSIPEntity *pEntity;
  1394. int dev_type;
  1395. };
  1396. void change_dev(int dev_type)
  1397. {
  1398. Dbg("change_dev dev_type:%d", dev_type);
  1399. if (m_pEndpoint) {
  1400. Dbg("begin invoke endpoint change audio device!");
  1401. endpoint_change_audio_dev(m_pEndpoint, dev_type);
  1402. Dbg("end invoke endpoint change audio device!");
  1403. }
  1404. }
  1405. static int __change_dev(void *arg)
  1406. {
  1407. ChangeDevCommand *pCmd = (ChangeDevCommand *)arg;
  1408. pCmd->pEntity->change_dev(pCmd->dev_type);
  1409. delete pCmd;
  1410. return 0;
  1411. }
  1412. void SwitchHandFree()
  1413. {
  1414. LOG_FUNCTION();
  1415. int rc = 0;
  1416. ChangeDevCommand *pCmd = new ChangeDevCommand();
  1417. pCmd->pEntity = this;
  1418. pCmd->dev_type = DEV_HANDFREE;
  1419. if (endpoint_invoke(m_pEndpoint, &__change_dev, pCmd, &rc) != 0) {
  1420. Dbg("endpoint invoke failed!");
  1421. delete pCmd;
  1422. }
  1423. }
  1424. void SwitchPickup()
  1425. {
  1426. LOG_FUNCTION();
  1427. int rc = 0;
  1428. ChangeDevCommand *pCmd = new ChangeDevCommand();
  1429. pCmd->pEntity = this;
  1430. pCmd->dev_type = DEV_PICKUP;
  1431. if (endpoint_invoke(m_pEndpoint, &__change_dev, pCmd, &rc) != 0) {
  1432. Dbg("endpoint invoke failed!");
  1433. delete pCmd;
  1434. }
  1435. }
  1436. void SetState(int state)
  1437. {
  1438. m_state = state;
  1439. }
  1440. ErrorCodeEnum RealSelfCheck()
  1441. {
  1442. ErrorCodeEnum Error = Error_Succeed;
  1443. if (m_pSelfcheckClient)
  1444. {
  1445. SelfCheckerService_RealCheck_Req req;
  1446. req.name = GetEntityName();
  1447. SelfCheckerService_RealCheck_Ans ans;
  1448. DWORD Timeout = 500;
  1449. Error = m_pSelfcheckClient->RealCheck(req,ans,Timeout);
  1450. if (Error!=Error_Succeed)
  1451. {
  1452. Dbg("RealSelfcheck fail!");
  1453. }
  1454. else
  1455. {
  1456. Dbg("RealSelfcheck");
  1457. }
  1458. }
  1459. return Error;
  1460. }
  1461. CSimpleStringA MakeUri(const char *terminal_id)
  1462. {
  1463. CSimpleStringA str;
  1464. str = CSimpleStringA::Format("sip:%s@%s;transport=UDP", terminal_id, m_localip);
  1465. return str;
  1466. }
  1467. void Handle_RecordVideoLocation_Info(const char* pszMessage)
  1468. {
  1469. if (NULL == pszMessage){
  1470. return;
  1471. }
  1472. CSimpleStringA strMsg = pszMessage;
  1473. if (strMsg.IsStartWith("ews|",true)){
  1474. strMsg = strMsg.SubString(4,strMsg.GetLength()-4);
  1475. }
  1476. int lxPos,lyPos,lwidth,lheight;
  1477. CSimpleStringA str;
  1478. sscanf(strMsg.GetData(), "%d@%d@%d@%d@%d@%s", &lxPos, &lyPos, &lwidth, &lheight, &str);
  1479. Dbg("start record preview local video param : (x=%d,y=%d,width=%d,height=%d).",lxPos,lyPos,lwidth,lheight);
  1480. m_RecordVideoLocation.x = lxPos;
  1481. m_RecordVideoLocation.y = lyPos;
  1482. m_RecordVideoLocation.width = lwidth;
  1483. m_RecordVideoLocation.height = lheight;
  1484. }
  1485. void Handle_AdjustVideoEchoEvent(const char* pszMessage)
  1486. {
  1487. if (NULL == pszMessage){
  1488. return;
  1489. }
  1490. CSimpleStringA strMsg = pszMessage;
  1491. if (strMsg.IsStartWith("ews|",true)){
  1492. strMsg = strMsg.SubString(4,strMsg.GetLength()-4);
  1493. }
  1494. int lxPos,lyPos,lwidth,lheight;
  1495. CSimpleStringA str;
  1496. sscanf(strMsg.GetData(), "%d@%d@%d@%d@%d@%s", &lxPos, &lyPos, &lwidth, &lheight, &str);
  1497. Dbg("begin adjust local video param : (x=%d,y=%d,width=%d,height=%d).",lxPos,lyPos,lwidth,lheight);
  1498. if (DEFAULT_RECORD_VIDEO_WIDTH == lwidth && DEFAULT_RECORD_VIDEO_HEIGHT == lheight){
  1499. m_stVideoParam.nWindowState = 0;
  1500. }
  1501. else if(SMALL_RECORD_VIDEO_WIDTH == lwidth && SMALL_RECORD_VIDEO_HEIGHT == lheight){
  1502. m_stVideoParam.nWindowState = 5;
  1503. }
  1504. else{
  1505. Dbg("not support width and height.");
  1506. }
  1507. m_RecordVideoLocation.x = lxPos;
  1508. m_RecordVideoLocation.y = lyPos;
  1509. m_RecordVideoLocation.width = lwidth;
  1510. m_RecordVideoLocation.height = lheight;
  1511. }
  1512. private:
  1513. ErrorCodeEnum LoadConfig(endpoint_conf_t *conf)
  1514. {
  1515. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1516. CSmartPointer<IConfigInfo> spRootConfig;
  1517. ErrorCodeEnum Error = spFunction->OpenConfig(Config_Root, spRootConfig);
  1518. if (Error == Error_Succeed) {
  1519. CSimpleStringA strHandFreeIn;
  1520. CSimpleStringA strHandFreeOut;
  1521. CSimpleStringA strPickupIn;
  1522. CSimpleStringA strPickupOut;
  1523. SpIniMappingTable table;
  1524. table.AddEntryString("audio", "handfree_in_dev", strHandFreeIn, "$");
  1525. table.AddEntryString("audio", "handfree_out_dev", strHandFreeOut, "$");
  1526. table.AddEntryString("audio", "pickup_in_dev", strPickupIn, "$");
  1527. table.AddEntryString("audio", "pickup_out_dev", strPickupOut, "$");
  1528. table.AddEntryBoolean("audio", "pickup_out_agc", conf->audio_pickup_out_agc, false);
  1529. table.AddEntryBoolean("audio", "pickup_in_agc", conf->audio_pickup_in_agc, false);
  1530. table.AddEntryBoolean("audio", "handfree_in_agc", conf->audio_handfree_in_agc, false);
  1531. table.AddEntryBoolean("audio", "handfree_out_agc", conf->audio_handfree_out_agc, false);
  1532. table.AddEntryBoolean("audio", "pickup_out_ns", conf->audio_pickup_out_ns, false);
  1533. table.AddEntryBoolean("audio", "pickup_in_ns", conf->audio_pickup_in_ns, false);
  1534. table.AddEntryBoolean("audio", "handfree_in_ns", conf->audio_handfree_in_ns, false);
  1535. table.AddEntryBoolean("audio", "handfree_out_ns", conf->audio_handfree_out_ns, false);
  1536. table.AddEntryBoolean("audio", "pickup_aec", conf->audio_pickup_aec, false);
  1537. table.AddEntryBoolean("audio", "handfree_aec", conf->audio_handfree_aec, false);
  1538. table.AddEntryInt("audio", "handfree_in_volume", m_kept_volume_in[DEV_HANDFREE], 0);
  1539. table.AddEntryInt("audio", "handfree_out_volume", m_kept_volume_out[DEV_HANDFREE], 0);
  1540. table.AddEntryInt("audio", "pickup_in_volume", m_kept_volume_in[DEV_PICKUP], 0);
  1541. table.AddEntryInt("audio", "pickup_out_volume", m_kept_volume_out[DEV_PICKUP], 0);
  1542. table.AddEntryInt("video", "quant", conf->quant, 0);
  1543. table.AddEntryInt("video", "mtu", conf->mtu, 0);
  1544. Error = table.Load(spRootConfig);
  1545. if (Error == Error_Succeed) {
  1546. int id;
  1547. id = capture_get_audio_device_id(true, strHandFreeIn);
  1548. if (id == -1)
  1549. {
  1550. Dbg("audio device %s does not exist!", (LPCSTR)strHandFreeIn);
  1551. Error = Error_Param;
  1552. }
  1553. strcpy(conf->audio_handfree_in_dev, strHandFreeIn);
  1554. id = capture_get_audio_device_id(false, strHandFreeOut);
  1555. if (id == -1)
  1556. {
  1557. Dbg("audio device %s does not exist!", (LPCSTR)strHandFreeOut);
  1558. Error = Error_Param;
  1559. }
  1560. strcpy(conf->audio_handfree_out_dev, strHandFreeOut);
  1561. id = capture_get_audio_device_id(true, strPickupIn);
  1562. if (id == -1) {
  1563. Dbg("audio device %s does not exist!", (LPCSTR)strPickupIn);
  1564. Error = Error_Param;
  1565. }
  1566. strcpy(conf->audio_pickup_in_dev, strPickupIn);
  1567. id = capture_get_audio_device_id(false, strPickupOut);
  1568. if (id == -1) {
  1569. Dbg("audio device %s does not exist!", (LPCSTR)strPickupOut);
  1570. Error = Error_Param;
  1571. }
  1572. strcpy(conf->audio_pickup_out_dev, strPickupOut);
  1573. conf->ref_active_camera = &m_stVideoParam.iActiveCamera;
  1574. conf->ref_camera_switch = &m_stVideoParam.iCameraSwitch;
  1575. conf->ref_window_state = &m_stVideoParam.nWindowState;
  1576. conf->ref_active_img = &m_stVideoParam.bShowActiveImg;
  1577. conf->ref_Is_ActiveInspect = &m_stVideoParam.bActiveInspect;
  1578. conf->ref_camera_state = &m_stVideoParam.iCameraState;
  1579. conf->ref_Is_showPersonArea = &m_stVideoParam.bShowPersonArea;
  1580. conf->ref_Is_showRecordArea = &m_stVideoParam.bShowRecordArea;
  1581. if (eMobilePadType == m_eDeviceType)
  1582. {
  1583. m_stVideoParam.nUpDynamicFps = 3;
  1584. }
  1585. else if ((ePadtype==m_eDeviceType)||(eDesk2SType==m_eDeviceType)||(eDesk1SType==m_eDeviceType)||(eDesk2SIntegratedType==m_eDeviceType))
  1586. {
  1587. m_stVideoParam.nUpDynamicFps = REC_COMMON_VIDEO_FPS_MOBILE;
  1588. }
  1589. else if(eStand2sType == m_eDeviceType)
  1590. {
  1591. m_stVideoParam.nUpDynamicFps = 0;
  1592. }
  1593. Dbg("init up dynamic fps to %d",m_stVideoParam.nUpDynamicFps);
  1594. conf->ref_Up_Fps = &m_stVideoParam.nUpDynamicFps;
  1595. if ((eMobilePadType == m_eDeviceType)||(ePadtype == m_eDeviceType)||(eDesk2SType == m_eDeviceType)||(eDesk1SType==m_eDeviceType)||(eDesk2SIntegratedType==m_eDeviceType))
  1596. {
  1597. conf->camera_count = 1;
  1598. }
  1599. else if(eStand2sType == m_eDeviceType)
  1600. {
  1601. conf->camera_count = 2;
  1602. }
  1603. //DecideCameraCount(conf->camera_count);
  1604. DecideScreenCount(conf->screen_count);
  1605. }
  1606. }
  1607. return Error;
  1608. }
  1609. //载入运行时配置
  1610. ErrorCodeEnum LoadAudioRunConfig(int&nHandfreeout,int&nPickupout,int&nHandfreein,int&nPickupin)
  1611. {
  1612. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1613. CSmartPointer<IConfigInfo> spConfig;
  1614. ErrorCodeEnum Error = spFunction->OpenConfig(Config_Run, spConfig);
  1615. if (Error == Error_Succeed)
  1616. {
  1617. SpIniMappingTable table;
  1618. table.AddEntryInt("Audio", "handfree_out_volume", nHandfreeout, 0);
  1619. table.AddEntryInt("Audio", "pickup_out_volume", nPickupout, 0);
  1620. table.AddEntryInt("Audio", "handfree_in_volume", nHandfreein, 0);
  1621. table.AddEntryInt("Audio", "pickup_in_volume", nPickupin, 0);
  1622. Error = table.Load(spConfig);
  1623. if (Error != Error_Succeed)
  1624. {
  1625. LOG_TRACE("[dbg] failed to load run config.");
  1626. }
  1627. }
  1628. else
  1629. {
  1630. LOG_TRACE("[dbg] failed to open run config.");
  1631. }
  1632. return Error;
  1633. }
  1634. //保存运行时
  1635. ErrorCodeEnum SaveAudioRunConfig(int nHandfreeout,int nPickupout,int nHandfreein,int nPickupin)
  1636. {
  1637. CSmartPointer<IEntityFunction> spFunction = GetFunction();;
  1638. CSmartPointer<IConfigInfo> spConfig;
  1639. ErrorCodeEnum Error = spFunction->OpenConfig(Config_Run, spConfig);
  1640. if (Error == Error_Succeed)
  1641. {
  1642. Error = spConfig->WriteConfigValueInt("Audio", "handfree_out_volume", nHandfreeout);
  1643. if(Error == Error_Succeed)
  1644. {
  1645. Error = spConfig->WriteConfigValueInt("Audio", "pickup_out_volume", nPickupout);
  1646. }
  1647. else
  1648. {
  1649. Dbg("SaveAudioRunConfig handfree_out_volume fail!");
  1650. return Error;
  1651. }
  1652. if(Error == Error_Succeed)
  1653. {
  1654. Error = spConfig->WriteConfigValueInt("Audio", "handfree_in_volume", nHandfreein);
  1655. }
  1656. else
  1657. {
  1658. Dbg("SaveAudioRunConfig pickup_out_volume fail!");
  1659. return Error;
  1660. }
  1661. if(Error == Error_Succeed)
  1662. {
  1663. Error = spConfig->WriteConfigValueInt("Audio", "pickup_in_volume", nPickupin);
  1664. }
  1665. else
  1666. {
  1667. Dbg("SaveAudioRunConfig handfree_in_volume fail!");
  1668. return Error;
  1669. }
  1670. if (Error != Error_Succeed)
  1671. {
  1672. Dbg("SaveAudioRunConfig pickup_in_volume fail!");
  1673. return Error;
  1674. }
  1675. }
  1676. else
  1677. {
  1678. Dbg("SaveAudioRunConfig is fail , open sipphone.ini fail!");
  1679. }
  1680. return Error;
  1681. }
  1682. // we use root.ini Video section config to decide camera count
  1683. ErrorCodeEnum DecideCameraCount(int &nCount)
  1684. {
  1685. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1686. CSmartPointer<IConfigInfo> spConfig;
  1687. ErrorCodeEnum Error = spFunction->OpenConfig(Config_Root, spConfig);
  1688. if (Error == Error_Succeed) {
  1689. CSimpleStringA strVideoEnv;
  1690. CSimpleStringA strVideoOpt;
  1691. SpIniMappingTable table;
  1692. nCount = 0;
  1693. table.AddEntryString("Video", "EnvCamera", strVideoEnv, "$");
  1694. table.AddEntryString("Video", "OptCamera", strVideoOpt, "$");
  1695. Error = table.Load(spConfig);
  1696. if (Error == Error_Succeed) {
  1697. if (strVideoEnv.GetLength() > 1)
  1698. nCount++;
  1699. if (strVideoOpt.GetLength() > 1)
  1700. nCount++;
  1701. }
  1702. }
  1703. return Error;
  1704. }
  1705. ErrorCodeEnum DecideScreenCount(int &nCount)
  1706. {
  1707. CSystemStaticInfo Info;
  1708. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1709. ErrorCodeEnum Error = spFunction->GetSystemStaticInfo(Info);
  1710. if (Error == Error_Succeed)
  1711. {
  1712. nCount = (int)Info.eScreen;
  1713. }
  1714. return Error;
  1715. }
  1716. DeviceTypeEnum RvcGetDeviceType()
  1717. {
  1718. DeviceTypeEnum eType = eStand2sType;
  1719. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1720. CSystemStaticInfo stStaticinfo;
  1721. spFunction->GetSystemStaticInfo(stStaticinfo);
  1722. if (stricmp(stStaticinfo.strMachineType, "RVC.PAD") == 0) {
  1723. if (stricmp(stStaticinfo.strSite, "CMB.FLB") == 0) {
  1724. eType = eMobilePadType;
  1725. }
  1726. else {
  1727. eType = ePadtype;
  1728. }
  1729. }
  1730. else if (stricmp(stStaticinfo.strMachineType, "RVC.Desk2S") == 0) {
  1731. eType = eDesk2SType;
  1732. WORD nMajor = stStaticinfo.MachineVersion.GetMajor();
  1733. WORD nMinor = stStaticinfo.MachineVersion.GetMinor();
  1734. Dbg("MachineVersion is %d.%d", nMajor, nMinor);
  1735. if (2 == nMajor) {
  1736. eType = eDesk2SIntegratedType;
  1737. }
  1738. }
  1739. else if (stricmp(stStaticinfo.strMachineType, "RPM.Stand1S") == 0) {
  1740. eType = eRpm1sType;
  1741. }
  1742. else if (stricmp(stStaticinfo.strMachineType, "RVC.Desk1S") == 0) {
  1743. eType = eDesk1SType;
  1744. }
  1745. else {
  1746. eType = eStand2sType;
  1747. }
  1748. if (eType >= 0 && eType < sizeof(Device_Type_Table) / sizeof(char*)) {
  1749. LOG_TRACE("device type is %s.", Device_Type_Table[eType]);
  1750. }
  1751. return eType;
  1752. }
  1753. public:
  1754. int m_kept_volume_in[2];
  1755. int m_kept_volume_out[2];
  1756. void *m_pKeeperIn[2];
  1757. void *m_pKeeperOut[2];
  1758. //int m_nDownDynamicFps; //当前视频下行的帧频,由前端通知后端更改频率,只有移动版才使用
  1759. CSystemStaticInfo staticInfo;
  1760. char m_localip[256]; //本地ip
  1761. endpoint_conf_t conf;
  1762. endpoint_t *m_pEndpoint;
  1763. int m_iPickupPhoneState;
  1764. ErrorCodeEnum m_SipErrorCode;
  1765. DeviceTypeEnum m_eDeviceType;
  1766. CallingTypeEnum m_nCallType; //呼叫模式,0:可视柜台正常呼叫,1:PAD主动外呼,2:PAD被动呼叫,来源PAD,3:PAD被动呼叫,来源手机端
  1767. int m_nSysCallType;//0:普通模式,1:p2p模式
  1768. volatile stVideoParam m_stVideoParam; //视频参数,add by ch@20190424
  1769. volatile int m_bIsSalesRecord; //add by ly@20180725
  1770. volatile int m_bEwsRecord; //add by ly@2019/04/18
  1771. record_echo_location_t m_RecordVideoLocation;
  1772. private:
  1773. CServerSessionBase *m_pCurrentSession;
  1774. int m_state;
  1775. CAutoArray<CUUID> m_arrListener;
  1776. ChannelSipphoneClient*m_pSipphoneChannel;
  1777. SelfChekerClient*m_pSelfcheckClient;
  1778. };
  1779. //
  1780. // CSIPPhoneSession
  1781. //
  1782. void CSIPPhoneSession::OnClose( ErrorCodeEnum eErrorCode )
  1783. {
  1784. LOG_FUNCTION();
  1785. }
  1786. void CSIPPhoneSession::Handle_MakeCall( SpReqAnsContext<PhoneService_MakeCall_Req, PhoneService_MakeCall_Ans>::Pointer ctx )
  1787. {
  1788. LOG_FUNCTION();
  1789. LOG_TRACE("make call [%s]", (LPCSTR)ctx->Req.call_uri);
  1790. int rc;
  1791. MakeCallCommand *cmd = new MakeCallCommand();
  1792. cmd->pSIPPhoneSession = this;
  1793. cmd->strUri = ctx->Req.call_uri;
  1794. ///////////重新初始化sip话机,防止断网导致IP改变//////////////////
  1795. if (m_pEntity->m_pEndpoint)
  1796. {
  1797. Dbg("Handle_MakeCall endpoint_destroy m_pEndpoint addr is %0x.",m_pEntity->m_pEndpoint);
  1798. endpoint_destroy(m_pEntity->m_pEndpoint);
  1799. m_pEntity->m_pEndpoint = NULL;
  1800. }
  1801. CSimpleStringA strUri = m_pEntity->MakeUri(m_pEntity->staticInfo.strTerminalID);
  1802. if (strUri.GetLength() > 0)
  1803. {
  1804. strcpy(m_pEntity->conf.uri, strUri);
  1805. m_pEntity->conf.media_start_port = REC_COMMON_AUDIO_PORT_START;
  1806. m_pEntity->conf.media_stop_port = REC_COMMON_AUDIO_PORT_STOP;
  1807. m_pEntity->m_pEndpoint = endpoint_create(m_pEntity, &m_pEntity->conf,m_pEntity->m_iPickupPhoneState);
  1808. if (!m_pEntity->m_pEndpoint)
  1809. {
  1810. LOG_TRACE("create endpoint failed!");
  1811. }
  1812. else{
  1813. Dbg("Handle_MakeCall endpoint_create m_pEndpoint addr is %0x.", m_pEntity->m_pEndpoint);
  1814. }
  1815. }
  1816. else
  1817. {
  1818. LOG_TRACE("strUri length equals zero!");
  1819. }
  1820. ErrorCodeEnum Error = m_pEntity->GetLocalIP();
  1821. if (Error != 0)
  1822. {
  1823. LOG_TRACE("get local ip failed!");
  1824. }
  1825. if (m_pEntity->m_eDeviceType == eMobilePadType)
  1826. {
  1827. m_pEntity->m_stVideoParam.nUpDynamicFps = 3;
  1828. }
  1829. ///////////重新初始化sip话机,防止断网导致IP改变//////////////////
  1830. endpoint_invoke(m_pEntity->GetEndpoint(), &__make_call, cmd, &rc);
  1831. ctx->Answer((ErrorCodeEnum)rc);
  1832. }
  1833. void CSIPPhoneSession::Handle_HangupCall( SpReqAnsContext<PhoneService_HangupCall_Req, PhoneService_HangupCall_Ans>::Pointer ctx )
  1834. {
  1835. LOG_FUNCTION();
  1836. int rc;
  1837. HangupCallCommand *cmd = new HangupCallCommand();
  1838. cmd->pSIPPhoneSession = this;
  1839. cmd->strSession_num = ctx->Req.session_num;
  1840. cmd->strBranch_server_ip = ctx->Req.branch_server_ip;
  1841. cmd->iBranch_server_port = ctx->Req.branch_server_port;
  1842. if (m_pEntity->GetEndpoint())
  1843. {
  1844. endpoint_invoke(m_pEntity->GetEndpoint(), &__hangup_call, cmd, &rc);
  1845. }
  1846. ctx->Answer((ErrorCodeEnum)rc);
  1847. }
  1848. void CSIPPhoneSession::Handle_ReleaseCall( SpReqAnsContext<PhoneService_ReleaseCall_Req, PhoneService_ReleaseCall_Ans>::Pointer ctx )
  1849. {
  1850. LOG_FUNCTION();
  1851. int rc = Error_Succeed;
  1852. g_IsExternalTerminalted = TRUE;
  1853. endpoint_invoke(m_pEntity->GetEndpoint(), &__release_call, this, &rc);
  1854. Dbg("Handle_ReleaseCall endpoint_destroy m_pEndpoint addr is %0x.",m_pEntity->m_pEndpoint);
  1855. endpoint_destroy(m_pEntity->m_pEndpoint);
  1856. m_pEntity->m_pEndpoint = NULL;
  1857. ctx->Answer((ErrorCodeEnum)rc);
  1858. }
  1859. void CSIPPhoneSession::Handle_SetCallingParam(SpOnewayCallContext<PhoneService_SetCallingParam_Info>::Pointer ctx)
  1860. {
  1861. LOG_FUNCTION();
  1862. Dbg("SetCallingParam CallType = %d", ctx->Info.CallType);
  1863. m_pEntity->m_nCallType = (CallingTypeEnum)ctx->Info.CallType;
  1864. }
  1865. void CSIPPhoneSession::Handle_RealErrorCheck(SpOnewayCallContext<PhoneService_RealErrorCheck_Info>::Pointer ctx)
  1866. {
  1867. LOG_FUNCTION();
  1868. m_pEntity->m_SipErrorCode = Error_InvalidState;
  1869. m_pEntity->RealSelfCheck();
  1870. }
  1871. void CSIPPhoneSession::Handle_StartVideo( SpOnewayCallContext<PhoneService_StartVideo_Info>::Pointer ctx )
  1872. {
  1873. LOG_FUNCTION();
  1874. int rc;
  1875. ControlVideoCommand *pCmd = new ControlVideoCommand();
  1876. pCmd->pSIPPhoneSession = this;
  1877. pCmd->start = TRUE;
  1878. pCmd->local_hwd_move = 0;
  1879. pCmd->remote_hwd_move = 0;
  1880. if(!(ctx->Info.remote_view_x||ctx->Info.remote_view_y||ctx->Info.remote_view_cx||ctx->Info.remote_view_cy||ctx->Info.remote_width||ctx->Info.remote_height))
  1881. {
  1882. m_IsLocalPlay= TRUE;
  1883. m_VideoWindowPlayType = eOnly_Local_Video;
  1884. Dbg("LocalPlay Mod");
  1885. }
  1886. else
  1887. {
  1888. m_IsLocalPlay= FALSE;
  1889. m_VideoWindowPlayType = eOnline_Mode_Video;
  1890. Dbg("OnlinePlay Mod");
  1891. if (0 == ctx->Info.remote_port){
  1892. m_VideoWindowPlayType = eBoth_Local_Remote_Video;
  1893. m_pEntity->m_nCallType = NORMAL_CALLTYPE;
  1894. Dbg("both local and remote mode.");
  1895. if (NULL == m_pEntity->GetEndpoint())
  1896. {
  1897. Dbg("m_pEndpoint has destroy, now new init it.");
  1898. m_pEntity->InitEndpoint();
  1899. }
  1900. }
  1901. }
  1902. pCmd->local_ip = inet_addr(m_pEntity->m_localip);
  1903. pCmd->local_port = REC_COMMON_VIDEO_PORT;
  1904. pCmd->remote_ip = inet_addr(ctx->Info.remote_ip);
  1905. pCmd->remote_port = ctx->Info.remote_port;
  1906. pCmd->local_view_x = ctx->Info.local_view_x;
  1907. pCmd->local_view_y = ctx->Info.local_view_y;
  1908. pCmd->local_view_cx = ctx->Info.local_view_cx;
  1909. pCmd->local_view_cy = ctx->Info.local_view_cy;
  1910. pCmd->remote_view_x = ctx->Info.remote_view_x;
  1911. pCmd->remote_view_y = ctx->Info.remote_view_y;
  1912. pCmd->remote_view_cx = ctx->Info.remote_view_cx;
  1913. pCmd->remote_view_cy = ctx->Info.remote_view_cy;
  1914. pCmd->remote_width = ctx->Info.remote_width;
  1915. pCmd->remote_height = ctx->Info.remote_height;
  1916. pCmd->local_hwd_move = ctx->Info.local_hwd_move;
  1917. pCmd->remote_hwd_move = ctx->Info.remote_hwd_move;
  1918. //初始化窗口参数
  1919. //m_pEntity->m_stVideoParam.nWindowState = 0;
  1920. //m_pEntity->GetFunction()->SetTimer(1, m_pEntity, 1000);
  1921. //m_pEntity->m_nDownDynamicFps = ctx->Info.remote_fps;
  1922. //g_nDynamicFps = ctx->Info.remote_fps;
  1923. //g_nSysFps = ctx->Info.remote_fps;
  1924. //g_nLastRecFrameTime = GetTickCount();
  1925. endpoint_invoke(m_pEntity->GetEndpoint(), &__control_video, pCmd, &rc);
  1926. }
  1927. void CSIPPhoneSession::Handle_StopVideo( SpOnewayCallContext<PhoneService_StopVideo_Info>::Pointer ctx )
  1928. {
  1929. LOG_FUNCTION();
  1930. int rc;
  1931. ControlVideoCommand *pCmd = new ControlVideoCommand();
  1932. pCmd->pSIPPhoneSession = this;
  1933. pCmd->start = FALSE;
  1934. m_pEntity->GetFunction()->KillTimer(1);
  1935. if (NULL != m_pEntity->GetEndpoint()){
  1936. endpoint_invoke(m_pEntity->GetEndpoint(), &__control_video, pCmd, &rc);
  1937. }
  1938. else{
  1939. endpoint_call_stop_double_record_broadcast_video();
  1940. }
  1941. m_pEntity->m_stVideoParam.bShowActiveImg = 0;
  1942. m_pEntity->m_stVideoParam.bActiveInspect = 0;
  1943. //初始化窗口参数
  1944. m_pEntity->m_stVideoParam.nWindowState = 0;
  1945. }
  1946. void CSIPPhoneSession::Handle_BeginState( SpSubscribeContext<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::Pointer ctx )
  1947. {
  1948. LOG_FUNCTION();
  1949. m_spCallbackContext = ctx;
  1950. }
  1951. void CSIPPhoneSession::Handle_EndState( SpOnewayCallContext<PhoneService_EndState_Info>::Pointer ctx )
  1952. {
  1953. LOG_FUNCTION();
  1954. SpSubscribeContext<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::Pointer tmp_ctx = m_spCallbackContext;
  1955. m_spCallbackContext.Clear();
  1956. }
  1957. void CSIPPhoneSession::hangup_call(HangupCallCommand* cmd)
  1958. {
  1959. LOG_FUNCTION();
  1960. if (m_pCall) {
  1961. Dbg("normal hangup.");
  1962. endpoint_call_hangup(m_pCall);
  1963. }
  1964. else
  1965. {
  1966. if (m_pEntity && m_pEntity->m_nCallType == MOBILETOPAD_CALLTYPE){
  1967. //分布式呼叫主动挂断场景
  1968. Dbg("distribute hangup, without pickup");
  1969. if (cmd){
  1970. const char* pserver = cmd->strBranch_server_ip.GetData();
  1971. const char* pcallnum = cmd->strSession_num.GetData();
  1972. if (pcallnum && pserver){
  1973. endpoint_distribute_call_info_t* tinfo = (endpoint_distribute_call_info_t*)malloc(sizeof(endpoint_distribute_call_info_t));
  1974. if (tinfo){
  1975. memset(tinfo, 0, sizeof(endpoint_distribute_call_info_t));
  1976. memcpy(tinfo->server_ip, pserver, strlen(pserver));
  1977. memcpy(tinfo->call_name, pcallnum, strlen(pcallnum));
  1978. tinfo->etype = INS_HANGUP;
  1979. tinfo->server_port = cmd->iBranch_server_port;
  1980. endpoint_distribute_hangup(tinfo);
  1981. free(tinfo);
  1982. tinfo = NULL;
  1983. }
  1984. }
  1985. }
  1986. LogEvent(Severity_Middle,LOG_EVT_DISTRIBUTE_SIPPHONE_IDLE,"SIPPhone to idle.");
  1987. LogEvent(Severity_Middle,LOG_EVT_DISTRIBUTE_ASSISTANTCHANNEL_IDLE,"AssistantChannel to idle.");
  1988. }
  1989. }
  1990. }
  1991. void CSIPPhoneSession::release_call()
  1992. {
  1993. if (m_pCall)
  1994. {
  1995. Terminatedcall(m_pCall);
  1996. }
  1997. }
  1998. void CSIPPhoneSession::on_call_state(int state, const char *state_desc, const char *phrase)
  1999. {
  2000. LOG_FUNCTION();
  2001. if (m_spCallbackContext != NULL)
  2002. {
  2003. LOG_TRACE("on_call_state message state = %d, status=%s, phrase=%s!", state, state_desc, phrase);
  2004. PhoneService_PhoneState_Info Info;
  2005. Info.state = state;
  2006. Info.status = CSimpleStringA::Format("%s,%s", state_desc, phrase);
  2007. m_spCallbackContext->SendMessage(Info);
  2008. Dbg("%s:%d", __FUNCTION__, __LINE__);
  2009. }
  2010. if (state == TERMINATED)
  2011. {
  2012. Dbg("%s:%d", __FUNCTION__, __LINE__);
  2013. if (m_pCall)
  2014. {
  2015. Dbg("%s:%d", __FUNCTION__, __LINE__);
  2016. endpoint_call_destroy(m_pCall);
  2017. m_pCall = NULL;
  2018. }
  2019. }
  2020. Dbg("%s:%d", __FUNCTION__, __LINE__);
  2021. m_pEntity->SetState(state);
  2022. Dbg("%s:%d", __FUNCTION__, __LINE__);
  2023. }
  2024. int CSIPPhoneSession::make_call( const char *remote_uri )
  2025. {
  2026. if (m_pCall)
  2027. {
  2028. LOG_TRACE("call duplicated! and endpoint destroy old call.");
  2029. endpoint_call_destroy(m_pCall);
  2030. m_pCall = NULL;
  2031. //return Error_Duplication;
  2032. }
  2033. //else
  2034. {
  2035. endpoint_call_callback_t cb = {0};
  2036. cb.on_call_state = &__on_call_state;
  2037. cb.user_data = this;
  2038. m_pCall = endpoint_call_create(m_pEntity->GetEndpoint(), remote_uri, m_pEntity->m_localip,m_pEntity->m_eDeviceType,m_pEntity->m_nCallType,&cb);
  2039. if (m_pCall)
  2040. {
  2041. g_IsExternalTerminalted = FALSE;
  2042. Dbg("g_IsExternalTerminalted = FALSE");
  2043. LOG_TRACE("create call endpoint ok!");
  2044. if (endpoint_call_start(m_pCall) == 0)
  2045. {
  2046. LOG_TRACE("start call ok!");
  2047. return Error_Succeed;
  2048. }
  2049. else
  2050. {
  2051. LOG_TRACE("start call failed! and endpoint destroy call.");
  2052. endpoint_call_destroy(m_pCall);
  2053. m_pCall = NULL;
  2054. return Error_Unexpect;
  2055. }
  2056. }
  2057. else
  2058. {
  2059. g_IsExternalTerminalted = TRUE;
  2060. Dbg("g_IsExternalTerminalted = TRUE");
  2061. LOG_TRACE("create call endpoint failed!");
  2062. m_pEntity->m_SipErrorCode = Error_InvalidState;
  2063. m_pEntity->RealSelfCheck();
  2064. return Error_Unexpect;
  2065. }
  2066. }
  2067. }
  2068. void CSIPPhoneSession::control_video( ControlVideoCommand *pCmd )
  2069. {
  2070. LOG_FUNCTION();
  2071. if (m_pCall)
  2072. {
  2073. if (pCmd->start)
  2074. {
  2075. endpoint_call_start_video(m_pCall,
  2076. pCmd->remote_ip, pCmd->remote_port,
  2077. pCmd->local_ip, pCmd->local_port,
  2078. pCmd->remote_width, pCmd->remote_height,
  2079. pCmd->local_view_x, pCmd->local_view_y, pCmd->local_view_cx, pCmd->local_view_cy,
  2080. pCmd->remote_view_x, pCmd->remote_view_y, pCmd->remote_view_cx, pCmd->remote_view_cy,
  2081. pCmd->local_hwd_move, pCmd->remote_hwd_move, &m_cb_video_box_move);
  2082. }
  2083. else
  2084. {
  2085. //双录第一阶段结束录像,销毁call资源
  2086. if ((eOnly_Local_Video == m_VideoWindowPlayType) || (eBoth_Local_Remote_Video == m_VideoWindowPlayType && m_pEntity->m_nCallType != DOUBLERECORD_CALLTYPE ))
  2087. {
  2088. Dbg("stop record play.");
  2089. local_play_stop_video(m_pCall);
  2090. m_IsLocalPlay = FALSE;
  2091. endpoint_call_destroy(m_pCall);
  2092. m_pCall = NULL;
  2093. }
  2094. else
  2095. {
  2096. endpoint_call_stop_video(m_pCall);
  2097. }
  2098. }
  2099. }
  2100. else
  2101. {
  2102. if (pCmd->start)
  2103. {
  2104. endpoint_call_callback_t cb = {0};
  2105. cb.on_call_state = &__on_call_state;
  2106. cb.user_data = this;
  2107. m_pCall = endpoint_call_create(m_pEntity->GetEndpoint(), "test",m_pEntity->m_localip,m_pEntity->m_eDeviceType,m_pEntity->m_nCallType, &cb);
  2108. if (eOnly_Local_Video == m_VideoWindowPlayType){
  2109. Dbg("start local play mode record.");
  2110. local_play_start_video(m_pCall,pCmd->local_view_x, pCmd->local_view_y, pCmd->local_view_cx, pCmd->local_view_cy, pCmd->local_hwd_move, &m_cb_video_box_move);
  2111. }
  2112. else if (eBoth_Local_Remote_Video == m_VideoWindowPlayType){
  2113. Dbg("start local and remote video play mode record.");
  2114. local_remote_show_video(m_pCall,pCmd->local_view_x, pCmd->local_view_y, pCmd->local_view_cx, pCmd->local_view_cy,pCmd->remote_view_x, pCmd->remote_view_y, pCmd->remote_view_cx, pCmd->remote_view_cy, pCmd->local_hwd_move, pCmd->remote_hwd_move,&m_cb_video_box_move);
  2115. }
  2116. }
  2117. else{
  2118. Dbg("record call remote agent timeout, close video session.");
  2119. endpoint_call_stop_double_record_broadcast_video();
  2120. }
  2121. }
  2122. }
  2123. int CSIPPhoneSession::on_video_box_move(int imessageType, int ivideotype, int ileft, int ibottom)
  2124. {
  2125. int iret = -1;
  2126. if (0 == imessageType){
  2127. VideoBoxStartMove evt;
  2128. evt.videoboxflag = ivideotype;
  2129. evt.leftlowerx = ileft;
  2130. evt.leftlowery = ibottom;
  2131. iret = SpSendBroadcast(m_pEntity->GetFunction(), SP_MSG_OF(VideoBoxStartMove), SP_MSG_SIG_OF(VideoBoxStartMove), evt);
  2132. Dbg("VideoBoxStartMove broadcast sent, video type is %d, left is %d, bottom is %d.", ivideotype, ileft, ibottom);
  2133. }
  2134. else{
  2135. VideoBoxStopMove evt;
  2136. evt.videoboxflag = ivideotype;
  2137. evt.leftlowerx = ileft;
  2138. evt.leftlowery = ibottom;
  2139. iret = SpSendBroadcast(m_pEntity->GetFunction(), SP_MSG_OF(VideoBoxStopMove), SP_MSG_SIG_OF(VideoBoxStopMove), evt);
  2140. Dbg("VideoBoxStopMove broadcast sent, video type is %d, left is %d, bottom is %d.", ivideotype, ileft, ibottom);
  2141. }
  2142. return iret;
  2143. }
  2144. ChannelSipphoneClient::ChannelSipphoneClient( CSIPEntity *pEntity ) : ChannelService_ClientBase(pEntity)
  2145. {
  2146. }
  2147. void ChannelSipphoneClient::OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData)
  2148. {
  2149. if (Error == Error_Succeed)
  2150. {
  2151. CSIPEntity *pEntity = static_cast<CSIPEntity*>(m_pEntityBase);
  2152. if (Msg.state == eChannelState_Connected)
  2153. {
  2154. if (pEntity->m_pKeeperIn[DEV_HANDFREE])
  2155. {
  2156. pEntity->SendAudioDeviceVolumn(DEVICE_HANDFREE_IN);
  2157. }
  2158. if (pEntity->m_pKeeperOut[DEV_HANDFREE])
  2159. {
  2160. pEntity->SendAudioDeviceVolumn(DEVICE_HANDFREE_OUT);
  2161. }
  2162. if (pEntity->m_pKeeperOut[DEV_PICKUP])
  2163. {
  2164. pEntity->SendAudioDeviceVolumn(DEVICE_PICKUP_OUT);
  2165. }
  2166. if (pEntity->m_pKeeperIn[DEV_PICKUP])
  2167. {
  2168. pEntity->SendAudioDeviceVolumn(DEVICE_PICKUP_IN);
  2169. }
  2170. }
  2171. //else if (Msg.state == eChannelState_Idle)
  2172. //{
  2173. // if (pEntity->m_kept_volume_out[DEV_PICKUP])
  2174. // {
  2175. // pEntity->ChangeKeeperVolumn(pEntity->m_pKeeperOut[DEV_PICKUP],pEntity->m_kept_volume_out[DEV_PICKUP],DEV_PICKUP);
  2176. // }
  2177. // if (pEntity->m_kept_volume_out[DEV_HANDFREE])
  2178. // {
  2179. // pEntity->ChangeKeeperVolumn(pEntity->m_pKeeperOut[DEV_HANDFREE],pEntity->m_kept_volume_out[DEV_HANDFREE],DEV_HANDFREE);
  2180. // }
  2181. //}
  2182. }
  2183. }
  2184. void ChannelSipphoneClient::OnMessage( ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData )
  2185. {
  2186. LOG_FUNCTION();
  2187. if (Error == Error_Succeed)
  2188. {
  2189. CSIPEntity *pEntity = static_cast<CSIPEntity*>(m_pEntityBase);
  2190. pEntity->OnReceivePkt(Msg.type,Msg.sub_type, (const char*)Msg.data.m_pData, Msg.data.m_iLength);
  2191. }
  2192. }
  2193. SelfChekerClient::SelfChekerClient( CSIPEntity *pEntity ) : SelfCheckerService_ClientBase(pEntity)
  2194. {
  2195. }
  2196. SP_BEGIN_ENTITY_MAP()
  2197. SP_ENTITY(CSIPEntity)
  2198. SP_END_ENTITY_MAP()