mod_recorder.cpp 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060
  1. #include "mod_recorder.h"
  2. #ifdef RVC_OS_WIN
  3. #include "stdafx.h"
  4. #else
  5. #include<sys/stat.h>
  6. #include<sys/types.h>
  7. #include<dirent.h>
  8. #include<unistd.h>
  9. #endif // RVC_OS_WIN
  10. #include "Event.h"
  11. #include "y2k_time.h"
  12. #include <string.h>
  13. #include "filecryption.h"
  14. #include "mod_facetracking/sysvar.h"
  15. #include "mod_interactivecontrol/Event.h"
  16. #include "mod_mediacontroller/Event.h"
  17. using namespace Recorder;
  18. #ifndef RVC_MAX_VIDEO_NAME_LEN
  19. #define RVC_MAX_VIDEO_NAME_LEN 256
  20. #endif
  21. #ifndef RVC_FILEENC_STR
  22. #define RVC_FILEENC_STR "enc_"
  23. #endif
  24. #ifndef MAX_LOG_LEN
  25. #define MAX_LOG_LEN 512
  26. #endif
  27. #ifndef RVC_TRANSATCION_RECORD_SUFFIX
  28. #define RVC_TRANSATCION_RECORD_SUFFIX "B_"
  29. #endif // !RVC_TRANSATCION_RECORD_SUFFIX
  30. #ifndef RVC_ENCRYPT_TRANSATCION_RECORD_SUFFIX
  31. #define RVC_ENCRYPT_TRANSATCION_RECORD_SUFFIX "enc_B_"
  32. #endif // !RVC_ENCRYPT_TRANSATCION_RECORD_SUFFIX
  33. static unsigned long GetFileSize(const char* pfilename)
  34. {
  35. #ifdef RVC_OS_WIN
  36. unsigned long usize = 0;
  37. if (NULL == pfilename) {
  38. return usize;
  39. }
  40. FILE* pFile = fopen(pfilename, "rb");
  41. if (pFile) {
  42. fseek(pFile, 0, SEEK_END);
  43. usize = ftell(pFile);
  44. fclose(pFile);
  45. }
  46. return usize;
  47. #else
  48. struct stat statbuf;
  49. stat(pfilename, &statbuf);
  50. return statbuf.st_size;
  51. #endif
  52. }
  53. static const char* GetFileName(const char* pfilename)
  54. {
  55. if (NULL == pfilename) {
  56. return NULL;
  57. }
  58. return strstr(pfilename, RVC_TRANSATCION_RECORD_SUFFIX);
  59. }
  60. static void LogVideoSizeInfo(const char* pszMessage)
  61. {
  62. unsigned long ufilesize = GetFileSize(pszMessage);
  63. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_VIDEO_SIZE, CSimpleStringA::Format("%s file size is %u byte.", pszMessage, ufilesize).GetData());
  64. }
  65. static void rvcDbg(filecrypt_loglevel elevel, const char* fmt, ...)
  66. {
  67. LOG_LEVEL_E eloglevel = LOG_LEVEL_DEBUG;
  68. if (FILECRYPT_LOG_INFO <= elevel) {
  69. eloglevel = LOG_LEVEL_INFO;
  70. }
  71. va_list arg;
  72. va_start(arg, fmt);
  73. int n = vsnprintf(NULL, 0, fmt, arg);
  74. if (n >= MAX_LOG_LEN) {
  75. char* buf = (char*)malloc((size_t)(n + 1));
  76. vsnprintf(buf, n + 1, fmt, arg);
  77. DbgWithLink(eloglevel, LOG_TYPE_SYSTEM)("%s", buf);
  78. free(buf);
  79. }
  80. else{
  81. char strlog[MAX_LOG_LEN] = {0};
  82. vsnprintf(strlog, MAX_LOG_LEN, fmt, arg);
  83. DbgWithLink(eloglevel, LOG_TYPE_SYSTEM)("%s", strlog);
  84. }
  85. va_end(arg);
  86. }
  87. static bool rvcMoveFile(const char* strSrcFile, const char* strDstFile)
  88. {
  89. bool bRet = false;
  90. if (NULL == strSrcFile || NULL == strDstFile) {
  91. return bRet;
  92. }
  93. #ifdef RVC_OS_WIN
  94. bRet = MoveFile(strSrcFile, strDstFile);
  95. #else
  96. if (0 == rename(strSrcFile, strDstFile)) {
  97. bRet = true;
  98. }
  99. #endif // RVC_OS_WIN
  100. return bRet;
  101. }
  102. static bool RvcDeleteFile(const char* strSrcFile)
  103. {
  104. bool bRet = false;
  105. if (NULL == strSrcFile) {
  106. return bRet;
  107. }
  108. #ifdef RVC_OS_WIN
  109. bRet = DeleteFile(strSrcFile);
  110. #else
  111. if (0 == remove(strSrcFile)) {
  112. bRet = true;
  113. }
  114. #endif // RVC_OS_WIN
  115. return bRet;
  116. }
  117. void RecordServiceSession::Handle_StartTransactionRecord(SpReqAnsContext<RecorderSerVice_StartTransactionRecord_Req, RecorderSerVice_StartTransactionRecord_Ans>::Pointer ctx)
  118. {
  119. DbgToBeidou(ctx->link, __FUNCTION__)();
  120. if (m_pEntity->GetStartFlag()) {
  121. m_pEntity->StopRecord();
  122. }
  123. m_pEntity->SetRecordSessionID(ctx->Req.VideoName.GetData());
  124. m_pEntity->StartRecord(CSimpleStringA::Format("%s%s", RVC_TRANSATCION_RECORD_SUFFIX, ctx->Req.VideoName.GetData()).GetData());
  125. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("start video record %s.", ctx->Req.VideoName.GetData());
  126. ctx->Answer(Error_Succeed);
  127. }
  128. void RecordServiceSession::Handle_StopTransactionRecord(SpReqAnsContext<RecorderSerVice_StopTransactionRecord_Req, RecorderSerVice_StopTransactionRecord_Ans>::Pointer ctx)
  129. {
  130. DbgToBeidou(ctx->link, __FUNCTION__)();
  131. m_pEntity->StopRecord();
  132. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("stop video record %s.", ctx->Req.VideoName.GetData());
  133. ctx->Answer(Error_Succeed);
  134. }
  135. void CRecorderEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  136. {
  137. ErrorCodeEnum Error = __OnStart(Error_Succeed);
  138. pTransactionContext->SendAnswer(Error);
  139. }
  140. void CRecorderEntity::OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  141. {
  142. ErrorCodeEnum Error = __OnClose(Error_Succeed);
  143. pTransactionContext->SendAnswer(Error);
  144. }
  145. ErrorCodeEnum CRecorderEntity::__OnStart(ErrorCodeEnum preOperationError)
  146. {
  147. ErrorCodeEnum Error = Error_Succeed;
  148. m_eDeviceType = RvcGetDeviceType();
  149. if (preOperationError != Error_Succeed) {
  150. return preOperationError;
  151. }
  152. m_iActiveCamera = CAMERA_TYPE_ENV;
  153. m_iCameraState = 'N';
  154. InitRecorder();
  155. int i = 0;
  156. m_arrListener.Init(7);
  157. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, EVENT_MOD_PAUSE_RECORD, NULL, false);
  158. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, EVENT_MOD_CONTINUE_RECORD, NULL, false);
  159. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_RECORDER_SECTION_FINISHED, NULL, false);
  160. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_RECORDER_WHOLE_FINISHED, NULL, false);
  161. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_START_BUSINESSRECORD_FAILED, NULL, false);
  162. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_MEDIACONTROLLER_CAMERA_STARTED, NULL, false);
  163. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_MEDIACONTROLLER_CAMERA_STOPPED, NULL, false);
  164. GetFunction()->RegistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA,this);
  165. GetFunction()->RegistSysVarEvent(SYSVAR_CAMERASTATE,this);
  166. CSimpleStringA strValue;
  167. GetFunction()->GetSysVar(SYSVAR_CAMERASTATE, strValue);
  168. m_iCameraState = strValue[0];
  169. if (strValue[0] == 'E'){
  170. m_iActiveCamera = CAMERA_TYPE_OPT;
  171. if (eStand1SPlusType == m_eDeviceType){
  172. m_iActiveCamera = CAMERA_TYPE_ERROR;
  173. }
  174. }
  175. else if (strValue[0] == 'O'){
  176. m_iActiveCamera = CAMERA_TYPE_ENV;
  177. }
  178. else if(strValue[0] == 'B'){
  179. m_iActiveCamera = CAMERA_TYPE_ERROR;
  180. }
  181. else if (strValue[0] == 'N'){
  182. m_iActiveCamera = CAMERA_TYPE_ENV;
  183. }
  184. Error = GetFunction()->GetPath("Temp", m_TempDir);
  185. if (Error != Error_Succeed) {
  186. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get global record temp path failed!");
  187. }
  188. if (m_TempDir.GetLength() > 0 && m_TempDir[m_TempDir.GetLength()-1] != SPLIT_SLASH) {
  189. m_TempDir += SPLIT_SLASH_STR;
  190. }
  191. Error = GetFunction()->GetPath("UploadVideo", m_RecordSaveDir);
  192. if (Error != Error_Succeed) {
  193. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get global record save path failed!");
  194. }
  195. if (m_RecordSaveDir.GetLength() > 0 && m_RecordSaveDir[m_RecordSaveDir.GetLength()-1] != SPLIT_SLASH) {
  196. m_RecordSaveDir += SPLIT_SLASH_STR;
  197. }
  198. return Error;
  199. }
  200. void CRecorderEntity::OnStarted()
  201. {
  202. CSystemStaticInfo si;
  203. ErrorCodeEnum Error = GetFunction()->GetSystemStaticInfo(si);
  204. if (Error == Error_Succeed) {
  205. m_strAppVersion = si.InstallVersion.ToString();
  206. m_strTerminalId = si.strTerminalID;
  207. }
  208. LoadEntityConfig();
  209. //DeleteExceptionLogFiles();
  210. SaveExceptionRecordVideos();
  211. if (m_vRecordList.size() > 0) {
  212. HandleExceptionRecordVideos();
  213. PostVideoRecordInfos();
  214. }
  215. }
  216. bool CRecorderEntity::InitRecorder()
  217. {
  218. bool bRet = false;
  219. if (eStand1SPlusType == m_eDeviceType) {
  220. m_pRecorder = new Clibvideorecord(&bRet, this, REC_COMMON_AUDIO_SHM_QUEUE,
  221. REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE, NULL);
  222. }
  223. else {
  224. m_pRecorder = new Clibvideorecord(&bRet, this, REC_COMMON_AUDIO_SHM_QUEUE,
  225. REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE, REC_COMMON_VIDEO_OPT_SHM_RTP_QUEUE);
  226. }
  227. return bRet;
  228. }
  229. bool CRecorderEntity::ReleaseRecorder()
  230. {
  231. if (m_pRecorder) {
  232. delete m_pRecorder;
  233. m_pRecorder = NULL;
  234. }
  235. return true;
  236. }
  237. ErrorCodeEnum CRecorderEntity::__OnClose(ErrorCodeEnum preOperationError)
  238. {
  239. if (preOperationError != Error_Succeed) {
  240. return preOperationError;
  241. }
  242. for (int i = 0; i < m_arrListener.GetCount(); ++i) {
  243. GetFunction()->UnsubscribeLog(m_arrListener[i]);
  244. }
  245. GetFunction()->UnregistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA);
  246. GetFunction()->UnregistSysVarEvent(SYSVAR_CAMERASTATE);
  247. StopRecord();
  248. return Error_Succeed;
  249. }
  250. CServerSessionBase* CRecorderEntity::OnNewSession(const char* pszRemoteEntityName, const char* pszClass)
  251. {
  252. return new RecordServiceSession(this);
  253. }
  254. void CRecorderEntity::Debug(record_loglevel elevel, const char *fmt, ...)
  255. {
  256. if (RECORD_LOG_INFO <= elevel) {
  257. va_list arg;
  258. va_start(arg, fmt);
  259. int n = vsnprintf(NULL, 0, fmt, arg);
  260. if (n >= MAX_LOG_LEN) {
  261. char* buf = (char*)malloc((size_t)(n + 1));
  262. vsnprintf(buf, n + 1, fmt, arg);
  263. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
  264. free(buf);
  265. }
  266. else{
  267. char strlog[MAX_LOG_LEN] = {0};
  268. vsnprintf(strlog, MAX_LOG_LEN, fmt, arg);
  269. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
  270. }
  271. va_end(arg);
  272. }
  273. }
  274. void CRecorderEntity::vDebug(record_loglevel elevel, const char* str, va_list list)
  275. {
  276. if (RECORD_LOG_INFO <= elevel) {
  277. int n = vsnprintf(NULL, 0, str, list);
  278. if (n >= MAX_LOG_LEN) {
  279. char* buf = (char*)malloc((size_t)(n + 1));
  280. vsnprintf(buf, n + 1, str, list);
  281. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
  282. free(buf);
  283. }
  284. else {
  285. char strlog[MAX_LOG_LEN] = { 0 };
  286. vsnprintf(strlog, MAX_LOG_LEN, str, list);
  287. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
  288. }
  289. }
  290. }
  291. int CRecorderEntity::GetActiveCamera()
  292. {
  293. return m_iActiveCamera;
  294. }
  295. ErrorCodeEnum CRecorderEntity::LoadEntityConfig()
  296. {
  297. ErrorCodeEnum Error = Error_Succeed;
  298. int iTimeOut = RVC_HTTPTIMEOUT;
  299. int iStopEncflag = 0;
  300. CSimpleStringA strHttpServerAddr("");
  301. CSmartPointer<IConfigInfo> spConfig;
  302. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  303. if (spFunction->OpenConfig(Config_CenterSetting, spConfig) == Error_Succeed) {
  304. spConfig->ReadConfigValue("Recorder", "http_video_record_addr", strHttpServerAddr);
  305. spConfig->ReadConfigValueInt("Recorder", "http_timeout", iTimeOut);
  306. spConfig->ReadConfigValueInt("Recorder", "stopencflag", iStopEncflag);
  307. }
  308. else {
  309. Error = Error_Failed;
  310. }
  311. if (strHttpServerAddr.GetLength() > 0) {
  312. m_strHttpServerAddr = strHttpServerAddr;
  313. }
  314. if (iTimeOut > 0 && iTimeOut < 20 * RVC_HTTPTIMEOUT) {
  315. m_iHttpTimeOut = iTimeOut;
  316. }
  317. if (1 == iStopEncflag) {
  318. m_bEncFlag = false;
  319. }
  320. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_bEncFlag is %s.", m_bEncFlag ? "true":"false");
  321. return Error;
  322. }
  323. ErrorCodeEnum CRecorderEntity::PostVideoRecordInfos()
  324. {
  325. ErrorCodeEnum Error = Error_Failed;
  326. char strtimenow[MAX_PATH] = { 0 };
  327. y2k_time_t nowtime = y2k_time_now();
  328. y2k_to_string(nowtime, strtimenow, MAX_PATH);
  329. video_record_info_t video_params;
  330. video_params.strServerURL = m_strHttpServerAddr;
  331. video_params.strAPI = m_strHttpServerAPI;
  332. video_params.strAppVersion = m_strAppVersion;
  333. video_params.strRecordEndTime = strtimenow;
  334. video_params.strTerminalNo = m_strTerminalId;
  335. video_params.iBusinessStatus = (int)m_eBusinessStatus;
  336. if (eFailed == m_eBusinessStatus) {
  337. if (m_vRecordList.size() > 0) {
  338. video_params.iBusinessStatus = eInterrupt;
  339. }
  340. }
  341. video_params.strRecordID = m_strRecordName;
  342. for (vector<record_item_t>::iterator it = m_vRecordList.begin(); it < m_vRecordList.end(); ++it) {
  343. video_params.vRecordList.push_back(*it);
  344. }
  345. unsigned int uposttime = 0;
  346. CSimpleStringA strErrorMsg("");
  347. if (0 == post_video_recordinfo_list(uposttime, strErrorMsg, &video_params, m_iHttpTimeOut, false)) {
  348. LogWarn(Severity_Low, Error_Debug, LOG_EVT_POST_RECORDINFO_COST_TIME, CSimpleStringA::Format("post video record infos cost time is %ums.", uposttime).GetData());
  349. Error = Error_Succeed;
  350. }
  351. else {
  352. LogWarn(Severity_Middle, Error_Exception, LOG_EVT_POST_RECORDINFO_FAILED, strErrorMsg.GetData());
  353. }
  354. m_vRecordList.clear();
  355. return Error;
  356. }
  357. ErrorCodeEnum CRecorderEntity::HandleExceptionRecordVideos()
  358. {
  359. ErrorCodeEnum Error = Error_Failed;
  360. const char* videofilename = m_vRecordList[0].file_path.c_str();
  361. if (NULL == videofilename) {
  362. return Error;
  363. }
  364. char strSession[RVC_MAX_VIDEO_NAME_LEN] = { 0 };
  365. int iSeriesNum = -1;
  366. char strFormat[RVC_MAX_VIDEO_NAME_LEN] = { 0 };
  367. if (-1 == GetRecordVideoInfo(videofilename, strSession, RVC_MAX_VIDEO_NAME_LEN, &iSeriesNum, strFormat, RVC_MAX_VIDEO_NAME_LEN)) {
  368. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[%s] get record video info failed.", videofilename);
  369. return Error;
  370. }
  371. SetRecordSessionID(strSession + strlen(RVC_TRANSATCION_RECORD_SUFFIX));
  372. while (--iSeriesNum >= 0) {
  373. CSimpleStringA strFilePath("");
  374. strFilePath = CSimpleStringA::Format("%s%s_%d.%s", m_RecordSaveDir.GetData(), strSession, iSeriesNum, strFormat);
  375. if (ExistsFile(strFilePath.GetData())) {
  376. AddToVideoRecordList(strFilePath.GetData());
  377. }
  378. else {
  379. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("File {%s} is not exist.", strFilePath.GetData());
  380. }
  381. }
  382. return Error;
  383. }
  384. ErrorCodeEnum CRecorderEntity::AddToVideoRecordList(const char* videofilename)
  385. {
  386. ErrorCodeEnum Error = Error_Failed;
  387. if (NULL == videofilename) {
  388. return Error;
  389. }
  390. record_item_t* item = new record_item_t();
  391. item->file_path = videofilename;
  392. item->file_length = (int)GetFileSize(videofilename);
  393. const char* strfilename = GetFileName(videofilename);
  394. if (strfilename) {
  395. item->file_name = strfilename;
  396. }
  397. m_vRecordList.push_back(*item);
  398. Error = Error_Succeed;
  399. return Error;
  400. }
  401. void CRecorderEntity::OnRecordFailed(eRvcRecordFailedCase eCase, const char *pszMessage, bool bRecordDevFault)
  402. {
  403. m_eBusinessStatus = eFailed;
  404. if (!bRecordDevFault){
  405. LogEvent(Severity_Middle,LOG_EVT_RECORDFAILED,"0");
  406. LogWarn(Severity_Middle, Error_Debug, LOG_EVT_RECORDING_FAILED, CSimpleStringA::Format("%s 本地录音录像失败,已停止!", pszMessage ? pszMessage : " ").GetData());
  407. }
  408. else{
  409. LogEvent(Severity_Middle,LOG_EVT_RECORDFAILED,"1");
  410. LogWarn(Severity_Middle, Error_Debug, LOG_EVT_RECORDING_FAILED, CSimpleStringA::Format("%s 本地录音录像设备故障,尝试恢复中(预计10s内),请稍等", pszMessage ? pszMessage : " ").GetData());
  411. }
  412. }
  413. void CRecorderEntity::OnRecordEntityExcption()
  414. {
  415. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_ENTITY_EXCEPTION, "OnRecordEntityExcption!");
  416. }
  417. void CRecorderEntity::OnRecordFinished()
  418. {
  419. }
  420. int CRecorderEntity:: GetCameraState()
  421. {
  422. return m_iCameraState;
  423. }
  424. void CRecorderEntity::OnASectionFinished(const char *pszMessage, int iSerialNum, bool bfinished)
  425. {
  426. if (false == bfinished){
  427. LogEvent(Severity_Middle, LOG_EVT_RECORDER_SECTION_FINISHED, pszMessage);
  428. }
  429. else{
  430. LogEvent(Severity_Middle, LOG_EVT_RECORDER_WHOLE_FINISHED, pszMessage);
  431. }
  432. }
  433. void CRecorderEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  434. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  435. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext& pLinkInfo)
  436. {
  437. switch (dwUserCode)
  438. {
  439. case EVENT_MOD_PAUSE_RECORD:
  440. m_pRecorder->PauseRecord();
  441. if (m_bStarted) {
  442. m_pRecorder->CloseVideoFile();
  443. }
  444. break;
  445. case EVENT_MOD_CONTINUE_RECORD:
  446. m_pRecorder->ContinueRecord();
  447. break;
  448. case LOG_EVT_RECORDER_SECTION_FINISHED:
  449. {
  450. LogVideoSizeInfo(pszMessage);
  451. if (m_bEncFlag){
  452. HandleEncryptVideoRecord(pszMessage);
  453. }
  454. HandleSaveVideoRecord(pszMessage);
  455. }
  456. break;
  457. case LOG_EVT_RECORDER_WHOLE_FINISHED:
  458. {
  459. LogVideoSizeInfo(pszMessage);
  460. if (m_bEncFlag){
  461. HandleEncryptVideoRecord(pszMessage);
  462. }
  463. HandleFinishedVideoRecord(pszMessage);
  464. PostVideoRecordInfos();
  465. }
  466. break;
  467. case LOG_EVT_START_BUSINESSRECORD_FAILED:
  468. m_eBusinessStatus = eFailed;
  469. PostVideoRecordInfos();
  470. break;
  471. case LOG_EVT_MEDIACONTROLLER_CAMERA_STARTED:
  472. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("recv LOG_EVT_MEDIACONTROLLER_CAMERA_STARTED event");
  473. break;
  474. case LOG_EVT_MEDIACONTROLLER_CAMERA_STOPPED:
  475. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("recv LOG_EVT_MEDIACONTROLLER_CAMERA_STOPPED event");
  476. break;
  477. default:
  478. break;
  479. }
  480. }
  481. void CRecorderEntity::OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName)
  482. {
  483. if (_stricmp(pszKey, SYSVAR_CAMERASTATE) == 0)
  484. {
  485. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("OnSysVarEvent Key = %s, Value = %s.", pszKey, pszValue);
  486. m_iCameraState = pszValue[0];
  487. if (pszValue[0] == 'E'){
  488. m_iActiveCamera = CAMERA_TYPE_OPT;
  489. }
  490. else if (pszValue[0] == 'O'){
  491. m_iActiveCamera = CAMERA_TYPE_ENV;
  492. }
  493. else if(pszValue[0] == 'B'){
  494. m_iActiveCamera = CAMERA_TYPE_ERROR;
  495. }
  496. else if (pszValue[0] == 'N'){
  497. m_iActiveCamera = CAMERA_TYPE_ENV;
  498. }
  499. }
  500. else if (_stricmp(pszKey, SYSVAR_ACTIVETRACKINGCAMERA) == 0)
  501. {
  502. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("OnSysVarEvent Key = %s, Value = %s.", pszKey, pszValue);
  503. if (m_iCameraState == 'N'){
  504. if (pszValue[0] == 'E'){
  505. m_iActiveCamera = CAMERA_TYPE_ENV;
  506. }
  507. else if (pszValue[0] == 'O'){
  508. m_iActiveCamera = CAMERA_TYPE_OPT;
  509. }
  510. }
  511. }
  512. }
  513. void CRecorderEntity::OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  514. {
  515. if (Test_ShakeHand == eTestType){
  516. pTransactionContext->SendAnswer(Error_Succeed);
  517. }
  518. }
  519. void CRecorderEntity::StartRecord(const char *videofilename)
  520. {
  521. int fps = 5;
  522. Rvc_RecordAudioParam_t tAudioParams;
  523. tAudioParams.eRecordType = eSingleSide;
  524. tAudioParams.eOutPutType = eLowDefinition;
  525. tAudioParams.bIsNsOn = true;
  526. tAudioParams.iNsPolicy = 2;
  527. tAudioParams.iAudioOutBitRate = 8;
  528. tAudioParams.bIsTransOn = false;
  529. tAudioParams.iAudioChannels = 1;
  530. if (m_pRecorder->StartVideoRecord(fps, 75, eMP4, &tAudioParams, NULL, false, true, m_TempDir.GetData(), m_RecordSaveDir.GetLength(), videofilename, strlen(videofilename)))
  531. {
  532. m_bStarted = true;
  533. m_eBusinessStatus = eSuccess;
  534. }
  535. }
  536. void CRecorderEntity::StopRecord()
  537. {
  538. if (m_bStarted) {
  539. m_pRecorder->StopVideoRecord();
  540. m_bStarted = false;
  541. }
  542. }
  543. void CRecorderEntity::SetRecordSessionID(const char* strRecordID)
  544. {
  545. if (NULL != strRecordID) {
  546. memset(m_strRecordName, 0 , MAX_PATH);
  547. snprintf(m_strRecordName, MAX_PATH, "%s", strRecordID);
  548. }
  549. }
  550. void CRecorderEntity::GetRecordSessionID(char* strRecordID, size_t uLen)
  551. {
  552. if (NULL != strRecordID) {
  553. snprintf(strRecordID, uLen, "%s", m_strRecordName);
  554. }
  555. }
  556. DeviceTypeEnum CRecorderEntity::RvcGetDeviceType()
  557. {
  558. DeviceTypeEnum eType = eStand2sType;
  559. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  560. CSystemStaticInfo stStaticinfo;
  561. spFunction->GetSystemStaticInfo(stStaticinfo);
  562. if (_stricmp(stStaticinfo.strMachineType.GetData(), "RVC.Stand1SPlus") == 0) {
  563. eType = eStand1SPlusType;
  564. }
  565. else if (_stricmp(stStaticinfo.strMachineType.GetData(), "RVC.CardStore") == 0 || _stricmp(stStaticinfo.strMachineType.GetData(), "RVC.CardPrinter") == 0) {
  566. eType = eCardStore;
  567. }
  568. else {
  569. eType = eStand2sType;
  570. }
  571. if (eType >= 0 && eType < sizeof(Device_Type_Table) / sizeof(char*)) {
  572. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("device type is %s.", Device_Type_Table[eType]);
  573. }
  574. m_terminalNo = stStaticinfo.strTerminalID;
  575. return eType;
  576. }
  577. int CRecorderEntity::HandleFinishedVideoRecord(const char* videofilename)
  578. {
  579. int iRet = -1;
  580. if (NULL == videofilename){
  581. return iRet;
  582. }
  583. char strSession[RVC_MAX_VIDEO_NAME_LEN] = {0};
  584. int iSeriesNum = -1;
  585. char strFormat[RVC_MAX_VIDEO_NAME_LEN] = {0};
  586. if (-1 == GetRecordVideoInfo(videofilename, strSession, RVC_MAX_VIDEO_NAME_LEN, &iSeriesNum, strFormat, RVC_MAX_VIDEO_NAME_LEN)){
  587. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[%s] get record video info failed.", videofilename);
  588. return iRet;
  589. }
  590. CSimpleStringA srcfile = CSimpleStringA::Format("%s%s_%d_end.%s", m_TempDir.GetData(), strSession, iSeriesNum, strFormat);
  591. CSimpleStringA dstfile = CSimpleStringA::Format("%s%s_%d_end.%s", m_RecordSaveDir.GetData(), strSession, iSeriesNum, strFormat);
  592. bool bRet = false;
  593. if (ExistsFile(srcfile.GetData())){
  594. bRet = rvcMoveFile(srcfile.GetData(), dstfile.GetData());
  595. if(!bRet) {
  596. #ifdef RVC_OS_WIN
  597. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("Error Code %u while move %s ", GetLastError(), srcfile.GetData()).GetData());
  598. #else
  599. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("%s(%d) while move %s ", strerror(errno), errno, srcfile.GetData()).GetData());
  600. #endif // RVC_OS_WIN
  601. }
  602. else {
  603. AddToVideoRecordList(dstfile.GetData());
  604. }
  605. }
  606. srcfile = CSimpleStringA::Format("%s%s_%d.%s",m_TempDir.GetData(), strSession, iSeriesNum-1, strFormat);
  607. dstfile = CSimpleStringA::Format("%s%s_%d.%s",m_RecordSaveDir.GetData(), strSession, iSeriesNum-1, strFormat);
  608. if (ExistsFile(srcfile.GetData())){
  609. bRet = rvcMoveFile(srcfile.GetData(), dstfile.GetData());
  610. if(!bRet) {
  611. #ifdef RVC_OS_WIN
  612. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("Error Code %u while move %s ", GetLastError(), srcfile.GetData()).GetData());
  613. #else
  614. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("%s(%d) while move %s ", strerror(errno), errno, srcfile.GetData()).GetData());
  615. #endif // RVC_OS_WIN
  616. }
  617. else {
  618. AddToVideoRecordList(dstfile.GetData());
  619. }
  620. }
  621. iRet = 0;
  622. return iRet;
  623. }
  624. int CRecorderEntity::HandleEncryptVideoRecord(const char* videofilename)
  625. {
  626. int iRet = -1;
  627. if (NULL == videofilename){
  628. return iRet;
  629. }
  630. filecryption_callback_t cb = {0};
  631. cb.dbg = &rvcDbg;
  632. char strOutFile[MAX_PATH] = {0};
  633. int iresult = encryption_file(strOutFile, MAX_PATH, videofilename, &cb, eVerB);
  634. if (0 != iresult){
  635. LogWarn(Severity_Middle, Error_Debug, LOG_EVT_RECORDER_ENCRYPT_FAILED, CSimpleStringA::Format("encryption file %s failed, delete out temp file %s!", videofilename, strOutFile).GetData());
  636. if (ExistsFile(strOutFile)) {
  637. if (!RvcDeleteFile(strOutFile)) {
  638. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("DeleteFile file %s failed!", strOutFile);
  639. }
  640. }
  641. return iRet;
  642. }
  643. bool bRet = RvcDeleteFile(videofilename);
  644. if(!bRet) {
  645. #ifdef RVC_OS_WIN
  646. LogWarn(Severity_Middle, Error_Debug, LOG_EVT_RECORDER_DELETE_FAILED, CSimpleStringA::Format("Error Code %lu while delete %s, delete out temp file[%s]!", GetLastError(), videofilename, strOutFile).GetData());
  647. #else
  648. LogWarn(Severity_Middle, Error_Debug, LOG_EVT_RECORDER_DELETE_FAILED, CSimpleStringA::Format("%s(%d) while delete %s, delete out temp file[%s]!", strerror(errno), errno, videofilename, strOutFile).GetData());
  649. #endif // RVC_OS_WIN
  650. if (!RvcDeleteFile(strOutFile)){
  651. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("DeleteFile file %s failed!", strOutFile);
  652. }
  653. return iRet;
  654. }
  655. else{
  656. if (rvcMoveFile(strOutFile, videofilename)){
  657. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("after encryption rename %s to %s Success!",strOutFile, videofilename);
  658. iRet = 0;
  659. }
  660. else{
  661. #ifdef RVC_OS_WIN
  662. LogWarn(Severity_Middle, Error_Debug, LOG_EVT_RECORDER_RENAME_FAILED, CSimpleStringA::Format("Error Code %lu while rename %s.", GetLastError(), strOutFile).GetData());
  663. #else
  664. LogWarn(Severity_Middle, Error_Debug, LOG_EVT_RECORDER_RENAME_FAILED, CSimpleStringA::Format("%s(%d) while rename %s.", strerror(errno), errno, strOutFile).GetData());
  665. #endif // RVC_OS_WIN
  666. }
  667. }
  668. #if 0
  669. char strdecFile[MAX_PATH] = { 0 };
  670. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("begin decrypt file %s.", videofilename);
  671. iresult = decryption_file(strdecFile, MAX_PATH, videofilename, &cb, eVerB);
  672. if (0 == iresult) {
  673. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("decrypt file %s -> %s success!", videofilename, strdecFile);
  674. }
  675. else {
  676. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("decrypt file %s -> %s failed!", videofilename, strdecFile);
  677. }
  678. #endif
  679. return iRet;
  680. }
  681. int CRecorderEntity::HandleSaveVideoRecord(const char* videofilename)
  682. {
  683. int iRet = -1;
  684. if (NULL == videofilename){
  685. return iRet;
  686. }
  687. char strSession[RVC_MAX_VIDEO_NAME_LEN] = {0};
  688. int iSeriesNum = -1;
  689. char strFormat[RVC_MAX_VIDEO_NAME_LEN] = {0};
  690. if (-1 == GetRecordVideoInfo(videofilename, strSession, RVC_MAX_VIDEO_NAME_LEN, &iSeriesNum, strFormat, RVC_MAX_VIDEO_NAME_LEN)){
  691. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[%s] get record video info failed.", videofilename);
  692. return iRet;
  693. }
  694. CSimpleStringA srcfile = CSimpleStringA::Format("%s%s_%d.%s", m_TempDir.GetData(), strSession, iSeriesNum, strFormat);
  695. CSimpleStringA dstfile = CSimpleStringA::Format("%s%s_%d.%s", m_RecordSaveDir.GetData(), strSession, iSeriesNum, strFormat);
  696. if (ExistsFile(srcfile.GetData())) {
  697. bool bRet = rvcMoveFile(srcfile.GetData(), dstfile.GetData());
  698. if (!bRet) {
  699. #ifdef RVC_OS_WIN
  700. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("Error Code %u while move %s ", GetLastError(), srcfile.GetData()));
  701. #else
  702. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("%s(%d) while move %s ", strerror(errno), errno, srcfile.GetData()));
  703. #endif // RVC_OS_WIN
  704. }
  705. else {
  706. AddToVideoRecordList(dstfile.GetData());
  707. }
  708. }
  709. iRet = 0;
  710. return iRet;
  711. }
  712. int CRecorderEntity::GetRecordVideoInfo(const char* videofilename, char* strSession, size_t uSessionLen, int* iSeriesNum, char* strFormat, size_t uFormatLen)
  713. {
  714. int iRet = -1;
  715. char strFileName[RVC_MAX_VIDEO_NAME_LEN] = {0};
  716. size_t uLen = strlen(videofilename);
  717. if (uLen <= RVC_MAX_VIDEO_NAME_LEN){
  718. const char *pIndex = strrchr(videofilename, SPLIT_SLASH);
  719. if (pIndex){
  720. snprintf(strFileName, RVC_MAX_VIDEO_NAME_LEN, "%s", pIndex + 1);
  721. }
  722. }
  723. else{
  724. return iRet;
  725. }
  726. int ioffset = 0;
  727. if (0 == memcmp(strFileName, RVC_TRANSATCION_RECORD_SUFFIX, strlen(RVC_TRANSATCION_RECORD_SUFFIX))) {
  728. ioffset = strlen(RVC_TRANSATCION_RECORD_SUFFIX);
  729. }
  730. char* pNum = strstr(strFileName+ioffset, "_");
  731. if (pNum){
  732. *pNum = 0;
  733. strcpy(strSession, strFileName);
  734. pNum++;
  735. }
  736. else{
  737. return iRet;
  738. }
  739. char* pend = strstr(pNum, "_end");
  740. if (pend){
  741. *pend = 0;
  742. *iSeriesNum = atoi(pNum);
  743. pNum = pend + 1;
  744. }
  745. char* pFormat = strstr(pNum, ".");
  746. if (pFormat){
  747. *pFormat = 0;
  748. pFormat++;
  749. strcpy(strFormat, pFormat);
  750. }
  751. else{
  752. return iRet;
  753. }
  754. if (NULL == pend){
  755. *iSeriesNum = atoi(pNum);
  756. }
  757. iRet = 0;
  758. return iRet;
  759. }
  760. int CRecorderEntity::SaveExceptionRecordVideos()
  761. {
  762. int iRet = -1;
  763. #ifdef RVC_OS_WIN
  764. char srcFilePath[MAX_PATH]={0};
  765. WIN32_FIND_DATA FindFileData;
  766. HANDLE hFind;
  767. bool fFinished = false;
  768. char strVideoFormat[MAX_PATH] = { 0 };
  769. snprintf(strVideoFormat, MAX_PATH, "%s", RECORD_MP4_SUFFIX);
  770. snprintf(srcFilePath, MAX_PATH, "%s*.%s", m_TempDir.GetData(), strVideoFormat);
  771. hFind = FindFirstFile(srcFilePath, &FindFileData);
  772. if (INVALID_HANDLE_VALUE != hFind)
  773. {
  774. while (!fFinished){
  775. if (FILE_ATTRIBUTE_DIRECTORY & FindFileData.dwFileAttributes){
  776. goto on_next;
  777. }
  778. if (0 == memcmp(FindFileData.cFileName, RVC_TRANSATCION_RECORD_SUFFIX, strlen(RVC_TRANSATCION_RECORD_SUFFIX)) ||
  779. 0 == memcmp(FindFileData.cFileName, RVC_ENCRYPT_TRANSATCION_RECORD_SUFFIX, strlen(RVC_ENCRYPT_TRANSATCION_RECORD_SUFFIX))){
  780. CSimpleStringA srcfile = CSimpleStringA::Format("%s%s",m_TempDir.GetData(), FindFileData.cFileName);
  781. if (m_bEncFlag){
  782. filecryption_callback_t cb = {0};
  783. cb.dbg = &rvcDbg;
  784. if (false == is_file_encrypted(srcfile.GetData(), &cb)){
  785. HandleEncryptVideoRecord(srcfile.GetData());
  786. }
  787. else{
  788. char* pIndex = NULL;
  789. if (pIndex = strstr(FindFileData.cFileName, RVC_FILEENC_STR)){
  790. char strname[MAX_PATH] = {0};
  791. memcpy(strname, pIndex+strlen(RVC_FILEENC_STR), strlen(pIndex+strlen(RVC_FILEENC_STR)));
  792. CSimpleStringA tempsrcfile = CSimpleStringA::Format("%s%s",m_TempDir.GetData(), strname);
  793. if (!rename(srcfile.GetData(),tempsrcfile.GetData())){
  794. srcfile = tempsrcfile;
  795. memset(FindFileData.cFileName, 0, MAX_PATH);
  796. memcpy(FindFileData.cFileName, strname, strlen(strname));
  797. }
  798. else{
  799. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_RENAME_FAILED, CSimpleStringA::Format("Error Code %lu while rename %s.", GetLastError(), srcfile.GetData()).GetData());
  800. }
  801. }
  802. }
  803. }
  804. CSimpleStringA dstfile = CSimpleStringA::Format("%s%s",m_RecordSaveDir.GetData(), FindFileData.cFileName);
  805. bool bRet = rvcMoveFile(srcfile.GetData(), dstfile.GetData());
  806. if(!bRet) {
  807. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("Error Code %u while move %s -> %s", GetLastError(), srcfile.GetData(), dstfile.GetData()).GetData());
  808. }
  809. else{
  810. AddToVideoRecordList(dstfile.GetData());
  811. iRet = 0;
  812. }
  813. }
  814. on_next:
  815. if (!FindNextFile(hFind, &FindFileData)){
  816. if (GetLastError() == ERROR_NO_MORE_FILES){
  817. fFinished = true;
  818. }
  819. else{
  820. break;
  821. }
  822. }
  823. }
  824. FindClose(hFind);
  825. }
  826. #else
  827. struct dirent* ptr;
  828. DIR* dir = opendir(m_TempDir.GetData());
  829. while ((ptr = readdir(dir)) != NULL)
  830. {
  831. if (ptr->d_type & DT_DIR) {
  832. continue;
  833. }
  834. if (0 == memcmp(ptr->d_name, RVC_TRANSATCION_RECORD_SUFFIX, strlen(RVC_TRANSATCION_RECORD_SUFFIX)) ||
  835. 0 == memcmp(ptr->d_name, RVC_ENCRYPT_TRANSATCION_RECORD_SUFFIX, strlen(RVC_ENCRYPT_TRANSATCION_RECORD_SUFFIX))) {
  836. CSimpleStringA srcfile = CSimpleStringA::Format("%s%s", m_TempDir.GetData(), ptr->d_name);
  837. if (m_bEncFlag) {
  838. filecryption_callback_t cb = { 0 };
  839. cb.dbg = &rvcDbg;
  840. if (false == is_file_encrypted(srcfile.GetData(), &cb)) {
  841. HandleEncryptVideoRecord(srcfile.GetData());
  842. }
  843. else {
  844. char* pIndex = NULL;
  845. if (pIndex = strstr(ptr->d_name, RVC_FILEENC_STR)) {
  846. char strname[MAX_PATH] = { 0 };
  847. memcpy(strname, pIndex + strlen(RVC_FILEENC_STR), strlen(pIndex + strlen(RVC_FILEENC_STR)));
  848. CSimpleStringA tempsrcfile = CSimpleStringA::Format("%s%s", m_TempDir.GetData(), strname);
  849. if (rvcMoveFile(srcfile.GetData(), tempsrcfile.GetData())) {
  850. srcfile = tempsrcfile;
  851. memset(ptr->d_name, 0, MAX_PATH);
  852. memcpy(ptr->d_name, strname, strlen(strname));
  853. }
  854. else {
  855. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_RENAME_FAILED, CSimpleStringA::Format("%s(%d) while rename %s.", strerror(errno), errno, srcfile.GetData()).GetData());
  856. }
  857. }
  858. }
  859. }
  860. CSimpleStringA dstfile = CSimpleStringA::Format("%s%s", m_RecordSaveDir.GetData(), ptr->d_name);
  861. bool bRet = rvcMoveFile(srcfile.GetData(), dstfile.GetData());
  862. if (!bRet) {
  863. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("Error Code %u while move %s -> %s", GetLastError(), srcfile.GetData(), dstfile.GetData()).GetData());
  864. }
  865. else {
  866. AddToVideoRecordList(dstfile.GetData());
  867. iRet = 0;
  868. }
  869. }
  870. }
  871. closedir(dir);
  872. #endif // RVC_OS_WIN
  873. return iRet;
  874. }
  875. SP_BEGIN_ENTITY_MAP()
  876. SP_ENTITY(CRecorderEntity)
  877. SP_END_ENTITY_MAP()