mod_sipphone.cpp 76 KB

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