mod_sipphone.cpp 103 KB

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