mod_sipphone.cpp 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760
  1. #include "stdafx.h"
  2. #include "pthread.h"
  3. #include "mod_sipphone.h"
  4. #include "../mod_agentip/sysvar.h"
  5. #include "../mod_facetracking/sysvar.h"
  6. #include "sockutil.h"
  7. #include "rvc_media_common.h"
  8. #include "../mod_interactivecontrol/Event.h"
  9. #include "audio_session.h"
  10. #include "video_session.h"
  11. //#include "volumekeeper.h"
  12. #define EVT_CONVERTER "EventConverter"
  13. #define DEVICE_HANDFREE_OUT 0
  14. #define DEVICE_PICKUP_OUT 1
  15. #define DEVICE_HANDFREE_IN 2
  16. #define DEVICE_PICKUP_IN 3
  17. #ifndef DEFAULT_RECORD_VIDEO_WIDTH
  18. #define DEFAULT_RECORD_VIDEO_WIDTH 1056
  19. #endif
  20. #ifndef DEFAULT_RECORD_VIDEO_HEIGHT
  21. #define DEFAULT_RECORD_VIDEO_HEIGHT 595
  22. #endif
  23. #ifndef SMALL_RECORD_VIDEO_WIDTH
  24. #define SMALL_RECORD_VIDEO_WIDTH 244
  25. #endif
  26. #ifndef SMALL_RECORD_VIDEO_HEIGHT
  27. #define SMALL_RECORD_VIDEO_HEIGHT 138
  28. #endif
  29. #ifndef RVC_VIDEO_FRESH_TIME
  30. #define RVC_VIDEO_FRESH_TIME 50
  31. #endif // !RVC_VIDEO_FRESH_TIME
  32. #ifndef RVC_MAX_VIDEO_FRESH_TIME
  33. #define RVC_MAX_VIDEO_FRESH_TIME 200
  34. #endif // !RVC_MAX_VIDEO_FRESH_TIME
  35. #ifndef RVC_MIN_VIDEO_FRESH_TIME
  36. #define RVC_MIN_VIDEO_FRESH_TIME 1
  37. #endif // !RVC_MAX_VIDEO_FRESH_TIME
  38. extern BOOL g_IsExternalTerminalted;
  39. static void __on_video_box_move(int imessagetype, int ivideotype, int ileft, int ibottom, void *user_data)
  40. {
  41. CSIPPhoneSession *pThis = static_cast<CSIPPhoneSession*>(user_data);
  42. pThis->on_video_box_move(imessagetype, ivideotype, ileft, ibottom);
  43. }
  44. static void __on_call_state(int state, const char *state_desc, const char *phrase, void *user_data)
  45. {
  46. CSIPPhoneSession *pThis = static_cast<CSIPPhoneSession*>(user_data);
  47. if (pThis->m_iLastState != state) {
  48. pThis->m_iLastState = state;
  49. pThis->on_call_state(state, state_desc, phrase);
  50. }
  51. }
  52. static int __make_call(void *user_data)
  53. {
  54. MakeCallCommand_t *cmd = (MakeCallCommand_t*)user_data;
  55. int rc = cmd->pSIPPhoneSession->make_call(cmd);
  56. delete cmd;
  57. return rc;
  58. }
  59. static int __hangup_call(void *user_data)
  60. {
  61. HangupCallCommand *cmd = (HangupCallCommand*)(user_data);
  62. cmd->pSIPPhoneSession->hangup_call(cmd);
  63. delete cmd;
  64. return 0;
  65. }
  66. static int __control_video(void *arg)
  67. {
  68. ControlVideoCommand *pCmd = (ControlVideoCommand*)(arg);
  69. pCmd->pSIPPhoneSession->control_video(pCmd);
  70. delete pCmd;
  71. return 0;
  72. }
  73. static int __video_render(void* arg)
  74. {
  75. VideoRenderCommand_t* pCmd = (VideoRenderCommand_t*)(arg);
  76. pCmd->pSIPPhoneSession->video_render(pCmd);
  77. delete pCmd;
  78. return 0;
  79. }
  80. static int __release_call(void *user_data)
  81. {
  82. CSIPPhoneSession *pThis = static_cast<CSIPPhoneSession*>(user_data);
  83. pThis->release_call();
  84. pThis->on_call_state(TERMINATED,"STATE:terminated","bye bye");
  85. return 0;
  86. }
  87. static void __video_render_log(void* user_data, const char* fmt, va_list arg)
  88. {
  89. int n = vsnprintf(NULL, 0, fmt, arg);
  90. if (n >= MAX_PATH) {
  91. char* buf = (char*)malloc((size_t)(n + 1));
  92. vsnprintf(buf, n + 1, fmt, arg);
  93. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
  94. free(buf);
  95. }
  96. else {
  97. char strlog[MAX_PATH] = { 0 };
  98. vsnprintf(strlog, MAX_PATH, fmt, arg);
  99. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
  100. }
  101. }
  102. static int __on_stop_remote_video_render_callback(void* user_data)
  103. {
  104. int iret = -1;
  105. CSIPEntity* pThis = static_cast<CSIPEntity*>(user_data);
  106. if (NULL != pThis->m_render) {
  107. if (pThis->m_render->remote_render_threadid > 0) {
  108. iret = rvc_stop_remote_video_render(pThis->m_render);
  109. }
  110. }
  111. return iret;
  112. }
  113. static int __remote_video_render_callback(void* videoframe, void* user_data)
  114. {
  115. CSIPEntity* pThis = static_cast<CSIPEntity*>(user_data);
  116. return rvc_remote_video_render(pThis->m_render, videoframe);
  117. }
  118. static int __on_window_type_callback(void* user_data)
  119. {
  120. CSIPEntity* pThis = static_cast<CSIPEntity*>(user_data);
  121. return pThis->m_stVideoParam.bShowPersonArea;
  122. }
  123. static CSimpleStringA generateAudioInfoJson(const char* handfreeIn, const char* handfreeOut, const char* pickupIn, const char* pickupOut)
  124. {
  125. return CSimpleStringA::Format("{\"handfree_in_dev\":\"%s\",\"handfree_out_dev\":\"%s\",\"pickup_in_dev\":\"%s\",\"pickup_out_dev\":\"%s\"}",
  126. handfreeIn, handfreeOut, pickupIn, pickupOut);
  127. }
  128. static CSimpleStringA generateVolumeJson(int ihandfreeIn, int ihandfreeOut, int ipickupIn, int ipickupOut)
  129. {
  130. return CSimpleStringA::Format("{\"handfree_in_volume\":\"%d\",\"handfree_out_volume\":\"%d\",\"pickup_in_volume\":\"%d\",\"pickup_out_volume\":\"%d\"}",
  131. ihandfreeIn, ihandfreeOut, ipickupIn, ipickupOut);
  132. }
  133. static CSimpleStringA generateAudioDspFlags(endpoint_audiodsp_config_t conf)
  134. {
  135. int ipickup_in_agc = 0;
  136. int ipickup_out_agc = 0;
  137. int ihandfree_in_agc = 0;
  138. int ihandfree_out_agc = 0;
  139. int ipickup_in_ns = 0;
  140. int ipickup_out_ns = 0;
  141. int ihandfree_in_ns = 0;
  142. int ihandfree_out_ns = 0;
  143. int ipickup_aec = 0;
  144. int ihandfree_aec = 0;
  145. conf.audio_pickup_in_agc ? ipickup_in_agc = 1 : ipickup_in_agc = 0;
  146. conf.audio_pickup_out_agc ? ipickup_out_agc = 1 : ipickup_out_agc = 0;
  147. conf.audio_handfree_in_agc ? ihandfree_in_agc = 1 : ihandfree_in_agc = 0;
  148. conf.audio_handfree_out_agc ? ihandfree_out_agc = 1 : ihandfree_out_agc = 0;
  149. conf.audio_pickup_in_ns ? ipickup_in_ns = 1 : ipickup_in_ns = 0;
  150. conf.audio_pickup_out_ns ? ipickup_out_ns = 1 : ipickup_out_ns = 0;
  151. conf.audio_handfree_in_ns ? ihandfree_in_ns = 1 : ihandfree_in_ns = 0;
  152. conf.audio_handfree_out_ns ? ihandfree_out_ns = 1 : ihandfree_out_ns = 0;
  153. conf.audio_pickup_aec ? ipickup_aec = 1 : ipickup_aec = 0;
  154. conf.audio_handfree_aec ? ihandfree_aec = 1 : ihandfree_aec = 0;
  155. 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\"}",
  156. ihandfree_in_agc, ihandfree_out_agc, ipickup_in_agc, ipickup_out_agc,
  157. ihandfree_in_ns, ihandfree_out_ns, ipickup_in_ns, ipickup_out_ns,
  158. ihandfree_aec, ipickup_aec);
  159. }
  160. CSIPPhoneSession::CSIPPhoneSession(CSIPEntity* pEntity) : m_pEntity(pEntity), m_pCall(NULL), m_iLastState(0)
  161. {
  162. }
  163. CSIPEntity::CSIPEntity() : m_pCurrentSession(NULL), m_state(INIT),m_iPickupPhoneState(ePickupMicrophoneState_Off)
  164. {
  165. m_kept_volume_in[0] = m_kept_volume_in[1] = 0;
  166. m_kept_volume_out[0] = m_kept_volume_out[1] = 0;
  167. #ifdef RVC_OS_WIN
  168. m_pKeeperIn[0] = m_pKeeperIn[1] = NULL;
  169. m_pKeeperOut[0] = m_pKeeperOut[1] = NULL;
  170. #else
  171. m_pAudioMgr = NULL;
  172. #endif
  173. m_SipErrorCode = Error_Succeed;
  174. memset((void*)&m_stVideoParam,0,sizeof(stVideoParam));
  175. m_bConnectedAssist = false;
  176. m_ilocalvideo_freshtime = RVC_VIDEO_FRESH_TIME;
  177. m_iremotevideo_freshtime = RVC_VIDEO_FRESH_TIME;
  178. m_render = NULL;
  179. m_iAudioDspUseCenter = 0;
  180. }
  181. void CSIPEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  182. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  183. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext& pLinkInfo)
  184. {
  185. switch (dwUserCode)
  186. {
  187. case LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS:
  188. {
  189. Sleep(810);
  190. if (m_pSipphoneChannel != NULL){
  191. m_bConnectedAssist = false;
  192. m_pSipphoneChannel->GetFunction()->CloseSession();
  193. m_pSipphoneChannel = NULL;
  194. }
  195. if (Error_Succeed == ConnectAssistChannel()) {
  196. m_bConnectedAssist = true;
  197. }
  198. else {
  199. GetFunction()->SetTimer(2, this, 3200);
  200. }
  201. }
  202. break;
  203. case EVENT_MOD_CONNECT_HANDFREE_TO_PICKUP:
  204. case EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP:
  205. case EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE:
  206. case EVENT_MOD_CONNECT_PICKUP_TO_HANDFREE:
  207. case EVENT_MOD_CONNECT_PICKUP_CALL:
  208. case EVENT_MOD_CONNECT_SLV_HANDFREECALL:
  209. case EVENT_MOD_CONNECT_SLV_PICKUPCALL:
  210. case LOG_EVT_HANDFREE_MODE_REMOTE_CALL:
  211. case LOG_EVT_PICKUP_MODE_REMOTE_CALL:
  212. {
  213. int old_state = m_iPickupPhoneState;
  214. if (dwUserCode == EVENT_MOD_CONNECT_HANDFREE_TO_PICKUP) { // 免提->提机
  215. m_iPickupPhoneState = ePickupMicrophoneState_On;
  216. }
  217. else if (dwUserCode == EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP) { //坐席控制免提->提机
  218. m_iPickupPhoneState = ePickupMicrophoneState_On;
  219. }
  220. else if (dwUserCode == EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE) { //坐席控制提机->免提
  221. m_iPickupPhoneState = ePickupMicrophoneState_Off;
  222. }
  223. else if (dwUserCode == EVENT_MOD_CONNECT_PICKUP_TO_HANDFREE)
  224. { // // 提机->免提
  225. m_iPickupPhoneState = ePickupMicrophoneState_Off;
  226. }
  227. else if (dwUserCode == EVENT_MOD_CONNECT_PICKUP_CALL)
  228. { // 提机拨号
  229. m_iPickupPhoneState = ePickupMicrophoneState_On;
  230. }
  231. else if (dwUserCode == EVENT_MOD_CONNECT_SLV_HANDFREECALL)
  232. { // 免提拨号
  233. m_iPickupPhoneState = ePickupMicrophoneState_Off;
  234. }
  235. else if (dwUserCode == EVENT_MOD_CONNECT_SLV_PICKUPCALL)
  236. {
  237. // 通过界面拨号,但话筒未挂,进入提机拨号
  238. m_iPickupPhoneState = ePickupMicrophoneState_On;
  239. }
  240. else if (dwUserCode == LOG_EVT_HANDFREE_MODE_REMOTE_CALL)
  241. { // 免提模式开始远程双录连线
  242. m_iPickupPhoneState = ePickupMicrophoneState_Off;
  243. }
  244. else if (dwUserCode == LOG_EVT_PICKUP_MODE_REMOTE_CALL)
  245. {
  246. // 话筒模式开始远程双录连线
  247. m_iPickupPhoneState = ePickupMicrophoneState_On;
  248. }
  249. if (old_state != m_iPickupPhoneState)
  250. {
  251. if (m_iPickupPhoneState == ePickupMicrophoneState_On)
  252. {
  253. SwitchPickup();
  254. }
  255. else
  256. {
  257. SwitchHandFree();
  258. }
  259. }
  260. }
  261. break;
  262. case LOG_EVT_ENTER_ACM_FLOW:
  263. {
  264. m_stVideoParam.nWindowState = 1;
  265. }
  266. break;
  267. case LOG_EVT_EXIT_ACM_FLOW:
  268. {
  269. if(m_stVideoParam.nWindowState == 1)
  270. {
  271. m_stVideoParam.nWindowState = 0;
  272. }
  273. }
  274. break;
  275. case LOG_EVT_CHANGELIVEDETECTIONCAM:
  276. {
  277. if (pszMessage && strlen(pszMessage) > 0)
  278. {
  279. int i = atoi(pszMessage);
  280. m_stVideoParam.iCameraSwitch = i;
  281. }
  282. else
  283. {
  284. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("change active display camera param error");
  285. }
  286. }
  287. break;
  288. case LOG_EVT_RELEASELIVEDETECTION:
  289. {
  290. m_stVideoParam.bActiveInspect = 0;
  291. m_stVideoParam.bShowActiveImg = 0;
  292. m_stVideoParam.iCameraSwitch = CAMERA_TYPE_ENV;
  293. }
  294. break;
  295. case LOG_EVT_UI_HIDEONLINEVIDEO:
  296. {
  297. m_stVideoParam.nWindowState = 2;
  298. HideBothVideo();
  299. }
  300. break;
  301. case LOG_EVT_UI_SHOWONLINEVIDEO:
  302. {
  303. if (m_stVideoParam.nWindowState == 2)
  304. {
  305. m_stVideoParam.nWindowState = 3;
  306. ShowBothVideo();
  307. }
  308. }
  309. break;
  310. case LOG_EVT_UI_STARTRECORD:
  311. case LOG_EVT_UI_STARTREMOTERECORD:
  312. {
  313. }
  314. break;
  315. case LOG_EVT_UI_STARTRECORDPREVIEW:
  316. {
  317. m_stVideoParam.bShowRecordArea = 1;
  318. Handle_RecordVideoLocation_Info(pszMessage);
  319. }
  320. break;
  321. case LOG_EVT_UI_STOPRECORD:
  322. case LOG_EVT_UI_STOPREMOTERECORD:
  323. {
  324. if (m_stVideoParam.bShowRecordArea){
  325. m_stVideoParam.bShowRecordArea = 0;
  326. }
  327. rvc_stop_video_render(m_render);
  328. }
  329. break;
  330. case LOG_EVT_UI_STOPRECORDPREVIEW:
  331. {
  332. m_stVideoParam.bShowRecordArea = 0;
  333. }
  334. break;
  335. case LOG_EVT_UI_RETURNMENU:
  336. {
  337. }
  338. break;
  339. case LOG_EVT_UI_SHOWLOCALVIDEO:
  340. {
  341. if (m_stVideoParam.nWindowState == 4)
  342. {
  343. m_stVideoParam.nWindowState = 3;
  344. ShowLocalVideo();
  345. }
  346. }
  347. break;
  348. case LOG_EVT_UI_HIDELOCALVIDEO:
  349. {
  350. m_stVideoParam.nWindowState = 4;
  351. HideLocalVideo();
  352. }
  353. break;
  354. case LOG_EVT_UI_HIDEPERSONAREA:
  355. {
  356. m_stVideoParam.bShowPersonArea = 0;
  357. }
  358. break;
  359. case LOG_EVT_UI_SHOWPERSONAREA:
  360. {
  361. m_stVideoParam.bShowPersonArea = 1;
  362. }
  363. break;
  364. case LOG_EVT_UI_ADJUSTVIDEOECHOSIZE:
  365. {
  366. Handle_AdjustVideoEchoEvent(pszMessage);
  367. }
  368. break;
  369. default:
  370. {
  371. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("unknown dwUserCode = 0x%08x.",dwUserCode);
  372. }
  373. break;
  374. }
  375. }
  376. void CSIPEntity::OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName)
  377. {
  378. if (_stricmp(pszKey, SYSVAR_CAMERASTATE) == 0)
  379. {
  380. if (pszValue[0] == 'E')
  381. {
  382. m_stVideoParam.iCameraState = CAMERA_TYPE_OPT;
  383. }
  384. else if (pszValue[0] == 'O')
  385. {
  386. m_stVideoParam.iCameraState = CAMERA_TYPE_ENV;
  387. }
  388. else if(pszValue[0] == 'B') ///////显示贴图
  389. {
  390. /////////////////////////此处显示贴图//////////////////////////////////
  391. //m_stVideoParam.iCameraSwitch = CAMERA_TYPE_ERROR;
  392. m_stVideoParam.iCameraState = CAMERA_TYPE_ERROR;
  393. }
  394. else if (pszValue[0] == 'N')
  395. {
  396. m_stVideoParam.iCameraState = CAMERA_TYPE_AUTO;
  397. //m_stVideoParam.iCameraSwitch = CAMERA_TYPE_AUTO;
  398. }
  399. }
  400. else if (_stricmp(pszKey, SYSVAR_ACTIVETRACKINGCAMERA) == 0)
  401. {
  402. if (pszValue[0] == 'E')
  403. {
  404. m_stVideoParam.iActiveCamera = CAMERA_TYPE_ENV;
  405. }
  406. else if (pszValue[0] == 'O')
  407. {
  408. m_stVideoParam.iActiveCamera = CAMERA_TYPE_OPT;
  409. }
  410. else
  411. {
  412. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("warning: unknown ActiveTrackingCamera value!");
  413. }
  414. }
  415. else if (_stricmp(pszKey, SYSVAR_AGENTCAMERASWITCH) == 0)
  416. {
  417. if(pszValue[0] == 'E')
  418. {
  419. m_stVideoParam.iCameraSwitch = CAMERA_TYPE_ENV;
  420. }
  421. else if(pszValue[0] == 'O')
  422. {
  423. m_stVideoParam.iCameraSwitch = CAMERA_TYPE_OPT;
  424. }
  425. else if(pszValue[0] == 'A')
  426. {
  427. m_stVideoParam.iCameraSwitch = CAMERA_TYPE_AUTO;
  428. }
  429. }
  430. else if (_stricmp(pszKey, SYSVAR_CALLTYPE) == 0)
  431. {
  432. if(pszValue[0] == CALLTYPE_NORMAL)
  433. {
  434. m_nSysCallType = 0;
  435. }
  436. else if(pszValue[0] == CALLTYPE_MOBILE)
  437. {
  438. m_nSysCallType = 1;
  439. }
  440. else
  441. {
  442. m_nSysCallType =-1;
  443. }
  444. }
  445. }
  446. void CSIPEntity::OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  447. {
  448. if (Test_ShakeHand == eTestType)
  449. {
  450. pTransactionContext->SendAnswer(m_SipErrorCode);
  451. }
  452. }
  453. void CSIPEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  454. {
  455. ErrorCodeEnum Error = __OnStart(Error_Succeed);
  456. pTransactionContext->SendAnswer(Error);
  457. }
  458. void CSIPEntity::OnStarted()
  459. {
  460. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_ENTITY_STARTED, "sipphone entity started.");
  461. ErrorCodeEnum Error = Error_Succeed;
  462. m_pHMClient = new HealthManagerService_ClientBase(this);
  463. Error = m_pHMClient->Connect();
  464. if (Error != Error_Succeed) {
  465. m_pHMClient->SafeDelete();
  466. m_pHMClient = NULL;
  467. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_pHMClient connect fail!");
  468. }
  469. m_pSipphoneChannel = new ChannelSipphoneClient(this);
  470. if (Error_Succeed == ConnectAssistChannel()){
  471. m_bConnectedAssist = true;
  472. }
  473. else {
  474. GetFunction()->SetTimer(2, this, 3200);
  475. }
  476. LogEvent(Severity_Middle, LOG_EVT_MOD_SIPPHONE_STARTED_SUCCESS, "sip phone started successfully.");
  477. }
  478. static void __audiomgrlog(void* user_data, const char* fmt, va_list arg)
  479. {
  480. int n = _vscprintf(fmt, arg);
  481. if (n >= 512) {
  482. char* buf = (char*)malloc((size_t)(n + 1));
  483. vsnprintf(buf, n + 1, fmt, arg);
  484. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s", buf);
  485. free(buf);
  486. }
  487. else {
  488. char strlog[512] = { 0 };
  489. vsnprintf(strlog, 512, fmt, arg);
  490. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s", strlog);
  491. }
  492. }
  493. ErrorCodeEnum CSIPEntity::LoadEntityConfig()
  494. {
  495. SpIniMappingTable table;
  496. int iAudioDspUseCenter = 0;
  497. table.AddEntryInt("SipPhone", "AudioDspUseCenter", iAudioDspUseCenter, 0);
  498. CSmartPointer<IConfigInfo> spConfig;
  499. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
  500. if (Error == Error_Succeed) {
  501. Error = table.Load(spConfig);
  502. if (Error_Succeed == Error) {
  503. m_iAudioDspUseCenter = iAudioDspUseCenter;
  504. }
  505. }
  506. return Error;
  507. }
  508. ErrorCodeEnum CSIPEntity::ConnectAssistChannel()
  509. {
  510. if (NULL == m_pSipphoneChannel) {
  511. m_pSipphoneChannel = new ChannelSipphoneClient(this);
  512. }
  513. ErrorCodeEnum Error = m_pSipphoneChannel->Connect();
  514. if (Error != Error_Succeed) {
  515. m_pSipphoneChannel = NULL;
  516. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ChannelSipphoneClient connect fail!");
  517. return Error;
  518. }
  519. {
  520. ChannelService_BeginState_Sub Sub;
  521. Error = (*m_pSipphoneChannel)(EntityResource::getLink().upgradeLink())->BeginState(Sub);
  522. if (Error != Error_Succeed) {
  523. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("BeginState biz channel failed!");
  524. m_pSipphoneChannel->GetFunction()->CloseSession();
  525. m_pSipphoneChannel = NULL;
  526. return Error;
  527. }
  528. }
  529. {
  530. ChannelService_BeginRecv_Sub Sub;
  531. Sub.type = ACM_TYPE_DEVICE;
  532. Error = (*m_pSipphoneChannel)(EntityResource::getLink().upgradeLink())->BeginRecv(Sub);
  533. if (Error != Error_Succeed) {
  534. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Begin BeginRecv ACM_TYPE_DEVICE failed!");
  535. m_pSipphoneChannel->GetFunction()->CloseSession();
  536. m_pSipphoneChannel = NULL;
  537. return Error;
  538. }
  539. }
  540. {
  541. ChannelService_BeginRecv_Sub Sub;
  542. Sub.type = ACM_TYPE_VIDEOFREQ;
  543. Error = (*m_pSipphoneChannel)(EntityResource::getLink().upgradeLink())->BeginRecv(Sub);
  544. if (Error != Error_Succeed) {
  545. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Begin BeginRecv ACM_TYPE_VIDEOFREQ failed!");
  546. m_pSipphoneChannel->GetFunction()->CloseSession();
  547. m_pSipphoneChannel = NULL;
  548. return Error;
  549. }
  550. }
  551. return Error;
  552. }
  553. ErrorCodeEnum CSIPEntity::__OnStart(ErrorCodeEnum preOperationError)
  554. {
  555. ErrorCodeEnum Error;
  556. //MessageBoxA(0,0,0,0);
  557. m_nCallType = NORMAL_CALLTYPE;
  558. m_nSysCallType = 0;
  559. m_pSipphoneChannel = new ChannelSipphoneClient(this);
  560. memset(m_localip,0,256);
  561. #ifdef RVC_OS_LINUX
  562. {
  563. audiomgr_callback_t t_callback = { 0 };
  564. t_callback.debug = &__audiomgrlog;
  565. m_pAudioMgr = CreateAudioMgrObj(&t_callback);
  566. if (0 != m_pAudioMgr->audio_mgr_initialize()) {
  567. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Audio Manager Initialize failed!");
  568. return Error_Param;
  569. }
  570. }
  571. #endif
  572. m_eDeviceType = RvcGetDeviceType();
  573. m_stVideoParam.bActiveInspect = 0;
  574. m_stVideoParam.bShowActiveImg = 0;
  575. m_stVideoParam.nWindowState = 0;
  576. m_RecordVideoLocation.x = 0;
  577. m_RecordVideoLocation.y = 0;
  578. m_RecordVideoLocation.width = DEFAULT_RECORD_VIDEO_WIDTH;
  579. m_RecordVideoLocation.height = DEFAULT_RECORD_VIDEO_HEIGHT;
  580. video_lib_init();
  581. audio_lib_init();
  582. endpoint_init_lib();
  583. Error = GetLocalIP();
  584. if (Error != 0) {
  585. CSimpleStringA strErrMsg = "获取本地 IP 地址失败,请检查本地网络是否连接!";
  586. LogWarn(Severity_Middle, Error_NetBroken, ERROR_MOD_SIP_GET_LOCAL_IP_FAILED, strErrMsg.GetData());
  587. return Error;
  588. }
  589. #ifdef RVC_OS_LINUX
  590. RvcGetAudioDeviceInfo();
  591. #endif
  592. if (Error_Succeed != LoadEntityConfig()) {
  593. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("LoadEntityConfig failed.");
  594. }
  595. Error = LoadConfig(&conf);
  596. if (Error != Error_Succeed) {
  597. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("load config failed!");
  598. return Error;
  599. }
  600. if (IsPostAudioConfigInfo()) {
  601. 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());
  602. }
  603. int nhandfreeout = 0;
  604. int npickupout = 0;
  605. int nhanfreein = 0;
  606. int npickupin = 0;
  607. Error = LoadAudioRunConfig(nhandfreeout,npickupout,nhanfreein,npickupin);
  608. if (Error == Error_Succeed)
  609. {
  610. if (nhandfreeout > 0){
  611. m_kept_volume_out[DEV_HANDFREE] = nhandfreeout;
  612. }
  613. if (npickupout > 0){
  614. m_kept_volume_out[DEV_PICKUP] = npickupout;
  615. }
  616. if (nhanfreein > 0){
  617. m_kept_volume_in[DEV_HANDFREE] = nhanfreein;
  618. }
  619. if (npickupin > 0){
  620. m_kept_volume_in[DEV_PICKUP] = npickupin;
  621. }
  622. }
  623. #ifdef RVC_OS_LINUX
  624. RvcSetSaveAudioVolume();
  625. #endif
  626. {
  627. CSmartPointer<IEntityFunction> Func = GetFunction();
  628. Func->GetSystemStaticInfo(staticInfo);
  629. }
  630. CSimpleStringA strUri = MakeUri(staticInfo.strTerminalID);
  631. if (strUri.GetLength() > 0)
  632. {
  633. strcpy(conf.uri, strUri);
  634. conf.media_start_port = REC_COMMON_AUDIO_PORT_START;
  635. conf.media_stop_port = REC_COMMON_AUDIO_PORT_STOP;
  636. m_pEndpoint = endpoint_create(this, &conf,DEV_HANDFREE);
  637. if (!m_pEndpoint) {
  638. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create endpoint failed!");
  639. return Error_Unexpect;
  640. }
  641. }
  642. else
  643. {
  644. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("strUri length equals zero!");
  645. return Error_Unexpect;
  646. }
  647. {
  648. CSmartPointer<IEntityFunction> Func = GetFunction();
  649. CUUID id;
  650. int i = 0;
  651. m_arrListener.Init(30);
  652. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANDFREE_TO_PICKUP, EVT_CONVERTER);
  653. m_arrListener[i++] = id;
  654. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_PICKUP_TO_HANDFREE, EVT_CONVERTER);
  655. m_arrListener[i++] = id;
  656. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_PICKUP_CALL, EVT_CONVERTER);
  657. m_arrListener[i++] = id;
  658. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_SLV_HANDFREECALL,NULL,false);
  659. m_arrListener[i++] = id;
  660. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_SLV_PICKUPCALL,NULL,false);
  661. m_arrListener[i++] = id;
  662. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP,NULL,false);
  663. m_arrListener[i++] = id;
  664. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE,NULL,false);
  665. m_arrListener[i++] = id;
  666. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS,NULL,false);
  667. m_arrListener[i++] = id;
  668. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_ENTER_ACM_FLOW,NULL,false);
  669. m_arrListener[i++] = id;
  670. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_EXIT_ACM_FLOW,NULL,false);
  671. m_arrListener[i++] = id;
  672. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_CHANGELIVEDETECTIONCAM,NULL,false);
  673. m_arrListener[i++] = id;
  674. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_RELEASELIVEDETECTION,NULL,false);
  675. m_arrListener[i++] = id;
  676. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_HIDEONLINEVIDEO,NULL,false);
  677. m_arrListener[i++] = id;
  678. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_SHOWONLINEVIDEO,NULL,false);
  679. m_arrListener[i++] = id;
  680. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORD,NULL,false);
  681. m_arrListener[i++] = id;
  682. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPRECORD,NULL,false);
  683. m_arrListener[i++] = id;
  684. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RETURNMENU,NULL,false);
  685. m_arrListener[i++] = id;
  686. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_HIDELOCALVIDEO,NULL,false);
  687. m_arrListener[i++] = id;
  688. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_SHOWLOCALVIDEO,NULL,false);
  689. m_arrListener[i++] = id;
  690. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_HIDEPERSONAREA,NULL,false);
  691. m_arrListener[i++] = id;
  692. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_SHOWPERSONAREA,NULL,false);
  693. m_arrListener[i++] = id;
  694. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_STOP_RECORD_BROADCAST,NULL,false);
  695. m_arrListener[i++] = id;
  696. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_BEGAIN_RECORD_CALL,NULL,false);
  697. m_arrListener[i++] = id;
  698. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTREMOTERECORD,NULL,false);
  699. m_arrListener[i++] = id;
  700. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPREMOTERECORD,NULL,false);
  701. m_arrListener[i++] = id;
  702. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_HANDFREE_MODE_REMOTE_CALL,NULL,false);
  703. m_arrListener[i++] = id;
  704. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_PICKUP_MODE_REMOTE_CALL,NULL,false);
  705. m_arrListener[i++] = id;
  706. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORDPREVIEW,NULL,false);
  707. m_arrListener[i++] = id;
  708. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPRECORDPREVIEW,NULL,false);
  709. m_arrListener[i++] = id;
  710. Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_ADJUSTVIDEOECHOSIZE,NULL,false);
  711. m_arrListener[i++] = id;
  712. }
  713. {
  714. CSmartPointer<IEntityFunction> Func = GetFunction();
  715. CSimpleStringA strValue;
  716. Func->RegistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA, this);
  717. Func->GetSysVar(SYSVAR_ACTIVETRACKINGCAMERA, strValue);
  718. if (strValue[0] == 'E')
  719. {
  720. m_stVideoParam.iActiveCamera = CAMERA_TYPE_ENV;
  721. }
  722. else if (strValue[0] == 'O')
  723. {
  724. m_stVideoParam.iActiveCamera = CAMERA_TYPE_OPT;
  725. }
  726. else
  727. {
  728. assert(0);
  729. }
  730. }
  731. {
  732. CSmartPointer<IEntityFunction> Func = GetFunction();
  733. CSimpleStringA strValue;
  734. Func->RegistSysVarEvent(SYSVAR_CAMERASTATE, this);
  735. Func->GetSysVar(SYSVAR_CAMERASTATE, strValue);
  736. if (strValue[0] == 'E')
  737. {
  738. m_stVideoParam.iCameraState = CAMERA_TYPE_OPT;
  739. }
  740. else if (strValue[0] == 'O')
  741. {
  742. m_stVideoParam.iCameraState = CAMERA_TYPE_ENV;
  743. }
  744. else if(strValue[0] == 'B') ///////显示贴图
  745. {
  746. /////////////////////////此处显示贴图//////////////////////////////////
  747. //m_stVideoParam.iCameraSwitch = CAMERA_TYPE_ERROR;
  748. m_stVideoParam.iCameraState = CAMERA_TYPE_ERROR;
  749. }
  750. else if (strValue[0] == 'N')
  751. {
  752. //m_stVideoParam.iCameraSwitch = CAMERA_TYPE_AUTO;
  753. m_stVideoParam.iCameraState = CAMERA_TYPE_AUTO;
  754. }
  755. }
  756. {
  757. CSmartPointer<IEntityFunction> Func = GetFunction();
  758. CSimpleStringA strValue;
  759. Func->RegistSysVarEvent(SYSVAR_AGENTCAMERASWITCH, this);
  760. Func->GetSysVar(SYSVAR_AGENTCAMERASWITCH, strValue);
  761. if((strValue[0] == 'E'))
  762. {
  763. m_stVideoParam.iCameraSwitch = CAMERA_TYPE_ENV;
  764. }
  765. else if((strValue[0] == 'O'))
  766. {
  767. m_stVideoParam.iCameraSwitch = CAMERA_TYPE_OPT;
  768. }
  769. else if ((strValue[0] == 'A'))
  770. {
  771. m_stVideoParam.iCameraSwitch = CAMERA_TYPE_AUTO;
  772. }
  773. }
  774. {
  775. CSmartPointer<IEntityFunction> Func = GetFunction();
  776. CSimpleStringA strValue;
  777. Func->RegistSysVarEvent(SYSVAR_CALLTYPE, this);
  778. Func->GetSysVar(SYSVAR_CALLTYPE, strValue);
  779. if (strValue[0] == CALLTYPE_NORMAL)
  780. {
  781. m_nSysCallType = 0;
  782. }
  783. else if (strValue[0] == CALLTYPE_MOBILE)
  784. {
  785. m_nSysCallType = 1;
  786. }
  787. else
  788. {
  789. assert(0);
  790. }
  791. }
  792. #ifdef RVC_OS_WIN
  793. if (m_kept_volume_in[DEV_HANDFREE]) {
  794. m_pKeeperIn[DEV_HANDFREE] = volume_keeper_create(conf.audio_handfree_in_dev, 1, m_kept_volume_in[DEV_HANDFREE]);
  795. if (m_pKeeperIn[DEV_HANDFREE]) {
  796. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("HANDFREE in volume keeper create ok! %d", m_kept_volume_in[DEV_HANDFREE]);
  797. }
  798. else {
  799. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("HANDFREE in volume keeper create failed!");
  800. }
  801. }
  802. if (m_kept_volume_out[DEV_HANDFREE]) {
  803. m_pKeeperOut[DEV_HANDFREE] = volume_keeper_create(conf.audio_handfree_out_dev, 0, m_kept_volume_out[DEV_HANDFREE]);
  804. if (m_pKeeperOut[DEV_HANDFREE]) {
  805. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("HANDFREE out volume keeper create ok! %d", m_kept_volume_out[DEV_HANDFREE]);
  806. }
  807. else {
  808. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("HANDFREE out volume keeper create failed!");
  809. }
  810. }
  811. if (m_kept_volume_in[DEV_PICKUP]&&(eStand2sType == m_eDeviceType)){
  812. m_pKeeperIn[DEV_PICKUP] = volume_keeper_create(conf.audio_pickup_in_dev, 1, m_kept_volume_in[DEV_PICKUP]);
  813. if (m_pKeeperIn[DEV_PICKUP]) {
  814. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("PICKUP in volume keeper create ok! %d", m_kept_volume_in[DEV_PICKUP]);
  815. }
  816. else {
  817. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PICKUP in volume keeper create failed!");
  818. }
  819. }
  820. if (m_kept_volume_out[DEV_PICKUP]&&(eStand2sType == m_eDeviceType)){
  821. m_pKeeperOut[DEV_PICKUP] = volume_keeper_create(conf.audio_pickup_out_dev, 0, m_kept_volume_out[DEV_PICKUP]);
  822. if (m_pKeeperOut[DEV_PICKUP]) {
  823. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("PICKUP out volume keeper create ok! %d", m_kept_volume_out[DEV_PICKUP]);
  824. }
  825. else {
  826. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PICKUP out volume keeper create failed!");
  827. }
  828. }
  829. #else
  830. #endif // RVC_OS_WIN
  831. return Error_Succeed;
  832. }
  833. void CSIPEntity::OnReceivePkt(int type, int sub_type, const char *buffer, int size)
  834. {
  835. if (type == ACM_TYPE_DEVICE)
  836. {
  837. if (sub_type == ACM_SET_HANDFREE_OUTVOLUMN)
  838. {
  839. CVolumnValue num;
  840. SpBuffer buf;
  841. buf.OpenRead(buffer,size);
  842. num.Serialize(buf);
  843. #ifdef RVC_OS_WIN
  844. if (m_pKeeperOut[DEV_HANDFREE])
  845. {
  846. volume_keeper_change(m_pKeeperOut[DEV_HANDFREE], num.nValue);
  847. m_kept_volume_out[DEV_HANDFREE] = num.nValue;
  848. SendAudioDeviceVolumn(DEVICE_HANDFREE_OUT);
  849. 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]);
  850. }
  851. else
  852. {
  853. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("HANDFREE out volume keeper create failed!");
  854. }
  855. #else
  856. if (m_pAudioMgr)
  857. {
  858. m_pAudioMgr->audio_set_device_volume(num.nValue, conf.audio_handfree_out_dev, false);
  859. m_kept_volume_out[DEV_HANDFREE] = num.nValue;
  860. SendAudioDeviceVolumn(DEVICE_HANDFREE_OUT);
  861. 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]);
  862. }
  863. else
  864. {
  865. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("HANDFREE out volume keeper create failed!");
  866. }
  867. #endif
  868. }
  869. else if((sub_type == ACM_SET_PICKUP_OUTVOLUMN)&&(eStand2sType == m_eDeviceType))
  870. {
  871. CVolumnValue num;
  872. SpBuffer buf;
  873. buf.OpenRead(buffer,size);
  874. num.Serialize(buf);
  875. #ifdef RVC_OS_WIN
  876. if (m_pKeeperOut[DEV_PICKUP])
  877. {
  878. if(eStand2sType == m_eDeviceType){
  879. volume_keeper_change(m_pKeeperOut[DEV_PICKUP],num.nValue);
  880. m_kept_volume_out[DEV_PICKUP] = num.nValue;
  881. SendAudioDeviceVolumn(DEVICE_PICKUP_OUT);
  882. 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]);
  883. }
  884. else //pad版屏蔽当前PICKUP音量设置
  885. {
  886. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PAD type, ignore pickupout volume adj");
  887. }
  888. }
  889. else {
  890. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PICKUP out volume keeper create failed!");
  891. }
  892. #else
  893. if (m_pAudioMgr)
  894. {
  895. if (eStand2sType == m_eDeviceType)
  896. {
  897. m_pAudioMgr->audio_set_device_volume(num.nValue, conf.audio_pickup_out_dev, false);
  898. m_kept_volume_out[DEV_PICKUP] = num.nValue;
  899. SendAudioDeviceVolumn(DEVICE_PICKUP_OUT);
  900. 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]);
  901. }
  902. else //pad版屏蔽当前PICKUP音量设置
  903. {
  904. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PAD type, ignore pickupout volume adj");
  905. }
  906. }
  907. else
  908. {
  909. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PICKUP out volume keeper create failed!");
  910. }
  911. #endif
  912. }
  913. else if (sub_type == ACM_SET_HANDFREE_INVOLUMN)
  914. {
  915. CVolumnValue num;
  916. SpBuffer buf;
  917. buf.OpenRead(buffer,size);
  918. num.Serialize(buf);
  919. #ifdef RVC_OS_WIN
  920. if (m_pKeeperIn[DEV_HANDFREE])
  921. {
  922. volume_keeper_change(m_pKeeperIn[DEV_HANDFREE], num.nValue);
  923. m_kept_volume_in[DEV_HANDFREE] = num.nValue;
  924. SendAudioDeviceVolumn(DEVICE_HANDFREE_IN);
  925. 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]);
  926. }
  927. else{
  928. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("handfree in volume keeper create failed!");
  929. }
  930. #else
  931. if (m_pAudioMgr)
  932. {
  933. m_pAudioMgr->audio_set_device_volume(num.nValue, conf.audio_handfree_in_dev, true);
  934. m_kept_volume_in[DEV_HANDFREE] = num.nValue;
  935. SendAudioDeviceVolumn(DEVICE_HANDFREE_IN);
  936. 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]);
  937. }
  938. else
  939. {
  940. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("handfree in volume keeper create failed!");
  941. }
  942. #endif
  943. }
  944. else if((sub_type == ACM_SET_PICKUP_INVOLUMN)&&(eStand2sType == m_eDeviceType))
  945. {
  946. CVolumnValue num;
  947. SpBuffer buf;
  948. buf.OpenRead(buffer,size);
  949. num.Serialize(buf);
  950. #ifdef RVC_OS_WIN
  951. if (m_pKeeperIn[DEV_PICKUP])
  952. {
  953. if (eStand2sType == m_eDeviceType)
  954. {
  955. volume_keeper_change(m_pKeeperIn[DEV_PICKUP], num.nValue);
  956. m_kept_volume_in[DEV_PICKUP] = num.nValue;
  957. SendAudioDeviceVolumn(DEVICE_PICKUP_IN);
  958. 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]);
  959. }
  960. else //pad版屏蔽当前PICKUP音量设置
  961. {
  962. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PAD type, ignore pickupin volume adj");
  963. }
  964. }
  965. else
  966. {
  967. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("pickup in volume keeper create failed!");
  968. }
  969. #else
  970. if (m_pAudioMgr)
  971. {
  972. if (eStand2sType == m_eDeviceType)
  973. {
  974. m_pAudioMgr->audio_set_device_volume(num.nValue, conf.audio_pickup_in_dev, true);
  975. m_kept_volume_in[DEV_PICKUP] = num.nValue;
  976. SendAudioDeviceVolumn(DEVICE_PICKUP_IN);
  977. 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]);
  978. }
  979. else //pad版屏蔽当前PICKUP音量设置
  980. {
  981. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PAD type, ignore pickupin volume adj");
  982. }
  983. }
  984. else
  985. {
  986. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("pickup in volume keeper create failed!");
  987. }
  988. #endif
  989. }
  990. else if (sub_type == ACM_CONTROL_PERSONAREA) //控制人形框
  991. {
  992. CVolumnValue num;
  993. SpBuffer buf;
  994. buf.OpenRead(buffer,size);
  995. num.Serialize(buf);
  996. if (num.nValue == 0) //隐藏人形框
  997. {
  998. LogEvent(Severity_Middle,LOG_EVT_UI_HIDELOCALVIDEO,"Agent send hide local video");
  999. LogEvent(Severity_Middle,LOG_EVT_UI_HIDEPERSONAREA,"Agent send Hide Person area");
  1000. }
  1001. else if (num.nValue == 1) //显示人形框
  1002. {
  1003. LogEvent(Severity_Middle,LOG_EVT_UI_SHOWLOCALVIDEO,"Agent send show local video");
  1004. LogEvent(Severity_Middle,LOG_EVT_UI_SHOWPERSONAREA,"Agent send Show Person area");
  1005. }
  1006. else {
  1007. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("recv control person area sub_type error!");
  1008. }
  1009. }
  1010. }
  1011. else if (type == ACM_TYPE_VIDEOFREQ)
  1012. {
  1013. }
  1014. }
  1015. #ifdef RVC_OS_LINUX
  1016. ErrorCodeEnum CSIPEntity::RvcGetAudioDeviceInfo()
  1017. {
  1018. ErrorCodeEnum Error = Error_Param;
  1019. if (NULL != m_pAudioMgr) {
  1020. int icountmic = m_pAudioMgr->audio_get_device_count(true);
  1021. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("audio input devices(%d):", icountmic);
  1022. int i = 0;
  1023. CSimpleStringA strJsonIn("");
  1024. for (; i < icountmic; i++) {
  1025. char strname[MAX_PATH] = { 0 };
  1026. m_pAudioMgr->audio_get_device_name(strname, MAX_PATH, true, i);
  1027. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%d = %s", i, strname);
  1028. strJsonIn += CSimpleStringA::Format("\"%d\":\"%s\",", i, strname);
  1029. }
  1030. if (strJsonIn.GetLength() > 0) {
  1031. strJsonIn[strJsonIn.GetLength() - 1] = '\0';
  1032. }
  1033. CSimpleStringA strJsonInData = CSimpleStringA::Format("audio in devices [{%s}]", strJsonIn.GetData());
  1034. LogWarn(Severity_Low, Error_Debug, LOG_EVT_SIPPHONE_GET_AUDIO_IN_INFOS, strJsonInData.GetData());
  1035. CSimpleStringA strJsonOut("");
  1036. int icountspeaker = m_pAudioMgr->audio_get_device_count(false);
  1037. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("audio output devices(%d):", icountspeaker);
  1038. for (i = 0; i < icountspeaker; i++) {
  1039. char strname[MAX_PATH] = { 0 };
  1040. m_pAudioMgr->audio_get_device_name(strname, MAX_PATH, false, i);
  1041. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%d = %s", i, strname);
  1042. strJsonOut += CSimpleStringA::Format("\"%d\":\"%s\",", i, strname);
  1043. }
  1044. if (strJsonOut.GetLength() > 0) {
  1045. strJsonOut[strJsonOut.GetLength() - 1] = '\0';
  1046. }
  1047. CSimpleStringA strJsonOutData = CSimpleStringA::Format("audio out devices [{%s}]", strJsonOut.GetData());
  1048. LogWarn(Severity_Low, Error_Debug, LOG_EVT_SIPPHONE_GET_AUDIO_OUT_INFOS, strJsonOutData.GetData());
  1049. Error = Error_Succeed;
  1050. }
  1051. return Error;
  1052. }
  1053. ErrorCodeEnum CSIPEntity::RvcSetSaveAudioVolume()
  1054. {
  1055. ErrorCodeEnum Error = Error_Succeed;
  1056. if (eStand2sType == m_eDeviceType) {
  1057. if (m_pAudioMgr){
  1058. m_pAudioMgr->audio_set_device_volume(m_kept_volume_out[DEV_HANDFREE], conf.audio_handfree_out_dev, false);
  1059. m_pAudioMgr->audio_set_device_volume(m_kept_volume_in[DEV_HANDFREE], conf.audio_handfree_in_dev, true);
  1060. m_pAudioMgr->audio_set_device_volume(m_kept_volume_out[DEV_PICKUP], conf.audio_pickup_out_dev, false);
  1061. m_pAudioMgr->audio_set_device_volume(m_kept_volume_in[DEV_PICKUP], conf.audio_pickup_in_dev, true);
  1062. }
  1063. }
  1064. return Error;
  1065. }
  1066. #endif
  1067. void CSIPEntity::HideLocalVideo()
  1068. {
  1069. if (NULL != m_render) {
  1070. if (NULL != m_render->plocal_render) {
  1071. m_render->plocal_render->HideVideoWindow();
  1072. }
  1073. }
  1074. }
  1075. void CSIPEntity::ShowLocalVideo()
  1076. {
  1077. if (NULL != m_render) {
  1078. if (NULL != m_render->premote_render && NULL != m_render->plocal_render) {
  1079. m_render->plocal_render->ShowVideoWindow();
  1080. m_render->premote_render->HideVideoWindow();
  1081. m_render->premote_render->ShowVideoWindow();
  1082. }
  1083. }
  1084. }
  1085. void CSIPEntity::HideBothVideo()
  1086. {
  1087. if (NULL != m_render) {
  1088. if (NULL != m_render->premote_render && NULL != m_render->plocal_render) {
  1089. m_render->plocal_render->HideVideoWindow();
  1090. m_render->premote_render->HideVideoWindow();
  1091. }
  1092. }
  1093. }
  1094. void CSIPEntity::ShowBothVideo()
  1095. {
  1096. if (NULL != m_render) {
  1097. if (NULL != m_render->premote_render && NULL != m_render->plocal_render) {
  1098. m_render->plocal_render->ShowVideoWindow();
  1099. m_render->premote_render->ShowVideoWindow();
  1100. }
  1101. }
  1102. }
  1103. ErrorCodeEnum CSIPEntity::AudioDspFlagsUseCentersetting(endpoint_conf_t* conf)
  1104. {
  1105. SpIniMappingTable table;
  1106. CSmartPointer<IConfigInfo> spConfig;
  1107. endpoint_audiodsp_config_t audiodsp = { false, false, false, false, true, false, true, false, false, true };
  1108. table.AddEntryBoolean("SipPhone", "pickup_out_agc", audiodsp.audio_pickup_out_agc, false);
  1109. table.AddEntryBoolean("SipPhone", "pickup_in_agc", audiodsp.audio_pickup_in_agc, false);
  1110. table.AddEntryBoolean("SipPhone", "handfree_in_agc", audiodsp.audio_handfree_in_agc, false);
  1111. table.AddEntryBoolean("SipPhone", "handfree_out_agc", audiodsp.audio_handfree_out_agc, false);
  1112. table.AddEntryBoolean("SipPhone", "pickup_out_ns", audiodsp.audio_pickup_out_ns, false);
  1113. table.AddEntryBoolean("SipPhone", "pickup_in_ns", audiodsp.audio_pickup_in_ns, true);
  1114. table.AddEntryBoolean("SipPhone", "handfree_in_ns", audiodsp.audio_handfree_in_ns, true);
  1115. table.AddEntryBoolean("SipPhone", "handfree_out_ns", audiodsp.audio_handfree_out_ns, false);
  1116. table.AddEntryBoolean("SipPhone", "pickup_aec", audiodsp.audio_pickup_aec, false);
  1117. table.AddEntryBoolean("SipPhone", "handfree_aec", audiodsp.audio_handfree_aec, true);
  1118. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
  1119. if (Error == Error_Succeed) {
  1120. Error = table.Load(spConfig);
  1121. if (Error_Succeed == Error) {
  1122. memcpy(&conf->audio_dsp, &audiodsp, sizeof(endpoint_audiodsp_config_t));
  1123. }
  1124. }
  1125. else {
  1126. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("AudioDspFlagsUseCentersetting load Centersetting failed!");
  1127. memcpy(&conf->audio_dsp, &audiodsp, sizeof(endpoint_audiodsp_config_t));
  1128. }
  1129. return Error;
  1130. }
  1131. bool CSIPEntity::IsPostAudioConfigInfo()
  1132. {
  1133. bool bRet = false;
  1134. if (eStand2sType == m_eDeviceType || eStand1SPlusType == m_eDeviceType) {
  1135. if (strlen(conf.audio_handfree_in_dev) && strlen(conf.audio_handfree_out_dev) && strlen(conf.audio_pickup_in_dev) && strlen(conf.audio_pickup_out_dev)) {
  1136. bRet = true;
  1137. }
  1138. }
  1139. else {
  1140. if (strlen(conf.audio_handfree_in_dev) && strlen(conf.audio_handfree_out_dev)) {
  1141. bRet = true;
  1142. }
  1143. }
  1144. return bRet;
  1145. }
  1146. ErrorCodeEnum CSIPEntity::GetLocalIP()
  1147. {
  1148. #ifdef RVC_OS_WIN
  1149. char tmp[MAX_PATH] = { 0 };
  1150. gethostname(tmp, sizeof(tmp));
  1151. hostent* ent = gethostbyname(tmp);
  1152. if (ent) {
  1153. for (int i = 0; ent->h_addr_list[i]; ++i) {
  1154. if (ent->h_addrtype == AF_INET) {
  1155. struct in_addr* in = (struct in_addr*)ent->h_addr_list[i];
  1156. char* p = inet_ntoa(*in);
  1157. if (p[0] != '0')
  1158. {
  1159. if (strstr(p, "198.168.") == NULL)
  1160. {
  1161. strcpy(m_localip, p);
  1162. return Error_Succeed;
  1163. }
  1164. }
  1165. }
  1166. }
  1167. }
  1168. return Error_Unexpect;
  1169. #else
  1170. ErrorCodeEnum error = Error_Unexpect;
  1171. int sockfd = -1;
  1172. struct ifconf ifconf;
  1173. struct ifreq* ifreq = NULL;
  1174. char strbuf[MAX_PATH] = {0};
  1175. ifconf.ifc_len = MAX_PATH;
  1176. ifconf.ifc_buf = strbuf;
  1177. if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
  1178. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("socket error");
  1179. return error;
  1180. }
  1181. ioctl(sockfd, SIOCGIFCONF, &ifconf); //get all socket info
  1182. ifreq = (struct ifreq*)ifconf.ifc_buf;
  1183. for (int i = (ifconf.ifc_len / sizeof(struct ifreq)); i > 0; i--){
  1184. if (ifreq->ifr_flags == AF_INET) { //for ipv4
  1185. char* strIP = inet_ntoa(((struct sockaddr_in*) & (ifreq->ifr_addr))->sin_addr);
  1186. ifreq++;
  1187. if (NULL != strIP){
  1188. if (NULL == strstr(strIP, "198.168.") && NULL == strstr(strIP, "127.0.0.1"))
  1189. {
  1190. strcpy(m_localip, strIP);
  1191. error = Error_Succeed;
  1192. break;
  1193. }
  1194. }
  1195. }
  1196. }
  1197. close(sockfd);
  1198. return error;
  1199. #endif // RVC_OS_WIN
  1200. }
  1201. //send audio device volume
  1202. void CSIPEntity::SendAudioDeviceVolumn(int nDevice)
  1203. {
  1204. if (m_nSysCallType == 0)
  1205. {
  1206. ChannelService_Send_Info Info;
  1207. Info.compress = false;
  1208. Info.encrypt = false;
  1209. Info.type = ACM_TYPE_DEVICE;
  1210. Info.id = 0;
  1211. int nValue = 0;
  1212. bool rslt = false;
  1213. void*keeper = NULL;
  1214. if (nDevice == DEVICE_HANDFREE_OUT)
  1215. {
  1216. Info.sub_type = ACM_HANDFREE_OUTVOLUMN;
  1217. #ifdef RVC_OS_WIN
  1218. keeper = m_pKeeperOut[DEV_HANDFREE];
  1219. #else
  1220. m_pAudioMgr->audio_get_device_volume(&nValue, conf.audio_handfree_out_dev, false);
  1221. rslt = true;
  1222. #endif // RVC_OS_WIN
  1223. }
  1224. else if(nDevice == DEVICE_PICKUP_OUT)
  1225. {
  1226. if(eStand2sType == m_eDeviceType)
  1227. {
  1228. Info.sub_type = ACM_PICKUP_OUTVOLUMN;
  1229. #ifdef RVC_OS_WIN
  1230. keeper = m_pKeeperOut[DEV_PICKUP];
  1231. #else
  1232. m_pAudioMgr->audio_get_device_volume(&nValue, conf.audio_pickup_out_dev, false);
  1233. rslt = true;
  1234. #endif
  1235. }
  1236. else //pad版屏蔽当前PICKUP音量发送
  1237. {
  1238. return;
  1239. }
  1240. }
  1241. else if(nDevice == DEVICE_HANDFREE_IN)
  1242. {
  1243. Info.sub_type = ACM_HANDFREE_INVOLUMN;
  1244. #ifdef RVC_OS_WIN
  1245. keeper = m_pKeeperIn[DEV_HANDFREE];
  1246. #else
  1247. m_pAudioMgr->audio_get_device_volume(&nValue, conf.audio_handfree_in_dev, true);
  1248. rslt = true;
  1249. #endif
  1250. }
  1251. else if(nDevice == DEVICE_PICKUP_IN)
  1252. {
  1253. if(eStand2sType == m_eDeviceType)
  1254. {
  1255. Info.sub_type = ACM_PICKUP_INVOLUMN;
  1256. #ifdef RVC_OS_WIN
  1257. keeper = m_pKeeperIn[DEV_PICKUP];
  1258. #else
  1259. m_pAudioMgr->audio_get_device_volume(&nValue, conf.audio_pickup_in_dev, true);
  1260. rslt = true;
  1261. #endif
  1262. }
  1263. else //pad版屏蔽当前PICKUP音量发送
  1264. {
  1265. return;
  1266. }
  1267. }
  1268. Info.data.Alloc(sizeof(int));
  1269. SpBuffer buf;
  1270. buf.OpenWrite();
  1271. #ifdef RVC_OS_WIN
  1272. if (keeper){
  1273. rslt = get_audiodevice_volumn(keeper, &nValue);
  1274. }
  1275. #endif
  1276. if (rslt == true)
  1277. {
  1278. buf & nValue;
  1279. Info.data = buf.ToBlob();
  1280. m_pSipphoneChannel->Send(Info);
  1281. }
  1282. else
  1283. {
  1284. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Get cur Audio device %d volume Fail!",nDevice);
  1285. }
  1286. }
  1287. else
  1288. {
  1289. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("cur call type cannot send pkt");
  1290. }
  1291. }
  1292. ErrorCodeEnum CSIPEntity::SetHandfreeOutVolume(int iVolume)
  1293. {
  1294. ErrorCodeEnum Error = Error_Succeed;
  1295. #ifdef RVC_OS_WIN
  1296. if (m_pKeeperOut[DEV_HANDFREE]){
  1297. volume_keeper_change(m_pKeeperOut[DEV_HANDFREE], num.nValue);
  1298. m_kept_volume_out[DEV_HANDFREE] = iVolume;
  1299. 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]);
  1300. }
  1301. else{
  1302. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("HANDFREE out volume keeper create failed!");
  1303. }
  1304. #else
  1305. if (m_pAudioMgr){
  1306. m_pAudioMgr->audio_set_device_volume(iVolume, conf.audio_handfree_out_dev, false);
  1307. m_kept_volume_out[DEV_HANDFREE] = iVolume;
  1308. 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]);
  1309. }
  1310. else{
  1311. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("HANDFREE out volume keeper create failed!");
  1312. }
  1313. #endif
  1314. return Error;
  1315. }
  1316. ErrorCodeEnum CSIPEntity::SetPickupOutVolume(int iVolume)
  1317. {
  1318. ErrorCodeEnum Error = Error_Succeed;
  1319. #ifdef RVC_OS_WIN
  1320. if (m_pKeeperOut[DEV_PICKUP]){
  1321. if (eStand2sType == m_eDeviceType){
  1322. volume_keeper_change(m_pKeeperOut[DEV_PICKUP], iVolume);
  1323. m_kept_volume_out[DEV_PICKUP] = iVolume;
  1324. 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]);
  1325. }
  1326. else{
  1327. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PAD type, ignore pickupout volume adj");
  1328. }
  1329. }
  1330. else{
  1331. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PICKUP out volume keeper create failed!");
  1332. }
  1333. #else
  1334. if (m_pAudioMgr){
  1335. if (eStand2sType == m_eDeviceType || eStand1SPlusType == m_eDeviceType){
  1336. m_pAudioMgr->audio_set_device_volume(iVolume, conf.audio_pickup_out_dev, false);
  1337. m_kept_volume_out[DEV_PICKUP] = iVolume;
  1338. 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]);
  1339. }
  1340. else{
  1341. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PAD type, ignore pickupout volume adj");
  1342. }
  1343. }
  1344. else{
  1345. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PICKUP out volume keeper create failed!");
  1346. }
  1347. #endif
  1348. return Error;
  1349. }
  1350. ErrorCodeEnum CSIPEntity::SetHandfreeInVolume(int iVolume)
  1351. {
  1352. ErrorCodeEnum Error = Error_Succeed;
  1353. #ifdef RVC_OS_WIN
  1354. if (m_pKeeperIn[DEV_HANDFREE]) {
  1355. volume_keeper_change(m_pKeeperIn[DEV_HANDFREE], iVolume);
  1356. m_kept_volume_in[DEV_HANDFREE] = iVolume;
  1357. 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]);
  1358. }
  1359. #else
  1360. if (m_pAudioMgr) {
  1361. m_pAudioMgr->audio_set_device_volume(iVolume, conf.audio_handfree_in_dev, true);
  1362. m_kept_volume_in[DEV_HANDFREE] = iVolume;
  1363. 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]);
  1364. }
  1365. else {
  1366. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("HANDFREE in volume keeper create failed!");
  1367. }
  1368. #endif
  1369. return Error;
  1370. }
  1371. ErrorCodeEnum CSIPEntity::SetPickupInVolume(int iVolume)
  1372. {
  1373. ErrorCodeEnum Error = Error_Succeed;
  1374. #ifdef RVC_OS_WIN
  1375. if (m_pKeeperIn[DEV_PICKUP]) {
  1376. volume_keeper_change(m_pKeeperIn[DEV_PICKUP], iVolume);
  1377. m_kept_volume_in[DEV_PICKUP] = iVolume;
  1378. 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]);
  1379. }
  1380. #else
  1381. if (m_pAudioMgr) {
  1382. if (eStand2sType == m_eDeviceType || eStand1SPlusType == m_eDeviceType) {
  1383. m_pAudioMgr->audio_set_device_volume(iVolume, conf.audio_pickup_in_dev, true);
  1384. m_kept_volume_in[DEV_PICKUP] = iVolume;
  1385. 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]);
  1386. }
  1387. else {
  1388. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PAD type, ignore pickupin volume adj");
  1389. }
  1390. }
  1391. else {
  1392. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PICKUP in volume keeper create failed!");
  1393. }
  1394. #endif
  1395. return Error;
  1396. }
  1397. void CSIPEntity::OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  1398. {
  1399. ErrorCodeEnum Error = __OnClose(Error_Succeed);
  1400. pTransactionContext->SendAnswer(Error);
  1401. }
  1402. ErrorCodeEnum CSIPEntity::__OnClose(ErrorCodeEnum preOperationError)
  1403. {
  1404. int i;
  1405. #ifdef RVC_OS_WIN
  1406. if (m_pKeeperIn[DEV_HANDFREE]) {
  1407. volume_keeper_destroy(m_pKeeperIn[DEV_HANDFREE]);
  1408. m_pKeeperIn[DEV_HANDFREE] = NULL;
  1409. }
  1410. if (m_pKeeperOut[DEV_HANDFREE]) {
  1411. volume_keeper_destroy(m_pKeeperOut[DEV_HANDFREE]);
  1412. m_pKeeperOut[DEV_HANDFREE] = NULL;
  1413. }
  1414. if (m_pKeeperIn[DEV_PICKUP]) {
  1415. volume_keeper_destroy(m_pKeeperIn[DEV_PICKUP]);
  1416. m_pKeeperIn[DEV_PICKUP] = NULL;
  1417. }
  1418. if (m_pKeeperOut[DEV_PICKUP]) {
  1419. volume_keeper_destroy(m_pKeeperOut[DEV_PICKUP]);
  1420. m_pKeeperOut[DEV_PICKUP] = NULL;
  1421. }
  1422. #else
  1423. if (NULL != m_pAudioMgr) {
  1424. m_pAudioMgr->audio_mgr_terminate();
  1425. DestroyIAudioMgrObj(m_pAudioMgr);
  1426. m_pAudioMgr = NULL;
  1427. }
  1428. #endif
  1429. CSmartPointer<IEntityFunction> Func = GetFunction();
  1430. Func->UnregistSysVarEvent(SYSVAR_AGENTCAMERASWITCH);
  1431. Func->UnregistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA);
  1432. Func->UnregistSysVarEvent(SYSVAR_CAMERASTATE);
  1433. Func->UnregistSysVarEvent(SYSVAR_CALLTYPE);
  1434. for (i = 0; i < m_arrListener.GetCount(); ++i) {
  1435. Func->UnsubscribeLog(m_arrListener[i]);
  1436. }
  1437. m_arrListener.Clear();
  1438. endpoint_destroy(m_pEndpoint);
  1439. m_pEndpoint = NULL;
  1440. video_lib_deinit();
  1441. audio_lib_deinit();
  1442. endpoint_deinit_lib();
  1443. return Error_Succeed;
  1444. }
  1445. void CSIPEntity::OnPaused()
  1446. {
  1447. }
  1448. void CSIPEntity::OnContinued()
  1449. {
  1450. }
  1451. CServerSessionBase* CSIPEntity::OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszClass*/)
  1452. {
  1453. m_pCurrentSession = new CSIPPhoneSession(this);
  1454. return m_pCurrentSession;
  1455. }
  1456. void CSIPEntity::OnTimeout(DWORD dwTimerID)
  1457. {
  1458. if (dwTimerID == 1)
  1459. {
  1460. //如果当前动态帧频不等于之前的帧频,发送当前帧频
  1461. //if (g_nDynamicFps != m_nDownDynamicFps)
  1462. //{
  1463. // m_nDownDynamicFps = g_nDynamicFps;
  1464. // SendDynamicFps(g_nDynamicFps);
  1465. //}
  1466. GetFunction()->KillTimer(1);
  1467. m_stVideoParam.nUpDynamicFps = -1;
  1468. }
  1469. else if (2 == dwTimerID)
  1470. {
  1471. if (!m_bConnectedAssist) {
  1472. if (Error_Succeed == ConnectAssistChannel()) {
  1473. m_bConnectedAssist = true;
  1474. }
  1475. }
  1476. if (m_bConnectedAssist){
  1477. GetFunction()->KillTimer(2);
  1478. }
  1479. }
  1480. }
  1481. ErrorCodeEnum CSIPEntity::InitEndpoint()
  1482. {
  1483. ErrorCodeEnum eCode = Error_Param;
  1484. CSmartPointer<IEntityFunction> Func = GetFunction();
  1485. Func->GetSystemStaticInfo(staticInfo);
  1486. CSimpleStringA strUri = MakeUri(staticInfo.strTerminalID);
  1487. if (strUri.GetLength() > 0)
  1488. {
  1489. strcpy(conf.uri, strUri);
  1490. conf.media_start_port = REC_COMMON_AUDIO_PORT_START;
  1491. conf.media_stop_port = REC_COMMON_AUDIO_PORT_STOP;
  1492. m_pEndpoint = endpoint_create(this, &conf,DEV_HANDFREE);
  1493. if (!m_pEndpoint) {
  1494. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create endpoint failed!");
  1495. eCode = Error_Unexpect;
  1496. }
  1497. else{
  1498. eCode = Error_Succeed;
  1499. }
  1500. }
  1501. else
  1502. {
  1503. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("strUri length equals zero!");
  1504. eCode = Error_Unexpect;
  1505. }
  1506. return eCode;
  1507. }
  1508. void CSIPEntity::change_dev(int dev_type)
  1509. {
  1510. if (m_pEndpoint) {
  1511. endpoint_change_audio_dev(m_pEndpoint, dev_type);
  1512. }
  1513. }
  1514. static int __change_dev(void *arg)
  1515. {
  1516. ChangeDevCommand *pCmd = (ChangeDevCommand *)arg;
  1517. pCmd->pEntity->change_dev(pCmd->dev_type);
  1518. delete pCmd;
  1519. return 0;
  1520. }
  1521. void CSIPEntity::SwitchHandFree()
  1522. {
  1523. int rc = 0;
  1524. ChangeDevCommand *pCmd = new ChangeDevCommand();
  1525. pCmd->pEntity = this;
  1526. pCmd->dev_type = DEV_HANDFREE;
  1527. if (endpoint_invoke(m_pEndpoint, &__change_dev, pCmd, &rc) != 0) {
  1528. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("endpoint invoke failed!");
  1529. delete pCmd;
  1530. }
  1531. }
  1532. void CSIPEntity::SwitchPickup()
  1533. {
  1534. int rc = 0;
  1535. ChangeDevCommand *pCmd = new ChangeDevCommand();
  1536. pCmd->pEntity = this;
  1537. pCmd->dev_type = DEV_PICKUP;
  1538. if (endpoint_invoke(m_pEndpoint, &__change_dev, pCmd, &rc) != 0) {
  1539. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("endpoint invoke failed!");
  1540. delete pCmd;
  1541. }
  1542. }
  1543. void CSIPEntity::SetState(int state)
  1544. {
  1545. m_state = state;
  1546. }
  1547. ErrorCodeEnum CSIPEntity::RealSelfCheck()
  1548. {
  1549. ErrorCodeEnum Error = Error_Succeed;
  1550. if (m_pHMClient)
  1551. {
  1552. HealthManagerService_RealCheck_Req req;
  1553. req.name = GetEntityName();
  1554. HealthManagerService_RealCheck_Ans ans;
  1555. DWORD Timeout = 500;
  1556. Error = m_pHMClient->RealCheck(req,ans,Timeout);
  1557. if (Error!=Error_Succeed){
  1558. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("RealSelfcheck fail!");
  1559. }
  1560. }
  1561. return Error;
  1562. }
  1563. CSimpleStringA CSIPEntity::MakeUri(const char *terminal_id)
  1564. {
  1565. return CSimpleStringA::Format("sip:%s@%s;transport=UDP", terminal_id, m_localip);
  1566. }
  1567. void CSIPEntity::Handle_RecordVideoLocation_Info(const char* pszMessage)
  1568. {
  1569. if (NULL == pszMessage){
  1570. return;
  1571. }
  1572. CSimpleStringA strMsg = pszMessage;
  1573. int lxPos,lyPos,lwidth,lheight;
  1574. CSimpleStringA str;
  1575. sscanf(strMsg.GetData(), "%d@%d@%d@%d@%d@%s", &lxPos, &lyPos, &lwidth, &lheight, &str);
  1576. m_RecordVideoLocation.x = lxPos;
  1577. m_RecordVideoLocation.y = lyPos;
  1578. m_RecordVideoLocation.width = lwidth;
  1579. m_RecordVideoLocation.height = lheight;
  1580. }
  1581. void CSIPEntity::Handle_AdjustVideoEchoEvent(const char* pszMessage)
  1582. {
  1583. if (NULL == pszMessage){
  1584. return;
  1585. }
  1586. CSimpleStringA strMsg = pszMessage;
  1587. int lxPos,lyPos,lwidth,lheight;
  1588. CSimpleStringA str;
  1589. sscanf(strMsg.GetData(), "%d@%d@%d@%d@%d@%s", &lxPos, &lyPos, &lwidth, &lheight, &str);
  1590. if (DEFAULT_RECORD_VIDEO_WIDTH == lwidth && DEFAULT_RECORD_VIDEO_HEIGHT == lheight){
  1591. m_stVideoParam.nWindowState = 0;
  1592. }
  1593. else if(SMALL_RECORD_VIDEO_WIDTH == lwidth && SMALL_RECORD_VIDEO_HEIGHT == lheight){
  1594. m_stVideoParam.nWindowState = 5;
  1595. }
  1596. else{
  1597. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("not support width and height.");
  1598. }
  1599. m_RecordVideoLocation.x = lxPos;
  1600. m_RecordVideoLocation.y = lyPos;
  1601. m_RecordVideoLocation.width = lwidth;
  1602. m_RecordVideoLocation.height = lheight;
  1603. }
  1604. void CSIPEntity::InitFreshTimeConfig()
  1605. {
  1606. int ileftvideo = RVC_MAX_VIDEO_FRESH_TIME;
  1607. int irightvideo = RVC_MAX_VIDEO_FRESH_TIME;
  1608. CSmartPointer<IConfigInfo> spCacheConfig;
  1609. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_CenterSetting, spCacheConfig);
  1610. if (Error_Succeed == Error){
  1611. SpIniMappingTable table;
  1612. table.AddEntryInt("SIPPhone", "lfreshtime", ileftvideo, RVC_MAX_VIDEO_FRESH_TIME);
  1613. table.AddEntryInt("SIPPhone", "rfreshtime", irightvideo, RVC_MAX_VIDEO_FRESH_TIME);
  1614. Error = table.Load(spCacheConfig);
  1615. if (Error == Error_Succeed) {
  1616. if (0 == ileftvideo) {
  1617. ileftvideo = RVC_MAX_VIDEO_FRESH_TIME/2;
  1618. }
  1619. if (0 == irightvideo) {
  1620. irightvideo = RVC_MAX_VIDEO_FRESH_TIME/2;
  1621. }
  1622. if (ileftvideo < RVC_MIN_VIDEO_FRESH_TIME) {
  1623. ileftvideo = RVC_MIN_VIDEO_FRESH_TIME;
  1624. }
  1625. if (ileftvideo > RVC_MAX_VIDEO_FRESH_TIME) {
  1626. ileftvideo = RVC_MAX_VIDEO_FRESH_TIME;
  1627. }
  1628. if (irightvideo < RVC_MIN_VIDEO_FRESH_TIME) {
  1629. irightvideo = RVC_MIN_VIDEO_FRESH_TIME;
  1630. }
  1631. if (irightvideo > RVC_MAX_VIDEO_FRESH_TIME) {
  1632. irightvideo = RVC_MAX_VIDEO_FRESH_TIME;
  1633. }
  1634. }
  1635. }
  1636. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_OVERWRITE_FRESHVALUE,
  1637. CSimpleStringA::Format("overwrite video freshtime from centersetting cache, left fresh time is %d, right fresh time is %d.", ileftvideo, irightvideo).GetData());
  1638. m_ilocalvideo_freshtime = ileftvideo;
  1639. m_iremotevideo_freshtime = irightvideo;
  1640. }
  1641. ErrorCodeEnum CSIPEntity::LoadConfig(endpoint_conf_t *conf)
  1642. {
  1643. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1644. CSmartPointer<IConfigInfo> spRootConfig;
  1645. ErrorCodeEnum Error = spFunction->OpenConfig(Config_Root, spRootConfig);
  1646. if (Error == Error_Succeed) {
  1647. CSimpleStringA strHandFreeIn;
  1648. CSimpleStringA strHandFreeOut;
  1649. CSimpleStringA strPickupIn;
  1650. CSimpleStringA strPickupOut;
  1651. SpIniMappingTable table;
  1652. table.AddEntryString("audio", "handfree_in_dev", strHandFreeIn, "$");
  1653. table.AddEntryString("audio", "handfree_out_dev", strHandFreeOut, "$");
  1654. table.AddEntryString("audio", "pickup_in_dev", strPickupIn, "$");
  1655. table.AddEntryString("audio", "pickup_out_dev", strPickupOut, "$");
  1656. table.AddEntryBoolean("audio", "pickup_out_agc", conf->audio_dsp.audio_pickup_out_agc, false);
  1657. table.AddEntryBoolean("audio", "pickup_in_agc", conf->audio_dsp.audio_pickup_in_agc, false);
  1658. table.AddEntryBoolean("audio", "handfree_in_agc", conf->audio_dsp.audio_handfree_in_agc, false);
  1659. table.AddEntryBoolean("audio", "handfree_out_agc", conf->audio_dsp.audio_handfree_out_agc, false);
  1660. table.AddEntryBoolean("audio", "pickup_out_ns", conf->audio_dsp.audio_pickup_out_ns, false);
  1661. table.AddEntryBoolean("audio", "pickup_in_ns", conf->audio_dsp.audio_pickup_in_ns, false);
  1662. table.AddEntryBoolean("audio", "handfree_in_ns", conf->audio_dsp.audio_handfree_in_ns, false);
  1663. table.AddEntryBoolean("audio", "handfree_out_ns", conf->audio_dsp.audio_handfree_out_ns, false);
  1664. table.AddEntryBoolean("audio", "pickup_aec", conf->audio_dsp.audio_pickup_aec, false);
  1665. table.AddEntryBoolean("audio", "handfree_aec", conf->audio_dsp.audio_handfree_aec, false);
  1666. table.AddEntryInt("audio", "handfree_in_volume", m_kept_volume_in[DEV_HANDFREE], 0);
  1667. table.AddEntryInt("audio", "handfree_out_volume", m_kept_volume_out[DEV_HANDFREE], 0);
  1668. table.AddEntryInt("audio", "pickup_in_volume", m_kept_volume_in[DEV_PICKUP], 0);
  1669. table.AddEntryInt("audio", "pickup_out_volume", m_kept_volume_out[DEV_PICKUP], 0);
  1670. table.AddEntryInt("video", "quant", conf->quant, 0);
  1671. table.AddEntryInt("video", "mtu", conf->mtu, 0);
  1672. Error = table.Load(spRootConfig);
  1673. if (Error == Error_Succeed) {
  1674. int id = -1;
  1675. snprintf(conf->audio_handfree_in_dev, MAX_PATH, "%s", strHandFreeIn.GetData());
  1676. snprintf(conf->audio_handfree_out_dev, MAX_PATH, "%s", strHandFreeOut.GetData());
  1677. snprintf(conf->audio_pickup_in_dev, MAX_PATH, "%s", strPickupIn.GetData());
  1678. snprintf(conf->audio_pickup_out_dev, MAX_PATH, "%s", strPickupOut.GetData());
  1679. 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]));
  1680. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_AUDIO_DSP_INFO, generateAudioDspFlags(conf->audio_dsp).GetData());
  1681. if (m_iAudioDspUseCenter) {
  1682. AudioDspFlagsUseCentersetting(conf);
  1683. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_CENTER_AUDIO_DSP_FLAGS, generateAudioDspFlags(conf->audio_dsp).GetData());
  1684. }
  1685. #ifdef RVC_OS_WIN
  1686. id = capture_get_audio_device_id(true, strHandFreeIn.GetData());
  1687. #else
  1688. id = m_pAudioMgr->audio_get_device_id(strHandFreeIn.GetData(), true);
  1689. #endif
  1690. if (id == -1) {
  1691. CSimpleStringA strErrMsg = "外部麦克风配置错误,请重新配置!";
  1692. LogWarn(Severity_Middle, Error_Param, EVENT_MOD_SIP_AUDIO_IN_DEVICE_NOT_EXIST, strErrMsg.GetData());
  1693. Error = Error_Param;
  1694. }
  1695. #ifdef RVC_OS_WIN
  1696. id = capture_get_audio_device_id(false, strHandFreeOut.GetData());
  1697. #else
  1698. id = m_pAudioMgr->audio_get_device_id(strHandFreeOut.GetData(), false);
  1699. #endif
  1700. if (id == -1) {
  1701. CSimpleStringA strErrMsg = "外部扬声器配置错误,请重新配置!";
  1702. LogWarn(Severity_Middle, Error_Param, EVENT_MOD_SIP_AUDIO_OUT_DEVICE_NOT_EXIST, strErrMsg.GetData());
  1703. Error = Error_Param;
  1704. }
  1705. #ifdef RVC_OS_WIN
  1706. id = capture_get_audio_device_id(true, strPickupIn.GetData());
  1707. #else
  1708. id = m_pAudioMgr->audio_get_device_id(strPickupIn.GetData(), true);
  1709. #endif
  1710. if (id == -1) {
  1711. CSimpleStringA strErrMsg = "话筒麦克风(大机)配置错误,请重新配置!";
  1712. LogWarn(Severity_Middle, Error_Param, EVENT_MOD_SIP_AUDIO_IN_DEVICE_NOT_EXIST, strErrMsg.GetData());
  1713. Error = Error_Param;
  1714. }
  1715. #ifdef RVC_OS_WIN
  1716. id = capture_get_audio_device_id(false, strPickupOut.GetData());
  1717. #else
  1718. id = m_pAudioMgr->audio_get_device_id(strPickupOut.GetData(), false);
  1719. #endif
  1720. if (id == -1) {
  1721. CSimpleStringA strErrMsg = "话筒扬声器(大机)配置错误,请重新配置!";
  1722. LogWarn(Severity_Middle, Error_Param, EVENT_MOD_SIP_AUDIO_OUT_DEVICE_NOT_EXIST, strErrMsg.GetData());
  1723. Error = Error_Param;
  1724. }
  1725. conf->ref_active_camera = &m_stVideoParam.iActiveCamera;
  1726. conf->ref_camera_switch = &m_stVideoParam.iCameraSwitch;
  1727. conf->ref_window_state = &m_stVideoParam.nWindowState;
  1728. conf->ref_active_img = &m_stVideoParam.bShowActiveImg;
  1729. conf->ref_Is_ActiveInspect = &m_stVideoParam.bActiveInspect;
  1730. conf->ref_camera_state = &m_stVideoParam.iCameraState;
  1731. conf->ref_Is_showPersonArea = &m_stVideoParam.bShowPersonArea;
  1732. conf->ref_Is_showRecordArea = &m_stVideoParam.bShowRecordArea;
  1733. m_stVideoParam.nUpDynamicFps = 0;
  1734. conf->ref_Up_Fps = &m_stVideoParam.nUpDynamicFps;
  1735. if (eStand1SPlusType == m_eDeviceType)
  1736. {
  1737. conf->camera_count = 1;
  1738. }
  1739. else if(eStand2sType == m_eDeviceType)
  1740. {
  1741. conf->camera_count = 2;
  1742. }
  1743. //DecideCameraCount(conf->camera_count);
  1744. DecideScreenCount(conf->screen_count);
  1745. }
  1746. }
  1747. InitFreshTimeConfig();
  1748. return Error;
  1749. }
  1750. //载入运行时配置
  1751. ErrorCodeEnum CSIPEntity::LoadAudioRunConfig(int&nHandfreeout,int&nPickupout,int&nHandfreein,int&nPickupin)
  1752. {
  1753. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1754. CSmartPointer<IConfigInfo> spConfig;
  1755. ErrorCodeEnum Error = spFunction->OpenConfig(Config_Run, spConfig);
  1756. if (Error == Error_Succeed)
  1757. {
  1758. SpIniMappingTable table;
  1759. table.AddEntryInt("Audio", "handfree_out_volume", nHandfreeout, 0);
  1760. table.AddEntryInt("Audio", "pickup_out_volume", nPickupout, 0);
  1761. table.AddEntryInt("Audio", "handfree_in_volume", nHandfreein, 0);
  1762. table.AddEntryInt("Audio", "pickup_in_volume", nPickupin, 0);
  1763. Error = table.Load(spConfig);
  1764. if (Error != Error_Succeed)
  1765. {
  1766. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[dbg] failed to load run config.");
  1767. }
  1768. }
  1769. else
  1770. {
  1771. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[dbg] failed to open run config.");
  1772. }
  1773. return Error;
  1774. }
  1775. //保存运行时
  1776. ErrorCodeEnum CSIPEntity::SaveAudioRunConfig(int nHandfreeout,int nPickupout,int nHandfreein,int nPickupin)
  1777. {
  1778. CSmartPointer<IEntityFunction> spFunction = GetFunction();;
  1779. CSmartPointer<IConfigInfo> spConfig;
  1780. ErrorCodeEnum Error = spFunction->OpenConfig(Config_Run, spConfig);
  1781. if (Error == Error_Succeed)
  1782. {
  1783. Error = spConfig->WriteConfigValueInt("Audio", "handfree_out_volume", nHandfreeout);
  1784. if(Error == Error_Succeed)
  1785. {
  1786. Error = spConfig->WriteConfigValueInt("Audio", "pickup_out_volume", nPickupout);
  1787. }
  1788. else
  1789. {
  1790. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SaveAudioRunConfig handfree_out_volume fail!");
  1791. return Error;
  1792. }
  1793. if(Error == Error_Succeed)
  1794. {
  1795. Error = spConfig->WriteConfigValueInt("Audio", "handfree_in_volume", nHandfreein);
  1796. }
  1797. else
  1798. {
  1799. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SaveAudioRunConfig pickup_out_volume fail!");
  1800. return Error;
  1801. }
  1802. if(Error == Error_Succeed)
  1803. {
  1804. Error = spConfig->WriteConfigValueInt("Audio", "pickup_in_volume", nPickupin);
  1805. }
  1806. else
  1807. {
  1808. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SaveAudioRunConfig handfree_in_volume fail!");
  1809. return Error;
  1810. }
  1811. if (Error != Error_Succeed)
  1812. {
  1813. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SaveAudioRunConfig pickup_in_volume fail!");
  1814. return Error;
  1815. }
  1816. }
  1817. else
  1818. {
  1819. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SaveAudioRunConfig is fail , open sipphone.ini fail!");
  1820. }
  1821. return Error;
  1822. }
  1823. ErrorCodeEnum CSIPEntity::DecideScreenCount(int &nCount)
  1824. {
  1825. CSystemStaticInfo Info;
  1826. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1827. ErrorCodeEnum Error = spFunction->GetSystemStaticInfo(Info);
  1828. if (Error == Error_Succeed)
  1829. {
  1830. nCount = (int)Info.eScreen;
  1831. }
  1832. return Error;
  1833. }
  1834. DeviceTypeEnum CSIPEntity::RvcGetDeviceType()
  1835. {
  1836. DeviceTypeEnum eType = eStand2sType;
  1837. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1838. CSystemStaticInfo stStaticinfo;
  1839. spFunction->GetSystemStaticInfo(stStaticinfo);
  1840. if (_stricmp(stStaticinfo.strMachineType, "RVC.Stand1SPlus") == 0) {
  1841. eType = eStand1SPlusType;
  1842. }
  1843. else if (stricmp(stStaticinfo.strMachineType, "RVC.CardStore") == 0 || stricmp(stStaticinfo.strMachineType, "RVC.CardPrinter") == 0) {
  1844. eType = eCardStore;
  1845. }
  1846. else {
  1847. eType = eStand2sType;
  1848. }
  1849. if (eType >= 0 && eType < sizeof(Device_Type_Table) / sizeof(char*)) {
  1850. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("device type is %s.", Device_Type_Table[eType]);
  1851. }
  1852. return eType;
  1853. }
  1854. //
  1855. // CSIPPhoneSession
  1856. //
  1857. void CSIPPhoneSession::OnClose( ErrorCodeEnum eErrorCode )
  1858. {
  1859. }
  1860. void CSIPPhoneSession::Handle_MakeCall( SpReqAnsContext<PhoneService_MakeCall_Req, PhoneService_MakeCall_Ans>::Pointer ctx )
  1861. {
  1862. DbgToBeidou(ctx->link, __FUNCTION__)();
  1863. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_CALL_URL, CSimpleStringA::Format("make call [%s]", ctx->Req.to_uri.GetData()).GetData());
  1864. int rc = Error_Succeed;
  1865. MakeCallCommand_t *cmd = new MakeCallCommand_t();
  1866. cmd->pSIPPhoneSession = this;
  1867. cmd->toUri = ctx->Req.to_uri;
  1868. cmd->fromUri = ctx->Req.from_uri;
  1869. cmd->callId = ctx->Req.call_id;
  1870. cmd->imapped_audio_port = 0;
  1871. cmd->imapped_video_port = 0;
  1872. ///////////重新初始化sip话机,防止断网导致IP改变//////////////////
  1873. if (m_pEntity->m_pEndpoint){
  1874. endpoint_destroy(m_pEntity->m_pEndpoint);
  1875. m_pEntity->m_pEndpoint = NULL;
  1876. }
  1877. ErrorCodeEnum Error = m_pEntity->GetLocalIP();
  1878. if (Error != 0){
  1879. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get local ip failed!");
  1880. ctx->Answer(Error_Unexpect);
  1881. return;
  1882. }
  1883. cmd->strlocalip = m_pEntity->m_localip;
  1884. CSimpleStringA strUri = m_pEntity->MakeUri(m_pEntity->staticInfo.strTerminalID);
  1885. if (strUri.GetLength() > 0)
  1886. {
  1887. strcpy(m_pEntity->conf.uri, strUri);
  1888. m_pEntity->conf.media_start_port = REC_COMMON_AUDIO_PORT_START;
  1889. m_pEntity->conf.media_stop_port = REC_COMMON_AUDIO_PORT_STOP;
  1890. m_pEntity->m_pEndpoint = endpoint_create(m_pEntity, &m_pEntity->conf,m_pEntity->m_iPickupPhoneState);
  1891. if (!m_pEntity->m_pEndpoint){
  1892. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create endpoint failed!");
  1893. return;
  1894. }
  1895. else {
  1896. cmd->iaudio_port = new_media_port(m_pEntity->m_pEndpoint);
  1897. cmd->ivideo_port = REC_COMMON_VIDEO_PORT;
  1898. }
  1899. }
  1900. else {
  1901. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("strUri length equals zero!");
  1902. }
  1903. ///////////重新初始化sip话机,防止断网导致IP改变//////////////////
  1904. if (m_pEntity->GetEndpoint()) {
  1905. endpoint_invoke(m_pEntity->GetEndpoint(), &__make_call, cmd, &rc);
  1906. }
  1907. ctx->Answer((ErrorCodeEnum)rc);
  1908. }
  1909. void CSIPPhoneSession::Handle_HangupCall( SpReqAnsContext<PhoneService_HangupCall_Req, PhoneService_HangupCall_Ans>::Pointer ctx )
  1910. {
  1911. DbgToBeidou(ctx->link, __FUNCTION__)();
  1912. int rc = Error_Succeed;
  1913. HangupCallCommand *cmd = new HangupCallCommand();
  1914. cmd->pSIPPhoneSession = this;
  1915. cmd->strSession_num = ctx->Req.session_num;
  1916. cmd->strBranch_server_ip = ctx->Req.branch_server_ip;
  1917. cmd->iBranch_server_port = ctx->Req.branch_server_port;
  1918. if (m_pEntity->GetEndpoint())
  1919. {
  1920. endpoint_invoke(m_pEntity->GetEndpoint(), &__hangup_call, cmd, &rc);
  1921. }
  1922. ctx->Answer((ErrorCodeEnum)rc);
  1923. }
  1924. void CSIPPhoneSession::Handle_ReleaseCall( SpReqAnsContext<PhoneService_ReleaseCall_Req, PhoneService_ReleaseCall_Ans>::Pointer ctx )
  1925. {
  1926. DbgToBeidou(ctx->link, __FUNCTION__)();
  1927. int rc = Error_Succeed;
  1928. g_IsExternalTerminalted = TRUE;
  1929. endpoint_invoke(m_pEntity->GetEndpoint(), &__release_call, this, &rc);
  1930. if (NULL != m_pEntity->m_pEndpoint){
  1931. endpoint_destroy(m_pEntity->m_pEndpoint);
  1932. m_pEntity->m_pEndpoint = NULL;
  1933. }
  1934. ctx->Answer((ErrorCodeEnum)rc);
  1935. }
  1936. void CSIPPhoneSession::Handle_SetCallingParam(SpOnewayCallContext<PhoneService_SetCallingParam_Info>::Pointer ctx)
  1937. {
  1938. DbgToBeidou(ctx->link, __FUNCTION__)();
  1939. m_pEntity->m_nCallType = (CallingTypeEnum)ctx->Info.CallType;
  1940. }
  1941. void CSIPPhoneSession::Handle_RealErrorCheck(SpOnewayCallContext<PhoneService_RealErrorCheck_Info>::Pointer ctx)
  1942. {
  1943. DbgToBeidou(ctx->link, __FUNCTION__)();
  1944. m_pEntity->m_SipErrorCode = Error_InvalidState;
  1945. m_pEntity->RealSelfCheck();
  1946. }
  1947. void CSIPPhoneSession::Handle_StartVideo( SpOnewayCallContext<PhoneService_StartVideo_Info>::Pointer ctx )
  1948. {
  1949. DbgToBeidou(ctx->link, __FUNCTION__)();
  1950. int rc;
  1951. ControlVideoCommand *pCmd = new ControlVideoCommand();
  1952. pCmd->pSIPPhoneSession = this;
  1953. pCmd->start = TRUE;
  1954. pCmd->local_hwd_move = 0;
  1955. pCmd->remote_hwd_move = 0;
  1956. pCmd->local_ip = inet_addr(m_pEntity->m_localip);
  1957. pCmd->local_port = REC_COMMON_VIDEO_PORT;
  1958. pCmd->remote_ip = inet_addr(ctx->Info.remote_ip);
  1959. pCmd->remote_port = ctx->Info.remote_port;
  1960. pCmd->local_view_x = ctx->Info.local_view_x;
  1961. pCmd->local_view_y = ctx->Info.local_view_y;
  1962. pCmd->local_view_cx = ctx->Info.local_view_cx;
  1963. pCmd->local_view_cy = ctx->Info.local_view_cy;
  1964. pCmd->remote_view_x = ctx->Info.remote_view_x;
  1965. pCmd->remote_view_y = ctx->Info.remote_view_y;
  1966. pCmd->remote_view_cx = ctx->Info.remote_view_cx;
  1967. pCmd->remote_view_cy = ctx->Info.remote_view_cy;
  1968. pCmd->remote_width = ctx->Info.remote_width;
  1969. pCmd->remote_height = ctx->Info.remote_height;
  1970. pCmd->local_hwd_move = ctx->Info.local_hwd_move;
  1971. pCmd->remote_hwd_move = ctx->Info.remote_hwd_move;
  1972. pCmd->local_fresh_time = m_pEntity->m_ilocalvideo_freshtime;
  1973. pCmd->remote_fresh_time = m_pEntity->m_iremotevideo_freshtime;
  1974. endpoint_invoke(m_pEntity->GetEndpoint(), &__control_video, pCmd, &rc);
  1975. }
  1976. void CSIPPhoneSession::Handle_StopVideo( SpOnewayCallContext<PhoneService_StopVideo_Info>::Pointer ctx )
  1977. {
  1978. DbgToBeidou(ctx->link, __FUNCTION__)();
  1979. int rc;
  1980. ControlVideoCommand *pCmd = new ControlVideoCommand();
  1981. pCmd->pSIPPhoneSession = this;
  1982. pCmd->start = FALSE;
  1983. m_pEntity->GetFunction()->KillTimer(1);
  1984. if (NULL != m_pEntity->GetEndpoint()){
  1985. endpoint_invoke(m_pEntity->GetEndpoint(), &__control_video, pCmd, &rc);
  1986. }
  1987. m_pEntity->m_stVideoParam.bShowActiveImg = 0;
  1988. m_pEntity->m_stVideoParam.bActiveInspect = 0;
  1989. //初始化窗口参数
  1990. m_pEntity->m_stVideoParam.nWindowState = 0;
  1991. }
  1992. void CSIPPhoneSession::Handle_StartVideoRender(SpOnewayCallContext<PhoneService_StartVideoRender_Info>::Pointer ctx)
  1993. {
  1994. DbgToBeidou(ctx->link, __FUNCTION__)();
  1995. int rc;
  1996. VideoRenderCommand_t* pCmd = new VideoRenderCommand_t();
  1997. pCmd->pSIPPhoneSession = this;
  1998. pCmd->bstart = true;
  1999. pCmd->local_hwd_move = 0;
  2000. pCmd->remote_hwd_move = 0;
  2001. pCmd->local_view_x = ctx->Info.local_view_x;
  2002. pCmd->local_view_y = ctx->Info.local_view_y;
  2003. pCmd->local_view_cx = ctx->Info.local_view_cx;
  2004. pCmd->local_view_cy = ctx->Info.local_view_cy;
  2005. pCmd->remote_view_x = ctx->Info.remote_view_x;
  2006. pCmd->remote_view_y = ctx->Info.remote_view_y;
  2007. pCmd->remote_view_cx = ctx->Info.remote_view_cx;
  2008. pCmd->remote_view_cy = ctx->Info.remote_view_cy;
  2009. pCmd->local_hwd_move = ctx->Info.local_hwd_move;
  2010. pCmd->remote_hwd_move = ctx->Info.remote_hwd_move;
  2011. pCmd->local_fresh_time = m_pEntity->m_ilocalvideo_freshtime;
  2012. pCmd->remote_fresh_time = m_pEntity->m_iremotevideo_freshtime;
  2013. endpoint_invoke(m_pEntity->GetEndpoint(), &__video_render, pCmd, &rc);
  2014. }
  2015. void CSIPPhoneSession::Handle_StopVideoRender(SpOnewayCallContext<PhoneService_StopVideoRender_Info>::Pointer ctx)
  2016. {
  2017. DbgToBeidou(ctx->link, __FUNCTION__)();
  2018. VideoRenderCommand_t* pCmd = new VideoRenderCommand_t();
  2019. int rc;
  2020. pCmd->pSIPPhoneSession = this;
  2021. pCmd->bstart = false;
  2022. m_pEntity->GetFunction()->KillTimer(1);
  2023. if (NULL != m_pEntity->GetEndpoint()) {
  2024. endpoint_invoke(m_pEntity->GetEndpoint(), &__video_render, pCmd, &rc);
  2025. }
  2026. }
  2027. void CSIPPhoneSession::Handle_GetHandfreeInVolume(SpReqAnsContext<PhoneService_GetHandfreeInVolume_Req, PhoneService_GetHandfreeInVolume_Ans>::Pointer ctx)
  2028. {
  2029. DbgToBeidou(ctx->link, __FUNCTION__)();
  2030. ctx->Ans.Volume = m_pEntity->m_kept_volume_in[DEV_HANDFREE];
  2031. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("get hand free in volume is %d.", ctx->Ans.Volume);
  2032. ctx->Answer(Error_Succeed);
  2033. }
  2034. void CSIPPhoneSession::Handle_SetHandfreeInVolume(SpReqAnsContext<PhoneService_SetHandfreeInVolume_Req, PhoneService_SetHandfreeInVolume_Ans>::Pointer ctx)
  2035. {
  2036. DbgToBeidou(ctx->link, __FUNCTION__)();
  2037. int iVolume = ctx->Req.Volume;
  2038. if (iVolume > 100) {
  2039. iVolume = 100;
  2040. }
  2041. if (iVolume < 0) {
  2042. iVolume = 0;
  2043. }
  2044. m_pEntity->SetHandfreeInVolume(iVolume);
  2045. ctx->Answer(Error_Succeed);
  2046. }
  2047. void CSIPPhoneSession::Handle_SetPickupInVolume(SpReqAnsContext<PhoneService_SetPickupInVolume_Req, PhoneService_SetPickupInVolume_Ans>::Pointer ctx)
  2048. {
  2049. DbgToBeidou(ctx->link, __FUNCTION__)();
  2050. if (eStand2sType == m_pEntity->m_eDeviceType || eStand1SPlusType == m_pEntity->m_eDeviceType) {
  2051. int iVolume = ctx->Req.Volume;
  2052. if (iVolume > 100) {
  2053. iVolume = 100;
  2054. }
  2055. if (iVolume < 0) {
  2056. iVolume = 0;
  2057. }
  2058. m_pEntity->SetPickupInVolume(iVolume);
  2059. }
  2060. ctx->Answer(Error_Succeed);
  2061. }
  2062. void CSIPPhoneSession::Handle_GetPickupInVolume(SpReqAnsContext<PhoneService_GetPickupInVolume_Req, PhoneService_GetPickupInVolume_Ans>::Pointer ctx)
  2063. {
  2064. DbgToBeidou(ctx->link, __FUNCTION__)();
  2065. if (eStand2sType == m_pEntity->m_eDeviceType || eStand1SPlusType == m_pEntity->m_eDeviceType) {
  2066. ctx->Ans.Volume = m_pEntity->m_kept_volume_in[DEV_PICKUP];
  2067. }
  2068. else {
  2069. ctx->Ans.Volume = 0;
  2070. }
  2071. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("get pick up in volume is %d.", ctx->Ans.Volume);
  2072. ctx->Answer(Error_Succeed);
  2073. }
  2074. void CSIPPhoneSession::Handle_GetAudioDevices(SpReqAnsContext<PhoneService_GetAudioDevices_Req, PhoneService_GetAudioDevices_Ans>::Pointer ctx)
  2075. {
  2076. DbgToBeidou(ctx->link, __FUNCTION__)();
  2077. ctx->Ans.strHandfreeIn = m_pEntity->conf.audio_handfree_in_dev;
  2078. ctx->Ans.strHandfreeOut = m_pEntity->conf.audio_handfree_out_dev;
  2079. ctx->Ans.strPickupIn = m_pEntity->conf.audio_pickup_in_dev;
  2080. ctx->Ans.strPickupOut = m_pEntity->conf.audio_pickup_out_dev;
  2081. ctx->Ans.retCode = Error_Succeed;
  2082. ctx->Answer(Error_Succeed);
  2083. }
  2084. void CSIPPhoneSession::Handle_BeginState( SpSubscribeContext<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::Pointer ctx )
  2085. {
  2086. m_spCallbackContext = ctx;
  2087. }
  2088. void CSIPPhoneSession::Handle_EndState( SpOnewayCallContext<PhoneService_EndState_Info>::Pointer ctx )
  2089. {
  2090. DbgToBeidou(ctx->link, __FUNCTION__)();
  2091. SpSubscribeContext<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::Pointer tmp_ctx = m_spCallbackContext;
  2092. m_spCallbackContext.Clear();
  2093. }
  2094. void CSIPPhoneSession::Handle_GetHandfreeOutVolume(SpReqAnsContext<PhoneService_GetHandfreeOutVolume_Req, PhoneService_GetHandfreeOutVolume_Ans>::Pointer ctx)
  2095. {
  2096. DbgToBeidou(ctx->link, __FUNCTION__)();
  2097. ctx->Ans.Volume = m_pEntity->m_kept_volume_out[DEV_HANDFREE];
  2098. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("get hand free out volume is %d.", ctx->Ans.Volume);
  2099. ctx->Answer(Error_Succeed);
  2100. }
  2101. void CSIPPhoneSession::Handle_SetHandfreeOutVolume(SpReqAnsContext<PhoneService_SetHandfreeOutVolume_Req, PhoneService_SetHandfreeOutVolume_Ans>::Pointer ctx)
  2102. {
  2103. DbgToBeidou(ctx->link, __FUNCTION__)();
  2104. int iVolume = ctx->Req.Volume;
  2105. if (iVolume > 100){
  2106. iVolume = 100;
  2107. }
  2108. if (iVolume < 0){
  2109. iVolume = 0;
  2110. }
  2111. m_pEntity->SetHandfreeOutVolume(iVolume);
  2112. ctx->Answer(Error_Succeed);
  2113. }
  2114. void CSIPPhoneSession::Handle_GetPickupOutVolume(SpReqAnsContext<PhoneService_GetPickupOutVolume_Req, PhoneService_GetPickupOutVolume_Ans>::Pointer ctx)
  2115. {
  2116. DbgToBeidou(ctx->link, __FUNCTION__)();
  2117. if (eStand2sType == m_pEntity->m_eDeviceType || eStand1SPlusType == m_pEntity->m_eDeviceType){
  2118. ctx->Ans.Volume = m_pEntity->m_kept_volume_out[DEV_PICKUP];
  2119. }
  2120. else{
  2121. ctx->Ans.Volume = 0;
  2122. }
  2123. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("get pickup out volume is %d.", ctx->Ans.Volume);
  2124. ctx->Answer(Error_Succeed);
  2125. }
  2126. void CSIPPhoneSession::Handle_SetPickupOutVolume(SpReqAnsContext<PhoneService_SetPickupOutVolume_Req, PhoneService_SetPickupOutVolume_Ans>::Pointer ctx)
  2127. {
  2128. DbgToBeidou(ctx->link, __FUNCTION__)();
  2129. if (eStand2sType == m_pEntity->m_eDeviceType || eStand1SPlusType == m_pEntity->m_eDeviceType){
  2130. int iVolume = ctx->Req.Volume;
  2131. if (iVolume > 100) {
  2132. iVolume = 100;
  2133. }
  2134. if (iVolume < 0) {
  2135. iVolume = 0;
  2136. }
  2137. m_pEntity->SetPickupOutVolume(iVolume);
  2138. }
  2139. ctx->Answer(Error_Succeed);
  2140. }
  2141. void CSIPPhoneSession::hangup_call(HangupCallCommand* cmd)
  2142. {
  2143. if (m_pCall) {
  2144. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("normal hangup.");
  2145. endpoint_call_hangup(m_pCall);
  2146. }
  2147. }
  2148. void CSIPPhoneSession::release_call()
  2149. {
  2150. if (m_pCall){
  2151. terminatedcall(m_pCall);
  2152. }
  2153. }
  2154. void CSIPPhoneSession::on_call_state(int state, const char *state_desc, const char *phrase)
  2155. {
  2156. if (m_spCallbackContext != NULL)
  2157. {
  2158. PhoneService_PhoneState_Info Info;
  2159. Info.state = state;
  2160. Info.status = CSimpleStringA::Format("%s,%s", state_desc, phrase);
  2161. m_spCallbackContext->SendMessage(Info);
  2162. }
  2163. if (state == TERMINATED)
  2164. {
  2165. if (NULL != m_pCall){
  2166. endpoint_call_destroy(m_pCall);
  2167. m_pCall = NULL;
  2168. }
  2169. }
  2170. m_pEntity->SetState(state);
  2171. }
  2172. int CSIPPhoneSession::make_call( MakeCallCommand_t *pCmd)
  2173. {
  2174. if (m_pCall)
  2175. {
  2176. endpoint_call_destroy(m_pCall);
  2177. m_pCall = NULL;
  2178. }
  2179. {
  2180. endpoint_call_callback_t cb = {0};
  2181. cb.on_call_state = &__on_call_state;
  2182. cb.user_data = this;
  2183. endpoint_call_params_t t_callparam = {0};
  2184. t_callparam.to_uri = pCmd->toUri.GetData();
  2185. t_callparam.call_id = (pCmd->callId.GetLength() > 0) ? pCmd->callId.GetData() : NULL;
  2186. t_callparam.from_uri = (pCmd->fromUri.GetLength() > 0) ? pCmd->fromUri.GetData() : NULL;
  2187. t_callparam.local_ip = (pCmd->strlocalip.GetLength() > 0) ? pCmd->strlocalip.GetData() : NULL;
  2188. t_callparam.mapped_ip = (pCmd->strmappedip.GetLength() > 0) ? pCmd->strmappedip.GetData() : t_callparam.local_ip;
  2189. t_callparam.ilocal_audio_port = pCmd->iaudio_port;
  2190. t_callparam.ilocal_video_port = pCmd->ivideo_port;
  2191. t_callparam.imapped_audio_port = pCmd->imapped_audio_port;
  2192. t_callparam.imapped_video_port = pCmd->imapped_video_port;
  2193. t_callparam.nDeviceType = m_pEntity->m_eDeviceType;
  2194. t_callparam.nCallType = m_pEntity->m_nCallType;
  2195. m_pCall = endpoint_call_create(m_pEntity->GetEndpoint(), &t_callparam, &cb);
  2196. if (m_pCall)
  2197. {
  2198. g_IsExternalTerminalted = FALSE;
  2199. if (endpoint_call_start(m_pCall) == 0)
  2200. {
  2201. return Error_Succeed;
  2202. }
  2203. else
  2204. {
  2205. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start call failed! and endpoint destroy call.");
  2206. endpoint_call_destroy(m_pCall);
  2207. m_pCall = NULL;
  2208. return Error_Unexpect;
  2209. }
  2210. }
  2211. else
  2212. {
  2213. g_IsExternalTerminalted = TRUE;
  2214. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("g_IsExternalTerminalted = TRUE");
  2215. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create call endpoint failed!");
  2216. m_pEntity->m_SipErrorCode = Error_InvalidState;
  2217. m_pEntity->RealSelfCheck();
  2218. return Error_Unexpect;
  2219. }
  2220. }
  2221. }
  2222. void CSIPPhoneSession::control_video( ControlVideoCommand *pCmd )
  2223. {
  2224. if (m_pCall)
  2225. {
  2226. if (pCmd->start)
  2227. {
  2228. endpoint_call_param_t callparam = { 0 };
  2229. callparam.remote_ip = pCmd->remote_ip;
  2230. callparam.remote_port = pCmd->remote_port;
  2231. callparam.local_ip = pCmd->local_ip;
  2232. callparam.local_port = pCmd->local_port;
  2233. callparam.remote_width = pCmd->remote_width;
  2234. callparam.remote_height = pCmd->remote_height;
  2235. rvc_video_render_callback_t t_callback = { 0 };
  2236. t_callback.user_data = m_pEntity;
  2237. t_callback.on_remote_video_render = &__remote_video_render_callback;
  2238. t_callback.on_stop_remote_video_render = &__on_stop_remote_video_render_callback;
  2239. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d video_render_cb = 0x%08x and video_render_cb->on_video_render = 0x%08x, video_render_cb->user_data = 0x%08x.", __FUNCTION__, __LINE__, &t_callback, t_callback.on_remote_video_render, t_callback.user_data);
  2240. endpoint_call_start_video(m_pCall, &callparam, &t_callback);
  2241. if (DOUBLERECORD_CALLTYPE != m_pEntity->m_nCallType) {
  2242. rvc_video_render_params_t render_param = { 0 };
  2243. render_param.ilocal_view_x = pCmd->local_view_x;
  2244. render_param.ilocal_view_y = pCmd->local_view_y;
  2245. render_param.ilocal_view_cx = pCmd->local_view_cx;
  2246. render_param.ilocal_view_cy = pCmd->local_view_cy;
  2247. render_param.iremote_view_x = pCmd->remote_view_x;
  2248. render_param.iremote_view_y = pCmd->remote_view_y;
  2249. render_param.iremote_view_cx = pCmd->remote_view_cx;
  2250. render_param.iremote_view_cy = pCmd->remote_view_cy;
  2251. render_param.ilocal_move = pCmd->local_hwd_move;
  2252. render_param.iremote_move = pCmd->remote_hwd_move;
  2253. render_param.ilocal_fresh_time = pCmd->local_fresh_time;
  2254. render_param.iremote_fresh_time = pCmd->remote_fresh_time;
  2255. start_video_render(&render_param, false);
  2256. }
  2257. }
  2258. else {
  2259. endpoint_call_stop_video(m_pCall);
  2260. if (NULL != m_pEntity->m_render) {
  2261. stop_video_render();
  2262. }
  2263. }
  2264. }
  2265. else
  2266. {
  2267. if (pCmd->start)
  2268. {
  2269. endpoint_call_callback_t cb = {0};
  2270. cb.on_call_state = &__on_call_state;
  2271. cb.user_data = this;
  2272. endpoint_call_params_t t_callparam = {0};
  2273. t_callparam.to_uri = "test";
  2274. t_callparam.call_id = NULL;
  2275. t_callparam.from_uri = NULL;
  2276. t_callparam.local_ip = m_pEntity->m_localip;
  2277. t_callparam.nDeviceType = m_pEntity->m_eDeviceType;
  2278. t_callparam.nCallType = m_pEntity->m_nCallType;
  2279. m_pCall = endpoint_call_create(m_pEntity->GetEndpoint(), &t_callparam, &cb);
  2280. }
  2281. else {
  2282. if (NULL != m_pEntity->m_render) {
  2283. stop_video_render();
  2284. }
  2285. }
  2286. }
  2287. }
  2288. void CSIPPhoneSession::video_render(VideoRenderCommand_t* pCmd)
  2289. {
  2290. if (true== pCmd->bstart) {
  2291. rvc_video_render_params_t render_param = { 0 };
  2292. render_param.ilocal_view_x = pCmd->local_view_x;
  2293. render_param.ilocal_view_y = pCmd->local_view_y;
  2294. render_param.ilocal_view_cx = pCmd->local_view_cx;
  2295. render_param.ilocal_view_cy = pCmd->local_view_cy;
  2296. render_param.iremote_view_x = pCmd->remote_view_x;
  2297. render_param.iremote_view_y = pCmd->remote_view_y;
  2298. render_param.iremote_view_cx = pCmd->remote_view_cx;
  2299. render_param.iremote_view_cy = pCmd->remote_view_cy;
  2300. render_param.ilocal_move = pCmd->local_hwd_move;
  2301. render_param.iremote_move = pCmd->remote_hwd_move;
  2302. render_param.ilocal_fresh_time = pCmd->local_fresh_time;
  2303. render_param.iremote_fresh_time = pCmd->remote_fresh_time;
  2304. start_video_render(&render_param, true);
  2305. }
  2306. else {
  2307. stop_video_render();
  2308. }
  2309. }
  2310. int CSIPPhoneSession::start_video_render(rvc_video_render_params_t* render_param, bool bremote)
  2311. {
  2312. m_pEntity->m_render = new rvc_video_render_t();
  2313. videorender_callback_t t_callback = { 0 };
  2314. t_callback.debug = &__video_render_log;
  2315. m_pEntity->m_render->plocal_render = CreateVideoRenderObj(&t_callback);
  2316. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_LOCAL_VIDEO_RENDER_CREATE, "local video render create.");
  2317. m_pEntity->m_render->premote_render = CreateVideoRenderObj(&t_callback);
  2318. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_REMOTE_VIDEO_RENDER_CREATE, "remote video render create.");
  2319. memcpy(&m_pEntity->m_render->location_param, render_param, sizeof(rvc_video_render_params_t));
  2320. m_pEntity->m_render->ui_threadid = 0;
  2321. m_pEntity->m_render->remote_render_threadid = 0;
  2322. rvc_video_box_move_callback_t t_render_callback = { 0 };
  2323. t_render_callback.on_video_box_move = &__on_video_box_move;
  2324. t_render_callback.user_data = this;
  2325. rvc_video_render_window_type_callback_t t_window_type_callback = { 0 };
  2326. t_window_type_callback.on_window_type = &__on_window_type_callback;
  2327. t_window_type_callback.user_data = this->m_pEntity;
  2328. memcpy(&m_pEntity->m_render->cb, &t_window_type_callback, sizeof(rvc_video_render_window_type_callback_t));
  2329. m_pEntity->m_stVideoParam.bShowPersonArea = 0;
  2330. if (Error_Succeed == rvc_start_video_render(m_pEntity->m_render, bremote, &t_render_callback)) {
  2331. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start video render success.");
  2332. }
  2333. return 0;
  2334. }
  2335. int CSIPPhoneSession::stop_video_render()
  2336. {
  2337. if (Error_Succeed == rvc_stop_video_render(m_pEntity->m_render)) {
  2338. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop video render success.");
  2339. }
  2340. DestroyVideoRenderObj(m_pEntity->m_render->plocal_render);
  2341. DestroyVideoRenderObj(m_pEntity->m_render->premote_render);
  2342. delete(m_pEntity->m_render);
  2343. m_pEntity->m_render = NULL;
  2344. return 0;
  2345. }
  2346. int CSIPPhoneSession::on_video_box_move(int imessageType, int ivideotype, int ileft, int ibottom)
  2347. {
  2348. int iret = -1;
  2349. if (0 == imessageType){
  2350. VideoBoxStartMove evt;
  2351. evt.videoboxflag = ivideotype;
  2352. evt.leftlowerx = ileft;
  2353. evt.leftlowery = ibottom;
  2354. iret = SpSendBroadcast(m_pEntity->GetFunction(), SP_MSG_OF(VideoBoxStartMove), SP_MSG_SIG_OF(VideoBoxStartMove), evt);
  2355. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("VideoBoxStartMove broadcast sent, video type is %d, left is %d, bottom is %d.", ivideotype, ileft, ibottom);
  2356. }
  2357. else{
  2358. VideoBoxStopMove evt;
  2359. evt.videoboxflag = ivideotype;
  2360. evt.leftlowerx = ileft;
  2361. evt.leftlowery = ibottom;
  2362. iret = SpSendBroadcast(m_pEntity->GetFunction(), SP_MSG_OF(VideoBoxStopMove), SP_MSG_SIG_OF(VideoBoxStopMove), evt);
  2363. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("VideoBoxStopMove broadcast sent, video type is %d, left is %d, bottom is %d.", ivideotype, ileft, ibottom);
  2364. }
  2365. return iret;
  2366. }
  2367. ChannelSipphoneClient::ChannelSipphoneClient( CSIPEntity *pEntity ) : ChannelService_ClientBase(pEntity)
  2368. {
  2369. }
  2370. void ChannelSipphoneClient::OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData)
  2371. {
  2372. if (Error == Error_Succeed)
  2373. {
  2374. CSIPEntity *pEntity = static_cast<CSIPEntity*>(m_pEntityBase);
  2375. if (Msg.state == eChannelState_Connected)
  2376. {
  2377. #ifdef RVC_OS_WIN
  2378. if (pEntity->m_pKeeperIn[DEV_HANDFREE])
  2379. #else
  2380. if (pEntity->m_pAudioMgr)
  2381. #endif
  2382. {
  2383. pEntity->SendAudioDeviceVolumn(DEVICE_HANDFREE_IN);
  2384. }
  2385. #ifdef RVC_OS_WIN
  2386. if (pEntity->m_pKeeperOut[DEV_HANDFREE])
  2387. #else
  2388. if (pEntity->m_pAudioMgr)
  2389. #endif
  2390. {
  2391. pEntity->SendAudioDeviceVolumn(DEVICE_HANDFREE_OUT);
  2392. }
  2393. #ifdef RVC_OS_WIN
  2394. if (pEntity->m_pKeeperOut[DEV_PICKUP])
  2395. #else
  2396. if (pEntity->m_pAudioMgr)
  2397. #endif
  2398. {
  2399. pEntity->SendAudioDeviceVolumn(DEVICE_PICKUP_OUT);
  2400. }
  2401. #ifdef RVC_OS_WIN
  2402. if (pEntity->m_pKeeperIn[DEV_PICKUP])
  2403. #else
  2404. if (pEntity->m_pAudioMgr)
  2405. #endif
  2406. {
  2407. pEntity->SendAudioDeviceVolumn(DEVICE_PICKUP_IN);
  2408. }
  2409. }
  2410. }
  2411. }
  2412. void ChannelSipphoneClient::OnMessage( ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData )
  2413. {
  2414. if (Error == Error_Succeed)
  2415. {
  2416. CSIPEntity *pEntity = static_cast<CSIPEntity*>(m_pEntityBase);
  2417. pEntity->OnReceivePkt(Msg.type,Msg.sub_type, (const char*)Msg.data.m_pData, Msg.data.m_iLength);
  2418. }
  2419. }
  2420. SP_BEGIN_ENTITY_MAP()
  2421. SP_ENTITY(CSIPEntity)
  2422. SP_END_ENTITY_MAP()