mod_SalesRecorder.cpp 48 KB

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