Ver código fonte

Z991239-5263 #comment 优化mod_recorder实体跨平台实现方式

80274480 1 ano atrás
pai
commit
6d36053dbd

+ 1 - 1
Module/mod_recorder/CMakeLists.txt

@@ -2,7 +2,7 @@
 define_module("recorder")
 
 set(${MODULE_PREFIX}_SRCS
-	${CMAKE_CURRENT_SOURCE_DIR}/${MODULE_PLAFORM_SUBDIR}/mod_recorder.cpp
+	${CMAKE_CURRENT_SOURCE_DIR}/mod_recorder.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/recordinfo.cpp
 )
 

+ 132 - 174
Module/mod_recorder/unix/mod_recorder.cpp → Module/mod_recorder/mod_recorder.cpp

@@ -1,43 +1,89 @@
 #include "mod_recorder.h"
 
-#include "fileutil.h"
-#include "Event.h"
-#include "array.h"
-#include <memutil.h>
-#include <algorithm>
+#ifdef RVC_OS_WIN
+#include "stdafx.h"
+#include "filecryption.h"
+#else
 #include <sys/stat.h>
+#endif // RVC_OS_WIN
+#include "Event.h"
 #include "y2k_time.h"
+#include <string.h>
 
 #include "mod_customeraware/Event.h"
 #include "mod_facetracking/sysvar.h"
 #include "mod_interactivecontrol/Event.h"
 
-#include <assert.h>
-
 using namespace Recorder;
 
-
 #ifndef RVC_MAX_VIDEO_NAME_LEN
 #define RVC_MAX_VIDEO_NAME_LEN 256
 #endif
+
+#ifndef RVC_FILEENC_STR
+#define RVC_FILEENC_STR "enc_"
+#endif
+
+#ifndef MAX_LOGFILE_SIZE
+#define MAX_LOGFILE_SIZE 20*1024*1024
+#endif
+
 #ifndef MAX_LOG_LEN
 #define MAX_LOG_LEN 512
 #endif
 
-
 #ifndef RVC_TRANSATCION_RECORD_SUFFIX
 #define RVC_TRANSATCION_RECORD_SUFFIX "B_"
 #endif // !RVC_TRANSATCION_RECORD_SUFFIX
 
+static struct {
+	DeviceTypeEnum device_type;
+	int type_hex;
+} g_device_value[] = {
+	{eMobilePadType, 0x0001},
+	{ePadtype, 0x0010},
+	{eDesk1SType, 0x0100},
+	{eDesk2SType, 0x0100},
+	{eDesk2SIntegratedType, 0x0100},
+	{eStand2sType, 0x1000}
+};
+
+static int GetDeviceTypeValue(DeviceTypeEnum eType)
+{
+	int iRet = 0;
+	for (int i = 0; i < sizeof(g_device_value)/sizeof(g_device_value[0]); i++){
+		if (g_device_value[i].device_type == eType) {
+			iRet = g_device_value[i].type_hex;
+			break;
+		}
+	}
+
+	return iRet;
+}
 
-static unsigned long GetFileSize(const char* filename)
+static unsigned long GetFileSize(const char* pfilename)
 {
+#ifdef RVC_OS_WIN
+	unsigned long usize = 0;
+	if (NULL == pfilename) {
+		return usize;
+	}
+
+	FILE* pFile = fopen(pfilename, "rb");
+	if (pFile) {
+		fseek(pFile, 0, SEEK_END);
+		usize = ftell(pFile);
+		fclose(pFile);
+	}
+
+	return usize;
+#else
 	struct stat statbuf;
-	stat(filename, &statbuf);
+	stat(pfilename, &statbuf);
 	return statbuf.st_size;
+#endif
 }
 
-
 static const char* GetFileName(const char* pfilename)
 {
 	if (NULL == pfilename) {
@@ -47,13 +93,49 @@ static const char* GetFileName(const char* pfilename)
 	return strstr(pfilename, RVC_TRANSATCION_RECORD_SUFFIX);
 }
 
-
 static void LogVideoSizeInfo(const char* pszMessage)
 {
 	unsigned long ufilesize = GetFileSize(pszMessage);
 	LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_VIDEO_SIZE, CSimpleStringA::Format("%s file size is %u byte.", pszMessage, ufilesize).GetData());
 }
 
+void rvcDbg(const char* fmt, ...)
+{
+	va_list arg;
+	va_start(arg, fmt);
+
+	int n = _vscprintf(fmt, arg);
+	if (n >= MAX_LOG_LEN) {
+		char* buf = (char*)malloc((size_t)(n + 1));
+		vsnprintf(buf, n + 1, fmt, arg);
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
+		free(buf);
+	}
+	else{
+		char strlog[MAX_LOG_LEN] = {0};
+		vsnprintf(strlog, MAX_LOG_LEN, fmt, arg);
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
+	}
+	va_end(arg);
+}
+
+
+static bool rvcMoveFile(const char* strSrcFile, const char* strDstFile)
+{
+	bool bRet = false;
+	if (NULL == strSrcFile || NULL == strDstFile) {
+		return bRet;
+	}
+#ifdef RVC_OS_WIN
+	bRet = MoveFile(strSrcFile, strDstFile);
+#else
+	if (0 == rename(strSrcFile, strDstFile)) {
+		bRet = true;
+	}
+#endif // RVC_OS_WIN
+	return bRet;
+}
+
 
 void RecordServiceSession::Handle_StartTransactionRecord(SpReqAnsContext<RecorderSerVice_StartTransactionRecord_Req, RecorderSerVice_StartTransactionRecord_Ans>::Pointer ctx)
 {
@@ -117,7 +199,7 @@ ErrorCodeEnum CRecorderEntity::__OnStart(ErrorCodeEnum preOperationError)
 	GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_RECORDER_SECTION_FINISHED, NULL, false);
 	GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_RECORDER_WHOLE_FINISHED, NULL, false);
 	GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_START_BUSINESSRECORD_FAILED, NULL, false);
-
+	
 	GetFunction()->RegistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA,this);
 	GetFunction()->RegistSysVarEvent(SYSVAR_CAMERASTATE,this);
 	CSimpleStringA strValue;
@@ -139,11 +221,6 @@ ErrorCodeEnum CRecorderEntity::__OnStart(ErrorCodeEnum preOperationError)
 		m_iActiveCamera = CAMERA_TYPE_ENV;
 	}
 
-	Error = GetFunction()->RegistSysVarEvent("SessionID", this);
-	if (Error != Error_Succeed) {
-		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("register sysvar %s failed!", "SessionID");
-	}
-
 	Error = GetFunction()->GetPath("Temp", m_TempDir);
 	if (Error != Error_Succeed) {
 		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get global record temp path failed!");
@@ -164,7 +241,6 @@ ErrorCodeEnum CRecorderEntity::__OnStart(ErrorCodeEnum preOperationError)
 	return Error;
 }
 
-
 void CRecorderEntity::OnStarted()
 {
 	CSystemStaticInfo si;
@@ -222,15 +298,12 @@ ErrorCodeEnum CRecorderEntity::__OnClose(ErrorCodeEnum preOperationError)
 
 	GetFunction()->UnregistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA);
 	GetFunction()->UnregistSysVarEvent(SYSVAR_CAMERASTATE);
-
 	StopRecord();
 
 	return Error_Succeed;
 }
 
 
-
-
 CServerSessionBase* CRecorderEntity::OnNewSession(const char* pszRemoteEntityName, const char* pszClass)
 {
 	return new RecordServiceSession(this);
@@ -316,10 +389,6 @@ ErrorCodeEnum CRecorderEntity::LoadEntityConfig()
 	}
 #endif // RVC_OS_WIN
 
-	if (1 == iRecordMode) {
-		m_iRecordMode = 1;
-	}
-
 	if (strHttpServerAddr.GetLength() > 0) {
 		m_strHttpServerAddr = strHttpServerAddr;
 	}
@@ -337,8 +406,6 @@ ErrorCodeEnum CRecorderEntity::LoadEntityConfig()
 	return Error;
 }
 
-
-
 ErrorCodeEnum CRecorderEntity::PostVideoRecordInfos()
 {
 	ErrorCodeEnum Error = Error_Failed;
@@ -346,15 +413,12 @@ ErrorCodeEnum CRecorderEntity::PostVideoRecordInfos()
 	char strtimenow[MAX_PATH] = { 0 };
 	y2k_time_t nowtime = y2k_time_now();
 	y2k_to_string(nowtime, strtimenow, MAX_PATH);
-
 	video_record_info_t video_params;
 	video_params.strServerURL = m_strHttpServerAddr;
 	video_params.strAPI = m_strHttpServerAPI;
 	video_params.strAppVersion = m_strAppVersion;
 	video_params.strRecordEndTime = strtimenow;
-
 	video_params.strTerminalNo = m_strTerminalId;
-
 	video_params.iBusinessStatus = (int)m_eBusinessStatus;
 	if (eFailed == m_eBusinessStatus) {
 		if (m_vRecordList.size() > 0) {
@@ -412,6 +476,8 @@ ErrorCodeEnum CRecorderEntity::HandleExceptionRecordVideos()
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("File {%s} is not exist.", strFilePath.GetData());
 		}
 	}
+
+	return Error;
 }
 
 
@@ -474,7 +540,6 @@ int CRecorderEntity:: GetCameraState()
 
 void CRecorderEntity::OnASectionFinished(const char *pszMessage, int iSerialNum, bool bfinished)
 {
-	m_iSeriesNum = iSerialNum;
 	if (false == bfinished){
 		LogEvent(Severity_Middle, LOG_EVT_RECORDER_SECTION_FINISHED, pszMessage);
 	}
@@ -503,9 +568,7 @@ void CRecorderEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,
 
 	case LOG_EVT_RECORDER_SECTION_FINISHED:
 		{
-			if (m_iRecordMode) {
-				LogVideoSizeInfo(pszMessage);
-			}
+			LogVideoSizeInfo(pszMessage);
 			if (m_bEncFlag){
 				HandleEncryptVideoRecord(pszMessage);
 			}
@@ -515,9 +578,7 @@ void CRecorderEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,
 
 	case LOG_EVT_RECORDER_WHOLE_FINISHED:
 		{
-			if (m_iRecordMode) {
-				LogVideoSizeInfo(pszMessage);
-			}
+			LogVideoSizeInfo(pszMessage);
 			if (m_bEncFlag){
 				HandleEncryptVideoRecord(pszMessage);
 			}
@@ -669,31 +730,31 @@ int CRecorderEntity::HandleFinishedVideoRecord(const char* videofilename)
 		return iRet;
 	}
 
-	if (iSeriesNum >= 1 || m_iRecordMode){
-		CSimpleStringA srcfile = CSimpleStringA::Format("%s%s_%d_end.%s",(LPCTSTR)m_TempDir,(LPCTSTR)strSession, iSeriesNum, strFormat);
-		CSimpleStringA dstfile = CSimpleStringA::Format("%s%s_%d_end.%s",(LPCTSTR)m_RecordSaveDir,(LPCTSTR)strSession, iSeriesNum, strFormat);
-		BOOL bRet = FALSE;
-		if (ExistsFile(srcfile.GetData())){
-			if(rename(srcfile.GetData(), dstfile.GetData())) {
-				LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("Error Code %u while move %s ", GetLastError(), srcfile.GetData()).GetData());
-			}
-			else {
-				AddToVideoRecordList(dstfile.GetData());
-			}
+	CSimpleStringA srcfile = CSimpleStringA::Format("%s%s_%d_end.%s",(LPCTSTR)m_TempDir,(LPCTSTR)strSession, iSeriesNum, strFormat);
+	CSimpleStringA dstfile = CSimpleStringA::Format("%s%s_%d_end.%s",(LPCTSTR)m_RecordSaveDir,(LPCTSTR)strSession, iSeriesNum, strFormat);
+	bool bRet = false;
+	if (ExistsFile(srcfile.GetData())){
+		bRet = rvcMoveFile(srcfile.GetData(), dstfile.GetData());
+		if(!bRet) {
+			LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("Error Code %u while move %s ", GetLastError(), srcfile.GetData()).GetData());
 		}
-
-		srcfile = CSimpleStringA::Format("%s%s_%d.%s",(LPCTSTR)m_TempDir,(LPCTSTR)strSession, iSeriesNum-1, strFormat);
-		dstfile = CSimpleStringA::Format("%s%s_%d.%s",(LPCTSTR)m_RecordSaveDir,(LPCTSTR)strSession, iSeriesNum-1, strFormat);
-		if (ExistsFile(srcfile.GetData())){
-			if(rename(srcfile.GetData(), dstfile.GetData())) {
-				LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("Error Code %u while move %s ", GetLastError(), srcfile.GetData()).GetData());
-			}
-			else {
-				AddToVideoRecordList(dstfile.GetData());
-			}
+		else {
+			AddToVideoRecordList(dstfile.GetData());
 		}
 	}
 
+	srcfile = CSimpleStringA::Format("%s%s_%d.%s",(LPCTSTR)m_TempDir,(LPCTSTR)strSession, iSeriesNum-1, strFormat);
+	dstfile = CSimpleStringA::Format("%s%s_%d.%s",(LPCTSTR)m_RecordSaveDir,(LPCTSTR)strSession, iSeriesNum-1, strFormat);
+	if (ExistsFile(srcfile.GetData())){
+		bRet = rvcMoveFile(srcfile.GetData(), dstfile.GetData());
+		if(!bRet) {
+			LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("Error Code %u while move %s ", GetLastError(), srcfile.GetData()).GetData());
+		}
+		else {
+			AddToVideoRecordList(dstfile.GetData());
+		}
+	}
+	
 	iRet =  0;
 
 	return iRet;
@@ -761,64 +822,18 @@ int CRecorderEntity::HandleSaveVideoRecord(const char* videofilename)
 		return iRet;
 	}
 
-	if (1 == m_iRecordMode) {
-		CSimpleStringA srcfile = CSimpleStringA::Format("%s%s_%d.%s", (LPCTSTR)m_TempDir, (LPCTSTR)strSession, iSeriesNum, strFormat);
-		CSimpleStringA dstfile = CSimpleStringA::Format("%s%s_%d.%s", (LPCTSTR)m_RecordSaveDir, (LPCTSTR)strSession, iSeriesNum, strFormat);
-		if (ExistsFile(srcfile.GetData())) {
-			if (rename(srcfile.GetData(), dstfile.GetData())) {
-				LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("Error Code %u while move %s ", GetLastError(), srcfile.GetData()).GetData());
-			}
-			else {
-				AddToVideoRecordList(dstfile.GetData());
-			}
-		}
-	}
-	else {
-		if (iSeriesNum >= 1) {
-			CSimpleStringA srcfile = CSimpleStringA::Format("%s%s_%d.%s", (LPCTSTR)m_TempDir, (LPCTSTR)strSession, iSeriesNum - 1, strFormat);
-			CSimpleStringA dstfile = CSimpleStringA::Format("%s%s_%d.%s", (LPCTSTR)m_RecordSaveDir, (LPCTSTR)strSession, iSeriesNum - 1, strFormat);
-			if (ExistsFile(srcfile.GetData())) {
-				if (rename(srcfile.GetData(), dstfile.GetData())) {
-					LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("Error Code %u while move %s ", GetLastError(), srcfile.GetData()).GetData());
-				}
-				m_iMovedSeriesNum = iSeriesNum - 1;
-			}
+	CSimpleStringA srcfile = CSimpleStringA::Format("%s%s_%d.%s", (LPCTSTR)m_TempDir, (LPCTSTR)strSession, iSeriesNum, strFormat);
+	CSimpleStringA dstfile = CSimpleStringA::Format("%s%s_%d.%s", (LPCTSTR)m_RecordSaveDir, (LPCTSTR)strSession, iSeriesNum, strFormat);
+	if (ExistsFile(srcfile.GetData())) {
+		bool bRet = rvcMoveFile(srcfile.GetData(), dstfile.GetData());
+		if (!bRet) {
+			LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("Error Code %u while move %s ", GetLastError(), srcfile.GetData()));
 		}
 		else {
-			if (0 == m_iMovedSeriesNum) {
-				if (false == m_bMoveFlag) {
-					m_bMoveFlag = true;
-				}
-				else {
-					CSimpleStringA srcfile = CSimpleStringA::Format("%s%s_%d_end.%s", (LPCTSTR)m_TempDir, (LPCTSTR)m_LastSaveSessionId, 0, strFormat);
-					if (ExistsFile(srcfile.GetData())) {
-						CSimpleStringA dstfile = CSimpleStringA::Format("%s%s_%d_end.%s", (LPCTSTR)m_RecordSaveDir, (LPCTSTR)m_LastSaveSessionId, 0, strFormat);
-						if (rename(srcfile.GetData(), dstfile.GetData())) {
-							LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("Error Code %u while move %s ", GetLastError(), srcfile.GetData()).GetData());
-						}
-						else {
-							AddToVideoRecordList(dstfile.GetData());
-						}
-					}
-				}
-			}
-			else {
-				CSimpleStringA srcfile = CSimpleStringA::Format("%s%s_%d_end.%s", (LPCTSTR)m_TempDir, (LPCTSTR)m_LastSaveSessionId, m_iMovedSeriesNum + 1, strFormat);
-				if (ExistsFile(srcfile.GetData())) {
-					CSimpleStringA dstfile = CSimpleStringA::Format("%s%s_%d_end.%s", (LPCTSTR)m_RecordSaveDir, (LPCTSTR)m_LastSaveSessionId, m_iMovedSeriesNum + 1, strFormat);
-					if (rename(srcfile.GetData(), dstfile.GetData())) {
-						LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("Error Code %u while move %s ", GetLastError(), srcfile.GetData()).GetData());
-					}
-					else {
-						AddToVideoRecordList(dstfile.GetData());
-					}
-				}
-				m_iMovedSeriesNum = 0;
-			}
-			m_LastSaveSessionId = strSession;
+			AddToVideoRecordList(dstfile.GetData());
 		}
 	}
-
+	
 	iRet =  0;
 
 	return iRet;
@@ -893,13 +908,13 @@ int CRecorderEntity::SaveExceptionRecordVideos()
 	bool fFinished = false;
 	char strVideoFormat[MAX_PATH] = { 0 };
 	if (eMP4 == m_eRecordType) {
-		sprintf_s(strVideoFormat, MAX_PATH, "%s", RECORD_MP4_SUFFIX);
+		_snprintf(strVideoFormat, MAX_PATH, "%s", RECORD_MP4_SUFFIX);
 	}
 	else {
-		sprintf_s(strVideoFormat, MAX_PATH, "%s", RECORD_WMV_SUFFIX);                                                                                                                                                                                                                                                         
+		_snprintf(strVideoFormat, MAX_PATH, "%s", RECORD_WMV_SUFFIX);                                                                                                                                                                                                                                                         
 	}
 
-	sprintf_s(srcFilePath, MAX_PATH, "%s*.%s", m_TempDir.GetData(), strVideoFormat);
+	_snprintf(srcFilePath, MAX_PATH, "%s*.%s", m_TempDir.GetData(), strVideoFormat);
 
 	hFind = FindFirstFile(srcFilePath, &FindFileData);
 
@@ -965,63 +980,6 @@ on_next:
 }
 
 
-int CRecorderEntity::DeleteExceptionLogFiles()
-{
-	CSimpleStringA strDbgPath;
-#ifdef RVC_OS_WIN
-
-	WIN32_FIND_DATA FindFileData;
-	HANDLE hFind;
-	bool fFinished = false;
-
-	auto pFunc = GetFunction();
-	pFunc->GetPath("Dbg", strDbgPath);
-
-	char logPath[MAX_PATH] = "";
-	sprintf(logPath, "%s\\%s", strDbgPath.GetData(), MOD_RECORDER_NAME);
-
-	char srcFilePath[MAX_PATH]={0};
-	sprintf_s(srcFilePath, MAX_PATH, "%s\\*.*", logPath);
-
-	hFind = FindFirstFile(srcFilePath, &FindFileData);
-
-	if (INVALID_HANDLE_VALUE != hFind)
-	{
-		while (!fFinished)
-		{
-			if (FILE_ATTRIBUTE_DIRECTORY & FindFileData.dwFileAttributes)
-			{
-				goto on_next;
-			}
-
-			__int64 nSize = ((__int64)FindFileData.nFileSizeHigh << 32) + FindFileData.nFileSizeLow;
-			if (nSize > MAX_LOGFILE_SIZE)
-			{
-				CSimpleStringA dstfile = CSimpleStringA::Format("%s\\%s",logPath, FindFileData.cFileName);
-				BOOL bRet = DeleteFile(dstfile.GetData());
-				if(bRet) {
-					LogWarn(Severity_Low, Error_Debug, LOG_EVT_DELETE_BIG_LOGFILE, dstfile.GetData());
-				}
-			}
-on_next:
-			if (!FindNextFile(hFind, &FindFileData)){
-				if (GetLastError() == ERROR_NO_MORE_FILES){
-					fFinished = true;
-				}
-				else{
-					break;
-				}
-			}
-		}
-		FindClose(hFind);
-	}
-
-#endif // RVC_OS_WIN
-
-	return 0;
-}
-
-
 SP_BEGIN_ENTITY_MAP()
 	SP_ENTITY(CRecorderEntity)
 SP_END_ENTITY_MAP()

+ 3 - 16
Module/mod_recorder/mod_recorder.h

@@ -4,15 +4,11 @@
 #include "SpIni.h"
 #include "libvideorecord.h"
 #include "EventCode.h"
-#if defined(RVC_OS_WIN)
 #include "fileutil.h"
 #include "array.h"
 #include <memutil.h>
-#include "filecryption.h"
 #include <algorithm>
 #include <assert.h>
-#endif //RVC_OS_WIN
-#include "libvideorecord.h"
 #include "rvc_media_common.h"
 
 #include "Recorder_client_g.h"
@@ -21,11 +17,12 @@
 
 #include "recordinfo.h"
 
+
 namespace Recorder {
 	class CRecorderEntity : public CEntityBase, public CHostApi, public ILogListener, public ISysVarListener
 	{
 	public:
-		CRecorderEntity() : m_bStarted(false), m_pRecorder(NULL), m_LastSaveSessionId("N"), m_iSeriesNum(0), m_iMovedSeriesNum(0), m_bMoveFlag(false), m_bEncFlag(false), m_eRecordType(eWMV), m_iRecordMode(0){
+		CRecorderEntity() : m_bStarted(false), m_pRecorder(NULL), m_bEncFlag(false), m_eRecordType(eWMV){
 			m_strHttpServerAPI = RVC_UPLOAD_VIDEORECORDING_HTTP_API;
 			m_iHttpTimeOut = RVC_HTTPTIMEOUT;
 			m_strHttpServerAddr = RVC_UPLOAD_VIDEORECORDING_HTTP_ADDR;
@@ -33,7 +30,6 @@ namespace Recorder {
 			m_strTerminalId = NULL;
 			memset(m_strRecordName, 0, MAX_PATH);
 			m_eBusinessStatus = eInterrupt;
-			m_bPostVideoInfoOn = false;
 		}
 
 		virtual ~CRecorderEntity() {}
@@ -47,11 +43,9 @@ namespace Recorder {
 
 		ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError);
 		ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError);
-#if defined(RVC_OS_WIN)
-#else
+
 		bool InitRecorder();
 		bool ReleaseRecorder();
-#endif //RVC_OS_WIN
 
 		virtual void OnStarted();
 
@@ -83,7 +77,6 @@ namespace Recorder {
 		int HandleFinishedVideoRecord(const char* videofilename);
 		int SaveExceptionRecordVideos();
 		int HandleEncryptVideoRecord(const char* videofilename);
-		int DeleteExceptionLogFiles();
 		ErrorCodeEnum LoadEntityConfig();
 		ErrorCodeEnum PostVideoRecordInfos();
 		ErrorCodeEnum AddToVideoRecordList(const char* videofilename);
@@ -100,14 +93,8 @@ namespace Recorder {
 		CSimpleStringA m_terminalNo;
 		CSimpleStringA m_TempDir;
 		CSimpleStringA m_RecordSaveDir;
-		CSimpleStringA m_LastSaveSessionId;
-		int m_iSeriesNum;
-		int m_iMovedSeriesNum;			//相同session号已移动文件数
-		bool m_bMoveFlag;
 		bool m_bEncFlag;
 		eVideoFormat m_eRecordType;
-		int m_iRecordMode;
-		bool m_bPostVideoInfoOn;
 
 		CSimpleStringA m_strHttpServerAddr;
 		CSimpleStringA m_strHttpServerAPI;

+ 0 - 1103
Module/mod_recorder/win/mod_recorder.cpp

@@ -1,1103 +0,0 @@
-#include "stdafx.h"
-#include "mod_recorder.h"
-#include <string.h>
-#include <Windows.h>
-#include <stdio.h>
-#include <io.h>
-#include "fileutil.h"
-#include "Event.h"
-#include "y2k_time.h"
-
-
-#include "..\\mod_customeraware\\Event.h"
-#include "..\\mod_facetracking\\sysvar.h"
-#include "../mod_interactivecontrol/Event.h"
-
-using namespace Recorder;
-
-
-#ifndef RVC_MAX_VIDEO_NAME_LEN
-#define RVC_MAX_VIDEO_NAME_LEN 256
-#endif
-
-#ifndef RVC_FILEENC_STR
-#define RVC_FILEENC_STR "enc_"
-#endif
-
-#ifndef MOD_RECORDER_NAME
-#define MOD_RECORDER_NAME "mod_recorder"
-#endif
-
-#ifndef MAX_LOGFILE_SIZE
-#define MAX_LOGFILE_SIZE 20*1024*1024
-#endif
-
-
-#ifndef MAX_LOG_LEN
-#define MAX_LOG_LEN 512
-#endif
-
-
-#ifndef RVC_TRANSATCION_RECORD_SUFFIX
-#define RVC_TRANSATCION_RECORD_SUFFIX "B_"
-#endif // !RVC_TRANSATCION_RECORD_SUFFIX
-
-
-static struct {
-	DeviceTypeEnum device_type;
-	int type_hex;
-} g_device_value[] = {
-	{eMobilePadType, 0x0001},
-	{ePadtype, 0x0010},
-	{eDesk1SType, 0x0100},
-	{eDesk2SType, 0x0100},
-	{eDesk2SIntegratedType, 0x0100},
-	{eStand2sType, 0x1000}
-};
-
-
-static int GetDeviceTypeValue(DeviceTypeEnum eType)
-{
-	int iRet = 0;
-	for (int i = 0; i < sizeof(g_device_value)/sizeof(g_device_value[0]); i++){
-		if (g_device_value[i].device_type == eType) {
-			iRet = g_device_value[i].type_hex;
-			break;
-		}
-	}
-
-	return iRet;
-}
-
-
-static unsigned long GetFileSize(const char* pfilename)
-{
-	unsigned long usize = 0;
-	if (NULL == pfilename) {
-		return usize;
-	}
-
-	FILE* pFile = fopen(pfilename, "rb");
-	if (pFile) {
-		fseek(pFile, 0, SEEK_END);
-		usize = ftell(pFile);
-		fclose(pFile);
-	}
-
-	return usize;
-}
-
-
-static const char* GetFileName(const char* pfilename)
-{
-	if (NULL == pfilename) {
-		return NULL;
-	}
-
-	return strstr(pfilename, RVC_TRANSATCION_RECORD_SUFFIX);
-}
-
-
-static void LogVideoSizeInfo(const char* pszMessage)
-{
-	unsigned long ufilesize = GetFileSize(pszMessage);
-	LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_VIDEO_SIZE, CSimpleStringA::Format("%s file size is %u byte.", pszMessage, ufilesize).GetData());
-}
-
-
-void rvcDbg(const char* fmt, ...)
-{
-	va_list arg;
-	va_start(arg, fmt);
-
-	int n = _vscprintf(fmt, arg);
-	if (n >= MAX_LOG_LEN) {
-		char* buf = (char*)malloc((size_t)(n + 1));
-		_vsnprintf(buf, n + 1, fmt, arg);
-		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
-		free(buf);
-	}
-	else{
-		char strlog[MAX_LOG_LEN] = {0};
-		_vsnprintf(strlog, MAX_LOG_LEN, fmt, arg);
-		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
-	}
-	va_end(arg);
-}
-
-
-void RecordServiceSession::Handle_StartTransactionRecord(SpReqAnsContext<RecorderSerVice_StartTransactionRecord_Req, RecorderSerVice_StartTransactionRecord_Ans>::Pointer ctx)
-{
-	DbgToBeidou(ctx->link, __FUNCTION__)();
-	if (m_pEntity->GetStartFlag()) {
-		m_pEntity->StopRecord();
-	}
-
-	m_pEntity->SetRecordSessionID(ctx->Req.VideoName.GetData());
-
-	m_pEntity->StartRecord(CSimpleStringA::Format("%s%s", RVC_TRANSATCION_RECORD_SUFFIX, ctx->Req.VideoName.GetData()).GetData());
-
-	ctx->Answer(Error_Succeed);
-}
-
-void RecordServiceSession::Handle_StopTransactionRecord(SpReqAnsContext<RecorderSerVice_StopTransactionRecord_Req, RecorderSerVice_StopTransactionRecord_Ans>::Pointer ctx)
-{
-	DbgToBeidou(ctx->link, __FUNCTION__)();
-	
-	m_pEntity->StopRecord();
-
-	ctx->Answer(Error_Succeed);
-}
-
-
-void CRecorderEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext) 
-{ 
-	ErrorCodeEnum Error = __OnStart(Error_Succeed);
-	pTransactionContext->SendAnswer(Error);
-}
-
-
-void CRecorderEntity::OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext) 
-{ 
-	ErrorCodeEnum Error = __OnClose(Error_Succeed);
-	pTransactionContext->SendAnswer(Error); 
-}
-
-
-ErrorCodeEnum CRecorderEntity::__OnStart(ErrorCodeEnum preOperationError)
-{	
-	ErrorCodeEnum Error = Error_Succeed;
-	m_eDeviceType = RvcGetDeviceType();
-
-	if (preOperationError != Error_Succeed) {
-		return preOperationError;
-	}
-	
-	m_iActiveCamera = CAMERA_TYPE_ENV;
-	m_iCameraState = 'N';
-	bool bRet = false;
-
-	if (eMobilePadType == m_eDeviceType)
-	{
-		//pad 版增加远端视频队列
-		m_pRecorder = new Clibvideorecord(&bRet, this, REC_COMMON_AUDIO_SHM_QUEUE, 
-			REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE,NULL);
-	} 
-	else { 
-		//  == 2
-		m_pRecorder = new Clibvideorecord(&bRet, this, REC_COMMON_AUDIO_SHM_QUEUE, 
-			REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE,REC_COMMON_VIDEO_OPT_SHM_RTP_QUEUE);
-	}
-
-	int i = 0;
-	m_arrListener.Init(8);
-	GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, EVENT_MOD_BEGIN_RECORD, NULL, false);
-	GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, EVENT_MOD_END_RECORD, NULL, false);
-	GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RETURNMENU, NULL, false);
-	GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, EVENT_MOD_PAUSE_RECORD, NULL, false);
-	GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, EVENT_MOD_CONTINUE_RECORD, NULL, false);
-	GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_RECORDER_SECTION_FINISHED, NULL, false);
-	GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_RECORDER_WHOLE_FINISHED, NULL, false);
-	GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_START_BUSINESSRECORD_FAILED, NULL, false);
-	
-	GetFunction()->RegistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA,this);
-	GetFunction()->RegistSysVarEvent(SYSVAR_CAMERASTATE,this);
-	CSimpleStringA strValue;
-	GetFunction()->GetSysVar(SYSVAR_CAMERASTATE, strValue);
-	m_iCameraState = strValue[0];
-	if (strValue[0] == 'E'){
-		m_iActiveCamera = CAMERA_TYPE_OPT;
-		if (eStand1SPlusType == m_eDeviceType){
-			m_iActiveCamera = CAMERA_TYPE_ERROR;
-		}
-	}
-	else if (strValue[0] == 'O'){
-		m_iActiveCamera = CAMERA_TYPE_ENV;
-	}
-	else if(strValue[0] == 'B'){
-		m_iActiveCamera = CAMERA_TYPE_ERROR;
-	}
-	else if (strValue[0] == 'N'){
-		m_iActiveCamera = CAMERA_TYPE_ENV;
-	}
-		
-	Error = GetFunction()->RegistSysVarEvent("SessionID", this);
-	if (Error != Error_Succeed) {
-		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("register sysvar %s failed!", "SessionID");
-	}
-
-	Error = GetFunction()->GetPath("Temp", m_TempDir);
-	if (Error != Error_Succeed) {
-		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get global record temp path failed!");
-	}
-	
-	if (m_TempDir.GetLength() > 0 && m_TempDir[m_TempDir.GetLength()-1] != '\\') {
-		m_TempDir += "\\";
-	}
-
-	Error = GetFunction()->GetPath("UploadVideo", m_RecordSaveDir);
-	if (Error != Error_Succeed) {
-		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get global record save path failed!");
-	}
-
-	if (m_RecordSaveDir.GetLength() > 0 && m_RecordSaveDir[m_RecordSaveDir.GetLength()-1] != '\\') {
-		m_RecordSaveDir += "\\";
-	}
-
-	return Error;
-}
-
-
-void CRecorderEntity::OnStarted()
-{
-	CSystemStaticInfo si;
-	ErrorCodeEnum Error = GetFunction()->GetSystemStaticInfo(si);
-	if (Error == Error_Succeed) {
-		m_strAppVersion = si.InstallVersion.ToString();
-		m_strTerminalId = si.strTerminalID;
-	}
-
-	LoadEntityConfig();
-	//DeleteExceptionLogFiles();
-	SaveExceptionRecordVideos();
-
-	if (m_vRecordList.size() > 0) {
-		HandleExceptionRecordVideos();
-		if (m_bPostVideoInfoOn) {
-			PostVideoRecordInfos();
-		}
-		else {
-			m_vRecordList.clear();
-		}
-	}
-}
-
-
-ErrorCodeEnum CRecorderEntity::__OnClose(ErrorCodeEnum preOperationError)
-{
-	if (preOperationError != Error_Succeed) {
-		return preOperationError;
-	}
-	
-	for (int i = 0; i < m_arrListener.GetCount(); ++i) {
-		GetFunction()->UnsubscribeLog(m_arrListener[i]);
-	}
-
-	GetFunction()->UnregistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA);
-	GetFunction()->UnregistSysVarEvent(SYSVAR_CAMERASTATE);
-	StopRecord();
-
-	return Error_Succeed;
-}
-
-
-CServerSessionBase* CRecorderEntity::OnNewSession(const char* pszRemoteEntityName, const char* pszClass)
-{
-	return new RecordServiceSession(this);
-}
-
-// CAviHostAPI
-void CRecorderEntity::Debug(record_loglevel elevel, const char *fmt, ...)
-{
-	if (RECORD_LOG_INFO <= elevel) {
-		va_list arg;
-		va_start(arg, fmt);
-
-		int n = _vscprintf(fmt, arg);
-		if (n >= MAX_LOG_LEN) {
-			char* buf = (char*)malloc((size_t)(n + 1));
-			_vsnprintf(buf, n + 1, fmt, arg);
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
-			free(buf);
-		}
-		else{
-			char strlog[MAX_LOG_LEN] = {0};
-			_vsnprintf(strlog, MAX_LOG_LEN, fmt, arg);
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
-		}
-		va_end(arg);
-	}
-}
-
-
-void CRecorderEntity::vDebug(record_loglevel elevel, const char* str, va_list list)
-{
-	if (RECORD_LOG_INFO <= elevel) {
-		int n = _vscprintf(str, list);
-		if (n >= MAX_LOG_LEN) {
-			char* buf = (char*)malloc((size_t)(n + 1));
-			_vsnprintf(buf, n + 1, str, list);
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
-			free(buf);
-		}
-		else {
-			char strlog[MAX_LOG_LEN] = { 0 };
-			_vsnprintf(strlog, MAX_LOG_LEN, str, list);
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
-		}
-	}
-}
-
-
-int CRecorderEntity::GetActiveCamera()
-{
-	return m_iActiveCamera;
-}
-
-
-ErrorCodeEnum CRecorderEntity::LoadEntityConfig()
-{
-	ErrorCodeEnum Error = Error_Succeed;
-
-	int iEncrytion = 0;
-	int iRecordType = 0;
-	int iRecordMode = 0;
-	UINT64 uMtype = 0x0;
-	int iTimeOut = RVC_HTTPTIMEOUT;
-	int iPostOn = 0;
-	CSimpleStringA strHttpServerAddr("");
-	CSmartPointer<IConfigInfo> spConfig;
-	CSmartPointer<IEntityFunction> spFunction = GetFunction();
-	if (spFunction->OpenConfig(Config_CenterSetting, spConfig) == Error_Succeed) {
-		spConfig->ReadConfigValueInt("Recorder", "Encryption", iEncrytion);
-		spConfig->ReadConfigValueHexInt("Recorder", "EncMtype", uMtype);
-		spConfig->ReadConfigValueInt("Recorder", "RecordType", iRecordType);
-		spConfig->ReadConfigValueInt("InteractiveControl", "RecordMode", iRecordMode);
-		spConfig->ReadConfigValue("Recorder", "http_video_record_addr", strHttpServerAddr);
-		spConfig->ReadConfigValueInt("Recorder", "http_timeout", iTimeOut);
-		spConfig->ReadConfigValueInt("Recorder", "post_videoinfo_on", iPostOn);
-	}
-	else {
-		Error = Error_Failed;
-	}
-
-	if (1 == iEncrytion && (uMtype & GetDeviceTypeValue(m_eDeviceType))) {
-		m_bEncFlag = true;
-	}
-
-	if (1 == iRecordMode) {
-		m_iRecordMode = 1;
-	}
-
-	if (strHttpServerAddr.GetLength() > 0) {
-		m_strHttpServerAddr = strHttpServerAddr;
-	}
-
-	if (iPostOn > 0) {
-		m_bPostVideoInfoOn = true;
-	}
-
-	if (eMobilePadType != m_eDeviceType) {
-		if (0 != iRecordType) {
-			m_eRecordType = eMP4;
-		}
-	}
-
-	if (iTimeOut > 0 && iTimeOut < 20 * RVC_HTTPTIMEOUT) {
-		m_iHttpTimeOut = iTimeOut;
-	}
-
-	return Error;
-}
-
-
-ErrorCodeEnum CRecorderEntity::PostVideoRecordInfos()
-{
-	ErrorCodeEnum Error = Error_Failed;
-
-	char strtimenow[MAX_PATH] = { 0 };
-	y2k_time_t nowtime = y2k_time_now();
-	y2k_to_string(nowtime, strtimenow, MAX_PATH);
-	video_record_info_t video_params;
-	video_params.strServerURL = m_strHttpServerAddr;
-	video_params.strAPI = m_strHttpServerAPI;
-	video_params.strAppVersion = m_strAppVersion;
-	video_params.strRecordEndTime = strtimenow;
-	video_params.strTerminalNo = m_strTerminalId;
-	video_params.iBusinessStatus = (int)m_eBusinessStatus;
-	if (eFailed == m_eBusinessStatus) {
-		if (m_vRecordList.size() > 0) {
-			video_params.iBusinessStatus = eInterrupt;
-		}
-	}
-
-	video_params.strRecordID = m_strRecordName;
-	for (vector<record_item_t>::iterator it = m_vRecordList.begin(); it < m_vRecordList.end(); ++it) {
-		video_params.vRecordList.push_back(*it);
-	}
-
-	unsigned int uposttime = 0;
-	CSimpleStringA strErrorMsg("");
-	if (0 == post_video_recordinfo_list(uposttime, strErrorMsg, &video_params, m_iHttpTimeOut, false)) {
-		LogWarn(Severity_Low, Error_Debug, LOG_EVT_POST_RECORDINFO_COST_TIME, CSimpleStringA::Format("post video record infos cost time is %ums.", uposttime).GetData());
-		Error = Error_Succeed;
-	}
-	else {
-		LogWarn(Severity_Middle, Error_Exception, LOG_EVT_POST_RECORDINFO_FAILED, strErrorMsg.GetData());
-	}
-
-	m_vRecordList.clear();
-
-	return Error;
-}
-
-
-ErrorCodeEnum CRecorderEntity::HandleExceptionRecordVideos()
-{
-	ErrorCodeEnum Error = Error_Failed;
-	const char* videofilename = m_vRecordList[0].file_path.c_str();
-	if (NULL == videofilename) {
-		return Error;
-	}
-
-	char strSession[RVC_MAX_VIDEO_NAME_LEN] = { 0 };
-	int iSeriesNum = -1;
-	char strFormat[RVC_MAX_VIDEO_NAME_LEN] = { 0 };
-
-	if (-1 == GetRecordVideoInfo(videofilename, strSession, RVC_MAX_VIDEO_NAME_LEN, &iSeriesNum, strFormat, RVC_MAX_VIDEO_NAME_LEN)) {
-		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[%s] get record video info failed.", videofilename);
-		return Error;
-	}
-
-	SetRecordSessionID(strSession + strlen(RVC_TRANSATCION_RECORD_SUFFIX));
-
-	while (--iSeriesNum >= 0) {
-		CSimpleStringA strFilePath("");
-		strFilePath = CSimpleStringA::Format("%s%s_%d.%s", m_RecordSaveDir.GetData(), strSession, iSeriesNum, strFormat);
-		if (ExistsFile(strFilePath.GetData())) {
-			AddToVideoRecordList(strFilePath.GetData());
-		}
-		else {
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("File {%s} is not exist.", strFilePath.GetData());
-		}
-	}
-}
-
-
-ErrorCodeEnum CRecorderEntity::AddToVideoRecordList(const char* videofilename)
-{
-	ErrorCodeEnum Error = Error_Failed;
-	if (NULL == videofilename) {
-		return Error;
-	}
-
-	record_item_t* item = new record_item_t();
-
-	item->file_path = videofilename;
-
-	item->file_length = (int)GetFileSize(videofilename);
-
-	const char* strfilename = GetFileName(videofilename);
-	if (strfilename) {
-		item->file_name = strfilename;
-	}
-
-	m_vRecordList.push_back(*item);
-
-	Error = Error_Succeed;
-
-	return Error;
-}
-
-
-void CRecorderEntity::OnRecordFailed(eRvcRecordFailedCase eCase, const char *pszMessage, bool bRecordDevFault)
-{
-	m_eBusinessStatus = eFailed;
-	if (!bRecordDevFault){
-		LogEvent(Severity_Middle,LOG_EVT_RECORDFAILED,"0");
-		LogWarn(Severity_Middle, Error_Debug, LOG_EVT_RECORDING_FAILED, CSimpleStringA::Format("{%s} 本地录音录像失败,已停止!", pszMessage ? pszMessage : " ").GetData());
-	}
-	else{
-		LogEvent(Severity_Middle,LOG_EVT_RECORDFAILED,"1");
-		LogWarn(Severity_Middle, Error_Debug, LOG_EVT_RECORDING_FAILED, CSimpleStringA::Format("{%s} 本地录音录像设备故障,尝试恢复中(预计10s内),请稍等", pszMessage ? pszMessage : " ").GetData());
-	}
-}
-
-
-void CRecorderEntity::OnRecordEntityExcption()
-{
-	LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_ENTITY_EXCEPTION, "OnRecordEntityExcption!");
-}
-
-
-void CRecorderEntity::OnRecordFinished()
-{
-
-}
-
-int CRecorderEntity:: GetCameraState()
-{
-	return m_iCameraState;
-}
-
-
-void CRecorderEntity::OnASectionFinished(const char *pszMessage, int iSerialNum, bool bfinished)
-{
-	m_iSeriesNum = iSerialNum;
-	if (false == bfinished){
-		LogEvent(Severity_Middle, LOG_EVT_RECORDER_SECTION_FINISHED, pszMessage);
-	}
-	else{
-		LogEvent(Severity_Middle, LOG_EVT_RECORDER_WHOLE_FINISHED, pszMessage);
-	}
-}
-
-
-void CRecorderEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
-	const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID, 
-	const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext& pLinkInfo)
-{
-	switch (dwUserCode) 
-	{
-	case EVENT_MOD_PAUSE_RECORD:
-		if (m_bStarted) {
-			m_pRecorder->PauseRecord();
-			m_pRecorder->CloseVideoFile();
-		}
-		break;
-
-	case EVENT_MOD_CONTINUE_RECORD:
-		m_pRecorder->ContinueRecord();
-		break;
-
-	case LOG_EVT_RECORDER_SECTION_FINISHED:
-		{
-			if (m_iRecordMode) {
-				LogVideoSizeInfo(pszMessage);
-			}
-			if (m_bEncFlag){
-				HandleEncryptVideoRecord(pszMessage);
-			}
-			HandleSaveVideoRecord(pszMessage);
-		}
-		break;
-
-	case LOG_EVT_RECORDER_WHOLE_FINISHED:
-		{
-			if (m_iRecordMode) {
-				LogVideoSizeInfo(pszMessage);
-			}
-			if (m_bEncFlag){
-				HandleEncryptVideoRecord(pszMessage);
-			}
-			HandleFinishedVideoRecord(pszMessage);
-			if (m_bPostVideoInfoOn) {
-				PostVideoRecordInfos();
-			}
-			else {
-				m_vRecordList.clear();
-			}
-		}
-		break;
-
-	case LOG_EVT_START_BUSINESSRECORD_FAILED:
-		m_eBusinessStatus = eFailed;
-		if (m_bPostVideoInfoOn) {
-			PostVideoRecordInfos();
-		}
-		else {
-			m_vRecordList.clear();
-		}
-		break;
-
-	default:
-		break;
-	}
-}
-	
-
-void CRecorderEntity::OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName)
-{	
-	if (_stricmp(pszKey, SYSVAR_CAMERASTATE) == 0)
-	{
-		m_iCameraState = pszValue[0]; 
-		if (pszValue[0] == 'E'){
-			m_iActiveCamera = CAMERA_TYPE_OPT;
-		}
-		else if (pszValue[0] == 'O'){
-			m_iActiveCamera = CAMERA_TYPE_ENV;
-		}
-		else if(pszValue[0] == 'B'){
-			m_iActiveCamera = CAMERA_TYPE_ERROR;
-		}
-		else if (pszValue[0] == 'N'){
-			m_iActiveCamera = CAMERA_TYPE_ENV;
-		}
-	}
-	else if (_stricmp(pszKey, SYSVAR_ACTIVETRACKINGCAMERA) == 0)
-	{
-		if (m_iCameraState == 'N'){
-			if (pszValue[0] == 'E'){
-				m_iActiveCamera = CAMERA_TYPE_ENV;
-			}
-			else if (pszValue[0] == 'O'){
-				m_iActiveCamera = CAMERA_TYPE_OPT;
-			}
-		}
-	}
-}
-
-
-void CRecorderEntity::OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
-{ 
-	if (Test_ShakeHand == eTestType){
-		pTransactionContext->SendAnswer(Error_Succeed); 
-	}
-}
-
-
-void CRecorderEntity::StartRecord(const char *videofilename)
-{
-	int fps = 5;
-	Rvc_RecordAudioParam_t tAudioParams;
-	tAudioParams.eRecordType = eSingleSide;
-	tAudioParams.eOutPutType = eLowDefinition;
-	tAudioParams.bIsNsOn = false;
-	tAudioParams.iNsPolicy = 2;
-	tAudioParams.iAudioOutBitRate = 8;
-	tAudioParams.bIsTransOn = false;
-	tAudioParams.iAudioChannels = 1;
-
-	if (m_pRecorder->StartVideoRecord(fps, 75, m_eRecordType, &tAudioParams, NULL, FALSE, TRUE, (LPCSTR)m_TempDir, m_RecordSaveDir.GetLength(), videofilename, strlen(videofilename)))
-	{
-		m_bStarted = true;
-		m_eBusinessStatus = eSuccess;
-	}
-}
-
-
-void CRecorderEntity::StopRecord()
-{
-	if (m_bStarted) {
-		m_pRecorder->StopVideoRecord();
-		m_bStarted = false;
-	}
-}
-
-
-void CRecorderEntity::SetRecordSessionID(const char* strRecordID)
-{
-	if (NULL != strRecordID) {
-		memset(m_strRecordName, 0 , MAX_PATH);
-		_snprintf(m_strRecordName, MAX_PATH, "%s", strRecordID);
-	}
-}
-
-void CRecorderEntity::GetRecordSessionID(char* strRecordID, size_t uLen)
-{
-	if (NULL != strRecordID) {
-		_snprintf(strRecordID, uLen, "%s", m_strRecordName);
-	}
-}
-
-
-DeviceTypeEnum CRecorderEntity::RvcGetDeviceType()
-{
-	DeviceTypeEnum eType = eStand2sType;
-	CSmartPointer<IEntityFunction> spFunction = GetFunction();
-	CSystemStaticInfo stStaticinfo;
-	spFunction->GetSystemStaticInfo(stStaticinfo);
-	if (_stricmp(stStaticinfo.strMachineType, "RVC.Stand1SPlus") == 0) {
-		eType = eStand1SPlusType;
-	}
-	else if (_stricmp(stStaticinfo.strMachineType, "RVC.PAD") == 0) {
-		if (_stricmp(stStaticinfo.strSite, "CMB.FLB") == 0) {
-			eType = eMobilePadType;
-		}
-	}
-	else if (_stricmp(stStaticinfo.strMachineType, "RPM.Stand1S") == 0) {
-		eType = eRpm1sType;
-	}
-	else if (_stricmp(stStaticinfo.strMachineType, "RVC.Desk1S") == 0) {
-		eType = eDesk1SType;
-	}
-	else if (stricmp(stStaticinfo.strMachineType, "RVC.CardStore") == 0 || stricmp(stStaticinfo.strMachineType, "RVC.CardPrinter") == 0) {
-		eType = eCardStore;
-	}
-	else {
-		eType = eStand2sType;
-	}
-
-	if (eType >= 0 && eType < sizeof(Device_Type_Table) / sizeof(char*)) {
-		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("device type is %s.", Device_Type_Table[eType]);
-	}
-
-	m_terminalNo = stStaticinfo.strTerminalID;
-
-	return eType;
-}
-
-
-int CRecorderEntity::HandleFinishedVideoRecord(const char* videofilename)
-{
-	int iRet = -1;
-	if (NULL == videofilename){
-		return iRet;
-	}
-
-	char strSession[RVC_MAX_VIDEO_NAME_LEN] = {0};
-	int iSeriesNum = -1;
-	char strFormat[RVC_MAX_VIDEO_NAME_LEN] = {0};
-
-	if (-1 == GetRecordVideoInfo(videofilename, strSession, RVC_MAX_VIDEO_NAME_LEN, &iSeriesNum, strFormat, RVC_MAX_VIDEO_NAME_LEN)){
-		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[%s] get record video info failed.", videofilename);
-		return iRet;
-	}
-
-	if (iSeriesNum >= 1 || m_iRecordMode){
-		CSimpleStringA srcfile = CSimpleStringA::Format("%s%s_%d_end.%s",(LPCTSTR)m_TempDir,(LPCTSTR)strSession, iSeriesNum, strFormat);
-		CSimpleStringA dstfile = CSimpleStringA::Format("%s%s_%d_end.%s",(LPCTSTR)m_RecordSaveDir,(LPCTSTR)strSession, iSeriesNum, strFormat);
-		BOOL bRet = FALSE;
-		if (ExistsFile(srcfile.GetData())){
-			bRet = MoveFile(srcfile.GetData(), dstfile.GetData());
-			if(!bRet) {
-				LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("Error Code %u while move %s ", GetLastError(), srcfile.GetData()).GetData());
-			}
-			else {
-				AddToVideoRecordList(dstfile.GetData());
-			}
-		}
-
-		srcfile = CSimpleStringA::Format("%s%s_%d.%s",(LPCTSTR)m_TempDir,(LPCTSTR)strSession, iSeriesNum-1, strFormat);
-		dstfile = CSimpleStringA::Format("%s%s_%d.%s",(LPCTSTR)m_RecordSaveDir,(LPCTSTR)strSession, iSeriesNum-1, strFormat);
-		if (ExistsFile(srcfile.GetData())){
-			bRet = MoveFile(srcfile.GetData(), dstfile.GetData());
-			if(!bRet) {
-				LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("Error Code %u while move %s ", GetLastError(), srcfile.GetData()).GetData());
-			}
-			else {
-				AddToVideoRecordList(dstfile.GetData());
-			}
-		}
-	}
-
-	iRet =  0;
-
-	return iRet;
-}
-
-
-int CRecorderEntity::HandleEncryptVideoRecord(const char* videofilename)
-{
-	int iRet = -1;
-	if (NULL == videofilename){
-		return iRet;
-	}
-
-	filecryption_callback_t cb = {0};
-	cb.dbg = &rvcDbg;
-	
-	char strOutFile[MAX_PATH] = {0};
-	int iresult = encryption_file(strOutFile, MAX_PATH, videofilename, &cb, eVerA);
-	if (0 != iresult){
-		LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_ENCRYPT_FAILED, CSimpleStringA::Format("encryption file %s failed, delete out temp file %s!", videofilename, strOutFile).GetData());
-		if (!DeleteFile(strOutFile)){
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("DeleteFile file %s failed!", strOutFile);
-		}
-		return iRet;
-	}
-
-	BOOL bRet = DeleteFile(videofilename);
-	if(!bRet) {
-		LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_DELETE_FAILED, CSimpleStringA::Format("Error Code %lu while delete %s, delete out temp file[%s]!", GetLastError(), videofilename, strOutFile).GetData());
-		if (!DeleteFile(strOutFile)){
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("DeleteFile file %s failed!", strOutFile);
-		}
-		return iRet;
-	}
-	else{
-		if (!rename(strOutFile, videofilename)){
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("rename %s to %s Success!",strOutFile, videofilename);
-			iRet = 0;
-		}
-		else{
-			LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_RENAME_FAILED, CSimpleStringA::Format("Error Code %lu while rename %s.", GetLastError(), strOutFile).GetData());
-		}
-	}
-
-	return iRet;
-}
-
-
-
-int CRecorderEntity::HandleSaveVideoRecord(const char* videofilename)
-{
-	int iRet = -1;
-	if (NULL == videofilename){
-		return iRet;
-	}
-
-	char strSession[RVC_MAX_VIDEO_NAME_LEN] = {0};
-	int iSeriesNum = -1;
-	char strFormat[RVC_MAX_VIDEO_NAME_LEN] = {0};
-
-	if (-1 == GetRecordVideoInfo(videofilename, strSession, RVC_MAX_VIDEO_NAME_LEN, &iSeriesNum, strFormat, RVC_MAX_VIDEO_NAME_LEN)){
-		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[%s] get record video info failed.", videofilename);
-		return iRet;
-	}
-
-	if (1 == m_iRecordMode) {
-		CSimpleStringA srcfile = CSimpleStringA::Format("%s%s_%d.%s", (LPCTSTR)m_TempDir, (LPCTSTR)strSession, iSeriesNum, strFormat);
-		CSimpleStringA dstfile = CSimpleStringA::Format("%s%s_%d.%s", (LPCTSTR)m_RecordSaveDir, (LPCTSTR)strSession, iSeriesNum, strFormat);
-		if (ExistsFile(srcfile.GetData())) {
-			BOOL bRet = MoveFile(srcfile.GetData(), dstfile.GetData());
-			if (!bRet) {
-				LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("Error Code %u while move %s ", GetLastError(), srcfile.GetData()));
-			}
-			else {
-				AddToVideoRecordList(dstfile.GetData());
-			}
-		}
-	}
-	else {
-		if (iSeriesNum >= 1) {
-			CSimpleStringA srcfile = CSimpleStringA::Format("%s%s_%d.%s", (LPCTSTR)m_TempDir, (LPCTSTR)strSession, iSeriesNum - 1, strFormat);
-			CSimpleStringA dstfile = CSimpleStringA::Format("%s%s_%d.%s", (LPCTSTR)m_RecordSaveDir, (LPCTSTR)strSession, iSeriesNum - 1, strFormat);
-			if (ExistsFile(srcfile.GetData())) {
-				BOOL bRet = MoveFile(srcfile.GetData(), dstfile.GetData());
-				if (!bRet) {
-					LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("Error Code %u while move %s ", GetLastError(), srcfile.GetData()).GetData());
-				}
-				m_iMovedSeriesNum = iSeriesNum - 1;
-			}
-		}
-		else {
-			if (0 == m_iMovedSeriesNum) {
-				if (false == m_bMoveFlag) {
-					m_bMoveFlag = true;
-				}
-				else {
-					CSimpleStringA srcfile = CSimpleStringA::Format("%s%s_%d_end.%s", (LPCTSTR)m_TempDir, (LPCTSTR)m_LastSaveSessionId, 0, strFormat);
-					if (ExistsFile(srcfile.GetData())) {
-						CSimpleStringA dstfile = CSimpleStringA::Format("%s%s_%d_end.%s", (LPCTSTR)m_RecordSaveDir, (LPCTSTR)m_LastSaveSessionId, 0, strFormat);
-						BOOL bRet = MoveFile(srcfile.GetData(), dstfile.GetData());
-						if (!bRet) {
-							LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("Error Code %u while move %s ", GetLastError(), srcfile.GetData()).GetData());
-						}
-						else {
-							AddToVideoRecordList(dstfile.GetData());
-						}
-					}
-				}
-			}
-			else {
-				CSimpleStringA srcfile = CSimpleStringA::Format("%s%s_%d_end.%s", (LPCTSTR)m_TempDir, (LPCTSTR)m_LastSaveSessionId, m_iMovedSeriesNum + 1, strFormat);
-				if (ExistsFile(srcfile.GetData())) {
-					CSimpleStringA dstfile = CSimpleStringA::Format("%s%s_%d_end.%s", (LPCTSTR)m_RecordSaveDir, (LPCTSTR)m_LastSaveSessionId, m_iMovedSeriesNum + 1, strFormat);
-					BOOL bRet = MoveFile(srcfile.GetData(), dstfile.GetData());
-					if (!bRet) {
-						LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, CSimpleStringA::Format("Error Code %u while move %s.", GetLastError(), srcfile.GetData()).GetData());
-					}
-					else {
-						AddToVideoRecordList(dstfile.GetData());
-					}
-				}
-				m_iMovedSeriesNum = 0;
-			}
-			m_LastSaveSessionId = strSession;
-		}
-	}
-
-	iRet =  0;
-
-	return iRet;
-}
-
-
-int CRecorderEntity::GetRecordVideoInfo(const char* videofilename, char* strSession, size_t uSessionLen, int* iSeriesNum, char* strFormat, size_t uFormatLen)
-{
-	int iRet = -1;
-
-	char strFileName[RVC_MAX_VIDEO_NAME_LEN] = {0};
-	size_t uLen = strlen(videofilename);
-	if (uLen <= RVC_MAX_VIDEO_NAME_LEN){
-		const char *pIndex = strrchr(videofilename, '\\');
-		if (pIndex){
-			_snprintf(strFileName, RVC_MAX_VIDEO_NAME_LEN, "%s", pIndex + 1);
-		}
-	}
-	else{
-		return iRet;
-	}
-
-	int ioffset = 0;
-	if (0 == memcmp(strFileName, RVC_TRANSATCION_RECORD_SUFFIX, strlen(RVC_TRANSATCION_RECORD_SUFFIX))) {
-		ioffset = strlen(RVC_TRANSATCION_RECORD_SUFFIX);
-	}
-
-	char* pNum = strstr(strFileName+ioffset, "_");
-	if (pNum){
-		*pNum = 0;
-		strcpy(strSession, strFileName);
-		pNum++;
-	}
-	else{
-		return iRet;
-	}
-
-	char* pend = strstr(pNum, "_end");
-	if (pend){
-		*pend = 0;
-		*iSeriesNum = atoi(pNum);
-		pNum = pend + 1;
-	}
-
-	char* pFormat = strstr(pNum, ".");
-	if (pFormat){
-		*pFormat = 0;
-		pFormat++;
-		strcpy(strFormat, pFormat);
-	}
-	else{
-		return iRet;
-	}
-
-	if (NULL == pend){
-		*iSeriesNum = atoi(pNum);
-	}
-
-	iRet = 0;
-
-	return iRet;
-}
-
-
-int CRecorderEntity::SaveExceptionRecordVideos()
-{
-	int iRet = -1;
-	char srcFilePath[MAX_PATH]={0};
-	WIN32_FIND_DATA FindFileData;
-	HANDLE hFind;
-	bool fFinished = false;
-	char strVideoFormat[MAX_PATH] = { 0 };
-	if (eMP4 == m_eRecordType) {
-		_snprintf(strVideoFormat, MAX_PATH, "%s", RECORD_MP4_SUFFIX);
-	}
-	else {
-		_snprintf(strVideoFormat, MAX_PATH, "%s", RECORD_WMV_SUFFIX);                                                                                                                                                                                                                                                         
-	}
-
-	_snprintf(srcFilePath, MAX_PATH, "%s*.%s", m_TempDir.GetData(), strVideoFormat);
-
-	hFind = FindFirstFile(srcFilePath, &FindFileData);
-
-	if (INVALID_HANDLE_VALUE != hFind)
-	{
-		while (!fFinished){
-			if (FILE_ATTRIBUTE_DIRECTORY & FindFileData.dwFileAttributes){
-				goto on_next;
-			}
-
-			if (NULL == strstr(FindFileData.cFileName, "S_") && NULL == strstr(FindFileData.cFileName, "G_")){
-				CSimpleStringA srcfile = CSimpleStringA::Format("%s%s",m_TempDir.GetData(), FindFileData.cFileName);
-				if (m_bEncFlag){
-					filecryption_callback_t cb = {0};
-					cb.dbg = &rvcDbg;
-					if (false == is_file_encrypted(srcfile.GetData(), &cb)){
-						HandleEncryptVideoRecord(srcfile.GetData());
-					}
-					else{
-						char* pIndex = NULL;
-						if (pIndex = strstr(FindFileData.cFileName, RVC_FILEENC_STR)){
-							char strname[MAX_PATH] = {0};
-							memcpy(strname, pIndex+strlen(RVC_FILEENC_STR), strlen(pIndex+strlen(RVC_FILEENC_STR)));
-							CSimpleStringA tempsrcfile = CSimpleStringA::Format("%s%s",m_TempDir.GetData(), strname);
-							if (!rename(srcfile.GetData(),tempsrcfile.GetData())){
-								srcfile = tempsrcfile;
-								memset(FindFileData.cFileName, 0, MAX_PATH);
-								memcpy(FindFileData.cFileName, strname, strlen(strname));
-							}
-							else{
-								LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_RENAME_FAILED, CSimpleStringA::Format("Error Code %lu while rename %s.", GetLastError(), srcfile.GetData()).GetData());
-							}
-						}
-					}
-				}
-
-				CSimpleStringA dstfile = CSimpleStringA::Format("%s%s",m_RecordSaveDir.GetData(), FindFileData.cFileName);
-				BOOL bRet = MoveFile(srcfile.GetData(), dstfile.GetData());
-				if(!bRet) {
-					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());
-				}
-				else{
-					AddToVideoRecordList(dstfile.GetData());
-					iRet = 0;
-				}
-			}
-
-on_next:
-			if (!FindNextFile(hFind, &FindFileData)){
-				if (GetLastError() == ERROR_NO_MORE_FILES){
-					fFinished = true;
-				}
-				else{
-					break;
-				}
-			}
-		}
-		FindClose(hFind);
-	}
-
-	return iRet;
-}
-
-
-int CRecorderEntity::DeleteExceptionLogFiles()
-{
-	CSimpleStringA strDbgPath;
-
-	WIN32_FIND_DATA FindFileData;
-	HANDLE hFind;
-	bool fFinished = false;
-
-	auto pFunc = GetFunction();
-	pFunc->GetPath("Dbg", strDbgPath);
-
-	char logPath[MAX_PATH] = "";
-	sprintf(logPath, "%s\\%s", strDbgPath.GetData(), MOD_RECORDER_NAME);
-
-	char srcFilePath[MAX_PATH]={0};
-	sprintf_s(srcFilePath, MAX_PATH, "%s\\*.*", logPath);
-
-	hFind = FindFirstFile(srcFilePath, &FindFileData);
-
-	if (INVALID_HANDLE_VALUE != hFind)
-	{
-		while (!fFinished)
-		{
-			if (FILE_ATTRIBUTE_DIRECTORY & FindFileData.dwFileAttributes)
-			{
-				goto on_next;
-			}
-
-			__int64 nSize = ((__int64)FindFileData.nFileSizeHigh << 32) + FindFileData.nFileSizeLow;
-			if (nSize > MAX_LOGFILE_SIZE)
-			{
-				CSimpleStringA dstfile = CSimpleStringA::Format("%s\\%s",logPath, FindFileData.cFileName);
-				BOOL bRet = DeleteFile(dstfile.GetData());
-				if(bRet) {
-					LogWarn(Severity_Low, Error_Debug, LOG_EVT_DELETE_BIG_LOGFILE, dstfile.GetData());
-				}
-			}
-on_next:
-			if (!FindNextFile(hFind, &FindFileData)){
-				if (GetLastError() == ERROR_NO_MORE_FILES){
-					fFinished = true;
-				}
-				else{
-					break;
-				}
-			}
-		}
-		FindClose(hFind);
-	}
-
-	return 0;
-}
-
-
-
-SP_BEGIN_ENTITY_MAP()
-	SP_ENTITY(CRecorderEntity)
-SP_END_ENTITY_MAP()
-