12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456 |
- #include "stdafx.h"
- #include "mod_SurveillanceRecorder.h"
- #include "y2k_time.h"
- #include "ModuleMix.h"
- #include "rec_common.h"
- #include "fileutil.h"
- #include "array.h"
- #include <memutil.h>
- #include <algorithm>
- #include "..\mod_CameraConfigManage\CameraConfigManage_client_g.h"
- #include "..\mod_CameraConfigManage\CameraConfigManage_def_g.h"
- using namespace CameraConfigManage;
- #define TIMERID_CAMCHK 1
- #define TIMERID_RECORD 2
- #define TIMERID_UPLOAD 3
- #define CAMCHK_CYCLE 5000
- #define RECORD_CYCLE 60000
- #define UPLOAD_CYCLE 600000
- #define MAX_DISK_PERCENT 95
- #define DATE_LEN 10
- #define MAX_LISTSIZE 50
- using namespace SurveillanceRecorder;
- using namespace LibVideoEcho;
- extern DeviceTypeEnum g_eDeviceType;
- static ErrorCodeEnum ParseIPAddress(const char *str, CSimpleStringA &ip, int &port)
- {
- ErrorCodeEnum Error = Error_Unexpect;
- if (str) {
- char tmp1[32] = {};
- char tmp2[16] = {};
- sscanf(str, "%s %s", tmp1, tmp2);
- if (tmp1[0] != 0 && tmp2[0] != 0)
- {
- ip = tmp1;
- port = atoi(tmp2);
- Error = Error_Succeed;
- }
- else
- return Error;
- }
- return Error;
- }
- // 寻找某目录下与通配符匹配的文件 add by ly at 2017/03/25
- static BOOL FindMatchedFile(LPCSTR sFindPath, LPCSTR sFindFileName, std::vector<std::string> &sFiles)
- {
- char sPath[MAX_PATH];
- memset(sPath, 0, MAX_PATH);
- char sFormatFileName[MAX_PATH+2] = "*";
- WIN32_FIND_DATA FindFileData;
- HANDLE hFind;
- BOOL fFinished = FALSE;
- lstrcpy(sFormatFileName, sFindPath);
- if(sFindPath[strlen(sFindPath)-1] != '\\')
- {
- lstrcat(sFormatFileName, "\\*");
- }
- else
- {
- lstrcat(sFormatFileName, "*");
- }
- lstrcat(sFormatFileName, sFindFileName);
- lstrcat(sFormatFileName, "*");
- hFind = FindFirstFile(sFormatFileName, &FindFileData);
- if (hFind == INVALID_HANDLE_VALUE)
- {
- return FALSE;
- }
- else
- {
- while (!fFinished)
- {
- lstrcpy(sPath, sFindPath);
- if(sPath[strlen(sPath)-1] != '\\')
- {
- lstrcat(sPath, "\\");
- }
- lstrcat(sPath, FindFileData.cFileName);
- if (!(FILE_ATTRIBUTE_DIRECTORY & FindFileData.dwFileAttributes))
- {
- sFiles.push_back(FindFileData.cFileName);
- }
- if (!FindNextFile(hFind, &FindFileData))
- {
- if (GetLastError() == ERROR_NO_MORE_FILES)
- {
- fFinished = TRUE;
- }
- else
- {
- break;
- }
- }
- }
- FindClose(hFind);
- }
- return TRUE;
- }
- static BOOL CheckDiskStatus(const char *szRoot, int nPercent)
- {
- _ULARGE_INTEGER lpFreeBytesAvailableToCaller = {}, lpTotalNumberOfBytes = {}, lpTotalNumberOfFreeBytes = {};
- BOOL ret = GetDiskFreeSpaceEx(szRoot, &lpFreeBytesAvailableToCaller, &lpTotalNumberOfBytes, &lpTotalNumberOfFreeBytes);
- if (ret == 0)
- {
- Dbg("CheckDiskStatus.GetDiskFreeSpaceEx failed(%d).",GetLastError());
- return FALSE;
- }
- DWORD dwTotal = lpTotalNumberOfBytes.QuadPart/1048576;
- DWORD dwTotalFree = lpTotalNumberOfFreeBytes.QuadPart/1048576;
- int ratio = dwTotalFree*100/dwTotal;
- Dbg("lytest free disk %d MB, %d percent free.\n", dwTotalFree, ratio);
- //if (ratio < (100-MAX_DISK_PERCENT))
- if (ratio < (100-nPercent))
- {
- return FALSE;
- }
- return TRUE;
- }
- void CSurveillanceRecorderEntity::OnPreStart( CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext )
- {
- m_eDeviceType = eStand2sType;
- g_eDeviceType = eStand2sType;
- //MessageBoxA(0,0,0,0);
- m_bStartCamera = FALSE;
- m_bCamConfig = FALSE;
- m_bRecordPaused = FALSE;
- m_bStartRecord = FALSE;
- m_bCameraInserted = FALSE;
- //m_iCameraState = CAMERA_TYPE_EWS;
- m_bExternStartCam = FALSE;
- m_max_disk_percent = MAX_DISK_PERCENT;
- m_bNeedRestart = false;
- LOG_FUNCTION();
- ErrorCodeEnum Error;
- CSmartPointer<IEntityFunction> spFunction = GetFunction();
- CSystemStaticInfo stStaticinfo;
- spFunction->GetSystemStaticInfo(stStaticinfo);
- if (stricmp(stStaticinfo.strMachineType,"RVC.PAD")==0)
- {
- if (stricmp(stStaticinfo.strSite,"CMB.FLB")==0)
- {
- LOG_TRACE("the type is mobile pad");
- m_eDeviceType = eMobilePadType;
- }
- else
- {
- LOG_TRACE("the type is pad");
- m_eDeviceType = ePadtype;
- }
- }
- else if (stricmp(stStaticinfo.strMachineType,"RVC.Desk2S")==0)
- {
- LOG_TRACE("the type is Desk2S");
- m_eDeviceType = eDesk2SType;
- }
- else if (stricmp(stStaticinfo.strMachineType,"RPM.Stand1S")==0)
- {
- LOG_TRACE("the type is RPM.Stand1S");
- m_eDeviceType = eRpm1sType;
- }
- else
- {
- LOG_TRACE("the type is standard");
- m_eDeviceType = eStand2sType;
- }
- g_eDeviceType = m_eDeviceType;
- m_terminalNo = stStaticinfo.strTerminalID;
- SetCameraSysVar(CAMERA_NO_ERROR);
- memset(&conf,0,sizeof(ews_capture_config_t));
- Error = (ErrorCodeEnum)ews_capture_lib_init();
- if (Error == Error_Succeed)
- {
- Error = LoadConfig(&conf);
- if (Error!=Error_Succeed)
- {
- LOG_TRACE("Load EwsCamera Config failed(0x%x)!",Error);
- /*if (Error == Error_Resource)
- {
- LOG_TRACE("SurveillanceRecord is not allowed!");
- }
- else if (Error == Error_EwsCamera)
- {
- Dbg("Camera State to CAMERA_EWS_ERROR");
- GetFunction()->SetUserDefineState(USER_SURVEILLANCE_EWSERROR);
- }*/
- if (Error == Error_EwsCamera)
- {
- Dbg("Camera State to CAMERA_EWS_ERROR");
- GetFunction()->SetUserDefineState(USER_SURVEILLANCE_EWSERROR);
- }
- }
- else
- {
- m_bCameraInserted = TRUE;
- }
- }
- else
- {
- LOG_TRACE("ews_capture_lib_init failed!");
- }
- int i = 0;
- if ((ePadtype==m_eDeviceType||eDesk2SType==m_eDeviceType)&&m_bRecordAllowed)
- {
- // 初始化中台服务器 add by ly 2017/03/23
- Error = LoadServerConfig();
- if (Error != Error_Succeed) {
- LOG_TRACE("load server config failed!");
- pTransactionContext->SendAnswer(Error);
- return;
- }
- Error = GetFunction()->GetPath("Temp", m_TempDir);
- if (Error != Error_Succeed) {
- LOG_TRACE("get global record temp path failed!");
- pTransactionContext->SendAnswer(Error);
- return;
- }
- if (m_TempDir.GetLength() > 0 && m_TempDir[m_TempDir.GetLength()-1] != '\\') {
- m_TempDir += "\\";
- }
-
- Error = GetFunction()->GetPath("UploadVideo", m_RecordSaveDir);
- if (Error != Error_Succeed) {
- LOG_TRACE("get global record save path failed!");
- pTransactionContext->SendAnswer(Error);
- return;
- }
- if (m_RecordSaveDir.GetLength() > 0 && m_RecordSaveDir[m_RecordSaveDir.GetLength()-1] != '\\') {
- m_RecordSaveDir += "\\";
- }
- /*m_hUploadAnsEvt = CreateEvent(NULL, FALSE, FALSE, 0);
- if (!m_hUploadAnsEvt) {
- LOG_TRACE("create event handle failed!");
- pTransactionContext->SendAnswer(Error_NotInit);
- return;
- }*/
- // add by ly at 2017/05/25
- Error = GetFunction()->RegistSysVarEvent(SYSVAR_DISKSTATEUS_FOR_VIDEO, this);
- if (Error != Error_Succeed)
- {
- LOG_TRACE("register sysvar %s failed!", SYSVAR_DISKSTATEUS_FOR_VIDEO);
- }
- Dbg("[dbg] bAutoRecord:%d", m_bAutoMode);
- if (m_bAutoMode)
- {
- m_arrListener.Init(13);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STOP_CONTINURECORD, NULL, false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_START_ECHO_CONTINURECORD, NULL, false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STOP_ECHO_CONTINURECORD, 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_Middle, Error_IgnoreAll, LOG_EVT_START_CONTINURECORD, NULL, false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_STOP_CONTINURECORD, NULL, false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_High, Error_IgnoreAll, LOG_EVT_CONTINURECORD_FAILED, NULL, false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_High, Error_IgnoreAll, LOG_EVT_RESTART_EWSCAMERA, NULL, false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_CONTINURECORD_SECTION_FINISHED, 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_High, Error_IgnoreAll, LOG_EVT_CONTINURECORD_ENTITY_EXCEPTION, NULL, false);
- }
- else
- {
- m_arrListener.Init(13);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_START_CONTINURECORD, NULL, false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STOP_CONTINURECORD, NULL, false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_START_ECHO_CONTINURECORD, NULL, false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STOP_ECHO_CONTINURECORD, 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_Middle, Error_IgnoreAll, LOG_EVT_START_CONTINURECORD, NULL, false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_STOP_CONTINURECORD, NULL, false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_High, Error_IgnoreAll, LOG_EVT_CONTINURECORD_FAILED, NULL, false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_CONTINURECORD_SECTION_FINISHED, 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_High, Error_IgnoreAll, LOG_EVT_CONTINURECORD_ENTITY_EXCEPTION, NULL, false);
- }
- // 当前录像模式通知业务中台 add by ly 2017/04/12
- ContinuRecordMode evt1;
- evt1.isauto = GetContinuRecordMode();
- SpSendBroadcast(GetFunction(), SP_MSG_OF(ContinuRecordMode), SP_MSG_SIG_OF(ContinuRecordMode), evt1);
- Dbg("[dbg] GetContinuRecordMode broadcast sent!");
- // 初始状态通知到业务中台
- ContinuRecordInitialState evt;
- evt.statecod = GetContinuRecordState();
- SpSendBroadcast(GetFunction(), SP_MSG_OF(ContinuRecordInitialState), SP_MSG_SIG_OF(ContinuRecordInitialState), evt);
- Dbg("[dbg] ContinuRecordInitialState broadcast sent!");
- }
- if (conf.strAudioIn.GetLength()>1) {
- if (m_kept_volume_in>=0&&m_kept_volume_in<=100) {
- m_pKeeperIn = volume_keeper_create((LPCTSTR)conf.strAudioIn, 1, m_kept_volume_in);
- if (m_pKeeperIn) {
- Dbg("EWS in volume keeper create ok! %d", m_kept_volume_in);
- } else {
- Dbg("EWS in volume keeper create failed!");
- }
- }
- }
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- void CSurveillanceRecorderEntity::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!");
- }
- else
- {
- Dbg("SelfcheckClient connect success!");
- }
- // Auto Start Continu Record edit by ly 2017/04/12
- if ((ePadtype==m_eDeviceType||eDesk2SType==m_eDeviceType)&&m_bRecordAllowed)
- {
- GetFunction()->SetTimer(TIMERID_UPLOAD,this,UPLOAD_CYCLE);
- if (m_bAutoMode&&!m_bCamConfig)
- {
- LogEvent(Severity_Middle,LOG_EVT_START_CONTINURECORD,NULL);
- }
- }
- }
- void CSurveillanceRecorderEntity::OnPreClose( EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext )
- {
- LOG_FUNCTION();
- CSmartPointer<IEntityFunction> spFunction = GetFunction();
- spFunction->UnregistSysVarEvent(SYSVAR_DISKSTATEUS_FOR_VIDEO);
- if ((ePadtype==m_eDeviceType||eDesk2SType==m_eDeviceType)&&m_bRecordAllowed)
- {
- for (int i = 0; i < m_arrListener.GetCount(); ++i)
- {
- spFunction->UnsubscribeLog(m_arrListener[i]);
- }
- }
- SecureClientRelease();
- /*SetEvent(m_hUploadAnsEvt);
- CloseHandle(m_hUploadAnsEvt);
- m_hUploadAnsEvt = NULL;*/
- // Auto Stop Continu Record add by ly 2017/03/20
- StopEchoRecord(); // 停止回显
- StopRecord(); // 停止全程录像
- StopCamera(); // 停止摄像头
- GetFunction()->KillTimer(TIMERID_RECORD);
- GetFunction()->KillTimer(TIMERID_CAMCHK);
- GetFunction()->KillTimer(TIMERID_UPLOAD);
- if (m_pRecorder)
- {
- delete m_pRecorder;
- m_pRecorder = NULL;
- }
- if (m_pKeeperIn) {
- volume_keeper_destroy(m_pKeeperIn);
- m_pKeeperIn = NULL;
- }
- if (m_ews_capture) {
- ews_capture_stop(m_ews_capture);
- ews_capture_destroy(m_ews_capture);
- m_ews_capture = NULL;
- }
- ews_capture_lib_term();
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- void CSurveillanceRecorderEntity::OnTimeout( DWORD dwTimerID )
- {
- if (dwTimerID == TIMERID_CAMCHK)
- {
- int ews_n;
- DWORD nLastEwsTime;
- bool bEwsTimeout = false;
- if (!m_ews_capture)
- {
- Dbg("m_ews_capture =Null");
- return;
- }
- if (!m_bStartCamera)
- {
- Dbg("m_bStartCamera =false");
- return;
- }
- ews_capture_detect_camera_bug(m_ews_capture, &ews_n);
- ews_capture_get_last_frametime(m_ews_capture,&nLastEwsTime);
- if (ews_n == 0)
- {
- if (m_iEwsEmptyTimes < CAMERA_BUG_THRESHOLD)
- {
- m_iEwsEmptyTimes++;
- Dbg("get ews camera picture fail,Times=%d",m_iEwsEmptyTimes);
- }
- }
- else if (ews_n == -1)
- {
- m_iEwsEmptyTimes = CAMERA_BUG_THRESHOLD;
- }
- else
- {
- if (m_iEwsEmptyTimes == CAMERA_BUG_THRESHOLD)
- {
- Dbg("ews camera get right!");
- }
- m_iEwsEmptyTimes = 0;
- }
- //ews图像是否超时
- if(nLastEwsTime > 0)
- {
- //Dbg("now=%d,nLastEwsTime=%d",y2k_time_now(),nLastEwsTime);
- if(((y2k_time_now()-nLastEwsTime) > CAMERA_TIMEOUT)&&!bEwsTimeout)
- {
- bEwsTimeout = true;
- Dbg("bEwsTimeout");
- }
- else if (((y2k_time_now()-nLastEwsTime) < CAMERA_TIMEOUT)&&bEwsTimeout)
- {
- bEwsTimeout = false;
- Dbg("change ews camera from bEwsTimeout to OK");
- }
- }
- //ews是否30S没有图像或者图像20秒没有更新
- if(((m_iEwsEmptyTimes == CAMERA_BUG_THRESHOLD)||bEwsTimeout)&&(m_nCameraErrorCode!=Error_EwsCamera))
- {
- char strMessage[MAX_PATH*2] = {0};
- get_external_camera_exception_message(strMessage, MAX_PATH*2, m_CamFriendlyName, "Ews camera bug detected!");
- LogError(Severity_Middle, Error_Hardware, ERROR_MOD_SURVEILLANCERECORDER_EWSCAMERA_BUG, strMessage);
- if (ePadtype==m_eDeviceType||eDesk2SType==m_eDeviceType)
- {
- m_nCameraErrorCode = Error_EwsCamera;
- ChangeSysvar(m_nCameraErrorCode);
- //RealSelfCheck();
- }
- }
- else if((m_iEwsEmptyTimes != CAMERA_BUG_THRESHOLD)&&!bEwsTimeout&&((m_nCameraErrorCode == Error_EwsCamera)))
- {
- if (ePadtype==m_eDeviceType||eDesk2SType==m_eDeviceType)
- {
- m_nCameraErrorCode = Error_Succeed;
- ChangeSysvar(m_nCameraErrorCode);
- }
- }
- //重启摄像头
- if((m_nCameraErrorCode == Error_EwsCamera)&&(m_nEwsCameraRestartNum<CAMERA_RESTARTNUM))
- {
- if (ReStartEwsCamera() != Error_Succeed)
- {
- m_nEwsCameraRestartNum++;
- }
- else
- {
- m_nEwsCameraRestartNum = 0;
- m_nCameraErrorCode = Error_Succeed;
- ChangeSysvar(m_nCameraErrorCode);
- m_iEwsEmptyTimes = 0;
- bEwsTimeout = false;
- }
- }
- }
- else if (dwTimerID == TIMERID_RECORD)
- {
- Dbg("On record timer!");
- std::string strWmvFile;
- BOOL bRet = GetCurrentSectionBySerialID((LPCTSTR)m_uid.ToString(),strWmvFile);
- if (!bRet)
- {
- Dbg("failed to get current record file name!");
- }
- bRet = UpdateVideoRecord(strWmvFile.c_str());
- if (!bRet)
- {
- Dbg("failed to update video record!");
- }
- //m_last_disk_overtop = !CheckDiskStatus("C:\\",m_max_disk_percent);
- //if (m_last_disk_overtop)
- //{
- // //LogEvent(Severity_Middle,LOG_EVT_STOP_CONTINURECORD,NULL);
- // //OnWideAngleCameraStartFailed("磁盘所剩空间不足,已停止全程双录!");
- // LogEvent(Severity_High,LOG_EVT_CONTINURECORD_FAILED,"磁盘所剩空间不足,已停止全程双录!");
- // return;
- //}
- TCHAR strNowDate[DATE_LEN+1];
- SYSTEMTIME st;
- GetLocalTime(&st);
- sprintf_s(strNowDate, "%4d-%02d-%02d", st.wYear,st.wMonth, st.wDay);
- if(strncmp(strNowDate, (LPCTSTR)m_RecordBeginTime, DATE_LEN))
- {
- Dbg("T to T+1, restart continue record!");
- LogEvent(Severity_Middle,LOG_EVT_STOP_CONTINURECORD,NULL);
- }
- }
- else if (dwTimerID == TIMERID_UPLOAD)
- {
- /*UploadVideoRecord();*/
- Dbg("On upload timer!");
- UploadVideoRecordTask *task = new UploadVideoRecordTask(this);
- GetFunction()->PostThreadPoolTask(task);
- //GetFunction()->PostEntityTaskFIFO(task);
- //DWORD dwCode = WaitForSingleObject(m_hUploadAnsEvt, 60000);
- //Dbg("dwCode=0x%x while wait for upload event", dwCode);
- }
- else
- {
- Dbg("invalid timer id!");
- }
- }
- ErrorCodeEnum CSurveillanceRecorderEntity::SetCameraSysVar( const CSimpleStringA &newVal )
- {
- CSmartPointer<IEntityFunction> spFunction = this->GetFunction();
- if (!(ePadtype==m_eDeviceType||eDesk2SType==m_eDeviceType))
- {
- return spFunction->SetSysVar(SYSVAR_EWSCAMERASTATE, (LPCTSTR)newVal);
- }
- CSimpleStringA val = newVal;
- switch (val[0])
- {
- case 'W':
- val = val.Append(m_CamFriendlyName.GetLength()>1?(LPCTSTR)m_CamFriendlyName:"全程双录");
- break;
- case 'N':
- case 'I':
- default:
- break;
- }
- return spFunction->SetSysVar(SYSVAR_EWSCAMERASTATE, (LPCTSTR)val);
- }
- ErrorCodeEnum CSurveillanceRecorderEntity::ChangeSysvar( ErrorCodeEnum op )
- {
- switch (op)
- {
- case Error_Succeed:
- Dbg("Camera State to No_Error");
- SetCameraSysVar(CAMERA_NO_ERROR);
- GetFunction()->SetUserDefineState(USER_SURVEILLANCE_IDLE);
- break;
- case Error_EwsCamera:
- Dbg("Camera State to Ews_Error");
- SetCameraSysVar(CAMERA_EWS_ERROR);
- GetFunction()->SetUserDefineState(USER_SURVEILLANCE_EWSERROR);
- break;
- default:
- break;
- }
- return Error_Succeed;
- }
- bool CSurveillanceRecorderEntity::SetAutoBright( ErrorCodeEnum nCode )
- {
- return ews_capture_set_autobrightness(m_ews_capture,nCode);
- }
- int CSurveillanceRecorderEntity::GetActiveCamera()
- {
- return 0;
- }
- HINSTANCE CSurveillanceRecorderEntity::GetEntityHinstance()
- {
- return ModuleBase::GetModuleBase()->GetInstance();
- }
- void CSurveillanceRecorderEntity::OnRecordFailed( bool bRecordDevFault )
- {
- Dbg("OnRecordFailed!");
- if (!bRecordDevFault)
- {
- LogEvent(Severity_High,LOG_EVT_CONTINURECORD_FAILED,NULL);
- }
- }
- void CSurveillanceRecorderEntity::OnRecordEntityExcption()
- {
- //MessageBoxA(0,"全程双录有出现异常,录像已停止,系统正在恢复中,预计30秒!", "录像异常",0);
- Dbg("全程双录出现异常,录像已停止,系统正在恢复中,预计60秒!");
- SYSTEMTIME st;
- GetLocalTime(&st);
- CSimpleStringA strMessage = CSimpleStringA::Format("%02d:%02d:%02d %s",st.wHour,st.wMinute, st.wSecond, "全程双录出现异常,录像已停止,系统正在恢复中,预计60秒!");
- LogEvent(Severity_High,LOG_EVT_CONTINURECORD_ENTITY_EXCEPTION,strMessage.GetData());
- }
- void CSurveillanceRecorderEntity::OnASectionFinished( const char *pszMessage )
- {
- // filename
- Dbg("file %s finished.", pszMessage);
- GetFunction()->KillTimer(TIMERID_RECORD);
- LogEvent(Severity_Middle, LOG_EVT_CONTINURECORD_SECTION_FINISHED, pszMessage);
- }
- void CSurveillanceRecorderEntity::OnRecordFinished()
- {
- Dbg("OnRecordFinished.");
- }
- ErrorCodeEnum CSurveillanceRecorderEntity::RealSelfCheck()
- {
- ErrorCodeEnum Error = Error_Succeed;
- if (NULL == m_pSelfcheckClient){
- 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!");
- }
- }
-
- if (Error_Succeed == Error)
- {
- 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!");
- if (m_nCameraErrorCode != Error_Succeed)
- {
- m_nCameraErrorCode = Error_Succeed;
- }
- }
- else
- {
- Dbg("RealSelfcheck suc!");
- }
- }
- else{
- Dbg("m_pSelfcheckClient is NULL.");
- }
- return Error;
- }
- ContinuRecordStateCode CSurveillanceRecorderEntity::GetContinuRecordState()
- {
- ContinuRecordStateCode statecod = State_ReadyForContinuRecord;
- if (conf.strVideo.GetLength()<=1||conf.strAudioIn.GetLength()<=1)
- {
- // 未配置
- statecod = State_EwsCameraConfigNotFound;
- }
- else if (!m_bCameraInserted)
- {
- // 未插入
- statecod = State_EwsCameraNotInserted;
- }
- else if(!m_bStartRecord)
- {
- // 未开始录像
- statecod = State_ReadyForContinuRecord;
- }
- else
- {
- if (m_nCameraErrorCode != Error_Succeed)
- {
- // 摄像头故障
- statecod = State_EwsCameraFault;
- }
- else
- {
- // 正常录像中
- statecod = State_ContinuRecording;
- }
- }
- return statecod;
- }
- bool CSurveillanceRecorderEntity::GetContinuRecordMode() const
- {
- return m_bAutoMode;
- }
- ErrorCodeEnum CSurveillanceRecorderEntity::ExternStartCamera()
- {
- Dbg("Extern start camera");
- // edit by ly@2019/04/18
- if (!(eDesk2SType==m_eDeviceType||ePadtype==m_eDeviceType||eMobilePadType==m_eDeviceType))
- {
- Dbg("Only support Desk2S or Pad!");
- return Error_Cancel;
- }
- if(m_bCamConfig)
- {
- Dbg("Camera config now!");
- return Error_Break;
- }
- if (conf.strVideo.GetLength() <= 1 || conf.strAudioIn.GetLength() <= 1)
- {
- Dbg("EwsCamera is not configed!");
- return Error_Resource;
- }
-
- if (!m_bCameraInserted)
- {
- Dbg("EwsCamera is not inserted!");
- return Error_DevNotAvailable;
- }
- if (m_bStartCamera)
- {
- Dbg("EwsCamera has started!");
- return Error_Succeed;
- }
- CSimpleStringA strCamState;
- GetFunction()->GetSysVar(SYSVAR_EWSCAMERASTATE,strCamState);
- if (strCamState == CAMERA_START_ING)
- {
- Dbg("EwsCamera is starting!");
- return Error_InvalidState;
- }
- // 通报正在启动广角摄像头
- SetCameraSysVar(CAMERA_START_ING);
- // 启动广角摄像头
- ErrorCodeEnum Error = StartEwsCamera();
- if (Error!=Error_Succeed)
- {
- Dbg("[dbg] Start Ews Camera Error=0x%x", Error);
- if(Error == Error_EwsCamera)
- {
- m_bStartCamera = FALSE;
- //SetCameraSysVar(CAMERA_EWS_ERROR);
- Dbg("Camera State to Error_EwsCamera");
- m_nCameraErrorCode = Error_EwsCamera;
- GetFunction()->SetUserDefineState(USER_SURVEILLANCE_EWSERROR);
- }
- else
- {
- //SetCameraSysVar(Error);
- Dbg("Camera State to Other Error");
- m_nCameraErrorCode = Error;
- m_bStartCamera = FALSE;
- }
- if (!m_bAutoMode)
- {
- RealSelfCheck();
- }
- }
- else
- {
- if (m_bRecordAllowed&&!m_pRecorder)
- {
- BOOL bRet = FALSE;
- m_pRecorder = new Clibwmvrecord(&bRet, this, REC_COMMON_AUDIO_EWS_SHM_QUEUE, REC_COMMON_VIDEO_EWS_SHM_RTP_QUEUE, NULL);
- }
- m_bStartCamera = TRUE;
- Dbg("Camera State to CAMERA_NO_ERROR");
- m_nCameraErrorCode = Error_Succeed;
- GetFunction()->SetUserDefineState(USER_SURVEILLANCE_IDLE);
- }
- SetCameraSysVar(CAMERA_NO_ERROR);
- m_bExternStartCam = TRUE;
- return Error;
- }
- ErrorCodeEnum CSurveillanceRecorderEntity::ExternStopCamera()
- {
- Dbg("Extern stop camera");
- // edit by ly@2019/04/18
- if (!(eDesk2SType==m_eDeviceType||ePadtype==m_eDeviceType||eMobilePadType==m_eDeviceType))
- {
- Dbg("Only support Desk2S or Pad!");
- return Error_Cancel;
- }
- if (m_bCamConfig)
- {
- Dbg("Camera config now!");
- return Error_Break;
- }
- if (!m_bStartRecord)
- {
- StopEwsCamera();
- }
- m_bExternStartCam = FALSE;
- return Error_Succeed;
- }
- ErrorCodeEnum CSurveillanceRecorderEntity::LoadConfig( ews_capture_config_t *conf )
- {
- CSmartPointer<IEntityFunction> spFunction = GetFunction();
- CSmartPointer<IConfigInfo> spConfig;
- SpIniMappingTable table;
- ErrorCodeEnum Error = spFunction->OpenConfig(Config_CenterSetting, spConfig);
- CSimpleStringA strSecondBranch("");
- int iAudioQuality = 3;
- int iAudioSampleRate = 16;
- int iAudioNsPolicy = 2;
- int iIsAudioNsOn = 0;
- if (Error == Error_Succeed)
- {
- table.AddEntryBoolean("InteractiveControl", "SurveillanceRecordAllowed", m_bRecordAllowed, false);
- table.AddEntryBoolean("SurveillanceRecorder", "AutoMode", m_bAutoMode, false);
- table.AddEntryInt("SurveillanceRecorder", "MaxDiskPercent", m_max_disk_percent, MAX_DISK_PERCENT);
- table.AddEntryInt("SurveillanceRecorder", "SecondBranchAllowed", m_secondBranchAllowed, FALSE);
- table.AddEntryString("SurveillanceRecorder", "SecondBranchParams", strSecondBranch, "");
- table.AddEntryInt("SurveillanceRecorder", "AudioQuality", iAudioQuality, 3);
- table.AddEntryInt("SurveillanceRecorder", "AudioSampleRate", iAudioSampleRate, 16);
- table.AddEntryInt("SurveillanceRecorder","AudioNsPolicy",iAudioNsPolicy, 2);
- table.AddEntryInt("SurveillanceRecorder","IsAudioNsOn",iIsAudioNsOn,0);
-
- table.Load(spConfig);
- }
- if (8 != iAudioSampleRate){
- iAudioSampleRate = 16;
- }
- conf->iaudiosamplerate = iAudioSampleRate*1000;
- SetAudioQuality(iAudioQuality);
- SetAudioNsPolicy(iAudioNsPolicy);
- if (0 != iIsAudioNsOn){
- m_bIsAudioNsOn = true;
- }
- // edit by ly@2018/11/12
- if (!m_bRecordAllowed)
- {
- if (m_secondBranchAllowed && strSecondBranch.GetLength() > 0)
- {
- auto a1 = strSecondBranch.Split(',');
- if (a1.GetCount() > 0)
- {
- m_secondBranchParams = CAutoArray<SecondBranchParam>(a1.GetCount());
- for (int i = 0; i < a1.GetCount(); ++i)
- {
- memset(&m_secondBranchParams[i], 0, sizeof(SecondBranchParam));
- auto a2 = a1[i].Split('|');
- m_secondBranchParams[i].szDevicePrefix = a2[0];
- if (a2.GetCount() > 1)
- {
- m_secondBranchParams[i].bAutoMode = (!strcmp((LPCTSTR)a2[1], "1") ? TRUE : FALSE);
- }
- Dbg("secondBranchParams[%d]:%s,%d",i,
- (LPCTSTR)m_secondBranchParams[i].szDevicePrefix,
- m_secondBranchParams[i].bAutoMode);
- }
- }
- for (int i = 0; i < m_secondBranchParams.GetCount(); ++i)
- {
- int len = m_secondBranchParams[i].szDevicePrefix.GetLength();
- if (m_terminalNo.GetLength() >= len)
- {
- if (m_terminalNo.SubString(0, len) == m_secondBranchParams[i].szDevicePrefix)
- {
- m_bRecordAllowed = true;
- m_bAutoMode = m_secondBranchParams[i].bAutoMode;
- Dbg("bRecordAllowed:%d,m_bAutoMode:%d", m_bRecordAllowed, m_bAutoMode);
- break;
- }
- }
- }
- }
- }
- if (m_max_disk_percent < 0 || m_max_disk_percent > 100)
- {
- m_max_disk_percent = MAX_DISK_PERCENT;
- }
- table.Clear();
- Error = spFunction->OpenConfig(Config_Root, spConfig);
- if (Error == Error_Succeed)
- {
- table.AddEntryString("audio", "ews_in_dev", conf->strAudioIn, "$");
- table.AddEntryBoolean("audio", "ews_in_agc", conf->audio_ews_in_agc, false);
- table.AddEntryBoolean("audio", "ews_in_ns", conf->audio_ews_in_ns, false);
- table.AddEntryBoolean("audio", "ews_aec", conf->audio_ews_aec, false);
- table.AddEntryInt("audio", "ews_in_volume", m_kept_volume_in, 0);
- table.AddEntryString("Video", "EwsCamera", conf->strVideo, "$");
- table.AddEntryInt("Video", "EwsRotate", conf->video_rotate, 0);
- table.AddEntryString("Video", "EnvCamera", m_strEnvCam, "$");
- table.AddEntryString("Video", "OptCamera", m_strOptCam, "$");
- Error = table.Load(spConfig);
- if (Error == Error_Succeed) {
- //ews配置名自纠正
- AutoCorrectCameraConfigName(5000);
-
- conf->video_dev = ews_capture_get_video_device_id((LPCTSTR)conf->strVideo,m_CamFriendlyName);
- if (conf->video_dev == -1)
- {
- Dbg("find conf->strVideo:%s(-1)",(LPCTSTR)conf->strVideo);
- LogError(Severity_Middle,Error_DevMedia,ERROR_MOD_SURVEILLANCERECORDER_EWSCAM_INITFAIL,"external wide scale camera start error,please check config file or device");
- Error = Error_EwsCamera;
- return Error;
- }
- int nAudioId = ews_capture_get_audio_device_id(true, (LPCTSTR)conf->strAudioIn);
- if (nAudioId == -1)
- {
- Dbg("conf->strAudioIn:%s(-1)",(LPCTSTR)conf->strAudioIn);
- Error = Error_AudioIN;
- return Error;
- }
- }
- else
- {
- LOG_TRACE("load config failed!");
- }
- }
- else
- {
- LOG_TRACE("open config failed!");
- }
- return Error;
- }
- ErrorCodeEnum CSurveillanceRecorderEntity::CheckConfigEWSCameraName(){
- ErrorCodeEnum Error = Error_Succeed;
- CSimpleStringA strEwsCamFriendlyName = "$";
- //check Ews device
- if (conf.strVideo.GetLength() > 1)
- { // is not "$"
- int ews_id = ews_capture_get_video_device_id((LPCTSTR)conf.strVideo, strEwsCamFriendlyName);
- if (ews_id == -1)
- {
- Dbg("find strEwsCam:%s(-1)",(LPCTSTR)conf.strVideo);
- Error = Error_EwsCamera;
- return Error;
- }
- }
- else
- {
- //广角摄像头未配置,此时也认为广角摄像头OK(无广角摄像头场景)
- }
- return Error;
- }
- void CSurveillanceRecorderEntity::AutoCorrectCameraConfigName(long wait_time) {
- ErrorCodeEnum Error = Error_Succeed;
- int one_timeout = 400;
- int retry = 0;
- //检查配置名都成功,不用自动纠正
- Error = CheckConfigEWSCameraName();
- 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)m_strEnvCam, (LPCSTR)m_strOptCam, (LPCSTR)conf.strVideo);
- Dbg("AutoCorrectCameraConfig, new EnvCamera;%s, OptCamera;%s, EwsCamera;%s",
- (LPCSTR)ans.EnvCamera, (LPCSTR)ans.OptCamera, (LPCSTR)ans.EwsCamera);
- if ((ans.EnvCamera.GetLength() > 1) && (m_strEnvCam.GetLength() > 1)){
- m_strEnvCam = ans.EnvCamera;
- }
- if ((ans.OptCamera.GetLength() > 1) && (m_strOptCam.GetLength() > 1)){
- m_strOptCam = ans.OptCamera;
- }
- if ((ans.EwsCamera.GetLength() > 1) && (conf.strVideo.GetLength() > 1)){
- conf.strVideo = ans.EwsCamera;
- }
- Dbg("AutoCorrectCameraConfig, updated EnvCamera;%s, OptCamera;%s, EwsCamera;%s",
- (LPCSTR)m_strEnvCam, (LPCSTR)m_strOptCam, (LPCSTR)conf.strVideo);
- }
- pCameraConfigManageClient->GetFunction()->CloseSession();
- pCameraConfigManageClient->SafeDelete();
- pCameraConfigManageClient = NULL;
- }
- }
- void CSurveillanceRecorderEntity::OnWideAngleCameraStartFailed( const char* pszFailedMsg )
- {
- if (!pszFailedMsg) {
- return;
- }
- // 通报广角摄像头启动时故障
- WideAngleCameraStartFailed evt;
- evt.failedmsg = CSimpleStringA2W(pszFailedMsg);
- SpSendBroadcast(GetFunction(), SP_MSG_OF(WideAngleCameraStartFailed), SP_MSG_SIG_OF(WideAngleCameraStartFailed), evt);
- Dbg("[dbg] WideAngleCameraStartFailed broadcast sent!");
- }
- void CSurveillanceRecorderEntity::OnSysVarEvent( const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName )
- {
- LOG_TRACE("entity:%s key:%s value:%s", pszEntityName, pszKey, pszValue);
- if (_stricmp(pszKey,SYSVAR_DISKSTATEUS_FOR_VIDEO) == 0)
- {
- if (pszValue)
- {
- char state = pszValue[0];
- if (state == 'U')
- {
- Dbg("unknown state, maybe the video path is empty.");
- m_last_disk_overtop = FALSE;
- }
- else if (state == 'S')
- {
- Dbg("free disk space for video is sufficient for at least 7 days!");
- m_last_disk_overtop = FALSE;
- }
- else if (state == 'W')
- {
- Dbg("[Warn] free disk space for video is not sufficient for 7 days!");
- m_last_disk_overtop = FALSE;
- }
- else if (state == 'E')
- {
- Dbg("[Warn] free disk space for video is not sufficient for 3 days!");
- m_last_disk_overtop = FALSE;
- }
- else if (state == 'F')
- {
- Dbg("[Warn] free disk space for video is not sufficient for 1 day!");
- if (m_bStartRecord)
- {
- LogEvent(Severity_High,LOG_EVT_CONTINURECORD_FAILED,"磁盘所剩空间不足,已停止全程双录!");
- }
- m_last_disk_overtop = TRUE;
- }
- else
- {
- m_last_disk_overtop = FALSE;
- }
- if (state != 'F')
- {
- if (m_bAutoMode && !m_bStartRecord && !m_bCamConfig)
- {
- LogEvent(Severity_Middle,LOG_EVT_START_CONTINURECORD,NULL);
- }
- }
- }
- }
- }
- void CSurveillanceRecorderEntity::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);
- if ((dwUserCode == LOG_EVT_UI_START_CONTINURECORD ||
- dwUserCode == LOG_EVT_START_CONTINURECORD) && !m_bCamConfig)
- {
- ContinuRecordStateCode statecode = GetContinuRecordState();
- if (statecode == State_EwsCameraConfigNotFound)
- {
- OnWideAngleCameraStartFailed("广角摄像头未配置!");
- return;
- }
- if (statecode == State_EwsCameraNotInserted)
- {
- OnWideAngleCameraStartFailed("广角摄像头未插入!");
- return;
- }
- if (statecode == State_EwsCameraStarting)
- {
- OnWideAngleCameraStartFailed("广角摄像头正在启动中!");
- return;
- }
- if (statecode == State_EwsCameraFault)
- {
- OnWideAngleCameraStartFailed("广角摄像头故障中!");
- if (m_bAutoMode && !m_bCamConfig) // add by ly at 2017/05/16
- {
- Sleep(5000);
- LogEvent(Severity_High,LOG_EVT_RESTART_EWSCAMERA,NULL);
- }
- return;
- }
- //if (!CheckDiskStatus("C:\\",m_max_disk_percent))
- //{
- // if (m_bAutoMode) // add by ly at 2017/05/16
- // {
- // if (!m_last_disk_overtop)
- // {
- // m_last_disk_overtop = TRUE;
- // OnWideAngleCameraStartFailed("磁盘所剩空间不足,无法开始全程双录!");
- // }
- // Sleep(5000);
- // LogEvent(Severity_High,LOG_EVT_RESTART_EWSCAMERA,NULL);
- // }
- // else
- // {
- // m_last_disk_overtop = TRUE;
- // OnWideAngleCameraStartFailed("磁盘所剩空间不足,无法开始全程双录!");
- // }
- // return;
- //}
- //else
- //{
- // m_last_disk_overtop = FALSE;
- //}
- CSimpleStringA strDiskStatus;
- GetFunction()->GetSysVar(SYSVAR_DISKSTATEUS_FOR_VIDEO,strDiskStatus);
- Dbg("Disk status for video on start record:%s.",(LPCTSTR)strDiskStatus);
- if (strDiskStatus.GetLength()>0&&strDiskStatus[0]=='F')
- {
- if (m_bAutoMode) // add by ly at 2017/05/16
- {
- if (!m_last_disk_overtop)
- {
- m_last_disk_overtop = TRUE;
- OnWideAngleCameraStartFailed("磁盘所剩空间不足,无法开始全程双录!");
- }
- }
- else
- {
- m_last_disk_overtop = TRUE;
- OnWideAngleCameraStartFailed("磁盘所剩空间不足,无法开始全程双录!");
- }
- return;
- }
- else
- {
- m_last_disk_overtop = FALSE;
- }
- if (!m_bStartCamera) // 若摄像头未启动,则先启动摄像头 edit by ly@20180725
- {
- StartCamera();
- }
- else
- {
- WideAngleCameraStateChanged evt;
- evt.statecod = State_EwsCameraStartSucceeded;
- evt.statemsg = CSimpleStringA2W("已启动广角摄像头!");
- evt.camname = CSimpleStringA2W(m_CamFriendlyName.GetLength()>1?m_CamFriendlyName:"广角");
- SpSendBroadcast(GetFunction(), SP_MSG_OF(WideAngleCameraStateChanged), SP_MSG_SIG_OF(WideAngleCameraStateChanged), evt);
- Dbg("[dbg] WideAngleCameraStateChanged broadcast sent!");
- }
- if (m_bStartCamera)
- {
- // 开始全程录像
- Dbg("start record!");
- //StartRecord(pszMessage);
- m_uid = CUUID::Create(m_uid);
- m_RecordBeginTime = m_uid.GetTime().ToTimeString();
- Dbg("RecordBeginTime:%s", (LPCTSTR)m_RecordBeginTime);
- StopRecord(); // 如果正在录像,则先停止
- if (pszMessage&&strlen(pszMessage)>0)
- {
- StartRecord(pszMessage);
- }
- else
- {
- CSimpleStringA videoname = CSimpleStringA::Format("G_%s",(LPCTSTR)m_uid.ToString());
- StartRecord((LPCTSTR)videoname);
- }
- // 开始录像计时和数据记录
- RecordInit();
- GetFunction()->SetTimer(TIMERID_RECORD, this, RECORD_CYCLE);
- }
- else
- {
- if (m_bAutoMode && !m_bCamConfig) // edit by ly 2017/04/12
- {
- LogEvent(Severity_High,LOG_EVT_RESTART_EWSCAMERA,NULL);
- }
- }
- }
- else if (dwUserCode == LOG_EVT_UI_STOP_CONTINURECORD ||
- dwUserCode == LOG_EVT_STOP_CONTINURECORD)
- {
- Dbg("stop record!");
- StopEchoRecord(); // 停止回显
- StopRecord(); // 停止全程录像
- StopCamera(); // 停止摄像头
- GetFunction()->KillTimer(TIMERID_RECORD);
- std::string strWmvFile;
- BOOL bRet = GetCurrentSectionBySerialID((LPCTSTR)m_uid.ToString(),strWmvFile);
- if (!bRet)
- {
- Dbg("failed to get current record file name!");
- }
- bRet = UpdateVideoRecord(strWmvFile.c_str());
- if (!bRet)
- {
- Dbg("failed to update video record!");
- }
- CSimpleStringA srcfn = CSimpleStringA::Format("%s%s",
- (LPCTSTR)m_TempDir,strWmvFile.c_str());
- CSimpleStringA dstfn = CSimpleStringA::Format("%s%s",
- (LPCTSTR)m_RecordSaveDir,strWmvFile.c_str());
- bRet = MoveFile((LPCSTR)srcfn, (LPCSTR)dstfn);
- if(!bRet) {
- Dbg("Error Code %lu while move %s ", GetLastError(), (LPCSTR)srcfn);
- }
- //GetFunction()->KillTimer(TIMERID_UPLOAD);
- CSimpleStringA cfn = CSimpleStringA::Format("%sG_%s.txt",(LPCTSTR)m_TempDir,(LPCTSTR)m_uid.ToString());
- UploadVideoRecord((LPCTSTR)cfn);
- if (!stricmp(pszMessage,"Fault"))
- {
- if (m_bAutoMode && !m_bCamConfig) // edit by ly 2017/04/12
- {
- LogEvent(Severity_High,LOG_EVT_RESTART_EWSCAMERA,NULL);
- }
- else
- {
- Dbg("[dbg] camera fault, RealSelfCheck!");
- RealSelfCheck();
- }
- }
- else
- {
- m_nCameraErrorCode = Error_Succeed;
- if ((ePadtype==m_eDeviceType||eDesk2SType==m_eDeviceType)&&m_bRecordAllowed) // 重新开始全程录像 edit by ly 2017/04/12
- {
- //GetFunction()->SetTimer(TIMERID_UPLOAD,this,UPLOAD_CYCLE);
- if ((dwUserCode == LOG_EVT_STOP_CONTINURECORD || m_bAutoMode == true) && !m_bCamConfig)
- {
- LogEvent(Severity_Middle,LOG_EVT_START_CONTINURECORD,NULL);
- }
- }
- }
- }
- else if (dwUserCode == LOG_EVT_UI_START_ECHO_CONTINURECORD && !m_bCamConfig)
- {
- // 开始回显全程录像画面
- Dbg("start to echo continuous record, get pos = %s",pszMessage);
- int xPos,yPos,width,height;
- sscanf(pszMessage, "%d@%d@%d@%d", &xPos, &yPos, &width, &height);
- Dbg("x=%d,y=%d,width=%d,height=%d",xPos,yPos,width,height);
- int ScreenWidth = GetSystemMetrics(SM_CXSCREEN); //主屏幕宽度
- int ScreenHeight = GetSystemMetrics(SM_CYSCREEN); //主屏幕高度
- if (xPos<0||yPos<0||width<0||height<0||
- xPos+width>ScreenWidth||yPos+height>ScreenHeight) //
- {
- // 弹出模态窗口提示回显参数不正确
- MessageBoxA(NULL,(LPCSTR)("窗口参数不正确,无法回显录像!"),NULL,MB_SYSTEMMODAL);
- return;
- }
- StartEchoRecord(xPos, yPos, width, height);
- }
- else if (dwUserCode == LOG_EVT_UI_STOP_ECHO_CONTINURECORD)
- {
- // 停止回显全程录像画面
- StopEchoRecord();
- }
- else if (dwUserCode == LOG_EVT_CONTINURECORD_FAILED)
- {
- // 通知到业务中台
- ContinuRecordFailed evt;
- evt.failedmsg = CSimpleStringA2W(pszMessage==NULL?"全程双录失败!":pszMessage);
- SpSendBroadcast(GetFunction(), SP_MSG_OF(ContinuRecordFailed), SP_MSG_SIG_OF(ContinuRecordFailed), evt);
- Dbg("[dbg] ContinuRecordFailed broadcast sent!");
- if (m_bEchoRecord&&pSession)
- {
- if (pszMessage==NULL)
- {
- MessageBoxA(NULL,(LPCSTR)("全程双录失败,回显停止!"),NULL,MB_SYSTEMMODAL);
- }
- else
- {
- CSimpleStringA txt = CSimpleStringA::Format("%s回显停止!",pszMessage);
- MessageBoxA(NULL,(LPCSTR)txt,NULL,MB_SYSTEMMODAL);
- }
- }
- // 录像故障,停止回显,结束录像,停止摄像头
- StopEchoRecord();
- StopRecord();
- StopCamera();
-
- GetFunction()->KillTimer(TIMERID_RECORD);
- std::string strWmvFile;
- BOOL bRet = GetCurrentSectionBySerialID((LPCTSTR)m_uid.ToString(),strWmvFile);
- if (!bRet)
- {
- Dbg("failed to get current record file name!");
- }
- bRet = UpdateVideoRecord(strWmvFile.c_str());
- if (!bRet)
- {
- Dbg("failed to update video record!");
- }
- CSimpleStringA srcfn = CSimpleStringA::Format("%s%s",
- (LPCTSTR)m_TempDir,strWmvFile.c_str());
- CSimpleStringA dstfn = CSimpleStringA::Format("%s%s",
- (LPCTSTR)m_RecordSaveDir,strWmvFile.c_str());
- bRet = MoveFile((LPCSTR)srcfn, (LPCSTR)dstfn);
- if(!bRet) {
- Dbg("Error Code %lu while move %s ", GetLastError(), (LPCSTR)srcfn);
- }
- //GetFunction()->KillTimer(TIMERID_UPLOAD);
- CSimpleStringA cfn = CSimpleStringA::Format("%sG_%s.txt",(LPCTSTR)m_TempDir,(LPCTSTR)m_uid.ToString());
- UploadVideoRecord((LPCTSTR)cfn);
- m_nCameraErrorCode = Error_Succeed;
- if (m_bAutoMode && !pszMessage && !m_bCamConfig) // edit by ly at 2017/05/25
- {
- LogEvent(Severity_High,LOG_EVT_RESTART_EWSCAMERA,NULL);
- }
- }
- else if (dwUserCode == EVENT_USB_CAMER_INPUT)
- {
- Dbg("[dbg] usbcam %s inserted.", pszMessage);
- ::Sleep(2000); // 延迟2s后判断
- //ews配置名自纠正
- AutoCorrectCameraConfigName(4000);
-
- if ((ePadtype==m_eDeviceType||eDesk2SType==m_eDeviceType)&&m_bRecordAllowed) // edit by ly 2017/04/12
- {
- if (!stricmp((LPCTSTR)conf.strVideo,pszMessage))
- {
- m_bCameraInserted = TRUE;
- // 通报广角摄像头已经插入
- WideAngleCameraInserted evt;
- evt.camname = CSimpleStringA2W(m_CamFriendlyName.GetLength()>1?m_CamFriendlyName:"全程双录");
- SpSendBroadcast(GetFunction(), SP_MSG_OF(WideAngleCameraInserted), SP_MSG_SIG_OF(WideAngleCameraInserted), evt);
- Dbg("[dbg] WideAngleCameraInserted broadcast sent!");
- //GetFunction()->SetTimer(TIMERID_UPLOAD,this,UPLOAD_CYCLE);
- if (m_bAutoMode && !m_bCamConfig)
- {
- LogEvent(Severity_Middle,LOG_EVT_START_CONTINURECORD,NULL);
- }
- }
- }
- }
- else if (dwUserCode == EVENT_USB_CAMER_OUTPUT)
- {
- Dbg("[dbg] usbcam %s removed.", pszMessage);
- //::Sleep(1000); // 延迟1s后判断
- if (!stricmp((LPCTSTR)conf.strVideo,pszMessage))
- {
- // 及时通知正在用广角摄像头双录的业务 add by ly@2019/04/25
- if (m_bExternStartCam)
- {
- SetCameraSysVar(CAMERA_EWS_ERROR);
- }
- if ((ePadtype==m_eDeviceType||eDesk2SType==m_eDeviceType)&&m_bRecordAllowed)
- {
- m_bCameraInserted = FALSE;
- // 通报故障(正在使用时拔出广角摄像头)
- WideAngleCameraRemoved evt;
- evt.camname = CSimpleStringA2W(m_CamFriendlyName.GetLength()>1?m_CamFriendlyName:"全程双录");
- SpSendBroadcast(GetFunction(), SP_MSG_OF(WideAngleCameraRemoved), SP_MSG_SIG_OF(WideAngleCameraRemoved), evt);
- Dbg("[dbg] WideAngleCameraRemoved broadcast sent!");
- if (m_bEchoRecord&&pSession)
- {
- MessageBoxA(NULL,(LPCSTR)("广角摄像头已移除,回显停止!"),NULL,MB_SYSTEMMODAL);
- }
- StopEchoRecord(); // 停止回显
- StopRecord(); // 结束录像
- StopCamera(); // 停止摄像头
- m_nCameraErrorCode = Error_Succeed;
- GetFunction()->KillTimer(TIMERID_RECORD);
- std::string strWmvFile;
- BOOL bRet = GetCurrentSectionBySerialID((LPCTSTR)m_uid.ToString(),strWmvFile);
- if (!bRet)
- {
- Dbg("failed to get current record file name!");
- }
- bRet = UpdateVideoRecord(strWmvFile.c_str());
- if (!bRet)
- {
- Dbg("failed to update video record!");
- }
- CSimpleStringA srcfn = CSimpleStringA::Format("%s%s",
- (LPCTSTR)m_TempDir,strWmvFile.c_str());
- CSimpleStringA dstfn = CSimpleStringA::Format("%s%s",
- (LPCTSTR)m_RecordSaveDir,strWmvFile.c_str());
- bRet = MoveFile((LPCSTR)srcfn, (LPCSTR)dstfn);
- if(!bRet) {
- Dbg("Error Code %lu while move %s ", GetLastError(), (LPCSTR)srcfn);
- }
- //GetFunction()->KillTimer(TIMERID_UPLOAD);
- CSimpleStringA cfn = CSimpleStringA::Format("%sG_%s.txt",(LPCTSTR)m_TempDir,(LPCTSTR)m_uid.ToString());
- UploadVideoRecord((LPCTSTR)cfn);
- }
- }
- }
- else if (dwUserCode == LOG_EVT_RESTART_EWSCAMERA && !m_bCamConfig)
- {
- //if (!CheckDiskStatus("C:\\",m_max_disk_percent))
- //{
- // if (!m_last_disk_overtop) // edit by ly at 2017/05/17
- // {
- // m_last_disk_overtop = TRUE;
- // OnWideAngleCameraStartFailed("磁盘所剩空间不足,无法开始全程双录!");
- // }
- // Sleep(5000);
- // LogEvent(Severity_High,LOG_EVT_RESTART_EWSCAMERA,NULL);
- // return;
- //}
- //else
- //{
- // m_last_disk_overtop = FALSE;
- //}
- // 尝试重启广角摄像头(至多3次,达到3次即重启实体)
- int tryFailedTimes=0;
- do
- {
- StartCamera();
- if (m_bStartCamera)
- {
- // 开始全程录像
- Dbg("start record!");
- m_uid = CUUID::Create(m_uid);
- m_RecordBeginTime = m_uid.GetTime().ToTimeString();
- Dbg("RecordBeginTime:%s", (LPCTSTR)m_RecordBeginTime);
- StopRecord(); // 如果正在录像,则先停止
- if (pszMessage&&strlen(pszMessage)>0)
- {
- StartRecord(pszMessage);
- }
- else
- {
- CSimpleStringA videoname = CSimpleStringA::Format("G_%s",(LPCTSTR)m_uid.ToString());
- StartRecord((LPCTSTR)videoname);
- }
- // 开始录像计时和数据记录
- RecordInit();
- GetFunction()->SetTimer(TIMERID_RECORD, this, RECORD_CYCLE);
- break;
- }
- else
- {
- tryFailedTimes++;
- }
- } while (tryFailedTimes<3);
- if (tryFailedTimes>=3)
- {
- Dbg("restart camera failed for 3 times, restart entity now.");
- RealSelfCheck();
- }
- }
- else if (dwUserCode == LOG_EVT_CONTINURECORD_SECTION_FINISHED)
- {
- CSimpleStringA filename = pszMessage;
- int pos = filename.IndexOf("G");
- filename = filename.SubString(pos, filename.GetLength() - pos);
- BOOL bRet = UpdateVideoRecord((LPCTSTR)filename);
- if (!bRet)
- {
- Dbg("failed to update video record!");
- GetFunction()->SetTimer(TIMERID_RECORD, this, RECORD_CYCLE);
- return;
- }
- CSimpleStringA dstfn = CSimpleStringA::Format("%s%s",
- (LPCTSTR)m_RecordSaveDir,(LPCTSTR)filename);
- bRet = MoveFile(pszMessage, (LPCSTR)dstfn);
- if(!bRet) {
- Dbg("Error Code %lu while move %s ", GetLastError(), pszMessage);
- }
- GetFunction()->SetTimer(TIMERID_RECORD, this, RECORD_CYCLE);
- }
- else if (dwUserCode == LOG_EVT_BEGIN_CAMERA_CONFIG)
- {
- ExternBeginControl();
- }
- else if (dwUserCode == LOG_EVT_END_CAMERA_CONFIG)
- {
- ExternEndControl();
- }
- else if(LOG_EVT_CONTINURECORD_ENTITY_EXCEPTION == dwUserCode)
- {
- HandleContinurecordEntityException(pszMessage);
- }
- }
- void CSurveillanceRecorderEntity::OnSelfTest( EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext )
- {
- if (Test_ShakeHand == eTestType)
- {
- if ((ePadtype==m_eDeviceType||eDesk2SType==m_eDeviceType)&&m_bRecordAllowed) {
- if (conf.strVideo.GetLength()>1&&conf.strAudioIn.GetLength()>1&&m_bCameraInserted) {
- if (m_nCameraErrorCode != Error_Succeed) {
- Dbg("[dbg][OnSelfTest] m_nCameraErrorCode:0x%x", m_nCameraErrorCode);
- pTransactionContext->SendAnswer(Error_Unexpect);
- m_nCameraErrorCode = Error_Succeed;
- }
- else {
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- }
- else {
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- if (m_bNeedRestart){
- Dbg("[OnSelfTest] need restart entity now.");
- pTransactionContext->SendAnswer(Error_Unexpect);
- }
- }
- else {
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- }
- }
- ErrorCodeEnum CSurveillanceRecorderEntity::StartEwsCamera()
- {
- if (m_ews_capture == NULL)
- {
- //ews配置名自纠正
- AutoCorrectCameraConfigName(4000);
-
- ErrorCodeEnum Error = Error_Succeed;
- conf.ref_ews_capture_count = &m_lCaptureEwsCount;
- Error = (ErrorCodeEnum)ews_capture_create(&conf, &m_ews_capture);
- if (Error == Error_Succeed)
- {
- Error = ews_capture_start(m_ews_capture);
- Dbg("Error code=0x%x",Error);
- if (Error != Error_Succeed)
- {
- if (Error == Error_EwsCamera)
- {
- ews_capture_destroy(m_ews_capture);
- m_ews_capture = NULL;
- return Error;
- }
- else // Error_AudioIN
- {
- return Error;
- }
- }
- else
- {
- SetAutoBright(Error);
- GetFunction()->SetTimer(TIMERID_CAMCHK, this, CAMCHK_CYCLE);
- return Error_Succeed;
- }
- }
- else
- {
- Dbg("create ews_capture failed! %d", Error);
- m_ews_capture = NULL;
- return Error_Unexpect;
- }
- return Error;
- }
- else
- {
- Dbg("m_ews_capture == NULL");
- return Error_Unexpect;
- }
- }
- void CSurveillanceRecorderEntity::StartCamera()
- {
- // 通报正在启动广角摄像头
- SetCameraSysVar(CAMERA_START_ING);
- WideAngleCameraStateChanged evt;
- evt.statecod = State_EwsCameraStarting;
- evt.statemsg = CSimpleStringA2W("广角摄像头启动中,请稍等……");
- evt.camname = CSimpleStringA2W(m_CamFriendlyName.GetLength()>1?m_CamFriendlyName:"广角");
- SpSendBroadcast(GetFunction(), SP_MSG_OF(WideAngleCameraStateChanged), SP_MSG_SIG_OF(WideAngleCameraStateChanged), evt);
- Dbg("[dbg] WideAngleCameraStateChanged broadcast sent!");
- // 启动广角摄像头
- ErrorCodeEnum Error = StartEwsCamera();
- if (Error!=Error_Succeed)
- {
- Dbg("[dbg] Start Ews Camera Error=0x%x", Error);
- if(Error == Error_EwsCamera)
- {
- m_bStartCamera = FALSE;
- //SetCameraSysVar(CAMERA_EWS_ERROR);
- Dbg("Camera State to Error_EwsCamera");
- m_nCameraErrorCode = Error_EwsCamera;
- GetFunction()->SetUserDefineState(USER_SURVEILLANCE_EWSERROR);
- }
- else
- {
- //SetCameraSysVar(Error);
- Dbg("Camera State to Other Error");
- m_nCameraErrorCode = Error;
- m_bStartCamera = FALSE;
- }
- OnWideAngleCameraStartFailed("广角摄像头启动失败!");
- if (!m_bAutoMode)
- {
- RealSelfCheck();
- }
- }
- else
- {
- if (m_bRecordAllowed&&!m_pRecorder)
- {
- BOOL bRet = FALSE;
- m_pRecorder = new Clibwmvrecord(&bRet, this, REC_COMMON_AUDIO_EWS_SHM_QUEUE, REC_COMMON_VIDEO_EWS_SHM_RTP_QUEUE, NULL);
- }
- // 通报广角摄像头已经成功启动
- m_bStartCamera = TRUE;
- Dbg("Camera State to CAMERA_NO_ERROR");
- m_nCameraErrorCode = Error_Succeed;
- GetFunction()->SetUserDefineState(USER_SURVEILLANCE_IDLE);
- WideAngleCameraStateChanged evt;
- evt.statecod = State_EwsCameraStartSucceeded;
- evt.statemsg = CSimpleStringA2W("已启动广角摄像头!");
- evt.camname = CSimpleStringA2W(m_CamFriendlyName.GetLength()>1?m_CamFriendlyName:"广角");
- SpSendBroadcast(GetFunction(), SP_MSG_OF(WideAngleCameraStateChanged), SP_MSG_SIG_OF(WideAngleCameraStateChanged), evt);
- Dbg("[dbg] WideAngleCameraStateChanged broadcast sent!");
- }
- SetCameraSysVar(CAMERA_NO_ERROR);
- }
- void CSurveillanceRecorderEntity::StopEwsCamera()
- {
- // edit by ly@2019/04/18
- if ((ePadtype==m_eDeviceType||eMobilePadType==m_eDeviceType||eDesk2SType==m_eDeviceType)&&m_bStartCamera)
- {
- Dbg("Stop EwsCamera.");
- if (m_ews_capture)
- {
- GetFunction()->KillTimer(TIMERID_CAMCHK);
- ews_capture_stop(m_ews_capture);
- ews_capture_destroy(m_ews_capture);
- m_ews_capture = NULL;
- }
- SetCameraSysVar(CAMERA_NO_ERROR);
- m_bStartCamera = FALSE;
- }
- }
- void CSurveillanceRecorderEntity::StopCamera()
- {
- // edit by ly@20180725
- if (!m_bExternStartCam)
- {
- StopEwsCamera();
- }
- }
- ErrorCodeEnum CSurveillanceRecorderEntity::ReStartEwsCamera()
- {
- if (m_ews_capture != NULL)
- {
- if((ews_stop_camera(m_ews_capture)==-1))
- {
- Dbg("ReStartCamera,stop camera fail!");
- }
- Sleep(2000);
- //ews配置名自纠正
- AutoCorrectCameraConfigName(4000);
-
- ErrorCodeEnum Error = Error_Succeed;
- Error = ews_capture_create(&conf, m_ews_capture);
- if (Error == Error_Succeed)
- {
- Error = ews_capture_start(m_ews_capture);
- if (Error != Error_Succeed)
- {
- Dbg("ReStartCamera,capture_start fail!");
- ews_capture_destroy(m_ews_capture);
- return Error;
- }
- else
- {
- Dbg("ReStartCamera success!");
- return Error_Succeed;
- }
- }
- else
- {
- Dbg("ReStartCamera,capture_create fail!");
- ews_capture_destroy(m_ews_capture);
- return Error;
- }
- }
- else
- {
- return Error_Unexpect;
- }
- }
- void CSurveillanceRecorderEntity::StartRecord( const char *wmvfilename)
- {
- Dbg("wmvfilename = %s", wmvfilename);
- int fps = 5;
- SubtitleParam subtitleParam;
- ZeroMemory(&subtitleParam,sizeof(SubtitleParam));
- subtitleParam.bSubtitle = TRUE;
- subtitleParam.bSubtitleSection = FALSE;
- Rvc_RecordAudioParam_t tAudioParams;
- tAudioParams.eRecordType = eSingleSide;
- tAudioParams.eOutPutType = m_eAudioOutQuality;
- tAudioParams.bIsNsOn = false;
- tAudioParams.iNsPolicy = 2;
- tAudioParams.iAudioOutBitRate = 8;
- tAudioParams.bIsTransOn = false;
- if (m_pRecorder->StartWmvRecord(fps, 90, &tAudioParams, &subtitleParam, FALSE, FALSE, (LPCSTR)m_TempDir,
- m_TempDir.GetLength(), wmvfilename, strlen(wmvfilename))) {
- m_bStartRecord = TRUE;
- }
- }
- void CSurveillanceRecorderEntity::StopRecord()
- {
- if (m_bStartRecord)
- {
- m_bStartRecord = FALSE;
- m_pRecorder->StopWmvRecord();
- }
- }
- void CSurveillanceRecorderEntity::StartEchoRecord( int x, int y, int w, int h )
- {
- videoplay_session_conf_t video_conf;
- memset(&video_conf,0,sizeof(video_conf));
- video_conf.local_video_view_x = x;
- video_conf.local_video_view_y = y;
- video_conf.local_video_view_cx = w;
- video_conf.local_video_view_cy = h;
- //video_conf.ref_camera_state = &m_iCameraState;
- video_conf.pHostApi = this;
- strcpy(video_conf.local_video_preview_queue0,REC_COMMON_VIDEO_EWS_SHM_PREVIEW_QUEUE);
- int rc = Local_videoplay_session_create(&video_conf, &pSession);
- if (rc != 0)
- {
- Dbg("create video play session failed! rc = %d", rc);
- }
- else
- {
- rc = Local_videoplay_session_start(pSession);
- if (rc != 0)
- {
- Dbg("start video play session failed! rc = %d", rc);
- Local_videoplay_session_destroy(pSession);
- pSession = NULL;
- }
- else
- {
- m_bEchoRecord = TRUE;
- Dbg("start video play session succeed! rc = %d", rc);
- }
- }
- }
- void CSurveillanceRecorderEntity::StopEchoRecord()
- {
- if (m_bEchoRecord&&pSession)
- {
- m_bEchoRecord = FALSE;
- Local_videoplay_session_stop(pSession);
- Local_videoplay_session_destroy(pSession);
- pSession = NULL;
- Dbg("video play session stopped!");
- }
- }
- ErrorCodeEnum CSurveillanceRecorderEntity::LoadServerConfig()
- {
- CSmartPointer<IEntityFunction> spFunction = GetFunction();
- CSmartPointer<IConfigInfo> spConfig;
- ErrorCodeEnum Error = spFunction->OpenConfig(Config_CenterSetting, spConfig);
- if (Error == Error_Succeed) {
- CSimpleStringA str;
- Error = spConfig->ReadConfigValue("SurveillanceRecorder", "Server", str);
- if (Error == Error_Succeed)
- {
- Error = ParseIPAddress(str, m_server1, m_server1_port);
- }
- if (Error == Error_Succeed)
- {
- ErrorCodeEnum ErrorCode;
- ErrorCode = spConfig->ReadConfigValue("SurveillanceRecorder", "Server_Backup", str);
- if (ErrorCode == Error_Succeed)
- {
- ErrorCode = ParseIPAddress(str, m_server2, m_server2_port);
- }
- if (ErrorCode != Error_Succeed)
- {
- m_server2 = NULL;
- m_server2_port = 0;
- }
- }
- }
- return Error;
- }
- bool CSurveillanceRecorderEntity::SecureClientConnect()
- {
- if (m_pConnection!=NULL && m_pConnection->IsConnectionOK())
- {
- return true;
- }
- SecureClientRelease();
- m_pConnection = new CUploadRecordConnection(this);
- /*if (!m_pConnection->Connect(m_server1,m_server1_port,3))
- {
- SecureClientRelease();
- if ((m_server2!=NULL)&&(m_server2_port!=0)&&
- ((m_server2!=m_server1)||(m_server2_port!=m_server1_port)))
- {
- m_pConnection = new CUploadRecordConnection(this);
- if (!m_pConnection->Connect(m_server2,m_server2_port,3))
- {
- return false;
- }
- }
- }*/
- return m_pConnection->ConnectFromCentralSetting();
- }
- void CSurveillanceRecorderEntity::SecureClientRelease()
- {
- if (m_pConnection != NULL)
- {
- if (m_pConnection->IsConnectionOK())
- {
- m_pConnection->Close();
- }
- m_pConnection->DecRefCount();
- m_pConnection = NULL;
- }
- }
- BOOL CSurveillanceRecorderEntity::RecordInit()
- {
- CSimpleStringA fn = CSimpleStringA::Format("%sG_%s.txt",
- (LPCTSTR)m_TempDir,(LPCTSTR)m_uid.ToString());
- HANDLE hFile = CreateFile((LPCTSTR)fn,GENERIC_WRITE,FILE_SHARE_READ,
- NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
- if (hFile != INVALID_HANDLE_VALUE) {
- CloseHandle(hFile);
- hFile = NULL;
- WritePrivateProfileString("VideoRecord","LastLocalTime",
- (LPCTSTR)m_RecordBeginTime,(LPCTSTR)fn);
- WritePrivateProfileString("VideoRecord","LastFileCount","0",(LPCTSTR)fn);
-
- return TRUE;
- }
- else {
- Dbg("error to create file %s(error code:%d)!",(LPCTSTR)fn,GetLastError());
- return FALSE;
- }
- }
- BOOL CSurveillanceRecorderEntity::GetCurrentSectionBySerialID( const char* videoserialid, std::string &strWmvFile )
- {
- if (videoserialid == NULL)
- {
- return FALSE;
- }
- char wmvfilename[MAX_PATH] = {0};
- sprintf_s(wmvfilename, "G_%s*.wmv", videoserialid);
- std::vector<std::string> sfiles;
- BOOL bRet = FindMatchedFile((LPCSTR)m_TempDir, wmvfilename, sfiles);
- Dbg("bRet = %d while find %s", bRet, wmvfilename);
- if(!bRet)
- {
- strWmvFile = "";
- return FALSE;
- }
- std::vector<std::string>::iterator max_iter = max_element(sfiles.begin(),sfiles.end());
- strWmvFile = max_iter->c_str();
- return TRUE;
- }
- BOOL CSurveillanceRecorderEntity::UpdateVideoRecord(const char *videofilename)
- {
- CSimpleStringA fn;
- if (videofilename == NULL || strlen(videofilename) <= 1)
- {
- Dbg("videofilename is NULL or empty!");
- return FALSE;
- }
- fn = CSimpleStringA::Format("%s%s",(LPCTSTR)m_TempDir,videofilename);
- FILE *fin = fopen((LPCTSTR)fn, "rb");
- if (!fin)
- {
- fclose(fin);
- return FALSE;
- }
- int FileLen = 0;
- fseek(fin, 0, SEEK_END);
- FileLen = ftell(fin);
- fseek(fin, 0, SEEK_SET);
- fclose(fin);
- FileLen = int(1.0*FileLen/1024+0.5);
- char strtmp[20] = {0}, strtmpkey[20] = {0};
- int FileSeqNo = 0, FileCount = 0;
- sscanf(videofilename,"G_%[^_]_%d.wmv",strtmp,&FileSeqNo);
- FileCount = FileSeqNo + 1;
- CSimpleStringA cfn = CSimpleStringA::Format("%sG_%s.txt",
- (LPCTSTR)m_TempDir,strtmp);
- SYSTEMTIME st;
- GetLocalTime(&st);
- CSimpleStringA curtime = CSimpleStringA::Format("%4d-%02d-%02d %02d:%02d:%02d",
- st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute, st.wSecond);
- WritePrivateProfileString("VideoRecord","LastLocalTime",
- (LPCTSTR)curtime,(LPCTSTR)cfn);
- sprintf_s(strtmp, "%d", FileCount);
- WritePrivateProfileString("VideoRecord","LastFileCount",strtmp,(LPCTSTR)cfn);
- sprintf_s(strtmpkey, "%d_FileLength", FileSeqNo);
- sprintf_s(strtmp, "%d", FileLen);
- WritePrivateProfileString("VideoRecord",strtmpkey,strtmp,(LPCTSTR)cfn);
- return TRUE;
- }
- void CSurveillanceRecorderEntity::UploadVideoRecord(const char *videorecordname)
- {
- if (videorecordname == NULL)
- {
- if (SecureClientConnect())
- {
- auto arr = fileutil_get_sub_files((LPCTSTR)m_TempDir);
- if (arr != NULL)
- {
- char szTmp[64];
- std::vector<video_record_t *> videorecordlist;
- for (int i = 0; i < arr->nelts; ++i)
- {
- char *pszFile = ARRAY_IDX(arr, i, char*);
- if (strstr(pszFile,".txt") && strchr(pszFile,'G')
- && !strstr(pszFile,(LPCTSTR)m_uid.ToString()))
- {
- if (videorecordlist.size() >= MAX_LISTSIZE)
- {
- break;
- }
- video_record_t* r = ZALLOC_T(video_record_t);
- r->TerminalNo = _strdup((LPCTSTR)m_terminalNo);
- CSimpleStringA filename = pszFile;
- int pos = filename.IndexOf("G");
- filename = filename.SubString(pos, filename.GetLength() - pos);
- sscanf((LPCTSTR)filename, "G_%[^.].txt", szTmp);
- r->VideoSerialID = _strdup(szTmp);
- /*std::string strWmvFile;
- BOOL bRet = GetCurrentSectionBySerialID(szTmp,strWmvFile);
- if (bRet)
- {
- bRet = UpdateVideoRecord(strWmvFile.c_str());
- if (!bRet)
- {
- Dbg("failed to update video record!");
- }
- CSimpleStringA srcfn = CSimpleStringA::Format("%s%s",
- (LPCTSTR)m_TempDir,strWmvFile.c_str());
- CSimpleStringA dstfn = CSimpleStringA::Format("%s%s",
- (LPCTSTR)m_RecordSaveDir,strWmvFile.c_str());
- bRet = MoveFile((LPCSTR)srcfn, (LPCSTR)dstfn);
- if(!bRet) {
- Dbg("Error Code %lu while move %s ", GetLastError(), (LPCSTR)srcfn);
- }
- }*/
- GetPrivateProfileString("VideoRecord", "LastLocalTime", "", szTmp, 64, pszFile);
- r->EndTime = _strdup(szTmp);
- int nFileCount = GetPrivateProfileInt("VideoRecord", "LastFileCount", 0, pszFile);
- int nFileLen = 0;
- for (int j = 0; j < nFileCount; ++j)
- {
- sprintf_s(szTmp, "%d_FileLength", j);
- nFileLen += GetPrivateProfileInt("VideoRecord", szTmp, 0, pszFile);
- }
- r->FileLength = nFileLen;
- videorecordlist.push_back(r);
- }
- else if (strstr(pszFile,".wmv") && strchr(pszFile,'G')
- && !strstr(pszFile,(LPCTSTR)m_uid.ToString()))
- {
- CSimpleStringA strWmvFile = pszFile;
- int pos = strWmvFile.IndexOf("G");
- strWmvFile = strWmvFile.SubString(pos, strWmvFile.GetLength() - pos);
- CSimpleStringA srcfn = CSimpleStringA::Format("%s%s",
- (LPCTSTR)m_TempDir,(LPCTSTR)strWmvFile);
- CSimpleStringA dstfn = CSimpleStringA::Format("%s%s",
- (LPCTSTR)m_RecordSaveDir,(LPCTSTR)strWmvFile);
- BOOL bRet = MoveFile((LPCSTR)srcfn, (LPCSTR)dstfn);
- if(!bRet) {
- Dbg("Error Code %lu while move %s ", GetLastError(), (LPCSTR)srcfn);
- }
- }
- }
- Dbg("%d records added to upload list.", videorecordlist.size());
- toolkit_array_free2(arr);
- if (m_pConnection != NULL && m_pConnection->IsConnectionOK())
- {
- if (videorecordlist.size() > 0)
- {
- m_pConnection->SendVideoRecords(videorecordlist);
- }
- }
- for (std::vector<video_record_t *>::size_type i = 0; i < videorecordlist.size(); ++i)
- {
- video_record_destroy(videorecordlist[i]);
- }
- }
- //SecureClientRelease();
- }
- }
- else
- {
- if (SecureClientConnect())
- {
- if (m_pConnection != NULL && m_pConnection->IsConnectionOK())
- {
- char szTmp[64] = {0};
- video_record_t* r = ZALLOC_T(video_record_t);
- r->TerminalNo = _strdup((LPCTSTR)m_terminalNo);
- CSimpleStringA filename = videorecordname;
- int pos = filename.IndexOf("G");
- filename = filename.SubString(pos, filename.GetLength() - pos);
- sscanf((LPCTSTR)filename, "G_%[^.].txt", szTmp);
- r->VideoSerialID = _strdup(szTmp);
- GetPrivateProfileString("VideoRecord", "LastLocalTime", "", szTmp, 64, videorecordname);
- r->EndTime = _strdup(szTmp);
- int nFileCount = GetPrivateProfileInt("VideoRecord", "LastFileCount", 0, videorecordname);
- int nFileLen = 0;
- Dbg("nFileCount=%d",nFileCount);
- for (int j = 0; j < nFileCount; ++j)
- {
- sprintf_s(szTmp, "%d_FileLength", j);
- nFileLen += GetPrivateProfileInt("VideoRecord", szTmp, 0, videorecordname);
- }
- Dbg("nFileLen=%d",nFileLen);
- r->FileLength = nFileLen;
- m_pConnection->SendVideoRecord(r);
- video_record_destroy(r);
- }
- //SecureClientRelease();
- }
- }
- }
- void CSurveillanceRecorderEntity::OnEndUploadRecord( const char *videoserialid, int result )
- {
- Dbg("%s upload result: %d", videoserialid, result);
- if (0 == result)
- {
- Dbg("succeed to save video record: G_%s", videoserialid);
- CSimpleStringA cfn = CSimpleStringA::Format("%sG_%s.txt", (LPCTSTR)m_TempDir, videoserialid);
- DeleteFile(cfn);
- }
- }
- ErrorCodeEnum CSurveillanceRecorderEntity::ExternBeginControl()
- {
- Dbg("Extern begin control camera");
- m_bCamConfig = TRUE;
- if (m_ews_capture)
- {
- if (m_bStartRecord) m_bRecordPaused = TRUE;
- LogEvent(Severity_Middle,LOG_EVT_STOP_CONTINURECORD,NULL);
- GetFunction()->KillTimer(TIMERID_UPLOAD);
- }
- return Error_Succeed;
- }
- ErrorCodeEnum CSurveillanceRecorderEntity::ExternEndControl()
- {
- Dbg("Extern end control camera");
- m_bCamConfig = FALSE;
- if (m_bRecordPaused)
- {
- GetFunction()->SetTimer(TIMERID_UPLOAD,this,UPLOAD_CYCLE);
- LogEvent(Severity_Middle,LOG_EVT_START_CONTINURECORD,NULL);
- m_bRecordPaused = FALSE;
- }
- return Error_Succeed;
- }
- ErrorCodeEnum CSurveillanceRecorderEntity::HandleContinurecordEntityException(const char* pszMessage)
- {
- // 通知到业务中台
- ContinuRecordFailed evt;
- evt.failedmsg = CSimpleStringA2W(pszMessage==NULL?"全程双录异常!":pszMessage);
- SpSendBroadcast(GetFunction(), SP_MSG_OF(ContinuRecordFailed), SP_MSG_SIG_OF(ContinuRecordFailed), evt);
- Dbg("[dbg] ContinuRecord entity exception broadcast sent!");
- if (m_bEchoRecord&&pSession)
- {
- if (pszMessage==NULL)
- {
- MessageBoxA(NULL,(LPCSTR)("全程双录异常,回显停止!"),NULL,MB_SYSTEMMODAL);
- }
- else
- {
- CSimpleStringA txt = CSimpleStringA::Format("%s回显停止!",pszMessage);
- MessageBoxA(NULL,(LPCSTR)txt,NULL,MB_SYSTEMMODAL);
- }
- // 录像异常,停止回显
- StopEchoRecord();
- }
- //StopRecord();
- StopCamera();
- GetFunction()->KillTimer(TIMERID_RECORD);
- CUUID last_uid = m_uid;
- std::string strWmvFile;
- BOOL bRet = GetCurrentSectionBySerialID((LPCTSTR)last_uid.ToString(),strWmvFile);
- if (!bRet)
- {
- Dbg("failed to get current record file name!");
- }
- bRet = UpdateVideoRecord(strWmvFile.c_str());
- if (!bRet)
- {
- Dbg("failed to update video record!");
- }
- CSimpleStringA srcfn = CSimpleStringA::Format("%s%s",
- (LPCTSTR)m_TempDir,strWmvFile.c_str());
- CSimpleStringA dstfn = CSimpleStringA::Format("%s%s",
- (LPCTSTR)m_RecordSaveDir,strWmvFile.c_str());
- bRet = MoveFile((LPCSTR)srcfn, (LPCSTR)dstfn);
- if(!bRet) {
- Dbg("Error Code %lu while move %s ", GetLastError(), (LPCSTR)srcfn);
- }
- else{
- Dbg("Move File from %s to %s success. ", (LPCSTR)srcfn, (LPCSTR)dstfn);
- }
- //GetFunction()->KillTimer(TIMERID_UPLOAD);
- CSimpleStringA cfn = CSimpleStringA::Format("%sG_%s.txt",(LPCTSTR)m_TempDir,(LPCTSTR)last_uid.ToString());
- UploadVideoRecord((LPCTSTR)cfn);
- m_bNeedRestart = true;
- //重启实体
- RealSelfCheck();
- //重新开始全程双录
- //Dbg("Restart Continue Record.");
- //RestartContinueRecord();
- return Error_Succeed;
- }
- ErrorCodeEnum CSurveillanceRecorderEntity::RestartContinueRecord()
- {
- ErrorCodeEnum Error = Error_Succeed;
- Dbg("Start Camera!");
- StartCamera();
- // 重新开始全程录像
- Dbg("restart surveillance record!");
- m_uid = CUUID::Create(m_uid);
- m_RecordBeginTime = m_uid.GetTime().ToTimeString();
- Dbg("Restart Continue Record Name is %s, RecordBeginTime:%s", (LPCTSTR)m_uid.ToString(),(LPCTSTR)m_RecordBeginTime);
- //StopRecord(); // 如果正在录像,则先停止
- CSimpleStringA videoname = CSimpleStringA::Format("G_%s",(LPCTSTR)m_uid.ToString());
- StartRecord((LPCTSTR)videoname);
- // 开始录像计时和数据记录
- RecordInit();
- GetFunction()->SetTimer(TIMERID_RECORD, this, RECORD_CYCLE);
- return Error;
- }
- ErrorCodeEnum CSurveillanceRecorderEntity::SetAudioQuality(int iAudioQuality)
- {
- ErrorCodeEnum eRet = Error_Succeed;
- Dbg("iAudioQuality == %d.", iAudioQuality);
- switch (iAudioQuality)
- {
- case 1:
- m_eAudioOutQuality = eLowDefinition;
- break;
- case 2:
- m_eAudioOutQuality = eStandardDefinition;
- break;
- case 3:
- m_eAudioOutQuality = eHighDefinition;
- break;
- case 4:
- m_eAudioOutQuality = eUltraHD;
- break;
- default:
- m_eAudioOutQuality = eUltraHD;
- break;
- }
- return eRet;
- }
- ErrorCodeEnum CSurveillanceRecorderEntity::SetAudioNsPolicy(int iNsPolicy)
- {
- ErrorCodeEnum eRet = Error_Succeed;
- Dbg("iNsPolicy == %d.", iNsPolicy);
- if (1 == iNsPolicy || 3 == iNsPolicy){
- m_iAudioNsPolicy = iNsPolicy;
- }
- else{
- m_iAudioNsPolicy = 2;
- }
- return eRet;
- }
- SelfChekerClient::SelfChekerClient( CSurveillanceRecorderEntity *pEntity ) : SelfCheckerService_ClientBase(pEntity)
- {
- }
- void SurveillanceRecordServiceSession::Handle_GetContinuRecordInfo( SpReqAnsContext<SurveillanceRecorderService_GetContinuRecordInfo_Req, SurveillanceRecorderService_GetContinuRecordInfo_Ans>::Pointer ctx )
- {
- if (!(ePadtype==m_pEntity->m_eDeviceType||eDesk2SType==m_pEntity->m_eDeviceType)||!m_pEntity->m_bRecordAllowed)
- {
- ctx->Ans.Remark = CSimpleStringA2W("本设备不支持全程双录!");
- ctx->Answer(Error_Succeed);
- return;
- }
- if (m_pEntity->m_bStartRecord)
- {
- ctx->Ans.TerminalNo = CSimpleStringA2W(m_pEntity->m_terminalNo);
- ctx->Ans.RecordStartTime = CSimpleStringA2W(m_pEntity->m_RecordBeginTime);
- ctx->Ans.VideoSerialID = CSimpleStringA2W(m_pEntity->m_uid.ToString()); // 录像流水号
- if (!m_pEntity->m_bAutoMode)
- {
- ctx->Ans.Remark = CSimpleStringA2W("");
- }
- else
- {
- ctx->Ans.Remark = CSimpleStringA2W("AutoRecord");
- }
- }
- else
- {
- if (!m_pEntity->m_bAutoMode)
- {
- ctx->Ans.Remark = CSimpleStringA2W("录像未开始!");
- }
- else
- {
- ctx->Ans.Remark = CSimpleStringA2W("AutoRecord:录像未开始!");
- }
- }
- ctx->Answer(Error_Succeed);
- }
- void SurveillanceRecordServiceSession::Handle_GetContinuRecordState( SpReqAnsContext<SurveillanceRecorderService_GetContinuRecordState_Req, SurveillanceRecorderService_GetContinuRecordState_Ans>::Pointer ctx )
- {
- ctx->Ans.StateCode = m_pEntity->GetContinuRecordState();
- ctx->Answer(Error_Succeed);
- }
- void SurveillanceRecordServiceSession::Handle_GetContinuRecordMode( SpReqAnsContext<SurveillanceRecorderService_GetContinuRecordMode_Req, SurveillanceRecorderService_GetContinuRecordMode_Ans>::Pointer ctx )
- {
- ctx->Ans.IsAuto = m_pEntity->GetContinuRecordMode();
- ctx->Answer(Error_Succeed);
- }
- void SurveillanceRecordServiceSession::Handle_StartEwsCamera( SpReqAnsContext<SurveillanceRecorderService_StartEwsCamera_Req, SurveillanceRecorderService_StartEwsCamera_Ans>::Pointer ctx )
- {
- ErrorCodeEnum error = m_pEntity->ExternStartCamera();
- Dbg("ExternStartCamera:0x%x", error);
- int nRetCod = 7;
- CSimpleStringA strErrMsg;
- switch(error)
- {
- case Error_Succeed:
- nRetCod = 0;
- strErrMsg = "启动成功";
- break;
- case Error_Cancel:
- nRetCod = 1;
- strErrMsg = "设备类型非低柜双屏或PAD";
- break;
- case Error_Break:
- nRetCod = 2;
- strErrMsg = "当前处于摄像头配置模式";
- break;
- case Error_EwsCamera:
- nRetCod = 3;
- strErrMsg = "广角摄像头启动失败";
- break;
- case Error_InvalidState:
- nRetCod = 4;
- strErrMsg = "广角摄像头正在启动";
- break;
- case Error_Resource:
- nRetCod = 5;
- strErrMsg = "广角摄像头未配置";
- break;
- case Error_DevNotAvailable:
- nRetCod = 6;
- strErrMsg = "广角摄像头未插入";
- break;
- default:
- nRetCod = 7;
- strErrMsg = "发生其他错误";
- break;
- }
- ctx->Ans.StartErrorCode = nRetCod;
- ctx->Ans.StartErrorMsg = CSimpleStringA2W(strErrMsg);
- ctx->Answer(Error_Succeed);
- }
- void SurveillanceRecordServiceSession::Handle_StopEwsCamera( SpReqAnsContext<SurveillanceRecorderService_StopEwsCamera_Req, SurveillanceRecorderService_StopEwsCamera_Ans>::Pointer ctx )
- {
- ErrorCodeEnum error = m_pEntity->ExternStopCamera();
- Dbg("ExternStopCamera:0x%x", error);
- int nRetCod = 2;
- CSimpleStringA strErrMsg;
- if (error == Error_Succeed)
- {
- nRetCod = 0;
- strErrMsg = "停止成功";
- }
- else if (error == Error_Cancel)
- {
- nRetCod = 1;
- strErrMsg = "设备类型非低柜双屏或PAD";
- }
- else
- {
- nRetCod = 2;
- strErrMsg = "当前处于摄像头配置模式";
- }
- ctx->Ans.StopErrorCode = nRetCod;
- ctx->Ans.StopErrorMsg = CSimpleStringA2W(strErrMsg);
- ctx->Answer(Error_Succeed);
- }
- SP_BEGIN_ENTITY_MAP()
- SP_ENTITY(CSurveillanceRecorderEntity)
- SP_END_ENTITY_MAP()
|