mod_sipphone.cpp 103 KB

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