|
@@ -4,14 +4,39 @@
|
|
|
#include "mod_livenessdetection.h"
|
|
|
#include "../mod_interactivecontrol/Event.h"
|
|
|
|
|
|
+
|
|
|
+static int __on_get_videodata(eVideoType eType, eCameraType ecameraid, int* width, int* height, unsigned char* bmpdata, int isize, void* user_data)
|
|
|
+{
|
|
|
+ CLivenessDetectionEntity* pThis = static_cast<CLivenessDetectionEntity*>(user_data);
|
|
|
+
|
|
|
+ int iret = pThis->on_get_videodata(eType, ecameraid, width, height, bmpdata, isize);
|
|
|
+
|
|
|
+ return iret;
|
|
|
+}
|
|
|
+
|
|
|
+static void* start_wsserver(void* arg)
|
|
|
+{
|
|
|
+ CLivenessDetectionEntity* liveness_entity = (CLivenessDetectionEntity*)arg;
|
|
|
+
|
|
|
+ websocket_callback_t t_callback = { 0 };
|
|
|
+ t_callback.user_data = liveness_entity;
|
|
|
+ t_callback.on_get_videodata = &__on_get_videodata;
|
|
|
+ rvc_video_param_t t_param = { 0 };
|
|
|
+ t_param.iwidth = REC_COMMON_VIDEO_PREVIEW_WIDTH;
|
|
|
+ t_param.iheight = REC_COMMON_VIDEO_PREVIEW_HEIGHT;
|
|
|
+ t_param.icapwidth = REC_COMMON_VIDEO_SNAPSHOT_WIDTH;
|
|
|
+ t_param.icapheight = REC_COMMON_VIDEO_SNAPSHOT_HEIGHT;
|
|
|
+ int iRet = liveness_entity->GetWsServer()->Init_WsServer(&t_callback, &t_param, liveness_entity->GetWsPort());
|
|
|
+
|
|
|
+ return &iRet;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
CLivenessDetectionEntity::CLivenessDetectionEntity(): m_bStarted(FALSE), m_nCaptureType(-1)
|
|
|
{
|
|
|
-#ifdef RVC_OS_WIN
|
|
|
- m_pFsm = NULL;
|
|
|
-#endif
|
|
|
m_WsServer = new RvcWsServer();
|
|
|
m_pFaceVideo = new RvcFaceVideo();
|
|
|
- m_hWsServerThread = NULL;
|
|
|
+ m_hWsServerThreadId = 0;
|
|
|
m_iWsPort = RVC_LIVENESS_WS_PORT;
|
|
|
m_iCapType = 1;
|
|
|
}
|
|
@@ -23,10 +48,13 @@ CLivenessDetectionEntity::~CLivenessDetectionEntity()
|
|
|
m_WsServer = NULL;
|
|
|
}
|
|
|
|
|
|
- DWORD exitCode = 0;
|
|
|
- if (m_hWsServerThread){
|
|
|
- TerminateThread(m_hWsServerThread, exitCode);
|
|
|
- m_hWsServerThread = NULL;
|
|
|
+ pthread_cancel(m_hWsServerThreadId);
|
|
|
+ if (0 == pthread_join(m_hWsServerThreadId, NULL)) {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("thread join web socket server thread %u success!", m_hWsServerThreadId);
|
|
|
+ m_hWsServerThreadId = 0;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("thread join web socket server thread failed!");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -41,40 +69,37 @@ void CLivenessDetectionEntity::OnPreStart( CAutoArray<CSimpleStringA> strArgs,CS
|
|
|
pTransactionContext->SendAnswer(Error);
|
|
|
}
|
|
|
|
|
|
-void CLivenessDetectionEntity::OnPreClose( EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext )
|
|
|
-{
|
|
|
- ErrorCodeEnum Error = __OnClose(Error_Succeed);
|
|
|
- pTransactionContext->SendAnswer(Error);
|
|
|
-}
|
|
|
|
|
|
-static int __on_get_videodata(eVideoType eType, eCameraType ecameraid, int* width, int* height, unsigned char* bmpdata, int isize, void* user_data)
|
|
|
+void CLivenessDetectionEntity::OnStarted()
|
|
|
{
|
|
|
- CLivenessDetectionEntity *pThis = static_cast<CLivenessDetectionEntity *>(user_data);
|
|
|
-
|
|
|
- int iret = pThis->on_get_videodata(eType, ecameraid, width, height, bmpdata, isize);
|
|
|
+ if (Error_Succeed == GetEntityConfigure()) {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[LivenessDetectionFSM] Get Entity Configure Success!");
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[LivenessDetectionFSM] Get Entity Configure Failed!");
|
|
|
+ }
|
|
|
|
|
|
- return iret;
|
|
|
+ if (0 == pthread_create(&m_hWsServerThreadId, NULL, start_wsserver, (void*)this)) {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create web socket server thread and thread id is %u.", m_hWsServerThreadId);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create web socket server thread failed.");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-static unsigned int __stdcall start_wsserver(void* arg)
|
|
|
+void CLivenessDetectionEntity::OnPreClose( EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext )
|
|
|
{
|
|
|
- CLivenessDetectionEntity* liveness_entity = (CLivenessDetectionEntity*)arg;
|
|
|
-
|
|
|
- websocket_callback_t t_callback = { 0 };
|
|
|
- t_callback.user_data = liveness_entity;
|
|
|
- t_callback.on_get_videodata = &__on_get_videodata;
|
|
|
- rvc_video_param_t t_param = { 0 };
|
|
|
- t_param.iwidth = REC_COMMON_VIDEO_PREVIEW_WIDTH;
|
|
|
- t_param.iheight = REC_COMMON_VIDEO_PREVIEW_HEIGHT;
|
|
|
- t_param.icapwidth = REC_COMMON_VIDEO_SNAPSHOT_WIDTH;
|
|
|
- t_param.icapheight = REC_COMMON_VIDEO_SNAPSHOT_HEIGHT;
|
|
|
- liveness_entity->GetWsServer()->Init_WsServer(&t_callback, &t_param, liveness_entity->GetWsPort());
|
|
|
-
|
|
|
- return 0;
|
|
|
+ ErrorCodeEnum Error = __OnClose(Error_Succeed);
|
|
|
+ pTransactionContext->SendAnswer(Error);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
ErrorCodeEnum CLivenessDetectionEntity::__OnStart(ErrorCodeEnum preOperationError)
|
|
|
{
|
|
|
+ if (preOperationError != Error_Succeed) {
|
|
|
+ return preOperationError;
|
|
|
+ }
|
|
|
+
|
|
|
m_eDeviceType = eStand2sType;
|
|
|
//is Pad Version
|
|
|
CSmartPointer<IEntityFunction> spFunction = GetFunction();
|
|
@@ -87,10 +112,6 @@ ErrorCodeEnum CLivenessDetectionEntity::__OnStart(ErrorCodeEnum preOperationErro
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("the type is standard");
|
|
|
m_eDeviceType = eStand2sType;
|
|
|
}
|
|
|
-
|
|
|
- if (preOperationError != Error_Succeed) {
|
|
|
- return preOperationError;
|
|
|
- }
|
|
|
|
|
|
ErrorCodeEnum Error = Error_Succeed;
|
|
|
nActiveCamera = CAMERA_TYPE_ENV;
|
|
@@ -107,35 +128,19 @@ ErrorCodeEnum CLivenessDetectionEntity::__OnStart(ErrorCodeEnum preOperationErro
|
|
|
CSimpleStringA strValue;
|
|
|
GetFunction()->GetSysVar(SYSVAR_CAMERASTATE, strValue);
|
|
|
m_iCameraState = strValue[0];
|
|
|
- if (strValue[0] == 'E')
|
|
|
- {
|
|
|
+ if (strValue[0] == 'E'){
|
|
|
nActiveCamera = CAMERA_TYPE_OPT;
|
|
|
}
|
|
|
- else if (strValue[0] == 'O')
|
|
|
- {
|
|
|
+ else if (strValue[0] == 'O'){
|
|
|
nActiveCamera = CAMERA_TYPE_ENV;
|
|
|
}
|
|
|
- else if(strValue[0] == 'B') ///////显示贴图
|
|
|
- {
|
|
|
+ else if(strValue[0] == 'B') {
|
|
|
nActiveCamera = CAMERA_TYPE_ERROR;
|
|
|
}
|
|
|
- else if (strValue[0] == 'N')
|
|
|
- {
|
|
|
+ else if (strValue[0] == 'N'){
|
|
|
nActiveCamera = CAMERA_TYPE_ENV;
|
|
|
}
|
|
|
|
|
|
- if (Error_Succeed == GetEntityConfigure()) {
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[LivenessDetectionFSM] Get Entity Configure Success!");
|
|
|
- }
|
|
|
- else {
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[LivenessDetectionFSM] Get Entity Configure Failed!");
|
|
|
- }
|
|
|
-
|
|
|
- m_hWsServerThread = (HANDLE)_beginthreadex(NULL, 0, &start_wsserver, this, 0, NULL);
|
|
|
- if (NULL != m_hWsServerThread) {
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create web socket server success.");
|
|
|
- }
|
|
|
-
|
|
|
return Error;
|
|
|
}
|
|
|
|