| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455 |
- #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 = 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()
|