mod_sipphone.cpp 92 KB

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