mod_sipphone.cpp 103 KB

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