mod_recorder.cpp 32 KB

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