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