mod_sipphone.cpp 103 KB

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