mod_sipphone.cpp 74 KB

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