1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738 |
- #include "stdafx.h"
- #include "mod_SalesRecorder.h"
- using namespace SalesRecorder;
- #include "rvc_media_common.h"
- #include "fileutil.h"
- #include "array.h"
- #include <memutil.h>
- #include <algorithm>
- #include <Windows.h>
- #include "Event.h"
- #include "mod_customeraware/Event.h"
- #include "mod_facetracking/sysvar.h"
- #include <assert.h>
- #include "EventCode.h"
- #include "..\\mod_interactivecontrol\\InteractiveControl_client_g.h"
- #include "..\\mod_interactivecontrol\\InteractiveControl_def_g.h"
- #include "../mod_interactivecontrol/Event.h"
- using namespace InteractiveControl;
- #ifndef RVC_MIN_FILESIZE
- #define RVC_MIN_FILESIZE 10240
- #endif
- #define SYSVAR_CALLTYPE "CallType"
- #define CALLTYPE_NORMAL 'N' // 呼叫类型,普通模式
- #define CALLTYPE_MOBILE 'M' // 呼叫类型,手机模式
- #define MAX_DISK_PERCENT 95 // 磁盘最大占用百分比
- static const char* record_failed_case_table[] = {
- "[RTA3L01] 启动录像失败,初始化失败",
- "[RTA3L02] 启动录像失败,字体为空,添加水印失败",
- "[RTA3L03] 开始录像失败,请稍后(约30秒)再试",
- "[RTA3L04] 录像失败,摄像头故障,获取不到视频,请联系厂商进行维修",
- "[RTA3L05] 录像失败,获取不到远端音频,请检查风险提示音是否正常播放且音量大小是否正常",
- "[RTA3L06] 录像失败,麦克风故障,获取不到本地音频,请联系厂商进行维修",
- "[RTA3L07] 录像失败,系统不支持当前音频采样率",
- "[RTA3L08] 录像失败,音频流写入失败,请稍后(约30秒)再试",
- "[RTA3L09] 录像失败,获取不到远端视频,请稍后(约30秒)再试"
- };
- static BOOL CheckDiskStatus(const char *szRoot, int nPercent, int *pFreeRatio)
- {
- #ifdef RVC_OS_WIN
- _ULARGE_INTEGER lpFreeBytesAvailableToCaller = {}, lpTotalNumberOfBytes = {}, lpTotalNumberOfFreeBytes = {};
- BOOL ret = GetDiskFreeSpaceEx(szRoot, &lpFreeBytesAvailableToCaller, &lpTotalNumberOfBytes, &lpTotalNumberOfFreeBytes);
- if (ret == 0)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("CheckDiskStatus.GetDiskFreeSpaceEx failed(%d).",GetLastError());
- return FALSE;
- }
- DWORD dwTotal = lpTotalNumberOfBytes.QuadPart/1048576;
- DWORD dwTotalFree = lpTotalNumberOfFreeBytes.QuadPart/1048576;
- int ratio = dwTotalFree*100/dwTotal;
- *pFreeRatio = ratio;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("free disk %d MB, %d percent free.\n", dwTotalFree, ratio);
- //if (ratio < (100-MAX_DISK_PERCENT))
- if (ratio < (100-nPercent))
- {
- return FALSE;
- }
- return TRUE;
- #else
- //todo 调用resourcewatcher
- return TRUE;
- #endif
- }
- static int hch2int(char hch)
- {
- if (hch >= '0' && hch <= '9')
- return hch-'0';
- else if (hch >= 'a' && hch <= 'f')
- return hch-'a'+10;
- else if (hch >= 'A' && hch <= 'F')
- return hch-'A'+10;
- return 0;
- }
- static long hexstr2int(const char *str, int len)
- {
- long result = 0;
- if (str && len <= strlen(str)) {
- for (int i = 0; i < len; ++i) {
- result += (hch2int(str[i]) << ((len-i-1) << 2));
- }
- }
- return result;
- }
- static CSimpleStringA VideoSerialID2TimeString(const char *videoserialid)
- {
- DWORD nTimeTicks = hexstr2int(videoserialid,8);
- return ((CSmallDateTime)nTimeTicks).ToTimeString();
- }
- static void CStringSplit(char* str, char** result, const char* del)
- {
- char *p = strtok(str, del);
- while(p != NULL)
- {
- *result++ = p;
- p = strtok(NULL, del);
- }
- }
- // 寻找某目录下与通配符匹配的文件
- static BOOL FindMatchedFile(LPCSTR sFindPath, LPCSTR sFindFileName, ULONGLONG& uCountFile)
- {
- char sPath[MAX_PATH];
- ZeroMemory(sPath, MAX_PATH);
- char sFormatFileName[MAX_PATH + 2] = "*";
- WIN32_FIND_DATA FindFileData;
- HANDLE hFind;
- BOOL fFinished = FALSE;
- strcpy(sFormatFileName, sFindPath);
- if (sFindPath[strlen(sFindPath) - 1] != SPLIT_SLASH)
- {
- strcat(sFormatFileName, SPLIT_SLASH_STR);
- strcat(sFormatFileName, "*");
- }
- else
- {
- strcat(sFormatFileName, "*");
- }
- strcat(sFormatFileName, sFindFileName);
- strcat(sFormatFileName, "*");
- hFind = FindFirstFile(sFormatFileName, &FindFileData);
- if (hFind == INVALID_HANDLE_VALUE)
- {
- return FALSE;
- }
- else
- {
- while (!fFinished)
- {
- strcpy(sPath, sFindPath);
- if (sPath[strlen(sPath) - 1] != SPLIT_SLASH)
- {
- strcat(sPath, SPLIT_SLASH_STR);
- }
- strcat(sPath, FindFileData.cFileName);
- if (!(FILE_ATTRIBUTE_DIRECTORY & FindFileData.dwFileAttributes))
- {
- ++uCountFile;
- }
- if (!FindNextFile(hFind, &FindFileData))
- {
- if (GetLastError() == ERROR_NO_MORE_FILES)
- {
- fFinished = TRUE;
- }
- else
- {
- break;
- }
- }
- }
- FindClose(hFind);
- }
- return TRUE;
- }
- static CSimpleStringA DecryptString(LPCTSTR lpszEncrpyted)
- {
- if (NULL == lpszEncrpyted) {
- return CSimpleStringA("");
- }
- int iEncrypt = 0;
- int len = strlen(lpszEncrpyted);
- CSimpleStringA csPlainTxt('\0', (len) / 2 + 1);
- int iCh = 0;
- for (int i = 0; i < len; i += 2) {
- sscanf(lpszEncrpyted + i, "%02X", &iCh);
- csPlainTxt[i / 2] = (char)(((char)iCh) ^ (128 | (iEncrypt++ & 127)));
- }
- return CSimpleStringA((LPCTSTR)csPlainTxt);
- }
- static unsigned long GetFileSize(const char* pfilename)
- {
- unsigned long usize = 0;
- if (NULL == pfilename){
- return usize;
- }
- FILE* pFile = fopen(pfilename, "rb");
- if (pFile){
- fseek(pFile, 0, SEEK_END);
- usize = ftell(pFile);
- fclose(pFile);
- }
- return usize;
- }
- void SalesRecordServiceSession::Handle_GetOFLVideoRecords( SpReqAnsContext<SalesRecorderSerVice_GetOFLVideoRecords_Req, SalesRecorderSerVice_GetOFLVideoRecords_Ans>::Pointer ctx )
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- ctx->Answer(Error_Succeed);
- }
- void SalesRecordServiceSession::Handle_CheckVideoDiskStatus( SpReqAnsContext<SalesRecorderSerVice_CheckVideoDiskStatus_Req, SalesRecorderSerVice_CheckVideoDiskStatus_Ans>::Pointer ctx )
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- int nFreeRatio = 0;
- int bSufficient = CheckDiskStatus((LPCTSTR)ctx->Req.DriveLetter,m_pEntity->m_max_disk_percent,&nFreeRatio);
- ctx->Ans.IsSufficient = bSufficient;
- ctx->Ans.FreeRatio = nFreeRatio;
- ctx->Answer(Error_Succeed);
- }
- void SalesRecordServiceSession::Handle_PlayVideo(SpReqAnsContext<SalesRecorderSerVice_PlayVideo_Req, SalesRecorderSerVice_PlayVideo_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- ErrorCodeEnum ErrorCode = m_pEntity->HandleDisplayVideo();
- ctx->Answer(ErrorCode);
- }
- void SalesRecordServiceSession::Handle_SaveVideo(SpReqAnsContext<SalesRecorderSerVice_SaveVideo_Req, SalesRecorderSerVice_SaveVideo_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- ErrorCodeEnum ErrorCode = m_pEntity->HandleSaveVideo();
- ctx->Answer(ErrorCode);
- }
- void SalesRecordServiceSession::Handle_StopRecord(SpReqAnsContext<SalesRecorderSerVice_StopRecord_Req, SalesRecorderSerVice_StopRecord_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- ErrorCodeEnum ErrorCode = m_pEntity->HandleStopRecord((LPCTSTR)CSimpleStringW2A(ctx->Req.VideoName));
- ctx->Answer(ErrorCode);
- }
- void SalesRecordServiceSession::Handle_SetAudioTransFlag(SpReqAnsContext<SalesRecorderSerVice_SetAudioTransFlag_Req, SalesRecorderSerVice_SetAudioTransFlag_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Audio transmission flag is %s.", ctx->Req.TransFlag ? "true" : "false");
- ctx->Answer(Error_Succeed);
- }
- void SalesRecordServiceSession::Handle_StopShowVideo(SpReqAnsContext<SalesRecorderSerVice_StopShowVideo_Req, SalesRecorderSerVice_StopShowVideo_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Stop Show Video.");
- ErrorCodeEnum ErrorCode = m_pEntity->HandleStopShowVideo();
- ctx->Answer(ErrorCode);
- }
- void SalesRecordServiceSession::Handle_PlaySalesRecord(SpReqAnsContext<SalesRecorderSerVice_PlaySalesRecord_Req, SalesRecorderSerVice_PlaySalesRecord_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Stop Show Video.");
- ErrorCodeEnum ErrorCode = m_pEntity->HandlePlaySalesRecordVideo(ctx->Req.WndX, ctx->Req.WndY, ctx->Req.WndWidth, ctx->Req.WndHeight);
- ctx->Answer(ErrorCode);
- }
- void SalesRecordServiceSession::Handle_StartRemoteRecord(SpReqAnsContext<SalesRecorderSerVice_StartRemoteRecord_Req, SalesRecorderSerVice_StartRemoteRecord_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- ErrorCodeEnum ErrorCode = m_pEntity->HandleStartRecord(ctx->Req.VideoName.GetData(), true);
- ctx->Answer(ErrorCode);
- }
- void SalesRecordServiceSession::Handle_DeleteVideo(SpReqAnsContext<SalesRecorderSerVice_DeleteVideo_Req, SalesRecorderSerVice_DeleteVideo_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- ErrorCodeEnum ErrorCode = m_pEntity->HandleDeleteVideo();
- ctx->Answer(ErrorCode);
- }
- void SalesRecordServiceSession::Handle_AppendWatermark(SpReqAnsContext<SalesRecorderSerVice_AppendWatermark_Req, SalesRecorderSerVice_AppendWatermark_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- ErrorCodeEnum ErrorCode = m_pEntity->HandleVideoAppendWatermark(CSimpleStringW2A(ctx->Req.VideoName).GetData(), CSimpleStringW2A(ctx->Req.Watermark).GetData());
- ctx->Answer(ErrorCode);
- }
- CServerSessionBase * CSalesRecorderEntity::OnNewSession( const char* pszRemoteEntityName, const char * pszClass )
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s connected class = %s!", pszRemoteEntityName, pszClass);
- return new SalesRecordServiceSession(this);
- }
- void CSalesRecorderEntity::OnPreStart( CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext )
- {
- ErrorCodeEnum Error = __OnStart(Error_Succeed);
- pTransactionContext->SendAnswer(Error);
- }
- ErrorCodeEnum CSalesRecorderEntity::__OnStart( ErrorCodeEnum preOperationError )
- {
- //MessageBoxA(0,0,0,0);
- m_eDeviceType = eStand2sType;
- m_nSysCallType = 0;
- m_bNeedRestart = false;
- m_eAudioOutQuality = eUltraHD;
- m_bIsAudioNsOn = false;
- m_iAudioNsPolicy = 2;
- m_iAudioChannels = 1;
- m_xIdlePre = m_xKernelPre = m_xUserPre = 0;
- if (SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS)){
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Set Process(%d) RealTime Priority Success.",GetCurrentProcessId());
- }
- m_eDeviceType = RvcGetDeviceType();
- int iAudioQuality = 3;
- int iAudioNsPolicy = 2;
- int iIsAudioNsOn = 0;
- int iAudioChannels = 1;
- int iLogLevel = 1;
- int iLowestLevel = 1;
- int iRecordType = 0;
- m_max_disk_percent = MAX_DISK_PERCENT;
- m_audio_samplerate = 8;
- CSmartPointer<IConfigInfo> spConfig;
- CSmartPointer<IEntityFunction> spFunction = GetFunction();
- if (spFunction->OpenConfig(Config_CenterSetting, spConfig) == Error_Succeed) {
- spConfig->ReadConfigValueInt("SalesRecorder","MaxDiskPercent",m_max_disk_percent);
- spConfig->ReadConfigValueInt("SalesRecorder","AudioSampleRate",m_audio_samplerate);
- spConfig->ReadConfigValueInt("SalesRecorder","AudioBitRate",m_audio_out_bitrate);
- spConfig->ReadConfigValueInt("SalesRecorder","WholeSection",m_bWholeSection);
- spConfig->ReadConfigValueInt("SalesRecorder","ApplyHighQuality",m_bApplyHighQuality);
- spConfig->ReadConfigValueInt("SalesRecorder","AudioNsPolicy",iAudioNsPolicy);
- spConfig->ReadConfigValueInt("SalesRecorder","IsAudioNsOn",iIsAudioNsOn);
- spConfig->ReadConfigValueInt("SalesRecorder","AudioQuality",iAudioQuality);
- spConfig->ReadConfigValueInt("SalesRecorder","AudioChannels",iAudioChannels);
- spConfig->ReadConfigValueInt("SalesRecorder","LogLevel",iLogLevel);
- spConfig->ReadConfigValueInt("SalesRecorder","LowestLevel",iLowestLevel);
- spConfig->ReadConfigValueInt("SalesRecorder", "RecordType", iRecordType);
- }
- if (m_max_disk_percent <= 0 || m_max_disk_percent >= 100) {
- m_max_disk_percent = MAX_DISK_PERCENT;
- }
- if (iLogLevel <= RECORD_LOG_ERROR && iLogLevel > 0){
- m_loglevel = (record_loglevel)iLogLevel;
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_loglevel:%d", m_loglevel);
- if (iLowestLevel <= RECORD_LOG_ERROR && iLowestLevel > 0){
- m_lowestlevel = (record_loglevel)iLowestLevel;
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_lowestlevel:%d", m_lowestlevel);
- if (0 != iRecordType) {
- m_eRecordType = eMP4;
- }
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("video format is %s.", m_eRecordType == eMP4 ? RECORD_MP4_SUFFIX : RECORD_WMV_SUFFIX);
- SetRecordAudioQuality(iAudioQuality);
- SetRecordAudioNsPolicy(iAudioNsPolicy);
- SetRecordAudioChannles(iAudioChannels);
- if (0 != iIsAudioNsOn){
- m_bIsAudioNsOn = true;
- }
-
- if (m_bWholeSection != 0 && m_bWholeSection != 1){
- m_bWholeSection = FALSE;
- }
- if (m_bApplyHighQuality != 0 && m_bApplyHighQuality != 1){
- m_bApplyHighQuality = FALSE;
- }
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("m_bApplyHighQuality:%d",m_bApplyHighQuality);
- if (preOperationError != Error_Succeed) {
- return preOperationError;
- }
- ErrorCodeEnum Error = Error_Succeed;
- m_iActiveCamera = CAMERA_TYPE_ENV;
- m_iCameraState = 'N';
-
- int i = 0;
- m_arrListener.Init(3);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RETURNMENU, NULL, false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_VIDEOAPPENDWATERMARK, NULL, false);
- GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_High, Error_IgnoreAll, LOG_EVT_SALESRECORD_ENTITY_EXCEPTION, NULL, false);
-
- GetFunction()->RegistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA,this);
- GetFunction()->RegistSysVarEvent(SYSVAR_CAMERASTATE,this);
- CSimpleStringA strValue;
- GetFunction()->GetSysVar(SYSVAR_CAMERASTATE, strValue);
- m_iCameraState = strValue[0];
- if (strValue[0] == 'E'){
- m_iActiveCamera = CAMERA_TYPE_OPT;
- }
- else{
- m_iActiveCamera = CAMERA_TYPE_ENV;
- }
- GetFunction()->RegistSysVarEvent(SYSVAR_CALLTYPE, this);
- GetFunction()->GetSysVar(SYSVAR_CALLTYPE, strValue);
- if (strValue[0] == CALLTYPE_NORMAL) {
- m_nSysCallType = 0;
- }
- else if (strValue[0] == CALLTYPE_MOBILE) {
- m_nSysCallType = 1;
- }
- else {
- assert(0);
- }
- Error = GetFunction()->RegistSysVarEvent("SessionID", this);
- if (Error != Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("register sysvar %s failed!", "SessionID");
- }
- Error = GetFunction()->GetPath("Temp", m_TempDir);
- if (Error != Error_Succeed) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get global record temp path failed!");
- }
- if (m_TempDir.GetLength() > 0 && m_TempDir[m_TempDir.GetLength()-1] != SPLIT_SLASH) {
- m_TempDir += SPLIT_SLASH_STR;
- }
- Error = GetFunction()->GetPath("UploadVideo", m_RecordSaveDir);
- if (Error != Error_Succeed) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get global record save path failed!");
- }
- if (m_RecordSaveDir.GetLength() > 0 && m_RecordSaveDir[m_RecordSaveDir.GetLength()-1] != SPLIT_SLASH) {
- m_RecordSaveDir += SPLIT_SLASH_STR;
- }
- return Error;
- }
- void CSalesRecorderEntity::OnStarted()
- {
- LogEvent(Severity_Middle, LOG_EVT_MOD_SALESRECORDER_STARTED_SUCCESS, "sales recorder entity started successfully.");
- }
- void CSalesRecorderEntity::OnPreClose( EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext )
- {
- ErrorCodeEnum Error = __OnClose(Error_Succeed);
- pTransactionContext->SendAnswer(Error);
- }
- ErrorCodeEnum CSalesRecorderEntity::__OnClose( ErrorCodeEnum preOperationError )
- {
- if (preOperationError != Error_Succeed) {
- return preOperationError;
- }
-
- CSmartPointer<IEntityFunction> spFunction = GetFunction();
- for (int i = 0; i < m_arrListener.GetCount(); ++i) {
- spFunction->UnsubscribeLog(m_arrListener[i]);
- }
- GetFunction()->UnregistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA);
- GetFunction()->UnregistSysVarEvent(SYSVAR_CAMERASTATE);
- StopRecord();
- return Error_Succeed;
- }
- void CSalesRecorderEntity::OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- if (Test_ShakeHand == eTestType)
- {
- if (m_bNeedRestart){
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("[OnSelfTest] entity need restart now.");
- pTransactionContext->SendAnswer(Error_Unexpect);
- }
- else{
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- }
- }
- void CSalesRecorderEntity::Debug(record_loglevel elevel, const char *fmt, ...)
- {
- record_loglevel entitylevel = (m_lowestlevel > m_loglevel) ? m_lowestlevel : m_loglevel;
- if (entitylevel <= elevel) {
- va_list arg;
- va_start(arg, fmt);
- int n = _vscprintf(fmt, arg);
- if (n >= 512) {
- char* buf = (char*)malloc((size_t)(n + 1));
- _vsnprintf(buf, n + 1, fmt, arg);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
- free(buf);
- }
- else{
- char strlog[512] = {0};
- _vsnprintf(strlog, 512, fmt, arg);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
- }
- va_end(arg);
- }
- }
- void CSalesRecorderEntity::vDebug(record_loglevel elevel, const char* str, va_list list)
- {
- if (RECORD_LOG_INFO <= elevel) {
- int n = _vscprintf(str, list);
- if (n >= 512) {
- char* buf = (char*)malloc((size_t)(n + 1));
- _vsnprintf(buf, n + 1, str, list);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
- free(buf);
- }
- else {
- char strlog[512] = { 0 };
- _vsnprintf(strlog, 512, str, list);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
- }
- }
- }
- int CSalesRecorderEntity::GetActiveCamera()
- {
- return m_iActiveCamera;
- }
- int CSalesRecorderEntity::GetCameraState()
- {
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get active camera = %d", m_iCameraState);
- return m_iCameraState;
- }
- void CSalesRecorderEntity::OnRecordFailed(eRvcRecordFailedCase eCase, const char *pszMessage, bool bRecordDevFault)
- {
- double fCpuUsage = GetSystemCpuUsage();
- if (fCpuUsage > 50.0){
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_UI_RECORDFAILED_FOR_HIGHCPU, "more than 50 percent.");
- }
- if (eCase < eDefault && eCase >= 0){
- LogEvent(Severity_Middle, LOG_EVT_UI_RECORDFAILED, record_failed_case_table[eCase]);
- }
- m_loglevel = RECORD_LOG_INFO;
-
- char strmsg[MAX_PATH] = {0};
- _snprintf(strmsg, MAX_PATH, "{%s} current memory usage is %d, and cpu usage is %f.",pszMessage ? pszMessage : " ", GetSystemMemoryUsage(), fCpuUsage);
- LogWarn(Severity_Middle, Error_Debug, LOG_EVT_SALESRECORD_FAILED, strmsg);
- if (eBeginFailed == eCase){
- m_bNeedRestart = true;
- RealSelfCheck();
- }
- }
- void CSalesRecorderEntity::OnRecordEntityExcption()
- {
- LogEvent(Severity_High,LOG_EVT_SALESRECORD_ENTITY_EXCEPTION,"现场销售双录出现异常,请稍候重录,系统正在恢复中,预计60秒!");
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_ENTITY_EXCEPTION, "sales record entity exception!");
- }
- void CSalesRecorderEntity::OnRecordFinished()
- {
- LogEvent(Severity_High, LOG_EVT_SALESRECORD_FINISHED, "现场销售双录已完成.");
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_FINISHED, "现场销售双录已完成.");
- }
- void CSalesRecorderEntity::WmpDebug( const char *fmt, ... )
- {
- va_list arg;
- va_start(arg, fmt);
- int n = _vscprintf(fmt, arg);
- if (n >= 512) {
- char* buf = (char*)malloc((size_t)(n + 1));
- _vsnprintf(buf, n + 1, fmt, arg);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
- free(buf);
- }
- else {
- char strlog[512] = { 0 };
- _vsnprintf(strlog, 512, fmt, arg);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
- }
- va_end(arg);
- }
- // 定时任务:扫描是否有待提交的离线双录记录 add by ly @2018/02/08
- void CSalesRecorderEntity::OnTimeout( DWORD dwTimerID )
- {
- }
- void CSalesRecorderEntity::OnSysVarEvent( const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName )
- {
- if (_stricmp(pszKey, SYSVAR_CAMERASTATE) == 0)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("camera state from : %c to %c", pszOldValue[0], pszValue[0]);
- m_iCameraState = pszValue[0];
- if (pszValue[0] == 'E')
- {
- m_iActiveCamera = CAMERA_TYPE_OPT;
- }
- else
- {
- m_iActiveCamera = CAMERA_TYPE_ENV;
- }
- }
- else if (_stricmp(pszKey, SYSVAR_ACTIVETRACKINGCAMERA) == 0)
- {
- if (m_iCameraState == 'N')
- {
- if (pszValue[0] == 'E')
- {
- m_iActiveCamera = CAMERA_TYPE_ENV;
- }
- else if (pszValue[0] == 'O')
- {
- m_iActiveCamera = CAMERA_TYPE_OPT;
- }
- }
- }
- else if (_stricmp(pszKey, SYSVAR_CALLTYPE) == 0)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("sys calltype from: %c to %c", pszOldValue[0], pszValue[0]);
- if(pszValue[0] == CALLTYPE_NORMAL)
- {
- m_nSysCallType = 0;
- }
- else if(pszValue[0] == CALLTYPE_MOBILE)
- {
- m_nSysCallType = 1;
- }
- else
- {
- m_nSysCallType = -1;
- }
- }
- }
- void CSalesRecorderEntity::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, const linkContext &pLinkInfo)
- {
- // 响应客户经理销售录像相关的事件
- switch (dwUserCode)
- {
- case LOG_EVT_UI_RETURNMENU:
- HandleReturnMenu();
- break;
- case LOG_EVT_SALESRECORD_ENTITY_EXCEPTION:
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("handle sales record entity exception, and message is %s.", pszMessage);
- HandleSalesRecordEntityException(pszMessage);
- break;
- default:
- break;
- }
- }
- void CSalesRecorderEntity::StartPhone2PadRecord(const int fps, const char* wmvfilename, int videoquality, int audioOutBitRate, SubtitleParam* subtitleParam, BOOL bWholeSection, BOOL bSessionManage, eRvcRecordType eRecordType)
- {
- bool bRet = false;
- if ((ePadtype == m_eDeviceType) || (eMobilePadType == m_eDeviceType) || (eDesk1SType == m_eDeviceType) || (eDesk2SIntegratedType == m_eDeviceType))
- {
- //在线双录,录像统一使用前置摄像头, pad 版增加远端视频队列
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("m_pRecorder local video is REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE.");
- m_pRecorder = new Clibvideorecord(&bRet, this, REC_COMMON_AUDIO_SALESOL_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE,
- NULL, REC_COMMON_AUDIO_SALES_SHM_QUEUE, REC_COMMON_VIDEO_REMOTE_SHM_RTP_QUEUE, REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
- }
- else if (eDesk2SType == m_eDeviceType)
- {
- m_pRecorder = new Clibvideorecord(&bRet, this, REC_COMMON_AUDIO_SALESOL_SHM_QUEUE, REC_COMMON_VIDEO_SALES_EWS_SHM_RTP_QUEUE,
- NULL, REC_COMMON_AUDIO_SALES_SHM_QUEUE, REC_COMMON_VIDEO_REMOTE_SHM_RTP_QUEUE, REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
- }
- else
- {
- // == 2
- m_pRecorder = new Clibvideorecord(&bRet, this, REC_COMMON_AUDIO_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE,
- REC_COMMON_VIDEO_OPT_SHM_RTP_QUEUE, REC_COMMON_AUDIO_SALES_SHM_QUEUE);
- }
- Rvc_RecordAudioParam_t tAudioParams;
- tAudioParams.eRecordType = ePhone2Pad;
- tAudioParams.eOutPutType = m_eAudioOutQuality;
- tAudioParams.bIsNsOn = m_bIsAudioNsOn;
- tAudioParams.iNsPolicy = m_iAudioNsPolicy;
- tAudioParams.iAudioOutBitRate = 8;
- tAudioParams.bIsTransOn = false;
- tAudioParams.iAudioChannels = 1;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("init lib wmv record success! and record type is %s and output audio quality is %s, audio noise suppression flag is %s. noise suppression policy is %d, video format is %s.", record_type_table[eRecordType], audio_quality_type_table[m_eAudioOutQuality], tAudioParams.bIsNsOn ? "true" : "false", tAudioParams.iNsPolicy, m_eRecordType == eMP4 ? RECORD_MP4_SUFFIX : RECORD_WMV_SUFFIX);
- if (m_pRecorder->StartVideoRecord(fps, videoquality, m_eRecordType, &tAudioParams, subtitleParam, bWholeSection, FALSE, (LPCSTR)m_TempDir,
- m_TempDir.GetLength(), wmvfilename, strlen(wmvfilename)))
- {
- m_bStarted = TRUE;
- }
- }
- bool CSalesRecorderEntity::GetStandardQualityOnSiteSalesRecorder(const eRvcRecordType eRecordType)
- {
- bool bRet = false;
- if ((ePadtype == m_eDeviceType) || (eMobilePadType == m_eDeviceType) || eDesk2SType == m_eDeviceType)
- {
- if (ePad2Agent != eRecordType) {
- m_pRecorder = new Clibvideorecord(&bRet, this, REC_COMMON_AUDIO_SALESOL_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE,
- NULL, REC_COMMON_AUDIO_SALES_SHM_QUEUE);
- }
- else{
- m_pRecorder = new Clibvideorecord(&bRet, this, REC_COMMON_AUDIO_SALESOL_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE,
- NULL, REC_COMMON_AUDIO_SALES_SHM_QUEUE, REC_COMMON_VIDEO_REMOTE_SHM_RTP_QUEUE, REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
- }
- }
- else if(eDesk1SType == m_eDeviceType || eDesk2SIntegratedType == m_eDeviceType)
- {
- if (ePad2Agent != eRecordType) {
- m_pRecorder = new Clibvideorecord(&bRet, this, REC_COMMON_AUDIO_SALESOL_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE,
- NULL, REC_COMMON_AUDIO_SALES_SHM_QUEUE);
- }
- else {
- m_pRecorder = new Clibvideorecord(&bRet, this, REC_COMMON_AUDIO_SALESOL_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE,
- NULL, REC_COMMON_AUDIO_SALES_SHM_QUEUE, REC_COMMON_VIDEO_REMOTE_SHM_RTP_QUEUE, REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
- }
- }
- else
- {
- if (eStand2Agent != eRecordType){
- m_pRecorder = new Clibvideorecord(&bRet, this, REC_COMMON_AUDIO_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE,
- REC_COMMON_VIDEO_OPT_SHM_RTP_QUEUE, REC_COMMON_AUDIO_SALES_SHM_QUEUE);
- }
- else{
- m_pRecorder = new Clibvideorecord(&bRet, this, REC_COMMON_AUDIO_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE,
- REC_COMMON_VIDEO_OPT_SHM_SNAPSHOT_QUEUE, REC_COMMON_AUDIO_SALES_SHM_QUEUE, REC_COMMON_VIDEO_REMOTE_SHM_RTP_QUEUE, REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
- }
- }
- return bRet;
- }
- bool CSalesRecorderEntity::GetHighQualityOnSiteSalesRecorder(const eRvcRecordType eRecordType)
- {
- bool bRet = false;
- if (ePadtype == m_eDeviceType || eMobilePadType == m_eDeviceType || eDesk2SType == m_eDeviceType)
- {
- if (ePad2Agent == eRecordType) {
- m_pRecorder = new Clibvideorecord(&bRet, this, REC_COMMON_AUDIO_SALESOL_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE,
- NULL, REC_COMMON_AUDIO_SALES_SHM_QUEUE, REC_COMMON_VIDEO_REMOTE_SHM_RTP_QUEUE, REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
- }
- else {
- m_pRecorder = new Clibvideorecord(&bRet, this, REC_COMMON_AUDIO_SALESOL_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE,
- NULL, REC_COMMON_AUDIO_SALES_SHM_QUEUE);
- }
- }
- else if (eDesk1SType == m_eDeviceType || eDesk2SIntegratedType == m_eDeviceType)
- {
- if (ePad2Agent == eRecordType) {
- m_pRecorder = new Clibvideorecord(&bRet, this, REC_COMMON_AUDIO_SALESOL_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE,
- NULL, REC_COMMON_AUDIO_SALES_SHM_QUEUE, REC_COMMON_VIDEO_REMOTE_SHM_RTP_QUEUE, REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
- }
- else {
- m_pRecorder = new Clibvideorecord(&bRet, this, REC_COMMON_AUDIO_SALESOL_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE,
- NULL, REC_COMMON_AUDIO_SALES_SHM_QUEUE);
- }
- }
- else
- {
- if (eStand2Agent != eRecordType){
- m_pRecorder = new Clibvideorecord(&bRet, this, REC_COMMON_AUDIO_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE,
- REC_COMMON_VIDEO_OPT_SHM_SNAPSHOT_QUEUE, REC_COMMON_AUDIO_SALES_SHM_QUEUE);
- }
- else{
- m_pRecorder = new Clibvideorecord(&bRet, this, REC_COMMON_AUDIO_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE,
- REC_COMMON_VIDEO_OPT_SHM_SNAPSHOT_QUEUE, REC_COMMON_AUDIO_SALES_SHM_QUEUE, REC_COMMON_VIDEO_REMOTE_SHM_RTP_QUEUE, REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
- }
- }
- return bRet;
- }
- void CSalesRecorderEntity::StartOnSiteSalesRecord(const int fps, const char* wmvfilename, int videoquality, int audioOutBitRate, SubtitleParam* subtitleParam, BOOL bWholeSection, BOOL bSessionManage, eRvcRecordType eRecordType)
- {
- bool bRet = false;
- if (m_bApplyHighQuality)
- {
- bRet = GetHighQualityOnSiteSalesRecorder(eRecordType);
- }
- else
- {
- bRet = GetStandardQualityOnSiteSalesRecorder(eRecordType);
- }
- if (false == bRet){
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get onsite sales recorder failed.");
- return;
- }
- Rvc_RecordAudioParam_t tAudioParams;
- tAudioParams.eRecordType = eRecordType;
- tAudioParams.eOutPutType = m_eAudioOutQuality;
- tAudioParams.bIsNsOn = m_bIsAudioNsOn;
- tAudioParams.iNsPolicy = m_iAudioNsPolicy;
- tAudioParams.iAudioOutBitRate = audioOutBitRate;
- tAudioParams.bIsTransOn = false;
- tAudioParams.iAudioChannels = m_iAudioChannels;
- if (eStand2Agent == eRecordType || ePad2Agent == eRecordType) {
- tAudioParams.eOutPutType = eLowDefinition;
- tAudioParams.bIsNsOn = false;
- }
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("init record lib success! and record type is %s and output audio quality is %s, audio noise suppression flag is %s. noise suppression policy is %d, video format is %s.", record_type_table[eRecordType], audio_quality_type_table[m_eAudioOutQuality], tAudioParams.bIsNsOn ? "true" : "false", tAudioParams.iNsPolicy, m_eRecordType == eMP4 ? RECORD_MP4_SUFFIX : RECORD_WMV_SUFFIX);
- if (m_pRecorder->StartVideoRecord(fps, videoquality, m_eRecordType, &tAudioParams, subtitleParam, bWholeSection, FALSE, (LPCSTR)m_TempDir,
- m_TempDir.GetLength(), wmvfilename, strlen(wmvfilename)))
- {
- m_bStarted = TRUE;
- }
- else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Start WmvRecord failed!");
- }
- }
- void CSalesRecorderEntity::StartRecord(const char *wmvfilename, int videoquality, int audioOutBitRate, SubtitleParam *subtitleParam /* = NULL */, BOOL bWholeSection /* = FALSE */, BOOL bSessionManage /* = FALSE */, eRvcRecordType eRecordType /* = eSingleSide */)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("wmvfilename = %s", wmvfilename);
- //Dbg("strPath = %s", (LPCSTR)m_TempDir);
- int fps = 5;
- //是否需要录制双向视频和音频
- if(m_nSysCallType == 1)
- {
- StartPhone2PadRecord(fps, wmvfilename, videoquality, audioOutBitRate, subtitleParam, bWholeSection, bSessionManage, eRecordType);
- }
- // 现场销售录音录像
- else
- {
- StartOnSiteSalesRecord(fps, wmvfilename, videoquality, audioOutBitRate, subtitleParam, bWholeSection, bSessionManage, eRecordType);
- }
- }
- ErrorCodeEnum CSalesRecorderEntity::StopRecord()
- {
- ErrorCodeEnum eCode = Error_Succeed;
- if (m_bStarted) {
- m_pRecorder->StopVideoRecord();
- delete m_pRecorder;
- m_pRecorder = NULL;
- m_bStarted = FALSE;
- }
- //else{
- // eCode = Error_InvalidState;
- //}
- return eCode;
- }
- ErrorCodeEnum CSalesRecorderEntity::ShowVideo( const char *wmvfilename )
- {
- ErrorCodeEnum ErrorCode = Error_Succeed;
- return ErrorCode;
- }
- ErrorCodeEnum CSalesRecorderEntity::PlaySalesRecordVideo( const char *wmvfilename, int iWndX, int iWndY, int iWndWidth, int iWndHeight)
- {
- ErrorCodeEnum ErrorCode = Error_Succeed;
- return ErrorCode;
- }
- void CSalesRecorderEntity::DeleteAllVideo( const char *wmvfilename )
- {
- if(!m_bStarted)
- {
- CSimpleStringA strPath;
- ErrorCodeEnum Error = GetFunction()->GetPath("Temp", strPath);
- if (Error == Error_Succeed) {
- if (strPath.GetLength() > 0 && strPath[strPath.GetLength()-1] != '\\') {
- strPath += "\\";
- }
- ULONGLONG uVideoCount = 0;
- // 删除客户经理录像 edit by ly 2018/03/05
- CSimpleStringA strFindFileName = CSimpleStringA::Format("S_%s*.%s", wmvfilename, m_eRecordType == eMP4 ? RECORD_MP4_SUFFIX : RECORD_WMV_SUFFIX);
- BOOL bRet = FindMatchedFile((LPCSTR)strPath, (LPCSTR)strFindFileName, uVideoCount);
- if(bRet)
- {
- strFindFileName = strFindFileName.SubString(0,strFindFileName.GetLength()-5);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("succeed to get sales record count while delete video!");
- CSimpleStringA fileName;
- BOOL bDeleteSucc = TRUE;
- for(int i = 0; i != uVideoCount; ++i)
- {
- fileName = CSimpleStringA::Format("%s%s_%d.%s", (LPCSTR)strPath, (LPCSTR)strFindFileName, i, m_eRecordType == eMP4 ? RECORD_MP4_SUFFIX : RECORD_WMV_SUFFIX);
- bRet = DeleteFile((LPCSTR)fileName);
- if(!bRet) {
- bDeleteSucc = FALSE;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Error Code %lu while delete %s ", GetLastError(), (LPCSTR)fileName);
- }
- }
- if (bDeleteSucc) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("succeed to delete sales video!");
- }
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("sales videos not exist or have been deleted!");
- }
- // 删除见证录像
- uVideoCount = 0;
- strFindFileName = CSimpleStringA::Format("W_%s*.%s", wmvfilename, m_eRecordType == eMP4 ? RECORD_MP4_SUFFIX : RECORD_WMV_SUFFIX);
- bRet = FindMatchedFile((LPCSTR)strPath, (LPCSTR)strFindFileName, uVideoCount);
- if(bRet)
- {
- strFindFileName = strFindFileName.SubString(0,strFindFileName.GetLength()-5);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("succeed to get witness record count while delete video!");
- CSimpleStringA fileName;
- BOOL bDeleteSucc = TRUE;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("uVideoCount=%d", uVideoCount);
- for(int i = 0; i != uVideoCount; ++i)
- {
- fileName = CSimpleStringA::Format("%s%s_%d.%s", (LPCSTR)strPath, (LPCSTR)strFindFileName, i, m_eRecordType == eMP4 ? RECORD_MP4_SUFFIX : RECORD_WMV_SUFFIX);
- bRet = DeleteFile((LPCSTR)fileName);
- if(!bRet) {
- bDeleteSucc = FALSE;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Error Code %lu while delete %s ", GetLastError(), (LPCSTR)fileName);
- }
- }
- if (bDeleteSucc) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("succeed to delete witness video!");
- }
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("witness videos not exist or have been deleted!");
- }
- }
- }
- }
- ErrorCodeEnum CSalesRecorderEntity::DeleteVideo( const char *wmvfilename )
- {
- ErrorCodeEnum ErrorCode = Error_Succeed;
- if(!m_bStarted)
- {
- CSimpleStringA strPath;
- ErrorCodeEnum Error = GetFunction()->GetPath("Temp", strPath);
- if (Error == Error_Succeed) {
- if (strPath.GetLength() > 0 && strPath[strPath.GetLength()-1] != '\\') {
- strPath += "\\";
- }
- CSimpleStringA strFindFileName = CSimpleStringA::Format("%s*.%s", wmvfilename, m_eRecordType == eMP4 ? RECORD_MP4_SUFFIX : RECORD_WMV_SUFFIX);
- ULONGLONG uVideoCount = 0;
- BOOL bRet = FindMatchedFile((LPCSTR)strPath, (LPCTSTR)strFindFileName, uVideoCount);
- if(bRet)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("succeed to get record count while delete video!");
- CSimpleStringA fileName;
- BOOL bDeleteSucc = TRUE;
- for(int i = 0; i != uVideoCount; ++i)
- {
- fileName = CSimpleStringA::Format("%s%s_%d.%s", (LPCSTR)strPath, wmvfilename, i, m_eRecordType == eMP4 ? RECORD_MP4_SUFFIX : RECORD_WMV_SUFFIX);
- bRet = DeleteFile((LPCSTR)fileName);
- if(!bRet) {
- bDeleteSucc = FALSE;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Error Code %lu while delete %s ", GetLastError(), (LPCSTR)fileName);
- }
- }
- if (bDeleteSucc) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("succeed to delete videos!");
- }
- }
- else
- {
- ErrorCode = Error_NotExist;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[DeleteVideo] videos not exist or have been deleted!");
- }
- }
- }
- else {
- ErrorCode = Error_NotImpl;
- }
- return ErrorCode;
- }
- /*
- SaveVideo包含两步,找到录像和移动录像
- Error_Succeed 提交上传成功
- Error_NotExist not exist
- Error_NotImpl 方法执行失败
- */
- ErrorCodeEnum CSalesRecorderEntity::SaveVideo( const char *wmvfilename)
- {
- ErrorCodeEnum ErrorCode = Error_Succeed;
- if(!m_bStarted)
- {
- CSimpleStringA sourPath;
- ErrorCodeEnum Error = GetFunction()->GetPath("Temp", sourPath);
- if(Error == Error_Succeed)
- {
- if (sourPath.GetLength() > 0 && sourPath[sourPath.GetLength()-1] != '\\') {
- sourPath += "\\";
- }
- ULONGLONG uVideoCount = 0;
- CSimpleStringA strFindFileName = CSimpleStringA::Format("S_%s*.%s", wmvfilename, m_eRecordType == eMP4 ? RECORD_MP4_SUFFIX : RECORD_WMV_SUFFIX);
- BOOL bRet = FindMatchedFile((LPCSTR)sourPath, (LPCSTR)strFindFileName, uVideoCount);
- if(bRet)
- {
- strFindFileName = strFindFileName.SubString(0,strFindFileName.GetLength()-5);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("succeed to get sales record count while save video!");
- CSimpleStringA destPath;
- Error = GetFunction()->GetPath("UploadVideo", destPath);
- if(Error == Error_Succeed)
- {
- if (destPath.GetLength() > 0 && destPath[destPath.GetLength()-1] != '\\') {
- destPath += "\\";
- }
- CSimpleStringA sourFileName, destFileName;
- BOOL bMoveSucc = TRUE;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("strFindFileName=%s", (LPCSTR)strFindFileName);
- for(int i = 0; i != uVideoCount; ++i)
- {
- sourFileName = CSimpleStringA::Format("%s%s_%d.%s", (LPCSTR)sourPath, (LPCSTR)strFindFileName, i, m_eRecordType == eMP4 ? RECORD_MP4_SUFFIX : RECORD_WMV_SUFFIX);
- destFileName = CSimpleStringA::Format("%s%s_%d.%s", (LPCSTR)destPath, (LPCSTR)strFindFileName, i, m_eRecordType == eMP4 ? RECORD_MP4_SUFFIX : RECORD_WMV_SUFFIX);
- unsigned long ufilesize = GetFileSize(sourFileName.GetData());
- char strtext[MAX_PATH] = {0};
- _snprintf(strtext, MAX_PATH, "%s file size is %u byte.", (LPCSTR)sourFileName, ufilesize);
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_FILESIZE, strtext);
- bRet = MoveFile((LPCSTR)sourFileName, (LPCSTR)destFileName);
- if(!bRet) {
- bMoveSucc = FALSE;
- ErrorCode = Error_NotImpl;
- char strinfo[MAX_PATH] = {0};
- _snprintf(strinfo, MAX_PATH, "Error Code %lu while move %s.", GetLastError(), (LPCSTR)sourFileName);
- LogWarn(Severity_Middle, Error_Debug, LOG_EVT_RECORD_SAVED_FAILED, strinfo);
- if (183 == GetLastError()){
- ErrorCode = Error_InvalidState;
- }
- }
- if (ufilesize > RVC_MIN_FILESIZE){
- }
- else{
- char strmsg[MAX_PATH] = {0};
- _snprintf(strmsg, MAX_PATH, "%s file size is %u.", (LPCSTR)sourFileName, ufilesize);
- LogWarn(Severity_Middle, Error_Debug, LOG_EVT_RECORD_INVALID_FILE, strmsg);
- }
- }
- if (bMoveSucc) {
- char strmsg[MAX_PATH] = {0};
- _snprintf(strmsg, MAX_PATH, "succeed to save sales video, move it from %s to %s.", sourFileName.GetData(), destFileName.GetData());
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_SAVED_SUCCESS, strmsg);
- }
- }
- }
- else{
- LogWarn(Severity_Middle, Error_Debug, LOG_EVT_RECORD_SAVED_FAILED, "sales videos not exist or have been deleted");
- ErrorCode = Error_NotExist;
- }
- }
- }
- else{
- ErrorCode = Error_InvalidState;
- }
- return ErrorCode;
- }
- CSimpleStringA CSalesRecorderEntity::GetTerminalStage()
- {
- CSmartPointer<IEntityFunction> Func = GetFunction();
- CSimpleStringA strValue = "";
- Func->GetSysVar("TerminalStage", strValue);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("TerminalStage:%s", (LPCTSTR)strValue);
- return strValue;
- }
- ErrorCodeEnum CSalesRecorderEntity::StopRecordVideo()
- {
- auto rc = Error_Succeed;
- auto pUIClient = new UIService_ClientBase(this);
- if(pUIClient->Connect() != Error_Succeed)
- {
- pUIClient->SafeDelete();
- pUIClient = NULL;
- rc = Error_DevConnFailed;
- }
- else
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("UIClient connected success!");
- UIService_StopRecordVideo_Req req;
- UIService_StopRecordVideo_Ans ans;
- rc = (*pUIClient)(EntityResource::getLink().upgradeLink())->StopRecordVideo(req, ans, 5000);
- if(rc != Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Stop record video failed return 0x%08x", rc);
- }
- pUIClient->GetFunction()->CloseSession();
- pUIClient->SafeDelete();
- pUIClient = NULL;
- }
- return rc;
- }
- ErrorCodeEnum CSalesRecorderEntity::HandleStartRecord(const char *pszMessage, const bool bRemoteRecord)
- {
- ErrorCodeEnum Error = Error_Succeed;
- eRvcRecordType eRecordType = eSingleSide;
- if (NULL == pszMessage){
- return Error_Param;
- }
- size_t ulen = strlen(pszMessage);
- char *tmp = new char[ulen+1];
- strncpy_s(tmp, ulen+1, pszMessage, ulen);
-
- char *result[16] = {0};
- //CStringSplit(tmp, result, "@");
- // 解决中文stringsplit偶现乱码的问题 edit by ly@2018/07/04
- auto arr1 = CSimpleStringA2W(tmp).Split('@');
- auto arr2 = CAutoArray<CSimpleStringA>(arr1.GetCount());
- for (int i = 0; i < arr1.GetCount(); ++i)
- {
- arr2[i] = CSimpleStringW2A(arr1[i]);
- result[i] = const_cast<LPSTR>(arr2[i].GetData());
- }
- sprintf(m_SalesVideoName, "%s", result[4]);//录像名:录像类型标志_录像流水号(如S_C13213EF)
- RecordSubTitle subTitle;
- ZeroMemory(&subTitle,sizeof(RecordSubTitle));
- CSimpleStringA strCardNo = DecryptString(result[5]);
- if (sizeof(subTitle.CustCardNo) > strCardNo.GetLength()){
- strcpy_s(subTitle.CustCardNo, strCardNo.GetData());
- }
- else{
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CustCardNo.");
- }
-
- char *pStr = result[6];
- CSimpleStringW szCustName = CSimpleStringA2W(pStr);
- if (szCustName.GetLength() <= 4) {
- strcpy(subTitle.CustName, pStr);
- }
- else {
- CSimpleStringW aa = szCustName.SubString(0,4);
- sprintf(subTitle.CustName,"%s...",(LPCTSTR)CSimpleStringW2A(aa));
- }
-
- // 解决产品代码、产品名称过长,画面上显示不下的问题
- // 朝朝赢和招财赢支持双向录像
- pStr = result[7];
- int nProductCodeLen = strlen(pStr);
- if (nProductCodeLen <= 10) {
- strcpy(subTitle.ProductCode, pStr);
- }
- else {
- char aa[5]={0},bb[5]={0};
- strncpy(aa, pStr, 4);
- strncpy(bb, pStr+nProductCodeLen-4, 4);
- sprintf(subTitle.ProductCode,"%s...%s",aa,bb);
- }
- pStr = result[8];
- CSimpleStringW szProductName = CSimpleStringA2W(pStr);
- if (szProductName.GetLength() <= 5) {
- strcpy(subTitle.ProductName, pStr);
- }
- else {
- CSimpleStringW aa = szProductName.SubString(0,3);
- CSimpleStringW bb = szProductName.SubString(szProductName.GetLength()-2,2);
- sprintf(subTitle.ProductName,"%s...%s",(LPCTSTR)CSimpleStringW2A(aa),(LPCTSTR)CSimpleStringW2A(bb));
- }
- if (result[9]) {
- strcpy(subTitle.SapID, result[9]);
- } else {
- subTitle.SapID[0] = '\0';
- }
- if (result[10]) {
- pStr = result[10];
- CSimpleStringW szCustManagerName = CSimpleStringA2W(pStr);
- if (szCustManagerName.GetLength() <= 4) {
- strcpy(subTitle.CustManagerName, result[10]);
- }
- else {
- CSimpleStringW aa = szCustManagerName.SubString(0,4);
- sprintf(subTitle.CustManagerName,"%s...",(LPCTSTR)CSimpleStringW2A(aa));
- }
- } else {
- subTitle.CustManagerName[0] = '\0';
- }
- delete[] tmp;
- tmp = NULL;
- SubtitleParam subtitleParam;
- ZeroMemory(&subtitleParam,sizeof(SubtitleParam));
- subtitleParam.bSubtitle = TRUE;
- subtitleParam.bSubtitleSection = TRUE;
- subtitleParam.topSubtitleData[0] = '\0';
- if (strlen(subTitle.SapID)>0&&strlen(subTitle.CustManagerName)>0){
- sprintf(subtitleParam.bottomSubtitleData1, "%s %s %s", subTitle.CustCardNo, subTitle.CustName, subTitle.ProductCode);
- sprintf(subtitleParam.bottomSubtitleData2, "%s %s %s", subTitle.ProductName, subTitle.SapID, subTitle.CustManagerName);
- }
- else{
- sprintf(subtitleParam.bottomSubtitleData1, "%s %s", subTitle.CustCardNo, subTitle.CustName);
- sprintf(subtitleParam.bottomSubtitleData2, "%s %s", subTitle.ProductCode, subTitle.ProductName);
- }
- int i_audio_out_bitrate = m_audio_out_bitrate;
- if (bRemoteRecord)
- {
- if (m_eDeviceType == eStand2sType) { //如果是大机
- eRecordType = eStand2Agent; //可视柜台大机的双向录像
- }
- else{
- eRecordType = ePad2Agent; //可视柜台pad的双向录像
- }
- if(256 == m_audio_out_bitrate){
- i_audio_out_bitrate = 128;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("change remote record audio out bitrate to %d.", i_audio_out_bitrate);
- }
- }
- StartRecord(m_SalesVideoName, 90, i_audio_out_bitrate, &subtitleParam, m_bWholeSection, FALSE, eRecordType);
- char strmsg[MAX_PATH] = {0};
- _snprintf(strmsg, MAX_PATH, "start remote record %s.", m_SalesVideoName);
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_START_REMOTERECORD, strmsg);
- return Error;
- }
- ErrorCodeEnum CSalesRecorderEntity::HandleStopRecord(const char *pszMessage)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("stop record video name is %s!", m_SalesVideoName);
- ErrorCodeEnum ErrorCode = StopRecord();
- return ErrorCode;
- }
- ErrorCodeEnum CSalesRecorderEntity::HandleSetAudioTransmissionFlag(bool bFlag)
- {
- ErrorCodeEnum ErrorCode = Error_Succeed;
- return ErrorCode;
- }
- ErrorCodeEnum CSalesRecorderEntity::HandleDisplayVideo()
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("play record file name is %s!", m_SalesVideoName);
- ErrorCodeEnum ErrorCode = ShowVideo(m_SalesVideoName);
- return ErrorCode;
- }
- ErrorCodeEnum CSalesRecorderEntity::HandlePlaySalesRecordVideo(int iWndX, int iWndY, int iWndWidth, int iWndHeight)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("play sales record video file name is %s!", m_SalesVideoName);
- ErrorCodeEnum ErrorCode = PlaySalesRecordVideo(m_SalesVideoName, iWndX, iWndY, iWndWidth, iWndHeight);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("play sales record video return code is 0x%08x.", ErrorCode);
- return ErrorCode;
- }
- ErrorCodeEnum CSalesRecorderEntity::HandleStopShowVideo()
- {
- // 视频播放 libwmpplayer
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("stop show video record file name is %s!", m_SalesVideoName);
- ErrorCodeEnum ErrorCode = Error_Succeed;
- return ErrorCode;
- }
- ErrorCodeEnum CSalesRecorderEntity::HandleSaveVideo()
- {
- ErrorCodeEnum ErrorCode = Error_Succeed;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Save Record Name is %s.", m_SalesVideoName);
- // 将视频从tmp移动到uploadvideo
- ErrorCode = SaveVideo(m_SalesVideoName+2);
- ZeroMemory(m_SalesVideoName,sizeof(m_SalesVideoName));
- return ErrorCode;
- }
- ErrorCodeEnum CSalesRecorderEntity::HandleDeleteVideo()
- {
- ErrorCodeEnum ErrorCode = Error_Succeed;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Delete Record Name is %s.", m_SalesVideoName);
- // 删除tmp中的视频
- ErrorCode = DeleteVideo(m_SalesVideoName);
- ZeroMemory(m_SalesVideoName,sizeof(m_SalesVideoName));
- return ErrorCode;
- }
- void CSalesRecorderEntity::HandleReturnMenu()
- {
- CSimpleStringA strValue;
- GetFunction()->GetSysVar("DesktopType", strValue);
- if (strValue != CSimpleStringA("U"))
- {
- if (m_bStarted) // 如果正在进行客户经理录像
- {
- // 停止录像
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("stop record and return menu!");
- StopRecord();
- }
- // 删除tmp中的视频
- if (strlen(m_SalesVideoName) > 0)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("delete sales record!");
- DeleteAllVideo(m_SalesVideoName+2);
- }
- ZeroMemory(m_SalesVideoName,sizeof(m_SalesVideoName));
- }
- }
- void CSalesRecorderEntity::HandleUkeyPullout()
- {
- if (m_SalesVideoName && strstr(m_SalesVideoName, "OFL"))
- {
- if (m_bStarted) // 如果正在进行客户经理录像
- {
- // 停止录像
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("stop record and return menu!");
- StopRecord();
- }
- // 删除录像记录临时文件
- CSimpleStringA cfn = CSimpleStringA::Format("%s%s.txt", (LPCTSTR)m_TempDir, m_SalesVideoName);
- DeleteFile(cfn);
- // 删除tmp中的视频
- if (strlen(m_SalesVideoName) > 0)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("delete sales record!");
- DeleteAllVideo(m_SalesVideoName+4);
- }
- ZeroMemory(m_SalesVideoName,sizeof(m_SalesVideoName));
- StopRecordVideo();
- }
- }
- ErrorCodeEnum CSalesRecorderEntity::HandleVideoAppendWatermark(const char* pszVideoName, const char* pszWaterMark)
- {
- ErrorCodeEnum Error = Error_Failed;
- if (NULL == pszWaterMark){
- return Error_Param;
- }
- if (m_bStarted && (NULL != m_pRecorder)) {
- if (m_pRecorder->SetRightVideoWaterMark(pszWaterMark)) {
- Error = Error_Succeed;
- }
- }
- return Error;
- }
- ErrorCodeEnum CSalesRecorderEntity::HandleSalesRecordEntityException(const char* pszMessage)
- {
- // 通知到业务中台
- SalesRecordException evt;
- evt.failedmsg = CSimpleStringA2W(pszMessage==NULL?"现场销售双录过程出现异常!":pszMessage);
- SpSendBroadcast(GetFunction(), SP_MSG_OF(SalesRecordException), SP_MSG_SIG_OF(SalesRecordException), evt);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[dbg] SalesRecord entity exception broadcast sent!");
- //停止录像
- StopRecord();
- m_bNeedRestart = true;
- //重启实体
- RealSelfCheck();
- return Error_Succeed;
- }
- ErrorCodeEnum CSalesRecorderEntity::RealSelfCheck()
- {
- ErrorCodeEnum Error = Error_Succeed;
- SelfChekerClient* pSelfcheckClient = new SelfChekerClient(this);
- Error = pSelfcheckClient->Connect();
- if (Error != Error_Succeed)
- {
- pSelfcheckClient->SafeDelete();
- pSelfcheckClient = NULL;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SelfcheckClient connect fail!");
- }
- else
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("SelfcheckClient connect success!");
- }
- if (pSelfcheckClient)
- {
- SelfCheckerService_RealCheck_Req req;
- req.name = GetEntityName();
- SelfCheckerService_RealCheck_Ans ans;
- DWORD Timeout = 500;
- Error = pSelfcheckClient->RealCheck(req,ans,Timeout);
- if (Error!=Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("RealSelfcheck fail!");
- }
- else
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("RealSelfcheck success!");
- }
- }
- LogWarn(Severity_Middle, Error_Debug, LOG_EVT_ENTITY_RESTART, "sales record entity self restart.");
- return Error;
- }
- bool IsMatchedVideo(WIN32_FIND_DATA fileData)
- {
- bool bRet = false;
-
- if ('S' == fileData.cFileName[0] || 'W' == fileData.cFileName[0]){
- SYSTEMTIME sysTime;
- FileTimeToSystemTime(&fileData.ftCreationTime, &sysTime);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("File %s create data info is %d %d %d.", fileData.cFileName, sysTime.wYear, sysTime.wMonth, sysTime.wDay);
- if ((2020 == sysTime.wYear) && (sysTime.wMonth == 1)){
- if (sysTime.wDay >= 3 && sysTime.wDay <= 10){
- bRet = true;
- }
- }
- }
-
- return bRet;
- }
- void CSalesRecorderEntity::UploadTempPathVideos()
- {
- CSimpleStringA sourPath;
- CSimpleStringA destPath;
- ErrorCodeEnum Error = GetFunction()->GetPath("Temp", sourPath);
- Error = GetFunction()->GetPath("UploadVideo", destPath);
-
- if (sourPath.GetLength() > 0 && sourPath[sourPath.GetLength()-1] != SPLIT_SLASH) {
- sourPath += SPLIT_SLASH_STR;
- }
- if (destPath.GetLength() > 0 && destPath[destPath.GetLength()-1] != SPLIT_SLASH) {
- destPath += SPLIT_SLASH_STR;
- }
- if(Error == Error_Succeed)
- {
- char srcFilePath[MAX_PATH]={0};
- WIN32_FIND_DATA FindFileData;
- HANDLE hFind;
- BOOL fFinished = FALSE;
- sprintf_s(srcFilePath, MAX_PATH, "%s*.%s", sourPath, m_eRecordType == eMP4 ? RECORD_MP4_SUFFIX : RECORD_WMV_SUFFIX);
- hFind = FindFirstFile(srcFilePath, &FindFileData);
- if (INVALID_HANDLE_VALUE != hFind)
- {
- while (!fFinished)
- {
- if (FILE_ATTRIBUTE_DIRECTORY & FindFileData.dwFileAttributes)
- {
- continue;
- }
- if (IsMatchedVideo(FindFileData)){
- CSimpleStringA sourFileName = CSimpleStringA::Format("%s%s", (LPCSTR)sourPath, FindFileData.cFileName);
- CSimpleStringA destFileName = CSimpleStringA::Format("%sBAK_%s", (LPCSTR)destPath, FindFileData.cFileName);
- if(!MoveFile((LPCSTR)sourFileName, (LPCSTR)destFileName)) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Error Code %lu while move %s ", GetLastError(), (LPCSTR)sourFileName);
- }else{
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Move File %s success.", (LPCSTR)sourFileName);
- }
- }
- else{
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("File (%s) is not matched.", FindFileData.cFileName);
- }
- if (!FindNextFile(hFind, &FindFileData))
- {
- if (GetLastError() == ERROR_NO_MORE_FILES)
- {
- fFinished = TRUE;
- }
- else
- {
- break;
- }
- }
- }
- FindClose(hFind);
- }
- }
- }
- int CSalesRecorderEntity::GetSystemMemoryUsage()
- {
- // Use to convert bytes to KB
- #define DIV 1024
- MEMORYSTATUSEX statex;
- statex.dwLength = sizeof (statex);
- GlobalMemoryStatusEx (&statex);
- return statex.dwMemoryLoad;
- }
- double CSalesRecorderEntity::GetSystemCpuUsage()
- {
- double ratio = 0;
- #define _WIN32_WINNT 0x0601
- FILETIME idleTime,kernelTime,userTime;
- BOOL ret = GetSystemTimes(&idleTime,&kernelTime,&userTime);
- if (ret == 0)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("GetSystemCPUStatus.GetSystemTimes failed(%d).",GetLastError());
- return 80.0;
- }
- __int64 xIdle,xKernel,xUser;
- xIdle = idleTime.dwHighDateTime;
- xIdle <<= 32;
- xIdle |= idleTime.dwLowDateTime;
- xKernel = kernelTime.dwHighDateTime;
- xKernel <<= 32;
- xKernel |= kernelTime.dwLowDateTime;
- xUser = userTime.dwHighDateTime;
- xUser <<= 32;
- xUser |= userTime.dwLowDateTime;
- if (m_xIdlePre != 0)
- {
- __int64 xI,xK,xU;
- xI = xIdle - m_xIdlePre;
- xK = xKernel - m_xKernelPre;
- xU = xUser - m_xUserPre;
-
- if ((xK +xU) != 0)
- ratio = (xK - xI + xU) * 100 / (xK + xU);
- }
- m_xIdlePre = xIdle;
- m_xKernelPre = xKernel;
- m_xUserPre = xUser;
- return ratio;
- }
- ErrorCodeEnum CSalesRecorderEntity::SetRecordAudioQuality(int iAudioQuality)
- {
- ErrorCodeEnum eRet = Error_Succeed;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("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 CSalesRecorderEntity::SetRecordAudioNsPolicy(int iNsPolicy)
- {
- ErrorCodeEnum eRet = Error_Succeed;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("iNsPolicy == %d.", iNsPolicy);
- if (1 == iNsPolicy || 3 == iNsPolicy){
- m_iAudioNsPolicy = iNsPolicy;
- }
- else{
- m_iAudioNsPolicy = 2;
- }
- return eRet;
- }
- ErrorCodeEnum CSalesRecorderEntity::SetRecordAudioChannles(int iAudioChannles)
- {
- ErrorCodeEnum eRet = Error_Succeed;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Get iAudioChannles == %d.", iAudioChannles);
- m_iAudioChannels = 2;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Set AudioChannles == %d.", m_iAudioChannels);
- return eRet;
- }
- DeviceTypeEnum CSalesRecorderEntity::RvcGetDeviceType()
- {
- DeviceTypeEnum eType = eStand2sType;
- CSmartPointer<IEntityFunction> spFunction = GetFunction();
- CSystemStaticInfo stStaticinfo;
- spFunction->GetSystemStaticInfo(stStaticinfo);
- m_terminalNo = stStaticinfo.strTerminalID;
- if (stricmp(stStaticinfo.strMachineType, "RVC.PAD") == 0) {
- if (stricmp(stStaticinfo.strSite, "CMB.FLB") == 0) {
- eType = eMobilePadType;
- }
- else {
- eType = ePadtype;
- }
- }
- else if (stricmp(stStaticinfo.strMachineType, "RVC.Desk2S") == 0) {
- eType = eDesk2SType;
- WORD nMajor = stStaticinfo.MachineVersion.GetMajor();
- WORD nMinor = stStaticinfo.MachineVersion.GetMinor();
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("MachineVersion is %d.%d", nMajor, nMinor);
- if (2 == nMajor) {
- eType = eDesk2SIntegratedType;
- }
- }
- else if (stricmp(stStaticinfo.strMachineType, "RPM.Stand1S") == 0) {
- eType = eRpm1sType;
- }
- else if (stricmp(stStaticinfo.strMachineType, "RVC.Desk1S") == 0) {
- eType = eDesk1SType;
- }
- else if (stricmp(stStaticinfo.strMachineType, "RVC.CardStore") == 0 || stricmp(stStaticinfo.strMachineType, "RVC.CardPrinter") == 0) {
- eType = eCardStore;
- }
- else {
- eType = eStand2sType;
- }
- if (eType >= 0 && eType < sizeof(Device_Type_Table) / sizeof(char*)) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("device type is %s.", Device_Type_Table[eType]);
- }
- return eType;
- }
- SelfChekerClient::SelfChekerClient( CSalesRecorderEntity *pEntity ) : SelfCheckerService_ClientBase(pEntity)
- {
- }
- SP_BEGIN_ENTITY_MAP()
- SP_ENTITY(CSalesRecorderEntity)
- SP_END_ENTITY_MAP()
|