mod_sipphone.cpp 74 KB

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