mod_sipphone.cpp 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463
  1. #include "stdafx.h"
  2. //#include "pthread.h"
  3. #include "endpoint.h"
  4. #include "mod_sipphone.h"
  5. #include "y2k_time.h"
  6. #include "mod_agentip/sysvar.h"
  7. #include "mod_facetracking/sysvar.h"
  8. #include "mod_interactivecontrol/Event.h"
  9. #include "../mod_mediacontroller/Event.h"
  10. #include "sockutil.h"
  11. #include "media_config_const.h"
  12. #include "audio_session.h"
  13. #include "video_session.h"
  14. #include "EventCode.h"
  15. #define EVT_CONVERTER "EventConverter"
  16. #define DEVICE_HANDFREE_OUT 0
  17. #define DEVICE_PICKUP_OUT 1
  18. #define DEVICE_HANDFREE_IN 2
  19. #define DEVICE_PICKUP_IN 3
  20. #ifndef RVC_MAX_TRY_COUNT
  21. #define RVC_MAX_TRY_COUNT 1
  22. #endif
  23. /////////////////////////////////////////////
  24. // future roadmap
  25. // 1. 使用session timer
  26. // 2. 增强稳定性
  27. // 3. 健康检查里面触发 主备服务器切换(switch between freeswitchs) 定时发送options ping switch server
  28. /////////////////////////////////////////////
  29. extern bool g_IsExternalTerminalted;
  30. static void __on_video_box_move(int imessagetype, int ivideotype, int ileft, int ibottom, void *user_data)
  31. {
  32. CSIPPhoneSession *pThis = static_cast<CSIPPhoneSession*>(user_data);
  33. pThis->on_video_box_move(imessagetype, ivideotype, ileft, ibottom);
  34. }
  35. static void __on_call_state(int state, const char *state_desc, const char *phrase, void *user_data)
  36. {
  37. CSIPPhoneSession *pThis = static_cast<CSIPPhoneSession*>(user_data);
  38. if (pThis->m_iLastState != state) {
  39. pThis->m_iLastState = state;
  40. pThis->on_call_state(state, state_desc, phrase);
  41. }
  42. }
  43. static int __make_call(void *user_data)
  44. {
  45. MakeCallCommand_t *cmd = (MakeCallCommand_t*)user_data;
  46. int rc = cmd->pSIPPhoneSession->make_call(cmd);
  47. delete cmd;
  48. return rc;
  49. }
  50. static int __hangup_call(void *user_data)
  51. {
  52. HangupCallCommand_t *cmd = (HangupCallCommand_t*)(user_data);
  53. cmd->pSIPPhoneSession->hangup_call(cmd);
  54. delete cmd;
  55. return 0;
  56. }
  57. static int __control_video(void *arg)
  58. {
  59. ControlVideoCommand_t* pCmd = (ControlVideoCommand_t*)(arg);
  60. pCmd->pSIPPhoneSession->control_video(pCmd);
  61. delete pCmd;
  62. return 0;
  63. }
  64. static int __release_call(void *user_data)
  65. {
  66. CSIPPhoneSession *pThis = static_cast<CSIPPhoneSession*>(user_data);
  67. pThis->release_call();
  68. pThis->on_call_state(TERMINATED,"STATE:terminated","bye bye");
  69. return 0;
  70. }
  71. static void __audiomgrlog(void* user_data, const char* fmt, va_list arg)
  72. {
  73. int n = _vsnprintf(NULL, 0, fmt, arg);
  74. if (n >= 512) {
  75. char* buf = (char*)malloc((size_t)(n + 1));
  76. _vsnprintf(buf, n + 1, fmt, arg);
  77. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s", buf);
  78. free(buf);
  79. }
  80. else {
  81. char strlog[512] = { 0 };
  82. _vsnprintf(strlog, 512, fmt, arg);
  83. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s", strlog);
  84. }
  85. }
  86. static CSimpleStringA generateAudioInfoJson(const char* handfreeIn, const char* handfreeOut, const char* pickupIn, const char* pickupOut)
  87. {
  88. return CSimpleStringA::Format("{\"handfree_in_dev\":\"%s\",\"handfree_out_dev\":\"%s\",\"pickup_in_dev\":\"%s\",\"pickup_out_dev\":\"%s\"}",
  89. handfreeIn, handfreeOut, pickupIn, pickupOut);
  90. }
  91. static CSimpleStringA generateVolumeJson(int ihandfreeIn, int ihandfreeOut, int ipickupIn, int ipickupOut)
  92. {
  93. return CSimpleStringA::Format("{\"handfree_in_volume\":\"%d\",\"handfree_out_volume\":\"%d\",\"pickup_in_volume\":\"%d\",\"pickup_out_volume\":\"%d\"}",
  94. ihandfreeIn, ihandfreeOut, ipickupIn, ipickupOut);
  95. }
  96. static CSimpleStringA generateAudioDspFlags(endpoint_audiodsp_config_t conf)
  97. {
  98. int ipickup_in_agc = 0;
  99. int ipickup_out_agc = 0;
  100. int ihandfree_in_agc = 0;
  101. int ihandfree_out_agc = 0;
  102. int ipickup_in_ns = 0;
  103. int ipickup_out_ns = 0;
  104. int ihandfree_in_ns = 0;
  105. int ihandfree_out_ns = 0;
  106. int ipickup_aec = 0;
  107. int ihandfree_aec = 0;
  108. conf.audio_pickup_in_agc ? ipickup_in_agc = 1 : ipickup_in_agc = 0;
  109. conf.audio_pickup_out_agc ? ipickup_out_agc = 1 : ipickup_out_agc = 0;
  110. conf.audio_handfree_in_agc ? ihandfree_in_agc = 1 : ihandfree_in_agc = 0;
  111. conf.audio_handfree_out_agc ? ihandfree_out_agc = 1 : ihandfree_out_agc = 0;
  112. conf.audio_pickup_in_ns ? ipickup_in_ns = 1 : ipickup_in_ns = 0;
  113. conf.audio_pickup_out_ns ? ipickup_out_ns = 1 : ipickup_out_ns = 0;
  114. conf.audio_handfree_in_ns ? ihandfree_in_ns = 1 : ihandfree_in_ns = 0;
  115. conf.audio_handfree_out_ns ? ihandfree_out_ns = 1 : ihandfree_out_ns = 0;
  116. conf.audio_pickup_aec ? ipickup_aec = 1 : ipickup_aec = 0;
  117. conf.audio_handfree_aec ? ihandfree_aec = 1 : ihandfree_aec = 0;
  118. return CSimpleStringA::Format("{\"handfree_in_agc\":\"%d\",\"handfree_out_agc\":\"%d\",\"pickup_in_agc\":\"%d\",\"pickup_out_agc\":\"%d\",\"handfree_in_ns\":\"%d\",\"handfree_out_ns\":\"%d\",\"pickup_in_ns\":\"%d\",\"pickup_out_ns\":\"%d\",\"handfree_aec\":\"%d\",\"pickup_aec\":\"%d\"}",
  119. ihandfree_in_agc, ihandfree_out_agc, ipickup_in_agc, ipickup_out_agc,
  120. ihandfree_in_ns, ihandfree_out_ns, ipickup_in_ns, ipickup_out_ns,
  121. ihandfree_aec, ipickup_aec);
  122. }
  123. static int countnum(uint32_t unum)
  124. {
  125. int icount = 0;
  126. while (unum){
  127. unum &= (unum - 1);
  128. icount++;
  129. }
  130. return icount;
  131. }
  132. CSIPEntity::CSIPEntity() : m_pCurrentSession(NULL), m_state(INIT),m_iPickupPhoneState(ePickupMicrophoneState_Off)
  133. {
  134. m_kept_volume_in[0] = m_kept_volume_in[1] = 0;
  135. m_kept_volume_out[0] = m_kept_volume_out[1] = 0;
  136. m_pKeeperIn[0] = m_pKeeperIn[1] = NULL;
  137. m_pKeeperOut[0] = m_pKeeperOut[1] = NULL;
  138. m_SipErrorCode = Error_Succeed;
  139. m_eVideoRenderType = eGDI;
  140. memset((void*)&m_stVideoParam,0,sizeof(stVideoParam));
  141. m_bAudioMgrInited = false;
  142. m_pAudioMgr = NULL;
  143. m_pSipphoneChannel = NULL;
  144. m_bConnectedAssist = false;
  145. m_strStartTime = RVC_START_TIME;
  146. m_strEndTime = RVC_END_TIME;
  147. m_itervalTime = RVC_INTERVAL_TIME;
  148. m_bStopAutoRestart = false;
  149. m_iAudioDspUseCenter = 0;
  150. m_nCallType = NORMAL_CALLTYPE;
  151. memset(m_localip, 0, RVC_MAX_IP_LEN);
  152. m_bFirstLaunched = false;
  153. }
  154. void CSIPEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  155. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  156. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext &pLinkInfo)
  157. {
  158. switch (dwUserCode)
  159. {
  160. case LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS:
  161. {
  162. Sleep(810);
  163. if (m_pSipphoneChannel != NULL){
  164. m_bConnectedAssist = false;
  165. m_pSipphoneChannel->GetFunction()->CloseSession();
  166. m_pSipphoneChannel->SafeDelete();
  167. m_pSipphoneChannel = NULL;
  168. }
  169. if (Error_Succeed == ConnectAssistChannel()) {
  170. m_bConnectedAssist = true;
  171. }
  172. else {
  173. GetFunction()->SetTimer(2, this, 3200);
  174. }
  175. }
  176. break;
  177. case EVENT_MOD_CONNECT_HANDFREE_TO_PICKUP:
  178. case EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP:
  179. case EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE:
  180. case EVENT_MOD_CONNECT_PICKUP_TO_HANDFREE:
  181. case EVENT_MOD_CONNECT_PICKUP_CALL:
  182. case EVENT_MOD_CONNECT_SLV_HANDFREECALL:
  183. case EVENT_MOD_CONNECT_SLV_PICKUPCALL:
  184. case LOG_EVT_HANDFREE_MODE_REMOTE_CALL:
  185. case LOG_EVT_PICKUP_MODE_REMOTE_CALL:
  186. {
  187. int old_state = m_iPickupPhoneState;
  188. if (dwUserCode == EVENT_MOD_CONNECT_HANDFREE_TO_PICKUP) { // 免提->提机
  189. m_iPickupPhoneState = ePickupMicrophoneState_On;
  190. }
  191. else if (dwUserCode == EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP) { //坐席控制免提->提机
  192. m_iPickupPhoneState = ePickupMicrophoneState_On;
  193. }
  194. else if (dwUserCode == EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE) { //坐席控制提机->免提
  195. m_iPickupPhoneState = ePickupMicrophoneState_Off;
  196. }
  197. else if (dwUserCode == EVENT_MOD_CONNECT_PICKUP_TO_HANDFREE)
  198. { // // 提机->免提
  199. m_iPickupPhoneState = ePickupMicrophoneState_Off;
  200. }
  201. else if (dwUserCode == EVENT_MOD_CONNECT_PICKUP_CALL)
  202. { // 提机拨号
  203. m_iPickupPhoneState = ePickupMicrophoneState_On;
  204. }
  205. else if (dwUserCode == EVENT_MOD_CONNECT_SLV_HANDFREECALL)
  206. { // 免提拨号
  207. m_iPickupPhoneState = ePickupMicrophoneState_Off;
  208. }
  209. else if (dwUserCode == EVENT_MOD_CONNECT_SLV_PICKUPCALL)
  210. {
  211. // 通过界面拨号,但话筒未挂,进入提机拨号
  212. m_iPickupPhoneState = ePickupMicrophoneState_On;
  213. }
  214. else if (dwUserCode == LOG_EVT_HANDFREE_MODE_REMOTE_CALL)
  215. { // 免提模式开始远程双录连线
  216. m_iPickupPhoneState = ePickupMicrophoneState_Off;
  217. }
  218. else if (dwUserCode == LOG_EVT_PICKUP_MODE_REMOTE_CALL)
  219. {
  220. // 话筒模式开始远程双录连线
  221. m_iPickupPhoneState = ePickupMicrophoneState_On;
  222. }
  223. if (old_state != m_iPickupPhoneState)
  224. {
  225. if (m_iPickupPhoneState == ePickupMicrophoneState_On)
  226. {
  227. SwitchPickup();
  228. }
  229. else
  230. {
  231. SwitchHandFree();
  232. }
  233. }
  234. }
  235. break;
  236. case LOG_EVT_ENTER_ACM_FLOW:
  237. {
  238. m_stVideoParam.nWindowState = 1;
  239. }
  240. break;
  241. case LOG_EVT_EXIT_ACM_FLOW:
  242. {
  243. if(m_stVideoParam.nWindowState == 1)
  244. {
  245. m_stVideoParam.nWindowState = 0;
  246. }
  247. }
  248. break;
  249. case LOG_EVT_CHANGELIVEDETECTIONCAM:
  250. {
  251. if (pszMessage && strlen(pszMessage) > 0)
  252. {
  253. int i = atoi(pszMessage);
  254. m_stVideoParam.iCameraSwitch = i;
  255. }
  256. else
  257. {
  258. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("change active display camera param error");
  259. }
  260. }
  261. break;
  262. case LOG_EVT_RELEASELIVEDETECTION:
  263. {
  264. m_stVideoParam.bActiveInspect = 0;
  265. m_stVideoParam.bShowActiveImg = 0;
  266. m_stVideoParam.iCameraSwitch = MEDIA_CONFIG_CAMERA_TYPE_ENV;
  267. }
  268. break;
  269. case LOG_EVT_UI_HIDEONLINEVIDEO:
  270. {
  271. m_stVideoParam.nWindowState = 2;
  272. }
  273. break;
  274. case LOG_EVT_UI_SHOWONLINEVIDEO:
  275. {
  276. if (m_stVideoParam.nWindowState == 2)
  277. {
  278. m_stVideoParam.nWindowState = 3;
  279. }
  280. }
  281. break;
  282. case LOG_EVT_UI_STARTRECORD:
  283. case LOG_EVT_UI_STARTREMOTERECORD:
  284. {
  285. }
  286. break;
  287. case LOG_EVT_UI_STOPRECORD:
  288. case LOG_EVT_UI_STOPREMOTERECORD:
  289. {
  290. if (m_stVideoParam.bShowRecordArea){
  291. m_stVideoParam.bShowRecordArea = 0;
  292. }
  293. }
  294. break;
  295. case LOG_EVT_UI_RETURNMENU:
  296. {
  297. }
  298. break;
  299. case LOG_EVT_UI_SHOWLOCALVIDEO:
  300. {
  301. if (m_stVideoParam.nWindowState == 4)
  302. {
  303. m_stVideoParam.nWindowState = 3;
  304. }
  305. }
  306. break;
  307. case LOG_EVT_UI_HIDELOCALVIDEO:
  308. {
  309. m_stVideoParam.nWindowState = 4;
  310. }
  311. break;
  312. case LOG_EVT_UI_HIDEPERSONAREA:
  313. {
  314. m_stVideoParam.bShowPersonArea = 0;
  315. }
  316. break;
  317. case LOG_EVT_UI_SHOWPERSONAREA:
  318. {
  319. m_stVideoParam.bShowPersonArea = 1;
  320. }
  321. break;
  322. case EVENT_MOD_CONNECT_STOP_RECORD_BROADCAST:
  323. {
  324. }
  325. break;
  326. case EVENT_MOD_CONNECT_BEGAIN_RECORD_CALL:
  327. {
  328. }
  329. break;
  330. default:
  331. {
  332. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("unknown dwUserCode = 0x%08x.",dwUserCode);
  333. }
  334. break;
  335. }
  336. }
  337. void CSIPEntity::OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName)
  338. {
  339. if (_stricmp(pszKey, SYSVAR_CAMERASTATE) == 0)
  340. {
  341. if (pszValue[0] == 'E')
  342. {
  343. m_stVideoParam.iCameraState = MEDIA_CONFIG_CAMERA_TYPE_OPT;
  344. }
  345. else if (pszValue[0] == 'O')
  346. {
  347. m_stVideoParam.iCameraState = MEDIA_CONFIG_CAMERA_TYPE_ENV;
  348. }
  349. else if(pszValue[0] == 'B') ///////显示贴图
  350. {
  351. /////////////////////////此处显示贴图//////////////////////////////////
  352. //m_stVideoParam.iCameraSwitch = CAMERA_TYPE_ERROR;
  353. m_stVideoParam.iCameraState = MEDIA_CONFIG_CAMERA_TYPE_ERROR;
  354. }
  355. else if (pszValue[0] == 'N')
  356. {
  357. m_stVideoParam.iCameraState = MEDIA_CONFIG_CAMERA_TYPE_AUTO;
  358. //m_stVideoParam.iCameraSwitch = CAMERA_TYPE_AUTO;
  359. }
  360. }
  361. else if (_stricmp(pszKey, SYSVAR_ACTIVETRACKINGCAMERA) == 0)
  362. {
  363. if (pszValue[0] == 'E')
  364. {
  365. m_stVideoParam.iActiveCamera = MEDIA_CONFIG_CAMERA_TYPE_ENV;
  366. }
  367. else if (pszValue[0] == 'O')
  368. {
  369. m_stVideoParam.iActiveCamera = MEDIA_CONFIG_CAMERA_TYPE_OPT;
  370. }
  371. else
  372. {
  373. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("warning: unknown ActiveTrackingCamera value!");
  374. }
  375. }
  376. else if (_stricmp(pszKey, SYSVAR_AGENTCAMERASWITCH) == 0)
  377. {
  378. if(pszValue[0] == 'E')
  379. {
  380. m_stVideoParam.iCameraSwitch = MEDIA_CONFIG_CAMERA_TYPE_ENV;
  381. }
  382. else if(pszValue[0] == 'O')
  383. {
  384. m_stVideoParam.iCameraSwitch = MEDIA_CONFIG_CAMERA_TYPE_OPT;
  385. }
  386. else if(pszValue[0] == 'A')
  387. {
  388. m_stVideoParam.iCameraSwitch = MEDIA_CONFIG_CAMERA_TYPE_AUTO;
  389. }
  390. }
  391. if (_stricmp(pszKey, "UIState") == 0)
  392. {
  393. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("UIState %s -> %s.", pszOldValue, pszValue);
  394. if (pszOldValue[0] == 'X' && pszValue[0] == 'M')
  395. {
  396. if (false == m_bFirstLaunched) {
  397. m_bFirstLaunched = true;
  398. }
  399. }
  400. }
  401. }
  402. void CSIPEntity::OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  403. {
  404. if (Test_ShakeHand == eTestType)
  405. {
  406. pTransactionContext->SendAnswer(m_SipErrorCode);
  407. }
  408. }
  409. void CSIPEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  410. {
  411. ErrorCodeEnum Error = __OnStart(Error_Succeed);
  412. pTransactionContext->SendAnswer(Error);
  413. }
  414. void CSIPEntity::OnStarted()
  415. {
  416. ErrorCodeEnum Error = Error_Succeed;
  417. m_pHMClient = new HealthManagerService_ClientBase(this);
  418. Error = m_pHMClient->Connect();
  419. if (Error != Error_Succeed) {
  420. m_pHMClient->SafeDelete();
  421. m_pHMClient = NULL;
  422. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_pHMClient connect fail!");
  423. }
  424. m_pSipphoneChannel = new ChannelSipphoneClient(this);
  425. if (Error_Succeed == ConnectAssistChannel()){
  426. m_bConnectedAssist = true;
  427. }
  428. if (!m_pAudioMgr || !m_bAudioMgrInited){
  429. return;
  430. }
  431. int ideviceid = -1;
  432. if (strlen(conf.audio_handfree_in_dev) > 0){
  433. ideviceid = m_pAudioMgr->audio_get_device_id(conf.audio_handfree_in_dev, true);
  434. if (-1 == ideviceid){
  435. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_COREAUDIO_NOTMATCH_PORTAUDIO, CSimpleStringA::Format("core audio can not get [%s] device id.", conf.audio_handfree_in_dev).GetData());
  436. }
  437. }
  438. if (strlen(conf.audio_handfree_out_dev) > 0){
  439. ideviceid = m_pAudioMgr->audio_get_device_id(conf.audio_handfree_out_dev, false);
  440. if (-1 == ideviceid){
  441. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_COREAUDIO_NOTMATCH_PORTAUDIO, CSimpleStringA::Format("core audio can not get [%s] device id.", conf.audio_handfree_out_dev).GetData());
  442. }
  443. }
  444. if (eStand2sType == m_eDeviceType){
  445. if (strlen(conf.audio_pickup_in_dev) > 0){
  446. ideviceid = m_pAudioMgr->audio_get_device_id(conf.audio_pickup_in_dev, true);
  447. if (-1 == ideviceid){
  448. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_COREAUDIO_NOTMATCH_PORTAUDIO, CSimpleStringA::Format("core audio can not get [%s] device id.", conf.audio_pickup_in_dev).GetData());
  449. }
  450. }
  451. if (strlen(conf.audio_pickup_out_dev) > 0){
  452. ideviceid = m_pAudioMgr->audio_get_device_id(conf.audio_pickup_out_dev, false);
  453. if (-1 == ideviceid){
  454. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_COREAUDIO_NOTMATCH_PORTAUDIO, CSimpleStringA::Format("core audio can not get [%s] device id.", conf.audio_pickup_out_dev).GetData());
  455. }
  456. }
  457. }
  458. Error = GetLocalIP();
  459. if (Error != 0) {
  460. CSimpleStringA strErrMsg = "获取本地 IP 地址失败,请检查本地网络是否连接!";
  461. LogWarn(Severity_Middle, Error_NetBroken, ERROR_MOD_SIP_GET_LOCAL_IP_FAILED, strErrMsg.GetData());
  462. }
  463. LogEvent(Severity_Middle, LOG_EVT_MOD_SIPPHONE_STARTED_SUCCESS, "sipphone entity started successfully.");
  464. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_ENTITY_STARTED, "sipphone entity started.");
  465. }
  466. ErrorCodeEnum CSIPEntity::LoadEntityConfig()
  467. {
  468. SpIniMappingTable table;
  469. int iTime = RVC_INTERVAL_TIME;
  470. int iStopRestartFlag = 0;
  471. CSimpleStringA strStartTime;
  472. CSimpleStringA strEndTime;
  473. int iAudioLibType = 0;
  474. int iAudioDspUseCenter = 0;
  475. table.AddEntryInt("SipPhone", "AudioDspUseCenter", iAudioDspUseCenter, 0);
  476. table.AddEntryInt("SipPhone", "ReStartInterVal", iTime, RVC_INTERVAL_TIME);
  477. table.AddEntryInt("SipPhone", "StopAutoRestartFlag", iStopRestartFlag, 0);
  478. table.AddEntryString("SipPhone", "StartTime", strStartTime, "$");
  479. table.AddEntryString("SipPhone", "EndTime", strEndTime, "$");
  480. CSmartPointer<IConfigInfo> spConfig;
  481. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
  482. if (Error == Error_Succeed) {
  483. Error = table.Load(spConfig);
  484. if (Error_Succeed == Error){
  485. m_iAudioDspUseCenter = iAudioDspUseCenter;
  486. if (iTime >= RVC_INTERVAL_TIME/3){
  487. m_itervalTime = iTime;
  488. }
  489. if (1 == iStopRestartFlag){
  490. m_bStopAutoRestart = true;
  491. }
  492. if (strStartTime.GetLength() > 1 && _stricmp(strStartTime.GetData(), RVC_START_TIME) >= 0) {
  493. m_strStartTime = strStartTime;
  494. }
  495. if (strEndTime.GetLength() > 1 && _stricmp(strEndTime.GetData(), RVC_END_TIME) <= 0) {
  496. m_strEndTime = strEndTime;
  497. }
  498. }
  499. }
  500. return Error;
  501. }
  502. ErrorCodeEnum CSIPEntity::ConnectAssistChannel()
  503. {
  504. if (NULL == m_pSipphoneChannel) {
  505. m_pSipphoneChannel = new ChannelSipphoneClient(this);
  506. }
  507. ErrorCodeEnum Error = m_pSipphoneChannel->Connect();
  508. if (Error != Error_Succeed) {
  509. m_pSipphoneChannel->SafeDelete();
  510. m_pSipphoneChannel = NULL;
  511. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ChannelSipphoneClient connect fail!");
  512. return Error;
  513. }
  514. {
  515. ChannelService_BeginState_Sub Sub;
  516. Error = (*m_pSipphoneChannel)(EntityResource::getLink().upgradeLink())->BeginState(Sub);
  517. if (Error != Error_Succeed) {
  518. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("BeginState biz channel failed!");
  519. m_pSipphoneChannel->GetFunction()->CloseSession();
  520. m_pSipphoneChannel->SafeDelete();
  521. m_pSipphoneChannel = NULL;
  522. return Error;
  523. }
  524. }
  525. {
  526. ChannelService_BeginRecv_Sub Sub;
  527. Sub.type = ACM_TYPE_DEVICE;
  528. Error = (*m_pSipphoneChannel)(EntityResource::getLink().upgradeLink())->BeginRecv(Sub);
  529. if (Error != Error_Succeed) {
  530. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Begin BeginRecv ACM_TYPE_DEVICE failed!");
  531. m_pSipphoneChannel->GetFunction()->CloseSession();
  532. m_pSipphoneChannel->SafeDelete();
  533. m_pSipphoneChannel = NULL;
  534. return Error;
  535. }
  536. }
  537. {
  538. ChannelService_BeginRecv_Sub Sub;
  539. Sub.type = ACM_TYPE_VIDEOFREQ;
  540. Error = (*m_pSipphoneChannel)(EntityResource::getLink().upgradeLink())->BeginRecv(Sub);
  541. if (Error != Error_Succeed) {
  542. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Begin BeginRecv ACM_TYPE_VIDEOFREQ failed!");
  543. m_pSipphoneChannel->GetFunction()->CloseSession();
  544. m_pSipphoneChannel->SafeDelete();
  545. m_pSipphoneChannel = NULL;
  546. return Error;
  547. }
  548. }
  549. return Error;
  550. }
  551. void CSIPEntity::HandleUSBAudioDeviceErrorEvent()
  552. {
  553. struct tm* ptm = NULL;
  554. time_t t = time(NULL);
  555. ptm = localtime(&t);
  556. char strNow[MAX_PATH] = { 0 };
  557. char strTime[MAX_PATH] = { 0 };
  558. _snprintf(strNow, MAX_PATH, "%02d:%02d:%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
  559. unsigned int utime = y2k_time_now();
  560. y2k_to_string(utime, strTime, MAX_PATH);
  561. if (_stricmp(strNow, m_strStartTime.GetData()) < 0 || _stricmp(strNow, m_strEndTime.GetData()) >= 0) {
  562. GetFunction()->SetTimer(RVC_ENTER_HOME_PAGE_TIMER, this, 1000);
  563. }
  564. else {
  565. unsigned int ulasttime = 0;
  566. LoadRestartRunConfig(ulasttime);
  567. if (utime - ulasttime > m_itervalTime * 60) {
  568. LogWarn(Severity_Low, Error_Debug, LOG_EVT_SIPPHONE_RETART_REQUEST, "请求重启机器");
  569. if (Error_Succeed != SaveRestartRunConfig(utime)) {
  570. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Save Run Config Restart time[%s] failed.", strTime);
  571. }
  572. LogEvent(Severity_High, EVENT_MOD_SIP_RESART, "LogEvent Restart Event!");
  573. }
  574. }
  575. }
  576. //载入运行时配置
  577. ErrorCodeEnum CSIPEntity::LoadRestartRunConfig(unsigned int& utime)
  578. {
  579. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  580. CSmartPointer<IConfigInfo> spConfig;
  581. ErrorCodeEnum Error = spFunction->OpenConfig(Config_Run, spConfig);
  582. if (Error == Error_Succeed)
  583. {
  584. SpIniMappingTable table;
  585. table.AddEntryUInt("AutoResart", "time", utime, 0);
  586. Error = table.Load(spConfig);
  587. if (Error != Error_Succeed){
  588. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("failed to load run config.");
  589. }
  590. }
  591. else{
  592. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("failed to open run config.");
  593. }
  594. return Error;
  595. }
  596. //保存运行时
  597. ErrorCodeEnum CSIPEntity::SaveRestartRunConfig(unsigned int utime)
  598. {
  599. CSmartPointer<IEntityFunction> spFunction = GetFunction();;
  600. CSmartPointer<IConfigInfo> spConfig;
  601. ErrorCodeEnum Error = spFunction->OpenConfig(Config_Run, spConfig);
  602. if (Error == Error_Succeed){
  603. Error = spConfig->WriteConfigValueInt("AutoResart", "time", utime);
  604. }
  605. else{
  606. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("AutoResart is fail , open sipphone.ini fail!");
  607. }
  608. return Error;
  609. }
  610. ErrorCodeEnum CSIPEntity::AudioDspFlagsUseCentersetting(endpoint_conf_t* conf)
  611. {
  612. SpIniMappingTable table;
  613. CSmartPointer<IConfigInfo> spConfig;
  614. endpoint_audiodsp_config_t audiodsp = { false, false, false, false, true, false, true, false, false, true };
  615. table.AddEntryBoolean("SipPhone", "pickup_out_agc", audiodsp.audio_pickup_out_agc, false);
  616. table.AddEntryBoolean("SipPhone", "pickup_in_agc", audiodsp.audio_pickup_in_agc, false);
  617. table.AddEntryBoolean("SipPhone", "handfree_in_agc", audiodsp.audio_handfree_in_agc, false);
  618. table.AddEntryBoolean("SipPhone", "handfree_out_agc", audiodsp.audio_handfree_out_agc, false);
  619. table.AddEntryBoolean("SipPhone", "pickup_out_ns", audiodsp.audio_pickup_out_ns, false);
  620. table.AddEntryBoolean("SipPhone", "pickup_in_ns", audiodsp.audio_pickup_in_ns, true);
  621. table.AddEntryBoolean("SipPhone", "handfree_in_ns", audiodsp.audio_handfree_in_ns, true);
  622. table.AddEntryBoolean("SipPhone", "handfree_out_ns", audiodsp.audio_handfree_out_ns, false);
  623. table.AddEntryBoolean("SipPhone", "pickup_aec", audiodsp.audio_pickup_aec, false);
  624. table.AddEntryBoolean("SipPhone", "handfree_aec", audiodsp.audio_handfree_aec, true);
  625. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
  626. if (Error == Error_Succeed) {
  627. Error = table.Load(spConfig);
  628. if (Error_Succeed == Error) {
  629. memcpy(&conf->audio_dsp, &audiodsp, sizeof(endpoint_audiodsp_config_t));
  630. }
  631. }
  632. else {
  633. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("AudioDspFlagsUseCentersetting load Centersetting failed!");
  634. memcpy(&conf->audio_dsp, &audiodsp, sizeof(endpoint_audiodsp_config_t));
  635. }
  636. return Error;
  637. }
  638. ErrorCodeEnum CSIPEntity::__OnStart(ErrorCodeEnum preOperationError)
  639. {
  640. ErrorCodeEnum Error = Error_Succeed;
  641. {
  642. audiomgr_callback_t t_callback = { 0 };
  643. t_callback.debug = &__audiomgrlog;
  644. m_pAudioMgr = CreateAudioMgrObj(&t_callback);
  645. if (0 == m_pAudioMgr->audio_mgr_initialize()) {
  646. m_bAudioMgrInited = true;
  647. }
  648. else {
  649. LogWarn(Severity_Middle, Error_Debug, LOG_EVT_SIPPHONE_AUDIOMGR_INITIAL_FAILED, "audio manager initialize failed!");
  650. }
  651. }
  652. m_eDeviceType = RvcGetDeviceType();
  653. m_stVideoParam.bActiveInspect = 0;
  654. m_stVideoParam.bShowActiveImg = 0;
  655. m_stVideoParam.nWindowState = 0;
  656. video_lib_init();
  657. audio_lib_init();
  658. endpoint_init_lib();
  659. RvcGetAudioDeviceInfo();
  660. if (Error_Succeed != LoadEntityConfig()){
  661. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("LoadEntityConfig failed.");
  662. }
  663. Error = LoadConfig(&conf);
  664. if (Error != Error_Succeed) {
  665. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("load config failed!");
  666. }
  667. if (IsPostAudioConfigInfo()) {
  668. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_AUDIO_DEVICE_INFO, generateAudioInfoJson(conf.audio_handfree_in_dev, conf.audio_handfree_out_dev, conf.audio_pickup_in_dev, conf.audio_pickup_out_dev).GetData());
  669. }
  670. else {
  671. //有配置为空的,进关门页
  672. return Error_Param;
  673. }
  674. uint32_t uCheckRet = CheckAudioDevice();
  675. if (RVC_AUDIO_NO_ERROR == uCheckRet) {
  676. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("no audio device config error.");
  677. }
  678. else {
  679. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("error audio device number is %d.", countnum(uCheckRet));
  680. if (countnum(uCheckRet) >= 3) { //故障设备数大于3个或以上
  681. return Error_Param;
  682. }
  683. if (uCheckRet = RVC_AUDIO_HANDFREEIN_ERROR | RVC_AUDIO_HANDFREEOUT_ERROR) {
  684. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("can't find usb audio device.");
  685. HandleUSBAudioDeviceErrorEvent();
  686. }
  687. }
  688. int nhandfreeout = 0;
  689. int npickupout = 0;
  690. int nhanfreein = 0;
  691. int npickupin = 0;
  692. Error = LoadAudioRunConfig(nhandfreeout,npickupout,nhanfreein,npickupin);
  693. if (Error == Error_Succeed)
  694. {
  695. if (nhandfreeout > 0){
  696. m_kept_volume_out[DEV_HANDFREE] = nhandfreeout;
  697. }
  698. if (npickupout > 0){
  699. m_kept_volume_out[DEV_PICKUP] = npickupout;
  700. }
  701. if (nhanfreein > 0){
  702. m_kept_volume_in[DEV_HANDFREE] = nhanfreein;
  703. }
  704. if (npickupin > 0){
  705. m_kept_volume_in[DEV_PICKUP] = npickupin;
  706. }
  707. }
  708. #ifdef RVC_OS_LINUX
  709. RvcSetSaveAudioVolume();
  710. #endif
  711. {
  712. CSmartPointer<IEntityFunction> Func = GetFunction();
  713. CUUID id;
  714. int i = 0;
  715. m_arrListener.Init(27);
  716. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANDFREE_TO_PICKUP, EVT_CONVERTER);
  717. m_arrListener[i++] = id;
  718. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_PICKUP_TO_HANDFREE, EVT_CONVERTER);
  719. m_arrListener[i++] = id;
  720. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_PICKUP_CALL, EVT_CONVERTER);
  721. m_arrListener[i++] = id;
  722. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_SLV_HANDFREECALL,NULL,false);
  723. m_arrListener[i++] = id;
  724. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_SLV_PICKUPCALL,NULL,false);
  725. m_arrListener[i++] = id;
  726. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP,NULL,false);
  727. m_arrListener[i++] = id;
  728. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE,NULL,false);
  729. m_arrListener[i++] = id;
  730. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS,NULL,false);
  731. m_arrListener[i++] = id;
  732. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_ENTER_ACM_FLOW,NULL,false);
  733. m_arrListener[i++] = id;
  734. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_EXIT_ACM_FLOW,NULL,false);
  735. m_arrListener[i++] = id;
  736. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_CHANGELIVEDETECTIONCAM,NULL,false);
  737. m_arrListener[i++] = id;
  738. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_RELEASELIVEDETECTION,NULL,false);
  739. m_arrListener[i++] = id;
  740. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_HIDEONLINEVIDEO,NULL,false);
  741. m_arrListener[i++] = id;
  742. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_SHOWONLINEVIDEO,NULL,false);
  743. m_arrListener[i++] = id;
  744. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORD,NULL,false);
  745. m_arrListener[i++] = id;
  746. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPRECORD,NULL,false);
  747. m_arrListener[i++] = id;
  748. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RETURNMENU,NULL,false);
  749. m_arrListener[i++] = id;
  750. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_HIDELOCALVIDEO,NULL,false);
  751. m_arrListener[i++] = id;
  752. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_SHOWLOCALVIDEO,NULL,false);
  753. m_arrListener[i++] = id;
  754. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_HIDEPERSONAREA,NULL,false);
  755. m_arrListener[i++] = id;
  756. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_SHOWPERSONAREA,NULL,false);
  757. m_arrListener[i++] = id;
  758. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_STOP_RECORD_BROADCAST,NULL,false);
  759. m_arrListener[i++] = id;
  760. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_BEGAIN_RECORD_CALL,NULL,false);
  761. m_arrListener[i++] = id;
  762. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTREMOTERECORD,NULL,false);
  763. m_arrListener[i++] = id;
  764. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPREMOTERECORD,NULL,false);
  765. m_arrListener[i++] = id;
  766. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_HANDFREE_MODE_REMOTE_CALL,NULL,false);
  767. m_arrListener[i++] = id;
  768. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_PICKUP_MODE_REMOTE_CALL,NULL,false);
  769. m_arrListener[i++] = id;
  770. }
  771. {
  772. CSmartPointer<IEntityFunction> Func = GetFunction();
  773. CSimpleStringA strValue;
  774. Func->RegistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA, this);
  775. Func->GetSysVar(SYSVAR_ACTIVETRACKINGCAMERA, strValue);
  776. if (strValue[0] == 'E')
  777. {
  778. m_stVideoParam.iActiveCamera = MEDIA_CONFIG_CAMERA_TYPE_ENV;
  779. }
  780. else if (strValue[0] == 'O')
  781. {
  782. m_stVideoParam.iActiveCamera = MEDIA_CONFIG_CAMERA_TYPE_OPT;
  783. }
  784. else
  785. {
  786. assert(0);
  787. }
  788. }
  789. {
  790. CSmartPointer<IEntityFunction> Func = GetFunction();
  791. CSimpleStringA strValue;
  792. Func->RegistSysVarEvent(SYSVAR_CAMERASTATE, this);
  793. Func->GetSysVar(SYSVAR_CAMERASTATE, strValue);
  794. if (strValue[0] == 'E')
  795. {
  796. m_stVideoParam.iCameraState = MEDIA_CONFIG_CAMERA_TYPE_OPT;
  797. }
  798. else if (strValue[0] == 'O')
  799. {
  800. m_stVideoParam.iCameraState = MEDIA_CONFIG_CAMERA_TYPE_ENV;
  801. }
  802. else if(strValue[0] == 'B') ///////显示贴图
  803. {
  804. /////////////////////////此处显示贴图//////////////////////////////////
  805. //m_stVideoParam.iCameraSwitch = CAMERA_TYPE_ERROR;
  806. m_stVideoParam.iCameraState = MEDIA_CONFIG_CAMERA_TYPE_ERROR;
  807. }
  808. else if (strValue[0] == 'N')
  809. {
  810. //m_stVideoParam.iCameraSwitch = CAMERA_TYPE_AUTO;
  811. m_stVideoParam.iCameraState = MEDIA_CONFIG_CAMERA_TYPE_AUTO;
  812. }
  813. }
  814. {
  815. CSmartPointer<IEntityFunction> Func = GetFunction();
  816. CSimpleStringA strValue;
  817. Func->RegistSysVarEvent(SYSVAR_AGENTCAMERASWITCH, this);
  818. Func->GetSysVar(SYSVAR_AGENTCAMERASWITCH, strValue);
  819. if((strValue[0] == 'E'))
  820. {
  821. m_stVideoParam.iCameraSwitch = MEDIA_CONFIG_CAMERA_TYPE_ENV;
  822. }
  823. else if((strValue[0] == 'O'))
  824. {
  825. m_stVideoParam.iCameraSwitch = MEDIA_CONFIG_CAMERA_TYPE_OPT;
  826. }
  827. else if ((strValue[0] == 'A'))
  828. {
  829. m_stVideoParam.iCameraSwitch = MEDIA_CONFIG_CAMERA_TYPE_AUTO;
  830. }
  831. }
  832. {
  833. CSmartPointer<IEntityFunction> Func = GetFunction();
  834. CSimpleStringA strValue("");
  835. Func->RegistSysVarEvent("UIState", this);
  836. Func->GetSysVar("UIState", strValue);
  837. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("UIState %s.", strValue.GetData());
  838. }
  839. if (m_kept_volume_in[DEV_HANDFREE]) {
  840. m_pKeeperIn[DEV_HANDFREE] = volume_keeper_create(conf.audio_handfree_in_dev, 1, m_kept_volume_in[DEV_HANDFREE]);
  841. if (!m_pKeeperIn[DEV_HANDFREE]) {
  842. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("HANDFREE in volume keeper create failed!");
  843. }
  844. }
  845. if (m_kept_volume_out[DEV_HANDFREE]) {
  846. m_pKeeperOut[DEV_HANDFREE] = volume_keeper_create(conf.audio_handfree_out_dev, 0, m_kept_volume_out[DEV_HANDFREE]);
  847. if (!m_pKeeperOut[DEV_HANDFREE]) {
  848. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("HANDFREE out volume keeper create failed!");
  849. }
  850. }
  851. if (m_kept_volume_in[DEV_PICKUP]&&(eStand2sType == m_eDeviceType)){
  852. m_pKeeperIn[DEV_PICKUP] = volume_keeper_create(conf.audio_pickup_in_dev, 1, m_kept_volume_in[DEV_PICKUP]);
  853. if (!m_pKeeperIn[DEV_PICKUP]) {
  854. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PICKUP in volume keeper create failed!");
  855. }
  856. }
  857. if (m_kept_volume_out[DEV_PICKUP]&&(eStand2sType == m_eDeviceType)){
  858. m_pKeeperOut[DEV_PICKUP] = volume_keeper_create(conf.audio_pickup_out_dev, 0, m_kept_volume_out[DEV_PICKUP]);
  859. if (!m_pKeeperOut[DEV_PICKUP]) {
  860. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PICKUP out volume keeper create failed!");
  861. }
  862. }
  863. return Error_Succeed;
  864. }
  865. void CSIPEntity::OnReceivePkt(int type, int sub_type, const char *buffer, int size)
  866. {
  867. if (type == ACM_TYPE_DEVICE)
  868. {
  869. if (sub_type == ACM_SET_HANDFREE_OUTVOLUMN)
  870. {
  871. CVolumnValue num;
  872. SpBuffer buf;
  873. buf.OpenRead(buffer,size);
  874. num.Serialize(buf);
  875. if (m_pKeeperOut[DEV_HANDFREE]) {
  876. volume_keeper_change(m_pKeeperOut[DEV_HANDFREE],num.nValue);
  877. m_kept_volume_out[DEV_HANDFREE] = num.nValue;
  878. SendAudioDeviceVolumn(DEVICE_HANDFREE_OUT);
  879. 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]);
  880. }
  881. else{
  882. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("HANDFREE out volume keeper create failed!");
  883. }
  884. }
  885. else if((sub_type == ACM_SET_PICKUP_OUTVOLUMN)&&(eStand2sType == m_eDeviceType))
  886. {
  887. CVolumnValue num;
  888. SpBuffer buf;
  889. buf.OpenRead(buffer,size);
  890. num.Serialize(buf);
  891. if (m_pKeeperOut[DEV_PICKUP])
  892. {
  893. if(eStand2sType == m_eDeviceType){
  894. volume_keeper_change(m_pKeeperOut[DEV_PICKUP],num.nValue);
  895. m_kept_volume_out[DEV_PICKUP] = num.nValue;
  896. SendAudioDeviceVolumn(DEVICE_PICKUP_OUT);
  897. 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]);
  898. }
  899. else //pad版屏蔽当前PICKUP音量设置
  900. {
  901. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PAD type, ignore pickupout volume adj");
  902. }
  903. }
  904. else {
  905. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PICKUP out volume keeper create failed!");
  906. }
  907. }
  908. else if (sub_type == ACM_SET_HANDFREE_INVOLUMN)
  909. {
  910. CVolumnValue num;
  911. SpBuffer buf;
  912. buf.OpenRead(buffer,size);
  913. num.Serialize(buf);
  914. if (m_pKeeperIn[DEV_HANDFREE]) {
  915. volume_keeper_change(m_pKeeperIn[DEV_HANDFREE],num.nValue);
  916. m_kept_volume_in[DEV_HANDFREE] = num.nValue;
  917. SendAudioDeviceVolumn(DEVICE_HANDFREE_IN);
  918. 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]);
  919. }
  920. else {
  921. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("handfree in volume keeper create failed!");
  922. }
  923. }
  924. else if((sub_type == ACM_SET_PICKUP_INVOLUMN)&&(eStand2sType == m_eDeviceType))
  925. {
  926. CVolumnValue num;
  927. SpBuffer buf;
  928. buf.OpenRead(buffer,size);
  929. num.Serialize(buf);
  930. if (m_pKeeperIn[DEV_PICKUP]) {
  931. if(eStand2sType == m_eDeviceType){
  932. volume_keeper_change(m_pKeeperIn[DEV_PICKUP],num.nValue);
  933. m_kept_volume_in[DEV_PICKUP] = num.nValue;
  934. SendAudioDeviceVolumn(DEVICE_PICKUP_IN);
  935. 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]);
  936. }
  937. else //pad版屏蔽当前PICKUP音量设置
  938. {
  939. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PAD type, ignore pickup in volume adj");
  940. }
  941. }
  942. else{
  943. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("pickup in volume keeper create failed!");
  944. }
  945. }
  946. else if (sub_type == ACM_CONTROL_PERSONAREA) //控制人形框
  947. {
  948. CVolumnValue num;
  949. SpBuffer buf;
  950. buf.OpenRead(buffer,size);
  951. num.Serialize(buf);
  952. if (num.nValue == 0) //隐藏人形框
  953. {
  954. LogEvent(Severity_Middle,LOG_EVT_UI_HIDELOCALVIDEO,"Agent send hide local video");
  955. LogEvent(Severity_Middle,LOG_EVT_UI_HIDEPERSONAREA,"Agent send Hide Person area");
  956. }
  957. else if (num.nValue == 1) //显示人形框
  958. {
  959. LogEvent(Severity_Middle,LOG_EVT_UI_SHOWLOCALVIDEO,"Agent send show local video");
  960. LogEvent(Severity_Middle,LOG_EVT_UI_SHOWPERSONAREA,"Agent send Show Person area");
  961. }
  962. else {
  963. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("recv control person area sub_type error!");
  964. }
  965. }
  966. }
  967. else if (type == ACM_TYPE_VIDEOFREQ)
  968. {
  969. }
  970. }
  971. ErrorCodeEnum CSIPEntity::RvcGetAudioDeviceInfo()
  972. {
  973. ErrorCodeEnum Error = Error_Succeed;
  974. if (NULL != m_pAudioMgr || !m_bAudioMgrInited) {
  975. int icountmic = m_pAudioMgr->audio_get_device_count(true);
  976. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("core audio input device(%d):", icountmic);
  977. int i = 0;
  978. for (; i < icountmic; i++) {
  979. char strname[MAX_PATH] = { 0 };
  980. m_pAudioMgr->audio_get_device_name(strname, MAX_PATH, true, i);
  981. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%d = %s", i, strname);
  982. }
  983. if (icountmic < RVC_AUDIO_IN_DEVICE_COUNT) {
  984. LogWarn(Severity_Middle, Error_AudioIN, ERROR_MOD_SIP_AUDIO_IN_COUNT, CSimpleString::Format("audio in device count is %d.", icountmic).GetData());
  985. }
  986. int icountspeaker = m_pAudioMgr->audio_get_device_count(false);
  987. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("core audio output device(%d):", icountspeaker);
  988. for (i = 0; i < icountspeaker; i++) {
  989. char strname[MAX_PATH] = { 0 };
  990. m_pAudioMgr->audio_get_device_name(strname, MAX_PATH, false, i);
  991. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%d = %s", i, strname);
  992. }
  993. if (icountspeaker < RVC_AUDIO_IN_DEVICE_COUNT) {
  994. LogWarn(Severity_Middle, Error_AudioOut, ERROR_MOD_SIP_AUDIO_OUT_COUNT, CSimpleString::Format("audio out device count is %d.", icountspeaker).GetData());
  995. }
  996. Error = Error_Succeed;
  997. }
  998. return Error;
  999. }
  1000. ErrorCodeEnum CSIPEntity::RvcSetSaveAudioVolume()
  1001. {
  1002. ErrorCodeEnum Error = Error_Succeed;
  1003. if (m_pAudioMgr){
  1004. m_pAudioMgr->audio_set_device_volume(m_kept_volume_out[DEV_HANDFREE], conf.audio_handfree_out_dev, false);
  1005. m_pAudioMgr->audio_set_device_volume(m_kept_volume_in[DEV_HANDFREE], conf.audio_handfree_in_dev, true);
  1006. if (eStand2sType == m_eDeviceType){
  1007. m_pAudioMgr->audio_set_device_volume(m_kept_volume_out[DEV_PICKUP], conf.audio_pickup_out_dev, false);
  1008. m_pAudioMgr->audio_set_device_volume(m_kept_volume_in[DEV_PICKUP], conf.audio_pickup_in_dev, true);
  1009. }
  1010. }
  1011. return Error;
  1012. }
  1013. bool CSIPEntity::IsPostAudioConfigInfo()
  1014. {
  1015. bool bRet = false;
  1016. if (strlen(conf.audio_handfree_in_dev) && strlen(conf.audio_handfree_out_dev) && strlen(conf.audio_pickup_in_dev) && strlen(conf.audio_pickup_out_dev)) {
  1017. bRet = true;
  1018. }
  1019. return bRet;
  1020. }
  1021. uint32_t CSIPEntity::CheckAudioDevice()
  1022. {
  1023. int id = -1;
  1024. uint32_t Error = RVC_AUDIO_NO_ERROR;
  1025. id = capture_get_audio_device_id(true, conf.audio_handfree_in_dev);
  1026. if (id == -1) {
  1027. LogWarn(Severity_Middle, Error_Debug, EVENT_MOD_SIP_AUDIO_IN_DEVICE_NOT_EXIST, CSimpleStringA::Format("hand free in audio device %s does not exist!", conf.audio_handfree_in_dev).GetData());
  1028. Error = RVC_AUDIO_HANDFREEIN_ERROR;
  1029. }
  1030. id = capture_get_audio_device_id(false, conf.audio_handfree_out_dev);
  1031. if (id == -1) {
  1032. LogWarn(Severity_Middle, Error_Debug, EVENT_MOD_SIP_AUDIO_OUT_DEVICE_NOT_EXIST, CSimpleStringA::Format("hand free out audio device %s does not exist!", conf.audio_handfree_out_dev).GetData());
  1033. Error |= RVC_AUDIO_HANDFREEOUT_ERROR;
  1034. }
  1035. id = capture_get_audio_device_id(true, conf.audio_pickup_in_dev);
  1036. if (id == -1) {
  1037. LogWarn(Severity_Middle, Error_Debug, EVENT_MOD_SIP_AUDIO_IN_DEVICE_NOT_EXIST, CSimpleStringA::Format("pickup in audio device %s does not exist!", conf.audio_pickup_in_dev).GetData());
  1038. Error |= RVC_AUDIO_PICKUPIN_ERROR;
  1039. }
  1040. id = capture_get_audio_device_id(false, conf.audio_pickup_out_dev);
  1041. if (id == -1) {
  1042. LogWarn(Severity_Middle, Error_Debug, EVENT_MOD_SIP_AUDIO_OUT_DEVICE_NOT_EXIST, CSimpleStringA::Format("pickup out audio device %s does not exist!", conf.audio_pickup_out_dev).GetData());
  1043. Error |= RVC_AUDIO_PICKUPOUT_ERROR;
  1044. }
  1045. if (RVC_AUDIO_NO_ERROR != Error) {
  1046. LogWarn(Severity_Middle, Error_Debug, EVENT_MOD_SIP_AUDIO_DEVICE_CONFIG_ERROR, CSimpleStringA::Format("config audio device not exist.").GetData());
  1047. }
  1048. return Error;
  1049. }
  1050. ErrorCodeEnum CSIPEntity::GetLocalIP()
  1051. {
  1052. char tmp[MAX_PATH] = {0};
  1053. gethostname(tmp, sizeof(tmp));
  1054. hostent *ent = gethostbyname(tmp);
  1055. if (ent) {
  1056. int icount = 0;
  1057. for(; ent->h_addr_list[icount]; ){
  1058. ++icount;
  1059. }
  1060. if(icount > 1){
  1061. LogWarn(Severity_Middle, Error_Debug, EVENT_MOD_SIP_CALL_MUTIL_NIC, CSimpleStringA::Format("device net adapter number is %d.", icount).GetData());
  1062. }
  1063. for (int i = 0; ent->h_addr_list[i]; ++i) {
  1064. if (ent->h_addrtype == AF_INET) {
  1065. struct in_addr *in = (struct in_addr*)ent->h_addr_list[i];
  1066. char *p = inet_ntoa(*in);
  1067. if (p[0] != '0')
  1068. {
  1069. if(strstr(p,"198.168.") == NULL && 0 != strncmp(p, "2.0.0.1",strlen("2.0.0.1")))
  1070. {
  1071. strcpy(m_localip, p);
  1072. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_GET_LOCAL_IP, CSimpleStringA::Format("local ip == %s", m_localip).GetData());
  1073. return Error_Succeed;
  1074. }
  1075. else {
  1076. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_INVALID_IP, CSimpleStringA::Format("invalid ip == %s", p).GetData());
  1077. }
  1078. }
  1079. }
  1080. }
  1081. }
  1082. return Error_Unexpect;
  1083. }
  1084. //send audio device volume
  1085. void CSIPEntity::SendAudioDeviceVolumn(int nDevice)
  1086. {
  1087. ChannelService_Send_Info Info;
  1088. Info.compress = false;
  1089. Info.encrypt = false;
  1090. Info.type = ACM_TYPE_DEVICE;
  1091. Info.id = 0;
  1092. int nValue = 0;
  1093. bool rslt = false;
  1094. void*keeper = NULL;
  1095. if (nDevice == DEVICE_HANDFREE_OUT)
  1096. {
  1097. Info.sub_type = ACM_HANDFREE_OUTVOLUMN;
  1098. #ifdef RVC_OS_WIN
  1099. keeper = m_pKeeperOut[DEV_HANDFREE];
  1100. #else
  1101. m_pAudioMgr->audio_get_device_volume(&nValue, conf.audio_handfree_out_dev, false);
  1102. rslt = true;
  1103. #endif // RVC_OS_WIN
  1104. }
  1105. else if(nDevice == DEVICE_PICKUP_OUT)
  1106. {
  1107. if(eStand2sType == m_eDeviceType)
  1108. {
  1109. Info.sub_type = ACM_PICKUP_OUTVOLUMN;
  1110. #ifdef RVC_OS_WIN
  1111. keeper = m_pKeeperOut[DEV_PICKUP];
  1112. #else
  1113. m_pAudioMgr->audio_get_device_volume(&nValue, conf.audio_pickup_out_dev, false);
  1114. rslt = true;
  1115. #endif
  1116. }
  1117. else //pad版屏蔽当前PICKUP音量发送
  1118. {
  1119. return;
  1120. }
  1121. }
  1122. else if(nDevice == DEVICE_HANDFREE_IN)
  1123. {
  1124. Info.sub_type = ACM_HANDFREE_INVOLUMN;
  1125. #ifdef RVC_OS_WIN
  1126. keeper = m_pKeeperIn[DEV_HANDFREE];
  1127. #else
  1128. m_pAudioMgr->audio_get_device_volume(&nValue, conf.audio_handfree_in_dev, true);
  1129. rslt = true;
  1130. #endif
  1131. }
  1132. else if(nDevice == DEVICE_PICKUP_IN)
  1133. {
  1134. if(eStand2sType == m_eDeviceType)
  1135. {
  1136. Info.sub_type = ACM_PICKUP_INVOLUMN;
  1137. #ifdef RVC_OS_WIN
  1138. keeper = m_pKeeperIn[DEV_PICKUP];
  1139. #else
  1140. m_pAudioMgr->audio_get_device_volume(&nValue, conf.audio_pickup_in_dev, true);
  1141. rslt = true;
  1142. #endif
  1143. }
  1144. else //pad版屏蔽当前PICKUP音量发送
  1145. {
  1146. return;
  1147. }
  1148. }
  1149. Info.data.Alloc(sizeof(int));
  1150. SpBuffer buf;
  1151. buf.OpenWrite();
  1152. #ifdef RVC_OS_WIN
  1153. if (keeper){
  1154. rslt = get_audiodevice_volumn(keeper, &nValue);
  1155. }
  1156. #endif
  1157. if (rslt == true)
  1158. {
  1159. buf & nValue;
  1160. Info.data = buf.ToBlob();
  1161. m_pSipphoneChannel->Send(Info);
  1162. }
  1163. else
  1164. {
  1165. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Get cur Audio device %d volume Fail!",nDevice);
  1166. }
  1167. }
  1168. ErrorCodeEnum CSIPEntity::SetHandfreeOutVolume(int iVolume)
  1169. {
  1170. ErrorCodeEnum Error = Error_Succeed;
  1171. #ifdef RVC_OS_WIN
  1172. if (m_pKeeperOut[DEV_HANDFREE])
  1173. {
  1174. volume_keeper_change(m_pKeeperOut[DEV_HANDFREE], iVolume);
  1175. m_kept_volume_out[DEV_HANDFREE] = iVolume;
  1176. 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]);
  1177. }
  1178. else
  1179. {
  1180. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("HANDFREE out volume keeper create failed!");
  1181. }
  1182. #else
  1183. if (m_pAudioMgr)
  1184. {
  1185. m_pAudioMgr->audio_set_device_volume(iVolume, conf.audio_handfree_out_dev, false);
  1186. m_kept_volume_out[DEV_HANDFREE] = iVolume;
  1187. 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]);
  1188. }
  1189. else
  1190. {
  1191. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("HANDFREE out volume keeper create failed!");
  1192. }
  1193. #endif
  1194. return Error;
  1195. }
  1196. ErrorCodeEnum CSIPEntity::SetPickupOutVolume(int iVolume)
  1197. {
  1198. ErrorCodeEnum Error = Error_Succeed;
  1199. #ifdef RVC_OS_WIN
  1200. if (m_pKeeperOut[DEV_PICKUP]){
  1201. if (eStand2sType == m_eDeviceType){
  1202. volume_keeper_change(m_pKeeperOut[DEV_PICKUP], iVolume);
  1203. m_kept_volume_out[DEV_PICKUP] = iVolume;
  1204. 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]);
  1205. }
  1206. else{
  1207. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PAD type, ignore pickupout volume adj");
  1208. }
  1209. }
  1210. else{
  1211. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PICKUP out volume keeper create failed!");
  1212. }
  1213. #else
  1214. if (m_pAudioMgr){
  1215. if (eStand2sType == m_eDeviceType || eStand1SPlusType == m_eDeviceType){
  1216. m_pAudioMgr->audio_set_device_volume(iVolume, conf.audio_pickup_out_dev, false);
  1217. m_kept_volume_out[DEV_PICKUP] = iVolume;
  1218. 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]);
  1219. }
  1220. else{
  1221. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PAD type, ignore pickupout volume adj");
  1222. }
  1223. }
  1224. else{
  1225. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PICKUP out volume keeper create failed!");
  1226. }
  1227. #endif
  1228. return Error;
  1229. }
  1230. ErrorCodeEnum CSIPEntity::SetHandfreeInVolume(int iVolume)
  1231. {
  1232. ErrorCodeEnum Error = Error_Succeed;
  1233. #ifdef RVC_OS_WIN
  1234. if (m_pKeeperIn[DEV_HANDFREE]) {
  1235. volume_keeper_change(m_pKeeperIn[DEV_HANDFREE], iVolume);
  1236. m_kept_volume_in[DEV_HANDFREE] = iVolume;
  1237. 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]);
  1238. }
  1239. #else
  1240. if (m_pAudioMgr) {
  1241. m_pAudioMgr->audio_set_device_volume(iVolume, conf.audio_handfree_in_dev, true);
  1242. m_kept_volume_in[DEV_HANDFREE] = iVolume;
  1243. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("set hand free in volume to %d.", iVolume);
  1244. 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]);
  1245. }
  1246. else {
  1247. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("HANDFREE in volume keeper create failed!");
  1248. }
  1249. #endif
  1250. return Error;
  1251. }
  1252. ErrorCodeEnum CSIPEntity::SetPickupInVolume(int iVolume)
  1253. {
  1254. ErrorCodeEnum Error = Error_Succeed;
  1255. #ifdef RVC_OS_WIN
  1256. if (m_pKeeperIn[DEV_PICKUP]) {
  1257. volume_keeper_change(m_pKeeperIn[DEV_PICKUP], iVolume);
  1258. m_kept_volume_in[DEV_PICKUP] = iVolume;
  1259. 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]);
  1260. }
  1261. #else
  1262. if (m_pAudioMgr) {
  1263. if (eStand2sType == m_eDeviceType || eStand1SPlusType == m_eDeviceType) {
  1264. m_pAudioMgr->audio_set_device_volume(iVolume, conf.audio_pickup_in_dev, true);
  1265. m_kept_volume_in[DEV_PICKUP] = iVolume;
  1266. 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]);
  1267. }
  1268. else {
  1269. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PAD type, ignore pickupin volume adj");
  1270. }
  1271. }
  1272. else {
  1273. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PICKUP in volume keeper create failed!");
  1274. }
  1275. #endif
  1276. return Error;
  1277. }
  1278. void CSIPEntity::OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  1279. {
  1280. ErrorCodeEnum Error = __OnClose(Error_Succeed);
  1281. pTransactionContext->SendAnswer(Error);
  1282. }
  1283. ErrorCodeEnum CSIPEntity::__OnClose(ErrorCodeEnum preOperationError)
  1284. {
  1285. int i;
  1286. #ifdef RVC_OS_WIN
  1287. if (m_pKeeperIn[DEV_HANDFREE]) {
  1288. volume_keeper_destroy(m_pKeeperIn[DEV_HANDFREE]);
  1289. m_pKeeperIn[DEV_HANDFREE] = NULL;
  1290. }
  1291. if (m_pKeeperOut[DEV_HANDFREE]) {
  1292. volume_keeper_destroy(m_pKeeperOut[DEV_HANDFREE]);
  1293. m_pKeeperOut[DEV_HANDFREE] = NULL;
  1294. }
  1295. if (m_pKeeperIn[DEV_PICKUP]) {
  1296. volume_keeper_destroy(m_pKeeperIn[DEV_PICKUP]);
  1297. m_pKeeperIn[DEV_PICKUP] = NULL;
  1298. }
  1299. if (m_pKeeperOut[DEV_PICKUP]) {
  1300. volume_keeper_destroy(m_pKeeperOut[DEV_PICKUP]);
  1301. m_pKeeperOut[DEV_PICKUP] = NULL;
  1302. }
  1303. #else
  1304. if (NULL != m_pAudioMgr) {
  1305. m_pAudioMgr->audio_mgr_terminate();
  1306. DestroyIAudioMgrObj(m_pAudioMgr);
  1307. m_pAudioMgr = NULL;
  1308. }
  1309. #endif
  1310. CSmartPointer<IEntityFunction> Func = GetFunction();
  1311. Func->UnregistSysVarEvent(SYSVAR_AGENTCAMERASWITCH);
  1312. Func->UnregistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA);
  1313. Func->UnregistSysVarEvent(SYSVAR_CAMERASTATE);
  1314. Func->UnregistSysVarEvent("UIState");
  1315. for (i = 0; i < m_arrListener.GetCount(); ++i) {
  1316. Func->UnsubscribeLog(m_arrListener[i]);
  1317. }
  1318. m_arrListener.Clear();
  1319. endpoint_destroy(m_pEndpoint);
  1320. m_pEndpoint = NULL;
  1321. video_lib_deinit();
  1322. audio_lib_deinit();
  1323. endpoint_deinit_lib();
  1324. return Error_Succeed;
  1325. }
  1326. void CSIPEntity::OnPaused()
  1327. {
  1328. }
  1329. void CSIPEntity::OnContinued()
  1330. {
  1331. }
  1332. CServerSessionBase* CSIPEntity::OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszClass*/)
  1333. {
  1334. m_pCurrentSession = new CSIPPhoneSession(this);
  1335. return m_pCurrentSession;
  1336. }
  1337. void CSIPEntity::OnTimeout(DWORD dwTimerID)
  1338. {
  1339. if (dwTimerID == 1)
  1340. {
  1341. GetFunction()->KillTimer(1);
  1342. m_stVideoParam.nUpDynamicFps = -1;
  1343. }
  1344. else if (2 == dwTimerID)
  1345. {
  1346. if (!m_bConnectedAssist) {
  1347. if (Error_Succeed == ConnectAssistChannel()) {
  1348. m_bConnectedAssist = true;
  1349. }
  1350. }
  1351. if (m_bConnectedAssist){
  1352. GetFunction()->KillTimer(2);
  1353. }
  1354. }
  1355. else if (RVC_ENTER_HOME_PAGE_TIMER == dwTimerID) {
  1356. if (m_bFirstLaunched) {
  1357. Sleep(2000);
  1358. UIMessageBox evt;
  1359. evt.uboxtype = 2;
  1360. evt.strtitle = CSimpleStringA2W("声卡识别故障");
  1361. evt.strmessage = CSimpleStringA2W("识别不到USB声卡,请尝试重启机器解决,多次无效后请联系厂商处理");
  1362. SpSendBroadcast(GetFunction(), SP_MSG_OF(UIMessageBox), SP_MSG_SIG_OF(UIMessageBox), evt);
  1363. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SpSendBroadcast UIMessageBox.");
  1364. GetFunction()->KillTimer(RVC_ENTER_HOME_PAGE_TIMER);
  1365. }
  1366. }
  1367. }
  1368. ErrorCodeEnum CSIPEntity::InitEndpoint()
  1369. {
  1370. ErrorCodeEnum eCode = Error_Param;
  1371. CSmartPointer<IEntityFunction> Func = GetFunction();
  1372. Func->GetSystemStaticInfo(staticInfo);
  1373. CSimpleStringA strUri = MakeUri(staticInfo.strTerminalID);
  1374. if (strUri.GetLength() > 0)
  1375. {
  1376. strcpy(conf.uri, strUri);
  1377. conf.media_start_port = MEDIA_CONFIG_AUDIO_PORT_START;
  1378. conf.media_stop_port = MEDIA_CONFIG_AUDIO_PORT_STOP;
  1379. m_pEndpoint = endpoint_create(this, &conf,DEV_HANDFREE);
  1380. if (!m_pEndpoint) {
  1381. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create endpoint failed!");
  1382. eCode = Error_Unexpect;
  1383. }
  1384. else{
  1385. eCode = Error_Succeed;
  1386. }
  1387. }
  1388. else
  1389. {
  1390. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("strUri length equals zero!");
  1391. eCode = Error_Unexpect;
  1392. }
  1393. return eCode;
  1394. }
  1395. void CSIPEntity::change_dev(int dev_type)
  1396. {
  1397. if (m_pEndpoint) {
  1398. endpoint_change_audio_dev(m_pEndpoint, dev_type);
  1399. }
  1400. }
  1401. static int __change_dev(void *arg)
  1402. {
  1403. ChangeDevCommand *pCmd = (ChangeDevCommand *)arg;
  1404. pCmd->pEntity->change_dev(pCmd->dev_type);
  1405. delete pCmd;
  1406. return 0;
  1407. }
  1408. void CSIPEntity::SwitchHandFree()
  1409. {
  1410. int rc = 0;
  1411. ChangeDevCommand *pCmd = new ChangeDevCommand();
  1412. pCmd->pEntity = this;
  1413. pCmd->dev_type = DEV_HANDFREE;
  1414. if (endpoint_invoke(m_pEndpoint, &__change_dev, pCmd, &rc) != 0) {
  1415. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("endpoint invoke failed!");
  1416. delete pCmd;
  1417. }
  1418. }
  1419. void CSIPEntity::SwitchPickup()
  1420. {
  1421. int rc = 0;
  1422. ChangeDevCommand *pCmd = new ChangeDevCommand();
  1423. pCmd->pEntity = this;
  1424. pCmd->dev_type = DEV_PICKUP;
  1425. if (endpoint_invoke(m_pEndpoint, &__change_dev, pCmd, &rc) != 0) {
  1426. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("endpoint invoke failed!");
  1427. delete pCmd;
  1428. }
  1429. }
  1430. void CSIPEntity::SetState(int state)
  1431. {
  1432. m_state = state;
  1433. }
  1434. ErrorCodeEnum CSIPEntity::RealSelfCheck()
  1435. {
  1436. ErrorCodeEnum Error = Error_Succeed;
  1437. if (m_pHMClient)
  1438. {
  1439. HealthManagerService_RealCheck_Req req;
  1440. req.name = GetEntityName();
  1441. HealthManagerService_RealCheck_Ans ans;
  1442. DWORD Timeout = 500;
  1443. Error = m_pHMClient->RealCheck(req,ans,Timeout);
  1444. if (Error!=Error_Succeed)
  1445. {
  1446. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("RealSelfcheck fail!");
  1447. }
  1448. }
  1449. return Error;
  1450. }
  1451. CSimpleStringA CSIPEntity::MakeUri(const char *terminal_id)
  1452. {
  1453. return CSimpleStringA::Format("sip:%s@%s;transport=UDP", terminal_id, m_localip);
  1454. }
  1455. ErrorCodeEnum CSIPEntity::StartVideoRender()
  1456. {
  1457. ErrorCodeEnum Error = Error_Succeed;
  1458. return Error;
  1459. }
  1460. ErrorCodeEnum CSIPEntity::StopVideoRender()
  1461. {
  1462. ErrorCodeEnum Error = Error_Succeed;
  1463. return Error;
  1464. }
  1465. ErrorCodeEnum CSIPEntity::LoadConfig(endpoint_conf_t *conf)
  1466. {
  1467. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1468. CSmartPointer<IConfigInfo> spRootConfig;
  1469. ErrorCodeEnum Error = spFunction->OpenConfig(Config_Root, spRootConfig);
  1470. if (Error == Error_Succeed) {
  1471. CSimpleStringA strHandFreeIn;
  1472. CSimpleStringA strHandFreeOut;
  1473. CSimpleStringA strPickupIn;
  1474. CSimpleStringA strPickupOut;
  1475. SpIniMappingTable table;
  1476. table.AddEntryString("audio", "handfree_in_dev", strHandFreeIn, "$");
  1477. table.AddEntryString("audio", "handfree_out_dev", strHandFreeOut, "$");
  1478. table.AddEntryString("audio", "pickup_in_dev", strPickupIn, "$");
  1479. table.AddEntryString("audio", "pickup_out_dev", strPickupOut, "$");
  1480. table.AddEntryBoolean("audio", "pickup_out_agc", conf->audio_dsp.audio_pickup_out_agc, false);
  1481. table.AddEntryBoolean("audio", "pickup_in_agc", conf->audio_dsp.audio_pickup_in_agc, false);
  1482. table.AddEntryBoolean("audio", "handfree_in_agc", conf->audio_dsp.audio_handfree_in_agc, false);
  1483. table.AddEntryBoolean("audio", "handfree_out_agc", conf->audio_dsp.audio_handfree_out_agc, false);
  1484. table.AddEntryBoolean("audio", "pickup_out_ns", conf->audio_dsp.audio_pickup_out_ns, false);
  1485. table.AddEntryBoolean("audio", "pickup_in_ns", conf->audio_dsp.audio_pickup_in_ns, false);
  1486. table.AddEntryBoolean("audio", "handfree_in_ns", conf->audio_dsp.audio_handfree_in_ns, false);
  1487. table.AddEntryBoolean("audio", "handfree_out_ns", conf->audio_dsp.audio_handfree_out_ns, false);
  1488. table.AddEntryBoolean("audio", "pickup_aec", conf->audio_dsp.audio_pickup_aec, false);
  1489. table.AddEntryBoolean("audio", "handfree_aec", conf->audio_dsp.audio_handfree_aec, false);
  1490. table.AddEntryInt("audio", "handfree_in_volume", m_kept_volume_in[DEV_HANDFREE], 0);
  1491. table.AddEntryInt("audio", "handfree_out_volume", m_kept_volume_out[DEV_HANDFREE], 0);
  1492. table.AddEntryInt("audio", "pickup_in_volume", m_kept_volume_in[DEV_PICKUP], 0);
  1493. table.AddEntryInt("audio", "pickup_out_volume", m_kept_volume_out[DEV_PICKUP], 0);
  1494. table.AddEntryInt("video", "quant", conf->quant, 0);
  1495. table.AddEntryInt("video", "mtu", conf->mtu, 0);
  1496. Error = table.Load(spRootConfig);
  1497. if (Error == Error_Succeed) {
  1498. _snprintf(conf->audio_handfree_in_dev, MAX_PATH, "%s", strHandFreeIn.GetData());
  1499. _snprintf(conf->audio_handfree_out_dev, MAX_PATH, "%s", strHandFreeOut.GetData());
  1500. _snprintf(conf->audio_pickup_in_dev, MAX_PATH, "%s", strPickupIn.GetData());
  1501. _snprintf(conf->audio_pickup_out_dev, MAX_PATH, "%s", strPickupOut.GetData());
  1502. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_AUDIO_VOLUME_INFO, generateVolumeJson(m_kept_volume_in[DEV_HANDFREE], m_kept_volume_out[DEV_HANDFREE], m_kept_volume_in[DEV_PICKUP], m_kept_volume_out[DEV_PICKUP]).GetData());
  1503. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_AUDIO_DSP_INFO, generateAudioDspFlags(conf->audio_dsp).GetData());
  1504. if (m_iAudioDspUseCenter) {
  1505. AudioDspFlagsUseCentersetting(conf);
  1506. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_CENTER_AUDIO_DSP_FLAGS, generateAudioDspFlags(conf->audio_dsp).GetData());
  1507. }
  1508. conf->ref_active_camera = &m_stVideoParam.iActiveCamera;
  1509. conf->ref_camera_switch = &m_stVideoParam.iCameraSwitch;
  1510. conf->ref_window_state = &m_stVideoParam.nWindowState;
  1511. conf->ref_active_img = &m_stVideoParam.bShowActiveImg;
  1512. conf->ref_Is_ActiveInspect = &m_stVideoParam.bActiveInspect;
  1513. conf->ref_camera_state = &m_stVideoParam.iCameraState;
  1514. conf->ref_Is_showPersonArea = &m_stVideoParam.bShowPersonArea;
  1515. conf->ref_Is_showRecordArea = &m_stVideoParam.bShowRecordArea;
  1516. conf->irendertype = (int)m_eVideoRenderType;
  1517. m_stVideoParam.nUpDynamicFps = 0;
  1518. conf->ref_Up_Fps = &m_stVideoParam.nUpDynamicFps;
  1519. if (eStand1SPlusType == m_eDeviceType)
  1520. {
  1521. conf->camera_count = 1;
  1522. }
  1523. else if(eStand2sType == m_eDeviceType)
  1524. {
  1525. conf->camera_count = 2;
  1526. }
  1527. //DecideCameraCount(conf->camera_count);
  1528. DecideScreenCount(conf->screen_count);
  1529. }
  1530. }
  1531. return Error;
  1532. }
  1533. //载入运行时配置
  1534. ErrorCodeEnum CSIPEntity::LoadAudioRunConfig(int&nHandfreeout,int&nPickupout,int&nHandfreein,int&nPickupin)
  1535. {
  1536. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1537. CSmartPointer<IConfigInfo> spConfig;
  1538. ErrorCodeEnum Error = spFunction->OpenConfig(Config_Run, spConfig);
  1539. if (Error == Error_Succeed)
  1540. {
  1541. SpIniMappingTable table;
  1542. table.AddEntryInt("Audio", "handfree_out_volume", nHandfreeout, 0);
  1543. table.AddEntryInt("Audio", "pickup_out_volume", nPickupout, 0);
  1544. table.AddEntryInt("Audio", "handfree_in_volume", nHandfreein, 0);
  1545. table.AddEntryInt("Audio", "pickup_in_volume", nPickupin, 0);
  1546. Error = table.Load(spConfig);
  1547. if (Error != Error_Succeed)
  1548. {
  1549. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[dbg] failed to load run config.");
  1550. }
  1551. }
  1552. else
  1553. {
  1554. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[dbg] failed to open run config.");
  1555. }
  1556. return Error;
  1557. }
  1558. //保存运行时
  1559. ErrorCodeEnum CSIPEntity::SaveAudioRunConfig(int nHandfreeout,int nPickupout,int nHandfreein,int nPickupin)
  1560. {
  1561. CSmartPointer<IEntityFunction> spFunction = GetFunction();;
  1562. CSmartPointer<IConfigInfo> spConfig;
  1563. ErrorCodeEnum Error = spFunction->OpenConfig(Config_Run, spConfig);
  1564. if (Error == Error_Succeed)
  1565. {
  1566. Error = spConfig->WriteConfigValueInt("Audio", "handfree_out_volume", nHandfreeout);
  1567. if(Error == Error_Succeed)
  1568. {
  1569. Error = spConfig->WriteConfigValueInt("Audio", "pickup_out_volume", nPickupout);
  1570. }
  1571. else
  1572. {
  1573. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SaveAudioRunConfig handfree_out_volume fail!");
  1574. return Error;
  1575. }
  1576. if(Error == Error_Succeed)
  1577. {
  1578. Error = spConfig->WriteConfigValueInt("Audio", "handfree_in_volume", nHandfreein);
  1579. }
  1580. else
  1581. {
  1582. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SaveAudioRunConfig pickup_out_volume fail!");
  1583. return Error;
  1584. }
  1585. if(Error == Error_Succeed)
  1586. {
  1587. Error = spConfig->WriteConfigValueInt("Audio", "pickup_in_volume", nPickupin);
  1588. }
  1589. else
  1590. {
  1591. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SaveAudioRunConfig handfree_in_volume fail!");
  1592. return Error;
  1593. }
  1594. if (Error != Error_Succeed)
  1595. {
  1596. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SaveAudioRunConfig pickup_in_volume fail!");
  1597. return Error;
  1598. }
  1599. }
  1600. else
  1601. {
  1602. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SaveAudioRunConfig is fail , open sipphone.ini fail!");
  1603. }
  1604. return Error;
  1605. }
  1606. ErrorCodeEnum CSIPEntity::DecideScreenCount(int &nCount)
  1607. {
  1608. CSystemStaticInfo Info;
  1609. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1610. ErrorCodeEnum Error = spFunction->GetSystemStaticInfo(Info);
  1611. if (Error == Error_Succeed)
  1612. {
  1613. nCount = (int)Info.eScreen;
  1614. }
  1615. return Error;
  1616. }
  1617. DeviceTypeEnum CSIPEntity::RvcGetDeviceType()
  1618. {
  1619. DeviceTypeEnum eType = eStand2sType;
  1620. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1621. CSystemStaticInfo stStaticinfo;
  1622. spFunction->GetSystemStaticInfo(stStaticinfo);
  1623. if (_stricmp(stStaticinfo.strMachineType, "RVC.Stand1SPlus") == 0) {
  1624. eType = eStand1SPlusType;
  1625. }
  1626. else if (stricmp(stStaticinfo.strMachineType, "RVC.CardStore") == 0 || stricmp(stStaticinfo.strMachineType, "RVC.CardPrinter") == 0) {
  1627. eType = eCardStore;
  1628. }
  1629. else {
  1630. eType = eStand2sType;
  1631. }
  1632. if (eType >= 0 && eType < sizeof(Device_Type_Table) / sizeof(char*)) {
  1633. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("device type is %s.", Device_Type_Table[eType]);
  1634. }
  1635. return eType;
  1636. }
  1637. eVideoRenderType CSIPEntity::GetMediaConfig()
  1638. {
  1639. CSmartPointer<IConfigInfo> spConfig;
  1640. SpIniMappingTable table;
  1641. CSmartPointer<IEntityFunction> pFunc = GetFunction();
  1642. ErrorCodeEnum Error = pFunc->OpenConfig(Config_CenterSetting, spConfig);
  1643. int iRenderType = 0;
  1644. if (Error == Error_Succeed)
  1645. {
  1646. table.AddEntryInt("SipPhone", "VideoRenderType", iRenderType, 0);
  1647. table.Load(spConfig);
  1648. }
  1649. eVideoRenderType eRenderType = eGDI;
  1650. if (0 != iRenderType){
  1651. eRenderType = eSDL;
  1652. }
  1653. if (eRenderType >= eGDI && eRenderType < sizeof(VideoRender_Type_Table) / sizeof(char*)) {
  1654. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("video render type is %s.", VideoRender_Type_Table[eRenderType]);
  1655. }
  1656. return eRenderType;
  1657. }
  1658. //
  1659. // CSIPPhoneSession
  1660. //
  1661. CSIPPhoneSession::CSIPPhoneSession(CSIPEntity* pEntity) : m_pEntity(pEntity), m_pCall(NULL), m_iLastState(0), m_IsLocalPlay(0), m_VideoWindowPlayType(eOnline_Mode_Video)
  1662. {
  1663. m_cb_video_box_move.on_video_box_move = &__on_video_box_move;
  1664. m_cb_video_box_move.user_data = this;
  1665. }
  1666. void CSIPPhoneSession::OnClose( ErrorCodeEnum eErrorCode )
  1667. {
  1668. }
  1669. void CSIPPhoneSession::Handle_MakeCall( SpReqAnsContext<PhoneService_MakeCall_Req, PhoneService_MakeCall_Ans>::Pointer ctx )
  1670. {
  1671. DbgToBeidou(ctx->link, __FUNCTION__)();
  1672. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_CALL_URL, CSimpleStringA::Format("make call [%s]", ctx->Req.to_uri.GetData()).GetData());
  1673. int rc = Error_Succeed;
  1674. MakeCallCommand_t *cmd = new MakeCallCommand_t();
  1675. cmd->pSIPPhoneSession = this;
  1676. cmd->toUri = ctx->Req.to_uri;
  1677. cmd->fromUri = ctx->Req.from_uri;
  1678. cmd->callId = ctx->Req.call_id;
  1679. ///////////重新初始化sip话机,防止断网导致IP改变//////////////////
  1680. if (m_pEntity->m_pEndpoint){
  1681. endpoint_destroy(m_pEntity->m_pEndpoint);
  1682. m_pEntity->m_pEndpoint = NULL;
  1683. }
  1684. ErrorCodeEnum Error = m_pEntity->GetLocalIP();
  1685. if (Error != 0){
  1686. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get local ip failed!");
  1687. ctx->Answer(Error_Unexpect);
  1688. return;
  1689. }
  1690. cmd->strlocalip = m_pEntity->m_localip;
  1691. CSimpleStringA strUri = m_pEntity->MakeUri(m_pEntity->staticInfo.strTerminalID);
  1692. if (strUri.GetLength() > 0)
  1693. {
  1694. strcpy(m_pEntity->conf.uri, strUri);
  1695. m_pEntity->conf.media_start_port = MEDIA_CONFIG_AUDIO_PORT_START;
  1696. m_pEntity->conf.media_stop_port = MEDIA_CONFIG_AUDIO_PORT_STOP;
  1697. m_pEntity->m_pEndpoint = endpoint_create(m_pEntity, &m_pEntity->conf,m_pEntity->m_iPickupPhoneState);
  1698. if (!m_pEntity->m_pEndpoint){
  1699. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create endpoint failed!");
  1700. return;
  1701. }
  1702. else{
  1703. cmd->iaudio_port = new_media_port(m_pEntity->m_pEndpoint);
  1704. cmd->ivideo_port = REC_COMMON_VIDEO_PORT;
  1705. }
  1706. }
  1707. else {
  1708. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("strUri length equals zero!");
  1709. }
  1710. ///////////重新初始化sip话机,防止断网导致IP改变//////////////////
  1711. if (m_pEntity->GetEndpoint()) {
  1712. endpoint_invoke(m_pEntity->GetEndpoint(), &__make_call, cmd, &rc);
  1713. }
  1714. ctx->Answer((ErrorCodeEnum)rc);
  1715. }
  1716. void CSIPPhoneSession::Handle_HangupCall( SpReqAnsContext<PhoneService_HangupCall_Req, PhoneService_HangupCall_Ans>::Pointer ctx )
  1717. {
  1718. DbgToBeidou(ctx->link, __FUNCTION__)();
  1719. int rc = Error_Succeed;
  1720. HangupCallCommand_t *cmd = new HangupCallCommand_t();
  1721. cmd->pSIPPhoneSession = this;
  1722. cmd->strSession_num = ctx->Req.session_num;
  1723. cmd->strBranch_server_ip = ctx->Req.branch_server_ip;
  1724. cmd->iBranch_server_port = ctx->Req.branch_server_port;
  1725. if (m_pEntity->GetEndpoint())
  1726. {
  1727. endpoint_invoke(m_pEntity->GetEndpoint(), &__hangup_call, cmd, &rc);
  1728. }
  1729. ctx->Answer((ErrorCodeEnum)rc);
  1730. }
  1731. void CSIPPhoneSession::Handle_ReleaseCall( SpReqAnsContext<PhoneService_ReleaseCall_Req, PhoneService_ReleaseCall_Ans>::Pointer ctx )
  1732. {
  1733. DbgToBeidou(ctx->link, __FUNCTION__)();
  1734. int rc = Error_Succeed;
  1735. g_IsExternalTerminalted = true;
  1736. endpoint_invoke(m_pEntity->GetEndpoint(), &__release_call, this, &rc);
  1737. if (NULL != m_pEntity->m_pEndpoint){
  1738. endpoint_destroy(m_pEntity->m_pEndpoint);
  1739. m_pEntity->m_pEndpoint = NULL;
  1740. }
  1741. ctx->Answer((ErrorCodeEnum)rc);
  1742. }
  1743. void CSIPPhoneSession::Handle_SetCallingParam(SpOnewayCallContext<PhoneService_SetCallingParam_Info>::Pointer ctx)
  1744. {
  1745. DbgToBeidou(ctx->link, __FUNCTION__)();
  1746. m_pEntity->m_nCallType = (CallingTypeEnum)ctx->Info.CallType;
  1747. }
  1748. void CSIPPhoneSession::Handle_RealErrorCheck(SpOnewayCallContext<PhoneService_RealErrorCheck_Info>::Pointer ctx)
  1749. {
  1750. DbgToBeidou(ctx->link, __FUNCTION__)();
  1751. m_pEntity->m_SipErrorCode = Error_InvalidState;
  1752. m_pEntity->RealSelfCheck();
  1753. }
  1754. void CSIPPhoneSession::Handle_StartVideo( SpOnewayCallContext<PhoneService_StartVideo_Info>::Pointer ctx )
  1755. {
  1756. DbgToBeidou(ctx->link, __FUNCTION__)();
  1757. int rc;
  1758. ControlVideoCommand_t*pCmd = new ControlVideoCommand_t();
  1759. pCmd->pSIPPhoneSession = this;
  1760. pCmd->start = true;
  1761. pCmd->local_hwd_move = 0;
  1762. pCmd->remote_hwd_move = 0;
  1763. 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))
  1764. {
  1765. m_IsLocalPlay= true;
  1766. m_VideoWindowPlayType = eOnly_Local_Video;
  1767. }
  1768. else
  1769. {
  1770. m_IsLocalPlay= FALSE;
  1771. m_VideoWindowPlayType = eOnline_Mode_Video;
  1772. if (0 == ctx->Info.remote_port){
  1773. m_VideoWindowPlayType = eBoth_Local_Remote_Video;
  1774. m_pEntity->m_nCallType = NORMAL_CALLTYPE;
  1775. if (NULL == m_pEntity->GetEndpoint())
  1776. {
  1777. m_pEntity->InitEndpoint();
  1778. }
  1779. }
  1780. }
  1781. pCmd->local_ip = inet_addr(m_pEntity->m_localip);
  1782. pCmd->local_port = MEDIA_CONFIG_VIDEO_PORT;
  1783. pCmd->remote_ip = inet_addr(ctx->Info.remote_ip);
  1784. pCmd->remote_port = ctx->Info.remote_port;
  1785. pCmd->local_view_x = ctx->Info.local_view_x;
  1786. pCmd->local_view_y = ctx->Info.local_view_y;
  1787. pCmd->local_view_cx = ctx->Info.local_view_cx;
  1788. pCmd->local_view_cy = ctx->Info.local_view_cy;
  1789. pCmd->remote_view_x = ctx->Info.remote_view_x;
  1790. pCmd->remote_view_y = ctx->Info.remote_view_y;
  1791. pCmd->remote_view_cx = ctx->Info.remote_view_cx;
  1792. pCmd->remote_view_cy = ctx->Info.remote_view_cy;
  1793. pCmd->remote_width = ctx->Info.remote_width;
  1794. pCmd->remote_height = ctx->Info.remote_height;
  1795. pCmd->local_hwd_move = ctx->Info.local_hwd_move;
  1796. pCmd->remote_hwd_move = ctx->Info.remote_hwd_move;
  1797. endpoint_invoke(m_pEntity->GetEndpoint(), &__control_video, pCmd, &rc);
  1798. m_pEntity->m_stVideoParam.bShowActiveImg = 0;
  1799. m_pEntity->m_stVideoParam.bActiveInspect = 0;
  1800. //初始化窗口参数
  1801. m_pEntity->m_stVideoParam.nWindowState = 0;
  1802. }
  1803. void CSIPPhoneSession::Handle_StopVideo( SpOnewayCallContext<PhoneService_StopVideo_Info>::Pointer ctx )
  1804. {
  1805. DbgToBeidou(ctx->link, __FUNCTION__)();
  1806. int rc;
  1807. ControlVideoCommand_t*pCmd = new ControlVideoCommand_t();
  1808. pCmd->pSIPPhoneSession = this;
  1809. pCmd->start = false;
  1810. m_pEntity->GetFunction()->KillTimer(1);
  1811. if (NULL != m_pEntity->GetEndpoint()){
  1812. endpoint_invoke(m_pEntity->GetEndpoint(), &__control_video, pCmd, &rc);
  1813. }
  1814. else{
  1815. endpoint_call_stop_double_record_broadcast_video();
  1816. }
  1817. m_pEntity->m_stVideoParam.bShowActiveImg = 0;
  1818. m_pEntity->m_stVideoParam.bActiveInspect = 0;
  1819. //初始化窗口参数
  1820. m_pEntity->m_stVideoParam.nWindowState = 0;
  1821. m_VideoWindowPlayType = eOnline_Mode_Video;
  1822. }
  1823. void CSIPPhoneSession::Handle_StartVideoRender(SpOnewayCallContext<PhoneService_StartVideoRender_Info>::Pointer ctx)
  1824. {
  1825. DbgToBeidou(ctx->link, __FUNCTION__)();
  1826. }
  1827. void CSIPPhoneSession::Handle_StopVideoRender(SpOnewayCallContext<PhoneService_StopVideoRender_Info>::Pointer ctx)
  1828. {
  1829. DbgToBeidou(ctx->link, __FUNCTION__)();
  1830. }
  1831. void CSIPPhoneSession::Handle_GetHandfreeInVolume(SpReqAnsContext<PhoneService_GetHandfreeInVolume_Req, PhoneService_GetHandfreeInVolume_Ans>::Pointer ctx)
  1832. {
  1833. DbgToBeidou(ctx->link, __FUNCTION__)();
  1834. ctx->Ans.Volume = m_pEntity->m_kept_volume_in[DEV_HANDFREE];
  1835. ctx->Answer(Error_Succeed);
  1836. }
  1837. void CSIPPhoneSession::Handle_SetHandfreeInVolume(SpReqAnsContext<PhoneService_SetHandfreeInVolume_Req, PhoneService_SetHandfreeInVolume_Ans>::Pointer ctx)
  1838. {
  1839. DbgToBeidou(ctx->link, __FUNCTION__)();
  1840. int iVolume = ctx->Req.Volume;
  1841. if (iVolume > 100) {
  1842. iVolume = 100;
  1843. }
  1844. if (iVolume < 0) {
  1845. iVolume = 0;
  1846. }
  1847. m_pEntity->SetHandfreeInVolume(iVolume);
  1848. ctx->Answer(Error_Succeed);
  1849. }
  1850. void CSIPPhoneSession::Handle_SetPickupInVolume(SpReqAnsContext<PhoneService_SetPickupInVolume_Req, PhoneService_SetPickupInVolume_Ans>::Pointer ctx)
  1851. {
  1852. DbgToBeidou(ctx->link, __FUNCTION__)();
  1853. if (eStand2sType == m_pEntity->m_eDeviceType || eStand1SPlusType == m_pEntity->m_eDeviceType) {
  1854. int iVolume = ctx->Req.Volume;
  1855. if (iVolume > 100) {
  1856. iVolume = 100;
  1857. }
  1858. if (iVolume < 0) {
  1859. iVolume = 0;
  1860. }
  1861. m_pEntity->SetPickupInVolume(iVolume);
  1862. }
  1863. ctx->Answer(Error_Succeed);
  1864. }
  1865. void CSIPPhoneSession::Handle_GetPickupInVolume(SpReqAnsContext<PhoneService_GetPickupInVolume_Req, PhoneService_GetPickupInVolume_Ans>::Pointer ctx)
  1866. {
  1867. DbgToBeidou(ctx->link, __FUNCTION__)();
  1868. if (eStand2sType == m_pEntity->m_eDeviceType || eStand1SPlusType == m_pEntity->m_eDeviceType) {
  1869. ctx->Ans.Volume = m_pEntity->m_kept_volume_in[DEV_PICKUP];
  1870. }
  1871. else {
  1872. ctx->Ans.Volume = 0;
  1873. }
  1874. ctx->Answer(Error_Succeed);
  1875. }
  1876. void CSIPPhoneSession::Handle_GetAudioDevices(SpReqAnsContext<PhoneService_GetAudioDevices_Req, PhoneService_GetAudioDevices_Ans>::Pointer ctx)
  1877. {
  1878. DbgToBeidou(ctx->link, __FUNCTION__)();
  1879. ctx->Ans.strHandfreeIn = m_pEntity->conf.audio_handfree_in_dev;
  1880. ctx->Ans.strHandfreeOut = m_pEntity->conf.audio_handfree_out_dev;
  1881. ctx->Ans.strPickupIn = m_pEntity->conf.audio_pickup_in_dev;
  1882. ctx->Ans.strPickupOut = m_pEntity->conf.audio_pickup_out_dev;
  1883. ctx->Ans.retCode = Error_Succeed;
  1884. ctx->Answer(Error_Succeed);
  1885. }
  1886. void CSIPPhoneSession::Handle_BeginState( SpSubscribeContext<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::Pointer ctx )
  1887. {
  1888. m_spCallbackContext = ctx;
  1889. }
  1890. void CSIPPhoneSession::Handle_EndState( SpOnewayCallContext<PhoneService_EndState_Info>::Pointer ctx )
  1891. {
  1892. DbgToBeidou(ctx->link, __FUNCTION__)();
  1893. SpSubscribeContext<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::Pointer tmp_ctx = m_spCallbackContext;
  1894. m_spCallbackContext.Clear();
  1895. }
  1896. void CSIPPhoneSession::Handle_GetHandfreeOutVolume(SpReqAnsContext<PhoneService_GetHandfreeOutVolume_Req, PhoneService_GetHandfreeOutVolume_Ans>::Pointer ctx)
  1897. {
  1898. DbgToBeidou(ctx->link, __FUNCTION__)();
  1899. ctx->Ans.Volume = m_pEntity->m_kept_volume_out[DEV_HANDFREE];
  1900. ctx->Answer(Error_Succeed);
  1901. }
  1902. void CSIPPhoneSession::Handle_SetHandfreeOutVolume(SpReqAnsContext<PhoneService_SetHandfreeOutVolume_Req, PhoneService_SetHandfreeOutVolume_Ans>::Pointer ctx)
  1903. {
  1904. DbgToBeidou(ctx->link, __FUNCTION__)();
  1905. int iVolume = ctx->Req.Volume;
  1906. if (iVolume > 100){
  1907. iVolume = 100;
  1908. }
  1909. if (iVolume < 0){
  1910. iVolume = 0;
  1911. }
  1912. m_pEntity->SetHandfreeOutVolume(iVolume);
  1913. ctx->Answer(Error_Succeed);
  1914. }
  1915. void CSIPPhoneSession::Handle_GetPickupOutVolume(SpReqAnsContext<PhoneService_GetPickupOutVolume_Req, PhoneService_GetPickupOutVolume_Ans>::Pointer ctx)
  1916. {
  1917. DbgToBeidou(ctx->link, __FUNCTION__)();
  1918. if (eStand2sType == m_pEntity->m_eDeviceType || eStand1SPlusType == m_pEntity->m_eDeviceType){
  1919. ctx->Ans.Volume = m_pEntity->m_kept_volume_out[DEV_PICKUP];
  1920. }
  1921. else{
  1922. ctx->Ans.Volume = 0;
  1923. }
  1924. ctx->Answer(Error_Succeed);
  1925. }
  1926. void CSIPPhoneSession::Handle_SetPickupOutVolume(SpReqAnsContext<PhoneService_SetPickupOutVolume_Req, PhoneService_SetPickupOutVolume_Ans>::Pointer ctx)
  1927. {
  1928. DbgToBeidou(ctx->link, __FUNCTION__)();
  1929. if (eStand2sType == m_pEntity->m_eDeviceType || eStand1SPlusType == m_pEntity->m_eDeviceType){
  1930. int iVolume = ctx->Req.Volume;
  1931. if (iVolume > 100) {
  1932. iVolume = 100;
  1933. }
  1934. if (iVolume < 0) {
  1935. iVolume = 0;
  1936. }
  1937. m_pEntity->SetPickupOutVolume(iVolume);
  1938. }
  1939. ctx->Answer(Error_Succeed);
  1940. }
  1941. void CSIPPhoneSession::hangup_call(HangupCallCommand_t* cmd)
  1942. {
  1943. if (m_pCall) {
  1944. endpoint_call_hangup(m_pCall);
  1945. }
  1946. }
  1947. void CSIPPhoneSession::release_call()
  1948. {
  1949. if (m_pCall){
  1950. Terminatedcall(m_pCall);
  1951. }
  1952. }
  1953. void CSIPPhoneSession::on_call_state(int state, const char *state_desc, const char *phrase)
  1954. {
  1955. if (m_spCallbackContext != NULL)
  1956. {
  1957. PhoneService_PhoneState_Info Info;
  1958. Info.state = state;
  1959. Info.status = CSimpleStringA::Format("%s,%s", state_desc, phrase);
  1960. m_spCallbackContext->SendMessage(Info);
  1961. }
  1962. if (state == TERMINATED)
  1963. {
  1964. if (NULL != m_pCall){
  1965. endpoint_call_destroy(m_pCall);
  1966. m_pCall = NULL;
  1967. }
  1968. }
  1969. m_pEntity->SetState(state);
  1970. }
  1971. int CSIPPhoneSession::make_call( MakeCallCommand_t *pCmd)
  1972. {
  1973. if (m_pCall)
  1974. {
  1975. endpoint_call_destroy(m_pCall);
  1976. m_pCall = NULL;
  1977. }
  1978. {
  1979. endpoint_call_callback_t cb = {0};
  1980. cb.on_call_state = &__on_call_state;
  1981. cb.user_data = this;
  1982. endpoint_call_params_t t_callparam = {0};
  1983. t_callparam.to_uri = pCmd->toUri.GetData();
  1984. t_callparam.call_id = (pCmd->callId.GetLength() > 0) ? pCmd->callId.GetData() : NULL;
  1985. t_callparam.from_uri = (pCmd->fromUri.GetLength() > 0) ? pCmd->fromUri.GetData() : NULL;
  1986. t_callparam.local_ip = (pCmd->strlocalip.GetLength() > 0) ? pCmd->strlocalip.GetData() : NULL;
  1987. t_callparam.ilocal_audio_port = pCmd->iaudio_port;
  1988. t_callparam.ilocal_video_port = pCmd->ivideo_port;
  1989. t_callparam.nDeviceType = m_pEntity->m_eDeviceType;
  1990. t_callparam.nCallType = m_pEntity->m_nCallType;
  1991. m_pCall = endpoint_call_create(m_pEntity->GetEndpoint(), &t_callparam, &cb);
  1992. if (m_pCall)
  1993. {
  1994. g_IsExternalTerminalted = false;
  1995. if (endpoint_call_start(m_pCall) == 0)
  1996. {
  1997. return Error_Succeed;
  1998. }
  1999. else
  2000. {
  2001. endpoint_call_destroy(m_pCall);
  2002. m_pCall = NULL;
  2003. return Error_Unexpect;
  2004. }
  2005. }
  2006. else
  2007. {
  2008. g_IsExternalTerminalted = true;
  2009. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create call endpoint failed!");
  2010. m_pEntity->m_SipErrorCode = Error_InvalidState;
  2011. m_pEntity->RealSelfCheck();
  2012. return Error_Unexpect;
  2013. }
  2014. }
  2015. }
  2016. void CSIPPhoneSession::control_video( ControlVideoCommand_t *pCmd )
  2017. {
  2018. if (m_pCall)
  2019. {
  2020. if (pCmd->start)
  2021. {
  2022. endpoint_call_start_video(m_pCall,
  2023. pCmd->remote_ip, pCmd->remote_port,
  2024. pCmd->local_ip, pCmd->local_port,
  2025. pCmd->remote_width, pCmd->remote_height,
  2026. pCmd->local_view_x, pCmd->local_view_y, pCmd->local_view_cx, pCmd->local_view_cy,
  2027. pCmd->remote_view_x, pCmd->remote_view_y, pCmd->remote_view_cx, pCmd->remote_view_cy,
  2028. pCmd->local_hwd_move, pCmd->remote_hwd_move, &m_cb_video_box_move);
  2029. }
  2030. else
  2031. {
  2032. //双录第一阶段结束录像,销毁call资源
  2033. if ((eOnly_Local_Video == m_VideoWindowPlayType) || (eBoth_Local_Remote_Video == m_VideoWindowPlayType && m_pEntity->m_nCallType != DOUBLERECORD_CALLTYPE ))
  2034. {
  2035. local_play_stop_video(m_pCall);
  2036. m_IsLocalPlay = FALSE;
  2037. endpoint_call_destroy(m_pCall);
  2038. m_pCall = NULL;
  2039. }
  2040. else
  2041. {
  2042. endpoint_call_stop_video(m_pCall);
  2043. }
  2044. }
  2045. }
  2046. else
  2047. {
  2048. if (pCmd->start)
  2049. {
  2050. endpoint_call_callback_t cb = {0};
  2051. cb.on_call_state = &__on_call_state;
  2052. cb.user_data = this;
  2053. endpoint_call_params_t t_callparam = {0};
  2054. t_callparam.to_uri = "test";
  2055. t_callparam.call_id = NULL;
  2056. t_callparam.from_uri = NULL;
  2057. t_callparam.local_ip = m_pEntity->m_localip;
  2058. t_callparam.nDeviceType = m_pEntity->m_eDeviceType;
  2059. t_callparam.nCallType = m_pEntity->m_nCallType;
  2060. m_pCall = endpoint_call_create(m_pEntity->GetEndpoint(), &t_callparam, &cb);
  2061. if (eOnly_Local_Video == m_VideoWindowPlayType){
  2062. 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);
  2063. }
  2064. else if (eBoth_Local_Remote_Video == m_VideoWindowPlayType){
  2065. 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);
  2066. }
  2067. }
  2068. else{
  2069. endpoint_call_stop_double_record_broadcast_video();
  2070. }
  2071. }
  2072. }
  2073. int CSIPPhoneSession::on_video_box_move(int imessageType, int ivideotype, int ileft, int ibottom)
  2074. {
  2075. int iret = -1;
  2076. if (0 == imessageType){
  2077. VideoBoxStartMove evt;
  2078. evt.videoboxflag = ivideotype;
  2079. evt.leftlowerx = ileft;
  2080. evt.leftlowery = ibottom;
  2081. iret = SpSendBroadcast(m_pEntity->GetFunction(), SP_MSG_OF(VideoBoxStartMove), SP_MSG_SIG_OF(VideoBoxStartMove), evt);
  2082. }
  2083. else{
  2084. VideoBoxStopMove evt;
  2085. evt.videoboxflag = ivideotype;
  2086. evt.leftlowerx = ileft;
  2087. evt.leftlowery = ibottom;
  2088. iret = SpSendBroadcast(m_pEntity->GetFunction(), SP_MSG_OF(VideoBoxStopMove), SP_MSG_SIG_OF(VideoBoxStopMove), evt);
  2089. }
  2090. return iret;
  2091. }
  2092. ChannelSipphoneClient::ChannelSipphoneClient( CSIPEntity *pEntity ) : ChannelService_ClientBase(pEntity)
  2093. {
  2094. }
  2095. void ChannelSipphoneClient::OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData)
  2096. {
  2097. if (Error == Error_Succeed)
  2098. {
  2099. CSIPEntity *pEntity = static_cast<CSIPEntity*>(m_pEntityBase);
  2100. if (Msg.state == eChannelState_Connected)
  2101. {
  2102. #ifdef RVC_OS_WIN
  2103. if (pEntity->m_pKeeperIn[DEV_HANDFREE])
  2104. #else
  2105. if (pEntity->m_pAudioMgr)
  2106. #endif
  2107. {
  2108. pEntity->SendAudioDeviceVolumn(DEVICE_HANDFREE_IN);
  2109. }
  2110. #ifdef RVC_OS_WIN
  2111. if (pEntity->m_pKeeperOut[DEV_HANDFREE])
  2112. #else
  2113. if (pEntity->m_pAudioMgr)
  2114. #endif
  2115. {
  2116. pEntity->SendAudioDeviceVolumn(DEVICE_HANDFREE_OUT);
  2117. }
  2118. #ifdef RVC_OS_WIN
  2119. if (pEntity->m_pKeeperOut[DEV_PICKUP])
  2120. #else
  2121. if (pEntity->m_pAudioMgr)
  2122. #endif
  2123. {
  2124. pEntity->SendAudioDeviceVolumn(DEVICE_PICKUP_OUT);
  2125. }
  2126. #ifdef RVC_OS_WIN
  2127. if (pEntity->m_pKeeperIn[DEV_PICKUP])
  2128. #else
  2129. if (pEntity->m_pAudioMgr)
  2130. #endif
  2131. {
  2132. pEntity->SendAudioDeviceVolumn(DEVICE_PICKUP_IN);
  2133. }
  2134. }
  2135. }
  2136. }
  2137. void ChannelSipphoneClient::OnMessage( ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData )
  2138. {
  2139. if (Error == Error_Succeed)
  2140. {
  2141. CSIPEntity *pEntity = static_cast<CSIPEntity*>(m_pEntityBase);
  2142. pEntity->OnReceivePkt(Msg.type,Msg.sub_type, (const char*)Msg.data.m_pData, Msg.data.m_iLength);
  2143. }
  2144. }
  2145. SP_BEGIN_ENTITY_MAP()
  2146. SP_ENTITY(CSIPEntity)
  2147. SP_END_ENTITY_MAP()