mod_sipphone.cpp 104 KB

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