mod_SalesRecorder.cpp 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765
  1. #include "stdafx.h"
  2. #include "mod_SalesRecorder.h"
  3. #include "Event.h"
  4. #include "rvc_media_common.h"
  5. #include "fileutil.h"
  6. #include "array.h"
  7. #include <memutil.h>
  8. #include <algorithm>
  9. #include "y2k_time.h"
  10. #ifdef RVC_OS_WIN
  11. #include <Windows.h>
  12. #else
  13. #include <dirent.h>
  14. #include <sys/ioctl.h>
  15. #include <sys/stat.h>
  16. #include <sys/fcntl.h>
  17. #endif
  18. #include "mod_customeraware/Event.h"
  19. #include "mod_facetracking/sysvar.h"
  20. #include "mod_mediacontroller/Event.h"
  21. #include "mod_interactivecontrol/Event.h"
  22. #include <assert.h>
  23. #include "EventCode.h"
  24. #include <string.h>
  25. #include "filecryption.h"
  26. #ifndef RVC_MIN_FILESIZE
  27. #define RVC_MIN_FILESIZE 10240
  28. #endif
  29. #ifndef MAX_LOG_LEN
  30. #define MAX_LOG_LEN 512
  31. #endif
  32. #define MAX_DISK_PERCENT 95 // 磁盘最大占用百分比
  33. static const char* record_failed_case_table[] = {
  34. "[RTA3L01] 启动录像失败,初始化失败",
  35. "[RTA3L02] 启动录像失败,字体为空,添加水印失败",
  36. "[RTA3L03] 开始录像失败,请稍后(约30秒)再试",
  37. "[RTA3L04] 录像失败,摄像头故障,获取不到视频,请联系厂商进行维修",
  38. "[RTA3L05] 录像失败,获取不到远端音频,请检查风险提示音是否正常播放且音量大小是否正常",
  39. "[RTA3L06] 录像失败,麦克风故障,获取不到本地音频,请联系厂商进行维修",
  40. "[RTA3L07] 录像失败,系统不支持当前音频采样率",
  41. "[RTA3L08] 录像失败,音频流写入失败,请稍后(约30秒)再试",
  42. "[RTA3L09] 录像失败,获取不到远端视频,请稍后(约30秒)再试"
  43. };
  44. static BOOL CheckDiskStatus(const char *szRoot, int nPercent, int *pFreeRatio)
  45. {
  46. //todo 调用resourcewatcher
  47. return TRUE;
  48. }
  49. static int hch2int(char hch)
  50. {
  51. if (hch >= '0' && hch <= '9')
  52. return hch-'0';
  53. else if (hch >= 'a' && hch <= 'f')
  54. return hch-'a'+10;
  55. else if (hch >= 'A' && hch <= 'F')
  56. return hch-'A'+10;
  57. return 0;
  58. }
  59. static long hexstr2int(const char *str, int len)
  60. {
  61. long result = 0;
  62. if (str && len <= strlen(str)) {
  63. for (int i = 0; i < len; ++i) {
  64. result += (hch2int(str[i]) << ((len-i-1) << 2));
  65. }
  66. }
  67. return result;
  68. }
  69. static CSimpleStringA VideoSerialID2TimeString(const char *videoserialid)
  70. {
  71. DWORD nTimeTicks = hexstr2int(videoserialid,8);
  72. return ((CSmallDateTime)nTimeTicks).ToTimeString();
  73. }
  74. static void CStringSplit(char* str, char** result, const char* del)
  75. {
  76. char* pdata = NULL;
  77. char* p = NULL;
  78. #ifdef RVC_OS_WIN
  79. p = strtok_s(str, del, &pdata);
  80. #else
  81. p = strtok_r(str, del, &pdata);
  82. #endif // RVC_OS_WIN
  83. while (p != NULL) {
  84. *result++ = p;
  85. #ifdef RVC_OS_WIN
  86. p = strtok_s(NULL, del, &pdata);
  87. #else
  88. p = strtok_r(NULL, del, &pdata);
  89. #endif
  90. }
  91. }
  92. static bool rvcMoveFile(const char* strSrcFile, const char* strDstFile)
  93. {
  94. bool bRet = false;
  95. if (NULL == strSrcFile || NULL == strDstFile) {
  96. return bRet;
  97. }
  98. #ifdef RVC_OS_WIN
  99. bRet = MoveFile(strSrcFile, strDstFile);
  100. #else
  101. if (0 == rename(strSrcFile, strDstFile)) {
  102. bRet = true;
  103. }
  104. #endif // RVC_OS_WIN
  105. return bRet;
  106. }
  107. //TODO: CrossPlaform [Gifur@2025728]
  108. static bool RvcDeleteFile(const char* strSrcFile)
  109. {
  110. bool bRet = false;
  111. if (NULL == strSrcFile) {
  112. return bRet;
  113. }
  114. #ifdef RVC_OS_WIN
  115. bRet = DeleteFile(strSrcFile);
  116. #else
  117. if (0 == remove(strSrcFile)) {
  118. bRet = true;
  119. }
  120. #endif // RVC_OS_WIN
  121. return bRet;
  122. }
  123. #ifdef RVC_OS_WIN
  124. // 寻找某目录下与通配符匹配的文件
  125. static bool FindMatchedFile(const char* pstrFindPath, const char* pstrFindFileName, uint32_t & uCountFile)
  126. {
  127. char sPath[MAX_PATH] = {0};
  128. char sFormatFileName[MAX_PATH + 2] = "*";
  129. WIN32_FIND_DATA FindFileData;
  130. HANDLE hFind;
  131. bool fFinished = false;
  132. strcpy(sFormatFileName, pstrFindPath);
  133. if (pstrFindPath[strlen(pstrFindPath) - 1] != SPLIT_SLASH)
  134. {
  135. strcat(sFormatFileName, SPLIT_SLASH_STR);
  136. strcat(sFormatFileName, "*");
  137. }
  138. else
  139. {
  140. strcat(sFormatFileName, "*");
  141. }
  142. strcat(sFormatFileName, pstrFindFileName);
  143. strcat(sFormatFileName, "*");
  144. hFind = FindFirstFile(sFormatFileName, &FindFileData);
  145. if (hFind == INVALID_HANDLE_VALUE)
  146. {
  147. return false;
  148. }
  149. else
  150. {
  151. while (!fFinished)
  152. {
  153. strcpy(sPath, pstrFindPath);
  154. if (sPath[strlen(sPath) - 1] != SPLIT_SLASH)
  155. {
  156. strcat(sPath, SPLIT_SLASH_STR);
  157. }
  158. strcat(sPath, FindFileData.cFileName);
  159. if (!(FILE_ATTRIBUTE_DIRECTORY & FindFileData.dwFileAttributes))
  160. {
  161. ++uCountFile;
  162. }
  163. if (!FindNextFile(hFind, &FindFileData))
  164. {
  165. if (GetLastError() == ERROR_NO_MORE_FILES)
  166. {
  167. fFinished = true;
  168. }
  169. else
  170. {
  171. break;
  172. }
  173. }
  174. }
  175. FindClose(hFind);
  176. }
  177. return true;
  178. }
  179. #else
  180. static bool FindMatchedFile(const char* sFindPath, const char* sFindFileName, uint32_t& uCountFile)
  181. {
  182. bool bRet = false;
  183. DIR* pDir = NULL;
  184. struct dirent* pFile = NULL;
  185. CSimpleStringA tmpFindFileName = sFindFileName;
  186. pDir = opendir(sFindPath);
  187. if (pDir == NULL) {
  188. return bRet;
  189. }
  190. //linux不支持*查找,去掉后缀
  191. char strsuffix[MAX_PATH] = { 0 };
  192. snprintf(strsuffix, MAX_PATH, "*.%s", RECORD_MP4_SUFFIX);
  193. if (tmpFindFileName.IsEndWith(strsuffix)) {
  194. tmpFindFileName = tmpFindFileName.SubString(0, tmpFindFileName.GetLength() - 5);
  195. }
  196. while ((pFile = readdir(pDir)) != NULL) {
  197. if (pFile->d_type & DT_DIR) {
  198. continue;
  199. }
  200. else {
  201. if (0 == _strnicmp(pFile->d_name, tmpFindFileName.GetData(), tmpFindFileName.GetLength())) {
  202. ++uCountFile;
  203. bRet = true;
  204. }
  205. }
  206. }
  207. closedir(pDir);
  208. return bRet;
  209. }
  210. #endif
  211. static CSimpleStringA DecryptString(const char* lpszEncrpyted)
  212. {
  213. if (NULL == lpszEncrpyted) {
  214. return CSimpleStringA("");
  215. }
  216. int iEncrypt = 0;
  217. int len = strlen(lpszEncrpyted);
  218. CSimpleStringA csPlainTxt('\0', (len) / 2 + 1);
  219. int iCh = 0;
  220. for (int i = 0; i < len; i += 2) {
  221. sscanf(lpszEncrpyted + i, "%02X", &iCh);
  222. csPlainTxt[i / 2] = (char)(((char)iCh) ^ (128 | (iEncrypt++ & 127)));
  223. }
  224. return CSimpleStringA((LPCTSTR)csPlainTxt);
  225. }
  226. static unsigned long GetFileSize(const char* pfilename)
  227. {
  228. #ifdef RVC_OS_WIN
  229. unsigned long usize = 0;
  230. if (NULL == pfilename) {
  231. return usize;
  232. }
  233. FILE* pFile = fopen(pfilename, "rb");
  234. if (pFile) {
  235. fseek(pFile, 0, SEEK_END);
  236. usize = ftell(pFile);
  237. fclose(pFile);
  238. }
  239. return usize;
  240. #else
  241. struct stat statbuf;
  242. if (0 == stat(pfilename, &statbuf)) {
  243. return statbuf.st_size;
  244. }
  245. else {
  246. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("errno info is %s.", strerror(errno));
  247. return 0;
  248. }
  249. #endif
  250. }
  251. static void rvcDbg(filecrypt_loglevel elevel, const char* fmt, ...)
  252. {
  253. va_list arg;
  254. va_start(arg, fmt);
  255. int n = vsnprintf(NULL, 0, fmt, arg);
  256. if (n >= MAX_LOG_LEN) {
  257. char* buf = (char*)malloc((size_t)(n + 1));
  258. vsnprintf(buf, n + 1, fmt, arg);
  259. DbgWithLink((LOG_LEVEL_E)elevel, LOG_TYPE_SYSTEM)("%s", buf);
  260. free(buf);
  261. }
  262. else {
  263. char strlog[MAX_LOG_LEN] = { 0 };
  264. vsnprintf(strlog, MAX_LOG_LEN, fmt, arg);
  265. DbgWithLink((LOG_LEVEL_E)elevel, LOG_TYPE_SYSTEM)("%s", strlog);
  266. }
  267. va_end(arg);
  268. }
  269. void SalesRecordServiceSession::Handle_GetOFLVideoRecords( SpReqAnsContext<SalesRecorderSerVice_GetOFLVideoRecords_Req, SalesRecorderSerVice_GetOFLVideoRecords_Ans>::Pointer ctx )
  270. {
  271. DbgToBeidou(ctx->link, __FUNCTION__)();
  272. ctx->Answer(Error_Succeed);
  273. }
  274. void SalesRecordServiceSession::Handle_CheckVideoDiskStatus( SpReqAnsContext<SalesRecorderSerVice_CheckVideoDiskStatus_Req, SalesRecorderSerVice_CheckVideoDiskStatus_Ans>::Pointer ctx )
  275. {
  276. DbgToBeidou(ctx->link, __FUNCTION__)();
  277. int nFreeRatio = 0;
  278. int bSufficient = CheckDiskStatus(ctx->Req.DriveLetter.GetData(), m_pEntity->GetMaxDiskPercent(), &nFreeRatio);
  279. ctx->Ans.IsSufficient = bSufficient;
  280. ctx->Ans.FreeRatio = nFreeRatio;
  281. ctx->Answer(Error_Succeed);
  282. }
  283. void SalesRecordServiceSession::Handle_PlayVideo(SpReqAnsContext<SalesRecorderSerVice_PlayVideo_Req, SalesRecorderSerVice_PlayVideo_Ans>::Pointer ctx)
  284. {
  285. DbgToBeidou(ctx->link, __FUNCTION__)();
  286. ctx->Answer(Error_Succeed);
  287. }
  288. void SalesRecordServiceSession::Handle_SaveVideo(SpReqAnsContext<SalesRecorderSerVice_SaveVideo_Req, SalesRecorderSerVice_SaveVideo_Ans>::Pointer ctx)
  289. {
  290. DbgToBeidou(ctx->link, __FUNCTION__)();
  291. ErrorCodeEnum ErrorCode = m_pEntity->HandleSaveVideo();
  292. ctx->Answer(ErrorCode);
  293. }
  294. void SalesRecordServiceSession::Handle_StopRecord(SpReqAnsContext<SalesRecorderSerVice_StopRecord_Req, SalesRecorderSerVice_StopRecord_Ans>::Pointer ctx)
  295. {
  296. DbgToBeidou(ctx->link, __FUNCTION__)();
  297. ErrorCodeEnum ErrorCode = m_pEntity->HandleStopRecord(CSimpleStringW2A(ctx->Req.VideoName).GetData());
  298. ctx->Answer(ErrorCode);
  299. }
  300. void SalesRecordServiceSession::Handle_SetAudioTransFlag(SpReqAnsContext<SalesRecorderSerVice_SetAudioTransFlag_Req, SalesRecorderSerVice_SetAudioTransFlag_Ans>::Pointer ctx)
  301. {
  302. DbgToBeidou(ctx->link, __FUNCTION__)();
  303. ctx->Answer(Error_Succeed);
  304. }
  305. void SalesRecordServiceSession::Handle_StopShowVideo(SpReqAnsContext<SalesRecorderSerVice_StopShowVideo_Req, SalesRecorderSerVice_StopShowVideo_Ans>::Pointer ctx)
  306. {
  307. DbgToBeidou(ctx->link, __FUNCTION__)();
  308. ctx->Answer(Error_Succeed);
  309. }
  310. void SalesRecordServiceSession::Handle_PlaySalesRecord(SpReqAnsContext<SalesRecorderSerVice_PlaySalesRecord_Req, SalesRecorderSerVice_PlaySalesRecord_Ans>::Pointer ctx)
  311. {
  312. DbgToBeidou(ctx->link, __FUNCTION__)();
  313. ctx->Answer(Error_Succeed);
  314. }
  315. void SalesRecordServiceSession::Handle_StartRemoteRecord(SpReqAnsContext<SalesRecorderSerVice_StartRemoteRecord_Req, SalesRecorderSerVice_StartRemoteRecord_Ans>::Pointer ctx)
  316. {
  317. DbgToBeidou(ctx->link, __FUNCTION__)();
  318. ErrorCodeEnum ErrorCode = m_pEntity->HandleStartRecord(ctx->Req.VideoName.GetData(), true);
  319. ctx->Answer(ErrorCode);
  320. }
  321. void SalesRecordServiceSession::Handle_DeleteVideo(SpReqAnsContext<SalesRecorderSerVice_DeleteVideo_Req, SalesRecorderSerVice_DeleteVideo_Ans>::Pointer ctx)
  322. {
  323. DbgToBeidou(ctx->link, __FUNCTION__)();
  324. ErrorCodeEnum ErrorCode = m_pEntity->HandleDeleteVideo();
  325. ctx->Answer(ErrorCode);
  326. }
  327. void SalesRecordServiceSession::Handle_AppendWatermark(SpReqAnsContext<SalesRecorderSerVice_AppendWatermark_Req, SalesRecorderSerVice_AppendWatermark_Ans>::Pointer ctx)
  328. {
  329. DbgToBeidou(ctx->link, __FUNCTION__)();
  330. #ifdef RVC_OS_WIN
  331. ErrorCodeEnum ErrorCode = m_pEntity->HandleVideoAppendWatermark(CSimpleStringW2A(ctx->Req.VideoName).GetData(), CSimpleStringW2A(ctx->Req.Watermark).GetData());
  332. #else
  333. ErrorCodeEnum ErrorCode = m_pEntity->HandleVideoAppendWatermark(CSimpleStringW2A(ctx->Req.VideoName).GetData(), ctx->Req.Watermark.GetData());
  334. #endif
  335. ctx->Answer(ErrorCode);
  336. }
  337. void SalesRecordServiceSession::Handle_SetRecordCamera(SpReqAnsContext<SalesRecorderSerVice_SetRecordCamera_Req, SalesRecorderSerVice_SetRecordCamera_Ans>::Pointer ctx)
  338. {
  339. DbgToBeidou(ctx->link, __FUNCTION__)();
  340. ErrorCodeEnum ErrorCode = m_pEntity->SetRecordCamera(ctx->Req.iCamera);
  341. ctx->Answer(ErrorCode);
  342. }
  343. CServerSessionBase * CSalesRecorderEntity::OnNewSession( const char* pszRemoteEntityName, const char * pszClass )
  344. {
  345. return new SalesRecordServiceSession(this);
  346. }
  347. void CSalesRecorderEntity::OnPreStart( CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext )
  348. {
  349. ErrorCodeEnum Error = __OnStart(Error_Succeed);
  350. pTransactionContext->SendAnswer(Error);
  351. }
  352. ErrorCodeEnum CSalesRecorderEntity::__OnStart( ErrorCodeEnum preOperationError )
  353. {
  354. //MessageBoxA(0,0,0,0);
  355. m_eDeviceType = eStand2sType;
  356. m_bNeedRestart = false;
  357. #ifdef RVC_OS_WIN
  358. m_xIdlePre = m_xKernelPre = m_xUserPre = 0;
  359. if (SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS)) {
  360. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Set Process(%d) RealTime Priority Success.", GetCurrentProcessId());
  361. }
  362. #endif // RVC_OS_WIN
  363. m_eDeviceType = RvcGetDeviceType();
  364. if (preOperationError != Error_Succeed) {
  365. return preOperationError;
  366. }
  367. ErrorCodeEnum Error = Error_Succeed;
  368. m_iActiveCamera = CAMERA_TYPE_ENV;
  369. m_iCameraState = 'N';
  370. m_iRecordCamera = CAMERA_TYPE_ENV;
  371. int i = 0;
  372. m_arrListener.Init(4);
  373. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RETURNMENU, NULL, false);
  374. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_High, Error_IgnoreAll, LOG_EVT_SALESRECORD_ENTITY_EXCEPTION, NULL, false);
  375. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_SALESRECORD_SECTION_FINISHED, NULL, false);
  376. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_SALESRECORD_WHOLE_FINISHED, NULL, false);
  377. GetFunction()->RegistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA,this);
  378. GetFunction()->RegistSysVarEvent(SYSVAR_CAMERASTATE,this);
  379. CSimpleStringA strValue;
  380. GetFunction()->GetSysVar(SYSVAR_CAMERASTATE, strValue);
  381. m_iCameraState = strValue[0];
  382. if (strValue[0] == 'E'){
  383. m_iActiveCamera = CAMERA_TYPE_OPT;
  384. }
  385. else{
  386. m_iActiveCamera = CAMERA_TYPE_ENV;
  387. }
  388. Error = GetFunction()->GetPath("Temp", m_TempDir);
  389. if (Error != Error_Succeed) {
  390. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get global record temp path failed!");
  391. }
  392. if (m_TempDir.GetLength() > 0 && m_TempDir[m_TempDir.GetLength()-1] != SPLIT_SLASH) {
  393. m_TempDir += SPLIT_SLASH_STR;
  394. }
  395. Error = GetFunction()->GetPath("UploadVideo", m_RecordSaveDir);
  396. if (Error != Error_Succeed) {
  397. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get global record save path failed!");
  398. }
  399. if (m_RecordSaveDir.GetLength() > 0 && m_RecordSaveDir[m_RecordSaveDir.GetLength()-1] != SPLIT_SLASH) {
  400. m_RecordSaveDir += SPLIT_SLASH_STR;
  401. }
  402. return Error;
  403. }
  404. void CSalesRecorderEntity::OnStarted()
  405. {
  406. m_eAudioOutQuality = eUltraHD;
  407. m_bIsAudioNsOn = false;
  408. m_iAudioNsPolicy = 2;
  409. m_iAudioChannels = 1;
  410. m_bWholeSection = false;
  411. m_bEncFlag = true;
  412. m_iRemoteRecordType = 0;
  413. GetEntityConfig();
  414. #ifndef RVC_OS_WIN
  415. InitSalesRecorder();
  416. #endif
  417. LogEvent(Severity_Middle, LOG_EVT_MOD_SALESRECORDER_STARTED_SUCCESS, "sales recorder entity started successfully.");
  418. }
  419. void CSalesRecorderEntity::OnPreClose( EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext )
  420. {
  421. ErrorCodeEnum Error = __OnClose(Error_Succeed);
  422. pTransactionContext->SendAnswer(Error);
  423. }
  424. ErrorCodeEnum CSalesRecorderEntity::__OnClose( ErrorCodeEnum preOperationError )
  425. {
  426. if (preOperationError != Error_Succeed) {
  427. return preOperationError;
  428. }
  429. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  430. for (int i = 0; i < m_arrListener.GetCount(); ++i) {
  431. spFunction->UnsubscribeLog(m_arrListener[i]);
  432. }
  433. GetFunction()->UnregistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA);
  434. GetFunction()->UnregistSysVarEvent(SYSVAR_CAMERASTATE);
  435. StopRecord();
  436. #ifndef RVC_OS_WIN
  437. ReleaseSalesRecorder();
  438. #endif
  439. return Error_Succeed;
  440. }
  441. void CSalesRecorderEntity::OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  442. {
  443. if (Test_ShakeHand == eTestType)
  444. {
  445. if (m_bNeedRestart){
  446. pTransactionContext->SendAnswer(Error_Unexpect);
  447. }
  448. else{
  449. pTransactionContext->SendAnswer(Error_Succeed);
  450. }
  451. }
  452. }
  453. void CSalesRecorderEntity::Debug(record_loglevel elevel, const char* fmt, ...)
  454. {
  455. va_list arg;
  456. va_start(arg, fmt);
  457. int n = vsnprintf(NULL, 0, fmt, arg);
  458. if (n >= MAX_PATH) {
  459. char* buf = (char*)malloc((size_t)(n + 1));
  460. vsnprintf(buf, n + 1, fmt, arg);
  461. DbgWithLink((LOG_LEVEL_E)elevel, LOG_TYPE_SYSTEM)("%s", buf);
  462. free(buf);
  463. }
  464. else {
  465. char strlog[MAX_PATH] = { 0 };
  466. vsnprintf(strlog, MAX_PATH, fmt, arg);
  467. DbgWithLink((LOG_LEVEL_E)elevel, LOG_TYPE_SYSTEM)("%s", strlog);
  468. }
  469. va_end(arg);
  470. }
  471. void CSalesRecorderEntity::vDebug(record_loglevel elevel, const char* str, va_list list)
  472. {
  473. int n = vsnprintf(NULL, 0, str, list);
  474. if (n >= MAX_PATH) {
  475. char* buf = (char*)malloc((size_t)(n + 1));
  476. vsnprintf(buf, n + 1, str, list);
  477. DbgWithLink((LOG_LEVEL_E)elevel, LOG_TYPE_SYSTEM)("%s", buf);
  478. free(buf);
  479. }
  480. else {
  481. char strlog[MAX_PATH] = { 0 };
  482. vsnprintf(strlog, MAX_PATH, str, list);
  483. DbgWithLink((LOG_LEVEL_E)elevel, LOG_TYPE_SYSTEM)("%s", strlog);
  484. }
  485. }
  486. int CSalesRecorderEntity::GetRecordCamera()
  487. {
  488. int iRecordCamera = m_iRecordCamera;
  489. if (1 != m_iRemoteRecordType) {
  490. iRecordCamera = m_iActiveCamera;
  491. }
  492. else {
  493. if (0 == iRecordCamera) {
  494. LogWarn(Severity_Low, Error_Debug, LOG_EVT_SALESRECORD_USE_ENVCAMERA, "remote video record use env camera.");
  495. }
  496. else {
  497. LogWarn(Severity_Low, Error_Debug, LOG_EVT_SALESRECORD_USE_OPTCAMERA, "remote video record use opt camera.");
  498. }
  499. }
  500. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("remote record camera is %d.", iRecordCamera);
  501. return iRecordCamera;
  502. }
  503. int CSalesRecorderEntity::GetCameraState()
  504. {
  505. return m_iCameraState;
  506. }
  507. void CSalesRecorderEntity::OnRecordFailed(eRvcRecordFailedCase eCase, const char* pszMessage, bool bRecordDevFault)
  508. {
  509. #ifdef RVC_OS_WIN
  510. double fCpuUsage = GetSystemCpuUsage();
  511. if (fCpuUsage > 50.0){
  512. LogWarn(Severity_Low, Error_Debug, LOG_EVT_UI_RECORDFAILED_FOR_HIGHCPU, "more than 50 percent.");
  513. }
  514. #endif
  515. if (eCase < eDefault && eCase >= 0){
  516. LogEvent(Severity_Middle, LOG_EVT_UI_RECORDFAILED, record_failed_case_table[eCase]);
  517. }
  518. #ifdef RVC_OS_WIN
  519. LogWarn(Severity_Middle, Error_Debug, LOG_EVT_SALESRECORD_FAILED, CSimpleStringA::Format("{%s} current memory usage is %d, and cpu usage is %f.", pszMessage ? pszMessage : " ", GetSystemMemoryUsage(), fCpuUsage).GetData());
  520. #else
  521. LogWarn(Severity_Middle, Error_Debug, LOG_EVT_SALESRECORD_FAILED, CSimpleStringA::Format("%s", pszMessage ? pszMessage : " ").GetData());
  522. #endif
  523. if (eBeginFailed == eCase) {
  524. m_bNeedRestart = true;
  525. RealSelfCheck();
  526. }
  527. }
  528. void CSalesRecorderEntity::OnRecordEntityExcption()
  529. {
  530. LogEvent(Severity_High,LOG_EVT_SALESRECORD_ENTITY_EXCEPTION,"现场销售双录出现异常,请稍候重录,系统正在恢复中,预计60秒!");
  531. LogWarn(Severity_Low, Error_Debug, LOG_EVT_SALESRECORD_ENTITY_EXCEPTION, "sales record entity exception!");
  532. }
  533. void CSalesRecorderEntity::OnRecordFinished()
  534. {
  535. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_FINISHED, "现场销售双录已完成.");
  536. }
  537. void CSalesRecorderEntity::OnASectionFinished(const char* pszMessage, int iSerialNum, bool bfinished)
  538. {
  539. if (false == bfinished) {
  540. LogEvent(Severity_Middle, LOG_EVT_SALESRECORD_SECTION_FINISHED, pszMessage);
  541. }
  542. else {
  543. LogEvent(Severity_Middle, LOG_EVT_SALESRECORD_WHOLE_FINISHED, pszMessage);
  544. if (m_bEncFlag) {
  545. HandleEncryptVideoRecord(pszMessage);
  546. }
  547. }
  548. }
  549. void CSalesRecorderEntity::OnTimeout(DWORD dwTimerID)
  550. {
  551. }
  552. void CSalesRecorderEntity::OnSysVarEvent( const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName )
  553. {
  554. if (_stricmp(pszKey, SYSVAR_CAMERASTATE) == 0)
  555. {
  556. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("OnSysVarEvent Key = %s, Value = %s.", pszKey, pszValue);
  557. m_iCameraState = pszValue[0];
  558. if (pszValue[0] == 'E')
  559. {
  560. m_iActiveCamera = CAMERA_TYPE_OPT;
  561. }
  562. else
  563. {
  564. m_iActiveCamera = CAMERA_TYPE_ENV;
  565. }
  566. }
  567. else if (_stricmp(pszKey, SYSVAR_ACTIVETRACKINGCAMERA) == 0)
  568. {
  569. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("OnSysVarEvent Key = %s, Value = %s.", pszKey, pszValue);
  570. if (m_iCameraState == 'N')
  571. {
  572. if (pszValue[0] == 'E')
  573. {
  574. m_iActiveCamera = CAMERA_TYPE_ENV;
  575. }
  576. else if (pszValue[0] == 'O')
  577. {
  578. m_iActiveCamera = CAMERA_TYPE_OPT;
  579. }
  580. }
  581. }
  582. }
  583. 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)
  584. {
  585. // 响应客户经理销售录像相关的事件
  586. switch (dwUserCode)
  587. {
  588. case LOG_EVT_UI_RETURNMENU:
  589. HandleReturnMenu();
  590. break;
  591. case LOG_EVT_SALESRECORD_ENTITY_EXCEPTION:
  592. HandleSalesRecordEntityException(pszMessage);
  593. break;
  594. case LOG_EVT_SALESRECORD_SECTION_FINISHED:
  595. {
  596. if (m_bEncFlag) {
  597. HandleEncryptVideoRecord(pszMessage);
  598. }
  599. }
  600. break;
  601. case LOG_EVT_SALESRECORD_WHOLE_FINISHED:
  602. {
  603. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("recv LOG_EVT_SALESRECORD_WHOLE_FINISHED EVENT.");
  604. }
  605. break;
  606. default:
  607. break;
  608. }
  609. }
  610. bool CSalesRecorderEntity::GetStandardQualityOnSiteSalesRecorder()
  611. {
  612. bool bRet = false;
  613. m_pRecorder = new Clibvideorecord(&bRet, this, REC_COMMON_AUDIO_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE,
  614. 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);
  615. return bRet;
  616. }
  617. bool CSalesRecorderEntity::GetHighQualityOnSiteSalesRecorder()
  618. {
  619. bool bRet = false;
  620. m_pRecorder = new Clibvideorecord(&bRet, this, REC_COMMON_AUDIO_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE,
  621. 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);
  622. return bRet;
  623. }
  624. void CSalesRecorderEntity::StartOnSiteSalesRecord(const int fps, const char* videofilename, int videoquality, SubtitleParam* subtitleParam, bool bWholeSection, bool bSessionManage, eRvcRecordType eRecordType)
  625. {
  626. #ifdef RVC_OS_WIN
  627. bool bRet = false;
  628. bRet = GetStandardQualityOnSiteSalesRecorder();
  629. if (false == bRet){
  630. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get onsite sales recorder failed.");
  631. return;
  632. }
  633. #endif
  634. Rvc_RecordAudioParam_t tAudioParams;
  635. tAudioParams.eRecordType = eRecordType;
  636. tAudioParams.eOutPutType = m_eAudioOutQuality;
  637. tAudioParams.bIsNsOn = m_bIsAudioNsOn;
  638. tAudioParams.iNsPolicy = m_iAudioNsPolicy;
  639. tAudioParams.iAudioChannels = m_iAudioChannels;
  640. tAudioParams.bMuteAudioMode = false;
  641. if (eStand2Agent == eRecordType) {
  642. tAudioParams.eOutPutType = eLowDefinition;
  643. tAudioParams.bIsNsOn = false;
  644. }
  645. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("init lib video record success! and record type is %s and output audio quality is %s, audio noise suppression flag is %s. noise suppression policy is %d.", record_type_table[eRecordType], audio_quality_type_table[m_eAudioOutQuality], tAudioParams.bIsNsOn ? "true" : "false", tAudioParams.iNsPolicy);
  646. if (m_pRecorder->StartVideoRecord(fps, videoquality, eMP4, &tAudioParams, subtitleParam, bWholeSection, false, m_TempDir.GetData(),
  647. m_TempDir.GetLength(), videofilename, strlen(videofilename)))
  648. {
  649. m_bStarted = true;
  650. }
  651. else {
  652. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Start VideoRecord failed!");
  653. }
  654. }
  655. void CSalesRecorderEntity::StartRecord(const char * pszVideoName, int videoquality, SubtitleParam *subtitleParam /* = NULL */, bool bWholeSection /* = false */, bool bSessionManage /* = false */, eRvcRecordType eRecordType /* = eSingleSide */)
  656. {
  657. StartOnSiteSalesRecord(10, pszVideoName, videoquality, subtitleParam, bWholeSection, bSessionManage, eRecordType);
  658. }
  659. ErrorCodeEnum CSalesRecorderEntity::StopRecord()
  660. {
  661. ErrorCodeEnum eCode = Error_Succeed;
  662. if (m_bStarted) {
  663. m_pRecorder->StopVideoRecord();
  664. #ifdef RVC_OS_WIN
  665. delete m_pRecorder;
  666. m_pRecorder = NULL;
  667. #endif
  668. m_bStarted = false;
  669. }
  670. else{
  671. eCode = Error_InvalidState;
  672. }
  673. return eCode;
  674. }
  675. void CSalesRecorderEntity::DeleteAllVideo( const char * pszVideoName)
  676. {
  677. if(!m_bStarted)
  678. {
  679. CSimpleStringA strPath;
  680. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", strPath);
  681. if (Error == Error_Succeed) {
  682. if (strPath.GetLength() > 0 && strPath[strPath.GetLength()-1] != SPLIT_SLASH) {
  683. strPath += SPLIT_SLASH_STR;
  684. }
  685. uint32_t uVideoCount = 0;
  686. CSimpleStringA strFindFileName = CSimpleStringA::Format("S_%s*.%s", pszVideoName, RECORD_MP4_SUFFIX);
  687. bool bRet = FindMatchedFile(strPath.GetData(), strFindFileName.GetData(), uVideoCount);
  688. if(bRet)
  689. {
  690. strFindFileName = strFindFileName.SubString(0,strFindFileName.GetLength()-5);
  691. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("succeed to get sales record count while delete video!");
  692. CSimpleStringA fileName("");
  693. bool bDeleteSucc = true;
  694. for(int i = 0; i != uVideoCount; ++i)
  695. {
  696. fileName = CSimpleStringA::Format("%s%s_%d.%s", strPath.GetData(), strFindFileName.GetData(), i, RECORD_MP4_SUFFIX);
  697. bRet = RvcDeleteFile(fileName.GetData());
  698. if(!bRet) {
  699. bDeleteSucc = false;
  700. #ifdef RVC_OS_WIN
  701. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Error Code %lu while delete %s.", GetLastError(), fileName.GetData());
  702. #else
  703. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s(%d) while delete %s.", strerror(errno), errno, fileName.GetData());
  704. #endif // RVC_OS_WIN
  705. }
  706. }
  707. if (!bDeleteSucc) {
  708. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("failed to delete sales video!");
  709. }
  710. }
  711. }
  712. }
  713. }
  714. ErrorCodeEnum CSalesRecorderEntity::DeleteVideo( const char *videofilename)
  715. {
  716. ErrorCodeEnum ErrorCode = Error_Succeed;
  717. if(!m_bStarted)
  718. {
  719. CSimpleStringA strPath;
  720. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", strPath);
  721. if (Error == Error_Succeed) {
  722. if (strPath.GetLength() > 0 && strPath[strPath.GetLength()-1] != SPLIT_SLASH) {
  723. strPath += SPLIT_SLASH_STR;
  724. }
  725. CSimpleStringA strFindFileName = CSimpleStringA::Format("%s*.%s", videofilename, RECORD_MP4_SUFFIX);
  726. uint32_t uVideoCount = 0;
  727. bool bRet = FindMatchedFile(strPath.GetData(), strFindFileName.GetData(), uVideoCount);
  728. if(bRet)
  729. {
  730. CSimpleStringA fileName;
  731. bool bDeleteSucc = true;
  732. for(int i = 0; i != uVideoCount; ++i)
  733. {
  734. fileName = CSimpleStringA::Format("%s%s_%d.%s", strPath.GetData(), videofilename, i, RECORD_MP4_SUFFIX);
  735. bRet = RvcDeleteFile(fileName.GetData());
  736. if(!bRet) {
  737. bDeleteSucc = false;
  738. #ifdef RVC_OS_WIN
  739. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Error Code %lu while delete %s ", GetLastError(), fileName.GetData());
  740. #else
  741. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s(%d) while delete %s ", strerror(errno), errno, fileName.GetData());
  742. #endif
  743. }
  744. }
  745. if (!bDeleteSucc) {
  746. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("delete videos failed!");
  747. }
  748. }
  749. else
  750. {
  751. ErrorCode = Error_NotExist;
  752. }
  753. }
  754. }
  755. else {
  756. ErrorCode = Error_NotImpl;
  757. }
  758. return ErrorCode;
  759. }
  760. /*
  761. SaveVideo包含两步,找到录像和移动录像
  762. Error_Succeed 提交上传成功
  763. Error_NotExist not exist
  764. Error_NotImpl 方法执行失败
  765. */
  766. ErrorCodeEnum CSalesRecorderEntity::SaveVideo( const char * videofilename)
  767. {
  768. ErrorCodeEnum ErrorCode = Error_Succeed;
  769. if (NULL == videofilename || 0 == strlen(videofilename)) {
  770. return Error_Param;
  771. }
  772. if(!m_bStarted)
  773. {
  774. CSimpleStringA sourPath;
  775. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", sourPath);
  776. if(Error == Error_Succeed)
  777. {
  778. if (sourPath.GetLength() > 0 && sourPath[sourPath.GetLength()-1] != SPLIT_SLASH) {
  779. sourPath += SPLIT_SLASH_STR;
  780. }
  781. uint32_t uVideoCount = 0;
  782. CSimpleStringA strFindFileName = CSimpleStringA::Format("S_%s*.%s", videofilename, RECORD_MP4_SUFFIX);
  783. bool bRet = FindMatchedFile(sourPath.GetData(), strFindFileName.GetData(), uVideoCount);
  784. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("FindMatchedFile count is %d.", uVideoCount);
  785. if(bRet)
  786. {
  787. strFindFileName = strFindFileName.SubString(0,strFindFileName.GetLength()-5);
  788. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("strFindFileName is %s.", strFindFileName.GetData());
  789. CSimpleStringA destPath;
  790. Error = GetFunction()->GetPath("UploadVideo", destPath);
  791. if(Error == Error_Succeed)
  792. {
  793. if (destPath.GetLength() > 0 && destPath[destPath.GetLength()-1] != SPLIT_SLASH) {
  794. destPath += SPLIT_SLASH_STR;
  795. }
  796. CSimpleStringA sourFileName(""), destFileName("");
  797. bool bMoveSucc = false;
  798. for(int i = 0; i != uVideoCount; ++i)
  799. {
  800. sourFileName = CSimpleStringA::Format("%s%s_%d.%s", sourPath.GetData(), strFindFileName.GetData(), i, RECORD_MP4_SUFFIX);
  801. destFileName = CSimpleStringA::Format("%s%s_%d.%s", destPath.GetData(), strFindFileName.GetData(), i, RECORD_MP4_SUFFIX);
  802. unsigned long ufilesize = GetFileSize(sourFileName.GetData());
  803. char strhash[MAX_PATH] = { 0 };
  804. get_file_sm3digest(strhash, MAX_PATH, sourFileName.GetData());
  805. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_FILEINFO, CSimpleStringA::Format("%s file size is %u byte,sm3 digest is %s.", sourFileName.GetData(), ufilesize, strhash).GetData());
  806. bRet = rvcMoveFile(sourFileName.GetData(), destFileName.GetData());
  807. if (!bRet) {
  808. ErrorCode = Error_NotImpl;
  809. #ifdef RVC_OS_WIN
  810. LogWarn(Severity_Middle, Error_Debug, LOG_EVT_RECORD_SAVED_FAILED, CSimpleStringA::Format("Error Code %lu while move %s.", GetLastError(), sourFileName.GetData()).GetData());
  811. if (183 == GetLastError()) {
  812. ErrorCode = Error_InvalidState;
  813. }
  814. #else
  815. LogWarn(Severity_Middle, Error_Debug, LOG_EVT_RECORD_SAVED_FAILED, CSimpleStringA::Format("%s(%d) while move %s.", strerror(errno), errno, sourFileName.GetData()).GetData());
  816. #endif // RVC_OS_WIN
  817. }
  818. else {
  819. bMoveSucc = true;
  820. CSimpleStringA strVideoName = CSimpleStringA::Format("%s_%d.%s", strFindFileName.GetData(), i, RECORD_MP4_SUFFIX);
  821. }
  822. if (RVC_MIN_FILESIZE > ufilesize){
  823. LogWarn(Severity_Middle, Error_Debug, LOG_EVT_RECORD_INVALID_FILE, CSimpleStringA::Format("%s file size is %u.", sourFileName.GetData(), ufilesize).GetData());
  824. ErrorCode = Error_Failed;
  825. }
  826. }
  827. if (bMoveSucc) {
  828. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_SAVED_SUCCESS, CSimpleStringA::Format("succeed to save sales video, move it from %s to %s.", sourFileName.GetData(), destFileName.GetData()).GetData());
  829. }
  830. }
  831. }
  832. else{
  833. LogWarn(Severity_Middle, Error_Debug, LOG_EVT_RECORD_SAVED_FAILED, "sales videos not exist or have been deleted");
  834. ErrorCode = Error_NotExist;
  835. }
  836. }
  837. }
  838. else{
  839. ErrorCode = Error_InvalidState;
  840. }
  841. return ErrorCode;
  842. }
  843. CSimpleStringA CSalesRecorderEntity::GetTerminalStage()
  844. {
  845. CSmartPointer<IEntityFunction> Func = GetFunction();
  846. CSimpleStringA strValue = "";
  847. Func->GetSysVar("TerminalStage", strValue);
  848. return strValue;
  849. }
  850. ErrorCodeEnum CSalesRecorderEntity::HandleStartRecord(const char *pszMessage, const bool bRemoteRecord)
  851. {
  852. ErrorCodeEnum Error = Error_Succeed;
  853. eRvcRecordType eRecordType = eSingleSide;
  854. if (NULL == pszMessage){
  855. return Error_Param;
  856. }
  857. size_t ulen = strlen(pszMessage);
  858. char *tmp = new char[ulen+1];
  859. memset(tmp, 0, ulen + 1);
  860. memcpy(tmp, pszMessage, ulen);
  861. char* result[16] = { 0 };
  862. #ifdef RVC_OS_WIN
  863. auto arr1 = CSimpleStringA2W(tmp).Split('@');
  864. auto arr2 = CAutoArray<CSimpleStringA>(arr1.GetCount());
  865. for (int i = 0; i < arr1.GetCount(); ++i){
  866. arr2[i] = CSimpleStringW2A(arr1[i]);
  867. result[i] = const_cast<char*>(arr2[i].GetData());
  868. }
  869. _snprintf(m_SalesVideoName, MAX_PATH, "%s", result[4]); //录像名:录像类型标志_录像流水号(如S_C13213EF)
  870. #else
  871. CStringSplit(tmp, result, "@");
  872. memset(m_SalesVideoName, 0, MAX_PATH);
  873. if (result[4]) {
  874. snprintf(m_SalesVideoName, MAX_PATH, "%s", result[4]); //录像名:录像类型标志_录像流水号(如S_C13213EF)
  875. }
  876. #endif
  877. int iPostionArr[4][2] = { 0 };
  878. for (int i = 0; i < 4; i++){
  879. sscanf(result[i], "%d|%d", &iPostionArr[i][0], &iPostionArr[i][1]);
  880. }
  881. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("local video frame size is (%d,%d).", iPostionArr[2][0], iPostionArr[3][0]);
  882. if (iPostionArr[2][0] >= iPostionArr[3][0]) {
  883. m_iRecordCamera = CAMERA_TYPE_ENV;
  884. }
  885. else {
  886. m_iRecordCamera = CAMERA_TYPE_OPT;
  887. }
  888. RecordSubTitle subTitle;
  889. memset(&subTitle, 0, sizeof(RecordSubTitle));
  890. if (result[5]) {
  891. CSimpleStringA strCardNo = DecryptString(result[5]);
  892. if (sizeof(subTitle.CustCardNo) > strCardNo.GetLength()) {
  893. _snprintf(subTitle.CustCardNo, sizeof(subTitle.CustCardNo), "%s", strCardNo.GetData());
  894. }
  895. else {
  896. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CustCardNo.");
  897. }
  898. }
  899. char* pStr = result[6];
  900. if (pStr) {
  901. CSimpleStringW szCustName = CSimpleStringA2W(pStr);
  902. if (szCustName.GetLength() <= 4) {
  903. strcpy(subTitle.CustName, pStr);
  904. }
  905. else {
  906. CSimpleStringW aa = szCustName.SubString(0, 4);
  907. _snprintf(subTitle.CustName, 32, "%s...", CSimpleStringW2A(aa).GetData());
  908. }
  909. }
  910. pStr = result[7];
  911. if (pStr) {
  912. int nProductCodeLen = strlen(pStr);
  913. if (nProductCodeLen <= 10) {
  914. strcpy(subTitle.ProductCode, pStr);
  915. }
  916. else {
  917. char aa[5] = { 0 }, bb[5] = { 0 };
  918. strncpy(aa, pStr, 4);
  919. strncpy(bb, pStr + nProductCodeLen - 4, 4);
  920. _snprintf(subTitle.ProductCode, 32, "%s...%s", aa, bb);
  921. }
  922. }
  923. pStr = result[8];
  924. if (pStr) {
  925. CSimpleStringW szProductName = CSimpleStringA2W(pStr);
  926. if (szProductName.GetLength() <= 5) {
  927. strcpy(subTitle.ProductName, pStr);
  928. }
  929. else {
  930. CSimpleStringW aa = szProductName.SubString(0, 3);
  931. CSimpleStringW bb = szProductName.SubString(szProductName.GetLength() - 2, 2);
  932. _snprintf(subTitle.ProductName, 128, "%s...%s", CSimpleStringW2A(aa).GetData(), CSimpleStringW2A(bb).GetData());
  933. }
  934. }
  935. if (result[9]) {
  936. strcpy(subTitle.SapID, result[9]);
  937. }
  938. else {
  939. subTitle.SapID[0] = '\0';
  940. }
  941. if (result[10]) {
  942. pStr = result[10];
  943. CSimpleStringW szCustManagerName = CSimpleStringA2W(pStr);
  944. if (szCustManagerName.GetLength() <= 4) {
  945. strcpy(subTitle.CustManagerName, result[10]);
  946. }
  947. else {
  948. CSimpleStringW aa = szCustManagerName.SubString(0,4);
  949. _snprintf(subTitle.CustManagerName, 32,"%s...",CSimpleStringW2A(aa).GetData());
  950. }
  951. } else {
  952. subTitle.CustManagerName[0] = '\0';
  953. }
  954. delete[] tmp;
  955. tmp = NULL;
  956. SubtitleParam subtitleParam;
  957. memset(&subtitleParam, 0, sizeof(SubtitleParam));
  958. subtitleParam.bSubtitle = true;
  959. subtitleParam.bSubtitleSection = true;
  960. subtitleParam.topSubtitleData[0] = '\0';
  961. #ifdef RVC_OS_WIN
  962. if (strlen(subTitle.SapID)>0&&strlen(subTitle.CustManagerName)>0){
  963. _snprintf(subtitleParam.bottomSubtitleData1, MAX_PATH, "%s %s %s", subTitle.CustCardNo, subTitle.CustName, subTitle.ProductCode);
  964. _snprintf(subtitleParam.bottomSubtitleData2, MAX_PATH, "%s %s %s", subTitle.ProductName, subTitle.SapID, subTitle.CustManagerName);
  965. }
  966. else{
  967. _snprintf(subtitleParam.bottomSubtitleData1, MAX_PATH, "%s %s", subTitle.CustCardNo, subTitle.CustName);
  968. _snprintf(subtitleParam.bottomSubtitleData2, MAX_PATH, "%s %s", subTitle.ProductCode, subTitle.ProductName);
  969. }
  970. #else
  971. if (strlen(subTitle.SapID)>0&&strlen(subTitle.CustManagerName)>0){
  972. swprintf(subtitleParam.bottomSubtitleData1, MAX_PATH, L"%s %s %s", subTitle.CustCardNo, subTitle.CustName, subTitle.ProductCode);
  973. swprintf(subtitleParam.bottomSubtitleData2, MAX_PATH, L"%s %s %s", subTitle.ProductName, subTitle.SapID, subTitle.CustManagerName);
  974. }
  975. else{
  976. swprintf(subtitleParam.bottomSubtitleData1, MAX_PATH, L"%s %s", subTitle.CustCardNo, subTitle.CustName);
  977. swprintf(subtitleParam.bottomSubtitleData2, MAX_PATH, L"%s %s", subTitle.ProductCode, subTitle.ProductName);
  978. }
  979. #endif
  980. if (bRemoteRecord){
  981. if (eStand2sType == m_eDeviceType || eStand1SPlusType == m_eDeviceType) { //如果是大机
  982. eRecordType = eStand2Agent; //可视柜台大机的双向录像
  983. }
  984. }
  985. StartRecord(m_SalesVideoName, 90, &subtitleParam, m_bWholeSection, false, eRecordType);
  986. LogWarn(Severity_Low, Error_Debug, LOG_EVT_START_REMOTERECORD, CSimpleStringA::Format("start remote record %s.", m_SalesVideoName).GetData());
  987. return Error;
  988. }
  989. ErrorCodeEnum CSalesRecorderEntity::HandleStopRecord(const char *pszMessage)
  990. {
  991. ErrorCodeEnum ErrorCode = StopRecord();
  992. return ErrorCode;
  993. }
  994. ErrorCodeEnum CSalesRecorderEntity::HandleSaveVideo()
  995. {
  996. ErrorCodeEnum ErrorCode = Error_Succeed;
  997. // 将视频从tmp移动到uploadvideo
  998. ErrorCode = SaveVideo(m_SalesVideoName+2);
  999. ZeroMemory(m_SalesVideoName,sizeof(m_SalesVideoName));
  1000. return ErrorCode;
  1001. }
  1002. ErrorCodeEnum CSalesRecorderEntity::HandleDeleteVideo()
  1003. {
  1004. ErrorCodeEnum ErrorCode = Error_Succeed;
  1005. // 删除tmp中的视频
  1006. ErrorCode = DeleteVideo(m_SalesVideoName);
  1007. ZeroMemory(m_SalesVideoName,sizeof(m_SalesVideoName));
  1008. return ErrorCode;
  1009. }
  1010. void CSalesRecorderEntity::HandleReturnMenu()
  1011. {
  1012. CSimpleStringA strValue;
  1013. GetFunction()->GetSysVar("DesktopType", strValue);
  1014. if (strValue != CSimpleStringA("U"))
  1015. {
  1016. if (m_bStarted) // 如果正在进行客户经理录像
  1017. {
  1018. // 停止录像
  1019. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("stop record and return menu!");
  1020. StopRecord();
  1021. }
  1022. // 删除tmp中的视频
  1023. if (strlen(m_SalesVideoName) > 0)
  1024. {
  1025. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("delete sales record!");
  1026. DeleteAllVideo(m_SalesVideoName+2);
  1027. }
  1028. ZeroMemory(m_SalesVideoName,sizeof(m_SalesVideoName));
  1029. }
  1030. }
  1031. #ifdef RVC_OS_WIN
  1032. ErrorCodeEnum CSalesRecorderEntity::HandleVideoAppendWatermark(const char* pszVideoName, const char* pszWaterMark)
  1033. {
  1034. ErrorCodeEnum Error = Error_Failed;
  1035. if (NULL == pszWaterMark) {
  1036. return Error_Param;
  1037. }
  1038. if (m_bStarted && (NULL != m_pRecorder)) {
  1039. if (m_pRecorder->SetRightVideoWaterMark(pszWaterMark)) {
  1040. Error = Error_Succeed;
  1041. }
  1042. }
  1043. return Error;
  1044. }
  1045. #else
  1046. ErrorCodeEnum CSalesRecorderEntity::HandleVideoAppendWatermark(const char* pszVideoName, const wchar_t* pszWaterMark)
  1047. {
  1048. ErrorCodeEnum Error = Error_Failed;
  1049. if (NULL == pszWaterMark){
  1050. return Error_Param;
  1051. }
  1052. if (m_bStarted && (NULL != m_pRecorder)){
  1053. if (m_pRecorder->SetRightVideoWaterMark(pszWaterMark)) {
  1054. Error = Error_Succeed;
  1055. }
  1056. }
  1057. return Error;
  1058. }
  1059. #endif
  1060. ErrorCodeEnum CSalesRecorderEntity::HandleSalesRecordEntityException(const char* pszMessage)
  1061. {
  1062. // 通知到业务中台
  1063. SalesRecordException evt;
  1064. evt.failedmsg = CSimpleStringA2W(pszMessage==NULL?"现场销售双录过程出现异常!":pszMessage);
  1065. SpSendBroadcast(GetFunction(), SP_MSG_OF(SalesRecordException), SP_MSG_SIG_OF(SalesRecordException), evt);
  1066. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[dbg] SalesRecord entity exception broadcast sent!");
  1067. //停止录像
  1068. StopRecord();
  1069. m_bNeedRestart = true;
  1070. //重启实体
  1071. RealSelfCheck();
  1072. return Error_Succeed;
  1073. }
  1074. #ifdef RVC_OS_LINUX
  1075. bool CSalesRecorderEntity::InitSalesRecorder()
  1076. {
  1077. bool bRet = false;
  1078. bRet = GetStandardQualityOnSiteSalesRecorder();
  1079. return bRet;
  1080. }
  1081. bool CSalesRecorderEntity::ReleaseSalesRecorder()
  1082. {
  1083. if (m_pRecorder) {
  1084. delete m_pRecorder;
  1085. m_pRecorder = NULL;
  1086. }
  1087. return true;
  1088. }
  1089. #endif
  1090. ErrorCodeEnum CSalesRecorderEntity::RealSelfCheck()
  1091. {
  1092. ErrorCodeEnum Error = Error_Succeed;
  1093. HealthManagerService_ClientBase* pHMClient = new HealthManagerService_ClientBase(this);
  1094. Error = pHMClient->Connect();
  1095. if (Error != Error_Succeed){
  1096. pHMClient->SafeDelete();
  1097. pHMClient = NULL;
  1098. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("pHMClient connect fail!");
  1099. }
  1100. if (pHMClient)
  1101. {
  1102. HealthManagerService_RealCheck_Req req;
  1103. req.name = GetEntityName();
  1104. HealthManagerService_RealCheck_Ans ans;
  1105. DWORD Timeout = 500;
  1106. Error = pHMClient->RealCheck(req,ans,Timeout);
  1107. if (Error!=Error_Succeed){
  1108. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("RealSelfcheck fail!");
  1109. }
  1110. }
  1111. LogWarn(Severity_Middle, Error_Debug, LOG_EVT_ENTITY_RESTART, "sales record entity self restart.");
  1112. return Error;
  1113. }
  1114. #ifdef RVC_OS_WIN
  1115. bool IsMatchedVideo(WIN32_FIND_DATA fileData)
  1116. {
  1117. bool bRet = false;
  1118. if ('S' == fileData.cFileName[0] || 'W' == fileData.cFileName[0]){
  1119. SYSTEMTIME sysTime;
  1120. FileTimeToSystemTime(&fileData.ftCreationTime, &sysTime);
  1121. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("File %s create data info is %d %d %d.", fileData.cFileName, sysTime.wYear, sysTime.wMonth, sysTime.wDay);
  1122. if ((2020 == sysTime.wYear) && (sysTime.wMonth == 1)){
  1123. if (sysTime.wDay >= 3 && sysTime.wDay <= 10){
  1124. bRet = true;
  1125. }
  1126. }
  1127. }
  1128. return bRet;
  1129. }
  1130. void CSalesRecorderEntity::UploadTempPathVideos()
  1131. {
  1132. CSimpleStringA sourPath;
  1133. CSimpleStringA destPath;
  1134. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", sourPath);
  1135. Error = GetFunction()->GetPath("UploadVideo", destPath);
  1136. if (sourPath.GetLength() > 0 && sourPath[sourPath.GetLength()-1] != SPLIT_SLASH) {
  1137. sourPath += SPLIT_SLASH_STR;
  1138. }
  1139. if (destPath.GetLength() > 0 && destPath[destPath.GetLength()-1] != SPLIT_SLASH) {
  1140. destPath += SPLIT_SLASH_STR;
  1141. }
  1142. if(Error == Error_Succeed)
  1143. {
  1144. char srcFilePath[MAX_PATH]={0};
  1145. WIN32_FIND_DATA FindFileData;
  1146. HANDLE hFind;
  1147. BOOL fFinished = FALSE;
  1148. sprintf_s(srcFilePath, MAX_PATH, "%s*.%s", sourPath, RECORD_MP4_SUFFIX);
  1149. hFind = FindFirstFile(srcFilePath, &FindFileData);
  1150. if (INVALID_HANDLE_VALUE != hFind)
  1151. {
  1152. while (!fFinished)
  1153. {
  1154. if (FILE_ATTRIBUTE_DIRECTORY & FindFileData.dwFileAttributes)
  1155. {
  1156. continue;
  1157. }
  1158. if (IsMatchedVideo(FindFileData)){
  1159. CSimpleStringA sourFileName = CSimpleStringA::Format("%s%s", (LPCSTR)sourPath, FindFileData.cFileName);
  1160. CSimpleStringA destFileName = CSimpleStringA::Format("%sBAK_%s", (LPCSTR)destPath, FindFileData.cFileName);
  1161. if(!MoveFile((LPCSTR)sourFileName, (LPCSTR)destFileName)) {
  1162. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Error Code %lu while move %s ", GetLastError(), (LPCSTR)sourFileName);
  1163. }
  1164. }
  1165. else{
  1166. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("File (%s) is not matched.", FindFileData.cFileName);
  1167. }
  1168. if (!FindNextFile(hFind, &FindFileData))
  1169. {
  1170. if (GetLastError() == ERROR_NO_MORE_FILES)
  1171. {
  1172. fFinished = TRUE;
  1173. }
  1174. else
  1175. {
  1176. break;
  1177. }
  1178. }
  1179. }
  1180. FindClose(hFind);
  1181. }
  1182. }
  1183. }
  1184. int CSalesRecorderEntity::GetSystemMemoryUsage()
  1185. {
  1186. // Use to convert bytes to KB
  1187. #define DIV 1024
  1188. MEMORYSTATUSEX statex;
  1189. statex.dwLength = sizeof (statex);
  1190. GlobalMemoryStatusEx (&statex);
  1191. return statex.dwMemoryLoad;
  1192. }
  1193. double CSalesRecorderEntity::GetSystemCpuUsage()
  1194. {
  1195. double ratio = 0;
  1196. #define _WIN32_WINNT 0x0601
  1197. FILETIME idleTime,kernelTime,userTime;
  1198. BOOL ret = GetSystemTimes(&idleTime,&kernelTime,&userTime);
  1199. if (ret == 0)
  1200. {
  1201. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("GetSystemCPUStatus.GetSystemTimes failed(%d).",GetLastError());
  1202. return 80.0;
  1203. }
  1204. __int64 xIdle,xKernel,xUser;
  1205. xIdle = idleTime.dwHighDateTime;
  1206. xIdle <<= 32;
  1207. xIdle |= idleTime.dwLowDateTime;
  1208. xKernel = kernelTime.dwHighDateTime;
  1209. xKernel <<= 32;
  1210. xKernel |= kernelTime.dwLowDateTime;
  1211. xUser = userTime.dwHighDateTime;
  1212. xUser <<= 32;
  1213. xUser |= userTime.dwLowDateTime;
  1214. if (m_xIdlePre != 0)
  1215. {
  1216. __int64 xI,xK,xU;
  1217. xI = xIdle - m_xIdlePre;
  1218. xK = xKernel - m_xKernelPre;
  1219. xU = xUser - m_xUserPre;
  1220. if ((xK +xU) != 0)
  1221. ratio = (xK - xI + xU) * 100 / (xK + xU);
  1222. }
  1223. m_xIdlePre = xIdle;
  1224. m_xKernelPre = xKernel;
  1225. m_xUserPre = xUser;
  1226. return ratio;
  1227. }
  1228. #else
  1229. /*
  1230. **time_t转SYSTEMTIME
  1231. */
  1232. SYSTEMTIME Time_tToSystemTime(time_t t)
  1233. {
  1234. tm temptm = *localtime(&t);
  1235. SYSTEMTIME st = { 1900 + temptm.tm_year,
  1236. 1 + temptm.tm_mon,
  1237. temptm.tm_wday,
  1238. temptm.tm_mday,
  1239. temptm.tm_hour,
  1240. temptm.tm_min,
  1241. temptm.tm_sec,
  1242. 0 };
  1243. return st;
  1244. }
  1245. bool IsMatchedVideo(LPCTSTR path, struct dirent* file)
  1246. {
  1247. bool bRet = false;
  1248. if ((file->d_reclen > 0) && ('S' == file->d_name[0] || 'W' == file->d_name[0])){
  1249. struct stat fileInfo;
  1250. char ttp[256];
  1251. bzero(ttp, sizeof(ttp));
  1252. strcat(ttp, path);
  1253. if (strcmp(ttp, "/") != 0)strcat(ttp, "/");//如果是根目录不需要加
  1254. strcat(ttp, file->d_name);
  1255. if (stat(ttp, &fileInfo) == 0) {
  1256. SYSTEMTIME sysTime;
  1257. sysTime = Time_tToSystemTime(fileInfo.st_mtime);
  1258. if ((2020 == sysTime.wYear) && (sysTime.wMonth == 1)) {
  1259. if (sysTime.wDay >= 3 && sysTime.wDay <= 10) {
  1260. bRet = true;
  1261. }
  1262. }
  1263. }
  1264. }
  1265. return bRet;
  1266. }
  1267. void CSalesRecorderEntity::UploadTempPathVideos() {
  1268. CSimpleStringA sourPath;
  1269. CSimpleStringA destPath;
  1270. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", sourPath);
  1271. Error = GetFunction()->GetPath("UploadVideo", destPath);
  1272. if (sourPath.GetLength() > 0 && sourPath[sourPath.GetLength() - 1] != SPLIT_SLASH) {
  1273. sourPath += SPLIT_SLASH_STR;
  1274. }
  1275. if (destPath.GetLength() > 0 && destPath[destPath.GetLength() - 1] != SPLIT_SLASH) {
  1276. destPath += SPLIT_SLASH_STR;
  1277. }
  1278. if (Error == Error_Succeed)
  1279. {
  1280. char srcFilePath[MAX_PATH] = { 0 };
  1281. DIR* pDir = NULL;
  1282. struct dirent* pFile = NULL;
  1283. snprintf(srcFilePath, MAX_PATH, "%s*.%s", sourPath, RECORD_MP4_SUFFIX);
  1284. pDir = opendir(sourPath);
  1285. if (pDir == NULL) return ;
  1286. while ((pFile = readdir(pDir)) != NULL) {
  1287. if (pFile->d_type & DT_DIR) {
  1288. continue;
  1289. }
  1290. else {
  1291. if (IsMatchedVideo((LPCSTR)sourPath, pFile)) {
  1292. CSimpleStringA sourFileName = CSimpleStringA::Format("%s%s", (LPCSTR)sourPath, pFile->d_name);
  1293. CSimpleStringA destFileName = CSimpleStringA::Format("%sBAK_%s", (LPCSTR)destPath, pFile->d_name);
  1294. if (rename(sourFileName.GetData(), destFileName.GetData())) {
  1295. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Error Code %lu while move %s.", errno, sourFileName.GetData());
  1296. }
  1297. }
  1298. else {
  1299. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("File (%s) is not matched.", pFile->d_name);
  1300. }
  1301. }
  1302. }
  1303. closedir(pDir);
  1304. }
  1305. }
  1306. #endif
  1307. ErrorCodeEnum CSalesRecorderEntity::SetRecordAudioQuality(int iAudioQuality)
  1308. {
  1309. ErrorCodeEnum eRet = Error_Succeed;
  1310. switch (iAudioQuality)
  1311. {
  1312. case 1:
  1313. m_eAudioOutQuality = eLowDefinition;
  1314. break;
  1315. case 2:
  1316. m_eAudioOutQuality = eStandardDefinition;
  1317. break;
  1318. case 3:
  1319. m_eAudioOutQuality = eHighDefinition;
  1320. break;
  1321. case 4:
  1322. m_eAudioOutQuality = eUltraHD;
  1323. break;
  1324. default:
  1325. m_eAudioOutQuality = eUltraHD;
  1326. break;
  1327. }
  1328. return eRet;
  1329. }
  1330. ErrorCodeEnum CSalesRecorderEntity::SetRecordAudioNsPolicy(int iNsPolicy)
  1331. {
  1332. ErrorCodeEnum eRet = Error_Succeed;
  1333. if (1 == iNsPolicy || 3 == iNsPolicy){
  1334. m_iAudioNsPolicy = iNsPolicy;
  1335. }
  1336. else{
  1337. m_iAudioNsPolicy = 2;
  1338. }
  1339. return eRet;
  1340. }
  1341. ErrorCodeEnum CSalesRecorderEntity::SetRecordAudioChannles(int iAudioChannles)
  1342. {
  1343. ErrorCodeEnum eRet = Error_Succeed;
  1344. m_iAudioChannels = 2;
  1345. return eRet;
  1346. }
  1347. DeviceTypeEnum CSalesRecorderEntity::RvcGetDeviceType()
  1348. {
  1349. DeviceTypeEnum eType = eStand2sType;
  1350. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1351. CSystemStaticInfo stStaticinfo;
  1352. spFunction->GetSystemStaticInfo(stStaticinfo);
  1353. m_terminalNo = stStaticinfo.strTerminalID;
  1354. if (_stricmp(stStaticinfo.strMachineType, "RVC.Stand1SPlus") == 0) {
  1355. eType = eStand1SPlusType;
  1356. }
  1357. else if (stricmp(stStaticinfo.strMachineType, "RVC.CardStore") == 0 || stricmp(stStaticinfo.strMachineType, "RVC.CardPrinter") == 0) {
  1358. eType = eCardStore;
  1359. }
  1360. else {
  1361. eType = eStand2sType;
  1362. }
  1363. if (eType >= 0 && eType < sizeof(Device_Type_Table) / sizeof(char*)) {
  1364. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("device type is %s.", Device_Type_Table[eType]);
  1365. }
  1366. return eType;
  1367. }
  1368. int CSalesRecorderEntity::HandleEncryptVideoRecord(const char* videofilename)
  1369. {
  1370. int iRet = -1;
  1371. if (NULL == videofilename) {
  1372. return iRet;
  1373. }
  1374. if (!ExistsFile(videofilename)) {
  1375. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("File %s is not exist.", videofilename);
  1376. return iRet;
  1377. }
  1378. filecryption_callback_t cb = { 0 };
  1379. cb.dbg = &rvcDbg;
  1380. char strOutFile[MAX_PATH] = { 0 };
  1381. int iresult = encryption_file(strOutFile, MAX_PATH, videofilename, &cb, eVerB);
  1382. if (0 != iresult) {
  1383. LogWarn(Severity_Middle, Error_Debug, LOG_EVT_SALESRECORD_ENCRYPT_FAILED, CSimpleStringA::Format("encryption file %s failed, delete out temp file %s!", videofilename, strOutFile).GetData());
  1384. if (ExistsFile(strOutFile)) {
  1385. if (!RvcDeleteFile(strOutFile)) {
  1386. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("DeleteFile file %s failed!", strOutFile);
  1387. }
  1388. }
  1389. return iRet;
  1390. }
  1391. bool bRet = RvcDeleteFile(videofilename);
  1392. if (!bRet) {
  1393. #ifdef RVC_OS_WIN
  1394. LogWarn(Severity_Middle, Error_Debug, LOG_EVT_SALESRECORD_DELETE_FAILED, CSimpleStringA::Format("Error Code %lu while delete %s, delete out temp file[%s]!", GetLastError(), videofilename, strOutFile).GetData());
  1395. #else
  1396. LogWarn(Severity_Middle, Error_Debug, LOG_EVT_SALESRECORD_DELETE_FAILED, CSimpleStringA::Format("%s(%d) while delete %s, delete out temp file[%s]!", strerror(errno), errno, videofilename, strOutFile).GetData());
  1397. #endif // RVC_OS_WIN
  1398. if (!RvcDeleteFile(strOutFile)) {
  1399. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("DeleteFile file %s failed!", strOutFile);
  1400. }
  1401. return iRet;
  1402. }
  1403. else {
  1404. if (rvcMoveFile(strOutFile, videofilename)) {
  1405. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("rename %s to %s success!", strOutFile, videofilename);
  1406. iRet = 0;
  1407. }
  1408. else {
  1409. #ifdef RVC_OS_WIN
  1410. LogWarn(Severity_Middle, Error_Debug, LOG_EVT_SALESRECORD_RENAME_FAILED, CSimpleStringA::Format("Error Code %lu while rename %s.", GetLastError(), strOutFile).GetData());
  1411. #else
  1412. LogWarn(Severity_Middle, Error_Debug, LOG_EVT_SALESRECORD_RENAME_FAILED, CSimpleStringA::Format("%s(%d) while rename %s.", strerror(errno), errno, strOutFile).GetData());
  1413. #endif // RVC_OS_WIN
  1414. }
  1415. }
  1416. #if 0
  1417. char strdecFile[MAX_PATH] = { 0 };
  1418. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("begin decrypt file %s.", videofilename);
  1419. iresult = decryption_file(strdecFile, MAX_PATH, videofilename, &cb, eVerB);
  1420. if (0 == iresult) {
  1421. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("decrypt file %s -> %s success!", videofilename, strdecFile);
  1422. }
  1423. else {
  1424. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("decrypt file %s -> %s failed!", videofilename, strdecFile);
  1425. }
  1426. #endif
  1427. return iRet;
  1428. }
  1429. ErrorCodeEnum CSalesRecorderEntity::SetRecordCamera(int iCamera)
  1430. {
  1431. ErrorCodeEnum Error = Error_Succeed;
  1432. if (CAMERA_TYPE_OPT == iCamera) {
  1433. m_iRecordCamera = CAMERA_TYPE_OPT;
  1434. }
  1435. else {
  1436. m_iRecordCamera = CAMERA_TYPE_ENV;
  1437. }
  1438. return Error;
  1439. }
  1440. int CSalesRecorderEntity::GetMaxDiskPercent()
  1441. {
  1442. return m_max_disk_percent;
  1443. }
  1444. ErrorCodeEnum CSalesRecorderEntity::GetEntityConfig()
  1445. {
  1446. ErrorCodeEnum Error = Error_Succeed;
  1447. int iAudioQuality = 3;
  1448. int iAudioNsPolicy = 2;
  1449. int iIsAudioNsOn = 0;
  1450. int iAudioChannels = 1;
  1451. int iTimeOut = RVC_HTTPTIMEOUT;
  1452. CSimpleStringA strHttpServerAddr("");
  1453. int iPostOn = 0;
  1454. m_max_disk_percent = MAX_DISK_PERCENT;
  1455. int iStopEncflag = 0;
  1456. int iRemoteRecordType = 0;
  1457. CSmartPointer<IConfigInfo> spConfig;
  1458. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1459. if (spFunction->OpenConfig(Config_CenterSetting, spConfig) == Error_Succeed) {
  1460. spConfig->ReadConfigValueInt("SalesRecorder", "AudioNsPolicy", iAudioNsPolicy);
  1461. spConfig->ReadConfigValueInt("SalesRecorder", "IsAudioNsOn", iIsAudioNsOn);
  1462. spConfig->ReadConfigValueInt("SalesRecorder", "AudioQuality", iAudioQuality);
  1463. spConfig->ReadConfigValueInt("SalesRecorder", "AudioChannels", iAudioChannels);
  1464. spConfig->ReadConfigValueInt("SalesRecorder", "stopencflag", iStopEncflag);
  1465. spConfig->ReadConfigValueInt("InteractiveControl", "RemoteRecordType", iRemoteRecordType);
  1466. }
  1467. SetRecordAudioQuality(iAudioQuality);
  1468. SetRecordAudioNsPolicy(iAudioNsPolicy);
  1469. SetRecordAudioChannles(iAudioChannels);
  1470. if (0 != iIsAudioNsOn) {
  1471. m_bIsAudioNsOn = true;
  1472. }
  1473. if (1 == iStopEncflag) {
  1474. m_bEncFlag = false;
  1475. }
  1476. if (1 == iRemoteRecordType) {
  1477. m_iRemoteRecordType = 1;
  1478. }
  1479. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_bEncFlag is %s, m_iRemoteRecordType is %d.", m_bEncFlag ? "true" : "false", m_iRemoteRecordType);
  1480. return Error;
  1481. }
  1482. SP_BEGIN_ENTITY_MAP()
  1483. SP_ENTITY(CSalesRecorderEntity)
  1484. SP_END_ENTITY_MAP()