mod_recorder.cpp 32 KB

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