12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588 |
- #include "stdafx.h"
- #include "pthread.h"
- #include "endpoint.h"
- #include "mod_sipphone.h"
- #include "../mod_agentip/sysvar.h"
- #include "../mod_facetracking/sysvar.h"
- #include "sockutil.h"
- #include "rec_common.h"
- #include "audio_session.h"
- #include "video_session.h"
- //#include "volumekeeper.h"
- #define EVT_CONVERTER "EventConverter"
- #define DEVICE_HANDFREE_OUT 0
- #define DEVICE_PICKUP_OUT 1
- #define DEVICE_HANDFREE_IN 2
- #define DEVICE_PICKUP_IN 3
- #ifndef DEFAULT_RECORD_VIDEO_WIDTH
- #define DEFAULT_RECORD_VIDEO_WIDTH 1056
- #endif
- #ifndef DEFAULT_RECORD_VIDEO_HEIGHT
- #define DEFAULT_RECORD_VIDEO_HEIGHT 595
- #endif
- #ifndef SMALL_RECORD_VIDEO_WIDTH
- #define SMALL_RECORD_VIDEO_WIDTH 244
- #endif
- #ifndef SMALL_RECORD_VIDEO_HEIGHT
- #define SMALL_RECORD_VIDEO_HEIGHT 138
- #endif
- #ifndef RVC_VIDEO_FRESH_TIME
- #define RVC_VIDEO_FRESH_TIME 50
- #endif // !RVC_VIDEO_FRESH_TIME
- #ifndef RVC_MAX_VIDEO_FRESH_TIME
- #define RVC_MAX_VIDEO_FRESH_TIME 200
- #endif // !RVC_MAX_VIDEO_FRESH_TIME
- #ifndef RVC_MIN_VIDEO_FRESH_TIME
- #define RVC_MIN_VIDEO_FRESH_TIME 1
- #endif // !RVC_MAX_VIDEO_FRESH_TIME
- /////////////////////////////////////////////
- // future roadmap
- // 1. 使用session timer
- // 2. 增强稳定性
- // 3. 健康检查里面触发 主备服务器切换(switch between freeswitchs) 定时发送options ping switch server
- /////////////////////////////////////////////
- extern BOOL g_IsExternalTerminalted;
- extern BOOL g_bIsSalesRecord;
- extern BOOL g_bEwsRecord;
- static void __on_video_box_move(int imessagetype, int ivideotype, int ileft, int ibottom, void *user_data)
- {
- CSIPPhoneSession *pThis = static_cast<CSIPPhoneSession*>(user_data);
- pThis->on_video_box_move(imessagetype, ivideotype, ileft, ibottom);
- }
- CSIPPhoneSession::CSIPPhoneSession(CSIPEntity *pEntity) : m_pEntity(pEntity), m_pCall(NULL), m_iLastState(0),m_IsLocalPlay(0),m_VideoWindowPlayType(eOnline_Mode_Video)
- {
- m_cb_video_box_move.on_video_box_move = &__on_video_box_move;
- m_cb_video_box_move.user_data = this;
- }
- static void __on_call_state(int state, const char *state_desc, const char *phrase, void *user_data)
- {
- CSIPPhoneSession *pThis = static_cast<CSIPPhoneSession*>(user_data);
- if (pThis->m_iLastState != state) {
- pThis->m_iLastState = state;
- pThis->on_call_state(state, state_desc, phrase);
- }
- }
- static int __make_call(void *user_data)
- {
- MakeCallCommand *cmd = (MakeCallCommand*)user_data;
- int rc = cmd->pSIPPhoneSession->make_call(cmd->strUri);
- delete cmd;
- return rc;
- }
- static int __hangup_call(void *user_data)
- {
- HangupCallCommand *cmd = (HangupCallCommand*)(user_data);
- cmd->pSIPPhoneSession->hangup_call(/*cmd*/);
- delete cmd;
- return 0;
- }
- static int __control_video(void *arg)
- {
- ControlVideoCommand *pCmd = (ControlVideoCommand*)(arg);
- pCmd->pSIPPhoneSession->control_video(pCmd);
- delete pCmd;
- return 0;
- }
- static int __release_call(void *user_data)
- {
- CSIPPhoneSession *pThis = static_cast<CSIPPhoneSession*>(user_data);
- pThis->release_call();
- pThis->on_call_state(TERMINATED,"STATE:terminated","byebye");
- return 0;
- }
- CSIPEntity::CSIPEntity() : m_pCurrentSession(NULL), m_state(INIT),m_iPickupPhoneState(ePickupMicrophoneState_Off)
- {
- m_kept_volume_in[0] = m_kept_volume_in[1] = 0;
- m_kept_volume_out[0] = m_kept_volume_out[1] = 0;
- #ifdef RVC_OS_WIN
- m_pKeeperIn[0] = m_pKeeperIn[1] = NULL;
- m_pKeeperOut[0] = m_pKeeperOut[1] = NULL;
- #endif
- m_SipErrorCode = Error_Succeed;
- memset((void*)&m_stVideoParam,0,sizeof(stVideoParam));
- m_ilocalvideo_freshtime = RVC_VIDEO_FRESH_TIME;
- m_iremotevideo_freshtime = RVC_VIDEO_FRESH_TIME;
- }
- void CSIPEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
- const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
- const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage)
- {
- LOG_TRACE("user_code = 0x%08x", dwUserCode);
- switch (dwUserCode)
- {
- case LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE:
- {
- Dbg("recv LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE");
- if (m_pSipphoneChannel != NULL)
- {
- m_pSipphoneChannel->GetFunction()->CloseSession();
- m_pSipphoneChannel = NULL;
- Dbg("Close AssistChannel Session ");
- }
-
- ErrorCodeEnum Error;
- if (m_pSipphoneChannel == NULL)
- {
- Dbg("ReConnection AssistChannel Session");
- m_pSipphoneChannel = new ChannelSipphoneClient(this);
- Error = m_pSipphoneChannel->Connect();
- if (Error != Error_Succeed)
- {
- m_pSipphoneChannel->SafeDelete();
- Dbg("ChannelSipphoneClient connect fail!");
- }
- if (Error == Error_Succeed)
- {
- ChannelService_BeginState_Sub Sub;
- Error = m_pSipphoneChannel->BeginState(Sub);
- if (Error != Error_Succeed)
- {
- LOG_TRACE("BeginState biz channel failed!");
- m_pSipphoneChannel->GetFunction()->CloseSession();
- m_pSipphoneChannel = NULL;
- }
- }
- if (Error == Error_Succeed)
- {
- ChannelService_BeginRecv_Sub Sub;
- Sub.type = ACM_TYPE_DEVICE;
- Error = m_pSipphoneChannel->BeginRecv(Sub);
- if (Error != Error_Succeed)
- {
- Dbg("Begin BeginRecv ACM_TYPE_DEVICE failed!");
- m_pSipphoneChannel->GetFunction()->CloseSession();
- m_pSipphoneChannel = NULL;
- }
- }
- }
- }
- break;
- case EVENT_MOD_CONNECT_HANDFREE_TO_PICKUP:
- case EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP:
- case EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE:
- case EVENT_MOD_CONNECT_PICKUP_TO_HANDFREE:
- case EVENT_MOD_CONNECT_PICKUP_CALL:
- case EVENT_MOD_CONNECT_SLV_HANDFREECALL:
- case EVENT_MOD_CONNECT_SLV_PICKUPCALL:
- case LOG_EVT_HANDFREE_MODE_REMOTE_CALL:
- case LOG_EVT_PICKUP_MODE_REMOTE_CALL:
- {
- int old_state = m_iPickupPhoneState;
- if (dwUserCode == EVENT_MOD_CONNECT_HANDFREE_TO_PICKUP) { // 免提->提机
- m_iPickupPhoneState = ePickupMicrophoneState_On;
- }
- else if (dwUserCode == EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP) { //坐席控制免提->提机
- m_iPickupPhoneState = ePickupMicrophoneState_On;
- }
- else if (dwUserCode == EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE) { //坐席控制提机->免提
- m_iPickupPhoneState = ePickupMicrophoneState_Off;
- }
- else if (dwUserCode == EVENT_MOD_CONNECT_PICKUP_TO_HANDFREE)
- { // // 提机->免提
- m_iPickupPhoneState = ePickupMicrophoneState_Off;
- }
- else if (dwUserCode == EVENT_MOD_CONNECT_PICKUP_CALL)
- { // 提机拨号
- m_iPickupPhoneState = ePickupMicrophoneState_On;
- }
- else if (dwUserCode == EVENT_MOD_CONNECT_SLV_HANDFREECALL)
- { // 免提拨号
- m_iPickupPhoneState = ePickupMicrophoneState_Off;
- }
- else if (dwUserCode == EVENT_MOD_CONNECT_SLV_PICKUPCALL)
- {
- // 通过界面拨号,但话筒未挂,进入提机拨号
- m_iPickupPhoneState = ePickupMicrophoneState_On;
- }
- else if (dwUserCode == LOG_EVT_HANDFREE_MODE_REMOTE_CALL)
- { // 免提模式开始远程双录连线
- m_iPickupPhoneState = ePickupMicrophoneState_Off;
- }
- else if (dwUserCode == LOG_EVT_PICKUP_MODE_REMOTE_CALL)
- {
- // 话筒模式开始远程双录连线
- m_iPickupPhoneState = ePickupMicrophoneState_On;
- }
- LOG_TRACE("dwUserCode = 0x%08x,m_iPickupPhoneState %d.", dwUserCode, m_iPickupPhoneState);
- Dbg("dwUserCode = 0x%08x,old_PhoneState = %d,PickupPhoneState = %d", dwUserCode,old_state, m_iPickupPhoneState);
- if (old_state != m_iPickupPhoneState)
- {
- if (m_iPickupPhoneState == ePickupMicrophoneState_On)
- {
- SwitchPickup();
- }
- else
- {
- SwitchHandFree();
- }
- }
- }
- break;
- case LOG_EVT_ENTER_ACM_FLOW:
- {
- Dbg("LOG_EVT_ENTER_ACM_FLOW");
- m_stVideoParam.nWindowState = 1;
- }
- break;
-
- case LOG_EVT_EXIT_ACM_FLOW:
- {
- Dbg("LOG_EVT_EXIT_ACM_FLOW");
- if(m_stVideoParam.nWindowState == 1)
- {
- m_stVideoParam.nWindowState = 0;
- }
- }
- break;
- case LOG_EVT_STARTLIVEDETECTDISPLAY:
- {
- Dbg("start livedetection display");
- m_stVideoParam.bActiveInspect = 1;
- }
- break;
- case LOG_EVT_STOPLIVEDETECTDISPLAY:
- {
- Dbg("stop livedetection display and show livedetection photo %s",pszMessage);
- }
- break;
- case LOG_EVT_CHANGELIVEDETECTIONCAM:
- {
- if (pszMessage && strlen(pszMessage) > 0)
- {
- int i = atoi(pszMessage);
- Dbg("change active display camera to %d",i);
- m_stVideoParam.iCameraSwitch = i;
- }
- else
- {
- Dbg("change active display camera param error");
- }
- }
- break;
-
- case LOG_EVT_RELEASELIVEDETECTION:
- {
- Dbg("release show active image");
- m_stVideoParam.bActiveInspect = 0;
- m_stVideoParam.bShowActiveImg = 0;
- m_stVideoParam.iCameraSwitch = CAMERA_TYPE_ENV;
- }
- break;
- case LOG_EVT_UI_HIDEONLINEVIDEO:
- {
- Dbg("Receive UI hide online video evt!");
- m_stVideoParam.nWindowState = 2;
- }
- break;
- case LOG_EVT_UI_SHOWONLINEVIDEO:
- {
- Dbg("Receive UI show online video evt!");
- if (m_stVideoParam.nWindowState == 2)
- {
- m_stVideoParam.nWindowState = 3;
- }
- }
- break;
- case LOG_EVT_UI_STARTRECORD:
- case LOG_EVT_UI_STARTREMOTERECORD:
- {
- Dbg("start sales record video.");
- m_bIsSalesRecord = TRUE;
- g_bIsSalesRecord = m_bIsSalesRecord;
- m_bEwsRecord = FALSE;
- if (strlen(pszMessage)>=4&&!strnicmp(pszMessage,"ews|",4)){
- m_bEwsRecord = TRUE;
- }
- g_bEwsRecord = m_bEwsRecord;
- }
- break;
- case LOG_EVT_UI_STARTRECORDPREVIEW:
- {
- Dbg("start sales record preview.");
- m_stVideoParam.bShowRecordArea = 1;
- Handle_RecordVideoLocation_Info(pszMessage);
- }
- break;
- case LOG_EVT_UI_STOPRECORD:
- case LOG_EVT_UI_STOPREMOTERECORD:
- {
- Dbg("stop sales record video.");
- m_bIsSalesRecord = FALSE;
- g_bIsSalesRecord = m_bIsSalesRecord;
- m_bEwsRecord = FALSE; //add by ly@2019/04/18
- g_bEwsRecord = m_bEwsRecord; //add by ly@2019/04/18
- if (m_stVideoParam.bShowRecordArea){
- Dbg("stop sales record and stop preview.");
- m_stVideoParam.bShowRecordArea = 0;
- }
- }
- break;
- case LOG_EVT_UI_STOPRECORDPREVIEW:
- {
- Dbg("stop sales record preview.");
- m_stVideoParam.bShowRecordArea = 0;
- }
- break;
- case LOG_EVT_UI_RETURNMENU:
- {
- Dbg("return menu");
- m_bIsSalesRecord = FALSE;
- g_bIsSalesRecord = m_bIsSalesRecord;
- m_bEwsRecord = FALSE; //add by ly@2019/04/18
- g_bEwsRecord = m_bEwsRecord; //add by ly@2019/04/18
- }
- break;
- case LOG_EVT_UI_SHOWLOCALVIDEO:
- {
- Dbg("Receive UI show all video evt!");
- if (m_stVideoParam.nWindowState == 4)
- {
- m_stVideoParam.nWindowState = 3;
- }
- }
- break;
- case LOG_EVT_UI_HIDELOCALVIDEO:
- {
- Dbg("Receive UI hide local video evt!");
- m_stVideoParam.nWindowState = 4;
- }
- break;
- case LOG_EVT_UI_HIDEPERSONAREA:
- {
- Dbg("Receive UI hide person area!");
- m_stVideoParam.bShowPersonArea = 0;
- }
- break;
- case LOG_EVT_UI_SHOWPERSONAREA:
- {
- Dbg("Receive UI show person area!");
- m_stVideoParam.bShowPersonArea = 1;
- }
- break;
- case EVENT_MOD_CONNECT_STOP_RECORD_BROADCAST:
- {
- Dbg("stop remote record audio broadcast.");
- }
- break;
- case EVENT_MOD_CONNECT_BEGAIN_RECORD_CALL:
- {
- Dbg("begin double record call.");
- }
- break;
- case LOG_EVT_UI_ADJUSTVIDEOECHOSIZE:
- {
- Dbg("adjust video echo size %s.", pszMessage);
- Handle_AdjustVideoEchoEvent(pszMessage);
- }
- break;
- default:
- {
- Dbg("unknown dwUserCode = 0x%08x.",dwUserCode);
- }
- break;
- }
- }
- void CSIPEntity::OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName)
- {
- if (_stricmp(pszKey, SYSVAR_CAMERASTATE) == 0)
- {
- Dbg("camera state from : %c to %c", pszOldValue[0], pszValue[0]);
- if (pszValue[0] == 'E')
- {
- m_stVideoParam.iCameraState = CAMERA_TYPE_OPT;
- }
- else if (pszValue[0] == 'O')
- {
- m_stVideoParam.iCameraState = CAMERA_TYPE_ENV;
- }
- else if(pszValue[0] == 'B') ///////显示贴图
- {
- /////////////////////////此处显示贴图//////////////////////////////////
- //m_stVideoParam.iCameraSwitch = CAMERA_TYPE_ERROR;
- m_stVideoParam.iCameraState = CAMERA_TYPE_ERROR;
- }
- else if (pszValue[0] == 'N')
- {
- m_stVideoParam.iCameraState = CAMERA_TYPE_AUTO;
- //m_stVideoParam.iCameraSwitch = CAMERA_TYPE_AUTO;
- }
- }
- else if (_stricmp(pszKey, SYSVAR_ACTIVETRACKINGCAMERA) == 0)
- {
- Dbg("active camera from : %c to %c", pszOldValue[0], pszValue[0]);
- if (pszValue[0] == 'E')
- {
- m_stVideoParam.iActiveCamera = CAMERA_TYPE_ENV;
- }
- else if (pszValue[0] == 'O')
- {
- m_stVideoParam.iActiveCamera = CAMERA_TYPE_OPT;
- }
- else
- {
- Dbg("warning: unknown ActiveTrackingCamera value!");
- }
- }
- else if (_stricmp(pszKey, SYSVAR_AGENTCAMERASWITCH) == 0)
- {
- Dbg("agent camera switch from : %c to %c", pszOldValue[0], pszValue[0]);
- if((pszValue[0] == 'E')/*&&((m_iCameraState==CAMERA_TYPE_AUTO)||(m_iCameraState==CAMERA_TYPE_ENV))*/)
- {
- m_stVideoParam.iCameraSwitch = CAMERA_TYPE_ENV;
- }
- else if((pszValue[0] == 'O')/*&&((m_iCameraState==CAMERA_TYPE_AUTO)||(m_iCameraState==CAMERA_TYPE_OPT))*/)
- {
- m_stVideoParam.iCameraSwitch = CAMERA_TYPE_OPT;
- }
- else if((pszValue[0] == 'A')/*&&(m_iCameraState==CAMERA_TYPE_AUTO)*/)
- {
- m_stVideoParam.iCameraSwitch = CAMERA_TYPE_AUTO;
- }
- }
- else if (_stricmp(pszKey, SYSVAR_CALLTYPE) == 0)
- {
- Dbg("sys calltype from: %c to %c", pszOldValue[0], pszValue[0]);
- if(pszValue[0] == CALLTYPE_NORMAL)
- {
- m_nSysCallType = 0;
- }
- else if(pszValue[0] == CALLTYPE_MOBILE)
- {
- m_nSysCallType = 1;
- }
- else
- {
- m_nSysCallType =-1;
- }
- }
- }
- void CSIPEntity::OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- if (Test_ShakeHand == eTestType)
- {
- pTransactionContext->SendAnswer(m_SipErrorCode);
- }
- }
- void CSIPEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- ErrorCodeEnum Error = __OnStart(Error_Succeed);
- pTransactionContext->SendAnswer(Error);
- }
- void CSIPEntity::OnStarted()
- {
- LogWarn(Severity_Middle, Error_Debug, EVENT_MOD_SIP_ENTITY_STARTED, "sipphone entity started.");
- ErrorCodeEnum Error = Error_Succeed;
- m_pSelfcheckClient = new SelfChekerClient(this);
- Error = m_pSelfcheckClient->Connect();
- if (Error != Error_Succeed)
- {
- m_pSelfcheckClient->SafeDelete();
- m_pSelfcheckClient = NULL;
- Dbg("SelfcheckClient connect fail!");
- }
- else
- {
- Dbg("SelfcheckClient connect success!");
- }
- }
- static void __audiomgrlog(void* user_data, const char* fmt, va_list arg)
- {
- vDbg(fmt, arg);
- }
- ErrorCodeEnum CSIPEntity::__OnStart(ErrorCodeEnum preOperationError)
- {
- ErrorCodeEnum Error;
- //MessageBoxA(0,0,0,0);
- m_nCallType = NORMAL_CALLTYPE;
- m_nSysCallType = 0;
- m_pSipphoneChannel = new ChannelSipphoneClient(this);
- memset(m_localip,0,256);
- Error = m_pSipphoneChannel->Connect();
- if (Error != Error_Succeed)
- {
- m_pSipphoneChannel->SafeDelete();
- Dbg("ChannelSipphoneClient connect fail!");
- return Error;
- }
- {
- ChannelService_BeginState_Sub Sub;
- Error = m_pSipphoneChannel->BeginState(Sub);
- if (Error != Error_Succeed)
- {
- LOG_TRACE("BeginState biz channel failed!");
- m_pSipphoneChannel->GetFunction()->CloseSession();
- m_pSipphoneChannel = NULL;
- return Error;
- }
- }
- {
- ChannelService_BeginRecv_Sub Sub;
- Sub.type = ACM_TYPE_DEVICE;
- Error = m_pSipphoneChannel->BeginRecv(Sub);
- if (Error != Error_Succeed)
- {
- Dbg("Begin BeginRecv ACM_TYPE_DEVICE failed!");
- m_pSipphoneChannel->GetFunction()->CloseSession();
- m_pSipphoneChannel = NULL;
- return Error;
- }
- }
- {
- ChannelService_BeginRecv_Sub Sub;
- Sub.type = ACM_TYPE_VIDEOFREQ;
- Error = m_pSipphoneChannel->BeginRecv(Sub);
- if (Error != Error_Succeed)
- {
- Dbg("Begin BeginRecv ACM_TYPE_VIDEOFREQ failed!");
- m_pSipphoneChannel->GetFunction()->CloseSession();
- m_pSipphoneChannel = NULL;
- return Error;
- }
- }
- {
- m_pSelfcheckClient = new SelfChekerClient(this);
- Error = m_pSelfcheckClient->Connect();
- if (Error != Error_Succeed)
- {
- m_pSelfcheckClient->SafeDelete();
- m_pSelfcheckClient = NULL;
- Dbg("SelfcheckClient connect fail!");
- }
- else
- {
- Dbg("SelfcheckClient connect success!");
- }
- }
- #ifdef RVC_OS_LINUX
- {
- audiomgr_callback_t t_callback = { 0 };
- t_callback.debug = &__audiomgrlog;
- m_pAudioMgr = CreateAudioMgrObj(&t_callback);
- if (0 == m_pAudioMgr->audio_mgr_initialize()) {
- Dbg("Audio Manager Initialize success!");
- }
- else {
- Dbg("Audio Manager Initialize failed!");
- return Error_Param;
- }
- }
- #endif
- m_eDeviceType = RvcGetDeviceType();
- m_stVideoParam.bActiveInspect = 0;
- m_stVideoParam.bShowActiveImg = 0;
- m_bIsSalesRecord = FALSE;
- g_bIsSalesRecord = m_bIsSalesRecord;
- m_bEwsRecord = FALSE;
- g_bEwsRecord = m_bEwsRecord;
- m_stVideoParam.nWindowState = 0;
- m_RecordVideoLocation.x = 0;
- m_RecordVideoLocation.y = 0;
- m_RecordVideoLocation.width = DEFAULT_RECORD_VIDEO_WIDTH;
- m_RecordVideoLocation.height = DEFAULT_RECORD_VIDEO_HEIGHT;
- video_lib_init();
- audio_lib_init();
- endpoint_init_lib();
- Error = GetLocalIP();
- if (Error != 0)
- {
- LOG_TRACE("get local ip failed!");
- CSimpleStringA strErrMsg = "获取本地 IP 地址失败,请检查本地网络是否连接!";
- LogWarn(Severity_Middle, Error_NetBroken, 0, strErrMsg);
- return Error;
- }
- #ifdef RVC_OS_LINUX
- RvcGetAudioDeviceInfo();
- #endif
- Error = LoadConfig(&conf);
- if (Error != Error_Succeed)
- {
- LOG_TRACE("load config failed!");
- return Error;
- }
- int nhandfreeout = 0;
- int npickupout = 0;
- int nhanfreein = 0;
- int npickupin = 0;
- Error = LoadAudioRunConfig(nhandfreeout,npickupout,nhanfreein,npickupin);
- if (Error == Error_Succeed)
- {
- if (nhandfreeout > 0)
- {
- m_kept_volume_out[DEV_HANDFREE] = nhandfreeout;
- }
- if (npickupout > 0)
- {
- m_kept_volume_out[DEV_PICKUP] = npickupout;
- }
- if (nhanfreein > 0)
- {
- m_kept_volume_in[DEV_HANDFREE] = nhanfreein;
- }
- if (npickupin > 0)
- {
- m_kept_volume_in[DEV_PICKUP] = npickupin;
- }
- }
- #ifdef RVC_OS_LINUX
- RvcSetSaveAudioVolume();
- #endif
-
- {
- CSmartPointer<IEntityFunction> Func = GetFunction();
- Func->GetSystemStaticInfo(staticInfo);
- }
- CSimpleStringA strUri = MakeUri(staticInfo.strTerminalID);
- if (strUri.GetLength() > 0)
- {
- strcpy(conf.uri, strUri);
- conf.media_start_port = REC_COMMON_AUDIO_PORT_START;
- conf.media_stop_port = REC_COMMON_AUDIO_PORT_STOP;
- m_pEndpoint = endpoint_create(this, &conf,DEV_HANDFREE);
- if (!m_pEndpoint) {
- LOG_TRACE("create endpoint failed!");
- return Error_Unexpect;
- }
- else{
- Dbg("%s:%d call uri is %s, endpoint_create m_pEndpoint addr is 0x%08x.", __FUNCTION__, __LINE__, conf.uri, m_pEndpoint);
- }
- }
- else
- {
- LOG_TRACE("strUri length equals zero!");
- return Error_Unexpect;
- }
- {
- CSmartPointer<IEntityFunction> Func = GetFunction();
- CUUID id;
- int i = 0;
- m_arrListener.Init(32);
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANDFREE_TO_PICKUP, EVT_CONVERTER);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_PICKUP_TO_HANDFREE, EVT_CONVERTER);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_PICKUP_CALL, EVT_CONVERTER);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_SLV_HANDFREECALL,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_SLV_PICKUPCALL,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_ENTER_ACM_FLOW,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_EXIT_ACM_FLOW,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_STARTLIVEDETECTDISPLAY,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_STOPLIVEDETECTDISPLAY,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_CHANGELIVEDETECTIONCAM,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_RELEASELIVEDETECTION,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_HIDEONLINEVIDEO,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_SHOWONLINEVIDEO,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORD,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPRECORD,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RETURNMENU,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_HIDELOCALVIDEO,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_SHOWLOCALVIDEO,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_HIDEPERSONAREA,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_SHOWPERSONAREA,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_STOP_RECORD_BROADCAST,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_BEGAIN_RECORD_CALL,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTREMOTERECORD,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPREMOTERECORD,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_HANDFREE_MODE_REMOTE_CALL,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_PICKUP_MODE_REMOTE_CALL,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORDPREVIEW,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPRECORDPREVIEW,NULL,false);
- m_arrListener[i++] = id;
- Func->SubscribeLog(id, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_ADJUSTVIDEOECHOSIZE,NULL,false);
- m_arrListener[i++] = id;
- }
- {
- CSmartPointer<IEntityFunction> Func = GetFunction();
- CSimpleStringA strValue;
- Func->RegistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA, this);
- Func->GetSysVar(SYSVAR_ACTIVETRACKINGCAMERA, strValue);
- if (strValue[0] == 'E')
- {
- m_stVideoParam.iActiveCamera = CAMERA_TYPE_ENV;
- }
- else if (strValue[0] == 'O')
- {
- m_stVideoParam.iActiveCamera = CAMERA_TYPE_OPT;
- }
- else
- {
- assert(0);
- }
- }
- {
- CSmartPointer<IEntityFunction> Func = GetFunction();
- CSimpleStringA strValue;
- Func->RegistSysVarEvent(SYSVAR_CAMERASTATE, this);
- Func->GetSysVar(SYSVAR_CAMERASTATE, strValue);
- if (strValue[0] == 'E')
- {
- m_stVideoParam.iCameraState = CAMERA_TYPE_OPT;
- }
- else if (strValue[0] == 'O')
- {
- m_stVideoParam.iCameraState = CAMERA_TYPE_ENV;
- }
- else if(strValue[0] == 'B') ///////显示贴图
- {
- /////////////////////////此处显示贴图//////////////////////////////////
- //m_stVideoParam.iCameraSwitch = CAMERA_TYPE_ERROR;
- m_stVideoParam.iCameraState = CAMERA_TYPE_ERROR;
- }
- else if (strValue[0] == 'N')
- {
- //m_stVideoParam.iCameraSwitch = CAMERA_TYPE_AUTO;
- m_stVideoParam.iCameraState = CAMERA_TYPE_AUTO;
- }
- }
- {
- CSmartPointer<IEntityFunction> Func = GetFunction();
- CSimpleStringA strValue;
- Func->RegistSysVarEvent(SYSVAR_AGENTCAMERASWITCH, this);
- Func->GetSysVar(SYSVAR_AGENTCAMERASWITCH, strValue);
- if((strValue[0] == 'E')/*&&((m_iCameraState == CAMERA_TYPE_AUTO)||(m_iCameraState = CAMERA_TYPE_ENV))*/)
- {
- m_stVideoParam.iCameraSwitch = CAMERA_TYPE_ENV;
- }
- else if((strValue[0] == 'O')/*&&((m_iCameraState == CAMERA_TYPE_AUTO)||(m_iCameraState = CAMERA_TYPE_OPT))*/)
- {
- m_stVideoParam.iCameraSwitch = CAMERA_TYPE_OPT;
- }
- else if ((strValue[0] == 'A')/*&&(m_iCameraState == CAMERA_TYPE_AUTO)*/)
- {
- m_stVideoParam.iCameraSwitch = CAMERA_TYPE_AUTO;
- }
- }
- {
- CSmartPointer<IEntityFunction> Func = GetFunction();
- CSimpleStringA strValue;
- Func->RegistSysVarEvent(SYSVAR_CALLTYPE, this);
- Func->GetSysVar(SYSVAR_CALLTYPE, strValue);
- if (strValue[0] == CALLTYPE_NORMAL)
- {
- m_nSysCallType = 0;
- }
- else if (strValue[0] == CALLTYPE_MOBILE)
- {
- m_nSysCallType = 1;
- }
- else
- {
- assert(0);
- }
- }
- #ifdef RVC_OS_WIN
- if (m_kept_volume_in[DEV_HANDFREE])
- {
- m_pKeeperIn[DEV_HANDFREE] = volume_keeper_create(conf.audio_handfree_in_dev, 1, m_kept_volume_in[DEV_HANDFREE]);
- if (m_pKeeperIn[DEV_HANDFREE])
- {
- Dbg("HANDFREE in volume keeper create ok! %d", m_kept_volume_in[DEV_HANDFREE]);
- }
- else
- {
- Dbg("HANDFREE in volume keeper create failed!");
- }
- }
-
- if (m_kept_volume_out[DEV_HANDFREE])
- {
- m_pKeeperOut[DEV_HANDFREE] = volume_keeper_create(conf.audio_handfree_out_dev, 0, m_kept_volume_out[DEV_HANDFREE]);
- if (m_pKeeperOut[DEV_HANDFREE])
- {
- Dbg("HANDFREE out volume keeper create ok! %d", m_kept_volume_out[DEV_HANDFREE]);
- }
- else
- {
- Dbg("HANDFREE out volume keeper create failed!");
- }
- }
- if (m_kept_volume_in[DEV_PICKUP]&&(eStand2sType == m_eDeviceType)) //pad版屏蔽pickup
- {
- m_pKeeperIn[DEV_PICKUP] = volume_keeper_create(conf.audio_pickup_in_dev, 1, m_kept_volume_in[DEV_PICKUP]);
- if (m_pKeeperIn[DEV_PICKUP])
- {
- Dbg("PICKUP in volume keeper create ok! %d", m_kept_volume_in[DEV_PICKUP]);
- }
- else
- {
- Dbg("PICKUP in volume keeper create failed!");
- }
- }
- if (m_kept_volume_out[DEV_PICKUP]&&(eStand2sType == m_eDeviceType)) //pad版屏蔽pickup
- {
- m_pKeeperOut[DEV_PICKUP] = volume_keeper_create(conf.audio_pickup_out_dev, 0, m_kept_volume_out[DEV_PICKUP]);
- if (m_pKeeperOut[DEV_PICKUP])
- {
- Dbg("PICKUP out volume keeper create ok! %d", m_kept_volume_out[DEV_PICKUP]);
- }
- else
- {
- Dbg("PICKUP out volume keeper create failed!");
- }
- }
- #else
- #endif // RVC_OS_WIN
- return Error_Succeed;
- }
-
- video_session_t *video_session;
- void CSIPEntity::OnReceivePkt(int type, int sub_type, const char *buffer, int size)
- {
- if (type == ACM_TYPE_DEVICE)
- {
- if (sub_type == ACM_SET_HANDFREE_OUTVOLUMN)
- {
- CVolumnValue num;
- SpBuffer buf;
- buf.OpenRead(buffer,size);
- num.Serialize(buf);
- Dbg("recv adj handfree out volumn = %d",num.nValue);
- #ifdef RVC_OS_WIN
- if (m_pKeeperOut[DEV_HANDFREE])
- {
- volume_keeper_change(m_pKeeperOut[DEV_HANDFREE], num.nValue);
- m_kept_volume_out[DEV_HANDFREE] = num.nValue;
- SendAudioDeviceVolumn(DEVICE_HANDFREE_OUT);
- 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]);
- }
- else
- {
- Dbg("HANDFREE out volume keeper create failed!");
- }
- #else
- if (m_pAudioMgr)
- {
- m_pAudioMgr->audio_set_device_volume(num.nValue, conf.audio_handfree_out_dev, false);
- m_kept_volume_out[DEV_HANDFREE] = num.nValue;
- SendAudioDeviceVolumn(DEVICE_HANDFREE_OUT);
- 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]);
- }
- else
- {
- Dbg("HANDFREE out volume keeper create failed!");
- }
- #endif
- }
- else if((sub_type == ACM_SET_PICKUP_OUTVOLUMN)&&(eStand2sType == m_eDeviceType))
- {
- CVolumnValue num;
- SpBuffer buf;
- buf.OpenRead(buffer,size);
- num.Serialize(buf);
- Dbg("recv adj pickup out volumn = %d",num.nValue);
- #ifdef RVC_OS_WIN
- if (m_pKeeperOut[DEV_PICKUP])
- {
- if (eStand2sType == m_eDeviceType)
- {
- volume_keeper_change(m_pKeeperOut[DEV_PICKUP], num.nValue);
- m_kept_volume_out[DEV_PICKUP] = num.nValue;
- SendAudioDeviceVolumn(DEVICE_PICKUP_OUT);
- 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]);
- }
- else //pad版屏蔽当前PICKUP音量设置
- {
- Dbg("PAD type, ignore pickupout volume adj");
- }
- }
- else
- {
- Dbg("PICKUP out volume keeper create failed!");
- }
- #else
- if (m_pAudioMgr)
- {
- if (eStand2sType == m_eDeviceType)
- {
- m_pAudioMgr->audio_set_device_volume(num.nValue, conf.audio_pickup_out_dev, false);
- m_kept_volume_out[DEV_PICKUP] = num.nValue;
- SendAudioDeviceVolumn(DEVICE_PICKUP_OUT);
- 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]);
- }
- else //pad版屏蔽当前PICKUP音量设置
- {
- Dbg("PAD type, ignore pickupout volume adj");
- }
- }
- else
- {
- Dbg("PICKUP out volume keeper create failed!");
- }
- #endif
- }
- else if (sub_type == ACM_SET_HANDFREE_INVOLUMN)
- {
- CVolumnValue num;
- SpBuffer buf;
- buf.OpenRead(buffer,size);
- num.Serialize(buf);
- Dbg("recv adj handfree in volumn = %d",num.nValue);
- #ifdef RVC_OS_WIN
- if (m_pKeeperIn[DEV_HANDFREE])
- {
- volume_keeper_change(m_pKeeperIn[DEV_HANDFREE], num.nValue);
- m_kept_volume_in[DEV_HANDFREE] = num.nValue;
- SendAudioDeviceVolumn(DEVICE_HANDFREE_IN);
- 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]);
- }
- else
- {
- Dbg("handfree in volume keeper create failed!");
- }
- #else
- if (m_pAudioMgr)
- {
- m_pAudioMgr->audio_set_device_volume(num.nValue, conf.audio_handfree_in_dev, true);
- m_kept_volume_in[DEV_HANDFREE] = num.nValue;
- SendAudioDeviceVolumn(DEVICE_HANDFREE_IN);
- 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]);
- }
- else
- {
- Dbg("handfree in volume keeper create failed!");
- }
- #endif
- }
- else if((sub_type == ACM_SET_PICKUP_INVOLUMN)&&(eStand2sType == m_eDeviceType))
- {
- CVolumnValue num;
- SpBuffer buf;
- buf.OpenRead(buffer,size);
- num.Serialize(buf);
- Dbg("recv adj pickup in volume = %d",num.nValue);
- #ifdef RVC_OS_WIN
- if (m_pKeeperIn[DEV_PICKUP])
- {
- if (eStand2sType == m_eDeviceType)
- {
- volume_keeper_change(m_pKeeperIn[DEV_PICKUP], num.nValue);
- m_kept_volume_in[DEV_PICKUP] = num.nValue;
- SendAudioDeviceVolumn(DEVICE_PICKUP_IN);
- 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]);
- }
- else //pad版屏蔽当前PICKUP音量设置
- {
- Dbg("PAD type, ignore pickupin volume adj");
- }
- }
- else
- {
- Dbg("pickup in volume keeper create failed!");
- }
- #else
- if (m_pAudioMgr)
- {
- if (eStand2sType == m_eDeviceType)
- {
- m_pAudioMgr->audio_set_device_volume(num.nValue, conf.audio_pickup_in_dev, true);
- m_kept_volume_in[DEV_PICKUP] = num.nValue;
- SendAudioDeviceVolumn(DEVICE_PICKUP_IN);
- 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]);
- }
- else //pad版屏蔽当前PICKUP音量设置
- {
- Dbg("PAD type, ignore pickupin volume adj");
- }
- }
- else
- {
- Dbg("pickup in volume keeper create failed!");
- }
- #endif
- }
- else if (sub_type == ACM_CONTROL_PERSONAREA) //控制人形框
- {
- CVolumnValue num;
- SpBuffer buf;
- buf.OpenRead(buffer,size);
- num.Serialize(buf);
- Dbg("recv control personarea subtype = %d",num.nValue);
- if (num.nValue == 0) //隐藏人形框
- {
- LogEvent(Severity_Middle,LOG_EVT_UI_HIDELOCALVIDEO,"Agent send hide local video");
- LogEvent(Severity_Middle,LOG_EVT_UI_HIDEPERSONAREA,"Agent send Hide Person area");
- }
- else if (num.nValue == 1) //显示人形框
- {
- LogEvent(Severity_Middle,LOG_EVT_UI_SHOWLOCALVIDEO,"Agent send show local video");
- LogEvent(Severity_Middle,LOG_EVT_UI_SHOWPERSONAREA,"Agent send Show Person area");
- }
- else
- {
- Dbg("recv control personarea sub_type error!");
- }
- }
- }
- else if (type == ACM_TYPE_VIDEOFREQ)
- {
- if (eMobilePadType == m_eDeviceType)
- {
- CFpsValue nFps;
- SpBuffer buf;
- buf.OpenRead(buffer,size);
- nFps.Serialize(buf);
- Dbg("adj up stream fps to %d",nFps.nValue);
- if((m_stVideoParam.nUpDynamicFps == 1)&&(nFps.nValue!=1))
- {
- GetFunction()->KillTimer(1);
- }
- else if (nFps.nValue==1)
- {
- //如果1帧每秒维持20秒,停止视频
- Dbg("start timer for up fps");
- GetFunction()->SetTimer(1, this, 20000);
- }
- m_stVideoParam.nUpDynamicFps = nFps.nValue;
- }
- else
- {
- Dbg("not mobile pad,ignore down message!");
- }
- }
- }
- #ifdef RVC_OS_LINUX
- ErrorCodeEnum CSIPEntity::RvcGetAudioDeviceInfo()
- {
- ErrorCodeEnum Error = Error_Param;
- if (NULL != m_pAudioMgr) {
- int icountmic = m_pAudioMgr->audio_get_device_count(true);
- Dbg("audio input device(%d):", icountmic);
- int i = 0;
- for (; i < icountmic; i++) {
- char strname[MAX_PATH] = { 0 };
- m_pAudioMgr->audio_get_device_name(strname, MAX_PATH, true, i);
- Dbg("%d = %s", i, strname);
- }
- int icountspeaker = m_pAudioMgr->audio_get_device_count(false);
- Dbg("audio output device(%d):", icountspeaker);
- for (i = 0; i < icountspeaker; i++) {
- char strname[MAX_PATH] = { 0 };
- m_pAudioMgr->audio_get_device_name(strname, MAX_PATH, false, i);
- Dbg("%d = %s", i, strname);
- }
- Error = Error_Succeed;
- }
- return Error;
- }
- ErrorCodeEnum CSIPEntity::RvcSetSaveAudioVolume()
- {
- ErrorCodeEnum Error = Error_Succeed;
- if (eStand2sType == m_eDeviceType) {
- 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]);
- if (m_pAudioMgr){
- m_pAudioMgr->audio_set_device_volume(m_kept_volume_out[DEV_HANDFREE], conf.audio_handfree_out_dev, false);
- m_pAudioMgr->audio_set_device_volume(m_kept_volume_in[DEV_HANDFREE], conf.audio_handfree_in_dev, true);
- m_pAudioMgr->audio_set_device_volume(m_kept_volume_out[DEV_PICKUP], conf.audio_pickup_out_dev, false);
- m_pAudioMgr->audio_set_device_volume(m_kept_volume_in[DEV_PICKUP], conf.audio_pickup_in_dev, true);
- }
- }
- return Error;
- }
- #endif
- ErrorCodeEnum CSIPEntity::GetLocalIP()
- {
- #ifdef RVC_OS_WIN
- char tmp[MAX_PATH] = { 0 };
- gethostname(tmp, sizeof(tmp));
- hostent* ent = gethostbyname(tmp);
- if (ent) {
- for (int i = 0; ent->h_addr_list[i]; ++i) {
- if (ent->h_addrtype == AF_INET) {
- struct in_addr* in = (struct in_addr*)ent->h_addr_list[i];
- char* p = inet_ntoa(*in);
- if (p[0] != '0')
- {
- if (strstr(p, "198.168.") == NULL)
- {
- strcpy(m_localip, p);
- Dbg("local ip == %s", m_localip);
- return Error_Succeed;
- }
- }
- }
- }
- }
- return Error_Unexpect;
- #else
- ErrorCodeEnum error = Error_Unexpect;
- int sockfd = -1;
- struct ifconf ifconf;
- struct ifreq* ifreq = NULL;
- char strbuf[MAX_PATH] = {0};
- ifconf.ifc_len = MAX_PATH;
- ifconf.ifc_buf = strbuf;
- if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
- Dbg("socket error");
- return error;
- }
- ioctl(sockfd, SIOCGIFCONF, &ifconf); //get all socket info
- ifreq = (struct ifreq*)ifconf.ifc_buf;
- for (int i = (ifconf.ifc_len / sizeof(struct ifreq)); i > 0; i--){
- if (ifreq->ifr_flags == AF_INET) { //for ipv4
- char* strIP = inet_ntoa(((struct sockaddr_in*) & (ifreq->ifr_addr))->sin_addr);
- Dbg("name = %s, local addr = %s", ifreq->ifr_name, strIP);
- ifreq++;
- if (NULL != strIP){
- if (NULL == strstr(strIP, "198.168.") && NULL == strstr(strIP, "127.0.0.1"))
- {
- strcpy(m_localip, strIP);
- Dbg("local ip == %s", m_localip);
- error = Error_Succeed;
- break;
- }
- }
- }
- }
- return error;
- #endif // RVC_OS_WIN
- }
- //send DynamicFps
- void CSIPEntity::SendDynamicFps(int nFps)
- {
- if (eMobilePadType == m_eDeviceType)
- {
- ChannelService_Send_Info Info;
- Info.compress = false;
- Info.encrypt = false;
- Info.type = ACM_TYPE_VIDEOFREQ;
- Info.id = 0;
- Info.sub_type = ACM_VIDEOFREQ_DOWN;
- Info.data.Alloc(sizeof(int));
- SpBuffer buf;
- buf.OpenWrite();
- buf & nFps;
- Info.data = buf.ToBlob();
- m_pSipphoneChannel->Send(Info);
- Dbg("adj down stream fps to %d",nFps);
- }
- else
- {
- Dbg("not mobile pad,ignore up message!");
- }
- }
- //send audio device volume
- void CSIPEntity::SendAudioDeviceVolumn(int nDevice)
- {
- if (m_nSysCallType == 0)
- {
- ChannelService_Send_Info Info;
- Info.compress = false;
- Info.encrypt = false;
- Info.type = ACM_TYPE_DEVICE;
- Info.id = 0;
- int nValue = 0;
- bool rslt = false;
-
- void*keeper = NULL;
- if (nDevice == DEVICE_HANDFREE_OUT)
- {
- Info.sub_type = ACM_HANDFREE_OUTVOLUMN;
- #ifdef RVC_OS_WIN
- keeper = m_pKeeperOut[DEV_HANDFREE];
- #else
- m_pAudioMgr->audio_get_device_volume(&nValue, conf.audio_handfree_out_dev, false);
- rslt = true;
- #endif // RVC_OS_WIN
- }
- else if(nDevice == DEVICE_PICKUP_OUT)
- {
- if(eStand2sType == m_eDeviceType)
- {
- Info.sub_type = ACM_PICKUP_OUTVOLUMN;
- #ifdef RVC_OS_WIN
- keeper = m_pKeeperOut[DEV_PICKUP];
- #else
- m_pAudioMgr->audio_get_device_volume(&nValue, conf.audio_pickup_out_dev, false);
- rslt = true;
- #endif
- }
- else //pad版屏蔽当前PICKUP音量发送
- {
- return;
- }
- }
- else if(nDevice == DEVICE_HANDFREE_IN)
- {
- Info.sub_type = ACM_HANDFREE_INVOLUMN;
- #ifdef RVC_OS_WIN
- keeper = m_pKeeperIn[DEV_HANDFREE];
- #else
- m_pAudioMgr->audio_get_device_volume(&nValue, conf.audio_handfree_in_dev, true);
- rslt = true;
- #endif
- }
- else if(nDevice == DEVICE_PICKUP_IN)
- {
- if(eStand2sType == m_eDeviceType)
- {
- Info.sub_type = ACM_PICKUP_INVOLUMN;
- #ifdef RVC_OS_WIN
- keeper = m_pKeeperIn[DEV_PICKUP];
- #else
- m_pAudioMgr->audio_get_device_volume(&nValue, conf.audio_pickup_in_dev, true);
- rslt = true;
- #endif
- }
- else //pad版屏蔽当前PICKUP音量发送
- {
- return;
- }
- }
- Info.data.Alloc(sizeof(int));
- SpBuffer buf;
- buf.OpenWrite();
- #ifdef RVC_OS_WIN
- if (keeper){
- rslt = get_audiodevice_volumn(keeper, &nValue);
- }
- #endif
- if (rslt == true)
- {
- buf & nValue;
- Info.data = buf.ToBlob();
- m_pSipphoneChannel->Send(Info);
- Dbg("send cur Audio device %d,value = %d",nDevice,nValue);
- }
- else
- {
- Dbg("Get cur Audio device %d volume Fail!",nDevice);
- }
- }
- else
- {
- Dbg("cur call type cannot send pkt");
- }
- }
- ErrorCodeEnum CSIPEntity::SetHandfreeOutVolume(int iVolume)
- {
- ErrorCodeEnum Error = Error_Succeed;
- Dbg("handle set hand free out volume = %d.", iVolume);
- #ifdef RVC_OS_WIN
- if (m_pKeeperOut[DEV_HANDFREE])
- {
- volume_keeper_change(m_pKeeperOut[DEV_HANDFREE], num.nValue);
- m_kept_volume_out[DEV_HANDFREE] = iVolume;
- Dbg("set hand free out volume to %d.", iVolume);
- 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]);
- }
- else
- {
- Dbg("HANDFREE out volume keeper create failed!");
- }
- #else
- if (m_pAudioMgr)
- {
- m_pAudioMgr->audio_set_device_volume(iVolume, conf.audio_handfree_out_dev, false);
- m_kept_volume_out[DEV_HANDFREE] = iVolume;
- Dbg("set hand free out volume to %d.", iVolume);
- 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]);
- }
- else
- {
- Dbg("HANDFREE out volume keeper create failed!");
- }
- #endif
- return Error;
- }
- ErrorCodeEnum CSIPEntity::SetPickupOutVolume(int iVolume)
- {
- ErrorCodeEnum Error = Error_Succeed;
- Dbg("handle set pickup out volume = %d.", iVolume);
- #ifdef RVC_OS_WIN
- if (m_pKeeperOut[DEV_PICKUP])
- {
- if (eStand2sType == m_eDeviceType)
- {
- volume_keeper_change(m_pKeeperOut[DEV_PICKUP], num.nValue);
- m_kept_volume_out[DEV_PICKUP] = iVolume;
- Dbg("set pick up out volume to %d.", iVolume);
- 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]);
- }
- else //pad版屏蔽当前PICKUP音量设置
- {
- Dbg("PAD type, ignore pickupout volume adj");
- }
- }
- else
- {
- Dbg("PICKUP out volume keeper create failed!");
- }
- #else
- if (m_pAudioMgr)
- {
- if (eStand2sType == m_eDeviceType)
- {
- m_pAudioMgr->audio_set_device_volume(iVolume, conf.audio_pickup_out_dev, false);
- m_kept_volume_out[DEV_PICKUP] = iVolume;
- 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]);
- }
- else //pad版屏蔽当前PICKUP音量设置
- {
- Dbg("PAD type, ignore pickupout volume adj");
- }
- }
- else
- {
- Dbg("PICKUP out volume keeper create failed!");
- }
- #endif
- return Error;
- }
- void CSIPEntity::OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- ErrorCodeEnum Error = __OnClose(Error_Succeed);
- pTransactionContext->SendAnswer(Error);
- }
- ErrorCodeEnum CSIPEntity::__OnClose(ErrorCodeEnum preOperationError)
- {
- LOG_FUNCTION();
- int i;
- CSmartPointer<IEntityFunction> Func = GetFunction();
- Func->UnregistSysVarEvent(SYSVAR_AGENTCAMERASWITCH);
- Func->UnregistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA);
- Func->UnregistSysVarEvent(SYSVAR_CAMERASTATE);
- Func->UnregistSysVarEvent(SYSVAR_CALLTYPE);
-
- for (i = 0; i < m_arrListener.GetCount(); ++i) {
- Func->UnsubscribeLog(m_arrListener[i]);
- }
- m_arrListener.Clear();
- Dbg("__OnClose endpoint_destroy m_pEndpoint addr is 0x%08x.",m_pEndpoint);
- endpoint_destroy(m_pEndpoint);
- m_pEndpoint = NULL;
- video_lib_deinit();
- audio_lib_deinit();
- endpoint_deinit_lib();
- #ifdef RVC_OS_WIN
- if (m_pKeeperIn[DEV_HANDFREE]) {
- volume_keeper_destroy(m_pKeeperIn[DEV_HANDFREE]);
- m_pKeeperIn[DEV_HANDFREE] = NULL;
- }
- if (m_pKeeperOut[DEV_HANDFREE]) {
- volume_keeper_destroy(m_pKeeperOut[DEV_HANDFREE]);
- m_pKeeperOut[DEV_HANDFREE] = NULL;
- }
- if (m_pKeeperIn[DEV_PICKUP]) {
- volume_keeper_destroy(m_pKeeperIn[DEV_PICKUP]);
- m_pKeeperIn[DEV_PICKUP] = NULL;
- }
- if (m_pKeeperOut[DEV_PICKUP]) {
- volume_keeper_destroy(m_pKeeperOut[DEV_PICKUP]);
- m_pKeeperOut[DEV_PICKUP] = NULL;
- }
- #else
- if (NULL != m_pAudioMgr) {
- m_pAudioMgr->audio_mgr_terminate();
- DestroyIAudioMgrObj(m_pAudioMgr);
- m_pAudioMgr = NULL;
- }
- #endif
- return Error_Succeed;
- }
- void CSIPEntity::OnPaused()
- {
- int rc;
- video_session_conf_t conf = {0};
- conf.bit_rate = 256*1024;
- conf.local_rtp_ip = htonl(INADDR_LOOPBACK);
- conf.local_rtp_port = 3000;
- conf.local_video_view_cx = 320;
- conf.local_video_view_cy = 240;
- conf.local_video_view_x = 0;
- conf.local_video_view_y = 0;
- conf.mtu = 1500;
- conf.remote_rtp_ip = htonl(INADDR_LOOPBACK);
- conf.remote_rtp_port = 3000;
- conf.remote_video_view_cx = 320;
- conf.remote_video_view_cy = 320;
- conf.remote_video_view_x = 0;
- conf.remote_video_view_y = 320;
- conf.video_quant = 3;
- conf.remote_video_width = 320;
- conf.remote_video_height = 320;
- conf.ref_active_camera = &m_stVideoParam.iActiveCamera;
-
- video_session_create(&conf, &video_session);
- video_session_start(video_session);
- }
- void CSIPEntity::OnContinued()
- {
- video_session_stop(video_session);
- video_session_destroy(video_session);
- }
- CServerSessionBase* CSIPEntity::OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszClass*/)
- {
- LOG_FUNCTION();
- m_pCurrentSession = new CSIPPhoneSession(this);
- return m_pCurrentSession;
- }
- void CSIPEntity::OnTimeout(DWORD dwTimerID)
- {
- if (dwTimerID == 1)
- {
- //如果当前动态帧频不等于之前的帧频,发送当前帧频
- //if (g_nDynamicFps != m_nDownDynamicFps)
- //{
- // m_nDownDynamicFps = g_nDynamicFps;
- // SendDynamicFps(g_nDynamicFps);
- //}
- Dbg("stop up stream!");
- GetFunction()->KillTimer(1);
- m_stVideoParam.nUpDynamicFps = -1;
- }
- }
- ErrorCodeEnum CSIPEntity::InitEndpoint()
- {
- LOG_FUNCTION();
- ErrorCodeEnum eCode = Error_Param;
- CSmartPointer<IEntityFunction> Func = GetFunction();
- Func->GetSystemStaticInfo(staticInfo);
-
- CSimpleStringA strUri = MakeUri(staticInfo.strTerminalID);
- if (strUri.GetLength() > 0)
- {
- strcpy(conf.uri, strUri);
- conf.media_start_port = REC_COMMON_AUDIO_PORT_START;
- conf.media_stop_port = REC_COMMON_AUDIO_PORT_STOP;
- m_pEndpoint = endpoint_create(this, &conf,DEV_HANDFREE);
- if (!m_pEndpoint) {
- LOG_TRACE("create endpoint failed!");
- eCode = Error_Unexpect;
- }
- else{
- Dbg("%s:%d endpoint_create m_pEndpoint addr is 0x%08x.", __FUNCTION__, __LINE__, m_pEndpoint);
- eCode = Error_Succeed;
- }
- }
- else
- {
- LOG_TRACE("strUri length equals zero!");
- eCode = Error_Unexpect;
- }
- return eCode;
- }
- void CSIPEntity::change_dev(int dev_type)
- {
- Dbg("change_dev dev_type:%d", dev_type);
- if (m_pEndpoint) {
- Dbg("begin invoke endpoint change audio device!");
- endpoint_change_audio_dev(m_pEndpoint, dev_type);
- Dbg("end invoke endpoint change audio device!");
- }
- }
- static int __change_dev(void *arg)
- {
- ChangeDevCommand *pCmd = (ChangeDevCommand *)arg;
- pCmd->pEntity->change_dev(pCmd->dev_type);
- delete pCmd;
- return 0;
- }
- void CSIPEntity::SwitchHandFree()
- {
- LOG_FUNCTION();
- int rc = 0;
- ChangeDevCommand *pCmd = new ChangeDevCommand();
- pCmd->pEntity = this;
- pCmd->dev_type = DEV_HANDFREE;
- if (endpoint_invoke(m_pEndpoint, &__change_dev, pCmd, &rc) != 0) {
- Dbg("endpoint invoke failed!");
- delete pCmd;
- }
- }
- void CSIPEntity::SwitchPickup()
- {
- LOG_FUNCTION();
- int rc = 0;
- ChangeDevCommand *pCmd = new ChangeDevCommand();
- pCmd->pEntity = this;
- pCmd->dev_type = DEV_PICKUP;
- if (endpoint_invoke(m_pEndpoint, &__change_dev, pCmd, &rc) != 0) {
- Dbg("endpoint invoke failed!");
- delete pCmd;
- }
- }
- void CSIPEntity::SetState(int state)
- {
- m_state = state;
- }
- ErrorCodeEnum CSIPEntity::RealSelfCheck()
- {
- ErrorCodeEnum Error = Error_Succeed;
- if (m_pSelfcheckClient)
- {
- SelfCheckerService_RealCheck_Req req;
- req.name = GetEntityName();
- SelfCheckerService_RealCheck_Ans ans;
- DWORD Timeout = 500;
- Error = m_pSelfcheckClient->RealCheck(req,ans,Timeout);
- if (Error!=Error_Succeed)
- {
- Dbg("RealSelfcheck fail!");
- }
- else
- {
- Dbg("RealSelfcheck");
- }
- }
- return Error;
- }
- CSimpleStringA CSIPEntity::MakeUri(const char *terminal_id)
- {
- CSimpleStringA str;
- str = CSimpleStringA::Format("sip:%s@%s;transport=UDP", terminal_id, m_localip);
- return str;
- }
- void CSIPEntity::Handle_RecordVideoLocation_Info(const char* pszMessage)
- {
- if (NULL == pszMessage){
- return;
- }
- CSimpleStringA strMsg = pszMessage;
- if (strMsg.IsStartWith("ews|",true)){
- strMsg = strMsg.SubString(4,strMsg.GetLength()-4);
- }
- int lxPos,lyPos,lwidth,lheight;
- CSimpleStringA str;
- sscanf(strMsg.GetData(), "%d@%d@%d@%d@%d@%s", &lxPos, &lyPos, &lwidth, &lheight, &str);
- Dbg("start record preview local video param : (x=%d,y=%d,width=%d,height=%d).",lxPos,lyPos,lwidth,lheight);
- m_RecordVideoLocation.x = lxPos;
- m_RecordVideoLocation.y = lyPos;
- m_RecordVideoLocation.width = lwidth;
- m_RecordVideoLocation.height = lheight;
- }
- void CSIPEntity::Handle_AdjustVideoEchoEvent(const char* pszMessage)
- {
- if (NULL == pszMessage){
- return;
- }
- CSimpleStringA strMsg = pszMessage;
- if (strMsg.IsStartWith("ews|",true)){
- strMsg = strMsg.SubString(4,strMsg.GetLength()-4);
- }
- int lxPos,lyPos,lwidth,lheight;
- CSimpleStringA str;
- sscanf(strMsg.GetData(), "%d@%d@%d@%d@%d@%s", &lxPos, &lyPos, &lwidth, &lheight, &str);
- Dbg("begin adjust local video param : (x=%d,y=%d,width=%d,height=%d).",lxPos,lyPos,lwidth,lheight);
- if (DEFAULT_RECORD_VIDEO_WIDTH == lwidth && DEFAULT_RECORD_VIDEO_HEIGHT == lheight){
- m_stVideoParam.nWindowState = 0;
- }
- else if(SMALL_RECORD_VIDEO_WIDTH == lwidth && SMALL_RECORD_VIDEO_HEIGHT == lheight){
- m_stVideoParam.nWindowState = 5;
- }
- else{
- Dbg("not support width and height.");
- }
-
- m_RecordVideoLocation.x = lxPos;
- m_RecordVideoLocation.y = lyPos;
- m_RecordVideoLocation.width = lwidth;
- m_RecordVideoLocation.height = lheight;
- }
- void CSIPEntity::InitFreshTimeConfig()
- {
- int ileftvideo = RVC_MAX_VIDEO_FRESH_TIME;
- int irightvideo = RVC_MAX_VIDEO_FRESH_TIME;
- CSmartPointer<IConfigInfo> spCacheConfig;
- ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_CenterSetting, spCacheConfig);
- if (Error_Succeed == Error){
- SpIniMappingTable table;
- table.AddEntryInt("SIPPhone", "lfreshtime", ileftvideo, RVC_MAX_VIDEO_FRESH_TIME);
- table.AddEntryInt("SIPPhone", "rfreshtime", irightvideo, RVC_MAX_VIDEO_FRESH_TIME);
- Error = table.Load(spCacheConfig);
- if (Error == Error_Succeed) {
- Dbg("lfreshtime = %d, rfreshtime = %d.", ileftvideo, irightvideo);
- if (0 == ileftvideo) {
- ileftvideo = RVC_MAX_VIDEO_FRESH_TIME;
- }
- if (0 == irightvideo) {
- irightvideo = RVC_MAX_VIDEO_FRESH_TIME;
- }
- if (ileftvideo < RVC_MIN_VIDEO_FRESH_TIME) {
- ileftvideo = RVC_MIN_VIDEO_FRESH_TIME;
- }
- if (ileftvideo > RVC_MAX_VIDEO_FRESH_TIME) {
- ileftvideo = RVC_MAX_VIDEO_FRESH_TIME;
- }
- if (irightvideo < RVC_MIN_VIDEO_FRESH_TIME) {
- irightvideo = RVC_MIN_VIDEO_FRESH_TIME;
- }
- if (irightvideo > RVC_MAX_VIDEO_FRESH_TIME) {
- irightvideo = RVC_MAX_VIDEO_FRESH_TIME;
- }
- }
- }
- LogWarn(Severity_Middle, Error_Debug, EVENT_MOD_SIP_OVERWRITE_FRESHVALUE,
- CSimpleStringA::Format("overwrite video freshtime from centersetting cache, left fresh time is %d, right fresh time is %d.", ileftvideo, irightvideo));
- m_ilocalvideo_freshtime = ileftvideo;
- m_iremotevideo_freshtime = irightvideo;
-
- }
- ErrorCodeEnum CSIPEntity::LoadConfig(endpoint_conf_t *conf)
- {
- CSmartPointer<IEntityFunction> spFunction = GetFunction();
- CSmartPointer<IConfigInfo> spRootConfig;
- ErrorCodeEnum Error = spFunction->OpenConfig(Config_Root, spRootConfig);
- if (Error == Error_Succeed) {
- CSimpleStringA strHandFreeIn;
- CSimpleStringA strHandFreeOut;
- CSimpleStringA strPickupIn;
- CSimpleStringA strPickupOut;
- SpIniMappingTable table;
- table.AddEntryString("audio", "handfree_in_dev", strHandFreeIn, "$");
- table.AddEntryString("audio", "handfree_out_dev", strHandFreeOut, "$");
- table.AddEntryString("audio", "pickup_in_dev", strPickupIn, "$");
- table.AddEntryString("audio", "pickup_out_dev", strPickupOut, "$");
- table.AddEntryBoolean("audio", "pickup_out_agc", conf->audio_pickup_out_agc, false);
- table.AddEntryBoolean("audio", "pickup_in_agc", conf->audio_pickup_in_agc, false);
- table.AddEntryBoolean("audio", "handfree_in_agc", conf->audio_handfree_in_agc, false);
- table.AddEntryBoolean("audio", "handfree_out_agc", conf->audio_handfree_out_agc, false);
- table.AddEntryBoolean("audio", "pickup_out_ns", conf->audio_pickup_out_ns, false);
- table.AddEntryBoolean("audio", "pickup_in_ns", conf->audio_pickup_in_ns, false);
- table.AddEntryBoolean("audio", "handfree_in_ns", conf->audio_handfree_in_ns, false);
- table.AddEntryBoolean("audio", "handfree_out_ns", conf->audio_handfree_out_ns, false);
- table.AddEntryBoolean("audio", "pickup_aec", conf->audio_pickup_aec, false);
- table.AddEntryBoolean("audio", "handfree_aec", conf->audio_handfree_aec, false);
- table.AddEntryInt("audio", "handfree_in_volume", m_kept_volume_in[DEV_HANDFREE], 0);
- table.AddEntryInt("audio", "handfree_out_volume", m_kept_volume_out[DEV_HANDFREE], 0);
- table.AddEntryInt("audio", "pickup_in_volume", m_kept_volume_in[DEV_PICKUP], 0);
- table.AddEntryInt("audio", "pickup_out_volume", m_kept_volume_out[DEV_PICKUP], 0);
- table.AddEntryInt("video", "quant", conf->quant, 0);
- table.AddEntryInt("video", "mtu", conf->mtu, 0);
- Error = table.Load(spRootConfig);
- if (Error == Error_Succeed) {
- int id;
- #ifdef RVC_OS_WIN
- id = capture_get_audio_device_id(true, strHandFreeIn);
- #else
- id = m_pAudioMgr->audio_get_device_id(strHandFreeIn.GetData(), true);
- #endif
- if (id == -1) {
- Dbg("audio handfree in device %s does not exist!", (LPCSTR)strHandFreeIn);
- CSimpleStringA strErrMsg = "外部麦克风配置错误,请重新配置!";
- LogWarn(Severity_Middle, Error_Param, 0, strErrMsg);
- Error = Error_Param;
- }
- strcpy(conf->audio_handfree_in_dev, strHandFreeIn);
- #ifdef RVC_OS_WIN
- id = capture_get_audio_device_id(false, strHandFreeOut);
- #else
- id = m_pAudioMgr->audio_get_device_id(strHandFreeOut.GetData(), false);
- #endif
- if (id == -1) {
- Dbg("audio handfree out device %s does not exist!", (LPCSTR)strHandFreeOut);
- CSimpleStringA strErrMsg = "外部扬声器配置错误,请重新配置!";
- LogWarn(Severity_Middle, Error_Param, 0, strErrMsg);
- Error = Error_Param;
- }
- strcpy(conf->audio_handfree_out_dev, strHandFreeOut);
- #ifdef RVC_OS_WIN
- id = capture_get_audio_device_id(true, strPickupIn);
- #else
- id = m_pAudioMgr->audio_get_device_id(strPickupIn.GetData(), true);
- #endif
- if (id == -1) {
- Dbg("audio pickup in device %s does not exist!", (LPCSTR)strPickupIn);
- CSimpleStringA strErrMsg = "话筒麦克风(大机)配置错误,请重新配置!";
- LogWarn(Severity_Middle, Error_Param, 0, strErrMsg);
- Error = Error_Param;
- }
- strcpy(conf->audio_pickup_in_dev, strPickupIn);
- #ifdef RVC_OS_WIN
- id = capture_get_audio_device_id(false, strPickupOut);
- #else
- id = m_pAudioMgr->audio_get_device_id(strPickupOut.GetData(), false);
- #endif
- if (id == -1) {
- Dbg("audio device %s does not exist!", (LPCSTR)strPickupOut);
- CSimpleStringA strErrMsg = "话筒扬声器(大机)配置错误,请重新配置!";
- LogWarn(Severity_Middle, Error_Param, 0, strErrMsg);
- Error = Error_Param;
- }
- strcpy(conf->audio_pickup_out_dev, strPickupOut);
- conf->ref_active_camera = &m_stVideoParam.iActiveCamera;
- conf->ref_camera_switch = &m_stVideoParam.iCameraSwitch;
- conf->ref_window_state = &m_stVideoParam.nWindowState;
- conf->ref_active_img = &m_stVideoParam.bShowActiveImg;
- conf->ref_Is_ActiveInspect = &m_stVideoParam.bActiveInspect;
- conf->ref_camera_state = &m_stVideoParam.iCameraState;
- conf->ref_Is_showPersonArea = &m_stVideoParam.bShowPersonArea;
- conf->ref_Is_showRecordArea = &m_stVideoParam.bShowRecordArea;
- if (eMobilePadType == m_eDeviceType)
- {
- m_stVideoParam.nUpDynamicFps = 3;
- }
- else if ((ePadtype==m_eDeviceType)||(eDesk2SType==m_eDeviceType)||(eDesk1SType==m_eDeviceType)||(eDesk2SIntegratedType==m_eDeviceType))
- {
- m_stVideoParam.nUpDynamicFps = REC_COMMON_VIDEO_FPS_MOBILE;
- }
- else if(eStand2sType == m_eDeviceType)
- {
- m_stVideoParam.nUpDynamicFps = 0;
- }
- Dbg("init up dynamic fps to %d",m_stVideoParam.nUpDynamicFps);
- conf->ref_Up_Fps = &m_stVideoParam.nUpDynamicFps;
- if ((eMobilePadType == m_eDeviceType)||(ePadtype == m_eDeviceType)||(eDesk2SType == m_eDeviceType)||(eDesk1SType==m_eDeviceType)||(eDesk2SIntegratedType==m_eDeviceType))
- {
- conf->camera_count = 1;
- }
- else if(eStand2sType == m_eDeviceType)
- {
- conf->camera_count = 2;
- }
- //DecideCameraCount(conf->camera_count);
- DecideScreenCount(conf->screen_count);
- }
- }
- InitFreshTimeConfig();
- return Error;
- }
- //载入运行时配置
- ErrorCodeEnum CSIPEntity::LoadAudioRunConfig(int&nHandfreeout,int&nPickupout,int&nHandfreein,int&nPickupin)
- {
- CSmartPointer<IEntityFunction> spFunction = GetFunction();
- CSmartPointer<IConfigInfo> spConfig;
- ErrorCodeEnum Error = spFunction->OpenConfig(Config_Run, spConfig);
- if (Error == Error_Succeed)
- {
- SpIniMappingTable table;
- table.AddEntryInt("Audio", "handfree_out_volume", nHandfreeout, 0);
- table.AddEntryInt("Audio", "pickup_out_volume", nPickupout, 0);
- table.AddEntryInt("Audio", "handfree_in_volume", nHandfreein, 0);
- table.AddEntryInt("Audio", "pickup_in_volume", nPickupin, 0);
- Error = table.Load(spConfig);
- if (Error != Error_Succeed)
- {
- LOG_TRACE("[dbg] failed to load run config.");
- }
- }
- else
- {
- LOG_TRACE("[dbg] failed to open run config.");
- }
- return Error;
- }
- //保存运行时
- ErrorCodeEnum CSIPEntity::SaveAudioRunConfig(int nHandfreeout,int nPickupout,int nHandfreein,int nPickupin)
- {
- CSmartPointer<IEntityFunction> spFunction = GetFunction();;
- CSmartPointer<IConfigInfo> spConfig;
- ErrorCodeEnum Error = spFunction->OpenConfig(Config_Run, spConfig);
- if (Error == Error_Succeed)
- {
- Error = spConfig->WriteConfigValueInt("Audio", "handfree_out_volume", nHandfreeout);
- if(Error == Error_Succeed)
- {
- Error = spConfig->WriteConfigValueInt("Audio", "pickup_out_volume", nPickupout);
- }
- else
- {
- Dbg("SaveAudioRunConfig handfree_out_volume fail!");
- return Error;
- }
- if(Error == Error_Succeed)
- {
- Error = spConfig->WriteConfigValueInt("Audio", "handfree_in_volume", nHandfreein);
- }
- else
- {
- Dbg("SaveAudioRunConfig pickup_out_volume fail!");
- return Error;
- }
- if(Error == Error_Succeed)
- {
- Error = spConfig->WriteConfigValueInt("Audio", "pickup_in_volume", nPickupin);
- }
- else
- {
- Dbg("SaveAudioRunConfig handfree_in_volume fail!");
- return Error;
- }
- if (Error != Error_Succeed)
- {
- Dbg("SaveAudioRunConfig pickup_in_volume fail!");
- return Error;
- }
- }
- else
- {
- Dbg("SaveAudioRunConfig is fail , open sipphone.ini fail!");
- }
- return Error;
- }
- // we use root.ini Video section config to decide camera count
- ErrorCodeEnum CSIPEntity::DecideCameraCount(int &nCount)
- {
- CSmartPointer<IEntityFunction> spFunction = GetFunction();
- CSmartPointer<IConfigInfo> spConfig;
- ErrorCodeEnum Error = spFunction->OpenConfig(Config_Root, spConfig);
- if (Error == Error_Succeed) {
- CSimpleStringA strVideoEnv;
- CSimpleStringA strVideoOpt;
- SpIniMappingTable table;
- nCount = 0;
- table.AddEntryString("Video", "EnvCamera", strVideoEnv, "$");
- table.AddEntryString("Video", "OptCamera", strVideoOpt, "$");
- Error = table.Load(spConfig);
- if (Error == Error_Succeed) {
- if (strVideoEnv.GetLength() > 1)
- nCount++;
- if (strVideoOpt.GetLength() > 1)
- nCount++;
- }
- }
- return Error;
- }
- ErrorCodeEnum CSIPEntity::DecideScreenCount(int &nCount)
- {
- CSystemStaticInfo Info;
- CSmartPointer<IEntityFunction> spFunction = GetFunction();
- ErrorCodeEnum Error = spFunction->GetSystemStaticInfo(Info);
- if (Error == Error_Succeed)
- {
- nCount = (int)Info.eScreen;
- }
- return Error;
- }
- DeviceTypeEnum CSIPEntity::RvcGetDeviceType()
- {
- DeviceTypeEnum eType = eStand2sType;
- CSmartPointer<IEntityFunction> spFunction = GetFunction();
- CSystemStaticInfo stStaticinfo;
- spFunction->GetSystemStaticInfo(stStaticinfo);
- if (stricmp(stStaticinfo.strMachineType, "RVC.PAD") == 0) {
- if (stricmp(stStaticinfo.strSite, "CMB.FLB") == 0) {
- eType = eMobilePadType;
- }
- else {
- eType = ePadtype;
- }
- }
- else if (stricmp(stStaticinfo.strMachineType, "RVC.Desk2S") == 0) {
- eType = eDesk2SType;
- WORD nMajor = stStaticinfo.MachineVersion.GetMajor();
- WORD nMinor = stStaticinfo.MachineVersion.GetMinor();
- Dbg("MachineVersion is %d.%d", nMajor, nMinor);
- if (2 == nMajor) {
- eType = eDesk2SIntegratedType;
- }
- }
- else if (stricmp(stStaticinfo.strMachineType, "RPM.Stand1S") == 0) {
- eType = eRpm1sType;
- }
- else if (stricmp(stStaticinfo.strMachineType, "RVC.Desk1S") == 0) {
- eType = eDesk1SType;
- }
- else {
- eType = eStand2sType;
- }
- if (eType >= 0 && eType < sizeof(Device_Type_Table) / sizeof(char*)) {
- LOG_TRACE("device type is %s.", Device_Type_Table[eType]);
- }
- return eType;
- }
- //
- // CSIPPhoneSession
- //
- void CSIPPhoneSession::OnClose( ErrorCodeEnum eErrorCode )
- {
- LOG_FUNCTION();
- }
- void CSIPPhoneSession::Handle_MakeCall( SpReqAnsContext<PhoneService_MakeCall_Req, PhoneService_MakeCall_Ans>::Pointer ctx )
- {
- LOG_FUNCTION();
- LOG_TRACE("make call [%s]", (LPCSTR)ctx->Req.to_uri);
- int rc;
- MakeCallCommand *cmd = new MakeCallCommand();
- cmd->pSIPPhoneSession = this;
- cmd->strUri = ctx->Req.to_uri;
- ///////////重新初始化sip话机,防止断网导致IP改变//////////////////
- if (m_pEntity->m_pEndpoint){
- Dbg("%s:%d m_pEndpoint is not null and it's addr is 0x%08x,destroy it.", __FUNCTION__, __LINE__, m_pEntity->m_pEndpoint);
- endpoint_destroy(m_pEntity->m_pEndpoint);
- m_pEntity->m_pEndpoint = NULL;
- }
- CSimpleStringA strUri = m_pEntity->MakeUri(m_pEntity->staticInfo.strTerminalID);
- if (strUri.GetLength() > 0) {
- strcpy(m_pEntity->conf.uri, strUri);
- m_pEntity->conf.media_start_port = REC_COMMON_AUDIO_PORT_START;
- m_pEntity->conf.media_stop_port = REC_COMMON_AUDIO_PORT_STOP;
- m_pEntity->m_pEndpoint = endpoint_create(m_pEntity, &m_pEntity->conf, m_pEntity->m_iPickupPhoneState);
- if (!m_pEntity->m_pEndpoint) {
- LOG_TRACE("create endpoint failed!");
- }
- else {
- Dbg("%s:%d endpoint_create m_pEndpoint addr is 0x%08x.", __FUNCTION__, __LINE__, m_pEntity->m_pEndpoint);
- }
- }
- else {
- LOG_TRACE("strUri length equals zero!");
- }
- ErrorCodeEnum Error = m_pEntity->GetLocalIP();
- if (Error != 0) {
- LOG_TRACE("get local ip failed!");
- ctx->Answer(Error_Unexpect);
- return;
- }
- if (m_pEntity->m_eDeviceType == eMobilePadType) {
- m_pEntity->m_stVideoParam.nUpDynamicFps = 3;
- }
- ///////////重新初始化sip话机,防止断网导致IP改变//////////////////
- if (m_pEntity->GetEndpoint()) {
- endpoint_invoke(m_pEntity->GetEndpoint(), &__make_call, cmd, &rc);
- }
- ctx->Answer((ErrorCodeEnum)rc);
- }
- void CSIPPhoneSession::Handle_HangupCall( SpReqAnsContext<PhoneService_HangupCall_Req, PhoneService_HangupCall_Ans>::Pointer ctx )
- {
- LOG_FUNCTION();
- int rc;
- HangupCallCommand *cmd = new HangupCallCommand();
- cmd->pSIPPhoneSession = this;
- cmd->strSession_num = ctx->Req.session_num;
- cmd->strBranch_server_ip = ctx->Req.branch_server_ip;
- cmd->iBranch_server_port = ctx->Req.branch_server_port;
- if (m_pEntity->GetEndpoint())
- {
- endpoint_invoke(m_pEntity->GetEndpoint(), &__hangup_call, cmd, &rc);
- }
- ctx->Answer((ErrorCodeEnum)rc);
- }
- void CSIPPhoneSession::Handle_ReleaseCall( SpReqAnsContext<PhoneService_ReleaseCall_Req, PhoneService_ReleaseCall_Ans>::Pointer ctx )
- {
- LOG_FUNCTION();
- int rc = Error_Succeed;
- g_IsExternalTerminalted = TRUE;
- endpoint_invoke(m_pEntity->GetEndpoint(), &__release_call, this, &rc);
- Dbg("%s:%d endpoint_destroy m_pEndpoint addr is 0x%08x.", __FUNCTION__, __LINE__, m_pEntity->m_pEndpoint);
- if (NULL != m_pEntity->m_pEndpoint){
- endpoint_destroy(m_pEntity->m_pEndpoint);
- m_pEntity->m_pEndpoint = NULL;
- }
-
- ctx->Answer((ErrorCodeEnum)rc);
- }
- void CSIPPhoneSession::Handle_SetCallingParam(SpOnewayCallContext<PhoneService_SetCallingParam_Info>::Pointer ctx)
- {
- LOG_FUNCTION();
- Dbg("SetCallingParam CallType = %d", ctx->Info.CallType);
- m_pEntity->m_nCallType = (CallingTypeEnum)ctx->Info.CallType;
- }
- void CSIPPhoneSession::Handle_RealErrorCheck(SpOnewayCallContext<PhoneService_RealErrorCheck_Info>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->m_SipErrorCode = Error_InvalidState;
- m_pEntity->RealSelfCheck();
- }
- void CSIPPhoneSession::Handle_StartVideo( SpOnewayCallContext<PhoneService_StartVideo_Info>::Pointer ctx )
- {
- LOG_FUNCTION();
- int rc;
- ControlVideoCommand *pCmd = new ControlVideoCommand();
- pCmd->pSIPPhoneSession = this;
- pCmd->start = TRUE;
- pCmd->local_hwd_move = 0;
- pCmd->remote_hwd_move = 0;
- 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))
- {
- m_IsLocalPlay= TRUE;
- m_VideoWindowPlayType = eOnly_Local_Video;
- Dbg("LocalPlay Mod");
- }
- else
- {
- m_IsLocalPlay= FALSE;
- m_VideoWindowPlayType = eOnline_Mode_Video;
- Dbg("OnlinePlay Mod");
- if (0 == ctx->Info.remote_port){
- m_VideoWindowPlayType = eBoth_Local_Remote_Video;
- m_pEntity->m_nCallType = NORMAL_CALLTYPE;
- Dbg("both local and remote mode.");
- if (NULL == m_pEntity->GetEndpoint())
- {
- Dbg("m_pEndpoint has destroy, now new init it.");
- m_pEntity->InitEndpoint();
- }
- }
- }
- pCmd->local_ip = inet_addr(m_pEntity->m_localip);
- pCmd->local_port = REC_COMMON_VIDEO_PORT;
- pCmd->remote_ip = inet_addr(ctx->Info.remote_ip);
- pCmd->remote_port = ctx->Info.remote_port;
- pCmd->local_view_x = ctx->Info.local_view_x;
- pCmd->local_view_y = ctx->Info.local_view_y;
- pCmd->local_view_cx = ctx->Info.local_view_cx;
- pCmd->local_view_cy = ctx->Info.local_view_cy;
- pCmd->remote_view_x = ctx->Info.remote_view_x;
- pCmd->remote_view_y = ctx->Info.remote_view_y;
- pCmd->remote_view_cx = ctx->Info.remote_view_cx;
- pCmd->remote_view_cy = ctx->Info.remote_view_cy;
- pCmd->remote_width = ctx->Info.remote_width;
- pCmd->remote_height = ctx->Info.remote_height;
- pCmd->local_hwd_move = ctx->Info.local_hwd_move;
- pCmd->remote_hwd_move = ctx->Info.remote_hwd_move;
- pCmd->local_fresh_time = m_pEntity->m_ilocalvideo_freshtime;
- pCmd->remote_fresh_time = m_pEntity->m_iremotevideo_freshtime;
- //初始化窗口参数
- //m_pEntity->m_stVideoParam.nWindowState = 0;
- //m_pEntity->GetFunction()->SetTimer(1, m_pEntity, 1000);
- //m_pEntity->m_nDownDynamicFps = ctx->Info.remote_fps;
- //g_nDynamicFps = ctx->Info.remote_fps;
- //g_nSysFps = ctx->Info.remote_fps;
- //g_nLastRecFrameTime = GetTickCount();
- endpoint_invoke(m_pEntity->GetEndpoint(), &__control_video, pCmd, &rc);
- }
- void CSIPPhoneSession::Handle_StopVideo( SpOnewayCallContext<PhoneService_StopVideo_Info>::Pointer ctx )
- {
- int rc;
- ControlVideoCommand *pCmd = new ControlVideoCommand();
- pCmd->pSIPPhoneSession = this;
- pCmd->start = FALSE;
- m_pEntity->GetFunction()->KillTimer(1);
- if (NULL != m_pEntity->GetEndpoint()){
- endpoint_invoke(m_pEntity->GetEndpoint(), &__control_video, pCmd, &rc);
- }
- else{
- endpoint_call_stop_double_record_broadcast_video();
- }
-
- m_pEntity->m_stVideoParam.bShowActiveImg = 0;
- m_pEntity->m_stVideoParam.bActiveInspect = 0;
- //初始化窗口参数
- m_pEntity->m_stVideoParam.nWindowState = 0;
- }
- void CSIPPhoneSession::Handle_BeginState( SpSubscribeContext<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::Pointer ctx )
- {
- m_spCallbackContext = ctx;
- }
- void CSIPPhoneSession::Handle_EndState( SpOnewayCallContext<PhoneService_EndState_Info>::Pointer ctx )
- {
- SpSubscribeContext<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::Pointer tmp_ctx = m_spCallbackContext;
- m_spCallbackContext.Clear();
- }
- void CSIPPhoneSession::Handle_GetHandfreeOutVolume(SpReqAnsContext<PhoneService_GetHandfreeOutVolume_Req, PhoneService_GetHandfreeOutVolume_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- ctx->Ans.Volume = m_pEntity->m_kept_volume_out[DEV_HANDFREE];
- Dbg("get hand free out volume is %d.", ctx->Ans.Volume);
- ctx->Answer(Error_Succeed);
- }
- void CSIPPhoneSession::Handle_SetHandfreeOutVolume(SpReqAnsContext<PhoneService_SetHandfreeOutVolume_Req, PhoneService_SetHandfreeOutVolume_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- int iVolume = ctx->Req.Volume;
- if (iVolume > 100){
- iVolume = 100;
- }
- if (iVolume < 30){
- iVolume = 30;
- }
- m_pEntity->SetHandfreeOutVolume(iVolume);
- ctx->Answer(Error_Succeed);
- }
- void CSIPPhoneSession::Handle_GetPickupOutVolume(SpReqAnsContext<PhoneService_GetPickupOutVolume_Req, PhoneService_GetPickupOutVolume_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- if (eStand2sType == m_pEntity->m_eDeviceType){
- ctx->Ans.Volume = m_pEntity->m_kept_volume_out[DEV_PICKUP];
- }
- else{
- ctx->Ans.Volume = 0;
- }
-
- Dbg("get pickup out volume is %d.", ctx->Ans.Volume);
- ctx->Answer(Error_Succeed);
- }
- void CSIPPhoneSession::Handle_SetPickupOutVolume(SpReqAnsContext<PhoneService_SetPickupOutVolume_Req, PhoneService_SetPickupOutVolume_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- if (eStand2sType == m_pEntity->m_eDeviceType) {
- int iVolume = ctx->Req.Volume;
- if (iVolume > 100) {
- iVolume = 100;
- }
- if (iVolume < 30) {
- iVolume = 30;
- }
- m_pEntity->SetPickupOutVolume(iVolume);
- }
- ctx->Answer(Error_Succeed);
- }
- void CSIPPhoneSession::hangup_call(/*CSIPPhoneSession::HangupCallCommand* cmd*/)
- {
- if (m_pCall) {
- Dbg("normal hangup.");
- endpoint_call_hangup(m_pCall);
- }
- }
- void CSIPPhoneSession::release_call()
- {
- if (m_pCall){
- Terminatedcall(m_pCall);
- }
- }
- void CSIPPhoneSession::on_call_state(int state, const char *state_desc, const char *phrase)
- {
- if (m_spCallbackContext != NULL)
- {
- PhoneService_PhoneState_Info Info;
- Info.state = state;
- Info.status = CSimpleStringA::Format("%s,%s", state_desc, phrase);
- m_spCallbackContext->SendMessage(Info);
- }
- if (state == TERMINATED)
- {
- if (NULL != m_pCall){
- endpoint_call_destroy(m_pCall);
- m_pCall = NULL;
- }
- }
- m_pEntity->SetState(state);
- }
- int CSIPPhoneSession::make_call(const char *remote_uri)
- {
- if (m_pCall)
- {
- LOG_TRACE("call duplicated! and endpoint destroy old call.");
- endpoint_call_destroy(m_pCall);
- m_pCall = NULL;
- //return Error_Duplication;
- }
- //else
- {
- endpoint_call_callback_t cb = {0};
- cb.on_call_state = &__on_call_state;
- cb.user_data = this;
- m_pCall = endpoint_call_create(m_pEntity->GetEndpoint(), remote_uri, m_pEntity->m_localip,m_pEntity->m_eDeviceType,m_pEntity->m_nCallType,&cb);
- if (m_pCall)
- {
- g_IsExternalTerminalted = FALSE;
- Dbg("g_IsExternalTerminalted = FALSE");
- LOG_TRACE("create call endpoint ok!");
- if (endpoint_call_start(m_pCall) == 0)
- {
- LOG_TRACE("start call ok!");
- return Error_Succeed;
- }
- else
- {
- LOG_TRACE("start call failed! and endpoint destroy call.");
- endpoint_call_destroy(m_pCall);
- m_pCall = NULL;
- return Error_Unexpect;
- }
- }
- else
- {
- g_IsExternalTerminalted = TRUE;
- Dbg("g_IsExternalTerminalted = TRUE");
- LOG_TRACE("create call endpoint failed!");
- m_pEntity->m_SipErrorCode = Error_InvalidState;
- m_pEntity->RealSelfCheck();
- return Error_Unexpect;
- }
- }
- }
- void CSIPPhoneSession::control_video( ControlVideoCommand *pCmd )
- {
- LOG_FUNCTION();
- if (m_pCall)
- {
- if (pCmd->start)
- {
- endpoint_call_param_t callparam = { 0 };
- callparam.remote_ip = pCmd->remote_ip;
- callparam.remote_port = pCmd->remote_port;
- callparam.local_ip = pCmd->local_ip;
- callparam.local_port = pCmd->local_port;
- callparam.remote_width = pCmd->remote_width;
- callparam.remote_height = pCmd->remote_height;
- callparam.local_view_x = pCmd->local_view_x;
- callparam.local_view_y = pCmd->local_view_y;
- callparam.local_view_cx = pCmd->local_view_cx;
- callparam.local_view_cy = pCmd->local_view_cy;
- callparam.remote_view_x = pCmd->remote_view_x;
- callparam.remote_view_y = pCmd->remote_view_y;
- callparam.remote_view_cx = pCmd->remote_view_cx;
- callparam.remote_view_cy = pCmd->remote_view_cy;
- callparam.local_hwd_move = pCmd->local_hwd_move;
- callparam.remote_hwd_move = pCmd->remote_hwd_move;
- callparam.local_fresh_time = pCmd->local_fresh_time;
- callparam.remote_fresh_time = pCmd->remote_fresh_time;
- endpoint_call_start_video(m_pCall, &callparam, &m_cb_video_box_move);
- }
- else
- {
- //双录第一阶段结束录像,销毁call资源
- if ((eOnly_Local_Video == m_VideoWindowPlayType) || (eBoth_Local_Remote_Video == m_VideoWindowPlayType && m_pEntity->m_nCallType != DOUBLERECORD_CALLTYPE ))
- {
- Dbg("stop record play.");
- local_play_stop_video(m_pCall);
- m_IsLocalPlay = FALSE;
- endpoint_call_destroy(m_pCall);
- m_pCall = NULL;
- }
- else
- {
- endpoint_call_stop_video(m_pCall);
- }
- }
- }
- else
- {
- if (pCmd->start)
- {
- endpoint_call_callback_t cb = {0};
- cb.on_call_state = &__on_call_state;
- cb.user_data = this;
- m_pCall = endpoint_call_create(m_pEntity->GetEndpoint(), "test",m_pEntity->m_localip,m_pEntity->m_eDeviceType,m_pEntity->m_nCallType, &cb);
-
- if (eOnly_Local_Video == m_VideoWindowPlayType){
- Dbg("start local play mode record.");
- 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);
- }
- else if (eBoth_Local_Remote_Video == m_VideoWindowPlayType){
- Dbg("start local and remote video play mode record.");
- 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);
- }
- }
- else{
- #ifdef RVC_OS_WIN
- Dbg("record call remote agent timeout, close video session.");
- endpoint_call_stop_double_record_broadcast_video();
- #endif
- }
- }
- }
- int CSIPPhoneSession::on_video_box_move(int imessageType, int ivideotype, int ileft, int ibottom)
- {
- int iret = -1;
- if (0 == imessageType){
- VideoBoxStartMove evt;
- evt.videoboxflag = ivideotype;
- evt.leftlowerx = ileft;
- evt.leftlowery = ibottom;
- iret = SpSendBroadcast(m_pEntity->GetFunction(), SP_MSG_OF(VideoBoxStartMove), SP_MSG_SIG_OF(VideoBoxStartMove), evt);
- Dbg("VideoBoxStartMove broadcast sent, video type is %d, left is %d, bottom is %d.", ivideotype, ileft, ibottom);
- }
- else{
- VideoBoxStopMove evt;
- evt.videoboxflag = ivideotype;
- evt.leftlowerx = ileft;
- evt.leftlowery = ibottom;
- iret = SpSendBroadcast(m_pEntity->GetFunction(), SP_MSG_OF(VideoBoxStopMove), SP_MSG_SIG_OF(VideoBoxStopMove), evt);
- Dbg("VideoBoxStopMove broadcast sent, video type is %d, left is %d, bottom is %d.", ivideotype, ileft, ibottom);
- }
- return iret;
- }
- ChannelSipphoneClient::ChannelSipphoneClient( CSIPEntity *pEntity ) : ChannelService_ClientBase(pEntity)
- {
- }
- void ChannelSipphoneClient::OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData)
- {
- if (Error == Error_Succeed)
- {
- CSIPEntity *pEntity = static_cast<CSIPEntity*>(m_pEntityBase);
- if (Msg.state == eChannelState_Connected)
- {
- #ifdef RVC_OS_WIN
- if (pEntity->m_pKeeperIn[DEV_HANDFREE])
- #else
- if (pEntity->m_pAudioMgr)
- #endif
- {
- pEntity->SendAudioDeviceVolumn(DEVICE_HANDFREE_IN);
- }
- #ifdef RVC_OS_WIN
- if (pEntity->m_pKeeperOut[DEV_HANDFREE])
- #else
- if (pEntity->m_pAudioMgr)
- #endif
- {
- pEntity->SendAudioDeviceVolumn(DEVICE_HANDFREE_OUT);
- }
- #ifdef RVC_OS_WIN
- if (pEntity->m_pKeeperOut[DEV_PICKUP])
- #else
- if (pEntity->m_pAudioMgr)
- #endif
- {
- pEntity->SendAudioDeviceVolumn(DEVICE_PICKUP_OUT);
- }
- #ifdef RVC_OS_WIN
- if (pEntity->m_pKeeperIn[DEV_PICKUP])
- #else
- if (pEntity->m_pAudioMgr)
- #endif
- {
- pEntity->SendAudioDeviceVolumn(DEVICE_PICKUP_IN);
- }
- }
- }
- }
- void ChannelSipphoneClient::OnMessage( ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData )
- {
- //LOG_FUNCTION();
- if (Error == Error_Succeed)
- {
- CSIPEntity *pEntity = static_cast<CSIPEntity*>(m_pEntityBase);
- pEntity->OnReceivePkt(Msg.type,Msg.sub_type, (const char*)Msg.data.m_pData, Msg.data.m_iLength);
- }
- }
- SelfChekerClient::SelfChekerClient( CSIPEntity *pEntity ) : SelfCheckerService_ClientBase(pEntity)
- {
- }
- SP_BEGIN_ENTITY_MAP()
- SP_ENTITY(CSIPEntity)
- SP_END_ENTITY_MAP()
|