mod_sipphone.cpp 105 KB

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