1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575 |
- #include "stdafx.h"
- #include "SpBase.h"
- #include "SpIni.h"
- #include "endpoint.h"
- #include "SIPPhone_server_g.h"
- #include "SIPPhone_msg_g.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"
- #include "Event.h"
- #include "EventCode.h"
- #include "../mod_assistantchannel/AssistantChannel_client_g.h"
- using namespace AssistantChannel;
- #include "../mod_assistantchannel/chan_protocol.h"
- #include "../mod_selfchecker/SelfChecker_client_g.h"
- #include "../mod_selfchecker/SelfChecker_def_g.h"
- #include "audio_pulse.h"
- using namespace SelfChecker;
- #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 RVC_MAX_VOLUME
- #define RVC_MAX_VOLUME 100
- #endif
- enum ePickupMicrophoneState
- {
- ePickupMicrophoneState_On,
- ePickupMicrophoneState_Off,
- };
- /* 0:online local and remote video window, 1:only local video window, 2:both local and remote window */
- enum eShowVideoWindowType{
- eOnline_Mode_Video,
- eOnly_Local_Video,
- eBoth_Local_Remote_Video
- };
- struct CVolumnValue
- {
- int nValue;
- void Serialize(SpBuffer &Buf)
- {
- Buf & nValue;
- }
- };
- struct CFpsValue
- {
- int nValue;
- void Serialize(SpBuffer &Buf)
- {
- Buf & nValue;
- }
- };
- struct stVideoParam
- {
- int nWindowState; //视频窗口显示状态,0:正常大小显示,1:放大一倍显示,2:隐藏全部窗口,3:从隐藏状态恢复为全部显示,4:显示远程窗口,隐藏本地窗口, 5:缩放显示
- int bShowActiveImg; //活体检测显示图片
- int bActiveInspect; //是否启动活体检测
- int iActiveCamera; // set by facetracking
- int iCameraSwitch; // set by agent and camerastate
- int nUpDynamicFps; // 当前视频上行的帧频,由后端通知前端更改频率,只有移动版才使用
- int iCameraState; // set by agent and camerastate
- int bShowPersonArea; //是否显示人形框
- int bShowRecordArea; //是否显示录像人形轮廓
- };
- //record video echo location
- typedef struct record_echo_location_s{
- int x;
- int y;
- int width;
- int height;
- }record_echo_location_t;
- #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
- /////////////////////////////////////////////
- // 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;
- using namespace SIPPhone;
- class CSIPEntity;
- class SelfChekerClient:public SelfCheckerService_ClientBase
- {
- public:
- SelfChekerClient(CSIPEntity*pEntity);
- };
- class ChannelSipphoneClient : public ChannelService_ClientBase
- {
- public:
- ChannelSipphoneClient(CSIPEntity *pEntity);
- virtual void OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData);
- virtual void OnMessage(ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData);
- };
- class CSIPPhoneSession : public PhoneService_ServerSessionBase
- {
- public:
- 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;
- }
- virtual void Handle_MakeCall(SpReqAnsContext<PhoneService_MakeCall_Req, PhoneService_MakeCall_Ans>::Pointer ctx);
- virtual void Handle_HangupCall(SpReqAnsContext<PhoneService_HangupCall_Req, PhoneService_HangupCall_Ans>::Pointer ctx);
- virtual void Handle_StartVideo(SpOnewayCallContext<PhoneService_StartVideo_Info>::Pointer ctx);
- virtual void Handle_StopVideo(SpOnewayCallContext<PhoneService_StopVideo_Info>::Pointer ctx);
- virtual void Handle_BeginState(SpSubscribeContext<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::Pointer ctx);
- virtual void Handle_EndState(SpOnewayCallContext<PhoneService_EndState_Info>::Pointer ctx);
- virtual void Handle_ReleaseCall(SpReqAnsContext<PhoneService_ReleaseCall_Req, PhoneService_ReleaseCall_Ans>::Pointer ctx);
- virtual void Handle_RealErrorCheck(SpOnewayCallContext<PhoneService_RealErrorCheck_Info>::Pointer ctx);
- virtual void Handle_SetCallingParam(SpOnewayCallContext<PhoneService_SetCallingParam_Info>::Pointer ctx);
- virtual void OnClose(ErrorCodeEnum eErrorCode);
- private:
- struct MakeCallCommand
- {
- CSIPPhoneSession *pSIPPhoneSession;
- CSimpleStringA strUri;
- };
- struct ControlVideoCommand
- {
- CSIPPhoneSession *pSIPPhoneSession;
- int start;
- unsigned long local_ip;
- int local_port;
- unsigned long remote_ip;
- int remote_port;
- int local_view_x;
- int local_view_y;
- int local_view_cx;
- int local_view_cy;
- int remote_view_x;
- int remote_view_y;
- int remote_view_cx;
- int remote_view_cy;
- int remote_width;
- int remote_height;
- int local_hwd_move;
- int remote_hwd_move;
- };
- struct HangupCallCommand
- {
- CSIPPhoneSession *pSIPPhoneSession;
- CSimpleStringA strSession_num;
- CSimpleStringA strBranch_server_ip;
- int iBranch_server_port;
- };
- void on_call_state(int state, const char *state_desc, const char *phrase);
- int make_call(const char *uri);
- void hangup_call(/*HangupCallCommand *pCmd*/);
- void release_call();
- void control_video(ControlVideoCommand *pCmd);
- int on_video_box_move(int imessagetype, int ivideotype, int ileft, int ibottom);
- 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);
- }
- 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)
- {
- LOG_FUNCTION();
- 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;
- }
- private:
- SpSubscribeContext<PhoneService_BeginState_Sub, PhoneService_PhoneState_Info>::Pointer m_spCallbackContext;
- endpoint_call_t *m_pCall;
- CSIPEntity *m_pEntity;
- int m_iLastState;
- int m_IsLocalPlay;
- eShowVideoWindowType m_VideoWindowPlayType;/*add by clp 20190903 0:only remote video window, 1:only local video window, 2:both local and remote window */
- video_session_callback_t m_cb_video_box_move;
- };
- class CSIPEntity : public CEntityBase, public ILogListener, public ISysVarListener,public ITimerListener
- {
- public:
- 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;
- m_volume_max[0] = m_volume_max[1] = 100;
- #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));
- }
- virtual ~CSIPEntity() {}
- virtual const char *GetEntityName() const { return "SIPPhone"; }
- virtual void 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 = %x.",dwUserCode);
- }
- break;
- }
- }
- virtual void 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;
- }
- }
- }
- virtual void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- if (Test_ShakeHand == eTestType)
- {
- pTransactionContext->SendAnswer(m_SipErrorCode);
- }
- }
- virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- ErrorCodeEnum Error = __OnStart(Error_Succeed);
- pTransactionContext->SendAnswer(Error);
- }
- virtual void OnStarted()
- {
- 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!");
- }
- }
- ErrorCodeEnum __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
- {
- m_pAudioMgr = new AudioPulseMgr();
- if (0 == m_pAudioMgr->AudioMgrInitialize()) {
- 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%0x.", __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;
- //volumn adjust
- void 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,m_volume_max[DEV_HANDFREE], 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, m_volume_max[DEV_PICKUP], 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, RVC_MAX_VOLUME, 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, RVC_MAX_VOLUME, 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_HIDEPERSONAREA,"Agent send Hide Person area");
- //if((eMobilePadType == m_eDeviceType)||(ePadtype == m_eDeviceType)||(eDesk2SType == m_eDeviceType))
- //{
- 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_SHOWPERSONAREA,"Agent send Show Person area");
- //if((eMobilePadType == m_eDeviceType)||(ePadtype == m_eDeviceType)||(eDesk2SType == m_eDeviceType))
- //{
- 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 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 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], m_volume_max[DEV_HANDFREE], conf.audio_handfree_out_dev, false);
- m_pAudioMgr->audio_set_device_volume(m_kept_volume_in[DEV_HANDFREE], RVC_MAX_VOLUME, conf.audio_handfree_in_dev, true);
- m_pAudioMgr->audio_set_device_volume(m_kept_volume_out[DEV_PICKUP], m_volume_max[DEV_PICKUP], conf.audio_pickup_out_dev, false);
- m_pAudioMgr->audio_set_device_volume(m_kept_volume_in[DEV_PICKUP], RVC_MAX_VOLUME, conf.audio_pickup_in_dev, true);
- }
- }
- return Error;
- }
- #endif
- ErrorCodeEnum 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 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 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");
- }
- }
- virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- ErrorCodeEnum Error = __OnClose(Error_Succeed);
- pTransactionContext->SendAnswer(Error);
- }
- ErrorCodeEnum __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.",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->AudioMgrTerminate();
- delete m_pAudioMgr;
- m_pAudioMgr = NULL;
- }
- #endif
- return Error_Succeed;
- }
- /////////////////////////////////////////////////////////////////////
- #if 1
- virtual void 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);
- }
- virtual void OnContinued()
- {
- video_session_stop(video_session);
- video_session_destroy(video_session);
- }
- #endif
- /////////////////////////////////////////////////////////////////////
- virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszClass*/)
- {
- LOG_FUNCTION();
- m_pCurrentSession = new CSIPPhoneSession(this);
- return m_pCurrentSession;
- }
- virtual bool IsService()const{return true;}
- virtual void 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;
- }
- }
- bool IsCurrentSession(CServerSessionBase * pSession) { return m_pCurrentSession == pSession; }
- endpoint_t *GetEndpoint() { return m_pEndpoint; }
- ErrorCodeEnum 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%0x.", __FUNCTION__, __LINE__, m_pEndpoint);
- eCode = Error_Succeed;
- }
- }
- else
- {
- LOG_TRACE("strUri length equals zero!");
- eCode = Error_Unexpect;
- }
- return eCode;
- }
- struct ChangeDevCommand
- {
- CSIPEntity *pEntity;
- int dev_type;
- };
- void 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 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 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 SetState(int state)
- {
- m_state = state;
- }
- ErrorCodeEnum 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 MakeUri(const char *terminal_id)
- {
- CSimpleStringA str;
- str = CSimpleStringA::Format("sip:%s@%s;transport=UDP", terminal_id, m_localip);
- return str;
- }
- void 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 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;
- }
- private:
- ErrorCodeEnum 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", "handfree_out_max", m_volume_max[DEV_HANDFREE], 100);
- 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("audio", "pickup_out_max", m_volume_max[DEV_PICKUP], 100);
- 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);
- }
- }
- return Error;
- }
- //载入运行时配置
- ErrorCodeEnum 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 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 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 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 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;
- }
- public:
- int m_kept_volume_in[2];
- int m_kept_volume_out[2];
- int m_volume_max[2];
- #ifdef RVC_OS_WIN
- void* m_pKeeperIn[2];
- void* m_pKeeperOut[2];
- #else
- AudioPulseMgr* m_pAudioMgr;
- #endif
- //int m_nDownDynamicFps; //当前视频下行的帧频,由前端通知后端更改频率,只有移动版才使用
- CSystemStaticInfo staticInfo;
- char m_localip[256]; //本地ip
- endpoint_conf_t conf;
- endpoint_t *m_pEndpoint;
- int m_iPickupPhoneState;
- ErrorCodeEnum m_SipErrorCode;
- DeviceTypeEnum m_eDeviceType;
- CallingTypeEnum m_nCallType; //呼叫模式,0:可视柜台正常呼叫,1:PAD主动外呼,2:PAD被动呼叫,来源PAD,3:PAD被动呼叫,来源手机端
- int m_nSysCallType;//0:普通模式,1:p2p模式
- volatile stVideoParam m_stVideoParam; //视频参数,add by ch@20190424
- volatile int m_bIsSalesRecord; //add by ly@20180725
- volatile int m_bEwsRecord; //add by ly@2019/04/18
- record_echo_location_t m_RecordVideoLocation;
-
- private:
- CServerSessionBase *m_pCurrentSession;
- int m_state;
- CAutoArray<CUUID> m_arrListener;
- ChannelSipphoneClient*m_pSipphoneChannel;
- SelfChekerClient*m_pSelfcheckClient;
- };
- //
- // 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.call_uri);
- int rc;
- MakeCallCommand *cmd = new MakeCallCommand();
- cmd->pSIPPhoneSession = this;
- cmd->strUri = ctx->Req.call_uri;
- ///////////重新初始化sip话机,防止断网导致IP改变//////////////////
- if (m_pEntity->m_pEndpoint){
- Dbg("%s:%d m_pEndpoint is not null and it's addr is 0x%0x,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%0x.", __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%0x.", __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;
- //初始化窗口参数
- //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::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_start_video(m_pCall,
- pCmd->remote_ip, pCmd->remote_port,
- pCmd->local_ip, pCmd->local_port,
- pCmd->remote_width, pCmd->remote_height,
- 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
- {
- //双录第一阶段结束录像,销毁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()
|