From 50ec9ea795a91869880110d1a0c07eccb1684689 Mon Sep 17 00:00:00 2001 From: Evgeny Gagua Date: Tue, 27 Dec 2022 17:30:24 +0000 Subject: [PATCH] Event Filter Train Added --- Projects/la_mojo/la_mojo.vpj | 1 + Projects/la_mojo/makefile | 49 +++-- lib/App/common/MySQL_dataBinder.cpp | 42 ++-- lib/App/common/SQLite_dataBinder.cpp | 218 +++++++++++++++++-- lib/App/common/SQLite_dataBinder.h | 4 +- lib/App/common/dataBinder.h | 3 +- lib/App/common/dataBinder_structures.h | 28 ++- lib/App/common/deviceNodeCamera.cpp | 21 +- lib/App/common/deviceNodePTZCamControl.cpp | 32 --- lib/App/common/hardwareManager.cpp | 46 ++-- lib/App/common/kernelEventFilter.cpp | 64 ++++-- lib/App/common/kernelEventFilter.h | 22 +- lib/App/common/kernelEventFilterAPF.cpp | 16 +- lib/App/common/kernelEventFilterTrain.cpp | 198 +++++++++++++++++ lib/App/common/kernelEventFilterTrain.h | 34 +++ lib/App/common/kernelModuleEmbedVideo.cpp | 164 ++++++++++---- lib/App/common/kernelModuleEmbedVideo.h | 2 +- lib/App/common/kernelModuleOnvifObserver.cpp | 16 +- lib/components/base/basicEvent.h | 17 +- lib/components/base/basicFunctionality.cpp | 10 + lib/components/base/basicFunctionality.h | 5 +- lib/data/media/video/videoAVLIBSource.cpp | 2 +- lib/rgoose/rgooseTypes.h | 5 +- 23 files changed, 763 insertions(+), 236 deletions(-) create mode 100644 lib/App/common/kernelEventFilterTrain.cpp create mode 100644 lib/App/common/kernelEventFilterTrain.h diff --git a/Projects/la_mojo/la_mojo.vpj b/Projects/la_mojo/la_mojo.vpj index 728ec946..9ec8f319 100644 --- a/Projects/la_mojo/la_mojo.vpj +++ b/Projects/la_mojo/la_mojo.vpj @@ -421,6 +421,7 @@ + diff --git a/Projects/la_mojo/makefile b/Projects/la_mojo/makefile index 2766e800..9b3ab9ef 100644 --- a/Projects/la_mojo/makefile +++ b/Projects/la_mojo/makefile @@ -51,10 +51,10 @@ COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ - $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelModule.o \ - $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ - $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ - $(OUTDIR)/kernelModuleModemManager.o \ + $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterTrain.o \ + $(OUTDIR)/kernelModule.o $(OUTDIR)/kernelModuleEmbedVideo.o \ + $(OUTDIR)/kernelModuleFactory.o $(OUTDIR)/kernelModuleFlyHunter.o \ + $(OUTDIR)/kernelModuleKafka.o $(OUTDIR)/kernelModuleModemManager.o \ $(OUTDIR)/kernelModuleOnvifObserver.o $(OUTDIR)/kernelModuleSSDP.o \ $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ @@ -97,10 +97,10 @@ ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ - $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelModule.o \ - $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ - $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ - $(OUTDIR)/kernelModuleModemManager.o \ + $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterTrain.o \ + $(OUTDIR)/kernelModule.o $(OUTDIR)/kernelModuleEmbedVideo.o \ + $(OUTDIR)/kernelModuleFactory.o $(OUTDIR)/kernelModuleFlyHunter.o \ + $(OUTDIR)/kernelModuleKafka.o $(OUTDIR)/kernelModuleModemManager.o \ $(OUTDIR)/kernelModuleOnvifObserver.o $(OUTDIR)/kernelModuleSSDP.o \ $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ @@ -231,10 +231,10 @@ COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ - $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelModule.o \ - $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ - $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ - $(OUTDIR)/kernelModuleModemManager.o \ + $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterTrain.o \ + $(OUTDIR)/kernelModule.o $(OUTDIR)/kernelModuleEmbedVideo.o \ + $(OUTDIR)/kernelModuleFactory.o $(OUTDIR)/kernelModuleFlyHunter.o \ + $(OUTDIR)/kernelModuleKafka.o $(OUTDIR)/kernelModuleModemManager.o \ $(OUTDIR)/kernelModuleOnvifObserver.o $(OUTDIR)/kernelModuleSSDP.o \ $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ @@ -277,10 +277,10 @@ ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ - $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelModule.o \ - $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ - $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ - $(OUTDIR)/kernelModuleModemManager.o \ + $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterTrain.o \ + $(OUTDIR)/kernelModule.o $(OUTDIR)/kernelModuleEmbedVideo.o \ + $(OUTDIR)/kernelModuleFactory.o $(OUTDIR)/kernelModuleFlyHunter.o \ + $(OUTDIR)/kernelModuleKafka.o $(OUTDIR)/kernelModuleModemManager.o \ $(OUTDIR)/kernelModuleOnvifObserver.o $(OUTDIR)/kernelModuleSSDP.o \ $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ @@ -411,10 +411,10 @@ COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ - $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelModule.o \ - $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ - $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ - $(OUTDIR)/kernelModuleModemManager.o \ + $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterTrain.o \ + $(OUTDIR)/kernelModule.o $(OUTDIR)/kernelModuleEmbedVideo.o \ + $(OUTDIR)/kernelModuleFactory.o $(OUTDIR)/kernelModuleFlyHunter.o \ + $(OUTDIR)/kernelModuleKafka.o $(OUTDIR)/kernelModuleModemManager.o \ $(OUTDIR)/kernelModuleOnvifObserver.o $(OUTDIR)/kernelModuleSSDP.o \ $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ @@ -457,10 +457,10 @@ ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ - $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelModule.o \ - $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ - $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ - $(OUTDIR)/kernelModuleModemManager.o \ + $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterTrain.o \ + $(OUTDIR)/kernelModule.o $(OUTDIR)/kernelModuleEmbedVideo.o \ + $(OUTDIR)/kernelModuleFactory.o $(OUTDIR)/kernelModuleFlyHunter.o \ + $(OUTDIR)/kernelModuleKafka.o $(OUTDIR)/kernelModuleModemManager.o \ $(OUTDIR)/kernelModuleOnvifObserver.o $(OUTDIR)/kernelModuleSSDP.o \ $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ @@ -608,6 +608,7 @@ $(OUTDIR)/json_value.o: ../../lib/data/json/json_value.cpp ../../lib/data/json/j $(OUTDIR)/json_writer.o: ../../lib/data/json/json_writer.cpp ../../lib/data/json/json_tool.h $(OUTDIR)/kernelEventFilter.o: ../../lib/App/common/kernelEventFilter.cpp ../../lib/App/common/kernelEventFilter.h $(OUTDIR)/kernelEventFilterAPF.o: ../../lib/App/common/kernelEventFilterAPF.cpp ../../lib/App/common/kernelEventFilterAPF.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h +$(OUTDIR)/kernelEventFilterTrain.o: ../../lib/App/common/kernelEventFilterTrain.cpp ../../lib/App/common/kernelEventFilterTrain.h $(OUTDIR)/kernelModule.o: ../../lib/App/common/kernelModule.cpp ../../lib/App/common/kernelModule.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h $(OUTDIR)/kernelModuleEmbedVideo.o: ../../lib/App/common/kernelModuleEmbedVideo.cpp ../../lib/App/common/kernelModuleEmbedVideo.h $(OUTDIR)/kernelModuleFactory.o: ../../lib/App/common/kernelModuleFactory.cpp ../../lib/App/common/kernelModuleFactory.h ../../lib/App/common/kernelModuleUSBRelay.h ../../lib/App/common/kernelModuleKafka.h ../../lib/App/common/kernelModuleFlyHunter.h ../../lib/App/common/kernelModuleSSDP.h ../../lib/App/common/kernelModuleOnvifObserver.h ../../lib/App/common/kernelModuleEmbedVideo.h ../../lib/App/common/kernelModuleModemManager.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h diff --git a/lib/App/common/MySQL_dataBinder.cpp b/lib/App/common/MySQL_dataBinder.cpp index 68372b2d..ffa74698 100644 --- a/lib/App/common/MySQL_dataBinder.cpp +++ b/lib/App/common/MySQL_dataBinder.cpp @@ -662,30 +662,26 @@ bool mysqlDBC::getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR ){ if( it != cArr->end() ){ tVal->id = atoi( it->second.c_str() ); }; - it = cArr->find("site_id"); - if( it != cArr->end() ){ - tVal->site_id = atoi( it->second.c_str() ); - }; - it = cArr->find("node_id"); + it = cArr->find("type"); if( it != cArr->end() ){ - tVal->node_id = atoi( it->second.c_str() ); + tVal->type = atoi( it->second.c_str() ); }; it = cArr->find("online"); if( it != cArr->end() ){ tVal->online = (bool) atoi( it->second.c_str() ); }; - it = cArr->find("type"); + it = cArr->find("stream_id"); if( it != cArr->end() ){ - tVal->type = atoi( it->second.c_str() ); - }; - it = cArr->find("name"); - if( it != cArr->end() ){ - strncpy( tVal->name, it->second.c_str(), 64 ); + tVal->stream_id = atoi( it->second.c_str() ); }; it = cArr->find("hardware"); if( it != cArr->end() ){ strncpy( tVal->hardware, it->second.c_str(), 32 ); }; + it = cArr->find("name"); + if( it != cArr->end() ){ + strncpy( tVal->name, it->second.c_str(), 64 ); + }; it = cArr->find("status"); if( it != cArr->end() ){ tVal->status = atoi( it->second.c_str() ); @@ -1676,7 +1672,7 @@ DBC_TARGET_FLITER_DATA *mysqlDBC::getTargetFilterData( uint32_t ID ){ cArr = result->at(0); it = cArr->find("type"); if( it != cArr->end() ){ - tVal->type = atoi( it->second.c_str() ); + tVal->type = (TARGET_FILTER_TYPE) atoi( it->second.c_str() ); }; it = cArr->find("aux_id"); if( it != cArr->end() ){ @@ -2551,30 +2547,26 @@ DBC_CAM_DATA *mysqlDBC::getCamData( uint32_t ID ){ tVal->id = ID; Assoc::iterator it; cArr = result->at(0); - it = cArr->find("site_id"); - if( it != cArr->end() ){ - tVal->site_id = atoi( it->second.c_str() ); - }; - it = cArr->find("node_id"); + it = cArr->find("type"); if( it != cArr->end() ){ - tVal->node_id = atoi( it->second.c_str() ); + tVal->type = atoi( it->second.c_str() ); }; it = cArr->find("online"); if( it != cArr->end() ){ tVal->online = (bool) atoi( it->second.c_str() ); }; - it = cArr->find("type"); - if( it != cArr->end() ){ - tVal->type = atoi( it->second.c_str() ); - }; - it = cArr->find("name"); + it = cArr->find("stream_id"); if( it != cArr->end() ){ - strncpy( tVal->name, it->second.c_str(), 64 ); + tVal->stream_id = atoi( it->second.c_str() ); }; it = cArr->find("hardware"); if( it != cArr->end() ){ strncpy( tVal->hardware, it->second.c_str(), 32 ); }; + it = cArr->find("name"); + if( it != cArr->end() ){ + strncpy( tVal->name, it->second.c_str(), 64 ); + }; it = cArr->find("status"); if( it != cArr->end() ){ tVal->status = atoi( it->second.c_str() ); diff --git a/lib/App/common/SQLite_dataBinder.cpp b/lib/App/common/SQLite_dataBinder.cpp index ec90767a..e466332d 100644 --- a/lib/App/common/SQLite_dataBinder.cpp +++ b/lib/App/common/SQLite_dataBinder.cpp @@ -132,7 +132,7 @@ bool sqliteDBC::connect( void ){ if( !fileExist( m_pDbMemory )) { bRecreateMemStructures = true; //Always recreate - //unlink( m_pDbMemory ); + unlink( m_pDbMemory ); }; m_pDataMemory = new SQLite_Connector(); if ( m_pDataMemory ) { @@ -143,6 +143,7 @@ bool sqliteDBC::connect( void ){ #endif chown( m_pDbMemory, web_access_user, web_access_group ); chmod( m_pDbMemory, 0664 ); + m_pDataMemory->SilentQuery("PRAGMA journal_mode=WAL"); //Recreate at Register Server //if ( bRecreateMemStructures ) initMemDB(); } else{ @@ -159,8 +160,8 @@ bool sqliteDBC::connect( void ){ }; void sqliteDBC::initMemDB( uint32_t sid ){ -m_pDataMemory->Query("DROP TABLE \"nodes_qcq\""); -m_pDataMemory->Query("CREATE TABLE \"nodes_qcq\" ( \ +m_pDataMemory->SilentQuery("DROP TABLE \"nodes_qcq\""); +m_pDataMemory->SilentQuery("CREATE TABLE \"nodes_qcq\" ( \ \"id\" INTEGER NOT NULL,\ \"node_id\" INTEGER NOT NULL,\ \"cmd\" INTEGER NOT NULL,\ @@ -168,8 +169,8 @@ m_pDataMemory->Query("CREATE TABLE \"nodes_qcq\" ( \ \"parameter\" TEXT,\ PRIMARY KEY(\"id\" AUTOINCREMENT)\ );"); -m_pDataMemory->Query("DROP TABLE \"servers\""); -m_pDataMemory->Query("CREATE TABLE \"servers\" (\ +m_pDataMemory->SilentQuery("DROP TABLE \"servers\""); +m_pDataMemory->SilentQuery("CREATE TABLE \"servers\" (\ \"id\" INTEGER NOT NULL,\ \"ts\" INTEGER DEFAULT 0,\ \"pid\" INTEGER DEFAULT 0,\ @@ -190,7 +191,7 @@ m_pDataMemory->Query("CREATE TABLE \"servers\" (\ );"); char tB[128]; sprintf( tB, "INSERT INTO `servers` (`id`,`ts`) VALUES (%d, strftime('%%s') )", sid ); -m_pDataMemory->Query( tB ); +m_pDataMemory->SilentQuery( tB ); }; @@ -393,7 +394,7 @@ bool sqliteDBC::addIPCam( OBSERVER_RESULT *tPtr ){ LOG_ERROR("Pos 0 - err"); tIpBuf[0] = (char)0; }; - sprintf(tQBuf,"INSERT INTO cameras (`online`,`uuid`,`onvif_ctrl`,`ip`,`type`,`status`,`mac`,`hardware`,`name`,`onvif_access`) VALUES (1,'%s','%s','%s',2,0,'%s','%s','%s','%s') ON CONFLICT(`uuid`) DO UPDATE SET `online`=1, `ip`='%s'", + sprintf(tQBuf,"INSERT INTO cameras (`online`,`uuid`,`onvif_ctrl`,`ip`,`type`,`status`,`mac`,`hardware`,`name`,`onvif_access`) VALUES (1,'%s','%s','%s',12,0,'%s','%s','%s','%s') ON CONFLICT(`uuid`) DO UPDATE SET `online`=1, `ip`='%s'", tPtr->RefID, //tPtr->XAddrs, tPath, @@ -414,7 +415,7 @@ bool sqliteDBC::addIPCam( OBSERVER_RESULT *tPtr ){ return false; }; -uint32_t sqliteDBC::addLocalCam( CSTR name, CSTR hardware, CSTR path, uint32_t width, uint32_t height ){ +uint32_t sqliteDBC::addLocalCam( CSTR name, CSTR hardware, CSTR path, uint32_t width, uint32_t height, uint16_t fps, uint16_t den ){ uint32_t RetVal = 0; if( m_bIsConnected ) { char tQBuf[1024]; @@ -426,7 +427,7 @@ uint32_t sqliteDBC::addLocalCam( CSTR name, CSTR hardware, CSTR path, uint32_t w tM5[32]=(char)0; free( tMD5 ); - sprintf(tQBuf,"INSERT INTO cameras (`online`,`uuid`,`type`,`status`,`hardware`,`name`,`ip`) VALUES (1,'%s',0,0,'%s','%s','%s') ON CONFLICT(`uuid`) DO UPDATE SET `online`=1", + sprintf(tQBuf,"INSERT INTO cameras (`online`,`uuid`,`type`,`status`,`hardware`,`name`,`ip`) VALUES (1,'%s',10,0,'%s','%s','%s') ON CONFLICT(`uuid`) DO UPDATE SET `online`=1", tM5, hardware, name, @@ -439,8 +440,8 @@ uint32_t sqliteDBC::addLocalCam( CSTR name, CSTR hardware, CSTR path, uint32_t w if ( camID == 0 ) { camID = getCamId( tM5 ); }; - sprintf(tQBuf, "INSERT INTO `media_streams`(`source_id`,`source_type`,`valid`,`name`,`token`,`img_width`,`img_height`,`mrl_proto`,`mrl`,`picture_proto`) VALUES(%d,'A',1,'%s','%s',%d,%d,'v4l2','%s','v4l2') ON CONFLICT(`source_id`,`token`) DO UPDATE SET `valid`=1, img_width=%d, img_height=%d", - camID, name, tM5, width, height, path, width, height ); + sprintf(tQBuf, "INSERT INTO `media_streams`(`source_id`,`source_type`,`valid`,`name`,`token`,`img_width`,`img_height`,`mrl_proto`,`mrl`,`picture_proto`,`fps`) VALUES(%d,'A',1,'%s','%s',%d,%d,'v4l2','%s','v4l2',%d) ON CONFLICT(`source_id`,`token`) DO UPDATE SET `valid`=1, img_width=%d, img_height=%d, `fps`=%d", + camID, name, tM5, width, height, path, fps, width, height, fps ); #ifdef DEBUG_EXTRA LOG(tQBuf); #endif @@ -662,6 +663,141 @@ uint32_t sqliteDBC::addResource( uint8_t type, CSTR devName, uint32_t auxID ){ return RetVal; }; +DBC_MODULE_EMBED_VIDEO_DATA *sqliteDBC::getEmbedVideoData( uint32_t ID ){ + DBC_MODULE_EMBED_VIDEO_DATA *tPtr = NULL; + if( m_bIsConnected ) { + char tQBuf[MAX_PATH_LEN]; + AAssoc *result; + sprintf( tQBuf, "SELECT * FROM `module_eve` WHERE `id`=%d", ID ); +#ifdef DEBUG_ALL + LOG(tQBuf); +#endif + result = m_pDataStorage->Query( tQBuf ); + if( result!= NULL ) { + if( result->size() > 0 ) { + Assoc *cArr; + tPtr = (DBC_MODULE_EMBED_VIDEO_DATA*)malloc(sizeof(DBC_MODULE_EMBED_VIDEO_DATA)); + if( tPtr!= NULL ) { + Assoc::iterator it; + memset(tPtr,0,sizeof(DBC_MODULE_EMBED_VIDEO_DATA)); + cArr = result->at(0); + it = cArr->find("output_mode"); + if( it != cArr->end() ){ + tPtr->output_mode = atoi( it->second.c_str() ); + }; + it = cArr->find("web_port"); + if( it != cArr->end() ){ + tPtr->port = atoi( it->second.c_str() ); + }; + it = cArr->find("width"); + if( it != cArr->end() ){ + tPtr->width = atoi( it->second.c_str() ); + }; + it = cArr->find("height"); + if( it != cArr->end() ){ + tPtr->height = atoi( it->second.c_str() ); + }; + it = cArr->find("compression_quality"); + if( it != cArr->end() ){ + tPtr->compression_quality = atoi( it->second.c_str() ); + }; + it = cArr->find("show_ts"); + if( it != cArr->end() ){ + tPtr->show_ts = (bool)atoi( it->second.c_str() ); + }; + it = cArr->find("ts_x"); + if( it != cArr->end() ){ + tPtr->ts_x = atoi( it->second.c_str() ); + }; + it = cArr->find("ts_y"); + if( it != cArr->end() ){ + tPtr->ts_y = atoi( it->second.c_str() ); + }; + it = cArr->find("ts_font_face"); + if( it != cArr->end() ){ + tPtr->ts_font_face = atoi( it->second.c_str() ); + }; + it = cArr->find("ts_font_scale"); + if( it != cArr->end() ){ + tPtr->ts_font_scale = atof( it->second.c_str() ); + }; + it = cArr->find("ts_font_thickness"); + if( it != cArr->end() ){ + tPtr->ts_font_thickness = atoi( it->second.c_str() ); + }; + it = cArr->find("ts_line_type"); + if( it != cArr->end() ){ + tPtr->ts_line_type = atoi( it->second.c_str() ); + }; + it = cArr->find("ts_transperant"); + if( it != cArr->end() ){ + tPtr->ts_transperant = (bool)atoi( it->second.c_str() ); + }; + it = cArr->find("show_label"); + if( it != cArr->end() ){ + tPtr->show_label = (bool)atoi( it->second.c_str() ); + }; + it = cArr->find("label_x"); + if( it != cArr->end() ){ + tPtr->label_x = atoi( it->second.c_str() ); + }; + it = cArr->find("label_y"); + if( it != cArr->end() ){ + tPtr->label_y = atoi( it->second.c_str() ); + }; + it = cArr->find("label_font_face"); + if( it != cArr->end() ){ + tPtr->label_font_face = atoi( it->second.c_str() ); + }; + it = cArr->find("label_font_scale"); + if( it != cArr->end() ){ + tPtr->label_font_scale = atof( it->second.c_str() ); + }; + it = cArr->find("label_font_thickness"); + if( it != cArr->end() ){ + tPtr->label_font_thickness = atoi( it->second.c_str() ); + }; + it = cArr->find("label_line_type"); + if( it != cArr->end() ){ + tPtr->label_line_type = atoi( it->second.c_str() ); + }; + it = cArr->find("label_transperant"); + if( it != cArr->end() ){ + tPtr->label_transperant = (bool) atoi( it->second.c_str() ); + }; + it = cArr->find("show_logo"); + if( it != cArr->end() ){ + tPtr->show_logo = (bool) atoi( it->second.c_str() ); + }; + it = cArr->find("logo_w"); + if( it != cArr->end() ){ + tPtr->logo_w = atoi( it->second.c_str() ); + }; + it = cArr->find("logo_h"); + if( it != cArr->end() ){ + tPtr->logo_h = atoi( it->second.c_str() ); + }; + it = cArr->find("logo_x"); + if( it != cArr->end() ){ + tPtr->logo_x = atoi( it->second.c_str() ); + }; + it = cArr->find("logo_y"); + if( it != cArr->end() ){ + tPtr->logo_y = atoi( it->second.c_str() ); + }; + it = cArr->find("logo_md5"); + if( it != cArr->end() ){ + strncpy( tPtr->logo_md5, it->second.c_str(),32); + tPtr->logo_md5[32]=(char)0; + }; + }; + }; + }; + deleteResult( result ); + }; + return tPtr; +}; + DBC_MEDIA_STREAM_DATA *sqliteDBC::getMediaStreamData(uint32_t ID){ DBC_MEDIA_STREAM_DATA *tVal = NULL; if(m_bIsConnected){ @@ -1149,6 +1285,46 @@ uint32_t sqliteDBC::getWiFi_ID( uint32_t nif_id ){ return tVal; }; +DBC_INT_LIST *sqliteDBC::listMediaStreams( uint32_t SiteId, uint8_t listMode ){ + DBC_INT_LIST * tVal = NULL; + if(m_bIsConnected){ + char tQBuf[CTEXT]; + AAssoc *result; + switch( listMode ){ + case LIST_VALID_RECORDS: + sprintf(tQBuf, "SELECT `ms`.`id` FROM `nodes` `nd` LEFT JOIN `media_streams` `ms` ON (`ms`.`id`=`nd`.`aux_parameter`) WHERE `nd`.`type` IN (10,11,12,13) AND `ms`.`valid`=1 AND `nd`.`online`=1" ); + break; + case LIST_INVALID_RECORDS: + sprintf(tQBuf, "SELECT `ms`.`id` FROM `nodes` `nd` LEFT JOIN `media_streams` `ms` ON (`ms`.`id`=`nd`.`aux_parameter`) WHERE `nd`.`type` IN (10,11,12,13) AND `ms`.`valid`=1 AND `nd`.`online`=0" ); + break; + default: + sprintf(tQBuf, "SELECT `ms`.`id` FROM `nodes` `nd` LEFT JOIN `media_streams` `ms` ON (`ms`.`id`=`nd`.`aux_parameter`) WHERE `nd`.`type` IN (10,11,12,13) AND `ms`.`valid`=1" ); + }; +#ifdef DEBUG_ALL + LOG(tQBuf); +#endif + result = m_pDataStorage->Query( tQBuf ); + if( result!= NULL ) { + if( result->size() > 0 ) { + Assoc *cArr; + tVal = new DBC_INT_LIST(); + if( tVal != NULL ) { + Assoc::iterator it; + for(int i=0;isize();i++) { + cArr = result->at(i); + it = cArr->find("id"); + if( it != cArr->end() ){ + tVal->push_back( atoi( it->second.c_str() )); + }; + }; + }; + }; + }; + deleteResult( result ); + }; + return tVal; +}; + DBC_INT_LIST *sqliteDBC::listModules(){ DBC_INT_LIST * tVal = NULL; if(m_bIsConnected){ @@ -1485,30 +1661,26 @@ DBC_CAM_DATA *sqliteDBC::getCamData( uint32_t ID ){ tVal->id = ID; Assoc::iterator it; cArr = result->at(0); - it = cArr->find("site_id"); - if( it != cArr->end() ){ - tVal->site_id = atoi( it->second.c_str() ); - }; - it = cArr->find("node_id"); + it = cArr->find("type"); if( it != cArr->end() ){ - tVal->node_id = atoi( it->second.c_str() ); + tVal->type = atoi( it->second.c_str() ); }; it = cArr->find("online"); if( it != cArr->end() ){ tVal->online = (bool) atoi( it->second.c_str() ); }; - it = cArr->find("type"); - if( it != cArr->end() ){ - tVal->type = atoi( it->second.c_str() ); - }; - it = cArr->find("name"); + it = cArr->find("stream_id"); if( it != cArr->end() ){ - strncpy( tVal->name, it->second.c_str(), 64 ); + tVal->stream_id = atoi( it->second.c_str() ); }; it = cArr->find("hardware"); if( it != cArr->end() ){ strncpy( tVal->hardware, it->second.c_str(), 32 ); }; + it = cArr->find("name"); + if( it != cArr->end() ){ + strncpy( tVal->name, it->second.c_str(), 64 ); + }; it = cArr->find("status"); if( it != cArr->end() ){ tVal->status = atoi( it->second.c_str() ); diff --git a/lib/App/common/SQLite_dataBinder.h b/lib/App/common/SQLite_dataBinder.h index 95d37a7c..9b14ee82 100644 --- a/lib/App/common/SQLite_dataBinder.h +++ b/lib/App/common/SQLite_dataBinder.h @@ -42,7 +42,7 @@ class sqliteDBC: public dataBinder { virtual bool isLocal( void ) const { return true; }; virtual bool addDeviceDraw( uint32_t DBID, uint8_t type, uint8_t lrf, void *th_data, uint32_t th_size ); virtual bool addIPCam( OBSERVER_RESULT *tPtr ); - virtual uint32_t addLocalCam( CSTR name, CSTR hardware, CSTR path, uint32_t width, uint32_t height ); + virtual uint32_t addLocalCam( CSTR name, CSTR hardware, CSTR path, uint32_t width, uint32_t height, uint16_t fps, uint16_t den = 1 ); virtual uint32_t addLocalNetwork( uint32_t NIF_ID, NETWORK_TYPE net_type, CSTR address, CSTR mask, CSTR gateway, CSTR broadcast ); virtual uint32_t addLocalNetworkInfrastructure( uint32_t NIF_ID, uint32_t OUTBOUND_NIF, bool ena_dhcp=false, CSTR BRANG=NULL, CSTR ERANG=NULL, CSTR MASK=NULL, CSTR LEASE_TIME=NULL ); virtual uint32_t addLocalNIF( CSTR device, CSTR mac, NIF_TYPE dtype, NIF_MODE dmode, uint32_t aux_id = 0 ); @@ -52,6 +52,7 @@ class sqliteDBC: public dataBinder { virtual bool cleanNodePushedCMD( void ); virtual DBC_CAM_DATA * getCamData( uint32_t CamID ); virtual uint32_t getCamId( CSTR UUID ); + virtual DBC_MODULE_EMBED_VIDEO_DATA * getEmbedVideoData( uint32_t ID ); virtual DBC_MODULE_DATA * getModuleData( uint32_t ID ); virtual DBC_MEDIA_STREAM_DATA * getMediaStreamData(uint32_t ID); virtual uint32_t getMediaStreamID( uint32_t source_id, CSTR token ); @@ -68,6 +69,7 @@ class sqliteDBC: public dataBinder { virtual uint32_t getServerNode( uint32_t SID ); virtual uint32_t getUartID( uint32_t NodeID, uint8_t Type, CSTR path ); + virtual DBC_INT_LIST * listMediaStreams( uint32_t SiteId, uint8_t listingType = LIST_ALL_RECORDS ); virtual DBC_INT_LIST * listModules(); virtual DBC_INT_LIST * listNewModules( DBC_INT_LIST * old_ids ); virtual DBC_INT_LIST * listNewNodes( DBC_INT_LIST * old_ids ); diff --git a/lib/App/common/dataBinder.h b/lib/App/common/dataBinder.h index 5bf1dd69..8f459993 100644 --- a/lib/App/common/dataBinder.h +++ b/lib/App/common/dataBinder.h @@ -24,7 +24,7 @@ class dataBinder{ virtual bool addIPCam( OBSERVER_RESULT *tPtr ){ return false;}; virtual uint32_t addLocalMediaSource( uint32_t SiteID, CSTR path, uint32_t width, uint32_t height ){ return 0;}; virtual uint32_t addLocalDCB( uint32_t SiteID, CSTR PATH, CSTR SERIAL, uint8_t CNT, uint32_t status ){ return 0;}; - virtual uint32_t addLocalCam( CSTR name, CSTR hardware, CSTR path, uint32_t width, uint32_t height ){ return 0;}; + virtual uint32_t addLocalCam( CSTR name, CSTR hardware, CSTR path, uint32_t width, uint32_t height, uint16_t fps, uint16_t den = 1 ){ return 0;}; virtual uint32_t addLocalUART( /*uint32_t NodeID,*/ uint8_t utype, uint32_t speed, uint8_t bit, char parity, float stop_bit, CSTR PATH, uint8_t mode=0, uint16_t port=0 ){ return 0;}; virtual uint32_t addLocalNIF( CSTR device, CSTR mac, NIF_TYPE dtype, NIF_MODE dmode, uint32_t aux_id = 0 ){ return 0;}; virtual uint32_t addLocalNetwork( uint32_t NIF_ID, NETWORK_TYPE net_type, CSTR address, CSTR mask, CSTR gateway, CSTR broadcast ){ return 0;}; @@ -117,6 +117,7 @@ class dataBinder{ virtual DBC_SITE_DATA * getSiteData( uint32_t ID ){ return NULL;}; //virtual DBC_SOCKET_DATA * getSocketData( uint32_t ID ){ return NULL;}; virtual DBC_TARGET_FLITER_DATA * getTargetFilterData( uint32_t ID ){ return NULL;}; + virtual TRAIN_FILTER_DATA * getTrainFilterData( uint32_t ID ){ return NULL; }; virtual DBC_UART_DATA * getUartData( uint32_t UartID ){ return NULL;}; virtual uint32_t getUartID( uint32_t NodeID, uint8_t Type, CSTR path ){ return 0;}; virtual uint32_t getWiFi_ID( uint32_t nif_id ){ return 0;}; diff --git a/lib/App/common/dataBinder_structures.h b/lib/App/common/dataBinder_structures.h index 715c5f17..600cb938 100644 --- a/lib/App/common/dataBinder_structures.h +++ b/lib/App/common/dataBinder_structures.h @@ -175,8 +175,7 @@ typedef enum E_CAM_TRIGGER_MODE{ typedef struct S_DBC_CAM_DATA{ uint32_t id; - uint32_t site_id; - uint32_t node_id; + uint32_t stream_id; bool online; uint8_t type; char name[65]; @@ -519,13 +518,18 @@ typedef struct S_DBC_FH_DATA{ uint32_t uart_id; }DBC_FH_DATA; +typedef enum E_TARGET_FILTER_TYPE{ + TF_UDEFINED_FILTER = 0, + TF_AUTHORISED_PEOPLE_FILTER = 1, + TF_LA_METRO_TRAIN_FILTER = 2 +}TARGET_FILTER_TYPE; + typedef struct S_DBC_TARGET_FLITER_DATA{ - uint32_t id; - uint8_t type; - uint32_t aux_id; + uint32_t id; + TARGET_FILTER_TYPE type; + uint32_t aux_id; }DBC_TARGET_FLITER_DATA; - typedef struct S_DBC_APF_DATA{ uint16_t port; char mode[3]; @@ -643,4 +647,16 @@ typedef struct S_DBC_SSDP_SETTINGS{ }DBC_SSDP_SETTINGS; +typedef struct S_TRAIN_FILTER_DATA{ + uint8_t bZoneCount; + uint32_t nUpperSensorID; + uint32_t nBottomSensorID; + bool bDebugMode; + bool bDetectTrain; + bool bTrackTrain; + uint32_t nTrainWidth; + uint32_t nDecisionTime; + uint32_t nSuspectTime; +}TRAIN_FILTER_DATA; + #endif \ No newline at end of file diff --git a/lib/App/common/deviceNodeCamera.cpp b/lib/App/common/deviceNodeCamera.cpp index 5dc52721..17554c9e 100644 --- a/lib/App/common/deviceNodeCamera.cpp +++ b/lib/App/common/deviceNodeCamera.cpp @@ -282,9 +282,9 @@ bool deviceNodeCamera::create(){ #ifdef DEBUG char tB[128]; - sprintf( tB, "Finalized Sensor Location: Lat:%.3f Lon:%.3f Alt:%.3f", m_oPosition.getLat(), m_oPosition.getLon(), m_oPosition.getAlt() ); + sprintf( tB, "Finalized Camera Location: Lat:%.3f Lon:%.3f Alt:%.3f", m_oPosition.getLat(), m_oPosition.getLon(), m_oPosition.getAlt() ); LOG( tB ); - sprintf( tB, "Finalized Sensor Location: x:%.3f y:%.3f z:%.3f", m_oPosition.getX(), m_oPosition.getY(), m_oPosition.getZ() ); + sprintf( tB, "Finalized Camera Location: x:%.3f y:%.3f z:%.3f", m_oPosition.getX(), m_oPosition.getY(), m_oPosition.getZ() ); LOG( tB ); sprintf( tB, "Orientation: x:%.3f y:%.3f z:%.3f", m_oPosition.getRotX_deg(), m_oPosition.getRotY_deg(), m_oPosition.getRotZ_deg() ); LOG( tB ); @@ -849,7 +849,7 @@ void deviceNodeCamera::m_fThreadProc( void ){ setWM( CAM_WS_READY ); break; }; - if( m_nRelativeMoveCounter > 10 ) { + if( m_nRelativeMoveCounter > 5 ) { m_nRelativeMoveCounter = 0; setWM( CAM_WS_READY ); }; @@ -876,7 +876,7 @@ void deviceNodeCamera::m_fThreadProc( void ){ if ( m_pCurrentROI != NULL ) { if( m_pBEH ){ EVENT_CONTAINER *tEVT = createBasicEvent( - m_sCamData.node_id, + m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_MOVE_TO, NULL, NULL, NULL ); @@ -899,7 +899,7 @@ void deviceNodeCamera::m_fThreadProc( void ){ if( tData != NULL ) { if( m_pBEH ){ EVENT_CONTAINER *tEVT = createBasicEvent( - m_sCamData.node_id, + m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_ON_POSITION, NULL, NULL, tData ); @@ -1015,11 +1015,20 @@ void deviceNodeCamera::m_fThreadProc( void ){ */ m_pCurrentROI = fusion_fetchROI(); if( m_pCurrentROI != NULL ) { +#ifdef DEBUG_EXTRA__ + LOG("HAVE ROI to see!"); +#endif setWM( CAM_WS_GO_ABS_POSITION ); } else { // Lowest Priority to Web Client Commands - PUSHED = m_pDBC->getNodePushedCMD( m_sCamData.node_id ); +#ifdef DEBUG_EXTRA__ + LOG("Check Web CMD!"); +#endif + PUSHED = m_pDBC->getNodePushedCMD( m_sNodeData.node_id ); if( PUSHED != NULL ) { +#ifdef DEBUG_EXTRA__ + LOG("HAVE Web CMD!"); +#endif m_pDBC->updateNodePushedCMD( PUSHED->id, DBC_CMD_READY_TO_CLEAN ); if( ( PUSHED->CMD & ARGUS_CAM_PCMD_CMD_MASK ) == ARGUS_CAM_PCMD_CMD_MASK ) { switch( PUSHED->CMD ) { diff --git a/lib/App/common/deviceNodePTZCamControl.cpp b/lib/App/common/deviceNodePTZCamControl.cpp index 3c50842d..b3ca0185 100644 --- a/lib/App/common/deviceNodePTZCamControl.cpp +++ b/lib/App/common/deviceNodePTZCamControl.cpp @@ -4,38 +4,6 @@ #define LOG_ERROR( X ) deviceNode::m_pLog->Log( "PTZ_CAM", this, _LOG_ERROR, X ) deviceNodePTZCamControl::deviceNodePTZCamControl( DBC_NODE_DATA *Data ): deviceNodeCamera( Data ), basicEventHandler(){ - //m_pLog = basicLogCollection::getInstance(); -/* - DBC_CAM_DATA * tData = m_pDBC->getCamData( m_sNodeData.aux_id ); - - m_fMaxRange = m_fMinHFov = m_fMaxHFov = m_fMinVFov = m_fMaxVFov = .0f; - - if( tData != NULL ) { - memcpy( &m_sCamData, tData, sizeof(DBC_CAM_DATA) ); - free( tData ); - }; - memset( &m_sCtrlData, 0, sizeof(CAMERA_CTRL_DATA) ); - if( m_sCamData.max_range == .0f ){ - m_fMaxRange = calcMaxDistance_mm( AC_imager_diag[m_sCamData.imager_type], m_sCamData.max_f, 1280 ); - } else { - m_fMaxRange = m_sCamData.max_range; - }; - m_fMinHFov = calcFOV_mm( AC_imager_width[m_sCamData.imager_type], m_sCamData.min_f ); - m_fMaxHFov = calcFOV_mm( AC_imager_width[m_sCamData.imager_type], m_sCamData.max_f ); - m_fMinVFov = calcFOV_mm( AC_imager_height[m_sCamData.imager_type], m_sCamData.min_f ); - m_fMaxVFov = calcFOV_mm( AC_imager_height[m_sCamData.imager_type], m_sCamData.max_f ); -#ifdef DEBUG - char tB[128]; - LOG("Camera Info:"); - sprintf( tB, "Maximal Range: %0.2f m. ", m_fMaxRange); - LOG(tB); - sprintf( tB, "Maximal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMinHFov, m_fMinVFov ); - LOG(tB); - sprintf( tB, "Minimal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMaxHFov, m_fMaxVFov ); - LOG(tB); -#endif - m_pPosition = new basicPosition( m_sCamData.lat, m_sCamData.lon, m_sCamData.alt, m_sCamData.roll, m_sCamData.pitch, m_sCamData.yaw ); - */ }; deviceNodePTZCamControl::deviceNodePTZCamControl( uint32_t id ): deviceNodeCamera( id ), basicEventHandler(){ diff --git a/lib/App/common/hardwareManager.cpp b/lib/App/common/hardwareManager.cpp index 9eb68693..b8d7f73a 100644 --- a/lib/App/common/hardwareManager.cpp +++ b/lib/App/common/hardwareManager.cpp @@ -340,17 +340,6 @@ bool hardwareManager::validate( void ){ return RetVal; }; -int xioctl(int fh, int request, void *arg){ - int r; - do { - r = ioctl( fh, request, arg ); - } while (-1 == r && EINTR == errno); - return r; -}; - -#define CLEAR(x) memset(&(x), 0, sizeof(x)) - - void hardwareManager::getMAC( CSTR if_name, CSTR buf ){ char tB[128]; FILE * fd=NULL; @@ -1181,6 +1170,7 @@ uint32_t hardwareManager::createResourceVIDEO( CSTR devName ){ //struct v4l2_cropcap cropcap; //struct v4l2_crop crop; struct v4l2_format fmt; + struct v4l2_frmivalenum sprm; char dev_name[CTEXT]; int fd = -1; struct stat st; @@ -1197,12 +1187,15 @@ uint32_t hardwareManager::createResourceVIDEO( CSTR devName ){ LOG_ERROR( tBuffer ); return 0; }; +#ifdef DEBUG + LOG( dev_name ); +#endif fd = open(dev_name, O_RDWR /* required */ | O_NONBLOCK, 0); if (-1 == fd) { sprintf( tBuffer, "Cannot open '%s': %d, %s\\n", dev_name, errno, strerror(errno)); LOG_ERROR( tBuffer ); } else { - if (-1 == xioctl(fd, VIDIOC_QUERYCAP, &cap)) { + if( -1 == xioctl(fd, VIDIOC_QUERYCAP, &cap) ){ if (EINVAL == errno) { sprintf( tBuffer, "%s is no V4L2 device", dev_name ); LOG_ERROR( tBuffer ); @@ -1213,7 +1206,7 @@ uint32_t hardwareManager::createResourceVIDEO( CSTR devName ){ return 0; }; if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { -#ifdef DEBUG_EXTRA +#ifdef DEBUG sprintf(tBuffer, "%s is no video capture device", dev_name); LOG_ERROR( tBuffer ); #endif @@ -1223,17 +1216,28 @@ uint32_t hardwareManager::createResourceVIDEO( CSTR devName ){ CLEAR(fmt); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; /* Preserve original settings as set by v4l2-ctl for example */ - if (-1 == xioctl(fd, VIDIOC_G_FMT, &fmt)){ - //LOG_ERROR("VIDIOC_G_FMT"); + if( -1 == xioctl(fd, VIDIOC_G_FMT, &fmt)){ + LOG_ERROR("VIDIOC_G_FMT"); } else { + CLEAR( sprm ); + if(-1 == xioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &sprm) && 0 ){ + LOG_ERROR("VIDIOC_ENUM_FRAMEINTERVALS"); + } else { + uint16_t fps = 15; + switch ( sprm.type ) { + case V4L2_FRMIVAL_TYPE_DISCRETE: LOG("1DISCRETE"); break; + case V4L2_FRMIVAL_TYPE_CONTINUOUS: LOG("2DISCRETE"); break; + case V4L2_FRMIVAL_TYPE_STEPWISE: LOG("3DISCRETE"); break; + }; #ifdef DEBUG - sprintf( tBuffer, "Grabber{%s}{%s}[%dx%d]", cap.card, cap.driver, fmt.fmt.pix.width,fmt.fmt.pix.height); - LOG( tBuffer ); + sprintf( tBuffer, "Grabber{%s}{%s}[%dx%d@%d]", cap.card, cap.driver, fmt.fmt.pix.width,fmt.fmt.pix.height, fps ); + LOG( tBuffer ); #endif - uint32_t mid = m_pDBC->addLocalCam( (CSTR)cap.card, (CSTR)cap.driver, dev_name, fmt.fmt.pix.width, fmt.fmt.pix.height ); - //uint64_t mid = m_pDBC->addLocalMediaSource( m_nSiteID, dev_name, fmt.fmt.pix.width, fmt.fmt.pix.height ); - //m_pDBC->addNodeSocket( m_nServerNodeID, mid, NODE_SOCK_TYPE_ANALOG_VIDEO_GRABBER, NODE_SOCK_MODE_OUT, false, dev_name, tBuffer ); - RetVal = m_pDBC->addResource( HARDWARE_ANALOG_VIDEO_IN, dev_name, mid ); + uint32_t mid = m_pDBC->addLocalCam( (CSTR)cap.card, (CSTR)cap.driver, dev_name, fmt.fmt.pix.width, fmt.fmt.pix.height, fps ); + //uint64_t mid = m_pDBC->addLocalMediaSource( m_nSiteID, dev_name, fmt.fmt.pix.width, fmt.fmt.pix.height ); + //m_pDBC->addNodeSocket( m_nServerNodeID, mid, NODE_SOCK_TYPE_ANALOG_VIDEO_GRABBER, NODE_SOCK_MODE_OUT, false, dev_name, tBuffer ); + RetVal = m_pDBC->addResource( HARDWARE_ANALOG_VIDEO_IN, dev_name, mid ); + }; }; close(fd); }; diff --git a/lib/App/common/kernelEventFilter.cpp b/lib/App/common/kernelEventFilter.cpp index db883367..a642ef36 100644 --- a/lib/App/common/kernelEventFilter.cpp +++ b/lib/App/common/kernelEventFilter.cpp @@ -1,27 +1,51 @@ #include "kernelEventFilter.h" -kernelEventFilter::kernelEventFilter( uint32_t id, TARGET_FILTER_TYPE type ){ - m_nDBID = id; - //m_pDBC = argusDBC::getInstance(); +#ifdef USE_MYSQL + #include "MySQL_dataBinder.h" +#else + #include "SQLite_dataBinder.h" +#endif + +kernelEventFilter::kernelEventFilter( uint32_t id, TARGET_FILTER_TYPE type ){ m_bActive = false; - m_bFilterType = type; - //if( m_pDBC != NULL ) { - //DBC_NODE_DATA *tData = NULL; - //tData = m_pDBC->getNodeData( m_nDBID ); - //if( tData != NULL ) { - // memcpy( &m_sNodeData , tData, sizeof(DBC_NODE_DATA)); - // free( tData ); - //} else { - // memset( &m_sNodeData , 0, sizeof(DBC_NODE_DATA)); - // m_sNodeData.type = ARGUS_UNKNOWN; - // m_sNodeData.node_id = id; - //}; - //} else { - //memset( &m_sNodeData , 0, sizeof(DBC_NODE_DATA)); - //m_sNodeData.type = ARGUS_UNKNOWN; - //m_sNodeData.node_id = id; - //}; +#ifdef USE_MYSQL + m_pDBC = mysqlDBC::getInstance(); +#else + m_pDBC = sqliteDBC::getInstance(); +#endif + m_pEventHeap = basicEventHeap::getInstance(); + if( m_pDBC != NULL ) { + DBC_TARGET_FLITER_DATA *tData = NULL; + tData = m_pDBC->getTargetFilterData( id ); + if( tData != NULL ) { + memcpy( &m_sFilterData , tData, sizeof(DBC_TARGET_FLITER_DATA)); + free( tData ); + } else { + memset( &m_sFilterData , 0, sizeof(DBC_TARGET_FLITER_DATA)); + m_sFilterData.type = type; + m_sFilterData.id = id; + }; + } else { + memset( &m_sFilterData , 0, sizeof(DBC_TARGET_FLITER_DATA)); + m_sFilterData.type = type; + m_sFilterData.id = id; + }; }; kernelEventFilter::~kernelEventFilter(){ }; + +void kernelEventFilter::createFilterEvent( basicEventTypeID typ, CSTR msg ){ + if ( m_pEventHeap!= NULL ) { + EVENT_CONTAINER *tEvt = NULL; + switch ( m_sFilterData.type ) { + case TF_LA_METRO_TRAIN_FILTER:{ + tEvt = createBasicEvent( m_sFilterData.id, EVT_CLASS_KRNL_FILTER_LATF, typ, NULL, msg ); + break; + }; + }; + if( tEvt ){ + m_pEventHeap->broadcast( tEvt ); + }; + }; +}; diff --git a/lib/App/common/kernelEventFilter.h b/lib/App/common/kernelEventFilter.h index 4e7a4ab4..d1ac38e9 100644 --- a/lib/App/common/kernelEventFilter.h +++ b/lib/App/common/kernelEventFilter.h @@ -1,31 +1,29 @@ #ifndef __KERNEL_EVENT_FILTER_HEADER__ #define __KERNEL_EVENT_FILTER_HEADER__ -#include "../../components/base/basicEvent.h" +//#include "../../components/base/basicEvent.h" +#include "../../components/base/basicEventHeap.h" #include "../../components/base/basicPosition.h" #include "dataBinder.h" -typedef enum E_TARGET_FILTER_TYPE{ - TF_UDEFINED_FILTER = 0, - TF_AUTHORISED_PEOPLE_FILTER = 1, - TF_LA_METRO_TRAIN_FILTER = 2 -}TARGET_FILTER_TYPE; - class kernelEventFilter{ protected: - uint32_t m_nDBID; - uint8_t m_bFilterType; - bool m_bActive; + DBC_TARGET_FLITER_DATA m_sFilterData; + dataBinder * m_pDBC; + basicEventHeap * m_pEventHeap; + bool m_bActive; + void createFilterEvent( basicEventTypeID typ, CSTR msg = NULL ); public: explicit kernelEventFilter( uint32_t id, TARGET_FILTER_TYPE type = TF_UDEFINED_FILTER ); virtual ~kernelEventFilter(); virtual bool validateTarget( uint32_t DevID, TARGET_DATA *ptr ){ return true; }; virtual bool initFilter(){ return true; }; virtual bool stopFilter(){ return true; }; - uint32_t getID(){ return m_nDBID; }; - uint8_t getType(){ return m_bFilterType; }; + uint32_t getID(){ return m_sFilterData.id; }; + uint8_t getType(){ return m_sFilterData.type; }; bool pause(); bool resume(); + bool isActive(){ return m_bActive; }; }; typedef vector vectorKernelEventFilters; diff --git a/lib/App/common/kernelEventFilterAPF.cpp b/lib/App/common/kernelEventFilterAPF.cpp index b8bfc15f..9e35eaff 100644 --- a/lib/App/common/kernelEventFilterAPF.cpp +++ b/lib/App/common/kernelEventFilterAPF.cpp @@ -1,12 +1,5 @@ #include "kernelEventFilterAPF.h" -#ifdef USE_MYSQL - #include "MySQL_dataBinder.h" -#else - #include "SQLite_dataBinder.h" -#endif - - #define LOG( X ) m_pLog->Log( "APF", this, X ) #ifdef DEBUG #define LOG_ERROR( X ) {\ @@ -25,13 +18,8 @@ kernelEventFilterAPF::kernelEventFilterAPF( uint32_t id ):kernelEventFilter( id, m_fDeltaX = 0.5f; m_fDeltaY = 0.5f; m_fDeltaZ = 1.0f; -#ifdef USE_MYSQL - m_pDBC = mysqlDBC::getInstance(); -#else - m_pDBC = sqliteDBC::getInstance(); -#endif memset( &m_Settings, 0, sizeof(DBC_APF_DATA)); - DBC_APF_DATA *tData = m_pDBC->getAPFData( m_nDBID ); + DBC_APF_DATA *tData = m_pDBC->getAPFData( m_sFilterData.aux_id ); if( tData != NULL ) { memcpy( &m_Settings, tData, sizeof(DBC_APF_DATA)); free( tData ); @@ -202,7 +190,7 @@ void kernelEventFilterAPF::m_fThreadProc( void ){ tDecart.z = atof( (*Parts)[7] );//Z decart2spherical( tDecart, tSpherical ); tSystem->convertToSystem( m_pPosition, tSpherical, tBOX->position ); - m_pDBC->updateAFPBox( m_nDBID, (*Parts)[1], tDecart.x, tDecart.y, tDecart.z ); + m_pDBC->updateAFPBox( m_sFilterData.aux_id, (*Parts)[1], tDecart.x, tDecart.y, tDecart.z); } else { LOG_ERROR("No SYSTEM ANCHOR!"); } diff --git a/lib/App/common/kernelEventFilterTrain.cpp b/lib/App/common/kernelEventFilterTrain.cpp new file mode 100644 index 00000000..5865ffb8 --- /dev/null +++ b/lib/App/common/kernelEventFilterTrain.cpp @@ -0,0 +1,198 @@ +#include "kernelEventFilterTrain.h" +#include "../../components/base/basicFunctionality.h" + +#define LOG( X ) m_pLog->Log( "TTF", this, X ) +#ifdef DEBUG + #define LOG_ERROR( X ) {\ + char _tBfrErrMSG2w34[256];\ + sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ + m_pLog->Log( "TTF", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ + } +#else + #define LOG_ERROR( X ) m_pLog->Log( "TTF", this, _LOG_ERROR, X ); +#endif + + +kernelEventFilterTrain::kernelEventFilterTrain( uint32_t id ): kernelEventFilter( id, TF_LA_METRO_TRAIN_FILTER ){ + m_pLog = basicLogCollection::getInstance(); + memset( &m_sTrainFilterData, 0, sizeof(TRAIN_FILTER_DATA)); +}; + +kernelEventFilterTrain::~kernelEventFilterTrain(){ + +}; + +bool kernelEventFilterTrain::validateTarget( uint32_t DevID, TARGET_DATA *ptr ){ + if( m_bActive && ( ptr != NULL ) ){ + if( m_sTrainFilterData.bDebugMode ){ + createFilterEvent( EVT_FLT_LATF_CHK ); + char tmpC[CTEXT]; + // Mark Event Message + sprintf( tmpC, "A:%0.3f R:%0.3f W:%d", ptr->local_target.fi, ptr->local_target.r, ptr->area ); + LOG( tmpC ); + }; + // Validate Zones and statuses (EXP) + uint64_t cts = getMilliseconds(); + //Upper Sensor Zone + if( m_sUpperZone.TrainOnTheField ){ + if( ( cts - m_sUpperZone.ts ) > m_sTrainFilterData.nDecisionTime ){ + // Clear Expired Suspicious + m_sUpperZone.TrainOnTheField = false; + m_sUpperZone.startAngle = 0; + m_sUpperZone.endAngle = 0; + }; + }; + if( m_sUpperZone.SuspiciousUnconfirmed ){ + if( ( cts - m_sUpperZone.ts ) > ( m_sTrainFilterData.nSuspectTime << 1 ) ){ + m_sUpperZone.SuspiciousUnconfirmed = false; + }; + }; + if( m_sUpperZone.SuspiciousObject ){ + if( ( cts - m_sUpperZone.ts ) > m_sTrainFilterData.nSuspectTime ){ + m_sUpperZone.SuspiciousObject = false; + if( !m_sUpperZone.TrainOnTheField ) m_sUpperZone.SuspiciousUnconfirmed = true; + }; + }; + //Bottom Sensor Zone + if( m_sBottomZone.TrainOnTheField ){ + if( ( cts - m_sBottomZone.ts ) > m_sTrainFilterData.nDecisionTime ){ + // Clear Expired Suspicious + m_sBottomZone.TrainOnTheField = false; + m_sBottomZone.startAngle = 0; + m_sBottomZone.endAngle = 0; + }; + }; + if( m_sBottomZone.SuspiciousUnconfirmed ){ + if( ( cts - m_sBottomZone.ts ) > ( m_sTrainFilterData.nSuspectTime << 1 ) ){ + m_sBottomZone.SuspiciousUnconfirmed = false; + }; + }; + if( m_sBottomZone.SuspiciousObject ){ + if( ( cts - m_sBottomZone.ts ) > m_sTrainFilterData.nSuspectTime ){ + m_sBottomZone.SuspiciousObject = false; + if( !m_sBottomZone.TrainOnTheField ) m_sBottomZone.SuspiciousUnconfirmed = true; + }; + }; + + // Check Current Target + float tAngleWidth; + if( ptr->digital > 0 ) { + tAngleWidth = ( 360.0f * ( ptr->area / (float)ptr->digital) ) / 12000.0f; + } else { + tAngleWidth = ( 360.0f * ptr->area ) / 12000.0f; + }; + + if( DevID == m_sTrainFilterData.nUpperSensorID ){ //If Upper Sensor + // Train is detected; + if( m_sUpperZone.TrainOnTheField ){ + // Already was Train Detection + m_sUpperZone.ts = cts; // Update TS + if( ( ptr->local_target.fi - tAngleWidth ) < m_sUpperZone.startAngle ) m_sUpperZone.startAngle = ptr->local_target.fi - tAngleWidth; + if( ( ptr->local_target.fi + tAngleWidth ) > m_sUpperZone.endAngle ) m_sUpperZone.endAngle = ptr->local_target.fi + tAngleWidth; + if( m_sTrainFilterData.bDebugMode ){ + //Train Position Update Event + createFilterEvent( EVT_FLT_LATF_TRP_UPDT ); + // Proceed Event as normal + return false; + }; + // Block Event + return true; + } else { + // Newly Detected Train + m_sUpperZone.TrainOnTheField = true; + // Clear Suspicies - Train Detected! + m_sUpperZone.SuspiciousObject = false; + m_sUpperZone.SuspiciousUnconfirmed = false; + m_sUpperZone.ts = cts; + m_sUpperZone.startAngle = ptr->local_target.fi - tAngleWidth; + m_sUpperZone.endAngle = ptr->local_target.fi + tAngleWidth; + if( m_sTrainFilterData.bDetectTrain || m_sTrainFilterData.bDebugMode ){ + //Train Detection Event + createFilterEvent( EVT_FLT_LATF_TRP_DET ); + // Proceed Event as normal + return false; + }; + // Block Event + return true; + }; + } else { + // check pedestrians detection as Train + if( m_sBottomZone.SuspiciousObject == false ){ + // No Train is detected by Upper Sensor Yet + if( m_sBottomZone.TrainOnTheField == false ){ + // If the object is suspicious + if( m_sBottomZone.SuspiciousUnconfirmed == false ){ + // Check New Suspicious + if( ptr->area > m_sTrainFilterData.nTrainWidth ){ + m_sBottomZone.SuspiciousObject = true; + m_sBottomZone.ts = cts; + if( m_sTrainFilterData.bDebugMode ){ + // Suspisious Detection + createFilterEvent( EVT_FLT_LATF_SUSP_START ); + // Proceed Event as normal + return false; + }; + return true; + }; + // Regular Target + if( m_sTrainFilterData.bDebugMode ){ + createFilterEvent( EVT_FLT_LATF_REGULAR ); + }; + } else { + // Unconfirmed Suspicious + if( m_sTrainFilterData.bDebugMode ){ + createFilterEvent( EVT_FLT_LATF_SUSP_NAK ); + }; + }; + } else { + // Disable Targets while Train is present + + // Detect Targets from others than train angles + //if( m_bTrackTrainDetection ){ + // if( ( event.target.dAngle < ( m_sGroupZone[cGID].startAngle - tAngleWidth ) ) + // || + // ( event.target.dAngle > ( m_sGroupZone[cGID].endAngle + tAngleWidth ) ) ) { + // EVT_FLT_LATF_DIFF_DET + // return false; + // }; + //}; + + if( m_sTrainFilterData.bDebugMode ){ + createFilterEvent( EVT_FLT_LATF_DISABLED ); + }; + return true; + }; + } else { + // Suspicious Mode Target + if( m_sTrainFilterData.bDebugMode ){ + createFilterEvent( EVT_FLT_LATF_SUSP_DET ); + return false; + }; + return true; + }; + }; + }; + return false; +}; + +bool kernelEventFilterTrain::initFilter(){ + m_bActive = false; + if( m_pDBC != NULL ){ + if( m_sFilterData.aux_id != 0 ){ + TRAIN_FILTER_DATA *tData = m_pDBC->getTrainFilterData( m_sFilterData.aux_id ); + if( tData != NULL ){ + memcpy( &m_sTrainFilterData, tData, sizeof( TRAIN_FILTER_DATA )); + free( tData ); + if( m_sTrainFilterData.nUpperSensorID && m_sTrainFilterData.nBottomSensorID ) { + m_bActive = true; + }; + }; + }; + }; + return m_bActive; +}; + +bool kernelEventFilterTrain::stopFilter(){ + m_bActive = false; + return true; +}; \ No newline at end of file diff --git a/lib/App/common/kernelEventFilterTrain.h b/lib/App/common/kernelEventFilterTrain.h new file mode 100644 index 00000000..f52b53d7 --- /dev/null +++ b/lib/App/common/kernelEventFilterTrain.h @@ -0,0 +1,34 @@ +#ifndef __KERNEL_EVENT_FILTER_TRAIN__ +#define __KERNEL_EVENT_FILTER_TRAIN__ + +#include "kernelEventFilter.h" + +typedef std::vector groupArray; + +typedef struct S_EFT_ZONE { + bool TrainOnTheField; + bool SuspiciousObject; + bool SuspiciousUnconfirmed; + uint64_t ts; + float startAngle; + float endAngle; +} EFT_ZONE; + + +class kernelEventFilterTrain: public kernelEventFilter{ + private: + basicLogCollection * m_pLog; + TRAIN_FILTER_DATA m_sTrainFilterData; + EFT_ZONE m_sUpperZone; + EFT_ZONE m_sBottomZone; + groupArray m_aUpperFIFO; + groupArray m_aBottomFIFO; + public: + explicit kernelEventFilterTrain( uint32_t id ); + virtual ~kernelEventFilterTrain(); + virtual bool validateTarget( uint32_t DevID, TARGET_DATA *ptr ); + virtual bool initFilter(); + virtual bool stopFilter(); +}; + +#endif \ No newline at end of file diff --git a/lib/App/common/kernelModuleEmbedVideo.cpp b/lib/App/common/kernelModuleEmbedVideo.cpp index e889ceea..182049e5 100644 --- a/lib/App/common/kernelModuleEmbedVideo.cpp +++ b/lib/App/common/kernelModuleEmbedVideo.cpp @@ -74,6 +74,7 @@ kernelModuleEmbedVideo::kernelModuleEmbedVideo( uint32_t moduleID ): kernelModul memcpy( &m_sEmbedVideoData, tDATA, sizeof(DBC_MODULE_EMBED_VIDEO_DATA) ); free( tDATA ); } else { + LOG_ERROR( "No DB Data Error!" ); memset( &m_sEmbedVideoData, 0, sizeof(DBC_MODULE_EMBED_VIDEO_DATA) ); m_sEmbedVideoData.port = 8972; }; @@ -110,6 +111,9 @@ kernelModuleEmbedVideo::kernelModuleEmbedVideo( uint32_t moduleID ): kernelModul }; kernelModuleEmbedVideo::~kernelModuleEmbedVideo(){ +#ifdef DEBUG + LOG("DESTRUCT!"); +#endif m_bEnabled = false; waitThreadEnd( true ); if( m_vHandlersPool.size() ) { // Kill-Wait Started Probes @@ -123,15 +127,35 @@ kernelModuleEmbedVideo::~kernelModuleEmbedVideo(){ m_vHandlersPool.clear(); }; #ifdef DEBUG - LOG("No More Client Handlers!"); + LOG("No More Clients Left"); #endif if( m_mapHANDLERS.size() ){ - for( mapSTREAMHANDLERS::iterator idx = m_mapHANDLERS.begin(); idx != m_mapHANDLERS.end(); idx++ ) delete( (*idx).second ); +#ifdef DEBUG + LOG("Deleting Client Handlers!"); +#endif + for( mapSTREAMHANDLERS::iterator idx = m_mapHANDLERS.begin(); idx != m_mapHANDLERS.end(); idx++ ){ +#ifdef DEBUG + LOG("Deleting Client Handler"); +#endif + delete( (*idx).second ); + } m_mapHANDLERS.clear(); }; +#ifdef DEBUG + LOG("Deleting CAPS"); +#endif if( m_mapCAPTURES.size() ) m_mapCAPTURES.clear(); +#ifdef DEBUG + LOG("Deleting MATS"); +#endif if( m_mapMATS.size() ) m_mapMATS.clear(); +#ifdef DEBUG + LOG("Deleting No Signal"); +#endif if( n_pNoSignalData ) free(n_pNoSignalData); +#ifdef DEBUG + LOG("All Done!"); +#endif }; static const char * ht_head = "HTTP/1.1 200 OK\r\n" @@ -625,7 +649,7 @@ bool kernelModuleEmbedVideo::stopService( bool force ){ m_bEnabled = false; m_bDetached = uninit(); #ifdef DEBUG - LOG("Service Thread ended!"); + LOG("StopService!"); #endif if( m_vHandlersPool.size() ) { // Kill-Wait Started Probes #ifdef DEBUG @@ -653,19 +677,44 @@ bool kernelModuleEmbedVideo::stopService( bool force ){ LOG("No More Client Handlers!"); #endif if( m_mapCAPTURES.size() ){ +#ifdef DEBUG + LOG("Some Caps!"); +#endif m_mapCAPTURES.clear(); //for( mapSTREAMCAPS::iterator idx = m_mapCAPTURES.begin(); idx < m_mapCAPTURES.end(); idx++ ) { //}; +#ifdef DEBUG + LOG("No More Caps!"); +#endif }; if( m_mapMATS.size() ){ +#ifdef DEBUG + LOG("Some Mats!"); +#endif + for( mapSTREAMMAPS::iterator idx = m_mapMATS.begin(); idx != m_mapMATS.end(); idx++ ) { +#ifdef DEBUG + LOG("Release Mat!"); +#endif + idx->second.release(); + }; +#ifdef DEBUG + LOG("Clear Map Mats!"); +#endif m_mapMATS.clear(); - //for( mapSTREAMMAPS::iterator idx = m_mapMATS.begin(); idx < m_mapMATS.end(); idx++ ) { - //}; +#ifdef DEBUG + LOG("No More Mats!"); +#endif }; if ( n_pNoSignalData ) { +#ifdef DEBUG + LOG("No Sig Data!"); +#endif free( n_pNoSignalData ); n_pNoSignalData = NULL; m_nNoSignalSize = 0; +#ifdef DEBUG + LOG("No No Sig Data!"); +#endif }; return m_bDetached; }; @@ -701,18 +750,26 @@ bool kernelModuleEmbedVideo::validate(){ }; free( tDATA ); } else { + LOG_ERROR("No Fetched EVE Data"); RetVal = false; }; if ( RetVal ) { DBC_INT_LIST *tList = m_pDBC->listMediaStreams(0, LIST_VALID_RECORDS); if ( tList != NULL ) { for( DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ){ +#ifdef DEBUG_EXTRA + LOG("REG STREAM"); +#endif if( !registerStream( *idx ) ){ - RetVal = false; - break; + //RetVal = false; + continue; }; }; delete ( tList ); +#ifdef DEBUG_EXTRA + } else { + LOG("- No Valid Streams -"); +#endif }; }; if ( RetVal ) { @@ -943,23 +1000,25 @@ bool kernelModuleEmbedVideo::generateSavePicPath( CSTR MD5, CSTR Output ){ }; bool kernelModuleEmbedVideo::registerStream( uint32_t streamID ){ - //Check if stream is not allready exists - //for ( vectorHANDLERS::iterator idx = m_vHandlersPool.begin(); idx < m_vHandlersPool.end(); idx++ ){ - // if ( (*idx)->CTX->mediaStreamId == streamID ) return true; - //}; - try { streamHandler * tData = m_mapHANDLERS.at( streamID ); if( tData!= NULL ) return true; } catch (const std::out_of_range& oor ) { - //std::cerr << "Out of Range error: " << oor.what() << '\n'; - m_mapHANDLERS[streamID] = new streamHandler( this ); - if ( m_mapHANDLERS[streamID] != NULL ) return m_mapHANDLERS[streamID]->create( m_pDBC, streamID ); + streamHandler * tSH = new streamHandler( this ); + if ( tSH != NULL ) { + if ( tSH->create( m_pDBC, streamID ) ) { + m_mapHANDLERS[streamID] = tSH; + return true; + } else { + delete( tSH ); + }; + }; }; return false; }; bool kernelModuleEmbedVideo::unregisterStream( uint32_t streamID ){ + return true; }; @@ -1006,20 +1065,33 @@ streamHandler::streamHandler( kernelModuleEmbedVideo *ptr, MS_WORK_MODE M ): m_p }; streamHandler::~streamHandler(){ +#ifdef DEBUG LOG("DESTRUCT!"); +#endif if ( m_sStreamData.id ) { - if (m_pMaster != NULL) m_pMaster->unregisterStream(m_sStreamData.id); - if ( m_pSource != NULL ) { +#ifdef DEBUG + LOG("Unreg STREAM!"); +#endif + if( m_pMaster != NULL) m_pMaster->unregisterStream(m_sStreamData.id); +#ifdef DEBUG + LOG("Delete Source!"); +#endif + if( m_pSource != NULL ) { switch( m_sStreamData.source_type[0] ) { case 'D': delete( ( videoLIVE555Source *) m_pSource ); break; case 'A': delete( ( videoAVLIBSource *) m_pSource ); break; }; }; +#ifdef DEBUG + LOG("Before CloseAll!"); +#endif #ifdef EVE_ENABLE_VIDEO closeAll(); #endif //EVE_ENABLE_VIDEO }; - +#ifdef DEBUG + LOG("DONE!"); +#endif }; bool streamHandler::create( dataBinder *ptr, uint32_t stremID ){ @@ -1032,7 +1104,7 @@ bool streamHandler::create( dataBinder *ptr, uint32_t stremID ){ free(tData); DBC_CAM_DATA *tCAM = m_pDBC->getCamData( m_sStreamData.source_id ); if( tCAM ){ - CSTR tNAM = m_pDBC->getNodeName( tCAM->node_id ); + CSTR tNAM = NULL;//m_pDBC->getNodeName( tCAM->node_id ); m_sSourceDesc.mediaStreamId = stremID; m_sSourceDesc.mediaSourceId = m_sStreamData.source_id; if ( tNAM!= NULL ) { @@ -1500,6 +1572,7 @@ bool streamHandler::pushFrame( cv::Mat &Frame, void* src ){ return true; }; +#ifdef EVE_ENABLE_VIDEO void streamHandler::closeSegmentA( void ){ m_mCurrentOperationProtector.lock(); if ( m_bCOP == 0 ) m_bCOP = 0x01; @@ -1516,30 +1589,32 @@ void streamHandler::closeSegmentB( void ){ void streamHandler::closeAll(){ waitThreadEnd( true ); - avcodec_send_frame( m_pCodecCtx, NULL ); - int ret = 0; - AVPacket *avp = av_packet_alloc(); - if ( avp ) { - do { + if( m_pCodecCtx != NULL && (m_bSegAActive || m_bSegBActive )) { + avcodec_send_frame( m_pCodecCtx, NULL ); + int ret = 0; + AVPacket *avp = av_packet_alloc(); + if ( avp ) { + do { + av_packet_unref( avp ); + ret = avcodec_receive_packet( m_pCodecCtx, avp ); + if ( !ret ) { + if ( m_bSegAActive ) av_write_frame( m_pFormatCtxA, avp ); + if ( m_bSegBActive ) av_write_frame( m_pFormatCtxB, avp ); + }; + } while ( !ret ); av_packet_unref( avp ); - ret = avcodec_receive_packet( m_pCodecCtx, avp ); - if ( !ret ) { - if ( m_bSegAActive ) av_write_frame( m_pFormatCtxA, avp ); - if ( m_bSegBActive ) av_write_frame( m_pFormatCtxB, avp ); - }; - } while ( !ret ); - av_packet_unref( avp ); - av_packet_free( &avp ); - }; - if ( m_bSegAActive ) { - av_write_trailer(m_pFormatCtxA); - avformat_close_input( &m_pFormatCtxA ); - m_bSegAActive = false; - }; - if ( m_bSegBActive ) { - av_write_trailer(m_pFormatCtxB); - avformat_close_input( &m_pFormatCtxB ); - m_bSegBActive = false; + av_packet_free( &avp ); + }; + if ( m_bSegAActive ) { + av_write_trailer(m_pFormatCtxA); + avformat_close_input( &m_pFormatCtxA ); + m_bSegAActive = false; + }; + if ( m_bSegBActive ) { + av_write_trailer(m_pFormatCtxB); + avformat_close_input( &m_pFormatCtxB ); + m_bSegBActive = false; + }; }; }; @@ -2150,7 +2225,11 @@ void streamHandler::swapActiveStreams( void ){ //m_mFrameCounterProtector.unlock(); }; +#endif // EVE_ENABLE_VIDEO + bool streamHandler::triggerEvent( uint32_t &dbid, uint32_t &frame ){ + +#ifdef EVE_ENABLE_VIDEO m_mFrameCounterProtector.lock(); // To Mark Events Frames m_bEvtMarkerCounter = 255; @@ -2187,6 +2266,7 @@ bool streamHandler::triggerEvent( uint32_t &dbid, uint32_t &frame ){ dbid = m_nVideoRegisteredDBID; LOG("Event Registered!"); m_mFrameCounterProtector.unlock(); +#endif // EVE_ENABLE_VIDEO return true; }; diff --git a/lib/App/common/kernelModuleEmbedVideo.h b/lib/App/common/kernelModuleEmbedVideo.h index 0f819cb9..49bed06d 100644 --- a/lib/App/common/kernelModuleEmbedVideo.h +++ b/lib/App/common/kernelModuleEmbedVideo.h @@ -12,7 +12,7 @@ class kernelModuleEmbedVideo; #define FILESTREAMBUFFERSZ 1048576 -#define EVE_ENABLE_VIDEO +//#define EVE_ENABLE_VIDEO diff --git a/lib/App/common/kernelModuleOnvifObserver.cpp b/lib/App/common/kernelModuleOnvifObserver.cpp index 93602bb4..7f2a2503 100644 --- a/lib/App/common/kernelModuleOnvifObserver.cpp +++ b/lib/App/common/kernelModuleOnvifObserver.cpp @@ -239,8 +239,8 @@ void kernelModuleOnvifObserver::m_fThreadProc(){ #endif }; continue; //To Fetch Another responces +#ifdef DEBUG_EXTRA } else { -#ifdef DEBUG LOG("Probe Finished By Timeout!"); #endif }; @@ -443,15 +443,19 @@ OBSERVER_RESULT *kernelModuleOnvifObserver::parseXML( CSTR data ){ if( response.isEmpty() ){ LOG_ERROR("The device descripe XML file is not a valid XML file. Cann't find root element."); } else { -#ifdef DEBUG +#ifdef DEBUG_EXTRA LOG("Probe XML parsed"); #endif XMLNode Body = response.getChildNode( "Body", 0 ); if(!Body.isEmpty()){ +#ifdef DEBUG_EXTRA LOG("Have Body elm"); +#endif XMLNode ProbeMatches = Body.getChildNode("ProbeMatches", 0);//EndpointReference if(!ProbeMatches.isEmpty()) { +#ifdef DEBUG_EXTRA LOG("Have ProbeMathes elm"); +#endif int matches = ProbeMatches.nChildNode(); for(int index=0;indexsize(); j++) { if( strlen(tArr->at(j)) > 10 ) { sprintf(retVal->RefID,"%s",tArr->at(j)); diff --git a/lib/components/base/basicEvent.h b/lib/components/base/basicEvent.h index 3fdfcbf0..e5b9710e 100644 --- a/lib/components/base/basicEvent.h +++ b/lib/components/base/basicEvent.h @@ -68,7 +68,18 @@ typedef enum E_basicEventTypeID { EVT_ERROR = 35, EVT_ROI_ACTIVE = 36, EVT_CAMERA_MOVE_TO = 37, - EVT_COUNT = 38 + EVT_FLT_LATF_CHK = 39, + EVT_FLT_LATF_UP_DETEC = 40, + EVT_FLT_LATF_BT_DETEC = 41, + EVT_FLT_LATF_TRP_DET = 42, + EVT_FLT_LATF_TRP_UPDT = 43, + EVT_FLT_LATF_SUSP_START = 44, + EVT_FLT_LATF_SUSP_NAK = 45, + EVT_FLT_LATF_REGULAR = 46, + EVT_FLT_LATF_DISABLED = 47, + EVT_FLT_LATF_SUSP_DET = 48, + EVT_FLT_LATF_DIFF_DET = 49, + EVT_COUNT = 50 } basicEventTypeID; @@ -88,7 +99,9 @@ typedef enum E_basicEventClassID{ EVT_CLASS_FLY_HUNTER = 13, EVT_CLASS_CAMERA_CTRL = 14, EVT_CLASS_EXTERNAL_CMD = 15, - EVT_CLASS_COUNT = 16 + EVT_CLASS_KRNL_FILTER_APF = 16, + EVT_CLASS_KRNL_FILTER_LATF = 17, + EVT_CLASS_COUNT = 18 } basicEventClassID; typedef struct S_EVENT_CONTAINER{ diff --git a/lib/components/base/basicFunctionality.cpp b/lib/components/base/basicFunctionality.cpp index e15812cd..c676530e 100644 --- a/lib/components/base/basicFunctionality.cpp +++ b/lib/components/base/basicFunctionality.cpp @@ -1,6 +1,8 @@ #include "basicFunctionality.h" #include "../../alg/generic/md5.h" +#include + //#include #ifdef DEBUG @@ -582,6 +584,14 @@ CSTR getTStr( CSTR Fmt ){ #ifdef __linux__ +int xioctl(int fh, int request, void *arg){ + int r; + do { + r = ioctl( fh, request, arg ); + } while (-1 == r && EINTR == errno); + return r; +}; + uint64_t getMilliseconds( void ){ uint64_t tMilliseconds = (uint64_t) 0; struct timeval tData; diff --git a/lib/components/base/basicFunctionality.h b/lib/components/base/basicFunctionality.h index e9c3eed5..67ff8e01 100644 --- a/lib/components/base/basicFunctionality.h +++ b/lib/components/base/basicFunctionality.h @@ -68,8 +68,11 @@ int checkCmdExists( CSTR cmd ); bool correctSysTime( int diff ); bool correctSoftTime( int diff ); +#define CLEAR(x) memset(&(x), 0, sizeof(x)) + #ifdef __linux__ - unsigned long long getTimeValue( void ); + unsigned long long getTimeValue( void ); + int xioctl(int fh, int request, void *arg); #else unsigned __int64 getTimeValue( void ); #endif diff --git a/lib/data/media/video/videoAVLIBSource.cpp b/lib/data/media/video/videoAVLIBSource.cpp index 972fe6be..cf38f75e 100644 --- a/lib/data/media/video/videoAVLIBSource.cpp +++ b/lib/data/media/video/videoAVLIBSource.cpp @@ -550,7 +550,7 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in LOG_ERROR("Error Allocating SwsCtx!"); return false; }; -#ifdef DEBUG_EXTRA +#ifdef DEBUG LOG("Allocation Done->Start Thread!"); #endif return init(); diff --git a/lib/rgoose/rgooseTypes.h b/lib/rgoose/rgooseTypes.h index 9eae03c4..cf5e3eaa 100644 --- a/lib/rgoose/rgooseTypes.h +++ b/lib/rgoose/rgooseTypes.h @@ -202,8 +202,9 @@ typedef enum E_ARGUS_CAM_TRIGGER_MODE{ typedef struct S_DBC_CAM_DATA{ uint32_t id; - uint32_t site_id; - uint32_t node_id; +// uint32_t site_id; +// uint32_t node_id; + uint32_t stream_id; bool online; uint8_t type; char name[65];