Browse Source

#IQRV #comment mod_recorder 编译通过

80374374 1 year ago
parent
commit
d3cf05fb3d

+ 1 - 1
Module/CMakeLists.txt

@@ -207,7 +207,7 @@ add_subdirectory(mod_countercontext)
 #zhaohu
 add_subdirectory(mod_mediacontroller)
 #zhaohu
-#add_subdirectory(mod_recorder)
+add_subdirectory(mod_recorder)
 add_subdirectory(mod_snapshot)
 #zhaohu
 add_subdirectory(mod_screenshot)

+ 6 - 4
Module/mod_recorder/CMakeLists.txt

@@ -1,9 +1,9 @@
 #ʵÌåÃû
 define_module("recorder")
 
-file(GLOB ${MODULE_PREFIX}_SRCS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
-    "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
-    "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp")
+set(${MODULE_PREFIX}_SRCS
+	${CMAKE_CURRENT_SOURCE_DIR}/${MODULE_PLAFORM_SUBDIR}/mod_recorder.cpp
+)
 
 set(MOD_VERSION_STRING "1.0.0-dev1")
 add_module_libraries(${MODULE_PREFIX} ${MODULE_NAME} ${MOD_VERSION_STRING})
@@ -11,11 +11,13 @@ add_module_libraries(${MODULE_PREFIX} ${MODULE_NAME} ${MOD_VERSION_STRING})
 # ÒÀÀµlibvideorecord
 target_include_directories(${MODULE_NAME} PRIVATE
 	${RVC_FRAMEWORK_INCLUDES_DIR}
+    ${CMAKE_CURRENT_SOURCE_DIR}
     ${CONAN_INCLUDE_DIRS_FFMPEG}
 	${CONAN_RVCFRAMEWORK_ROOT}/include
     ${MODULE_BASE_DIR}
     ${OTHER_LIB_PLATFORM_BASE_DIR}/libvideorecord
     ${OTHER_LIB_PLATFORM_BASE_DIR}/rvcmediacommon
+    ${OTHER_LIB_PLATFORM_BASE_DIR}/libfilecryption
     )
 
 target_link_directories(${MODULE_NAME} PRIVATE
@@ -23,7 +25,7 @@ target_link_directories(${MODULE_NAME} PRIVATE
 )
 
 set(${MODULE_PREFIX}_LIBS ${MODULE_BASE_LIBS})
-target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS} ${CONAN_PKG_LIBS_FFMPEG} libvideorecord)  
+target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS} ${CONAN_PKG_LIBS_FFMPEG} libvideorecord libfilecryption)  
 
 target_include_directories(${MODULE_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
 

+ 34 - 34
Module/mod_recorder/Recorder_client_g.h

@@ -86,26 +86,26 @@ public:
 	}
 	ErrorCodeEnum StartTransactionRecord(RecorderSerVice_StartTransactionRecord_Req &Req, RecorderSerVice_StartTransactionRecord_Ans &Ans, DWORD dwTimeout, DWORD &dwUserError, CSimpleString &str)
 	{
-        CSmartPointer<IAsynWaitSp> spAsyncWait;
-        ErrorCodeEnum Error = StartTransactionRecord(Req, spAsyncWait, dwTimeout);
-        if (Error == Error_Succeed) {
-            bool bEnd = false;
-            Error = SpWaitAnswerObject(spAsyncWait, Ans, bEnd, dwUserError, str, dwTimeout);
-            LOG_ASSERT(Error || bEnd);
-        }
-        return Error;
+		CSmartPointer<IAsynWaitSp> spAsyncWait;
+		ErrorCodeEnum Error = StartTransactionRecord(Req, spAsyncWait, dwTimeout);
+		if (Error == Error_Succeed) {
+			bool bEnd = false;
+			Error = SpWaitAnswerObject(spAsyncWait, Ans, bEnd, dwUserError, str, dwTimeout);
+			LOG_ASSERT(Error || bEnd);
+		}
+		return Error;
 	}
 	ErrorCodeEnum StartTransactionRecord(RecorderSerVice_StartTransactionRecord_Req &Req, RecorderSerVice_StartTransactionRecord_Ans &Ans, DWORD dwTimeout, DWORD &dwUserError)
 	{
-        CSmartPointer<IAsynWaitSp> spAsyncWait;
-        ErrorCodeEnum Error = StartTransactionRecord(Req, spAsyncWait, dwTimeout);
-        if (Error == Error_Succeed) {
-            bool bEnd = false;
-            CSimpleString str;
-            Error = SpWaitAnswerObject(spAsyncWait, Ans, bEnd, dwUserError, str, dwTimeout);
-            LOG_ASSERT(Error || bEnd);
-        }
-        return Error;
+		CSmartPointer<IAsynWaitSp> spAsyncWait;
+		ErrorCodeEnum Error = StartTransactionRecord(Req, spAsyncWait, dwTimeout);
+		if (Error == Error_Succeed) {
+			bool bEnd = false;
+			CSimpleString str;
+			Error = SpWaitAnswerObject(spAsyncWait, Ans, bEnd, dwUserError, str, dwTimeout);
+			LOG_ASSERT(Error || bEnd);
+		}
+		return Error;
 	}
 
 	ErrorCodeEnum StopTransactionRecord(RecorderSerVice_StopTransactionRecord_Req &Req, CSmartPointer<IAsynWaitSp> &spAsyncWait, DWORD dwTimeout)
@@ -135,26 +135,26 @@ public:
 	}
 	ErrorCodeEnum StopTransactionRecord(RecorderSerVice_StopTransactionRecord_Req &Req, RecorderSerVice_StopTransactionRecord_Ans &Ans, DWORD dwTimeout, DWORD &dwUserError, CSimpleString &str)
 	{
-        CSmartPointer<IAsynWaitSp> spAsyncWait;
-        ErrorCodeEnum Error = StopTransactionRecord(Req, spAsyncWait, dwTimeout);
-        if (Error == Error_Succeed) {
-            bool bEnd = false;
-            Error = SpWaitAnswerObject(spAsyncWait, Ans, bEnd, dwUserError, str, dwTimeout);
-            LOG_ASSERT(Error || bEnd);
-        }
-        return Error;
+		CSmartPointer<IAsynWaitSp> spAsyncWait;
+		ErrorCodeEnum Error = StopTransactionRecord(Req, spAsyncWait, dwTimeout);
+		if (Error == Error_Succeed) {
+			bool bEnd = false;
+			Error = SpWaitAnswerObject(spAsyncWait, Ans, bEnd, dwUserError, str, dwTimeout);
+			LOG_ASSERT(Error || bEnd);
+		}
+		return Error;
 	}
 	ErrorCodeEnum StopTransactionRecord(RecorderSerVice_StopTransactionRecord_Req &Req, RecorderSerVice_StopTransactionRecord_Ans &Ans, DWORD dwTimeout, DWORD &dwUserError)
 	{
-        CSmartPointer<IAsynWaitSp> spAsyncWait;
-        ErrorCodeEnum Error = StopTransactionRecord(Req, spAsyncWait, dwTimeout);
-        if (Error == Error_Succeed) {
-            bool bEnd = false;
-            CSimpleString str;
-            Error = SpWaitAnswerObject(spAsyncWait, Ans, bEnd, dwUserError, str, dwTimeout);
-            LOG_ASSERT(Error || bEnd);
-        }
-        return Error;
+		CSmartPointer<IAsynWaitSp> spAsyncWait;
+		ErrorCodeEnum Error = StopTransactionRecord(Req, spAsyncWait, dwTimeout);
+		if (Error == Error_Succeed) {
+			bool bEnd = false;
+			CSimpleString str;
+			Error = SpWaitAnswerObject(spAsyncWait, Ans, bEnd, dwUserError, str, dwTimeout);
+			LOG_ASSERT(Error || bEnd);
+		}
+		return Error;
 	}
 
 

+ 111 - 112
Module/mod_recorder/Recorder_server_g.h

@@ -8,124 +8,123 @@
 
 #include "Recorder_def_g.h"
 
-namespace Recorder
-{
+namespace Recorder {
 class RecorderSerVice_ServerSessionBase : public CServerSessionBase
 {
 public:
-    RecorderSerVice_ServerSessionBase()
-    {
-        /// override by user
-    }
-
-    virtual ~RecorderSerVice_ServerSessionBase()
-    {
-        /// override by user
-    }
-
-    virtual bool IsExclusive() { return false; }
-
-    virtual bool IsSessionOverlap() { return true; }
-
-    virtual ErrorCodeEnum GetMessageAttr(DWORD dwMessageID, DWORD dwSignature, bool& bOverlap)
-    {
-        ErrorCodeEnum Error = Error_Succeed;
-        switch (dwMessageID) {
-        case RecorderSerVice_Method_StartTransactionRecord:
-            if (dwSignature == RecorderSerVice_MethodSignature_StartTransactionRecord) {
-                bOverlap = true;
-            } else {
-                Error = Error_MethodSignatureFailed;
-            }
-            break;
-        case RecorderSerVice_Method_StopTransactionRecord:
-            if (dwSignature == RecorderSerVice_MethodSignature_StopTransactionRecord) {
-                bOverlap = true;
-            } else {
-                Error = Error_MethodSignatureFailed;
-            }
-            break;
-        default:
-            Error = Error_MethodNotFound;
-            break;
-        }
-        return Error;
-    }
-
-    int CheckMessageSignature(DWORD dwMessageID, DWORD dwSignature)
-    {
-        ErrorCodeEnum Error = Error_Succeed;
-        switch (dwMessageID) {
-        case RecorderSerVice_Method_StartTransactionRecord:
-            if (dwSignature != RecorderSerVice_MethodSignature_StartTransactionRecord) {
-                Error = Error_MethodSignatureFailed;
-            }
-            break;
-        case RecorderSerVice_Method_StopTransactionRecord:
-            if (dwSignature != RecorderSerVice_MethodSignature_StopTransactionRecord) {
-                Error = Error_MethodSignatureFailed;
-            }
-            break;
-        default:
-            Error = Error_MethodNotFound;
-            break;
-        }
-        return Error;
-    }
-
-    virtual void Handle_StartTransactionRecord(SpReqAnsContext<RecorderSerVice_StartTransactionRecord_Req, RecorderSerVice_StartTransactionRecord_Ans>::Pointer ctx)
-    {
-        /// override by user
-    }
-
-    virtual void Handle_StopTransactionRecord(SpReqAnsContext<RecorderSerVice_StopTransactionRecord_Req, RecorderSerVice_StopTransactionRecord_Ans>::Pointer ctx)
-    {
-        /// override by user
-    }
-
-    virtual void OnRequest(CSmartPointer<ITransactionContext> pTransactionContext)
-    {
-        CAutoBuffer Buf;
-        DWORD dwMessageID;
-        DWORD dwMessageSignature;
-        ErrorCodeEnum Error = pTransactionContext->GetReceiveBuffer(dwMessageID, dwMessageSignature, Buf);
-        if (Error == Error_Succeed) {
+	RecorderSerVice_ServerSessionBase()
+	{
+		/// override by user
+	}
+
+	virtual ~RecorderSerVice_ServerSessionBase()
+	{
+		/// override by user
+	}
+
+	virtual bool IsExclusive() { return false; }
+
+	virtual bool IsSessionOverlap() { return true; }
+
+	virtual ErrorCodeEnum GetMessageAttr(DWORD dwMessageID, DWORD dwSignature, bool &bOverlap)
+	{
+		ErrorCodeEnum Error = Error_Succeed;
+		switch (dwMessageID) {
+		case RecorderSerVice_Method_StartTransactionRecord:
+			if (dwSignature == RecorderSerVice_MethodSignature_StartTransactionRecord) {
+				bOverlap = true;
+			} else {
+				Error = Error_MethodSignatureFailed;
+			}
+			break;
+		case RecorderSerVice_Method_StopTransactionRecord:
+			if (dwSignature == RecorderSerVice_MethodSignature_StopTransactionRecord) {
+				bOverlap = true;
+			} else {
+				Error = Error_MethodSignatureFailed;
+			}
+			break;
+		default:
+			Error = Error_MethodNotFound;
+			break;
+		}
+		return Error;
+	}
+
+	int CheckMessageSignature(DWORD dwMessageID, DWORD dwSignature)
+	{
+		ErrorCodeEnum Error = Error_Succeed;
+		switch (dwMessageID) {
+		case RecorderSerVice_Method_StartTransactionRecord:
+			if (dwSignature != RecorderSerVice_MethodSignature_StartTransactionRecord) {
+				Error = Error_MethodSignatureFailed;
+			}
+			break;
+		case RecorderSerVice_Method_StopTransactionRecord:
+			if (dwSignature != RecorderSerVice_MethodSignature_StopTransactionRecord) {
+				Error = Error_MethodSignatureFailed;
+			}
+			break;
+		default:
+			Error = Error_MethodNotFound;
+			break;
+		}
+		return Error;
+	}
+
+	virtual void Handle_StartTransactionRecord(SpReqAnsContext<RecorderSerVice_StartTransactionRecord_Req, RecorderSerVice_StartTransactionRecord_Ans>::Pointer ctx)
+	{
+	/// override by user
+	}
+
+	virtual void Handle_StopTransactionRecord(SpReqAnsContext<RecorderSerVice_StopTransactionRecord_Req, RecorderSerVice_StopTransactionRecord_Ans>::Pointer ctx)
+	{
+	/// override by user
+	}
+
+	virtual void OnRequest(CSmartPointer<ITransactionContext> pTransactionContext)
+	{
+		CAutoBuffer Buf;
+		DWORD dwMessageID;
+		DWORD dwMessageSignature;
+		ErrorCodeEnum Error = pTransactionContext->GetReceiveBuffer(dwMessageID, dwMessageSignature, Buf);
+		if (Error == Error_Succeed) {
 #ifdef DEBUG
-            assert(CheckMessageSignature(dwMessageID, dwMessageSignature) == Error_Succeed);
+			assert(CheckMessageSignature(dwMessageID, dwMessageSignature) == Error_Succeed);
 #else
-            if (CheckMessageSignature(dwMessageID, dwMessageSignature) != Error_Succeed) {
-                pTransactionContext->SendAnswer(Error_MethodSignatureFailed);
-                return;
-            }
+			if (CheckMessageSignature(dwMessageID, dwMessageSignature) != Error_Succeed) {
+				pTransactionContext->SendAnswer(Error_MethodSignatureFailed);
+				return;
+			}
 #endif
-            switch (dwMessageID) {
-            case RecorderSerVice_Method_StartTransactionRecord:
-            {
-                SpReqAnsContext<RecorderSerVice_StartTransactionRecord_Req, RecorderSerVice_StartTransactionRecord_Ans>::Pointer ctx;
-                ctx.Attach(new SpReqAnsContext<RecorderSerVice_StartTransactionRecord_Req, RecorderSerVice_StartTransactionRecord_Ans>(pTransactionContext));
-                SpBuffer2Object(Buf, ctx->Req);
-                pTransactionContext->GetLinkContext(ctx->link);
-                Handle_StartTransactionRecord(ctx);
-            }
-            break;
-            case RecorderSerVice_Method_StopTransactionRecord:
-            {
-                SpReqAnsContext<RecorderSerVice_StopTransactionRecord_Req, RecorderSerVice_StopTransactionRecord_Ans>::Pointer ctx;
-                ctx.Attach(new SpReqAnsContext<RecorderSerVice_StopTransactionRecord_Req, RecorderSerVice_StopTransactionRecord_Ans>(pTransactionContext));
-                SpBuffer2Object(Buf, ctx->Req);
-                pTransactionContext->GetLinkContext(ctx->link);
-                Handle_StopTransactionRecord(ctx);
-            }
-            break;
-            default:
-                assert(0);
-                break;
-            }
-
-        } else {
-            pTransactionContext->SendAnswer(Error);
-        }
-    }
+			switch (dwMessageID) {
+				case RecorderSerVice_Method_StartTransactionRecord:
+					{
+						SpReqAnsContext<RecorderSerVice_StartTransactionRecord_Req,RecorderSerVice_StartTransactionRecord_Ans>::Pointer ctx;
+						ctx.Attach(new SpReqAnsContext<RecorderSerVice_StartTransactionRecord_Req,RecorderSerVice_StartTransactionRecord_Ans>(pTransactionContext));
+						SpBuffer2Object(Buf, ctx->Req);
+						pTransactionContext->GetLinkContext(ctx->link);
+						Handle_StartTransactionRecord(ctx);
+					}
+					break;
+				case RecorderSerVice_Method_StopTransactionRecord:
+					{
+						SpReqAnsContext<RecorderSerVice_StopTransactionRecord_Req,RecorderSerVice_StopTransactionRecord_Ans>::Pointer ctx;
+						ctx.Attach(new SpReqAnsContext<RecorderSerVice_StopTransactionRecord_Req,RecorderSerVice_StopTransactionRecord_Ans>(pTransactionContext));
+						SpBuffer2Object(Buf, ctx->Req);
+						pTransactionContext->GetLinkContext(ctx->link);
+						Handle_StopTransactionRecord(ctx);
+					}
+					break;
+				default:
+					assert(0);
+					break;
+			}
+			
+		} else {
+			pTransactionContext->SendAnswer(Error);
+		}
+	}
 
 };
 

+ 43 - 8
Module/mod_recorder/mod_recorder.h

@@ -3,7 +3,14 @@
 #include "SpBase.h"
 #include "SpIni.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"
 
@@ -16,7 +23,11 @@ namespace Recorder {
 	class CRecorderEntity : public CEntityBase, public CHostApi, public ILogListener, public ISysVarListener
 	{
 	public:
-		CRecorderEntity() : m_bStarted(false), m_pRecorder(NULL), m_eRecordType(eMP4){}
+#if defined(RVC_OS_WIN)
+		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) {}
+#else
+		CRecorderEntity() : m_bStarted(false), m_pRecorder(NULL), m_eRecordType(eMP4) {}
+#endif //RVC_OS_WIN
 		virtual ~CRecorderEntity() {}
 		virtual const char* GetEntityName() const { return "Recorder"; }
 
@@ -25,10 +36,15 @@ namespace Recorder {
 
 		virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext);
 		virtual void OnPreClose(EntityCloseCauseEnum eCloseCause, CSmartPointer<ITransactionContext> pTransactionContext);
-		bool InitRecorder();
-		bool ReleaseRecorder();
 		ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError);
 		ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError);
+#if defined(RVC_OS_WIN)
+		virtual void OnStarted();
+		virtual void WmpDebug(const char* fmt, ...);
+#else
+		bool InitRecorder();
+		bool ReleaseRecorder();
+#endif //RVC_OS_WIN
 
 		virtual void Debug(record_loglevel elevel, const char* fmt, ...);
 		virtual void vDebug(record_loglevel elevel, const char* str, va_list list);
@@ -42,7 +58,11 @@ namespace Recorder {
 			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);
 
+#if defined(RVC_OS_WIN)
+		void StartRecord(const char* wmvfilename);
+#else
 		void StartRecord(const char* videofilename);
+#endif //RVC_OS_WIN
 		void StopRecord();
 		bool GetStartFlag() { return m_bStarted; }
 
@@ -51,7 +71,16 @@ namespace Recorder {
 		virtual void OnSelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext);
 
 		DeviceTypeEnum RvcGetDeviceType();
-
+#if defined(RVC_OS_WIN)
+		ErrorCodeEnum DecideCameraCount(int& nCount);
+		int HandleSaveVideoRecord(const char* wmvfilename);
+		int GetRecordVideoInfo(const char* wmvfilename, char* strSession, size_t uSessionLen, int* iSeriesNum, char* strFormat, size_t uFormatLen);
+		int HandleFinishedVideoRecord(const char* wmvfilename);
+		int SaveExceptionRecordVideos();
+		int HandleEncryptVideoRecord(const char* wmvfilename);
+		bool IsCurrentTerminalMathed();
+		int DeleteExceptionLogFiles();
+#endif //RVC_OS_WIN
 	private:
 		DeviceTypeEnum m_eDeviceType;
 		int m_iActiveCamera;
@@ -59,9 +88,15 @@ namespace Recorder {
 		CAutoArray<CUUID> m_arrListener;
 		bool m_bStarted;
 		Clibvideorecord* m_pRecorder;
-  
-		CSimpleStringA m_TempDir;			
-		CSimpleStringA m_RecordSaveDir;		
+
+		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;
 	};

+ 0 - 0
Module/mod_recorder/mod_recorder.cpp → Module/mod_recorder/unix/mod_recorder.cpp


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

@@ -0,0 +1,1115 @@
+#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 "..\\mod_customeraware\\Event.h"
+#include "..\\mod_facetracking\\sysvar.h"
+
+using namespace Recorder;
+
+
+#define LOG_EVT_UI_RETURNMENU						0x30B00006				//退出到主菜单
+
+
+#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;
+}
+
+
+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()) {
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Current is recording, stop it.");
+		m_pEntity->StopRecord();
+	}
+
+	char strVideoName[MAX_PATH] = { 0 };
+	_snprintf(strVideoName, MAX_PATH, "%s%s",RVC_TRANSATCION_RECORD_SUFFIX, ctx->Req.VideoName.GetData());
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("StartRecord and video name is %s.", strVideoName);
+
+	m_pEntity->StartRecord(strVideoName);
+
+	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;
+
+	int iEncrytion = 0;
+	int iRecordType = 0;
+	int iRecordMode = 0;
+	UINT64 uMtype = 0x0;
+	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);
+	}
+
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Encryption flag is %d, and EncMtype is 0x%08x.", iEncrytion, uMtype);
+
+	if (1 == iEncrytion && (uMtype & GetDeviceTypeValue(m_eDeviceType))){
+		m_bEncFlag = true;
+	}
+
+	if (1 == iRecordMode) {
+		m_iRecordMode = 1;
+	}
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Record Mode is %d.", m_iRecordMode);
+
+	if (eMobilePadType != m_eDeviceType) {
+		if (0 != iRecordType) {
+			m_eRecordType = eMP4;
+		}
+	}
+
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("EncFlag is %s, video format is %s.", m_bEncFlag ? "true" : "false", m_eRecordType == eMP4 ? RECORD_MP4_SUFFIX : RECORD_WMV_SUFFIX);
+
+	if ((ePadtype == m_eDeviceType)||(eMobilePadType == m_eDeviceType)||(eDesk2SType == m_eDeviceType)||(eDesk1SType == m_eDeviceType)||(eDesk2SIntegratedType == 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);
+	}
+
+	//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("init libvideorecord success!");
+	int i = 0;
+	m_arrListener.Init(7);
+	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()->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 (eDesk1SType == m_eDeviceType || eDesk2SIntegratedType == 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()
+{
+	//DeleteExceptionLogFiles();
+	SaveExceptionRecordVideos();
+}
+
+
+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)
+{
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s connected class = %s!", pszRemoteEntityName, 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);
+		}
+	}
+}
+
+// CWmpHostAPI
+void CRecorderEntity::WmpDebug(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);
+}
+
+
+int CRecorderEntity::GetActiveCamera()
+{
+	return m_iActiveCamera;
+}
+
+
+void CRecorderEntity::OnRecordFailed(eRvcRecordFailedCase eCase, const char *pszMessage, bool bRecordDevFault)
+{
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("OnRecordFailed!");
+	if (!bRecordDevFault){
+		LogEvent(Severity_Middle,LOG_EVT_RECORDFAILED,"0");
+		char strmsg[MAX_PATH] = {0};
+		_snprintf(strmsg, MAX_PATH, "{%s} 本地录音录像失败,已停止!", pszMessage ? pszMessage : " ");
+		LogWarn(Severity_Middle, Error_Debug, LOG_EVT_RECORDING_FAILED, strmsg);
+	}
+	else{
+		LogEvent(Severity_Middle,LOG_EVT_RECORDFAILED,"1");
+		char strinfo[MAX_PATH] = {0};
+		_snprintf(strinfo, MAX_PATH, "{%s} 本地录音录像设备故障,尝试恢复中(预计10s内),请稍等", pszMessage ? pszMessage : " ");
+		LogWarn(Severity_Middle, Error_Debug, LOG_EVT_RECORDING_FAILED, strinfo);
+	}
+}
+
+
+void CRecorderEntity::OnRecordEntityExcption()
+{
+	LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_ENTITY_EXCEPTION, "OnRecordEntityExcption!");
+}
+
+
+void CRecorderEntity::OnRecordFinished()
+{
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("OnRecordFinished!");
+}
+
+int CRecorderEntity:: GetCameraState()
+{
+	return m_iCameraState;
+}
+
+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 void LogVideoSizeInfo(const char* pszMessage)
+{
+	unsigned long ufilesize = GetFileSize(pszMessage);
+	char strmsg[MAX_PATH] = { 0 };
+	_snprintf(strmsg, MAX_PATH, "%s file size is %u byte.", pszMessage, ufilesize);
+
+	LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_VIDEO_SIZE, strmsg);
+}
+
+
+void CRecorderEntity::OnASectionFinished(const char *pszMessage, int iSerialNum, bool bfinished)
+{
+	// filename
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("file %s finished.(SerialNum %d)", pszMessage, iSerialNum);
+	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)
+{
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("user_code = 0x%08x.", dwUserCode);
+	switch (dwUserCode) 
+	{
+	case EVENT_MOD_BEGIN_RECORD:
+		if (0 == m_iRecordMode) {
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start record!");
+			StartRecord(pszMessage);
+		}
+		break;
+
+	case EVENT_MOD_END_RECORD:
+		if (0 == m_iRecordMode) {
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop record!");
+			StopRecord();
+		}
+		break;
+
+	case LOG_EVT_UI_RETURNMENU:
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("exit to main!");
+		if (0 == m_iRecordMode) {
+			//本地录像,退回到首页关闭当前文件,重新开始录制
+			if (m_bStarted) {
+				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("return menu,close video file!");
+				m_pRecorder->CloseVideoFile();
+			}
+		}
+		break;
+
+	case EVENT_MOD_PAUSE_RECORD:
+		if (m_bStarted && (0 == m_iRecordMode)){
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("manipulate media device function called, pause record!");
+			m_pRecorder->PauseRecord();
+			m_pRecorder->CloseVideoFile();
+		}
+		break;
+
+	case EVENT_MOD_CONTINUE_RECORD:
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("manipulate media device function called, continue record!");
+		m_pRecorder->ContinueRecord();
+		break;
+
+	case LOG_EVT_RECORDER_SECTION_FINISHED:
+		{
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("recorder section finished, and message is %s.", pszMessage);
+			if (m_iRecordMode) {
+				LogVideoSizeInfo(pszMessage);
+			}
+			if (m_bEncFlag){
+				HandleEncryptVideoRecord(pszMessage);
+			}
+			HandleSaveVideoRecord(pszMessage);
+		}
+		break;
+
+	case LOG_EVT_RECORDER_WHOLE_FINISHED:
+		{
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("recorder whole finished, and message is %s.", pszMessage);
+			if (m_iRecordMode) {
+				LogVideoSizeInfo(pszMessage);
+			}
+			if (m_bEncFlag){
+				HandleEncryptVideoRecord(pszMessage);
+			}
+			HandleFinishedVideoRecord(pszMessage);
+		}
+		break;
+
+	default:
+		break;
+	}
+}
+	
+
+void CRecorderEntity::OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName)
+{	
+	if (_stricmp(pszKey, SYSVAR_CAMERASTATE) == 0)
+	{
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("camera state from : %c to %c", pszOldValue[0], pszValue[0]);
+		m_iCameraState = pszValue[0]; 
+		if (pszValue[0] == 'E')
+		{
+			m_iActiveCamera = CAMERA_TYPE_OPT;
+			if (eDesk1SType == m_eDeviceType || eDesk2SIntegratedType == m_eDeviceType){
+				m_iActiveCamera = CAMERA_TYPE_ERROR;
+			}
+		}
+		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;
+			}
+		}
+	}
+	else if(_stricmp(pszKey,"SessionID")==0)
+	{
+		CSimpleStringA strSessionID;
+		GetFunction()->GetSysVar("SessionID",strSessionID);
+		//如果sessionid改变且不为空,切换录像文件
+		if(_stricmp(strSessionID,"N")!=0)
+		{
+			if (m_bStarted && (0 == m_iRecordMode))
+			{
+				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Session Id change to %s, close record and start new video file.",strSessionID.GetData());
+				m_pRecorder->ReNameVideoFile(strSessionID);
+			}
+
+		} 			
+	}
+}
+
+
+void CRecorderEntity::OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext) 
+{ 
+	if (Test_ShakeHand == eTestType)
+	{
+		pTransactionContext->SendAnswer(Error_Succeed); 
+	}
+}
+
+
+void CRecorderEntity::StartRecord(const char *videofilename)
+{
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("videofilename = %s", 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;
+	}
+}
+
+// we use root.ini Video section config to decide camera count
+ErrorCodeEnum CRecorderEntity::DecideCameraCount(int &nCount)
+{
+	CSmartPointer<IEntityFunction> spFunction = GetFunction();
+	CSmartPointer<IConfigInfo> spConfig;
+	ErrorCodeEnum Error = spFunction->OpenConfig(Config_Root, spConfig);
+	if (Error == Error_Succeed) {
+		CSimpleStringA strVideoEnv;
+		CSimpleStringA strVideoOpt;
+		SpIniMappingTable table;
+		nCount = 0;
+		table.AddEntryString("Video", "EnvCamera", strVideoEnv, "$");
+		table.AddEntryString("Video", "OptCamera", strVideoOpt, "$");
+		Error = table.Load(spConfig);
+		if (Error == Error_Succeed) {
+			if (strVideoEnv.GetLength() > 1)
+				nCount++;
+			if (strVideoOpt.GetLength() > 1)
+				nCount++;
+		}
+	}
+	return Error;
+}
+
+
+void CRecorderEntity::StopRecord()
+{
+	if (m_bStarted) {
+		m_pRecorder->StopVideoRecord();
+		m_bStarted = false;
+	}
+}
+
+
+DeviceTypeEnum CRecorderEntity::RvcGetDeviceType()
+{
+	DeviceTypeEnum eType = eStand2sType;
+	CSmartPointer<IEntityFunction> spFunction = GetFunction();
+	CSystemStaticInfo stStaticinfo;
+	spFunction->GetSystemStaticInfo(stStaticinfo);
+	if (_stricmp(stStaticinfo.strMachineType, "RVC.PAD") == 0) {
+		if (_stricmp(stStaticinfo.strSite, "CMB.FLB") == 0) {
+			eType = eMobilePadType;
+		}
+		else {
+			eType = ePadtype;
+		}
+	}
+	else if (_stricmp(stStaticinfo.strMachineType, "RVC.Desk2S") == 0) {
+		eType = eDesk2SType;
+		WORD nMajor = stStaticinfo.MachineVersion.GetMajor();
+		WORD nMinor = stStaticinfo.MachineVersion.GetMinor();
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("MachineVersion is %d.%d", nMajor, nMinor);
+		if (2 == nMajor) {
+			eType = eDesk2SIntegratedType;
+		}
+	}
+	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* wmvfilename)
+{
+	int iRet = -1;
+	if (NULL == wmvfilename){
+		return iRet;
+	}
+
+	char strSession[RVC_MAX_VIDEO_NAME_LEN] = {0};
+	int iSeriesNum = -1;
+	char strFormat[RVC_MAX_VIDEO_NAME_LEN] = {0};
+
+	if (-1 == GetRecordVideoInfo(wmvfilename, 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.", wmvfilename);
+		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) {
+				char strmsg[MAX_PATH] = {0};
+				_snprintf(strmsg, MAX_PATH, "Error Code %u while move %s ", GetLastError(), srcfile.GetData());
+				LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, strmsg);
+			}
+			else {
+				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("record finished move file form %s to %s success.", srcfile.GetData(), 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) {
+				char strinfo[MAX_PATH] = {0};
+				_snprintf(strinfo, MAX_PATH, "Error Code %u while move %s ", GetLastError(), srcfile.GetData());
+				LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, strinfo);
+			}
+			else {
+				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("record finished move file form %s to %s success.", srcfile.GetData(), dstfile.GetData());
+			}
+		}
+	}
+
+	iRet =  0;
+
+	return iRet;
+}
+
+
+int CRecorderEntity::HandleEncryptVideoRecord(const char* wmvfilename)
+{
+	int iRet = -1;
+	if (NULL == wmvfilename){
+		return iRet;
+	}
+
+	filecryption_callback_t cb = {0};
+	cb.dbg = &rvcDbg;
+	
+	char strOutFile[MAX_PATH] = {0};
+	int iresult = encryption_file(strOutFile, MAX_PATH, wmvfilename, &cb, eVerA);
+	if (0 != iresult){
+		char strmsg[MAX_PATH] = {0};
+		_snprintf(strmsg, MAX_PATH, "encryption file %s failed, delete out temp file %s!", wmvfilename, strOutFile);
+		LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_ENCRYPT_FAILED, strmsg);
+		if (DeleteFile(strOutFile)){
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("DeleteFile file %s success!", strOutFile);
+		}
+		return iRet;
+	}
+	else{
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Encrypt file %s Success!", wmvfilename);
+	}
+
+	BOOL bRet = DeleteFile(wmvfilename);
+	if(!bRet) {
+		char strinfo[MAX_PATH] = {0};
+		_snprintf(strinfo, MAX_PATH, "Error Code %lu while delete %s, delete out temp file[%s]!", GetLastError(), wmvfilename, strOutFile);
+		LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_DELETE_FAILED, wmvfilename);
+		if (DeleteFile(strOutFile)){
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("DeleteFile file %s success!", strOutFile);
+		}
+		return iRet;
+	}
+	else{
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Delete %s Success!", wmvfilename);
+		if (!rename(strOutFile,wmvfilename)){
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("rename %s to %s Success!",strOutFile, wmvfilename);
+			iRet = 0;
+		}
+		else{
+			char strtext[MAX_PATH] = {0};
+			_snprintf(strtext, MAX_PATH, "Error Code %lu while rename %s.", GetLastError(), strOutFile);
+			LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_RENAME_FAILED, strtext);
+		}
+	}
+
+	return iRet;
+}
+
+
+
+int CRecorderEntity::HandleSaveVideoRecord(const char* wmvfilename)
+{
+	int iRet = -1;
+	if (NULL == wmvfilename){
+		return iRet;
+	}
+
+	char strSession[RVC_MAX_VIDEO_NAME_LEN] = {0};
+	int iSeriesNum = -1;
+	char strFormat[RVC_MAX_VIDEO_NAME_LEN] = {0};
+
+	if (-1 == GetRecordVideoInfo(wmvfilename, 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.", wmvfilename);
+		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) {
+				char strmsg[MAX_PATH] = { 0 };
+				_snprintf(strmsg, MAX_PATH, "Error Code %u while move %s ", GetLastError(), srcfile.GetData());
+				LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, strmsg);
+			}
+			else {
+				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("section finished move file form %s to %s success.", srcfile.GetData(), 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) {
+					char strmsg[MAX_PATH] = { 0 };
+					_snprintf(strmsg, MAX_PATH, "Error Code %u while move %s ", GetLastError(), srcfile.GetData());
+					LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, strmsg);
+				}
+				else {
+					DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("section finished move file form %s to %s success.", srcfile.GetData(), dstfile.GetData());
+				}
+				m_iMovedSeriesNum = iSeriesNum - 1;
+			}
+		}
+		else {
+			if (0 == m_iMovedSeriesNum) {
+				if (false == m_bMoveFlag) {
+					DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("First record video, ignore it.");
+					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) {
+							char strtext[MAX_PATH] = { 0 };
+							_snprintf(strtext, MAX_PATH, "Error Code %u while move %s ", GetLastError(), srcfile.GetData());
+							LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, strtext);
+						}
+						else {
+							DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("section finished move file form %s to %s success.", srcfile.GetData(), 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) {
+						char strinfo[MAX_PATH] = { 0 };
+						_snprintf(strinfo, MAX_PATH, "Error Code %u while move %s ", GetLastError(), srcfile.GetData());
+						LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, strinfo);
+					}
+					else {
+						DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("section finished move file form %s to %s success.", srcfile.GetData(), dstfile.GetData());
+					}
+				}
+				m_iMovedSeriesNum = 0;
+			}
+
+			m_LastSaveSessionId = strSession;
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("New set last save session id is %s ", m_LastSaveSessionId.GetData());
+		}
+	}
+
+	iRet =  0;
+
+	return iRet;
+}
+
+
+int CRecorderEntity::GetRecordVideoInfo(const char* wmvfilename, 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(wmvfilename);
+	if (uLen <= RVC_MAX_VIDEO_NAME_LEN){
+		const char *pIndex = strrchr(wmvfilename, '\\');
+		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;
+
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("video name info:(session is %s, series number is %d, video format is %s).", strSession, *iSeriesNum, strFormat);
+
+	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) {
+		sprintf_s(strVideoFormat, MAX_PATH, "%s", RECORD_MP4_SUFFIX);
+	}
+	else {
+		sprintf_s(strVideoFormat, MAX_PATH, "%s", RECORD_WMV_SUFFIX);                                                                                                                                                                                                                                                         
+	}
+
+	sprintf_s(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())){
+								DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("rename %s to %s Success!",srcfile.GetData(),tempsrcfile.GetData());
+								srcfile = tempsrcfile;
+								memset(FindFileData.cFileName, 0, MAX_PATH);
+								memcpy(FindFileData.cFileName, strname, strlen(strname));
+							}
+							else{
+								char strinfo[MAX_PATH] = {0};
+								_snprintf(strinfo, MAX_PATH, "Error Code %lu while rename %s.", GetLastError(), srcfile.GetData());
+								LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_RENAME_FAILED, strinfo);
+							}
+						}
+					}
+				}
+
+				CSimpleStringA dstfile = CSimpleStringA::Format("%s%s",m_RecordSaveDir.GetData(), FindFileData.cFileName);
+				BOOL bRet = MoveFile(srcfile.GetData(), dstfile.GetData());
+				if(!bRet) {
+					char strmsg[MAX_PATH] = {0};
+					_snprintf(strmsg, MAX_PATH, "Error Code %u while move %s -> %s", GetLastError(), srcfile.GetData(), dstfile.GetData());
+					LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_MOVE_FAILED, strmsg);
+				}
+				else{
+					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);
+
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("srcFilePath is %s.", srcFilePath);
+	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);
+				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("srcFilePath is %s.", dstfile.GetData());
+				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;
+}
+
+
+bool CRecorderEntity::IsCurrentTerminalMathed()
+{
+	bool bRet = false;
+	CSimpleStringA TerminalList ="";
+	CSmartPointer<IEntityFunction> spFunction = GetFunction();
+	CSmartPointer<IConfigInfo> spConfig;
+
+	ErrorCodeEnum Error = spFunction->OpenConfig(Config_CenterSetting, spConfig);
+	Error = spConfig->ReadConfigValue("Recorder", "TerminalList", TerminalList);
+	if (Error_Succeed == Error){
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get TerminalList=%s from CenterSetting.ini", TerminalList);
+		if (TerminalList.GetLength() > 0){
+			CSystemStaticInfo systemStaticInfo;
+			auto rc =  GetFunction()->GetSystemStaticInfo(systemStaticInfo);
+			CAutoArray<CSimpleStringA> tList = TerminalList.Split('|');
+			for(int i=0; i<tList.GetCount(); i++){
+				if(tList[i] == systemStaticInfo.strTerminalID){
+					bRet = true;
+					break;
+				}
+			}
+		}
+		else{
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("TerminalList length from CenterSetting.ini is zero.");
+			bRet = true;
+		}
+	} 
+	else{
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get TerminalList section from CenterSetting.ini failed!");
+		bRet = true;
+	}
+
+	return bRet;
+};
+
+SP_BEGIN_ENTITY_MAP()
+SP_ENTITY(CRecorderEntity)
+SP_END_ENTITY_MAP()
+