12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504 |
- #include "stdafx.h"
- #include "SpBase.h"
- #include "SpIni.h"
- #include "y2k_time.h"
- #include "capture.h"
- #include "Event.h"
- #include "../../Other/libaudiorender/iaudiorenderinterface.h"
- #include "../include/EventCode.h"
- #include "../mod_snapshot/Event.h"
- // id:0x208
- #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 "../include/ModuleMix.h"
- #include "MediaController_server_g.h"
- #include "MediaController_msg_g.h"
- #include "ExternalCameraMsg.h"
- using namespace MediaController;
- using namespace SelfChecker;
- #include "../mod_ScannerSet/ScannerSet_client_g.h"
- #include "../mod_ScannerSet/ScannerSet_def_g.h"
- using namespace ScannerSet;
- #include "../mod_CameraConfigManage/CameraConfigManage_client_g.h"
- #include "../mod_CameraConfigManage/CameraConfigManage_def_g.h"
- using namespace CameraConfigManage;
- #define LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE 0x50500001 //协助通道重启
- //extern DeviceTypeEnum g_eDeviceType;
- //extern int g_nSalesAudioSmpPsec; //现场销售双录音频采样率 add by ly@2018/06/13
- struct CCameraBrightValue
- {
- int nValue;
- void Serialize(SpBuffer &Buf)
- {
- Buf & nValue;
- }
- };
- class CMediaControllerEntity;
- class SelfChekerClient:public SelfCheckerService_ClientBase
- {
- public:
- SelfChekerClient(CMediaControllerEntity*pEntity);
- };
- class ChannelMediaControllerClient : public ChannelService_ClientBase
- {
- public:
- ChannelMediaControllerClient(CMediaControllerEntity *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 MediaServiceSession : public MediaService_ServerSessionBase
- {
- public:
- MediaServiceSession(CMediaControllerEntity *pEntity) : m_pEntity(pEntity){}
- virtual void Handle_GetVideoDeviceName(SpReqAnsContext<MediaService_GetVideoDeviceName_Req, MediaService_GetVideoDeviceName_Ans>::Pointer ctx);
- virtual void Handle_StartCamera(SpOnewayCallContext<MediaService_StartCamera_Info>::Pointer ctx);
- virtual void Handle_StopCamera(SpOnewayCallContext<MediaService_StopCamera_Info>::Pointer ctx);
- virtual void Handle_StartEnvCamera(SpReqAnsContext<MediaService_StartEnvCamera_Req, MediaService_StartEnvCamera_Ans>::Pointer ctx);
- virtual void Handle_StopEnvCamera(SpOnewayCallContext<MediaService_StopEnvCamera_Info>::Pointer ctx);
- //add by clp 20200319
- virtual void Handle_StartSpeakerRender(SpOnewayCallContext<MediaService_StartSpeakerRender_Info>::Pointer ctx);
- virtual void Handle_StopSpeakerRender(SpOnewayCallContext<MediaService_StopSpeakerRender_Info>::Pointer ctx);
- private:
- CMediaControllerEntity *m_pEntity;
- };
- class CMediaControllerEntity : public CEntityBase, public ILogListener, public ITimerListener,public ISysVarListener
- {
- public:
- CMediaControllerEntity() : m_capture(NULL),m_salesaudio_capture(NULL), m_lCaptureEnvCount(0),m_nCameraErrorCode(Error_Succeed),
- m_lCaptureEnvOptCount(0), m_lCaptureOptCount(0), m_iEnvEmptyTimes(0), m_iOptEmptyTimes(0),m_bSendCameraError(false),
- m_nEnvCameraRestartNum(0),m_nOptCameraRestartNum(0), m_nCameraCount(2),m_pSelfcheckClient(NULL),
- strFrontCam("$"), strRearCam("$"), strEnvCam("$"), strUSBCam("$"), strEwsCam("$"), m_bCustomerwareBegin(false),
- m_pAudioRenderObj(NULL), m_bRecordPCM(false),m_bIsRemoteRecord(false),m_bHasStartSpeakerRender(false){}
- virtual ~CMediaControllerEntity() {}
- virtual const char *GetEntityName() const { return "MediaController"; }
- virtual bool IsService()const{return true;}
- virtual void OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName)
- {
- if (_stricmp(pszKey, SYSVAR_CALLTYPE) == 0)
- {
- Dbg("sys call type 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 OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- m_eDeviceType = eStand2sType;
- g_eDeviceType = eStand2sType;
- m_bStartCamera = FALSE;
- m_bExternControlCam = FALSE;
- m_nSysCallType =0;
- LOG_FUNCTION();
- ErrorCodeEnum Error;
- //MessageBoxA(0,0,0,0);
- m_pMediaControllerChannel = new ChannelMediaControllerClient(this);
- Error = m_pMediaControllerChannel->Connect();
- if (Error != Error_Succeed)
- {
- m_pMediaControllerChannel->SafeDelete();
- Dbg("ChannelMediaControllerClient connect fail!");
- pTransactionContext->SendAnswer(Error);
- return;
- }
- else
- {
- Dbg("ChannelMediaControllerClient connect success!");
- }
- {
- 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);
- }
- }
- {
- ChannelService_BeginState_Sub Sub;
- Error = m_pMediaControllerChannel->BeginState(Sub);
- if (Error != Error_Succeed)
- {
- LOG_TRACE("BeginState biz channel failed!");
- m_pMediaControllerChannel->GetFunction()->CloseSession();
- m_pMediaControllerChannel->SafeDelete();
- m_pMediaControllerChannel = NULL;
- pTransactionContext->SendAnswer(Error);
- return;
- }
- else
- {
- Dbg("BeginState biz channel success!");
- }
- }
- {
- ChannelService_BeginRecv_Sub Sub;
- Sub.type = ACM_TYPE_DEVICE;
- Error = m_pMediaControllerChannel->BeginRecv(Sub);
- if (Error != Error_Succeed)
- {
- Dbg("Begin BeginRecv ACM_TYPE_DEVICE failed!");
- m_pMediaControllerChannel->GetFunction()->CloseSession();
- m_pMediaControllerChannel->SafeDelete();
- m_pMediaControllerChannel = NULL;
- pTransactionContext->SendAnswer(Error);
- return;
- }
- else
- {
- Dbg("Begin BeginRecv ACM_TYPE_DEVICE success!");
- }
- }
- //is Pad Version
- m_eDeviceType = RvcGetDeviceType();
- g_eDeviceType = m_eDeviceType;
- if (Error_Succeed == GetSalesRecordAudioParam()){
- Dbg("get sales record audio param success, and sales audio capture sample rate is %d, record local PCM flag is %s.", m_nSalesAudioSmpPsec, m_bRecordPCM ? "true":"false");
- }
- // only register once!! edit by ly 2017/03/21
- if (GetFunction()->RegistSysVarEvent("SessionID", this) != Error_Succeed){
- LOG_TRACE("register sysvar %s failed!", "SessionID");
- }
- memset(&conf,0,sizeof(capture_config_t));
- memset(&m_sales_audio_conf, 0, sizeof(rvc_audio_capture_config_t));
- Error = (ErrorCodeEnum)capture_lib_init();
- if (Error == Error_Succeed)
- {
- Error = LoadConfig(&conf);
- if (Error!=Error_Succeed)
- {
- if((Error == Error_OptCamera)||(Error == Error_EnvCamera))
- {
- if (Error == Error_EnvCamera)
- {
- LOG_TRACE("Load EnvCamera Config failed!");
- //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_ENV_ERROR);
- SetCameraSysVar(CAMERA_ENV_ERROR);
- Dbg("Camera State to CAMERA_ENV_ERROR");
- m_nCameraErrorCode = Error_EnvCamera;
- GetFunction()->SetUserDefineState(USER_MEDIA_ENVERRROR);
- }
- else if (Error == Error_OptCamera)
- {
- LOG_TRACE("Load OptCamera Config failed!");
- //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_OPT_ERROR);
- SetCameraSysVar(CAMERA_OPT_ERROR);
- Dbg("Camera State to CAMERA_OPT_ERROR");
- m_nCameraErrorCode = Error_OptCamera;
- GetFunction()->SetUserDefineState(USER_MEDIA_OPTERROR);
- }
- }
- else
- {
- if (Error == Error_AllCamera)
- {
- LOG_TRACE("Load all camera Config failed!");
- //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_BOTH_ERROR);
- SetCameraSysVar(CAMERA_BOTH_ERROR);
- Dbg("Camera State to CAMERA_BOTH_ERROR");
- m_nCameraErrorCode = Error_AllCamera;
- GetFunction()->SetUserDefineState(USER_MEDIA_ALLERROR);
- }
- LOG_TRACE("Load Config failed!");
- }
- }
- if ((ePadtype == m_eDeviceType)||(eMobilePadType == m_eDeviceType)||(eDesk2SType == m_eDeviceType))
- {
- CAutoArray<CSimpleStringA> hspCams;
- auto rc = GetHSPCameras(hspCams);
- Dbg("[GetHSPCameras]: (0x%x,%d)", rc, hspCams.GetCount());
- /************************************************************************/
- /* read runcfg & 暂存strVideoEnv add by ly 20160531 */
- /************************************************************************/
- if (eDesk2SType == m_eDeviceType)
- {
- strFrontCam = conf.strVideoEnv;
- strRearCam = "$";
-
- // 将内置摄像头写入到运行时配置
- SaveInnerCamera();
- }
- else
- {
- ErrorCodeEnum ErrCod = LoadRunConfig(strFrontCam, strRearCam);
- if (ErrCod == Error_Succeed) {
- Dbg("[dbg] Error=0x%x while LoadRunConfig.", ErrCod);
- if (strFrontCam.GetLength() <= 1 || strFrontCam != conf.strVideoEnv) {
- strFrontCam = conf.strVideoEnv;
- if (conf.strVideoOpt.GetLength() <= 1) {
- m_nCameraCount = videocap_optdev_fetch(strFrontCam,strEwsCam,hspCams,strRearCam);
- }
- else { // 如果root.ini中已配置
- strRearCam = conf.strVideoOpt;
- }
- // 将内置摄像头写入到运行时配置
- SaveInnerCamera();
- }
- }
- else {
- strFrontCam = conf.strVideoEnv;
- if (conf.strVideoOpt.GetLength() <= 1) {
- m_nCameraCount = videocap_optdev_fetch(strFrontCam,strEwsCam,hspCams,strRearCam);
- }
- else { // 如果root.ini中已配置
- strRearCam = conf.strVideoOpt;
- }
- // 将内置摄像头写入到运行时配置
- SaveInnerCamera();
- }
- }
- // 尝试获取外接摄像头
- m_nCameraCount = videocap_outerdev_fetch(strFrontCam,strRearCam,strEwsCam,hspCams,strUSBCam);
- Dbg("[dbg] strUSBCam=%s",(LPCTSTR)strUSBCam);
- strEnvCam = conf.strVideoEnv;
- }
- }
- else
- {
- LOG_TRACE("capture_lib_init failed!");
- }
- //PAD版获取客户感知状态
- CSimpleStringA strCustomerAware;
- if ((Error != Error_AllCamera)/*&&m_bIsPadType*/)
- {
- CSmartPointer<IEntityFunction> Func = GetFunction();
- if (Func->RegistSysVarEvent("CustomerHandle", this) != Error_Succeed)
- {
- LOG_TRACE("register sysvar %s failed!", "CustomerHandle");
- }
- else
- {
- Func->GetSysVar("CustomerHandle", strCustomerAware);
- //Dbg("CustomerHandle = %c",strCustomerAware[0]);
- Dbg("CustomerHandle = %s",(LPCTSTR)strCustomerAware);
- }
- }
- //启动摄像头
- if ((Error!=Error_AllCamera)&&(strCustomerAware.GetLength()>0)&&(strCustomerAware[0] != 'N'))
- {
- // comment by ly@2019/03/19
- //if ((ePadtype == m_eDeviceType)||(eMobilePadType == m_eDeviceType)||(eDesk2SType == m_eDeviceType))
- //{
- // // 尝试先启动外接摄像头,若失败,则自动切换为内置
- // Error = TryStartCamera();
- //}
- //else
- {
- Error = StartCamera();
- if (Error == Error_Succeed)
- {
- m_bStartCamera = TRUE;
- CSimpleStringA strSessionId;
- CSmartPointer<IEntityFunction> Func = GetFunction();
- Func->GetSysVar("SessionID", strSessionId);
- LogEvent(Severity_Middle, EVENT_MOD_BEGIN_RECORD,strSessionId);
- //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_NO_ERROR);
- SetCameraSysVar(CAMERA_NO_ERROR);
- Dbg("Camera State to CAMERA_NO_ERROR");
- m_nCameraErrorCode = Error_Succeed;
- GetFunction()->SetUserDefineState(USER_MEDIA_IDLE);
- }
- else
- {
- if((Error == Error_EnvCamera)||(Error == Error_OptCamera))
- {
- CSimpleStringA strSessionId;
- CSmartPointer<IEntityFunction> Func = GetFunction();
- Func->GetSysVar("SessionID", strSessionId);
- LogEvent(Severity_Middle, EVENT_MOD_BEGIN_RECORD,strSessionId);
- m_bStartCamera = TRUE;
- if (Error == Error_EnvCamera)
- {
- //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_ENV_ERROR);
- SetCameraSysVar(CAMERA_ENV_ERROR);
- Dbg("Camera State to CAMERA_ENV_ERROR");
- m_nCameraErrorCode = Error_EnvCamera;
- GetFunction()->SetUserDefineState(USER_MEDIA_ENVERRROR);
- Error = Error_Succeed;
- }
- else if (Error == Error_OptCamera)
- {
- //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_OPT_ERROR);
- SetCameraSysVar(CAMERA_OPT_ERROR);
- Dbg("StartCamera = Error_OptCamera");
- m_nCameraErrorCode = Error_OptCamera;
- GetFunction()->SetUserDefineState(USER_MEDIA_OPTERROR);
- Error = Error_Succeed;
- }
- }
- else if(Error == Error_AllCamera)
- {
- //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_BOTH_ERROR);
- SetCameraSysVar(CAMERA_BOTH_ERROR);
- Dbg("Camera State to CAMERA_BOTH_ERROR");
- m_nCameraErrorCode = Error_AllCamera;
- m_bStartCamera = FALSE;
- GetFunction()->SetUserDefineState(USER_MEDIA_ALLERROR);
- }
- else
- {
- SetCameraSysVar(Error);
- Dbg("Camera State to Other Error");
- m_nCameraErrorCode = Error;
- m_bStartCamera = FALSE;
- }
- }
- }
- }
- if(Error != Error_AllCamera) // edit by ly 20160329
- {
- int i = 0;
- if ((ePadtype == m_eDeviceType)||(eMobilePadType == m_eDeviceType)||(eDesk2SType == m_eDeviceType)||(eDesk1SType == m_eDeviceType)||(eDesk2SIntegratedType == m_eDeviceType))
- {
- m_arrListener.Init(18);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, MOD_EVENT_SNAPSHOT_START_CAPTURE_ENV);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, MOD_EVENT_SNAPSHOT_START_CAPTURE_OPT);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, MOD_EVENT_SNAPSHOT_START_CAPTURE_ENVOPT);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE,NULL,false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, EVENT_MOD_CUSTOMERAWARE_BEGIN, NULL, false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, EVENT_MOD_CUSTOMERAWARE_END, NULL, false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_USB_CAMER_INPUT,NULL,false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_USB_CAMER_OUTPUT,NULL,false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_USB_CAMERA_NOT_ONLY,NULL,false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_RECORDFAILED,NULL,false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RECORDFAILED,NULL,false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_BEGIN_CAMERA_CONFIG,NULL,false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_END_CAMERA_CONFIG,NULL,false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTREMOTERECORD,NULL,false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPREMOTERECORD,NULL,false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORD,NULL,false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPRECORD,NULL,false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORDPREVIEW,NULL,false);
-
- //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_START_CONTINURECORD,NULL,false);
- //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_STOP_CONTINURECORD,NULL,false);
- }
- else
- {
- m_arrListener.Init(13);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, MOD_EVENT_SNAPSHOT_START_CAPTURE_ENV);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, MOD_EVENT_SNAPSHOT_START_CAPTURE_OPT);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, MOD_EVENT_SNAPSHOT_START_CAPTURE_ENVOPT);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE,NULL,false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, EVENT_MOD_CUSTOMERAWARE_BEGIN, NULL, false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, EVENT_MOD_CUSTOMERAWARE_END, NULL, false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_RECORDFAILED,NULL,false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RECORDFAILED,NULL,false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTREMOTERECORD,NULL,false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPREMOTERECORD,NULL,false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORD,NULL,false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPRECORD,NULL,false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORDPREVIEW,NULL,false);
- }
- }
- pTransactionContext->SendAnswer(Error);
- }
- // add by ly at 20160801
- virtual void OnStarted()
- {
- m_pSelfcheckClient = new SelfChekerClient(this);
- ErrorCodeEnum Error = m_pSelfcheckClient->Connect();
- if (Error != Error_Succeed)
- {
- m_pSelfcheckClient->SafeDelete();
- m_pSelfcheckClient = NULL;
- Dbg("SelfcheckClient connect fail!");
- //pTransactionContext->SendAnswer(Error);
- //return;
- }
- else
- {
- Dbg("SelfcheckClient connect success!");
- }
- m_pAudioRenderObj = CreateIAudioRenderObj();
- if (NULL != m_pAudioRenderObj){
- Dbg("create audio render success, and addr is %0x.", m_pAudioRenderObj);
- }
- else{
- Dbg("create audio render failed.");
- }
- }
- 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;
- }
- void SetCameraSysVar(int n)
- {
- if (n==0)
- {
- //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_OPT_ERROR);
- SetCameraSysVar(CAMERA_OPT_ERROR);
- Dbg("Camera State to CAMERA_OPT_ERROR");
- }
- else if (n==1)
- {
- //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_ENV_ERROR);
- SetCameraSysVar(CAMERA_ENV_ERROR);
- Dbg("Camera State to CAMERA_ENV_ERROR");
- }
- else if (n==-1)
- {
- //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_BOTH_ERROR);
- SetCameraSysVar(CAMERA_BOTH_ERROR);
- Dbg("Camera State to CAMERA_BOTH_ERROR");
- }
- else if (n==3)
- {
- //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_NO_ERROR);
- SetCameraSysVar(CAMERA_NO_ERROR);
- Dbg("Camera State to CAMERA_NO_ERROR");
- }
- }
- ErrorCodeEnum GetSalesRecordAudioParam()
- {
- CSmartPointer<IConfigInfo> spConfig;
- SpIniMappingTable table;
- ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
- if (Error == Error_Succeed)
- {
- table.AddEntryInt("SalesRecorder", "AudioSampleRate", m_nSalesAudioSmpPsec, 8);
- table.AddEntryBoolean("SalesRecorder", "IsRecordPCM", m_bRecordPCM, false);
- Error= table.Load(spConfig);
- }
- if (m_nSalesAudioSmpPsec != 8 && m_nSalesAudioSmpPsec != 16)
- {
- m_nSalesAudioSmpPsec = 8;
- }
- m_nSalesAudioSmpPsec *= 1000;
- return Error;
- }
- ErrorCodeEnum SetEnvCameraOnSysVar(const CSimpleStringA strOnState)
- {
- ErrorCodeEnum Error = Error_Succeed;
- CSmartPointer<IEntityFunction> spFunction = this->GetFunction();
- Error = spFunction->SetSysVar(SYSVAR_ENVCAMERAON, strOnState.GetData());
- return Error;
- }
- // add by ly at 20161018
- ErrorCodeEnum SetCameraSysVar(const CSimpleStringA &newVal)
- {
- CSmartPointer<IEntityFunction> spFunction = this->GetFunction();
- if (eStand2sType == m_eDeviceType)
- {
- return spFunction->SetSysVar(SYSVAR_CAMERASTATE, (LPCTSTR)newVal);
- }
- CSimpleStringA val = newVal;
- switch (val[0])
- {
- case 'E':
- // comment by ly@2019/03/19
- //if(strstr((LPCTSTR)conf.strVideoEnv,(LPCTSTR)strUSBCam))
- //{
- // // 当前正在使用外接摄像头
- // val = val.Append("外接");
- //}
- //else
- {
- if (!strstr((LPCTSTR)strFrontCam,";"))
- {
- val = val.Append((LPCTSTR)strFrontCam);
- }
- else
- {
- val = val.Append((LPCTSTR)strFrontCam.SubString(0,strFrontCam.IndexOf(";")));
- }
- }
- break;
- case 'O':
- if (!strstr((LPCTSTR)strRearCam,";"))
- {
- val = val.Append((LPCTSTR)strRearCam);
- }
- else
- {
- val = val.Append((LPCTSTR)strRearCam.SubString(0,strRearCam.IndexOf(";")));
- }
- break;
- // comment by ly@2019/03/19
- //case 'U':
- // val = val.Append("外接");
- // break;
- case 'B':
- val = val.Append("内置前、后");
- break;
- case 'N':
- case 'I':
- default:
- break;
- }
-
- return spFunction->SetSysVar(SYSVAR_CAMERASTATE, (LPCTSTR)val);
- }
- virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- LOG_FUNCTION();
- CSmartPointer<IEntityFunction> spFunction = GetFunction();
- for (int i = 0; i < m_arrListener.GetCount(); ++i)
- {
- spFunction->UnsubscribeLog(m_arrListener[i]);
- }
- spFunction->UnregistSysVarEvent(SYSVAR_CALLTYPE);
- if (m_capture) {
- capture_stop(m_capture);
- capture_destroy(m_capture);
- m_capture = NULL;
- }
- if (m_salesaudio_capture){
- salesrecord_audio_capture_stop(m_salesaudio_capture);
- salesaudio_capture_destroy(m_salesaudio_capture);
- m_salesaudio_capture = NULL;
- }
- if (NULL != m_pAudioRenderObj){
- Dbg("destroy audio render obj,and it's addr is %0x.", m_pAudioRenderObj);
- DestroyIAudioRenderObj(m_pAudioRenderObj);
- }
- capture_lib_term();
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- virtual void OnTimeout(DWORD dwTimerID)
- {
- //Dbg("OnTimeout");
- int env_n, opt_n;
- DWORD nLastEnvTime,nLastOptTime;
- bool bEnvTimeout = false;
- bool bOptTimeout = false;
- if (!m_capture)
- {
- Dbg("m_capture =Null");
- return;
- }
- if (!m_bStartCamera)
- {
- Dbg("m_bStartCamera =false");
- return;
- }
- BOOL bIsPadType = FALSE;
- if ((ePadtype == m_eDeviceType)||(eMobilePadType == m_eDeviceType)||(eDesk2SType == m_eDeviceType)||(eDesk1SType == m_eDeviceType)||(eDesk2SIntegratedType == m_eDeviceType))
- {
- bIsPadType = TRUE;
- }
- capture_detect_camera_bug(m_capture, &env_n, &opt_n,bIsPadType);
- capture_get_last_frametime(m_capture,&nLastEnvTime,&nLastOptTime,bIsPadType);
- if (env_n == 0)
- {
- if (m_iEnvEmptyTimes < CAMERA_BUG_THRESHOLD)
- {
- m_iEnvEmptyTimes++;
- Dbg("get env camera picture fail,Times=%d",m_iEnvEmptyTimes);
- }
- }
- else if (env_n == -1)
- {
- m_iEnvEmptyTimes = CAMERA_BUG_THRESHOLD;
- }
- else
- {
- if (m_iEnvEmptyTimes == CAMERA_BUG_THRESHOLD)
- {
- Dbg("env camera get right!");
- }
- m_iEnvEmptyTimes = 0;
- }
- //env图像是否超时
- if(nLastEnvTime > 0)
- {
- //Dbg("now=%d,nLastEnvTime=%d",y2k_time_now(),nLastEnvTime);
- if(((y2k_time_now()-nLastEnvTime) > CAMERA_TIMEOUT)&&!bEnvTimeout)
- {
- bEnvTimeout = true;
- Dbg("bEnvTimeout");
- }
- else if (((y2k_time_now()-nLastEnvTime) < CAMERA_TIMEOUT)&&bEnvTimeout)
- {
- bEnvTimeout = false;
- Dbg("change env camera from bEnvTimeout to OK");
- }
- }
- //env是否30S没有图像或者图像20秒没有更新
- if(((m_iEnvEmptyTimes == CAMERA_BUG_THRESHOLD)||bEnvTimeout)&&(m_nCameraErrorCode!=Error_EnvCamera)&&(m_nCameraErrorCode!=Error_AllCamera))
- {
- char strMessage[MAX_PATH*2] = {0};
- get_camera_exception_message(strMessage, MAX_PATH*2, conf.strVideoEnv, "Env camera bug detected!");
- LogError(Severity_Middle, Error_Hardware, ERROR_MOD_MEDIACONTROLLER_ENVCAMERA_BUG, strMessage);
- if ((ePadtype == m_eDeviceType)||(eMobilePadType == m_eDeviceType)||(eDesk2SType == m_eDeviceType)||(eDesk1SType == m_eDeviceType)||(eDesk2SIntegratedType == m_eDeviceType))
- {
- // comment by ly@2019/03/19
- //if(!strstr((LPCTSTR)conf.strVideoEnv,(LPCTSTR)strUSBCam)) // 如果不是外接摄像头
- {
- m_nCameraErrorCode = Error_AllCamera;
- /*ChangeSysvar(m_nCameraErrorCode);*/
- ChangeSysvar(Error_EnvCamera);
- RealSelfCheck();
- return;
- }
- }
- else
- {
- if (m_nCameraErrorCode == Error_Succeed)
- {
- m_nCameraErrorCode = Error_EnvCamera;
- ChangeSysvar(m_nCameraErrorCode);
- }
- else if (m_nCameraErrorCode == Error_OptCamera)
- {
- m_nCameraErrorCode = Error_AllCamera;
- ChangeSysvar(m_nCameraErrorCode);
- RealSelfCheck();
- return;
- }
- }
- }
- else if((m_iEnvEmptyTimes != CAMERA_BUG_THRESHOLD)&&!bEnvTimeout&&((m_nCameraErrorCode == Error_EnvCamera)||(m_nCameraErrorCode == Error_AllCamera)))
- {
- if ((ePadtype == m_eDeviceType)||(eMobilePadType == m_eDeviceType)||(eDesk2SType == m_eDeviceType)||(eDesk1SType == m_eDeviceType)||(eDesk2SIntegratedType == m_eDeviceType))
- {
- m_nCameraErrorCode = Error_Succeed;
- ChangeSysvar(m_nCameraErrorCode);
- }
- else
- {
- if (m_nCameraErrorCode == Error_EnvCamera)
- {
- m_nCameraErrorCode = Error_Succeed;
- ChangeSysvar(m_nCameraErrorCode);
- Dbg("changeSysvar to No_Error");
- }
- else if (m_nCameraErrorCode == Error_AllCamera)
- {
- m_nCameraErrorCode = Error_OptCamera;
- ChangeSysvar(m_nCameraErrorCode);
- Dbg("changeSysvar to Opt_Error");
- }
- }
- }
- //opt是否没有图像
- if (eStand2sType == m_eDeviceType)
- {
- if (opt_n == 0)
- {
- if (m_iOptEmptyTimes < CAMERA_BUG_THRESHOLD)
- {
- m_iOptEmptyTimes++;
- Dbg("get opt camera picture fail,Times=%d",m_iOptEmptyTimes);
- }
- }
- else if (opt_n == -1)
- {
- m_iOptEmptyTimes = CAMERA_BUG_THRESHOLD;
- }
- else
- {
- if (m_iOptEmptyTimes == CAMERA_BUG_THRESHOLD)
- {
- Dbg("opt camera get right!");
- }
- m_iOptEmptyTimes = 0;
- }
- }
-
- //opt图像是否超时
- if((nLastOptTime > 0)&&(eStand2sType == m_eDeviceType))
- {
- if(((y2k_time_now()-nLastOptTime) > CAMERA_TIMEOUT)&&!bOptTimeout)
- {
- bOptTimeout = true;
- Dbg("bOptTimeout");
- }
- else if (((y2k_time_now()-nLastOptTime) < CAMERA_TIMEOUT)&&bOptTimeout)
- {
- bOptTimeout = false;
- Dbg("change opt camera from bOptTimeout to OK");
- }
- }
- //opt是否100S没有图像或者图像20秒没有更新
- if(((m_iOptEmptyTimes == CAMERA_BUG_THRESHOLD) ||bOptTimeout)&&(m_nCameraErrorCode!=Error_OptCamera)&&(m_nCameraErrorCode!=Error_AllCamera)&&(eStand2sType == m_eDeviceType))
- {
- char strMessage[MAX_PATH*2] = {0};
- get_camera_exception_message(strMessage, MAX_PATH*2, conf.strVideoOpt, "Opt camera bug detected!");
- LogError(Severity_Middle, Error_Hardware, ERROR_MOD_MEDIACONTROLLER_OPECAMERA_BUG, strMessage);
- if (m_nCameraErrorCode == Error_Succeed)
- {
- m_nCameraErrorCode = Error_OptCamera;
- ChangeSysvar(m_nCameraErrorCode);
- }
- else if (m_nCameraErrorCode == Error_EnvCamera)
- {
- m_nCameraErrorCode = Error_AllCamera;
- ChangeSysvar(m_nCameraErrorCode);
- RealSelfCheck();
- return;
- }
- }
- else if((m_iOptEmptyTimes != CAMERA_BUG_THRESHOLD)&&!bOptTimeout&&((m_nCameraErrorCode == Error_OptCamera)||(m_nCameraErrorCode == Error_AllCamera))&&(eStand2sType == m_eDeviceType))
- {
- if (m_nCameraErrorCode == Error_OptCamera)
- {
- m_nCameraErrorCode = Error_Succeed;
- ChangeSysvar(m_nCameraErrorCode);
- Dbg("changeSysvar to No_Error");
- }
- else if (m_nCameraErrorCode == Error_AllCamera)
- {
- m_nCameraErrorCode = Error_EnvCamera;
- ChangeSysvar(m_nCameraErrorCode);
- Dbg("changeSysvar to Env_Error");
- }
- }
- //重启摄像头
- if((m_nCameraErrorCode == Error_EnvCamera)&&(m_nEnvCameraRestartNum<CAMERA_RESTARTNUM))
- {
- if (ReStartCamera(ENVCAMERA) != Error_Succeed)
- {
- m_nEnvCameraRestartNum++;
- }
- else
- {
- m_nEnvCameraRestartNum = 0;
- m_nCameraErrorCode = Error_Succeed;
- ChangeSysvar(m_nCameraErrorCode);
- m_iEnvEmptyTimes = 0;
- bEnvTimeout = false;
- }
- }
- else if((m_nCameraErrorCode == Error_OptCamera)&&(m_nOptCameraRestartNum<CAMERA_RESTARTNUM)&&(eStand2sType == m_eDeviceType))
- {
- if (ReStartCamera(OPTCAMERA) != Error_Succeed)
- m_nOptCameraRestartNum++;
- else
- {
- m_nOptCameraRestartNum = 0;
- m_nCameraErrorCode = Error_Succeed;
- ChangeSysvar(m_nCameraErrorCode);
- m_iOptEmptyTimes = 0;
- bOptTimeout = false;
- }
- }
- else if (m_nCameraErrorCode == Error_AllCamera)
- {
- if (m_nEnvCameraRestartNum<CAMERA_RESTARTNUM)
- {
- if (ReStartCamera(ENVCAMERA) != Error_Succeed)
- m_nEnvCameraRestartNum++;
- else
- {
- m_nEnvCameraRestartNum = 0;
- m_nCameraErrorCode = Error_OptCamera;
- ChangeSysvar(m_nCameraErrorCode);
- m_iEnvEmptyTimes = 0;
- bEnvTimeout = false;
- }
- }
- if((m_nOptCameraRestartNum<CAMERA_RESTARTNUM)&&(eStand2sType == m_eDeviceType))
- {
- if (ReStartCamera(OPTCAMERA) != Error_Succeed)
- m_nOptCameraRestartNum++;
- else
- {
- m_nOptCameraRestartNum = 0;
- m_iOptEmptyTimes = 0;
- bOptTimeout = false;
- if (m_nCameraErrorCode == Error_AllCamera)
- {
- m_nCameraErrorCode = Error_EnvCamera;
- ChangeSysvar(m_nCameraErrorCode);
- }
- else
- {
- m_nCameraErrorCode = Error_Succeed;
- ChangeSysvar(m_nCameraErrorCode);
- }
- }
- }
- }
- }
- bool SetAutoBright(ErrorCodeEnum nCode)
- {
- return capture_set_autobrightness(m_capture,nCode);
- }
- //camera gain adjust
- void OnReceivePkt(int sub_type, const char *buffer, int size)
- {
- if (sub_type == ACM_SET_CAMERABRIGHT)
- {
- if (m_bStartCamera)
- {
- if (eStand2sType == m_eDeviceType)
- {
- //vamera bright adj
- CCameraBrightValue num;
- SpBuffer buf;
- buf.OpenRead(buffer,size);
- num.Serialize(buf);
- Dbg("recv ACM_SET_CAMERABRIGHT = %d",num.nValue);
- if (capture_adj_brightness(m_capture,num.nValue,m_nCameraErrorCode) == true)
- {
- Dbg("ACM_SET_CAMERABRIGHT success!");
- SendCameraBright();
- }
- else
- {
- Dbg("ACM_SET_CAMERABRIGHT fail!");
- }
- }
- else
- {
- Dbg("pad type cannot adj brightness");
- }
- }
- else
- {
- Dbg("the camera not start!");
- }
- }
- }
- 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;
- }
- void SendCameraBright()
- {
- if (m_nSysCallType == 0)
- {
- ChannelService_Send_Info Info;
- Info.compress = false;
- Info.encrypt = false;
- Info.type = ACM_TYPE_DEVICE;
- Info.id = 0;
- Info.sub_type = ACM_CAMERA_BRIGHT;
- Info.data.Alloc(sizeof(int));
- SpBuffer buf;
- buf.OpenWrite();
- int nValue = 0;
- bool rslt = true;
- nValue = capture_get_brightness(m_capture,m_nCameraErrorCode);
- if (nValue >= 0)
- {
- buf & nValue;
- Info.data = buf.ToBlob();
- m_pMediaControllerChannel->Send(Info);
- Dbg("send cur camera bright value = %d",nValue);
- }
- else
- {
- Dbg("send cur camera bright value Fail!");
- }
- }
- else
- {
- Dbg("cur call type cannot send pkt");
- }
- }
- ErrorCodeEnum StartEnvCamera()
- {
- LOG_FUNCTION();
- ErrorCodeEnum Error = Error_Succeed;
- if (FALSE == m_bStartCamera){
- Error = StartCamera();
- if (Error_Succeed == Error){
- SetCameraSysVar(CAMERA_NO_ERROR);
- Dbg("Camera State to CAMERA_NO_ERROR");
- m_bStartCamera = TRUE;
- }
- }
- else{
- Dbg("camera already start.");
- }
- return Error;
- }
- ErrorCodeEnum StopEnvCamera()
- {
- LOG_FUNCTION();
- if (m_capture){
- GetFunction()->KillTimer(1);
- capture_stop(m_capture);
- capture_destroy(m_capture);
- m_capture = NULL;
- }
- m_bStartCamera = FALSE;
- return Error_Succeed;
- }
- bool m_bSendCameraError;
- int m_iEnvEmptyTimes;
- int m_iOptEmptyTimes;
- int m_nEnvCameraRestartNum;
- int m_nOptCameraRestartNum;
- private:
- ErrorCodeEnum LoadRunConfig(CSimpleStringA& frontcam, CSimpleStringA& rearcam)
- {
- CSmartPointer<IEntityFunction> spFunction = GetFunction();
- CSmartPointer<IConfigInfo> spConfig;
- ErrorCodeEnum Error = spFunction->OpenConfig(Config_Run, spConfig);
- if (Error == Error_Succeed) {
- SpIniMappingTable table;
- table.AddEntryString("Video", "FrontCamera", frontcam, "$");
- table.AddEntryString("Video", "RearCamera", rearcam, "$");
- 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 CheckConfigCameraName(capture_config_t *conf){
- ErrorCodeEnum Error = Error_Succeed;
- int EnvConfigNameError = 0; //0:环境摄像头配置名能成功打开 -1:环境摄像头配置名不能打开 1:未配置环境摄像头名字
- int OptConfigNameError = 0; //0:操作摄像头配置名能成功打开 -1:操作摄像头配置名不能打开 1:未配置操作摄像头名字
- //check env device
- if (conf->strVideoEnv.GetLength() > 1)
- { // is not "$"
- conf->video_env_dev = capture_get_video_device_id(conf->strVideoEnv);
- if (conf->video_env_dev == -1)
- {
- Dbg("find strVideoEnv:%s(-1)",(LPCTSTR)conf->strVideoEnv);
- EnvConfigNameError = -1;
- }
- } else
- {
- conf->video_env_dev = -1;
- EnvConfigNameError = 1;
- }
- //check opt device
- if (conf->strVideoOpt.GetLength() > 1)
- { // is not "$"
- conf->video_opt_dev = capture_get_video_device_id(conf->strVideoOpt);
- if (conf->video_opt_dev == -1)
- {
- Dbg("find strVideoOpt:%s(-1)",(LPCTSTR)conf->strVideoOpt);
- OptConfigNameError = -1;
- }
- }
- else
- {
- conf->video_opt_dev = -1;
- OptConfigNameError = 1;
- }
- //环境摄像头配置名不能打开
- if (EnvConfigNameError == -1){
- //操作摄像头配置名不能打开,此时表明摄像头都不可用
- if(OptConfigNameError == -1){
- Error = Error_AllCamera;
- }
- //未配置操作摄像头名字or操作摄像头配置名能打开,此时表明只有操作摄像头OK
- else{
- Error = Error_EnvCamera;
- }
- }
- //环境摄像头配置名能打开
- else if (EnvConfigNameError == 0){
- //操作摄像头配置名不能打开,此时表明只有环境摄像头OK
- if (OptConfigNameError == -1){
- Error = Error_OptCamera;
- }
- //环境摄像头配置名能打开,未配置操作摄像头名字,此时也认为摄像头都OK(无操作摄像头场景)
- }
- //环境摄像头未配置
- else {
- //操作摄像头配置名不能打开,此时表明只有操作摄像头OK
- if(OptConfigNameError == -1){
- Error = Error_OptCamera;
- }
- //操作摄像头未配置,此时表明摄像头都不可用
- else if (OptConfigNameError == 1){
- Error = Error_AllCamera;
- }
- //操作摄像头名字能打开,此时也认为摄像头都OK(无环境摄像头场景)
- }
-
- return Error;
- }
- ErrorCodeEnum GetSalesAudioConfig(rvc_audio_capture_config_t *conf, bool bRemoteRecord)
- {
- CSmartPointer<IEntityFunction> spFunction = GetFunction();
- CSmartPointer<IConfigInfo> spConfig;
- SpIniMappingTable table;
- ErrorCodeEnum Error = spFunction->OpenConfig(Config_Root, spConfig);
- if (Error == Error_Succeed) {
- CSimpleStringA strAudioInDevice;
- table.AddEntryString("Audio", "sales_record_in_dev", conf->strAudioIn, "$");
- table.AddEntryString("Audio", "handfree_in_dev", strAudioInDevice, "$");
- table.AddEntryString("Audio", "handfree_out_dev", conf->strAudioOut, "$");
- Error = table.Load(spConfig);
- if (Error == Error_Succeed){
- conf->audio_capture_period = CAPTURE_FRAME_TIME;
- conf->audio_capture_samplerate = m_nSalesAudioSmpPsec;
- if (conf->strAudioIn==""){
- conf->strAudioIn = strAudioInDevice;
- }
- }
- else {
- LOG_TRACE("load sales audio device config failed!");
- }
- }
- else {
- LOG_TRACE("open sales audio device config failed!");
- }
- if (Error_Succeed != Error){
- Dbg("get sales audio device info failed, now get from default value.");
- m_sales_audio_conf.strAudioIn = this->conf.strAudioIn;
- m_sales_audio_conf.audio_capture_period = CAPTURE_FRAME_TIME;
- m_sales_audio_conf.audio_capture_samplerate = CAPTURE_CLOCK;
- Error = Error_Succeed;
- }
- conf->audio_capture_samplerate = CAPTURE_CLOCK*2;
- if (true == bRemoteRecord){
- if (CAPTURE_CLOCK*2 == m_sales_audio_conf.audio_capture_samplerate){
- m_sales_audio_conf.audio_capture_samplerate = CAPTURE_CLOCK;
- Dbg("remote record, change audio sample rate to from %d to %d.", CAPTURE_CLOCK*2, m_sales_audio_conf.audio_capture_samplerate);
- }
- }
- return Error;
- }
- ErrorCodeEnum LoadConfig(capture_config_t *conf)
- {
- CSmartPointer<IEntityFunction> spFunction = GetFunction();
- CSmartPointer<IConfigInfo> spConfig;
- SpIniMappingTable table;
- strEwsCam = "$";
- ErrorCodeEnum Error = spFunction->OpenConfig(Config_Root, spConfig);
- if (Error == Error_Succeed) {
- table.AddEntryString("Audio", "handfree_in_dev", conf->strAudioIn, "$");
- table.AddEntryString("Audio", "handfree_out_dev", conf->strAudioOut, "$");
- table.AddEntryString("Video", "EnvCamera", conf->strVideoEnv, "$");
- table.AddEntryString("Video", "OptCamera", conf->strVideoOpt, "$");
- table.AddEntryString("Video", "EwsCamera", strEwsCam, "$");
- table.AddEntryInt("Video", "EnvRotate", conf->video_env_rotate, 0);
- table.AddEntryInt("Video", "OptRotate", conf->video_opt_rotate, 0);
- Error = table.Load(spConfig);
- if (Error == Error_Succeed)
- {
- //进行Camera路径名自纠正后再检查
- AutoCorrectCameraConfigName(5000);
- Error = CheckConfigCameraName(conf);
- if (Error == Error_EnvCamera || Error == Error_AllCamera){
- char strMessage[MAX_PATH*2] = {0};
- get_camera_exception_message(strMessage, MAX_PATH*2, conf->strVideoEnv ,"env camera start error,please check config file or device.");
- LogError(Severity_High,Error_DevMedia,ERROR_MOD_MEDIACONTROLLER_ENVCAM_INITFAIL,strMessage);
- } else if (Error == Error_OptCamera){
- char strMessage[MAX_PATH*2] = {0};
- get_camera_exception_message(strMessage, MAX_PATH*2, conf->strVideoOpt, "operation camera start error,please check config file or device.");
- LogError(Severity_High,Error_DevMedia,ERROR_MOD_MEDIACONTROLLER_OPTCAM_INITFAIL, strMessage);
- }
- }
- else
- {
- LOG_TRACE("load config failed!");
- }
- }
- else
- {
- LOG_TRACE("open config failed!");
- }
- return Error;
- }
- // 外接摄像头启动失败 edit by ly 2018/03/08
- void OnExternalCameraSwitchFailed(const char* pszFailedMsg)
- {
- // 广播给业务系统
- ExternalCameraSwitchFailed evt;
- evt.failedmsg = CSimpleStringA2W(pszFailedMsg);
- SpSendBroadcast(GetFunction(), SP_MSG_OF(ExternalCameraSwitchFailed), SP_MSG_SIG_OF(ExternalCameraSwitchFailed), evt);
- Dbg("[dbg] ExternalCameraSwitchFailed broadcast sent!");
- CSmartPointer<IEntityFunction> Func = GetFunction();
- CSimpleStringA strValue;
- Func->GetSysVar("DesktopType", strValue);
- if (strValue == CSimpleStringA("U")) {
- #ifdef RVC_OS_WIN
- MessageBoxA(NULL, pszFailedMsg, NULL, MB_SYSTEMMODAL);
- #else
- #endif // RVC_OS_WIN
- }
- }
- // comment by ly@2019/03/19
- //ErrorCodeEnum TryStartCamera()
- //{
- // Dbg("[dbg] StartExternalCamera");
- // ErrorCodeEnum errorCode = StartUSBCamera();
- // Dbg("StartExternalCamera:0x%x", errorCode);
- // int nRetCod = 5;
- // switch(errorCode)
- // {
- // case Error_Succeed:
- // {
- // nRetCod = 0; // 正常
- // /// add by ly at 20161017
- // /// notify to rvcweb that outer camera switch has finished
- // ExternalCameraStateChanged evt;
- // evt.statemsg = CSimpleStringA2W("已切换到外接摄像头!");
- // evt.camname = CSimpleStringA2W(strUSBCam);
- // SpSendBroadcast(GetFunction(), SP_MSG_OF(ExternalCameraStateChanged), SP_MSG_SIG_OF(ExternalCameraStateChanged), evt);
- // Dbg("[dbg] ExternalCameraStateChanged broadcast sent!");
- // }
- // break;
- // case Error_Resource:
- // nRetCod = 1; // 外接摄像头未插入
- // break;
- // case Error_EnvCamera:
- // case Error_AllCamera:
- // nRetCod = 2; // 外接摄像头启动失败
- // OnExternalCameraSwitchFailed(SwitchFailed_StartFault);
- // break;
- // case Error_DevNotAvailable:
- // nRetCod = 3; // 检测到一个外接摄像头,但无法分辨名称
- // OnExternalCameraSwitchFailed(SwitchFailed_Ambiguous);
- // break;
- // case Error_Duplication:
- // nRetCod = 4; // 检测到两个以上外接摄像头
- // OnExternalCameraSwitchFailed(SwitchFailed_NoUnique);
- // break;
- // default:
- // nRetCod = 5; // 其他错误
- // OnExternalCameraSwitchFailed(SwitchFailed_StartFault);
- // break;
- // }
- // if (m_bStartCamera == FALSE) // 外接没启动成,如果内置没启动,切换到内置
- // {
- // SetCameraSysVar(CAMERA_START_ING);
- // ExternalCameraStateChanged evt;
- // evt.statemsg = CSimpleStringA2W("无法启动外接,内置切换中……");
- // evt.camname = CSimpleStringA2W(strEnvCam);
- // SpSendBroadcast(GetFunction(), SP_MSG_OF(ExternalCameraStateChanged), SP_MSG_SIG_OF(ExternalCameraStateChanged), evt);
- // Dbg("[dbg] ExternalCameraStateChanged broadcast sent!");
- // return StopUSBCamera();
- // }
- // return Error_Succeed;
- //}
- 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 = %08x", dwUserCode);
- switch (dwUserCode)
- {
- case MOD_EVENT_SNAPSHOT_START_CAPTURE_ENVOPT:
- {
- Dbg("recv MOD_EVENT_SNAPSHOT_START_CAPTURE_ENVOPT");
- InterlockedCompareExchange(&m_lCaptureEnvOptCount, 3, 0);
- }
- break;
- case MOD_EVENT_SNAPSHOT_START_CAPTURE_ENV:
- {
- Dbg("recv MOD_EVENT_SNAPSHOT_START_CAPTURE_ENV");
- InterlockedCompareExchange(&m_lCaptureEnvCount, 1, 0);
- }
- break;
- case MOD_EVENT_SNAPSHOT_START_CAPTURE_OPT:
- {
- Dbg("recv MOD_EVENT_SNAPSHOT_START_CAPTURE_OPT");
- InterlockedCompareExchange(&m_lCaptureOptCount, 1, 0);
- }
- break;
- case LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE:
- {
- Dbg("recv LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE");
- if (m_pMediaControllerChannel!=NULL)
- {
- m_pMediaControllerChannel->GetFunction()->CloseSession();
- m_pMediaControllerChannel->SafeDelete();
- m_pMediaControllerChannel = NULL;
- Dbg("Close AssistChannel Session ");
- }
- if (m_pMediaControllerChannel == NULL)
- {
- Dbg("ReConnection AssistChannel Session");
- m_pMediaControllerChannel = new ChannelMediaControllerClient(this);
- ErrorCodeEnum Error = m_pMediaControllerChannel->Connect();
- if (Error != Error_Succeed)
- {
- m_pMediaControllerChannel->SafeDelete();
- m_pMediaControllerChannel = NULL;
- Dbg("AssistChannelClient connect fail!");
- }
- if (Error == Error_Succeed)
- {
- ChannelService_BeginRecv_Sub Sub;
- Sub.type = ACM_TYPE_DEVICE;
- Error = m_pMediaControllerChannel->BeginRecv(Sub);
- if (Error != Error_Succeed)
- {
- m_pMediaControllerChannel->GetFunction()->CloseSession();
- m_pMediaControllerChannel->SafeDelete();
- m_pMediaControllerChannel = NULL;
- }
- }
- if (Error == Error_Succeed)
- {
- ChannelService_BeginState_Sub Sub;
- Error = m_pMediaControllerChannel->BeginState(Sub);
- if (Error != Error_Succeed)
- {
- LOG_TRACE("BeginState biz channel failed!");
- m_pMediaControllerChannel->GetFunction()->CloseSession();
- m_pMediaControllerChannel->SafeDelete();
- m_pMediaControllerChannel = NULL;
- }
- }
- }
- }
- break;
- case EVENT_MOD_CUSTOMERAWARE_BEGIN:
- {
- m_bCustomerwareBegin = true;
- if (/*m_bIsPadType&&*/!m_bStartCamera&&!m_bExternControlCam)
- {
- // comment by ly@2019/03/19
- //if ((ePadtype == m_eDeviceType)||(eMobilePadType == m_eDeviceType)||(eDesk2SType == m_eDeviceType))
- //{
- // TryStartCamera();
- //}
- //else
- {
- StartCameraAndTiggerRecord(pszMessage);
- }
- }
- }
- break;
- case EVENT_MOD_CUSTOMERAWARE_END:
- {
- m_bCustomerwareBegin = false;
- if (/*m_bIsPadType&&*/m_bStartCamera&&!m_bExternControlCam)
- {
- Dbg("stop camera");
- if (m_capture)
- {
- LogEvent(Severity_Middle, EVENT_MOD_END_RECORD,pszMessage);
- GetFunction()->KillTimer(1);
- capture_stop(m_capture);
- capture_destroy(m_capture);
- m_capture = NULL;
- }
- m_bStartCamera = FALSE;
- }
- }
- break;
- case EVENT_USB_CAMER_INPUT: // add by ly at 20160329
- {
- Dbg("[dbg] usbcam %s inserted.", pszMessage);
- //huchen add for support usb inout,camera config AutoCorrect
- if (m_bCustomerwareBegin){
- if (/*m_bIsPadType&&*/!m_bStartCamera&&!m_bExternControlCam) {
- CSimpleStringA strSessionId;
- CSmartPointer<IEntityFunction> Func = GetFunction();
- Func->GetSysVar("SessionID", strSessionId);
- StartCameraAndTiggerRecord((LPCTSTR)strSessionId);
- }
- }
-
- // comment by ly@2019/03/19
- //::Sleep(2000); // 延迟2s后判断
- //// 如果不是广角摄像头 edit by ly at 20161216
- //if(!strstr((LPCTSTR)strEwsCam,pszMessage))
- //{
- // if (strUSBCam.GetLength() <= 1)
- // {
- // strUSBCam = pszMessage;
- // // 对低柜双屏版屏蔽外接摄像头插入事件 edit by ly@2018/10
- // if (eDesk2SType != m_eDeviceType)
- // {
- // // 广播给业务系统
- // ExternalCameraInserted evt;
- // evt.camname = CSimpleStringA2W(strUSBCam);
- // SpSendBroadcast(GetFunction(), SP_MSG_OF(ExternalCameraInserted), SP_MSG_SIG_OF(ExternalCameraInserted), evt);
- // Dbg("[dbg] ExternalCameraInserted broadcast sent!");
- // }
- // /// add by ly at 20161017
- // /// notify to rvcweb that outer camera is switching
- // SetCameraSysVar(CAMERA_START_ING);
- // ExternalCameraStateChanged evt1;
- // evt1.statemsg = CSimpleStringA2W("外接摄像头切换中,请稍等……");
- // evt1.camname = CSimpleStringA2W(strUSBCam);
- // SpSendBroadcast(GetFunction(), SP_MSG_OF(ExternalCameraStateChanged), SP_MSG_SIG_OF(ExternalCameraStateChanged), evt1);
- // Dbg("[dbg] ExternalCameraStateChanged broadcast sent!");
- // TryStartCamera();
- // }
- // else
- // {
- // Dbg("[dbg] more than one USBCam inserted!");
- // }
- //}
- }
- break;
- case EVENT_USB_CAMER_OUTPUT: // add by ly at 20160329
- {
- Dbg("[dbg] usb cam %s removed.", pszMessage);
- int nEnv = capture_get_video_device_id((LPCTSTR)conf.strVideoEnv);
- // comment by ly@2019/03/19
- //if(strstr((LPCTSTR)conf.strVideoEnv,pszMessage))
- if(nEnv<0)
- {
- // 对低柜双屏版屏蔽外接摄像头拔出事件 edit by ly@2018/10
- if (eDesk2SType != m_eDeviceType)
- {
- // 广播给业务系统
- ExternalCameraRemoved evt;
- // comment by ly@2019/03/19
- //evt.camname = CSimpleStringA2W(strUSBCam);
- evt.camname = CSimpleStringA2W(pszMessage);
- SpSendBroadcast(GetFunction(), SP_MSG_OF(ExternalCameraRemoved), SP_MSG_SIG_OF(ExternalCameraRemoved), evt);
- Dbg("[dbg] ExternalCameraRemoved broadcast sent!");
- }
- // comment by ly@2019/03/19
- //// add by ly at 20161110
- //// notify to rvcweb that inner camera is switching
- //SetCameraSysVar(CAMERA_START_ING);
- //ExternalCameraStateChanged evt1;
- //evt1.statemsg = CSimpleStringA2W("内置摄像头启动中,请稍等……");
- //evt1.camname = CSimpleStringA2W(strEnvCam);
- //SpSendBroadcast(GetFunction(), SP_MSG_OF(ExternalCameraStateChanged), SP_MSG_SIG_OF(ExternalCameraStateChanged), evt1);
- //Dbg("[dbg] ExternalCameraStateChanged broadcast sent!");
- //
- //::Sleep(1000); // 延迟1s后切换内置
- //// 如果当前正在使用外接摄像头,则停用之
- //Dbg("[dbg] stop external camera.");
- //StopUSBCamera();
- // 停止摄像头 add by ly@2019/03/19
- if (m_bStartCamera&&!m_bExternControlCam)
- {
- Dbg("stop camera");
- if (m_capture)
- {
- LogEvent(Severity_Middle, EVENT_MOD_END_RECORD,pszMessage);
- GetFunction()->KillTimer(1);
- capture_stop(m_capture);
- capture_destroy(m_capture);
- m_capture = NULL;
- }
- m_bStartCamera = FALSE;
- }
- }
- else
- {
- Dbg("[dbg] USBCam(%s) is not the one used now!",pszMessage);
- }
- //strUSBCam = "$";
- }
- break;
- case EVENT_USB_CAMERA_NOT_ONLY: // add by ly at 20160707
- {
- Dbg("[dbg] more than one usb cam detected.");
- OnExternalCameraSwitchFailed(SwitchFailed_NoUnique);
- }
- break;
- case LOG_EVT_RECORDFAILED: // add by ly at 20160713(edit by ly@2018/06/08)
- {
- Dbg("[dbg] record failed event.");
- //GetFunction()->KillTimer(1);
- //if (m_bIsPadType)
- //{
- // LogEvent(Severity_Middle, LOG_EVT_UI_STOPRECORD, NULL);
- // m_nCameraErrorCode = Error_EnvCamera;
- // ChangeSysvar(m_nCameraErrorCode);
- // //重启ENV摄像头
- // if((m_nCameraErrorCode == Error_EnvCamera)&&(m_nEnvCameraRestartNum<CAMERA_RESTARTNUM))
- // {
- // Dbg("[dbg] Restart EnvCamera as Error_EnvCamera.");
- // if (ReStartCamera(ENVCAMERA) != Error_Succeed)
- // {
- // m_nEnvCameraRestartNum++;
- // }
- // else
- // {
- // m_nEnvCameraRestartNum = 0;
- // m_nCameraErrorCode = Error_Succeed;
- // ChangeSysvar(m_nCameraErrorCode);
- // m_iEnvEmptyTimes = 0;
- // }
- // }
- //}
- //else
- //{
- // LogEvent(Severity_Middle, EVENT_MOD_END_RECORD,NULL);
- // //重启ENV摄像头
- // if(m_nEnvCameraRestartNum<CAMERA_RESTARTNUM)
- // {
- // if (ReStartCamera(ENVCAMERA) != Error_Succeed)
- // {
- // m_nEnvCameraRestartNum++;
- // m_nCameraErrorCode = Error_EnvCamera;
- // ChangeSysvar(m_nCameraErrorCode);
- // }
- // else
- // {
- // m_nEnvCameraRestartNum = 0;
- // m_nCameraErrorCode = Error_Succeed;
- // ChangeSysvar(m_nCameraErrorCode);
- // m_iEnvEmptyTimes = 0;
- // }
- // }
- // //重启OPT摄像头
- // if(m_nEnvCameraRestartNum<CAMERA_RESTARTNUM)
- // {
- // if (ReStartCamera(OPTCAMERA) != Error_Succeed)
- // {
- // m_nEnvCameraRestartNum++;
- // m_nCameraErrorCode = Error_OptCamera;
- // ChangeSysvar(m_nCameraErrorCode);
- // }
- // else
- // {
- // m_nEnvCameraRestartNum = 0;
- // m_nCameraErrorCode = Error_Succeed;
- // ChangeSysvar(m_nCameraErrorCode);
- // m_iEnvEmptyTimes = 0;
- // }
- // }
- //}
- //GetFunction()->SetTimer(1, this, 5000);
- GetFunction()->KillTimer(1);
- //edit by ly @2018/01/17
- LogEvent(Severity_Middle, EVENT_MOD_END_RECORD, NULL);
- char FaildFlag = pszMessage[0];
- if (FaildFlag == '0')
- {
- GetFunction()->SetTimer(1, this, 5000);
- OnExternalCameraSwitchFailed("本地录音录像失败,已停止!");
- }
- else //if (FaildFlag == '1')
- {
- OnExternalCameraSwitchFailed("本地录音录像设备故障,尝试恢复中(预计10s内),请稍等");
- m_nCameraErrorCode = Error_AllCamera;
- RealSelfCheck(); // 录音录像失败,强行kill实体
- }
- }
- break;
- case LOG_EVT_UI_RECORDFAILED: // add by ly@2018/06/08
- {
- Dbg("[dbg] sales record failed event.");
- GetFunction()->KillTimer(1);
- if (m_bIsRemoteRecord){
- LogEvent(Severity_Middle, LOG_EVT_UI_STOPREMOTERECORD, NULL);
- }
- else{
- LogEvent(Severity_Middle, LOG_EVT_UI_STOPRECORD, NULL);
- }
-
- char FaildFlag = pszMessage[0];
- if (FaildFlag == '0')
- {
- GetFunction()->SetTimer(1, this, 5000);
- OnExternalCameraSwitchFailed("现场销售录音录像失败,已停止!");
- }
- else //if (FaildFlag == '1')
- {
- OnExternalCameraSwitchFailed("现场销售录音录像设备故障,尝试恢复中(预计10s内),请稍等");
- m_nCameraErrorCode = Error_AllCamera;
- RealSelfCheck(); // 录音录像失败,强行kill实体
- }
- }
- break;
- case LOG_EVT_BEGIN_CAMERA_CONFIG:
- {
- ExternStopCamera();
- }
- break;
- case LOG_EVT_END_CAMERA_CONFIG:
- {
- ExternStartCamera();
- }
- break;
- case LOG_EVT_UI_STARTREMOTERECORD:
- {
- m_bIsRemoteRecord = true;
- HandleRemoteRecord(pszMessage);
- }
- break;
- case LOG_EVT_UI_STOPREMOTERECORD:
- {
- m_bIsRemoteRecord = false;
- if (Error_Succeed == StopSalesRecordAudioCapture()){
- Dbg("stop remote sales record audio capture.");
- }
- if (true == m_bHasStartSpeakerRender){
- StopSpeakerAudioRender();
- }
- }
- break;
- //case EVENT_MOD_CONNECT_STOP_RECORD_BROADCAST:
- // {
- // if (eStand2sType == m_eDeviceType){
- // StopSpeakerAudioRender();
- // }
- // }
- // break;
- case LOG_EVT_UI_STARTRECORD:
- case LOG_EVT_UI_STARTRECORDPREVIEW:
- {
- m_bIsRemoteRecord = false;
- if (false == m_bRecordPCM){
- if (Error_Succeed == StartSalesRecordAudioCapture()){
- Dbg("begin remote sales record audio capture.");
- }
- }
- else{
- HandleSalesRecordPCMAudio(false, pszMessage);
- }
- }
- break;
- case LOG_EVT_UI_STOPRECORD:
- {
- if (Error_Succeed == StopSalesRecordAudioCapture()){
- Dbg("stop sales record audio capture.");
- }
- }
- break;
- case LOG_EVT_START_CONTINURECORD:
- {
- Dbg("receive LOG_EVT_START_CONTINURECORD event.");
- }
- break;
- case LOG_EVT_STOP_CONTINURECORD:
- {
- Dbg("receive LOG_EVT_STOP_CONTINURECORD event.");
- }
- break;
- default:
- Dbg("unknown event.");
- break;
- }
- }
- virtual void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- if (Test_ShakeHand == eTestType)
- {
- if (m_nCameraErrorCode == Error_AllCamera)
- {
- pTransactionContext->SendAnswer(Error_DevMedia);
- }
- else
- {
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- }
- }
- //获取当前使用摄像头,30分钟轮休一次
- int GetActiveCamera()
- {
- #ifdef RVC_OS_WIN
- SYSTEMTIME st;
- GetLocalTime(&st);
- if (st.wMinute <= CAMERA_CHANGE_TIMER)
- {
- return ENVCAMERA;
- }
- else if (st.wMinute > CAMERA_CHANGE_TIMER)
- {
- return OPTCAMERA;
- }
- #else
- return ENVCAMERA;
- #endif // RVC_OS_WIN
- }
- ErrorCodeEnum ChangeSysvar(ErrorCodeEnum op)
- {
- switch (op)
- {
- case Error_Succeed:
- Dbg("Camera State to No_Error");
- //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_NO_ERROR);
- SetCameraSysVar(CAMERA_NO_ERROR);
- GetFunction()->SetUserDefineState(USER_MEDIA_IDLE);
- break;
- case Error_EnvCamera:
- Dbg("Camera State to Env_Error");
- //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_ENV_ERROR);
- SetCameraSysVar(CAMERA_ENV_ERROR);
- GetFunction()->SetUserDefineState(USER_MEDIA_ENVERRROR);
- capture_clearsnapshotvideo(m_capture,ENVCAMERA);
- break;
- case Error_OptCamera:
- Dbg("Camera State to Opt_Error");
- //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_OPT_ERROR);
- SetCameraSysVar(CAMERA_OPT_ERROR);
- GetFunction()->SetUserDefineState(USER_MEDIA_OPTERROR);
- capture_clearsnapshotvideo(m_capture,OPTCAMERA);
- break;
- case Error_AllCamera:
- Dbg("Camera State to Both_Error");
- //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_BOTH_ERROR);
- SetCameraSysVar(CAMERA_BOTH_ERROR);
- GetFunction()->SetUserDefineState(USER_MEDIA_ALLERROR);
- capture_clearsnapshotvideo(m_capture,AlLCAMERA);
- break;
- default:
- break;
- }
- return Error_Succeed;
- }
- void AutoCorrectCameraConfigName(long wait_time) {
- ErrorCodeEnum Error = Error_Succeed;
- int one_timeout = 400;
- int retry = 0;
- //检查配置名都成功,不用自动纠正
- Error = CheckConfigCameraName(&conf);
- if (Error == Error_Succeed){
- return;
- }
- //只针对低柜双屏做自纠正
- if(eDesk2SType != m_eDeviceType){
- Dbg("AutoCorrectCameraConfig failed, DeviceType:%d is not Desk2SType", m_eDeviceType);
- return;
- }
- auto pCameraConfigManageClient = new CameraConfigManageService_ClientBase(this);
- while ((pCameraConfigManageClient->Connect() != Error_Succeed) && retry < wait_time/one_timeout)
- {
- Dbg("连接CameraConfigManage实体失败, retry:%d", retry);
- Sleep(one_timeout);
- retry++;
- }
- //连接不上,不纠正
- if (retry >= wait_time/one_timeout){
- pCameraConfigManageClient->SafeDelete();
- pCameraConfigManageClient = NULL;
- }
- else {
- CameraConfigManageService_AutoCorrectCameraConfig_Req req;
- CameraConfigManageService_AutoCorrectCameraConfig_Ans ans;
- DWORD Timeout = 5000;
- Error = pCameraConfigManageClient->AutoCorrectCameraConfig(req, ans, Timeout);
- if (Error != Error_Succeed)
- {
- Dbg("CameraConfigManage 调用 AutoCorrectCameraConfig 失败: 0x%x", Error);
- }
- else
- {
- Dbg("AutoCorrectCameraConfig, old EnvCamera;%s, OptCamera;%s, EwsCamera;%s",
- (LPCSTR)conf.strVideoEnv, (LPCSTR)conf.strVideoOpt, (LPCSTR)strEwsCam);
- Dbg("AutoCorrectCameraConfig, get new EnvCamera;%s, OptCamera;%s, EwsCamera;%s",
- (LPCSTR)ans.EnvCamera, (LPCSTR)ans.OptCamera, (LPCSTR)ans.EwsCamera);
- if ((ans.EnvCamera.GetLength() > 1) && (conf.strVideoEnv.GetLength() > 1)){
- conf.strVideoEnv = ans.EnvCamera;
- }
- if ((ans.OptCamera.GetLength() > 1) && (conf.strVideoOpt.GetLength() > 1)){
- conf.strVideoOpt = ans.OptCamera;
- }
- if ((ans.EwsCamera.GetLength() > 1) && (strEwsCam.GetLength() > 1)){
- strEwsCam = ans.EwsCamera;
- }
- Dbg("AutoCorrectCameraConfig, updated EnvCamera;%s, OptCamera;%s, EwsCamera;%s",
- (LPCSTR)conf.strVideoEnv, (LPCSTR)conf.strVideoOpt, (LPCSTR)strEwsCam);
- }
- pCameraConfigManageClient->GetFunction()->CloseSession();
- pCameraConfigManageClient->SafeDelete();
- pCameraConfigManageClient = NULL;
- }
- }
- //开始销售双录音频采集函数
- ErrorCodeEnum StartSalesRecordAudioCapture(bool bRemoteRecord = false, eRvcPCMTransType eType = eUnKnown, void* pData = NULL)
- {
- ErrorCodeEnum Error = Error_Succeed;
- if (NULL == m_salesaudio_capture){
- memset(&m_sales_audio_conf, 0, sizeof(m_sales_audio_conf));
- GetSalesAudioConfig(&m_sales_audio_conf, bRemoteRecord);
- Error = (ErrorCodeEnum)salesaudio_capture_create(&m_sales_audio_conf, &m_salesaudio_capture);
- if (Error_Succeed == Error){
- Error = SetSalesRecordAudioCaptureTransActionData(eType, pData);
- }
- }
- if (Error_Succeed == Error){
- Error = salesrecord_audio_capture_start(m_salesaudio_capture);
- if (Error_Succeed == Error){
- Dbg("sales record audio capture start success.");
- }
- else{
- Dbg("sales record audio capture start failed for param error.");
- }
- }
- return Error;
- }
- //停止销售双录音频采集函数
- ErrorCodeEnum StopSalesRecordAudioCapture()
- {
- salesrecord_audio_capture_stop(m_salesaudio_capture);
- salesaudio_capture_destroy(m_salesaudio_capture);
- m_salesaudio_capture = NULL;
- Dbg("set m_salesaudio_capture to null.");
- return Error_Succeed;
- }
- ErrorCodeEnum StartCamera()
- {
- if (m_capture == NULL)
- {
- //打开前检查配置摄像头名字是否能被打开并自纠正
- AutoCorrectCameraConfigName(4000);
-
- ErrorCodeEnum Error = Error_Succeed;
- conf.ref_env_capture_count = &m_lCaptureEnvCount;
- conf.ref_opt_capture_count = &m_lCaptureOptCount;
- conf.ref_envopt_capture_count = &m_lCaptureEnvOptCount;
- Error = (ErrorCodeEnum)capture_create(&conf, &m_capture);
- if (Error == Error_Succeed)
- {
- Error = capture_start(m_capture);
- Dbg("capture_start Error code=0x%x",Error);
- if (Error != Error_Succeed)
- {
- if((Error == Error_AudioIN)||(Error == Error_AudioOut))
- {
- return Error;
- }
- else if (Error == Error_AllCamera)
- {
- capture_destroy(m_capture);
- m_capture = NULL;
- return Error;
- }
- else
- {
- SetAutoBright(Error);
- GetFunction()->SetTimer(1, this, 5000);
- if((Error == Error_OptCamera)&&((ePadtype == m_eDeviceType)||(eMobilePadType == m_eDeviceType)||(eDesk2SType == m_eDeviceType)||(eDesk1SType == m_eDeviceType)||(eDesk2SIntegratedType == m_eDeviceType)))
- {
- return Error_Succeed;
- }
- else
- {
- return Error;
- }
- }
- }
- else
- {
- SetAutoBright(Error);
- GetFunction()->SetTimer(1, this, 5000);
- return Error_Succeed;
- }
- }
- else
- {
- Dbg("create capture failed! %d", Error);
- m_capture = NULL;
- return Error_Unexpect;
- }
- return Error;
- }
- else
- {
- Dbg("m_capture == NULL");
- return Error_Unexpect;
- }
- }
- ErrorCodeEnum StartCamera(int nCamera)
- {
- if (m_capture == NULL)
- {
- //打开前检查配置摄像头名字是否能被打开并自纠正
- AutoCorrectCameraConfigName(4000);
-
- ErrorCodeEnum Error = Error_Succeed;
- Error = capture_create(&conf, m_capture,nCamera);
- if (Error == Error_Succeed)
- {
- return capture_start(m_capture,nCamera);
- }
- else
- {
- return Error_Hardware;
- }
- }
- else
- {
- return Error_Unexpect;
- }
- }
- void StartCameraAndTiggerRecord(const char * strSessionId){
- Dbg("start camera");
- ErrorCodeEnum Error;
- Error = StartCamera();
- if (Error == Error_Succeed)
- {
- //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_NO_ERROR);
- SetCameraSysVar(CAMERA_NO_ERROR);
- Dbg("Camera State to CAMERA_NO_ERROR");
- m_bStartCamera = TRUE;
- LogEvent(Severity_Middle, EVENT_MOD_BEGIN_RECORD,strSessionId);
- }
- else
- {
- if (Error == Error_EnvCamera)
- {
- //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_ENV_ERROR);
- SetCameraSysVar(CAMERA_ENV_ERROR);
- Dbg("Camera State to CAMERA_ENV_ERROR");
- m_bStartCamera = TRUE;
- LogEvent(Severity_Middle, EVENT_MOD_BEGIN_RECORD,strSessionId);
- }
- else if (Error == Error_OptCamera)
- {
- //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_OPT_ERROR);
- SetCameraSysVar(CAMERA_OPT_ERROR);
- Dbg("Camera State to CAMERA_OPT_ERROR");
- m_bStartCamera = TRUE;
- LogEvent(Severity_Middle, EVENT_MOD_BEGIN_RECORD,strSessionId);
- }
- else if (Error == Error_AllCamera)
- {
- //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_BOTH_ERROR);
- SetCameraSysVar(CAMERA_BOTH_ERROR);
- Dbg("Camera State to CAMERA_BOTH_ERROR");
- m_nCameraErrorCode = Error_AllCamera;
- m_bStartCamera = FALSE;
- GetFunction()->SetUserDefineState(USER_MEDIA_ALLERROR);
- }
- else
- {
- SetCameraSysVar(Error);
- Dbg("Camera State to Other Error");
- m_nCameraErrorCode = Error;
- m_bStartCamera = FALSE;
- }
- }
- }
- ErrorCodeEnum ReStartCamera(int nCamera)
- {
- if (m_capture != NULL)
- {
- if((StopCamera(m_capture,nCamera)==-1))
- {
- Dbg("ReStartCamera,stop camera fail!");
- }
- Sleep(2000);
- //打开前检查配置摄像头名字是否能被打开并自纠正
- AutoCorrectCameraConfigName(4000);
-
- ErrorCodeEnum Error = Error_Succeed;
- Error = capture_create(&conf, m_capture,nCamera);
- if (Error == Error_Succeed)
- {
- Error = capture_start(m_capture,nCamera);
- if (Error != Error_Succeed)
- {
- Dbg("ReStartCamera,capture_start fail!");
- capture_destroy(m_capture,nCamera);
- return Error;
- }
- else
- {
- Dbg("ReStartCamera,camera = %d,success!",nCamera);
- return Error_Succeed;
- }
- }
- else
- {
- Dbg("ReStartCamera,capture_create fail!");
- capture_destroy(m_capture,nCamera);
- return Error;
- }
- }
- else
- {
- return Error_Unexpect;
- }
- }
- virtual CServerSessionBase *OnNewSession(const char* pszRemoteEntityName, const char * pszClass)
- {
- LOG_FUNCTION();
- LOG_TRACE("%s connected class = %s!", pszRemoteEntityName, pszClass);
- return new MediaServiceSession(this);
- }
- public:
- ErrorCodeEnum ExternStartCamera()
- {
- Dbg("Extern start camera");
- CSimpleStringA strSessionId;
- CSmartPointer<IEntityFunction> Func = GetFunction();
- Func->GetSysVar("SessionID", strSessionId);
- if (!m_bStartCamera)
- {
- StartCameraAndTiggerRecord((LPCTSTR)strSessionId);
- }
- m_bExternControlCam = FALSE;
- return Error_Succeed;
- }
- ErrorCodeEnum ExternStopCamera()
- {
- Dbg("Extern stop camera");
- if (m_capture)
- {
- LogEvent(Severity_Middle, EVENT_MOD_END_RECORD,NULL);
- GetFunction()->KillTimer(1);
- capture_stop(m_capture);
- capture_destroy(m_capture);
- m_capture = NULL;
- }
- m_bStartCamera = FALSE;
- m_bExternControlCam = TRUE;
- return Error_Succeed;
- }
- //add by ly at 20160401
- ErrorCodeEnum SaveInnerCamera()
- {
- if (strFrontCam.GetLength() <= 1) {
- return Error_Resource;
- }
- if (strstr((LPCTSTR)conf.strVideoEnv,(LPCTSTR)strFrontCam)==NULL)
- {
- CSimpleStringA tmp = strRearCam;
- strRearCam = strFrontCam;
- strFrontCam = tmp;
- }
- Dbg("[dbg] strFrontCam: %s, strRearCam: %s", (LPCSTR)strFrontCam, (LPCSTR)strRearCam);
- CSmartPointer<IEntityFunction> spFunction = GetFunction();
- CSmartPointer<IConfigInfo> spConfig;
- ErrorCodeEnum Error = spFunction->OpenConfig(Config_Run, spConfig);
- if (Error == Error_Succeed) {
- SpIniMappingTable table;
- table.AddEntryString("Video", "FrontCamera", strFrontCam, "$");
- table.AddEntryString("Video", "RearCamera", strRearCam, "$");
- Error = table.Save(spConfig);
- if (Error != Error_Succeed)
- {
- LOG_TRACE("[dbg] failed to save run config.");
- }
- }
- else {
- LOG_TRACE("[dbg] failed to open run config.");
- }
- return Error;
- }
- // 获取高拍仪摄像头(考虑多个高拍仪)
- ErrorCodeEnum GetHSPCameras(CAutoArray<CSimpleStringA> &HSPCameras)
- {
- enum CapTypeEnum {
- CAMTYPE_UNKNOWN = 0,
- CAMTYPE_ENV,
- CAMTYPE_OPT,
- CAMTYPE_EWS,
- CAMTYPE_HSPS,
- CAMTYPE_CIRCLE,
- CAMTYPE_MAX
- };
- auto rc = Error_Succeed;
- auto pScannerSetClient = new ScannerService_ClientBase(this);
- if (pScannerSetClient->Connect() != Error_Succeed)
- {
- Dbg("连接ScannerSet实体失败");
- pScannerSetClient->SafeDelete();
- pScannerSetClient = NULL;
- rc = Error_DevConnFailed;
- }
- else
- {
- ScannerService_GetOnlineCameras_Req req = {};
- ScannerService_GetOnlineCameras_Ans ans = {};
- rc = pScannerSetClient->GetOnlineCameras(req, ans, 10000);
- if (rc != Error_Succeed)
- {
- Dbg("ScannerSet 调用 GetOnlineCameras 失败: 0x%x", rc);
- }
- else
- {
- Dbg("ScannerSet invokes GetOnlineCameras suc.");
- Dbg("Count: %d", ans.devCount);
- if (ans.devCount > 0) {
- for (int i = 0; i < ans.devFriendlyNames.GetCount(); ++i) {
- Dbg("[%d]%s(%d)", i, (LPCTSTR)ans.devFriendlyNames[i],
- ans.devType[i]);
- CapTypeEnum devType = (CapTypeEnum)ans.devType[i];
- if (devType == CAMTYPE_HSPS)
- {
- HSPCameras.Append(ans.devFriendlyNames, i, 1);
- }
- }
- }
- }
- pScannerSetClient->GetFunction()->CloseSession();
- pScannerSetClient->SafeDelete();
- pScannerSetClient = NULL;
- }
- return rc;
- }
- ErrorCodeEnum HandleSalesRecordPCMAudio(bool bRemoteRecord, const char *pszMessage, audio_frame* pFrame = NULL)
- {
- ErrorCodeEnum Error = Error_Succeed;
- char strSwiftName[MAX_PATH] = {0};
- if (NULL != pszMessage){
- size_t ulen = strlen(pszMessage);
- char *tmp = new char[ulen+1];
- memset(tmp, 0, ulen + 1);
- memcpy(tmp, pszMessage, ulen);
- char *result[16] = {0};
- auto arr1 = CSimpleStringA2W(tmp).Split('@');
- auto arr2 = CAutoArray<CSimpleStringA>(arr1.GetCount());
- for (int i = 0; i < arr1.GetCount(); ++i){
- arr2[i] = CSimpleStringW2A(arr1[i]);
- result[i] = const_cast<LPSTR>(arr2[i].GetData());
- }
- if (arr1.GetCount() > 4){
- Dbg("remote record swift number is %s.", result[4]);
- sprintf(strSwiftName, "%s", result[4]);
- }
- delete tmp;
- tmp = NULL;
- }
- char strMicroName[MAX_PATH] = {0};
- CSimpleStringA strTempDir;
- if (Error_Succeed == GetFunction()->GetPath("Temp", strTempDir)){
- sprintf_s(strMicroName, MAX_PATH, "%s\\local_micro_%s.pcm", strTempDir.GetData(), strSwiftName);
- }
- else{
- sprintf_s(strMicroName, MAX_PATH, "local_micro_%s.pcm", strSwiftName);
- }
-
- FILE *pRecord = fopen(strMicroName, "wb+");
- if (NULL != pRecord){
- if (Error_Succeed == StartSalesRecordAudioCapture(bRemoteRecord, eSingleWriteLocal, pRecord)){
- Dbg("begin remote sales record audio capture and record local PCM.");
- }
- }
- else{
- Dbg("fopen %s failed.",strMicroName);
- }
- if (true == bRemoteRecord){
- char strSpeakerName[MAX_PATH] = {0};
- if ("" != strTempDir){
- sprintf_s(strSpeakerName, MAX_PATH, "%s\\remote_speaker_%s.pcm", strTempDir.GetData(), strSwiftName);
- }
- else{
- sprintf_s(strSpeakerName, MAX_PATH, "remote_speaker_%s.pcm", strSwiftName);
- }
- StartSpeakerAudioRender(0, pFrame, strSpeakerName);
- }
-
- return Error;
- }
- void HandleRemoteRecord(const char *pszMessage)
- {
- audio_frame frame;
- frame.bitspersample = 16;
- frame.format = 1;
- frame.framesize = 320;
- frame.nchannels = 1;
- frame.samplespersec = 8000;
- if (true == m_bRecordPCM){
- HandleSalesRecordPCMAudio(true, pszMessage, &frame);
- }
- else{
- if (Error_Succeed == StartSalesRecordAudioCapture(true)){
- Dbg("begin remote sales record audio capture.");
- }
- StartSpeakerAudioRender(0, &frame, NULL);
- }
- }
- ErrorCodeEnum StartSpeakerAudioRender(int iQueue, audio_frame* pFrame, const char* strName)
- {
- auto rc = Error_Succeed;
- Dbg("start speak audio render.");
-
- if (NULL != m_pAudioRenderObj){
- if(0 == m_pAudioRenderObj->StartRender(0, pFrame, strName)){
- m_bHasStartSpeakerRender = true;
- Dbg("start speak audio render success.");
- }
- }
- return rc;
- }
- ErrorCodeEnum StopSpeakerAudioRender()
- {
- auto rc = Error_Succeed;
- Dbg("stop speak audio render.");
- if (NULL != m_pAudioRenderObj){
- m_pAudioRenderObj->StopRender();
- m_bHasStartSpeakerRender = false;
- }
- return rc;
- }
- ErrorCodeEnum SetSalesRecordAudioCaptureTransActionData(eRvcPCMTransType eType, void* pData)
- {
- auto rc = Error_Param;
- if (NULL != m_salesaudio_capture){
- if (NULL != m_salesaudio_capture->rvc_audio){
- m_salesaudio_capture->rvc_audio->eType = eType;
- m_salesaudio_capture->rvc_audio->pdata = pData;
- rc = Error_Succeed;
- }
- }
- return rc;
- }
- DeviceTypeEnum m_eDeviceType;
- BOOL m_bStartCamera;
- BOOL m_bExternControlCam;
- capture_config_t conf;
- rvc_audio_capture_config_s m_sales_audio_conf; //销售双录音频配置
- ErrorCodeEnum m_nCameraErrorCode; //摄像头故障码,0:无故障,1:env摄像头故障,2:opt摄像头故障,3:双摄像头故障
- int m_nCurActiveCamera; //当前正在使用的摄像头
- CSimpleStringA strFrontCam;
- CSimpleStringA strRearCam;
- CSimpleStringA strEnvCam; //Env摄像头 add by ly 20160331
- CSimpleStringA strUSBCam; //外接摄像头 add by ly 20160329
- CSimpleStringA strEwsCam; //外部广角摄像头路径名(全程录像用,通常不配置)
- int m_nCameraCount; //当前摄像头数量 add by ly 20160531
- int m_nSysCallType;//0:普通模式,1:p2p模式
- capture_t *m_capture;
- rvc_sales_audio_capture_t *m_salesaudio_capture;
- BOOL m_bCustomerwareBegin;
- bool m_bHasStartSpeakerRender; //add by clp 20200416 是否已开启扬声器音频采集
- private:
- LONG m_lCaptureEnvCount;
- LONG m_lCaptureOptCount;
- LONG m_lCaptureEnvOptCount;
- CAutoArray<CUUID> m_arrListener;
- ChannelMediaControllerClient *m_pMediaControllerChannel;
- SelfChekerClient*m_pSelfcheckClient;
- IAudioRender* m_pAudioRenderObj; //add by clp 20200319 扬声器捕捉实体
- bool m_bRecordPCM; //add by clp 20200401 是否单独录制PCM音频
- int m_nSalesAudioSmpPsec; //add by clp 20200402 销售双录音频采样率
- bool m_bIsRemoteRecord; //add by clp 20200403 是否是远程双录
- };
- SelfChekerClient::SelfChekerClient( CMediaControllerEntity *pEntity ) : SelfCheckerService_ClientBase(pEntity)
- {
- }
- ChannelMediaControllerClient::ChannelMediaControllerClient( CMediaControllerEntity *pEntity ) : ChannelService_ClientBase(pEntity)
- {
- }
- void ChannelMediaControllerClient::OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData)
- {
- if (Error == Error_Succeed)
- {
- CMediaControllerEntity *pEntity = static_cast<CMediaControllerEntity*>(m_pEntityBase);
- if (Msg.state == eChannelState_Idle)
- {
- if (pEntity->m_bStartCamera)
- {
- if (pEntity->SetAutoBright(pEntity->m_nCameraErrorCode)==false)
- {
- Dbg("SetAutoBright Fail!");
- }
- }
- }
- else if (Msg.state == eChannelState_Connected)
- {
- if (pEntity->m_bStartCamera)
- {
- pEntity->SendCameraBright();
- }
- }
- }
- }
- void ChannelMediaControllerClient::OnMessage( ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData )
- {
- LOG_FUNCTION();
- if (Error == Error_Succeed)
- {
- CMediaControllerEntity *pEntity = static_cast<CMediaControllerEntity*>(m_pEntityBase);
- pEntity->OnReceivePkt(Msg.sub_type, (const char*)Msg.data.m_pData, Msg.data.m_iLength);
- }
- }
- // edit by ly 20160401
- void MediaServiceSession::Handle_GetVideoDeviceName(SpReqAnsContext<MediaService_GetVideoDeviceName_Req, MediaService_GetVideoDeviceName_Ans>::Pointer ctx)
- {
- CSimpleStringA frontcam = m_pEntity->strFrontCam;
- CSimpleStringA rearcam = m_pEntity->strRearCam;
- if (frontcam.GetLength() > 1 && rearcam.GetLength() > 1)
- {
- ctx->Ans.frontcam = frontcam;
- if (strstr((LPCTSTR)frontcam,";"))
- {
- ctx->Ans.frontcam = frontcam.SubString(0, frontcam.IndexOf(";"));
- }
- ctx->Ans.rearcam = rearcam;
- if (strstr((LPCTSTR)rearcam,";"))
- {
- ctx->Ans.rearcam = rearcam.SubString(0, rearcam.IndexOf(";"));
- }
- Dbg("get camera1 name:%s",m_pEntity->strFrontCam);
- Dbg("get camera2 name:%s",m_pEntity->strRearCam);
- }
- ctx->Answer(Error_Succeed);
- }
- void MediaServiceSession::Handle_StartCamera(SpOnewayCallContext<MediaService_StartCamera_Info>::Pointer ctx)
- {
- m_pEntity->ExternStartCamera();
- }
- void MediaServiceSession::Handle_StopCamera(SpOnewayCallContext<MediaService_StopCamera_Info>::Pointer ctx)
- {
- m_pEntity->ExternStopCamera();
- }
- void MediaServiceSession::Handle_StartEnvCamera(SpReqAnsContext<MediaService_StartEnvCamera_Req, MediaService_StartEnvCamera_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- ErrorCodeEnum Error = m_pEntity->StartEnvCamera();
- ctx->Ans.returncod = Error;
- ctx->Answer(Error);
- }
- void MediaServiceSession::Handle_StopEnvCamera(SpOnewayCallContext<MediaService_StopEnvCamera_Info>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->StopEnvCamera();
- }
- void MediaServiceSession::Handle_StartSpeakerRender(SpOnewayCallContext<MediaService_StartSpeakerRender_Info>::Pointer ctx)
- {
- LOG_FUNCTION();
- }
- void MediaServiceSession::Handle_StopSpeakerRender(SpOnewayCallContext<MediaService_StopSpeakerRender_Info>::Pointer ctx)
- {
- LOG_FUNCTION();
- if (true == m_pEntity->m_bHasStartSpeakerRender){
- m_pEntity->StopSpeakerAudioRender();
- }
- else{
- Dbg("speaker audio render already stopped.");
- }
-
- }
- SP_BEGIN_ENTITY_MAP()
- SP_ENTITY(CMediaControllerEntity)
- SP_END_ENTITY_MAP()
|