|
@@ -1,23 +1,65 @@
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
#include "stdafx.h"
|
|
|
-#include <stdint.h>
|
|
|
+#endif // RVC_OS_WIN
|
|
|
#include "mod_livenessdetection.h"
|
|
|
-#include "videoframework.h"
|
|
|
+#include "../mod_interactivecontrol/Event.h"
|
|
|
|
|
|
//compile with VS2019 bcz jpeg.lib is compiled from VS2010 which lower version.
|
|
|
-#if defined(RVC_OS_WIN)
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
#pragma comment(lib, "legacy_stdio_definitions.lib")
|
|
|
extern "C" {
|
|
|
FILE __iob_func[3] = { *stdin, *stdout, *stderr };
|
|
|
}
|
|
|
#endif //RVC_OS_WIN
|
|
|
|
|
|
-CLivenessDetectionEntity::CLivenessDetectionEntity(): m_bStarted(FALSE), m_nCaptureType(-1)/*, m_pFsm(NULL), m_pCapturer(NULL)*/
|
|
|
+
|
|
|
+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;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+static unsigned int __stdcall start_wsserver(void *arg)
|
|
|
+#else
|
|
|
+static void* start_wsserver(void* arg)
|
|
|
+#endif
|
|
|
+{
|
|
|
+ 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());
|
|
|
+
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ return 0;
|
|
|
+#else
|
|
|
+ return &iRet;
|
|
|
+#endif
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+CLivenessDetectionEntity::CLivenessDetectionEntity()
|
|
|
{
|
|
|
m_WsServer = new RvcWsServer();
|
|
|
m_pFaceVideo = new RvcFaceVideo();
|
|
|
- m_hWsServerThread = NULL;
|
|
|
m_iWsPort = RVC_LIVENESS_WS_PORT;
|
|
|
- m_iCapType = 1;
|
|
|
+
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ m_hWsServerThread = NULL;
|
|
|
+#else
|
|
|
+ m_hWsServerThreadId = 0;
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
CLivenessDetectionEntity::~CLivenessDetectionEntity()
|
|
@@ -27,6 +69,7 @@ CLivenessDetectionEntity::~CLivenessDetectionEntity()
|
|
|
m_WsServer = NULL;
|
|
|
}
|
|
|
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
if (m_pFaceVideo){
|
|
|
delete m_pFaceVideo;
|
|
|
m_pFaceVideo = NULL;
|
|
@@ -38,7 +81,16 @@ CLivenessDetectionEntity::~CLivenessDetectionEntity()
|
|
|
TerminateThread(m_hWsServerThread, exitCode);
|
|
|
m_hWsServerThread = NULL;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+#else
|
|
|
+ pthread_cancel(m_hWsServerThreadId);
|
|
|
+ if (0 == pthread_join(m_hWsServerThreadId, NULL)) {
|
|
|
+ m_hWsServerThreadId = 0;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("thread join web socket server thread failed!");
|
|
|
+ }
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
const char * CLivenessDetectionEntity::GetEntityName() const
|
|
@@ -53,43 +105,22 @@ void CLivenessDetectionEntity::OnPreStart( CAutoArray<CSimpleStringA> strArgs,CS
|
|
|
}
|
|
|
|
|
|
|
|
|
-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 unsigned int __stdcall 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;
|
|
|
- liveness_entity->GetWsServer()->Init_WsServer(&t_callback, &t_param, liveness_entity->GetWsPort());
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
void CLivenessDetectionEntity::OnStarted()
|
|
|
{
|
|
|
if (Error_Succeed != GetEntityConfigure()){
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[LivenessDetectionFSM] Get Entity Configure Failed!");
|
|
|
}
|
|
|
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
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.");
|
|
|
+ if (NULL == m_hWsServerThread){
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create web socket server thread failed.");
|
|
|
+ }
|
|
|
+#else
|
|
|
+ if (0 != pthread_create(&m_hWsServerThreadId, NULL, start_wsserver, (void*)this)) {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create web socket server thread failed.");
|
|
|
}
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
|
|
@@ -111,68 +142,50 @@ ErrorCodeEnum CLivenessDetectionEntity::__OnStart(ErrorCodeEnum preOperationErro
|
|
|
CSmartPointer<IEntityFunction> spFunction = GetFunction();
|
|
|
CSystemStaticInfo stStaticinfo;
|
|
|
spFunction->GetSystemStaticInfo(stStaticinfo);
|
|
|
- if (stricmp(stStaticinfo.strMachineType,"RVC.PAD")==0)
|
|
|
- {
|
|
|
- if (stricmp(stStaticinfo.strSite,"CMB.FLB")==0)
|
|
|
- {
|
|
|
+ if (stricmp(stStaticinfo.strMachineType,"RVC.PAD")==0){
|
|
|
+ if (stricmp(stStaticinfo.strSite,"CMB.FLB")==0){
|
|
|
m_eDeviceType = eMobilePadType;
|
|
|
}
|
|
|
}
|
|
|
- else if (stricmp(stStaticinfo.strMachineType,"RPM.Stand1S")==0)
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("the type is rpm.stand1s");
|
|
|
- m_eDeviceType = eRpm1sType;
|
|
|
- }
|
|
|
- else if (stricmp(stStaticinfo.strMachineType,"RVC.Desk2S")==0)
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("the type is Desk2S");
|
|
|
- m_eDeviceType = eDesk2SType;
|
|
|
+ else if (stricmp(stStaticinfo.strMachineType,"RPM.Stand1SPlus")==0) {
|
|
|
+ m_eDeviceType = eStand1SPlusType;
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("the type is standard");
|
|
|
+ else{
|
|
|
m_eDeviceType = eStand2sType;
|
|
|
}
|
|
|
|
|
|
- if (preOperationError != Error_Succeed)
|
|
|
- return preOperationError;
|
|
|
+ if (m_eDeviceType >= 0 && m_eDeviceType < sizeof(Device_Type_Table) / sizeof(char*)) {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("device type is %s.", Device_Type_Table[m_eDeviceType]);
|
|
|
+ }
|
|
|
|
|
|
ErrorCodeEnum Error = Error_Succeed;
|
|
|
nActiveCamera = CAMERA_TYPE_ENV;
|
|
|
m_iCameraState = 'N';
|
|
|
- BOOL bRet = FALSE;
|
|
|
|
|
|
- if (ePadtype==m_eDeviceType||eMobilePadType==m_eDeviceType||eDesk2SType==m_eDeviceType){
|
|
|
- m_pFaceVideo->InitVideoQueue(REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE, NULL, REC_COMMON_VIDEO_ENV_SHM_PREVIEW_QUEUE, NULL);
|
|
|
- }
|
|
|
- else{
|
|
|
- m_pFaceVideo->InitVideoQueue(REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE, REC_COMMON_VIDEO_OPT_SHM_SNAPSHOT_QUEUE, REC_COMMON_VIDEO_ENV_SHM_PREVIEW_QUEUE, REC_COMMON_VIDEO_OPT_SHM_PREVIEW_QUEUE);
|
|
|
- }
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ InitVideoQueueInfo();
|
|
|
+#endif
|
|
|
|
|
|
int i = 0;
|
|
|
m_arrListener.Init(2);
|
|
|
- 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_Middle, Error_IgnoreAll, LOG_EVT_MEDIACONTROLLER_CAMERA_STARTED, NULL, false);
|
|
|
+ GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_MEDIACONTROLLER_CAMERA_STOPPED, 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')
|
|
|
- {
|
|
|
+ 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;
|
|
|
}
|
|
|
|
|
@@ -181,38 +194,18 @@ ErrorCodeEnum CLivenessDetectionEntity::__OnStart(ErrorCodeEnum preOperationErro
|
|
|
|
|
|
ErrorCodeEnum CLivenessDetectionEntity::__OnClose( ErrorCodeEnum preOperationError )
|
|
|
{
|
|
|
- if (preOperationError != Error_Succeed)
|
|
|
+ if (preOperationError != Error_Succeed) {
|
|
|
return preOperationError;
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
CSmartPointer<IEntityFunction> spFunction = GetFunction();
|
|
|
- for (int i = 0; i < m_arrListener.GetCount(); ++i)
|
|
|
- {
|
|
|
+ for (int i = 0; i < m_arrListener.GetCount(); ++i){
|
|
|
spFunction->UnsubscribeLog(m_arrListener[i]);
|
|
|
}
|
|
|
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
|
|
|
-void CLivenessDetectionEntity::Debug( const char *fmt, ... )
|
|
|
-{
|
|
|
- va_list arg;
|
|
|
- va_start(arg, fmt);
|
|
|
-
|
|
|
- int n = _vscprintf(fmt, arg);
|
|
|
- if (n >= 512) {
|
|
|
- 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[512] = {0};
|
|
|
- _vsnprintf(strlog, 512, fmt, arg);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
|
|
|
- }
|
|
|
- va_end(arg);
|
|
|
-}
|
|
|
-
|
|
|
int CLivenessDetectionEntity::GetActiveCamera()
|
|
|
{
|
|
|
return nActiveCamera;
|
|
@@ -220,7 +213,23 @@ int CLivenessDetectionEntity::GetActiveCamera()
|
|
|
|
|
|
void CLivenessDetectionEntity::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)
|
|
|
+ {
|
|
|
+#ifdef RVC_OS_LINUX
|
|
|
+ case LOG_EVT_MEDIACONTROLLER_CAMERA_STARTED:
|
|
|
+ InitVideoQueueInfo();
|
|
|
+ break;
|
|
|
+
|
|
|
+ case LOG_EVT_MEDIACONTROLLER_CAMERA_STOPPED:
|
|
|
+ if (m_pFaceVideo){
|
|
|
+ delete m_pFaceVideo;
|
|
|
+ m_pFaceVideo = NULL;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+#endif
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void CLivenessDetectionEntity::OnSysVarEvent( const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName )
|
|
@@ -270,6 +279,19 @@ void CLivenessDetectionEntity::OnSelfTest( EntityTestEnum eTestType,CSmartPointe
|
|
|
}
|
|
|
|
|
|
|
|
|
+void CLivenessDetectionEntity::InitVideoQueueInfo()
|
|
|
+{
|
|
|
+ if (!m_pFaceVideo) {
|
|
|
+ m_pFaceVideo = new RvcFaceVideo();
|
|
|
+ }
|
|
|
+ if (eStand1SPlusType == m_eDeviceType || eMobilePadType == m_eDeviceType) {
|
|
|
+ m_pFaceVideo->InitVideoQueue(REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE, NULL, REC_COMMON_VIDEO_ENV_SHM_PREVIEW_QUEUE, NULL);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ m_pFaceVideo->InitVideoQueue(REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE, REC_COMMON_VIDEO_OPT_SHM_SNAPSHOT_QUEUE, REC_COMMON_VIDEO_ENV_SHM_PREVIEW_QUEUE, REC_COMMON_VIDEO_OPT_SHM_PREVIEW_QUEUE);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
int CLivenessDetectionEntity::on_get_videodata(eVideoType eType, eCameraType ecameraid, int* width, int* height, unsigned char* bmpdata, int isize)
|
|
|
{
|
|
@@ -297,19 +319,23 @@ int CLivenessDetectionEntity::on_get_videodata(eVideoType eType, eCameraType eca
|
|
|
qvframe.width = *width;
|
|
|
qvframe.height = *height;
|
|
|
qvframe.data = bmpdata;
|
|
|
- BOOL bRet = FALSE;
|
|
|
+ bool bRet = false;
|
|
|
if (ePreview_Type == eType){
|
|
|
int iPreviewflag = 3;
|
|
|
- if (eCamera_Env == ecameraid && 1 == m_iCapType){
|
|
|
+ #ifdef RVC_OS_WIN
|
|
|
+ if (eCamera_Env == ecameraid){
|
|
|
iPreviewflag = 1;
|
|
|
}
|
|
|
+ #endif
|
|
|
bRet = m_pFaceVideo->GetPreViewVideoFrame((int)ecameraid, &qvframe, iPreviewflag);
|
|
|
}
|
|
|
else{
|
|
|
int iCapflag = 2;
|
|
|
- if (eCamera_Env == ecameraid && 1 == m_iCapType){
|
|
|
+ #ifdef RVC_OS_WIN
|
|
|
+ if (eCamera_Env == ecameraid){
|
|
|
iCapflag = 0;
|
|
|
}
|
|
|
+ #endif
|
|
|
bRet = m_pFaceVideo->GetVideoFrame((int)ecameraid, &qvframe, iCapflag);
|
|
|
}
|
|
|
|
|
@@ -324,7 +350,6 @@ int CLivenessDetectionEntity::on_get_videodata(eVideoType eType, eCameraType eca
|
|
|
return idatalen;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
ErrorCodeEnum CLivenessDetectionEntity::GetEntityConfigure()
|
|
|
{
|
|
|
CSmartPointer<IConfigInfo> spConfig;
|
|
@@ -344,5 +369,5 @@ ErrorCodeEnum CLivenessDetectionEntity::GetEntityConfigure()
|
|
|
|
|
|
|
|
|
SP_BEGIN_ENTITY_MAP()
|
|
|
-SP_ENTITY(CLivenessDetectionEntity)
|
|
|
+ SP_ENTITY(CLivenessDetectionEntity)
|
|
|
SP_END_ENTITY_MAP()
|