mod_sipphone.cpp 102 KB

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