From c898fb8bb7ca38dc7653ac4b800ab2c9179c2bc0 Mon Sep 17 00:00:00 2001 From: Evgeny Gagua Date: Sun, 1 Dec 2024 17:28:37 +0200 Subject: [PATCH] ModemManager Finished + MediaEncoder For ServA Created --- Projects/la_serva/la_serva.vpj | 3 + Projects/la_serva/makefile | 140 ++++----- lib/App/common/dataBinder_structures.h | 12 + lib/App/common/deviceNodeCamera.cpp | 10 +- lib/App/common/deviceNodeCamera.h | 1 + lib/App/common/deviceNodeStaticCamControl.cpp | 9 + lib/App/common/kernelModuleEmbedVideo.cpp | 4 + lib/App/common/kernelModuleModemManager.cpp | 142 ++++++--- lib/App/common/kernelModuleModemManager.h | 1 + lib/App/common/serverDataBinder.h | 4 + lib/App/common/serverMySQL_dataBinder.cpp | 133 +++++++-- lib/App/common/serverMySQL_dataBinder.h | 8 +- lib/App/mojo/mojoKernel.cpp | 57 +++- lib/App/mojo/mojoKernel.h | 1 - lib/App/mojo/mojoRemoteClient.cpp | 270 +++++++++++++++--- lib/App/mojo/mojoRemoteClient.h | 39 ++- lib/App/serva/servaBackend.cpp | 4 +- lib/App/serva/servaKernel.cpp | 73 ++++- lib/App/serva/servaKernel.h | 8 +- lib/App/serva/servaRemoteClientHandler.cpp | 259 +++++++++++++---- lib/App/serva/servaRemoteClientHandler.h | 60 +++- lib/components/base/basicTransport.cpp | 3 + lib/components/base/basicTransport.h | 1 + lib/data/net/clientPort.cpp | 54 ++-- lib/data/net/clientPort.h | 1 + lib/data/protocol/protocolARGUS_DATA.h | 19 +- lib/data/transport/transportSocket.cpp | 18 +- 27 files changed, 1030 insertions(+), 304 deletions(-) diff --git a/Projects/la_serva/la_serva.vpj b/Projects/la_serva/la_serva.vpj index f1232248..d309a23e 100644 --- a/Projects/la_serva/la_serva.vpj +++ b/Projects/la_serva/la_serva.vpj @@ -500,6 +500,7 @@ + @@ -525,6 +526,7 @@ + @@ -543,6 +545,7 @@ + diff --git a/Projects/la_serva/makefile b/Projects/la_serva/makefile index 3037d96b..c05298d6 100644 --- a/Projects/la_serva/makefile +++ b/Projects/la_serva/makefile @@ -30,8 +30,9 @@ CFG_OBJ= COMMON_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ - $(OUTDIR)/basicLogCollection.o $(OUTDIR)/basicLoggingService.o \ - $(OUTDIR)/basicMutex.o $(OUTDIR)/basicObject.o $(OUTDIR)/basicRing.o \ + $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ + $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicMutex.o \ + $(OUTDIR)/basicObject.o $(OUTDIR)/basicRing.o \ $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ @@ -42,16 +43,17 @@ COMMON_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ $(OUTDIR)/objectMySQLLoggingService.o $(OUTDIR)/protocol.o \ $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/servaBackend.o \ $(OUTDIR)/servaKernel.o $(OUTDIR)/servaKernelToolKit.o \ - $(OUTDIR)/servaRemoteClient.o $(OUTDIR)/servaRemoteClientHandler.o \ - $(OUTDIR)/serverDataBinder.o $(OUTDIR)/serverMySQL_dataBinder.o \ - $(OUTDIR)/serverPort.o $(OUTDIR)/Transform.o \ - $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o + $(OUTDIR)/servaMediaEncoder.o $(OUTDIR)/servaRemoteClient.o \ + $(OUTDIR)/servaRemoteClientHandler.o $(OUTDIR)/serverDataBinder.o \ + $(OUTDIR)/serverMySQL_dataBinder.o $(OUTDIR)/serverPort.o \ + $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o OBJ=$(COMMON_OBJ) $(CFG_OBJ) ALL_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ - $(OUTDIR)/basicLogCollection.o $(OUTDIR)/basicLoggingService.o \ - $(OUTDIR)/basicMutex.o $(OUTDIR)/basicObject.o $(OUTDIR)/basicRing.o \ + $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ + $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicMutex.o \ + $(OUTDIR)/basicObject.o $(OUTDIR)/basicRing.o \ $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ @@ -62,15 +64,15 @@ ALL_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ $(OUTDIR)/objectMySQLLoggingService.o $(OUTDIR)/protocol.o \ $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/servaBackend.o \ $(OUTDIR)/servaKernel.o $(OUTDIR)/servaKernelToolKit.o \ - $(OUTDIR)/servaRemoteClient.o $(OUTDIR)/servaRemoteClientHandler.o \ - $(OUTDIR)/serverDataBinder.o $(OUTDIR)/serverMySQL_dataBinder.o \ - $(OUTDIR)/serverPort.o $(OUTDIR)/Transform.o \ - $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o -lsqlite3 -lpthread \ - -lmysqlclient -lssl -lcurl -lm -lcrypto -lconfig -lz `pkg-config \ - libavcodec libavdevice libavfilter libavformat libavutil libpostproc \ - libswresample libswscale --libs` -latomic `pkg-config --libs openssl \ - opencv4 rdkafka++`-lliveMedia -lgroupsock -lBasicUsageEnvironment \ - -lUsageEnvironment + $(OUTDIR)/servaMediaEncoder.o $(OUTDIR)/servaRemoteClient.o \ + $(OUTDIR)/servaRemoteClientHandler.o $(OUTDIR)/serverDataBinder.o \ + $(OUTDIR)/serverMySQL_dataBinder.o $(OUTDIR)/serverPort.o \ + $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \ + -lsqlite3 -lpthread -lmysqlclient -lssl -lcurl -lm -lcrypto -lconfig \ + -lz `pkg-config libavcodec libavdevice libavfilter libavformat \ + libavutil libpostproc libswresample libswscale --libs` -latomic \ + `pkg-config --libs openssl opencv4 rdkafka++`-lliveMedia -lgroupsock \ + -lBasicUsageEnvironment -lUsageEnvironment COMPILE=g++ -c -x c++ "-DDEBUG" "-DUSE_SERVER_MYSQL" "-D__STDC_CONSTANT_MACROS__" "-D_SERVER_APPLICATION_" "-D_OPENCV_" "-DRASPI_HARDWARE" -O0 -w -Wpointer-arith -std=c++11 -Wno-write-strings -I../../lib/include `pkg-config opencv4 libavcodec libavdevice libavfilter libavformat libavutil libpostproc libswresample libswscale live555 --cflags` -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $< LINK=g++ -O0 -w -o "$(OUTFILE)" $(ALL_OBJ) @@ -140,8 +142,9 @@ CFG_OBJ= COMMON_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ - $(OUTDIR)/basicLogCollection.o $(OUTDIR)/basicLoggingService.o \ - $(OUTDIR)/basicMutex.o $(OUTDIR)/basicObject.o $(OUTDIR)/basicRing.o \ + $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ + $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicMutex.o \ + $(OUTDIR)/basicObject.o $(OUTDIR)/basicRing.o \ $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ @@ -152,16 +155,17 @@ COMMON_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ $(OUTDIR)/objectMySQLLoggingService.o $(OUTDIR)/protocol.o \ $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/servaBackend.o \ $(OUTDIR)/servaKernel.o $(OUTDIR)/servaKernelToolKit.o \ - $(OUTDIR)/servaRemoteClient.o $(OUTDIR)/servaRemoteClientHandler.o \ - $(OUTDIR)/serverDataBinder.o $(OUTDIR)/serverMySQL_dataBinder.o \ - $(OUTDIR)/serverPort.o $(OUTDIR)/Transform.o \ - $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o + $(OUTDIR)/servaMediaEncoder.o $(OUTDIR)/servaRemoteClient.o \ + $(OUTDIR)/servaRemoteClientHandler.o $(OUTDIR)/serverDataBinder.o \ + $(OUTDIR)/serverMySQL_dataBinder.o $(OUTDIR)/serverPort.o \ + $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o OBJ=$(COMMON_OBJ) $(CFG_OBJ) ALL_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ - $(OUTDIR)/basicLogCollection.o $(OUTDIR)/basicLoggingService.o \ - $(OUTDIR)/basicMutex.o $(OUTDIR)/basicObject.o $(OUTDIR)/basicRing.o \ + $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ + $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicMutex.o \ + $(OUTDIR)/basicObject.o $(OUTDIR)/basicRing.o \ $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ @@ -172,10 +176,10 @@ ALL_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ $(OUTDIR)/objectMySQLLoggingService.o $(OUTDIR)/protocol.o \ $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/servaBackend.o \ $(OUTDIR)/servaKernel.o $(OUTDIR)/servaKernelToolKit.o \ - $(OUTDIR)/servaRemoteClient.o $(OUTDIR)/servaRemoteClientHandler.o \ - $(OUTDIR)/serverDataBinder.o $(OUTDIR)/serverMySQL_dataBinder.o \ - $(OUTDIR)/serverPort.o $(OUTDIR)/Transform.o \ - $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o + $(OUTDIR)/servaMediaEncoder.o $(OUTDIR)/servaRemoteClient.o \ + $(OUTDIR)/servaRemoteClientHandler.o $(OUTDIR)/serverDataBinder.o \ + $(OUTDIR)/serverMySQL_dataBinder.o $(OUTDIR)/serverPort.o \ + $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o COMPILE=g++ -c -x c++ "-DUSE_SERVER_MYSQL" "-D_SERVER_APPLICATION_" "-D_THREAD_SAFE" "-D_BSD_SOURCE" "-D_REENTRANT" "-DRASPI_HARDWARE" -O3 -w -Wpointer-arith -std=gnu++11 -I../../lib/include -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $< LINK=g++ -O3 -w -lconfig -lpthread -lmysqlclient -lelf -lcurses -lcdk -lcurl `pkg-config --libs rdkafka++` -s -o "$(OUTFILE)" $(ALL_OBJ) @@ -249,8 +253,9 @@ CFG_OBJ= COMMON_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ - $(OUTDIR)/basicLogCollection.o $(OUTDIR)/basicLoggingService.o \ - $(OUTDIR)/basicMutex.o $(OUTDIR)/basicObject.o $(OUTDIR)/basicRing.o \ + $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ + $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicMutex.o \ + $(OUTDIR)/basicObject.o $(OUTDIR)/basicRing.o \ $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ @@ -261,16 +266,17 @@ COMMON_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ $(OUTDIR)/objectMySQLLoggingService.o $(OUTDIR)/protocol.o \ $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/servaBackend.o \ $(OUTDIR)/servaKernel.o $(OUTDIR)/servaKernelToolKit.o \ - $(OUTDIR)/servaRemoteClient.o $(OUTDIR)/servaRemoteClientHandler.o \ - $(OUTDIR)/serverDataBinder.o $(OUTDIR)/serverMySQL_dataBinder.o \ - $(OUTDIR)/serverPort.o $(OUTDIR)/Transform.o \ - $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o + $(OUTDIR)/servaMediaEncoder.o $(OUTDIR)/servaRemoteClient.o \ + $(OUTDIR)/servaRemoteClientHandler.o $(OUTDIR)/serverDataBinder.o \ + $(OUTDIR)/serverMySQL_dataBinder.o $(OUTDIR)/serverPort.o \ + $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o OBJ=$(COMMON_OBJ) $(CFG_OBJ) ALL_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ - $(OUTDIR)/basicLogCollection.o $(OUTDIR)/basicLoggingService.o \ - $(OUTDIR)/basicMutex.o $(OUTDIR)/basicObject.o $(OUTDIR)/basicRing.o \ + $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ + $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicMutex.o \ + $(OUTDIR)/basicObject.o $(OUTDIR)/basicRing.o \ $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ @@ -281,15 +287,15 @@ ALL_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ $(OUTDIR)/objectMySQLLoggingService.o $(OUTDIR)/protocol.o \ $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/servaBackend.o \ $(OUTDIR)/servaKernel.o $(OUTDIR)/servaKernelToolKit.o \ - $(OUTDIR)/servaRemoteClient.o $(OUTDIR)/servaRemoteClientHandler.o \ - $(OUTDIR)/serverDataBinder.o $(OUTDIR)/serverMySQL_dataBinder.o \ - $(OUTDIR)/serverPort.o $(OUTDIR)/Transform.o \ - $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o -lpthread -lmysqlclient \ - -lssl -lcurl -lm -lcrypto -lconfig -lz `pkg-config libavcodec \ - libavdevice libavfilter libavformat libavutil libpostproc \ - libswresample libswscale --libs` -latomic `pkg-config --libs openssl \ - opencv4 rdkafka++` -lliveMedia -lgroupsock -lBasicUsageEnvironment \ - -lUsageEnvironment + $(OUTDIR)/servaMediaEncoder.o $(OUTDIR)/servaRemoteClient.o \ + $(OUTDIR)/servaRemoteClientHandler.o $(OUTDIR)/serverDataBinder.o \ + $(OUTDIR)/serverMySQL_dataBinder.o $(OUTDIR)/serverPort.o \ + $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \ + -lpthread -lmysqlclient -lssl -lcurl -lm -lcrypto -lconfig -lz \ + `pkg-config libavcodec libavdevice libavfilter libavformat libavutil \ + libpostproc libswresample libswscale --libs` -latomic `pkg-config \ + --libs openssl opencv4 rdkafka++` -lliveMedia -lgroupsock \ + -lBasicUsageEnvironment -lUsageEnvironment COMPILE=g++ -c -x c++ "-DDEBUG" "-DUSE_SERVER_MYSQL" "-D__STDC_CONSTANT_MACROS" "-D_SERVER_APPLICATION_" "-D_OPENCV_" -O0 -w -Wpointer-arith -std=c++11 -Wno-write-strings -I../../lib/include `pkg-config opencv4 libavcodec libavdevice libavfilter libavformat libavutil libpostproc libswresample libswscale live555 --cflags` -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $< LINK=g++ -O0 -w -o "$(OUTFILE)" $(ALL_OBJ) @@ -363,8 +369,9 @@ CFG_OBJ= COMMON_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ - $(OUTDIR)/basicLogCollection.o $(OUTDIR)/basicLoggingService.o \ - $(OUTDIR)/basicMutex.o $(OUTDIR)/basicObject.o $(OUTDIR)/basicRing.o \ + $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ + $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicMutex.o \ + $(OUTDIR)/basicObject.o $(OUTDIR)/basicRing.o \ $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ @@ -375,16 +382,17 @@ COMMON_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ $(OUTDIR)/objectMySQLLoggingService.o $(OUTDIR)/protocol.o \ $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/servaBackend.o \ $(OUTDIR)/servaKernel.o $(OUTDIR)/servaKernelToolKit.o \ - $(OUTDIR)/servaRemoteClient.o $(OUTDIR)/servaRemoteClientHandler.o \ - $(OUTDIR)/serverDataBinder.o $(OUTDIR)/serverMySQL_dataBinder.o \ - $(OUTDIR)/serverPort.o $(OUTDIR)/Transform.o \ - $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o + $(OUTDIR)/servaMediaEncoder.o $(OUTDIR)/servaRemoteClient.o \ + $(OUTDIR)/servaRemoteClientHandler.o $(OUTDIR)/serverDataBinder.o \ + $(OUTDIR)/serverMySQL_dataBinder.o $(OUTDIR)/serverPort.o \ + $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o OBJ=$(COMMON_OBJ) $(CFG_OBJ) ALL_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ - $(OUTDIR)/basicLogCollection.o $(OUTDIR)/basicLoggingService.o \ - $(OUTDIR)/basicMutex.o $(OUTDIR)/basicObject.o $(OUTDIR)/basicRing.o \ + $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ + $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicMutex.o \ + $(OUTDIR)/basicObject.o $(OUTDIR)/basicRing.o \ $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ @@ -395,15 +403,15 @@ ALL_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ $(OUTDIR)/objectMySQLLoggingService.o $(OUTDIR)/protocol.o \ $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/servaBackend.o \ $(OUTDIR)/servaKernel.o $(OUTDIR)/servaKernelToolKit.o \ - $(OUTDIR)/servaRemoteClient.o $(OUTDIR)/servaRemoteClientHandler.o \ - $(OUTDIR)/serverDataBinder.o $(OUTDIR)/serverMySQL_dataBinder.o \ - $(OUTDIR)/serverPort.o $(OUTDIR)/Transform.o \ - $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o -lpthread -lmysqlclient \ - -lssl -lcurl -lm -lcrypto -lconfig -lz `pkg-config libavcodec \ - libavdevice libavfilter libavformat libavutil libpostproc \ - libswresample libswscale --libs` -latomic `pkg-config --libs openssl \ - opencv4 rdkafka++` -lliveMedia -lgroupsock -lBasicUsageEnvironment \ - -lUsageEnvironment -s + $(OUTDIR)/servaMediaEncoder.o $(OUTDIR)/servaRemoteClient.o \ + $(OUTDIR)/servaRemoteClientHandler.o $(OUTDIR)/serverDataBinder.o \ + $(OUTDIR)/serverMySQL_dataBinder.o $(OUTDIR)/serverPort.o \ + $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \ + -lpthread -lmysqlclient -lssl -lcurl -lm -lcrypto -lconfig -lz \ + `pkg-config libavcodec libavdevice libavfilter libavformat libavutil \ + libpostproc libswresample libswscale --libs` -latomic `pkg-config \ + --libs openssl opencv4 rdkafka++` -lliveMedia -lgroupsock \ + -lBasicUsageEnvironment -lUsageEnvironment -s COMPILE=g++ -c -x c++ "-DUSE_SERVER_MYSQL" "-D__STDC_CONSTANT_MACROS" "-D_SERVER_APPLICATION_" "-D_OPENCV_" -O3 -w -Wpointer-arith -std=c++11 -Wno-write-strings -I../../lib/include `pkg-config opencv4 libavcodec libavdevice libavfilter libavformat libavutil libpostproc libswresample libswscale live555 --cflags` -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $< LINK=g++ -O3 -w -o "$(OUTFILE)" $(ALL_OBJ) @@ -470,6 +478,7 @@ $(OUTDIR)/basicEvent.o: ../../lib/components/base/basicEvent.cpp ../../lib/compo $(OUTDIR)/basicEventHandler.o: ../../lib/components/base/basicEventHandler.cpp ../../lib/components/base/basicEventHandler.h ../../lib/components/base/basicEventHeap.h $(OUTDIR)/basicEventHeap.o: ../../lib/components/base/basicEventHeap.cpp ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEventHandler.h $(OUTDIR)/basicFunctionality.o: ../../lib/components/base/basicFunctionality.cpp ../../lib/components/base/basicFunctionality.h ../../lib/alg/generic/md5.h ../../lib/components/base/basicLogCollection.h +$(OUTDIR)/basicLIBAV.o: ../../lib/components/base/basicLIBAV.cpp ../../lib/components/base/basicLIBAV.h $(OUTDIR)/basicLogCollection.o: ../../lib/components/base/basicLogCollection.cpp ../../lib/components/base/basicLogCollection.h ../../lib/alg/generic/heapDebug.h $(OUTDIR)/basicLoggingService.o: ../../lib/components/base/basicLoggingService.cpp ../../lib/components/base/basicLoggingService.h $(OUTDIR)/basicMutex.o: ../../lib/components/base/basicMutex.cpp ../../lib/components/base/basicMutex.h @@ -495,8 +504,9 @@ $(OUTDIR)/protocolARGUS_DATA.o: ../../lib/data/protocol/protocolARGUS_DATA.cpp . $(OUTDIR)/servaBackend.o: ../../lib/App/serva/servaBackend.cpp ../../lib/App/serva/servaBackend.h ../../lib/App/common/serverMySQL_dataBinder.h ../../lib/App/common/serverDataBinder.h ../../lib/App/common/dataBinder_structures.h ../../lib/data/mysql/mysql_class.h ../../lib/components/base/basicSettingsProvider.h ../../lib/alg/generic/md5.h ../../lib/alg/lgs/mask.h ../../lib/components/base/basicSettings.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicMemoryOperation.h ../../lib/components/object/objectFileLoggingService.h ../../lib/App/serva/objectMySQLLoggingService.h ../../lib/App/common/serverDataBinder.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/serva/servaKernel.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicEventHeap.h ../../lib/components/object/objectSystemAnchor.h ../../lib/alg/lgs/detectorStructures.h ../../lib/alg/lgs/detector.h ../../lib/alg/lgs/mask.h ../../lib/alg/generic/md5.h ../../lib/App/common/kernelPrototype.h ../../lib/App/serva/lifeMonitoring.h ../../lib/App/serva/servaRemoteClient.h ../../lib/data/net/netServer.h $(OUTDIR)/servaKernel.o: ../../lib/App/serva/servaKernel.cpp ../../lib/App/serva/servaKernel.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicEventHeap.h ../../lib/components/object/objectSystemAnchor.h ../../lib/alg/lgs/detectorStructures.h ../../lib/alg/lgs/detector.h ../../lib/alg/lgs/mask.h ../../lib/alg/generic/md5.h ../../lib/App/common/kernelPrototype.h ../../lib/App/serva/lifeMonitoring.h ../../lib/App/serva/servaRemoteClient.h ../../lib/data/net/netServer.h ../../lib/App/common/kernelEventFilterAPF.h ../../lib/App/common/kernelEventFilterTrain.h ../../lib/App/common/kernelModuleEmbedVideo.h ../../lib/App/common/serverMySQL_dataBinder.h ../../lib/App/common/serverDataBinder.h ../../lib/App/common/dataBinder_structures.h ../../lib/data/mysql/mysql_class.h ../../lib/components/base/basicSettingsProvider.h ../../lib/alg/generic/md5.h ../../lib/alg/lgs/mask.h $(OUTDIR)/servaKernelToolKit.o: ../../lib/App/serva/servaKernelToolKit.cpp ../../lib/App/serva/servaKernel.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicEventHeap.h ../../lib/components/object/objectSystemAnchor.h ../../lib/alg/lgs/detectorStructures.h ../../lib/alg/lgs/detector.h ../../lib/alg/lgs/mask.h ../../lib/alg/generic/md5.h ../../lib/App/common/kernelPrototype.h ../../lib/App/serva/lifeMonitoring.h ../../lib/App/serva/servaRemoteClient.h ../../lib/data/net/netServer.h -$(OUTDIR)/servaRemoteClient.o: ../../lib/App/serva/servaRemoteClient.cpp ../../lib/App/serva/servaRemoteClient.h ../../lib/data/net/netServer.h ../../lib/App/serva/servaRemoteClientHandler.h ../../lib/data/net/netClientHandler.h ../../lib/data/protocol/protocol.h ../../lib/data/protocol/protocolARGUS_DATA.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicEvent.h ../../lib/App/serva/servaKernel.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicEventHeap.h ../../lib/components/object/objectSystemAnchor.h ../../lib/alg/lgs/detectorStructures.h ../../lib/alg/lgs/detector.h ../../lib/alg/lgs/mask.h ../../lib/alg/generic/md5.h ../../lib/App/common/kernelPrototype.h ../../lib/App/serva/lifeMonitoring.h ../../lib/App/serva/servaRemoteClient.h ../../lib/data/net/netServer.h -$(OUTDIR)/servaRemoteClientHandler.o: ../../lib/App/serva/servaRemoteClientHandler.cpp ../../lib/App/serva/servaRemoteClientHandler.h ../../lib/data/net/netClientHandler.h ../../lib/data/protocol/protocol.h ../../lib/data/protocol/protocolARGUS_DATA.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicEvent.h ../../lib/App/serva/servaRemoteClient.h ../../lib/data/net/netServer.h ../../lib/App/serva/servaKernel.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicEventHeap.h ../../lib/components/object/objectSystemAnchor.h ../../lib/alg/lgs/detectorStructures.h ../../lib/alg/lgs/detector.h ../../lib/alg/lgs/mask.h ../../lib/alg/generic/md5.h ../../lib/App/common/kernelPrototype.h ../../lib/App/serva/lifeMonitoring.h ../../lib/App/serva/servaRemoteClient.h ../../lib/data/net/netServer.h +$(OUTDIR)/servaMediaEncoder.o: ../../lib/App/serva/servaMediaEncoder.cpp ../../lib/App/serva/servaMediaEncoder.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicLIBAV.h ../../lib/components/base/basicLogCollection.h +$(OUTDIR)/servaRemoteClient.o: ../../lib/App/serva/servaRemoteClient.cpp ../../lib/App/serva/servaRemoteClient.h ../../lib/data/net/netServer.h ../../lib/App/serva/servaRemoteClientHandler.h ../../lib/data/net/netClientHandler.h ../../lib/data/protocol/protocol.h ../../lib/data/protocol/protocolARGUS_DATA.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicThread.h ../../lib/App/common/serverMySQL_dataBinder.h ../../lib/App/common/serverDataBinder.h ../../lib/App/common/dataBinder_structures.h ../../lib/data/mysql/mysql_class.h ../../lib/components/base/basicSettingsProvider.h ../../lib/alg/generic/md5.h ../../lib/alg/lgs/mask.h ../../lib/App/serva/servaKernel.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicEventHeap.h ../../lib/components/object/objectSystemAnchor.h ../../lib/alg/lgs/detectorStructures.h ../../lib/alg/lgs/detector.h ../../lib/alg/lgs/mask.h ../../lib/alg/generic/md5.h ../../lib/App/common/kernelPrototype.h ../../lib/App/serva/lifeMonitoring.h ../../lib/App/serva/servaRemoteClient.h ../../lib/data/net/netServer.h +$(OUTDIR)/servaRemoteClientHandler.o: ../../lib/App/serva/servaRemoteClientHandler.cpp ../../lib/App/serva/servaRemoteClientHandler.h ../../lib/data/net/netClientHandler.h ../../lib/data/protocol/protocol.h ../../lib/data/protocol/protocolARGUS_DATA.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicThread.h ../../lib/App/common/serverMySQL_dataBinder.h ../../lib/App/common/serverDataBinder.h ../../lib/App/common/dataBinder_structures.h ../../lib/data/mysql/mysql_class.h ../../lib/components/base/basicSettingsProvider.h ../../lib/alg/generic/md5.h ../../lib/alg/lgs/mask.h ../../lib/App/serva/servaRemoteClient.h ../../lib/data/net/netServer.h ../../lib/App/serva/servaKernel.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicEventHeap.h ../../lib/components/object/objectSystemAnchor.h ../../lib/alg/lgs/detectorStructures.h ../../lib/alg/lgs/detector.h ../../lib/alg/lgs/mask.h ../../lib/alg/generic/md5.h ../../lib/App/common/kernelPrototype.h ../../lib/App/serva/lifeMonitoring.h ../../lib/App/serva/servaRemoteClient.h ../../lib/data/net/netServer.h $(OUTDIR)/serverDataBinder.o: ../../lib/App/common/serverDataBinder.cpp ../../lib/App/common/serverDataBinder.h ../../lib/App/common/dataBinder_structures.h $(OUTDIR)/serverMySQL_dataBinder.o: ../../lib/App/common/serverMySQL_dataBinder.cpp ../../lib/App/common/serverMySQL_dataBinder.h ../../lib/App/common/serverDataBinder.h ../../lib/App/common/dataBinder_structures.h ../../lib/data/mysql/mysql_class.h ../../lib/components/base/basicSettingsProvider.h ../../lib/alg/generic/md5.h ../../lib/alg/lgs/mask.h $(OUTDIR)/serverPort.o: ../../lib/data/net/serverPort.cpp ../../lib/data/net/serverPort.h diff --git a/lib/App/common/dataBinder_structures.h b/lib/App/common/dataBinder_structures.h index cf61924b..a00174b2 100644 --- a/lib/App/common/dataBinder_structures.h +++ b/lib/App/common/dataBinder_structures.h @@ -747,6 +747,8 @@ typedef struct S_VIDEO_SEGMENT_INFO{ DBC_INT_LIST eventTMS; char recordMD5[33]; char recordEXT[6]; + uint16_t streamWidth; + uint16_t streamHeight; uint8_t streamFPS; char scratchPath[PATH_MAX]; uint32_t dataSize; @@ -857,4 +859,14 @@ typedef struct S_DBC_REPORT_BACKUP_SETTINGS{ }DBC_REPORT_BACKUP_SETTINGS; +typedef struct S_DBC_RPC_MEDIA_INFO{ + char uuid[65]; + uint64_t reg_id; + uint64_t src; + uint16_t width; + uint16_t height; + uint8_t fps; + char fmt[6]; +}DBC_RPC_MEDIA_INFO; + #endif \ No newline at end of file diff --git a/lib/App/common/deviceNodeCamera.cpp b/lib/App/common/deviceNodeCamera.cpp index 77d041b5..8943e569 100644 --- a/lib/App/common/deviceNodeCamera.cpp +++ b/lib/App/common/deviceNodeCamera.cpp @@ -105,6 +105,7 @@ deviceNodeCamera::deviceNodeCamera( uint32_t NodeID ): deviceNode( NodeID ), bas m_bCurrentPresetCol = 0; m_bCurrentPresetRow = 0; m_bShineOnTarget = false; + m_bCameraIsStatic = false; m_bIRIsOn = false; m_bIRTO = 0; m_fSpeedRise = 0.03f; @@ -466,6 +467,8 @@ bool deviceNodeCamera::create(){ if( ( m_sCamData.type == ARGUS_IP_PRESET_CAMERA ) || ( m_sCamData.type == ARGUS_ANALOG_PRESET_CAMERA ) ) m_bNoAbsPositionning = true; if (m_pProtocol == NULL) { if( m_sCamData.protocol == 0 ) { + m_bCameraIsStatic = true; + m_bSkeepPositioningWait = true; m_sCamData.online = true; } else LOG_ERROR("No Proto Created!"); } else { @@ -580,7 +583,7 @@ bool deviceNodeCamera::fusion_compare( CAM_ROI *ptr, C3D_SPH_DEGREES tp ){ bool deviceNodeCamera::fusion_consumeData( uint32_t db_id, C3D_SPH_DEGREES tOR ){ if( db_id == 0 ) return false; - CAM_TRACK_RECORD * tTrackRecord = (CAM_TRACK_RECORD * ) malloc( sizeof(CAM_TRACK_RECORD)); + CAM_TRACK_RECORD *tTrackRecord = (CAM_TRACK_RECORD *)malloc(sizeof(CAM_TRACK_RECORD)); if( tTrackRecord == NULL ) return false; #ifdef DEBUG_EXTRA LOG("Fusion: Consuming new Data!"); @@ -1584,6 +1587,7 @@ bool deviceNodeCamera::testFOV( C3D_SPH_DEGREES SL ){ }; bool deviceNodeCamera::lookAt( uint32_t TargetRefID, C3D_WGS84_LOC L ){ + if ( m_bCameraIsStatic ) return true; systemAnchor* tSystem = systemAnchor::getInstance(); if( tSystem == NULL ) return false; C3D_SPH_DEGREES SL; @@ -1595,6 +1599,7 @@ bool deviceNodeCamera::lookAt( uint32_t TargetRefID, C3D_WGS84_LOC L ){ }; bool deviceNodeCamera::lookAt( uint32_t TargetRefID, C3D_DECART L ){ + if ( m_bCameraIsStatic ) return true; systemAnchor* tSystem = systemAnchor::getInstance(); if( tSystem == NULL ) return false; C3D_SPH_DEGREES SL; @@ -1606,6 +1611,7 @@ bool deviceNodeCamera::lookAt( uint32_t TargetRefID, C3D_DECART L ){ }; bool deviceNodeCamera::lookAt( uint32_t TargetRefID, C3D_SPH_RADIANS L ){ + if ( m_bCameraIsStatic ) return true; C3D_SPH_DEGREES SL; #ifdef DEBUG_EXTRA LOG("Look at spherical(rad) 2 spherical(deg) coords!"); @@ -1615,6 +1621,7 @@ bool deviceNodeCamera::lookAt( uint32_t TargetRefID, C3D_SPH_RADIANS L ){ }; bool deviceNodeCamera::lookAt( uint32_t TargetRefID, C3D_SPH_DEGREES L ){ + if ( m_bCameraIsStatic ) return true; //char tB[128]; //sprintf(tB, "Target On %.3f %.3f %.3f", L.r, L.fi, L.tetta ); //LOG( tB ); @@ -1652,6 +1659,7 @@ bool deviceNodeCamera::makeSnap( uint32_t TargetRefID ){ tTask->CMD = (CAM_PTZ_CMD *) malloc( sizeof(CAM_PTZ_CMD) ); if( tTask->CMD ){ tTask->CMD->CMD = PTZ_CAPTURE_ONLY; + tTask->movemet_needed = false; tTask->source_evt_id = TargetRefID; return pushCamTask( tTask ); } else { diff --git a/lib/App/common/deviceNodeCamera.h b/lib/App/common/deviceNodeCamera.h index 0db85169..4bb4cfe5 100644 --- a/lib/App/common/deviceNodeCamera.h +++ b/lib/App/common/deviceNodeCamera.h @@ -170,6 +170,7 @@ class deviceNodeCamera: public deviceNode, public basicThread { bool m_bSkeepPositioningWait; bool m_bNoAbsPositionning; + bool m_bCameraIsStatic; //IR functionality basicMutex m_mIRProtector; bool m_bShineOnTarget; diff --git a/lib/App/common/deviceNodeStaticCamControl.cpp b/lib/App/common/deviceNodeStaticCamControl.cpp index faa22012..05e3fd61 100644 --- a/lib/App/common/deviceNodeStaticCamControl.cpp +++ b/lib/App/common/deviceNodeStaticCamControl.cpp @@ -77,6 +77,15 @@ bool deviceNodeStaticCamControl::dispatchEvent( EVENT_CONTAINER *E ){ case EVT_CLASS_SENSOR_3D: case EVT_CLASS_SENSOR_ACC:{ switch( E->m_eType ) { + case EVT_ROI_ACTIVE:{ + TARGET_DATA *tDATA; + tDATA = (TARGET_DATA *)E->m_pEvtData; + LOG( "ROI" ); + if( tDATA ) { + makeSnap(E->m_db_id); + }; + break; + }; case EVT_TARGET_1D: case EVT_TARGET_2D_BLACK: case EVT_TARGET_2D_WHITE: diff --git a/lib/App/common/kernelModuleEmbedVideo.cpp b/lib/App/common/kernelModuleEmbedVideo.cpp index 85a58927..a93b0fd0 100644 --- a/lib/App/common/kernelModuleEmbedVideo.cpp +++ b/lib/App/common/kernelModuleEmbedVideo.cpp @@ -2592,6 +2592,8 @@ bool streamHandler::openSegmentA( void ){ //strncpy( m_sStreamSegmentInfo[0].recordEXT, VIDEO_OUTPUT_CONTAINER, 4 ); strncpy( m_sStreamSegmentInfo[0].recordEXT, VIDEO_OUTPUT_CONTAINER, 6 ); m_sStreamSegmentInfo[0].streamFPS = m_sStreamData.fps; + m_sStreamSegmentInfo[0].streamWidth = m_pMaster->getWidh(); + m_sStreamSegmentInfo[0].streamWidth = m_pMaster->getHeight(); m_sStreamSegmentInfo[0].eventIDS.clear(); m_sStreamSegmentInfo[0].eventTSS.clear(); m_sStreamSegmentInfo[0].eventTMS.clear(); @@ -2745,6 +2747,8 @@ bool streamHandler::openSegmentB( void ){ //strncpy( m_sStreamSegmentInfo[1].recordEXT, VIDEO_OUTPUT_CONTAINER, 4 ); strncpy( m_sStreamSegmentInfo[1].recordEXT, VIDEO_OUTPUT_CONTAINER, 6 ); m_sStreamSegmentInfo[1].streamFPS = m_sStreamData.fps; + m_sStreamSegmentInfo[0].streamWidth = m_pMaster->getWidh(); + m_sStreamSegmentInfo[0].streamWidth = m_pMaster->getHeight(); m_sStreamSegmentInfo[1].eventIDS.clear(); m_sStreamSegmentInfo[1].eventTSS.clear(); m_sStreamSegmentInfo[1].eventTMS.clear(); diff --git a/lib/App/common/kernelModuleModemManager.cpp b/lib/App/common/kernelModuleModemManager.cpp index 3bfac649..10912054 100644 --- a/lib/App/common/kernelModuleModemManager.cpp +++ b/lib/App/common/kernelModuleModemManager.cpp @@ -118,8 +118,14 @@ void kernelModuleModemManager::m_fThreadProc( void ){ if ( nCurrentPhoneBookId < m_vPhoneBook.size() ) { DBC_MODEM_PHONEBOOK_RECORD *tRECORD = m_vPhoneBook.at( nCurrentPhoneBookId ); if ( tRECORD ) { + m_bCurrentMode = tRECORD->mode; m_pDBC->updateModemManagerActivePhoneBookID( m_sMMData.id, tRECORD->id ); - if( tRECORD->mode == 0 ){ + + if( m_bCurrentMode == 0 ){ + if ( !m_sMMData.call_enabled ) { + setWM( MDM_FETCH_NEXT_WM ); + break; + }; nCurrentCallId = -1; LOG("Start Call"); char CMD[128]; @@ -147,11 +153,38 @@ void kernelModuleModemManager::m_fThreadProc( void ){ setWM( MDM_FETCH_NEXT_WM ); }; } else { + if ( !m_sMMData.sms_enabled ) { + setWM( MDM_FETCH_NEXT_WM ); + break; + }; + nCurrentCallId = -1; LOG("Start SMS"); - nCurrentCallId = 0; - sendSMS( tRECORD->number, tRECORD->custom_msg ); - //No need to wait SMS - setWM( MDM_FETCH_NEXT_WM ); + char CMSG[512]; + char CMD[1024]; + sprintf( CMSG, "Alarm Message\nSystem at http://%s/", m_cMyWanIP,tRECORD->custom_msg ); + sprintf( CMD, "mmcli -m %d --messaging-create-sms=\"text='%s',number='%s'\"", m_sMMData.modem_id, CMSG, tRECORD->number ); + LOG( CMD ); + FILE *fd = popen( CMD, "r"); + if ( fd ) { + char tB[1024]; + if ( fread( tB, 1, 1023, fd ) > 0 ) { + CSTR tS = strstr( tB, "SMS/" ); + if ( tS ) { + nCurrentCallId = atoi( tS+4 ); + }; + }; + pclose( fd ); + } else LOG_ERROR("Cannot Start POPEN 1!"); + if( nCurrentCallId > -1 ) { + sprintf( CMD, "mmcli -s %d --send", nCurrentCallId ); + system( CMD ); + m_pDBC->updateModemManagerActiveCall( m_sMMData.id, nCurrentCallId ); + lNextWindowAction = getMilliseconds() + m_sMMData.call_hangup_wait * 1000; + // Need to wait till calling + setWM( MDM_MODEM_IS_BUSY_WM ); + } else { + setWM( MDM_FETCH_NEXT_WM ); + }; }; } else { char ttB[65]; @@ -168,45 +201,76 @@ void kernelModuleModemManager::m_fThreadProc( void ){ break; }; case MDM_MODEM_IS_BUSY_WM:{ - char CMD[128]; - bool call_is_answered = false; - bool call_is_terminated = false; - bool call_is_finished = false; - sprintf( CMD, "mmcli -m %d --voice-list-calls" , m_sMMData.modem_id ); - FILE *fd = popen( CMD, "r"); - if ( fd ) { - char tB[1024]; - if ( fread( tB, 1, 1023, fd ) > 0 ) { - CSTR tS = strstr( tB, "(active)" ); - if ( tS ) { - call_is_answered = true; + if ( m_bCurrentMode == 0 ) { + // Finishing Call + char CMD[128]; + bool call_is_answered = false; + bool call_is_terminated = false; + bool call_is_finished = false; + sprintf( CMD, "mmcli -m %d --voice-list-calls" , m_sMMData.modem_id ); + FILE *fd = popen( CMD, "r"); + if ( fd ) { + char tB[1024]; + if ( fread( tB, 1, 1023, fd ) > 0 ) { + CSTR tS = strstr( tB, "(active)" ); + if ( tS ) { + call_is_answered = true; + }; + tS = strstr( tB, "(terminated)" ); + if ( tS ) { + call_is_terminated = true; + }; }; - tS = strstr( tB, "(terminated)" ); - if ( tS ) { - call_is_terminated = true; + pclose( fd ); + } else LOG_ERROR("Cannot Start POPEN 2!"); + if ( call_is_answered || call_is_terminated ) { + if ( call_is_answered ) { + LOG("Call is Answered!!"); + //Send Voice Message to user }; + call_is_finished = true; + } else { + if ( lNextWindowAction < getMilliseconds() ) call_is_finished = true; }; - pclose( fd ); - } else LOG_ERROR("Cannot Start POPEN 2!"); - if ( call_is_answered || call_is_terminated ) { - if ( call_is_answered ) { - LOG("Call is Answered!!"); - //Send Voice Message to user + if ( call_is_finished ) { + LOG("Hangup Call"); + sprintf( CMD, "mmcli -m %d --call %d --hangup", m_sMMData.modem_id, nCurrentCallId ); + LOG( CMD ); + system( CMD ); + sprintf( CMD, "mmcli -m %d --voice-delete-call=%d", m_sMMData.modem_id, nCurrentCallId ); + LOG( CMD ); + system( CMD ); + m_pDBC->updateModemManagerActiveCall( m_sMMData.id, -1 ); + setWM( MDM_FETCH_NEXT_WM ); }; - call_is_finished = true; } else { - if ( lNextWindowAction < getMilliseconds() ) call_is_finished = true; - }; - if ( call_is_finished ) { - LOG("Hangup Call"); - sprintf( CMD, "mmcli -m %d --call %d --hangup", m_sMMData.modem_id, nCurrentCallId ); - LOG( CMD ); - system( CMD ); - sprintf( CMD, "mmcli -m %d --voice-delete-call=%d", m_sMMData.modem_id, nCurrentCallId ); - LOG( CMD ); - system( CMD ); - m_pDBC->updateModemManagerActiveCall( m_sMMData.id, -1 ); - setWM( MDM_FETCH_NEXT_WM ); + // Finishing SMS + char CMD[128]; + bool sms_is_sent = false; + sprintf( CMD, "mmcli -m %d --messaging-list-sms" , m_sMMData.modem_id ); + FILE *fd = popen( CMD, "r"); + if ( fd ) { + char tB[1024]; + if ( fread( tB, 1, 1023, fd ) > 0 ) { + CSTR tS = strstr( tB, "(sent)" ); + if ( tS ) { + sms_is_sent = true; + }; + }; + pclose( fd ); + } else LOG_ERROR("Cannot Start POPEN 2!"); + if ( sms_is_sent ) { + LOG("SMS is Sent!!"); + } else { + if ( lNextWindowAction < getMilliseconds() ) sms_is_sent = true; + }; + if ( sms_is_sent ) { + sprintf( CMD, "mmcli -m %d --messaging-delete-sms=%d", m_sMMData.modem_id, nCurrentCallId ); + LOG( CMD ); + system( CMD ); + m_pDBC->updateModemManagerActiveCall( m_sMMData.id, -1 ); + setWM( MDM_FETCH_NEXT_WM ); + }; }; break; }; diff --git a/lib/App/common/kernelModuleModemManager.h b/lib/App/common/kernelModuleModemManager.h index 90733e79..fae6b945 100644 --- a/lib/App/common/kernelModuleModemManager.h +++ b/lib/App/common/kernelModuleModemManager.h @@ -48,6 +48,7 @@ class kernelModuleModemManager: public kernelModule, public basicThread { bool sessionStarted; bool notificationSent; char m_cMyWanIP[32]; + uint8_t m_bCurrentMode; //uint32_t m_nWindowCounterTO; // MThread procs static void * callProc( void * ); diff --git a/lib/App/common/serverDataBinder.h b/lib/App/common/serverDataBinder.h index 25a01285..7c77da16 100644 --- a/lib/App/common/serverDataBinder.h +++ b/lib/App/common/serverDataBinder.h @@ -19,11 +19,14 @@ class serverDataBinder { serverDataBinder(); virtual ~serverDataBinder(); /* Functionality */ + virtual uint64_t addMediaQueueRecord( CSTR uuid, CSTR tMD5, uint64_t src, uint32_t ts, uint16_t tsms, uint16_t width, uint16_t height, CSTR fmt ){ return 0;}; virtual bool connect( void ){ return false; }; virtual char getMojoWM( uint64_t id ){ return 'N'; }; virtual uint64_t getBottomLRF( uint64_t id ){ return 0; }; virtual uint32_t getCloudLTS( uint8_t Obj, uint64_t id ){ return 0; }; virtual uint8_t getCloudStatus( uint8_t Obj, uint64_t id ){ return 0; }; + virtual uint64_t getRecentMediaId(){ return 0;}; + virtual DBC_RPC_MEDIA_INFO * getRemoteMediaInfo( uint64_t id ){ return NULL; }; virtual uint64_t getUpperLRF( uint64_t id ){ return 0; }; virtual bool putIntoLog( CSTR A, CSTR B, CSTR Msg ){ return false; }; virtual uint64_t registerMojo( CSTR A, CSTR B ){ return 0; }; @@ -32,6 +35,7 @@ class serverDataBinder { virtual bool setNodeOnline( uint32_t NodeID, uint8_t status ){ return false; }; virtual bool setCloudStatus( uint8_t Obj, uint64_t id, uint32_t status, CSTR sid = NULL ){ return false; }; virtual bool unregisterServer(){ return false; }; + virtual bool updateEncodeStatus( uint64_t dbid, uint8_t status, uint8_t perc = 0 ){ return false; }; virtual bool updateServerUtilisation( DBC_SYS_LOAD_INFO *ptr ){ return false; }; }; diff --git a/lib/App/common/serverMySQL_dataBinder.cpp b/lib/App/common/serverMySQL_dataBinder.cpp index 4734839e..fab15e72 100644 --- a/lib/App/common/serverMySQL_dataBinder.cpp +++ b/lib/App/common/serverMySQL_dataBinder.cpp @@ -42,6 +42,31 @@ servaMySQLDBC::~servaMySQLDBC(){ _instance = NULL; }; +uint64_t servaMySQLDBC::addMediaQueueRecord( CSTR uuid, CSTR tMD5, uint64_t src, uint32_t ts, uint16_t tsms, uint16_t width, uint16_t height, CSTR fmt ){ + uint64_t RetVal = 0; + if(m_bIsConnected){ + char tQBuf[4096]; + LOG("Before"); + sprintf( tQBuf, "INSERT INTO `report_videos` SET `mojo_id`=%" PRIu64 ", `md5`='%s', `ts`=%d, `ts_ms`=%d, `recoded`=0", src, tMD5, ts, tsms ); + //sprintf( tQBuf, "Yenana"); +//#ifdef DEBUG + LOG(tQBuf); +//#endif + + uint64_t ref_id = m_pDatabase->QueryID( tQBuf ); + if ( ref_id ) { + sprintf( tQBuf, "INSERT INTO `media_queue` SET `ts`=UNIX_TIMESTAMP(now()), `uuid`='%s', `reg_id`=%" PRIu64 ", `src`=%" PRIu64 ", `width`=%d, `height`=%d, `fmt`='%s', `status`=0, `process`=0", + uuid, ref_id, src, width, height, fmt + ); +//#ifdef DEBUG + LOG(tQBuf); +//#endif + RetVal = m_pDatabase->QueryID( tQBuf ); + }; + }; + return RetVal; +}; + bool servaMySQLDBC::connect( void ){ config_setting_t * tSetting; m_bIsConnected = false; @@ -93,7 +118,7 @@ char servaMySQLDBC::getMojoWM( uint64_t id ){ if( m_bIsConnected ){ char tQBuf[MAX_PATH_LEN]; AAssoc *result; - sprintf( tQBuf, "SELECT `status` FROM `module_nodes` WHERE `id`=%lld", id ); + sprintf( tQBuf, "SELECT `status` FROM `module_nodes` WHERE `id`=%" PRIu64 "", id ); result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { @@ -139,7 +164,7 @@ uint32_t servaMySQLDBC::getCloudLTS( uint8_t Obj, uint64_t id ){ if( m_bIsConnected ){ char tQBuf[MAX_PATH_LEN]; AAssoc *result; - sprintf( tQBuf, "SELECT `ts` FROM `mem_online_cloud` WHERE `object_id`=%lld AND `object_type`=%d", id, Obj ); + sprintf( tQBuf, "SELECT `ts` FROM `mem_online_cloud` WHERE `object_id`=%" PRIu64 " AND `object_type`=%d", id, Obj ); LOG( tQBuf ); result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { @@ -163,7 +188,7 @@ uint8_t servaMySQLDBC::getCloudStatus( uint8_t Obj, uint64_t id ){ if( m_bIsConnected ){ char tQBuf[MAX_PATH_LEN]; AAssoc *result; - sprintf( tQBuf, "SELECT `status` FROM `mem_online_cloud` WHERE `object_id`=%lld AND `object_type`=%d", id, Obj ); + sprintf( tQBuf, "SELECT `status` FROM `mem_online_cloud` WHERE `object_id`=%" PRIu64 " AND `object_type`=%d", id, Obj ); result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { @@ -181,6 +206,77 @@ uint8_t servaMySQLDBC::getCloudStatus( uint8_t Obj, uint64_t id ){ return RetVal; }; +uint64_t servaMySQLDBC::getRecentMediaId(){ + uint64_t RetVal = 0; + if( m_bIsConnected ){ + char tQBuf[MAX_PATH_LEN]; + AAssoc *result; + sprintf( tQBuf, "SELECT `id` FROM `media_queue` WHERE `status`=1" ); + result = m_pDatabase->Query( tQBuf ); + if( result!= NULL ) { + if( result->size() > 0 ) { + Assoc *cArr; + Assoc::iterator it; + cArr = result->at(0); + it = cArr->find("id"); + if( it != cArr->end() ){ + RetVal = atoll( it->second.c_str() ); + }; + }; + }; + deleteResult( result ); + }; + return RetVal; +}; + +DBC_RPC_MEDIA_INFO *servaMySQLDBC::getRemoteMediaInfo( uint64_t id ){ + DBC_RPC_MEDIA_INFO *RetVal = NULL; + if( m_bIsConnected ){ + char tQBuf[MAX_PATH_LEN]; + AAssoc *result; + sprintf( tQBuf, "SELECT * FROM `media_queue` WHERE `id`='%" PRIu64 "'", id ); + result = m_pDatabase->Query( tQBuf ); + if( result!= NULL ) { + if (result->size() > 0) { + Assoc *cArr; + Assoc::iterator it; + RetVal = ( DBC_RPC_MEDIA_INFO *) malloc(sizeof(DBC_RPC_MEDIA_INFO)); + if ( RetVal ) { + cArr = result->at(0); + it = cArr->find("uuid"); + if( it != cArr->end() ){ + strncpy( RetVal->uuid, it->second.c_str(), 64 ); + RetVal->uuid[64] = (char)0; + }; + it = cArr->find("reg_id"); + if( it != cArr->end() ){ + RetVal->reg_id = atoll( it->second.c_str() ); + }; + it = cArr->find("src"); + if( it != cArr->end() ){ + RetVal->src = atoll( it->second.c_str() ); + }; + it = cArr->find("width"); + if( it != cArr->end() ){ + RetVal->width = atoi( it->second.c_str() ); + }; + it = cArr->find("height"); + if( it != cArr->end() ){ + RetVal->height = atoi( it->second.c_str() ); + }; + it = cArr->find("fmt"); + if( it != cArr->end() ){ + strncpy( RetVal->fmt, it->second.c_str(), 5 ); + RetVal->fmt[5] = (char)0; + }; + }; + }; + }; + deleteResult( result ); + }; + return RetVal; +}; + uint64_t servaMySQLDBC::getUpperLRF( uint64_t id ){ uint64_t RetVal = 0; if( m_bIsConnected ){ @@ -363,10 +459,10 @@ bool servaMySQLDBC::setCloudStatus( uint8_t Obj, uint64_t id, uint32_t status, C char tQBuf[CTEXT]; uint32_t CTS = time( NULL ); if( sid ) { - sprintf(tQBuf, "INSERT INTO `mem_online_cloud` SET `object_id`=%lld, `object_type`=%d, `status`=%d, `ts`=%d, `SID`='%s' ON DUPLICATE KEY UPDATE `status`=%d, `ts`=%d, `SID`='%s'", + sprintf(tQBuf, "INSERT INTO `mem_online_cloud` SET `object_id`=%" PRIu64 ", `object_type`=%d, `status`=%d, `ts`=%d, `SID`='%s' ON DUPLICATE KEY UPDATE `status`=%d, `ts`=%d, `SID`='%s'", id, Obj, status, CTS, sid, status, CTS, sid ); } else { - sprintf(tQBuf, "INSERT INTO `mem_online_cloud` SET `object_id`=%lld, `object_type`=%d, `status`=%d, `ts`=%d ON DUPLICATE KEY UPDATE `status`=%d, `ts`=%d", + sprintf(tQBuf, "INSERT INTO `mem_online_cloud` SET `object_id`=%" PRIu64 ", `object_type`=%d, `status`=%d, `ts`=%d ON DUPLICATE KEY UPDATE `status`=%d, `ts`=%d", id, Obj, status, CTS, status, CTS ); }; #ifdef DEBUG_ALL @@ -378,6 +474,21 @@ bool servaMySQLDBC::setCloudStatus( uint8_t Obj, uint64_t id, uint32_t status, C return false; }; +bool servaMySQLDBC::updateEncodeStatus( uint64_t dbid, uint8_t status, uint8_t perc ){ + if( m_bIsConnected ) { + char tQBuf[4096]; + sprintf(tQBuf, "UPDATE `media_queue` SET `ts`=UNIX_TIMESTAMP(now()), `status`=%d, `process`=%d WHERE `id`=%" PRIu64, + status, perc, dbid + ); +#ifdef DEBUG + LOG(tQBuf); +#endif + m_pDatabase->SilentQuery( tQBuf ); + return true; + }; + return false; +}; + //bool servaMySQLDBC::updateServerUtilisation( uint32_t ServerID, uint32_t nCores, float cpu1, float cpu5, float cpu15, float mem, float disk, uint64_t dtsize, uint64_t dcsize, uint64_t mtsize, uint64_t mcsize ){ bool servaMySQLDBC::updateServerUtilisation( DBC_SYS_LOAD_INFO *ptr ){ if( m_bIsConnected ) { @@ -405,18 +516,6 @@ bool servaMySQLDBC::updateServerUtilisation( DBC_SYS_LOAD_INFO *ptr ){ return false; }; -bool servaMySQLDBC::updateVideoTransfer( uint32_t rid, uint8_t status, uint8_t process ){ - if( m_bIsConnected ) { - char tQBuf[MAX_PATH_LEN]; - sprintf( tQBuf, "UPDATE `media_queue` SET `status`=%d, `process`=%d WHERE `id`=%d", status, process, rid ); -#ifdef DEBUG_ALL - LOG(tQBuf); -#endif - m_pDatabase->SilentQuery( tQBuf ); - return true; - }; - return false; -}; #undef LOG #undef LOG_ERROR diff --git a/lib/App/common/serverMySQL_dataBinder.h b/lib/App/common/serverMySQL_dataBinder.h index f8ab48f6..e656a473 100644 --- a/lib/App/common/serverMySQL_dataBinder.h +++ b/lib/App/common/serverMySQL_dataBinder.h @@ -22,6 +22,7 @@ class servaMySQLDBC: public serverDataBinder { static servaMySQLDBC * _instance; explicit servaMySQLDBC( config_setting_t * Settings = NULL ); public: + virtual uint64_t addMediaQueueRecord( CSTR uuid, CSTR tMD5, uint64_t src, uint32_t ts, uint16_t tsms, uint16_t width, uint16_t height, CSTR fmt ); static servaMySQLDBC * getInstance( config_setting_t * Settings = NULL ); virtual ~servaMySQLDBC(); /* Functionality */ @@ -30,7 +31,9 @@ class servaMySQLDBC: public serverDataBinder { virtual uint64_t getBottomLRF( uint64_t id ); virtual uint32_t getCloudLTS( uint8_t Obj, uint64_t id ); virtual uint8_t getCloudStatus( uint8_t Obj, uint64_t id ); - virtual uint64_t getUpperLRF( uint64_t id ); + virtual DBC_RPC_MEDIA_INFO * getRemoteMediaInfo( uint64_t id ); + virtual uint64_t getRecentMediaId(); + virtual uint64_t getUpperLRF( uint64_t id ); virtual bool putIntoLog( CSTR type, CSTR TS, CSTR Msg ); virtual uint64_t registerMojo( CSTR A, CSTR B ); virtual bool registerServer( uint32_t SiteID, CSTR identity, int PID, uint32_t *ServID, uint32_t *ServNode ); @@ -39,8 +42,9 @@ class servaMySQLDBC: public serverDataBinder { virtual bool setNodeOnline( uint32_t NodeID, uint8_t status ); virtual bool setCloudStatus( uint8_t Obj, uint64_t id, uint32_t status, CSTR sid = NULL ); virtual bool unregisterServer(); + virtual bool updateEncodeStatus( uint64_t dbid, uint8_t status, uint8_t perc = 0 ); virtual bool updateServerUtilisation( DBC_SYS_LOAD_INFO *ptr ); - virtual bool updateVideoTransfer( uint32_t rid, uint8_t status, uint8_t process = 0 ); + }; diff --git a/lib/App/mojo/mojoKernel.cpp b/lib/App/mojo/mojoKernel.cpp index 8217f883..0b63ff3d 100644 --- a/lib/App/mojo/mojoKernel.cpp +++ b/lib/App/mojo/mojoKernel.cpp @@ -117,6 +117,7 @@ mojoKernel::~mojoKernel(){ // LOG( "BopBop!" ); // SLEEP(1000); //}; + if ( m_pRPC ) delete( m_pRPC ); #ifdef LINUX_KERNEL_WATCHDOG LOG("Disable WD!"); if( m_iWatchdogFd > -1 ) { @@ -202,16 +203,7 @@ bool mojoKernel::create(){ if ( m_bDebugMode ) m_bKeepLocalReport = true; //Forced in case of debug mode m_bWorkWithRemoteServer = m_sSiteData.use_remote_server; - if ( m_bWorkWithRemoteServer ) { -#ifdef DEBUG - LOG("Working With Remote Server"); -#endif - if ( m_pRPC = new mojoRemoteClient( this ) ) { - if( m_bWorkWithRemoteServer = m_pRPC->create() ){ - - } else LOG_ERROR("Cannot Connect to Remote Server!"); - } else m_bWorkWithRemoteServer = false; - }; + //Check date/Time if correct! // Just in case that we have local reports if ( m_bKeepLocalReport ) { @@ -268,6 +260,19 @@ bool mojoKernel::create(){ LOG_ERROR("Node Factory Failure!"); return false; }; + + + if ( m_bWorkWithRemoteServer ) { +#ifdef DEBUG + LOG("Working With Remote Server"); +#endif + if ( m_pRPC = new mojoRemoteClient( this ) ) { + if( m_bWorkWithRemoteServer = m_pRPC->create() ){ + + } else LOG_ERROR("Cannot Connect to Remote Server!"); + } else m_bWorkWithRemoteServer = false; + }; + return init(); }; @@ -653,8 +658,8 @@ void mojoKernel::validateFilters(){ bool mojoKernel::dispatchEvent( EVENT_CONTAINER *Evt ){ if( Evt == NULL ) return false; if( m_bWorkWithRemoteServer && ( m_pRPC!=NULL) ) m_pRPC->addEvent( Evt ); - if( m_pDBC == NULL) return false; if( !m_bKeepLocalReport ) return true; + if( m_pDBC == NULL) return false; switch (Evt->m_eClass) { case EVT_CLASS_SYSTEM: switch (Evt->m_eType) { @@ -1049,8 +1054,27 @@ bool mojoKernel::dispatchEvent( EVENT_CONTAINER *Evt ){ return true; }; +/* +typedef struct S_VIDEO_SEGMENT_INFO{ + uint32_t stream_id; + uint32_t streamTSS; + uint32_t streamTMS; + DBC_INT_LIST eventIDS; + DBC_INT_LIST eventFrames; + DBC_INT_LIST eventTSS; + DBC_INT_LIST eventTMS; + char recordMD5[33]; + char recordEXT[6]; + uint8_t streamFPS; + char scratchPath[PATH_MAX]; + uint32_t dataSize; + uint32_t db_id; +}VIDEO_SEGMENT_INFO; + +*/ void mojoKernel::handleVideo( VIDEO_SEGMENT_INFO *ptr ){ if ( fileExist( ptr->scratchPath ) ) { + bool bKeepVideoFile = false; if( ptr->recordMD5[0] ) { if( m_bKeepLocalReport ) { //if wm is debug -> add all to database, else send to server @@ -1075,7 +1099,7 @@ void mojoKernel::handleVideo( VIDEO_SEGMENT_INFO *ptr ){ char dB[MAX_PATH]; //sprintf( tB, "%s/data/videos/%s.%s", getcwd(dB,MAX_PATH), ptr->recordMD5, ptr->recordEXT ); sprintf(tB, "%s/data/reports/%s/%s.%s", getcwd(dB, MAX_PATH), tP, ptr->recordMD5, ptr->recordEXT ); - fileCopy(ptr->scratchPath, tB); + fileCopy( ptr->scratchPath, tB ); ch_chown( tB, "nobody", "nogroup" ); chmod( tB, 0664 ); #ifdef DEBUG @@ -1089,11 +1113,16 @@ void mojoKernel::handleVideo( VIDEO_SEGMENT_INFO *ptr ){ LOG_ERROR("Failure in registration video!"); }; }; + if( m_bWorkWithRemoteServer && ( m_pRPC!=NULL) ){ + bKeepVideoFile = m_pRPC->addVideo( ptr ); + }; }; - unlink( ptr->scratchPath ); + if( !bKeepVideoFile ){ + unlink( ptr->scratchPath ); #ifdef DEBUG - LOG("Video Scratch Deleted!"); + LOG("Video Scratch Deleted!"); #endif + }; } else LOG_ERROR("Video File is Missing!"); }; diff --git a/lib/App/mojo/mojoKernel.h b/lib/App/mojo/mojoKernel.h index 5de01317..114a804d 100644 --- a/lib/App/mojo/mojoKernel.h +++ b/lib/App/mojo/mojoKernel.h @@ -75,7 +75,6 @@ class mojoKernel: public kernelPrototype{ bool m_bWorkWithRemoteServer; bool m_bSessionStarted; uint8_t m_bMediaMode; - uint32_t m_nNoAlarmCounter; #ifdef LA_METRO diff --git a/lib/App/mojo/mojoRemoteClient.cpp b/lib/App/mojo/mojoRemoteClient.cpp index c0fd0fa2..f30cc968 100644 --- a/lib/App/mojo/mojoRemoteClient.cpp +++ b/lib/App/mojo/mojoRemoteClient.cpp @@ -15,50 +15,55 @@ mojoRemoteClient::mojoRemoteClient( mojoKernel * ptr ):protocolParser(){ m_pLog = basicLogCollection::getInstance(); m_pPort = NULL; + m_pCurrentCMD = NULL; m_pMaster = ptr; m_nOutbondSerial = 0; m_nInbondSerial = 0; m_bShutdownCommunication = true; m_bCommunicationEstablished = false; m_bRegisteredWithRemotePeer = false; + m_pVideoHelper = new mojoVideoTransferHelper( ARGUS_RPC_DEFAULT_MEDIA_CHUNK ); m_qCMD = new RPC_CMD_QUEUE(); }; mojoRemoteClient::~mojoRemoteClient(){ + LOG("Destructor"); waitThreadEnd( true ); if( m_bRegisteredWithRemotePeer ) { //Unregister Mojo }; + LOG("Flushing"); + flushTransactions(); + if( m_pVideoHelper ) delete( m_pVideoHelper ); m_bShutdownCommunication = true; m_bCommunicationEstablished = false; m_bRegisteredWithRemotePeer = false; + LOG("Delete Port"); if ( m_pPort ) delete( m_pPort ); + LOG("Delete Ring"); delete( m_qCMD ); + LOG("Done"); }; bool mojoRemoteClient::create(){ if( m_pMaster == NULL ) return false; if( m_bCommunicationEstablished && ( m_bThreadStatus == TH_WORKING ) ) return true; m_bAutomationStage = ARGUS_RPC_STAGE_CONNECT; + m_pCurrentCMD = NULL; return init(); }; int mojoRemoteClient::packetChecker(U8 *Buffer, size_t BufferSize){ - //char tB[64]; if ( Buffer[0] == ARGUS_START_SERVER_FLAG ) { if( BufferSize > ARGUS_DATA_MSG_MIN_SIZE ){ - uint32_t SIZE = Buffer[1]; - SIZE = ( SIZE << 8 ) | Buffer[2]; - SIZE = ( SIZE << 8 ) | Buffer[3]; - SIZE = ( SIZE << 8 ) | Buffer[4]; - //sprintf( tB, "Pack Size: %08X", SIZE ); - //LOG(tB); + uint32_t SIZE = Buffer[5]; + SIZE = ( SIZE << 8 ) | Buffer[6]; + SIZE = ( SIZE << 8 ) | Buffer[7]; + SIZE = ( SIZE << 8 ) | Buffer[8]; if ( ( SIZE + ARGUS_HEADER_SIZE + ARGUS_CHECKSUM_SIZE ) <= BufferSize ) { uint16_t tCRC = checksum16( Buffer, SIZE + ARGUS_HEADER_SIZE ); uint16_t cCRC = Buffer[SIZE + ARGUS_HEADER_SIZE]; cCRC = ( cCRC << 8 ) | Buffer[SIZE + ARGUS_HEADER_SIZE+1]; - //sprintf( tB, "cCRC: %04X tCRC: %04X", tCRC, cCRC ); - //LOG(tB); if ( tCRC == cCRC ) return 0; } else return 1; // to grou } else return 1; //to grow @@ -70,10 +75,10 @@ protocolPackage *mojoRemoteClient::packetExtractor(U8 *Buffer, size_t BufferSize protocolPackage *tPack = (protocolPackage*) malloc( sizeof(protocolPackage)); if ( tPack ) { tPack->m_nCode = Buffer[ARGUS_HEADER_SIZE]; - tPack->m_nSize = Buffer[1]; - tPack->m_nSize = ( tPack->m_nSize << 8 ) | Buffer[2]; - tPack->m_nSize = ( tPack->m_nSize << 8 ) | Buffer[3]; - tPack->m_nSize = ( tPack->m_nSize << 8 ) | Buffer[4]; + tPack->m_nSize = Buffer[5]; + tPack->m_nSize = ( tPack->m_nSize << 8 ) | Buffer[6]; + tPack->m_nSize = ( tPack->m_nSize << 8 ) | Buffer[7]; + tPack->m_nSize = ( tPack->m_nSize << 8 ) | Buffer[8]; tPack->m_nSize = tPack->m_nSize + ARGUS_HEADER_SIZE + ARGUS_CHECKSUM_SIZE; tPack->m_pData = (U8 *) malloc( tPack->m_nSize ); if ( tPack->m_pData ) { @@ -87,21 +92,25 @@ protocolPackage *mojoRemoteClient::packetExtractor(U8 *Buffer, size_t BufferSize }; bool mojoRemoteClient::packetHandler( protocolPackage *Package ){ - m_nInbondSerial = Package->m_pData[1]; m_nInbondSerial = ( m_nInbondSerial << 8 ) | Package->m_pData[2]; m_nInbondSerial = ( m_nInbondSerial << 8 ) | Package->m_pData[3]; m_nInbondSerial = ( m_nInbondSerial << 8 ) | Package->m_pData[4]; - + //char bB[129]; + //sprintf( bB, "Code: %02X", Package->m_nCode ); + //LOG( bB ); switch( Package->m_nCode ){ - case ARGUS_DATA_MSG_REGISTER: + case ARGUS_DATA_MSG_REGISTER: + LOG("Reg From Server"); m_bRegisteredWithRemotePeer = true; - enqueueInfoMsg(); finishTransaction(); break; - case ARGUS_DATA_MSG_ACCESS_DENIED: m_bRegisteredWithRemotePeer = false; - case ARGUS_DATA_MSG_DISABLED: finishTransaction(); break; + case ARGUS_DATA_MSG_ACCESS_DENIED: m_bRegisteredWithRemotePeer = false; LOG("ACC DENIED"); + case ARGUS_DATA_MSG_DISABLED: finishTransaction(); LOG("MSG disabled"); break; + case ARGUS_DATA_MSG_INFO: finishTransaction(); break; + case ARGUS_DATA_MSG_GET_INFO: enqueueInfoMsg(); break; case ARGUS_DATA_MSG_REQ_TIME_SYNC:{ + LOG("TSYNC REQ"); RPC_CMD_RECORD *tCMD = (RPC_CMD_RECORD *)malloc(sizeof(RPC_CMD_RECORD)); if ( tCMD ) { tCMD->CMD = ARGUS_DATA_MSG_TIME_SYNC; @@ -120,6 +129,48 @@ bool mojoRemoteClient::packetHandler( protocolPackage *Package ){ }; free( tCMD ); }; + //Only On failure + finishTransaction(); + break; + }; + case ARGUS_DATA_MSG_EVT: finishTransaction(); break; + case ARGUS_DATA_MSG_VIDEO_INFO:{ + //get DATABASE ID + uint64_t tDBID = Package->m_pData[ARGUS_HEADER_SIZE+1]; + tDBID = ( tDBID << 8 ) | Package->m_pData[ARGUS_HEADER_SIZE+2]; + tDBID = ( tDBID << 8 ) | Package->m_pData[ARGUS_HEADER_SIZE+3]; + tDBID = ( tDBID << 8 ) | Package->m_pData[ARGUS_HEADER_SIZE+4]; + tDBID = ( tDBID << 8 ) | Package->m_pData[ARGUS_HEADER_SIZE+5]; + tDBID = ( tDBID << 8 ) | Package->m_pData[ARGUS_HEADER_SIZE+6]; + tDBID = ( tDBID << 8 ) | Package->m_pData[ARGUS_HEADER_SIZE+7]; + tDBID = ( tDBID << 8 ) | Package->m_pData[ARGUS_HEADER_SIZE+8]; + char tZ[128]; + sprintf( tZ, "Video Ack %lld ID", tDBID ); + LOG( tZ ); + m_pVideoHelper->setRemoteReferenceID( tDBID ); + }; + case ARGUS_DATA_MSG_VIDEO_DATA:{ + RPC_CMD_RECORD *tCMD = (RPC_CMD_RECORD *)malloc(sizeof(RPC_CMD_RECORD)); + if ( tCMD ) { + uint32_t tSize; + tCMD->CMD = ARGUS_DATA_MSG_VIDEO_DATA; + tCMD->DATA = (void *)m_pVideoHelper->getNextChunk( ARGUS_RPC_DEFAULT_MEDIA_CHUNK, &tSize ); + tCMD->DATA_SIZE = tSize; + //char tC[128]; + //sprintf( tC, "Sending Video Chunk %d bytes", tSize ); + //LOG( tC ); + if ( tCMD->DATA ) { + if ( peer_send_rpc_pack( tCMD ) ) { + setTO( 3 ); + free( tCMD->DATA ); + free( tCMD ); + break; + }; + free( tCMD->DATA ); + }; + free( tCMD ); + }; + //Only On failure finishTransaction(); break; }; @@ -152,6 +203,7 @@ bool mojoRemoteClient::packetHandler( protocolPackage *Package ){ finishTransaction(); break; }; + }; return true; }; @@ -177,16 +229,17 @@ void mojoRemoteClient::finishTransaction(){ m_pCurrentCMD = NULL; }; m_mCurrentCMDProtector.unlock(); + setAutomationStage( ARGUS_RPC_STAGE_IDLE ); }; bool mojoRemoteClient::validateTransaction(){ - if ( m_mCurrentCMDProtector.try_lock() ) { - if ( m_pCurrentCMD == NULL ) { - m_mCurrentCMDProtector.unlock(); - return true; - }; + if ( m_bShutdownCommunication ) return false; + m_mCurrentCMDProtector.lock(); + if ( m_pCurrentCMD == NULL ) { m_mCurrentCMDProtector.unlock(); + return true; }; + m_mCurrentCMDProtector.unlock(); return false; }; @@ -202,6 +255,7 @@ bool mojoRemoteClient::pushNewTransaction( RPC_CMD_RECORD *ptr ){ }; bool mojoRemoteClient::fetchNewTransaction(){ + if ( m_bShutdownCommunication ) return false; m_mCurrentCMDProtector.lock(); if ( m_pCurrentCMD ) { m_mCurrentCMDProtector.unlock(); @@ -274,6 +328,20 @@ void mojoRemoteClient::enqueueTimeReq(){ }; }; +void mojoRemoteClient::flushTransactions(){ + m_mCurrentCMDProtector.lock(); + if ( m_pCurrentCMD ) { + if (m_pCurrentCMD->DATA) free( m_pCurrentCMD->DATA ); + free( m_pCurrentCMD ); + }; + while( m_pCurrentCMD = m_qCMD->pop() ){ + if (m_pCurrentCMD->DATA) free( m_pCurrentCMD->DATA ); + free( m_pCurrentCMD ); + }; + m_pCurrentCMD = NULL; + m_mCurrentCMDProtector.unlock(); +}; + void mojoRemoteClient::setTO( uint8_t seconds ){ m_mTOProtoctor.lock(); m_bTOCounter = seconds; @@ -309,6 +377,7 @@ void mojoRemoteClient::m_fThreadProc( void ){ tTimeTSeconds = cTimeTSeconds; switch ( getAutomationStage() ) { case ARGUS_RPC_STAGE_CONNECT:{ + flushTransactions(); #ifdef DEBUG char tB[128]; sprintf(tB,"Creating Remote connection to [%s:%d]", m_pMaster->m_sSiteData.remote_ip, m_pMaster->m_sSiteData.remote_port ); @@ -327,6 +396,8 @@ void mojoRemoteClient::m_fThreadProc( void ){ setTransport( m_pPort, false ); setAutomationStage( ARGUS_RPC_STAGE_REGISTER ); } else { + setConnectionStatus( CS_DISCONNECTED ); + setTransport( NULL, false ); delete( m_pPort ); m_pPort = NULL; m_bShutdownCommunication = true; @@ -340,10 +411,12 @@ void mojoRemoteClient::m_fThreadProc( void ){ break; }; case ARGUS_RPC_STAGE_WAIT_RECONNECT:{ + LOG("Wait Reconnect!"); if ( !decTO() ) setAutomationStage( ARGUS_RPC_STAGE_CONNECT ); break; }; case ARGUS_RPC_STAGE_REGISTER:{ + LOG("Stage Reg!"); RPC_CMD_RECORD *tCMD = (RPC_CMD_RECORD*) malloc(sizeof(RPC_CMD_RECORD)); if ( tCMD ) { tCMD->CMD = ARGUS_DATA_MSG_REGISTER; @@ -363,12 +436,13 @@ void mojoRemoteClient::m_fThreadProc( void ){ break; }; case ARGUS_RPC_STAGE_WAIT_ACK:{ - LOG("TO On Waiting Responce!"); + LOG("Wait ACK!"); if ( !decTO() ) setAutomationStage( ARGUS_RPC_STAGE_CLOSE ); break; }; case ARGUS_RPC_STAGE_IDLE: if( ( tSecondsCounter % ARGUS_SECONDS_TO_SYNC_TIME ) == 15 ) enqueueTimeReq(); else enqueueStatMsg(); break; case ARGUS_RPC_STAGE_DISCONNECT:{ + LOG("Stage Disconnect!"); // Gracefully Disconnect //if( peer_send_disconnect() ){ // bTO_COUNTER = 1; @@ -378,6 +452,9 @@ void mojoRemoteClient::m_fThreadProc( void ){ }; case ARGUS_RPC_STAGE_CLOSE:{ // Just Disconnect + LOG("Stage Close!"); + flushTransactions(); + setTransport( NULL, false ); delete( m_pPort ); m_pPort = NULL; m_bShutdownCommunication = true; @@ -389,13 +466,12 @@ void mojoRemoteClient::m_fThreadProc( void ){ }; }; }; - if ( validateTransaction() ) { if ( fetchNewTransaction() ) { if( peer_send_rpc_pack( m_pCurrentCMD ) ) { setTO( 1 ); setAutomationStage( ARGUS_RPC_STAGE_WAIT_ACK ); - }; + } else LOG_ERROR("Failure!"); } else SLEEP( DEFAULT_THREAD_SLEEP_TIME ); } else SLEEP( DEFAULT_THREAD_SLEEP_TIME ); }; @@ -406,22 +482,21 @@ void mojoRemoteClient::m_fThreadProc( void ){ Register With Server and make Time Sync With Server */ -bool mojoRemoteClient::peer_send_rpc_pack( RPC_CMD_RECORD *ptr){ +bool mojoRemoteClient::peer_send_rpc_pack( RPC_CMD_RECORD *ptr ){ bool retVal; + uint8_t pBuffer[4096]; if ( ptr == NULL ) return false; if( !m_bCommunicationEstablished ) return false; - if( !m_bRegisteredWithRemotePeer ) return false; - m_mBufferProtector.lock(); - m_pBuffer[ARGUS_HEADER_SIZE] = ptr->CMD; + //if( !m_bRegisteredWithRemotePeer ) return false; + pBuffer[ARGUS_HEADER_SIZE] = ptr->CMD; uint16_t i = 0; - for (; i < ptr->DATA_SIZE; i++) m_pBuffer[ARGUS_HEADER_SIZE+1+i] = ((uint8_t *)ptr->DATA)[i]; + for (; i < ptr->DATA_SIZE; i++) pBuffer[ARGUS_HEADER_SIZE+1+i] = ((uint8_t *)ptr->DATA)[i]; m_nOutbondSerial++; - retVal = m_pPort->sendData( m_pBuffer, argus_rpc_finishupPackage( m_pBuffer, m_nOutbondSerial, ARGUS_HEADER_SIZE+1+i )); - m_mBufferProtector.unlock(); + retVal = m_pPort->sendData( pBuffer, argus_rpc_finishupPackage( pBuffer, m_nOutbondSerial, ARGUS_HEADER_SIZE+1+i )); return retVal; }; -bool mojoRemoteClient::createVideoTransferTask( ARGUS_DATA_VIDEO_SEGMENT *ptr ){ +/*bool mojoRemoteClient::createVideoTransferTask( ARGUS_DATA_VIDEO_SEGMENT *ptr ){ if( ptr == NULL ) return false; if( !m_bCommunicationEstablished ) return false; if( !m_bRegisteredWithRemotePeer ) return false; @@ -432,7 +507,7 @@ bool mojoRemoteClient::createVideoTransferTask( ARGUS_DATA_VIDEO_SEGMENT *ptr ){ m_nOutbondSerial++; return m_pPort->sendData(tBuffer, argus_rpc_finishupPackage(tBuffer, m_nOutbondSerial, ARGUS_HEADER_SIZE+1+i )); }; - +*/ bool mojoRemoteClient::validate(){ if( m_bCommunicationEstablished ){ if ( getConnectionStatus() == CS_DISCONNECTED ) { @@ -503,5 +578,128 @@ bool mojoRemoteClient::addEvent( EVENT_CONTAINER *Evt ){ return false; }; +bool mojoRemoteClient::addVideo( VIDEO_SEGMENT_INFO *ptr ){ +#ifdef DEBUG + LOG("Add Video!"); +#endif + if ( ptr == NULL ) return false; + if ( m_pVideoHelper == NULL ) return false; + + RPC_CMD_RECORD *tPack = (RPC_CMD_RECORD *)malloc(sizeof(RPC_CMD_RECORD)); + if ( tPack ) { + if( m_pVideoHelper->init( ptr ) ) { + tPack->DATA_SIZE = sizeof( ARGUS_DATA_VIDEO_INFO ); + tPack->DATA = malloc( tPack->DATA_SIZE ); + if ( tPack->DATA ) { + memcpy( tPack->DATA, m_pVideoHelper->getVideoInfo(), tPack->DATA_SIZE ); + tPack->CMD = ARGUS_DATA_MSG_VIDEO_INFO; + if( m_qCMD->push( tPack ) ) return true; + free( tPack->DATA ); + }; + m_pVideoHelper->abort(); + }; + free( tPack ); + }; + return false; +}; + +mojoVideoTransferHelper::mojoVideoTransferHelper( uint32_t buffer_size ){ + m_bVideoExists = false; + m_bVideoOpened = false; + m_nBufferSize = buffer_size; + m_pBuffer = (uint8_t *) malloc( m_nBufferSize ); + m_nCTSMS = 0; + m_nRemoteRefID = 0; + m_pFD = NULL; + memset( m_cCurrentFile, 0, MAX_PATH ); +}; + + +mojoVideoTransferHelper::~mojoVideoTransferHelper(){ + abort(); +}; +#include + +bool mojoVideoTransferHelper::init( VIDEO_SEGMENT_INFO *ptr ){ + if ( m_pBuffer == NULL ) return false; + if ( m_bVideoExists ) { + if ( m_bVideoOpened ) fclose( m_pFD ); + unlink(m_cCurrentFile); + }; + if( !( m_bVideoExists = fileExist(ptr->scratchPath) ) ) return false; + m_nRemoteRefID = 0; + + strncpy( m_cCurrentFile, ptr->scratchPath, MAX_PATH ); + m_cCurrentFile[MAX_PATH-1] = (char)0; + struct stat st; + stat( m_cCurrentFile, &st ); + m_sIn.DATA_SIZE = st.st_size; + m_sIn.DTS = ptr->streamTSS; + m_sIn.DMS = ptr->streamTMS; + m_sIn.EVTCNT = ptr->eventIDS.size(); + m_sIn.FPS = ptr->streamFPS; + strncpy( m_sIn.FMT, ptr->recordEXT, 5 ); + m_sIn.FMT[5]=(char)0; + strncpy( m_sIn.MD5, ptr->recordMD5, 32 ); + m_sIn.MD5[32]=(char)0; + m_sIn.WIDTH = ptr->streamWidth; + m_sIn.HEIGHT = ptr->streamHeight; + CSTR TtT = getUniqID_UUID(); + if ( TtT ) { + strncpy( m_sIn.UUID, TtT, 64 ); + m_sIn.UUID[64]=(char)0; + free( TtT ); + }; + m_pFD = fopen( m_cCurrentFile, "r" ); + if( m_bVideoOpened = m_pFD != NULL ) return true; + return false; +}; + +uint8_t *mojoVideoTransferHelper::getNextChunk( uint32_t req_chunk_size, uint32_t *ack_size ){ + uint8_t *retVal = NULL; + if ( m_bVideoOpened ) { + retVal = (uint8_t *) malloc( req_chunk_size + 12 );//+DB_SOURCE_ID_x_64+Size_32 + if ( retVal ) { + int32_t rv = fread( retVal+12, 1, req_chunk_size, m_pFD ); + if ( rv < 0 ) { + free( retVal ); + retVal = NULL; + abort(); + } else { + *ack_size = rv+12; + + retVal[0] = ( m_nRemoteRefID >> 56 ) & 0xFF; + retVal[1] = ( m_nRemoteRefID >> 48 ) & 0xFF; + retVal[2] = ( m_nRemoteRefID >> 40 ) & 0xFF; + retVal[3] = ( m_nRemoteRefID >> 32 ) & 0xFF; + retVal[4] = ( m_nRemoteRefID >> 24 ) & 0xFF; + retVal[5] = ( m_nRemoteRefID >> 16 ) & 0xFF; + retVal[6] = ( m_nRemoteRefID >> 8 ) & 0xFF; + retVal[7] = m_nRemoteRefID & 0xFF; + + retVal[8] = ( rv >> 24 ) & 0xFF; + retVal[9] = ( rv >> 16 ) & 0xFF; + retVal[10] = ( rv >> 8 ) & 0xFF; + retVal[11] = rv & 0xFF; + + if ( feof( m_pFD )){ + fclose( m_pFD ); + m_bVideoOpened = false; + }; + }; + }; + }; + return retVal; +}; + +ARGUS_DATA_VIDEO_INFO *mojoVideoTransferHelper::getVideoInfo(){ + return &m_sIn; +}; + +void mojoVideoTransferHelper::abort(){ + +}; + + #undef LOG #undef LOG_ERROR \ No newline at end of file diff --git a/lib/App/mojo/mojoRemoteClient.h b/lib/App/mojo/mojoRemoteClient.h index ba537286..9a996f40 100644 --- a/lib/App/mojo/mojoRemoteClient.h +++ b/lib/App/mojo/mojoRemoteClient.h @@ -6,6 +6,7 @@ #include "../../data/net/clientPort.h" #include "../../data/protocol/protocol.h" #include "../../data/protocol/protocolARGUS_DATA.h" +#include "../common/dataBinder.h" class mojoKernel; @@ -17,6 +18,30 @@ typedef struct S_RPC_CMD_RECORD{ typedef basicRing RPC_CMD_QUEUE; +class mojoVideoTransferHelper{ + private: + char m_cCurrentFile[MAX_PATH]; + bool m_bVideoExists; + bool m_bVideoOpened; + uint64_t m_nRemoteRefID; + FILE * m_pFD; + ARGUS_DATA_VIDEO_INFO m_sIn; + uint32_t m_nBufferSize; + uint8_t * m_pBuffer; + uint64_t m_nCTSMS; // future use for Target Binding ( history filtering ) + public: + explicit mojoVideoTransferHelper( uint32_t buffer_size = ARGUS_RPC_DEFAULT_MEDIA_CHUNK ); + ~mojoVideoTransferHelper(); + bool init( VIDEO_SEGMENT_INFO *ptr ); + uint8_t * getNextChunk( uint32_t req_chunk_size, uint32_t *ack_size ); + ARGUS_DATA_VIDEO_INFO * getVideoInfo(); + void clear(); + void abort(); + void registerEventID( uint32_t local, uint64_t remote ); + void setRemoteReferenceID( uint64_t rid ){ m_nRemoteRefID = rid; }; +}; + + class mojoRemoteClient: public basicThread, public protocolParser{ private: basicLogCollection * m_pLog; @@ -29,7 +54,7 @@ class mojoRemoteClient: public basicThread, public protocolParser{ RPC_CMD_QUEUE * m_qCMD; basicMutex m_mCurrentCMDProtector; RPC_CMD_RECORD * m_pCurrentCMD; - + mojoVideoTransferHelper * m_pVideoHelper; uint32_t m_nQueryMessage; uint32_t m_nInbondSerial; uint32_t m_nOutbondSerial; @@ -39,15 +64,6 @@ class mojoRemoteClient: public basicThread, public protocolParser{ bool m_bCommunicationEstablished; bool m_bRegisteredWithRemotePeer; - uint8_t m_pBuffer[4096]; - basicMutex m_mBufferProtector; - - bool peer_send_evt( ARGUS_DATA_EVENT *ptr ); - bool peer_send_hello( ARGUS_DATA_MOJO_INFO *ptr ); - bool peer_send_reg_req( CSTR identity ); - bool peer_send_status( ARGUS_DATA_MOJO_STATUS *ptr ); - bool peer_send_time_sync_req( ARGUS_DATA_TIME_SYNC_REQ *ptr ); - bool peer_send_rpc_pack( RPC_CMD_RECORD *ptr); void enqueueInfoMsg(); @@ -75,9 +91,10 @@ class mojoRemoteClient: public basicThread, public protocolParser{ explicit mojoRemoteClient( mojoKernel *ptr ); ~mojoRemoteClient(); virtual bool create(); - bool createVideoTransferTask( ARGUS_DATA_VIDEO_SEGMENT *ptr ); + //bool createVideoTransferTask( ARGUS_DATA_VIDEO_SEGMENT *ptr ); bool validate(); bool addEvent( EVENT_CONTAINER *ptr ); + bool addVideo( VIDEO_SEGMENT_INFO *ptr ); }; #endif \ No newline at end of file diff --git a/lib/App/serva/servaBackend.cpp b/lib/App/serva/servaBackend.cpp index 638a9944..74684f0a 100644 --- a/lib/App/serva/servaBackend.cpp +++ b/lib/App/serva/servaBackend.cpp @@ -417,8 +417,8 @@ int main( int argc, char *argv[] ){ delete( m_pLog ); return -1; }; - LOG("Adding Database Log Service!"); - m_pLog->addHandler((basicLoggingService *) new objectMySQLLoggingService( DBC )); + //LOG("Adding Database Log Service!"); + //m_pLog->addHandler((basicLoggingService *) new objectMySQLLoggingService( DBC )); }; // Start Loop of Restarted Kernel diff --git a/lib/App/serva/servaKernel.cpp b/lib/App/serva/servaKernel.cpp index 83e81447..cea1730a 100644 --- a/lib/App/serva/servaKernel.cpp +++ b/lib/App/serva/servaKernel.cpp @@ -28,7 +28,6 @@ #include "../common/serverMySQL_dataBinder.h" - #define LOG( X ) kernelPrototype::m_pLog->Log( "KRNL", this, X ) #ifdef DEBUG #define LOG_ERROR( X ) {\ @@ -185,8 +184,16 @@ bool servaKernel::create(){ //m_bSessionStarted = m_pDBC->getEventSessionStatus( m_nServerNodeID ); //stopSession( false ); m_pRPC = servaRemoteClient::getInstance( this ); + //processVideoFile( "1647bde08730af03aefdef979aa12ec9.mjpeg", 2323, "1647bde08730af03aefdef979aa12ec9.mp4" ); + servaMediaEncoder *ME = new servaMediaEncoder(); + if ( ME ) { + LOG("CC OK"); + if ( ME->create( "./997958795a78c61aa2f7ac7a2bf7830f.mjpeg", "./997958795a78c61aa2f7ac7a2bf7830f.mp4", 25 ) ) { + LOG("COK"); + } else LOG("CFAIL"); + } else LOG("CC FAIL"); - if ( m_pRPC ) { + if (m_pRPC) { if( m_pRPC->start() ) return init(); }; return false; @@ -209,7 +216,20 @@ void servaKernel::m_fThreadProc( void ){ //ToDo: Make Error Handling here! write( m_iWatchdogFd, &tB, strlen( tB ) ); }; -#endif +#endif + if ( m_vEncodersPool.size() ) { + for ( V_MEDIA_ENCODERS::iterator idx = m_vEncodersPool.begin(); idx < m_vEncodersPool.end(); idx++ ) { + if ( (*idx)->getStatus() == ENCODER_FINISHED ) { + //handleEncodedVideo( (*idx)->getDBID() ); + delete( *idx ); + m_vEncodersPool.erase( idx ); + }; + }; + }; + if ( uint64_t new_id = m_pDBC->getRecentMediaId() ) { + LOG("Start Encoder!"); + if ( processVideoFile( new_id ) ) updateEncodeStatus( new_id, MEDIA_ENCODE_PROGRESS, 0 ); + }; //m_pHardwareManager->updateSysInfo( &m_sSysInfo ); DBC_PUSHED_CMD * tCMD = NULL;//m_pDBC->getNodePushedCMD( 0 ); //Kernel if( tCMD != NULL ) { @@ -342,5 +362,52 @@ void servaKernel::m_fThreadProc( void ){ }; }; +void servaKernel::updateEncodeStatus( uint64_t dbid, uint8_t status, uint8_t perc ){ + m_pDBC->updateEncodeStatus( dbid, status, perc ); +}; + +bool servaKernel::processVideoFile( uint64_t dbid ){ + if ( dbid == 0 ) return false; + DBC_RPC_MEDIA_INFO *NFO = m_pDBC->getRemoteMediaInfo( dbid ); + if ( NFO ) { + servaMediaEncoder *ptr = new servaMediaEncoder( dbid ); + if ( ptr ) { + LOG("Encoder Constructed!"); + char tA[MAX_PATH]; + char tB[MAX_PATH]; + sprintf( tA,"data/%s.%s", NFO->uuid, NFO->fmt ); + sprintf( tB,"data/%s.mp4", NFO->uuid ); + if ( ptr->create( tA, tB, /*NFO->fps*/ 25 ) ) { + LOG("Encoder Created!"); + m_vEncodersPool.push_back( ptr ); + return true; + }; + delete( ptr ); + }; + free( NFO ); + }; + return false; +}; + +void servaKernel::handleEncodedVideo( uint64_t dbid ){ + +}; + +uint64_t servaKernel::registerRemoteVideo( CSTR uuid, uint64_t src, uint32_t ts, uint16_t tsms, uint16_t width, uint16_t height, CSTR fmt ){ + if ( m_pDBC ) { + LOG("Video Register 1"); + CSTR tMD5 = getUniqID_MD5(); + if ( tMD5 ) { + LOG( fmt ); + LOG( tMD5 ); + uint64_t rv = m_pDBC->addMediaQueueRecord( uuid, tMD5, src, ts, tsms, width, height, fmt ); + free( tMD5 ); + return rv; + }; + }; + return 0; +}; + + #undef LOG #undef LOG_ERROR diff --git a/lib/App/serva/servaKernel.h b/lib/App/serva/servaKernel.h index 89d1554b..f3dcb77b 100644 --- a/lib/App/serva/servaKernel.h +++ b/lib/App/serva/servaKernel.h @@ -33,6 +33,7 @@ #include "../common/kernelPrototype.h" #include "lifeMonitoring.h" #include "servaRemoteClient.h" +#include "servaMediaEncoder.h" #define MAX_CYCLE_COUNTER_VALUE 0xFFFFFFFF; #define SLEEP_KERNEL_INTERVAL 10 // 10 millisecond @@ -44,10 +45,13 @@ class servaKernel: public kernelPrototype{ static servaKernel * _instance; servaLifeMonitoring * m_pLifeMonitor; servaRemoteClient * m_pRPC; + V_MEDIA_ENCODERS m_vEncodersPool; protected: virtual void m_fThreadProc( void ); // Constructor - explicit servaKernel( config_setting_t *ptr ); + explicit servaKernel( config_setting_t *ptr ); + bool processVideoFile( uint64_t dbid ); + void handleEncodedVideo( uint64_t dbid ); public: static servaKernel * getInstance( config_setting_t *ptr = NULL ); // Destructor @@ -55,6 +59,8 @@ class servaKernel: public kernelPrototype{ virtual bool create(); // Functionality (implementatio in servaKernelToolKit.cpp ) bool registerMojo(); + void updateEncodeStatus( uint64_t dbid, uint8_t status, uint8_t perc ); + uint64_t registerRemoteVideo( CSTR uuid, uint64_t src, uint32_t ts, uint16_t tsms, uint16_t width, uint16_t height, CSTR fmt ); friend class servaRemoteClient; friend class servaRPCHadnler; diff --git a/lib/App/serva/servaRemoteClientHandler.cpp b/lib/App/serva/servaRemoteClientHandler.cpp index ebc2f4e7..71e4e9c9 100644 --- a/lib/App/serva/servaRemoteClientHandler.cpp +++ b/lib/App/serva/servaRemoteClientHandler.cpp @@ -13,17 +13,21 @@ #define LOG_ERROR( X ) networkClientHandler::m_pLog->Log( "RPCH", this, _LOG_ERROR, X ); #endif -servaRPCHadnler::servaRPCHadnler( int SocketFD, networkServiceEngine *ptr ):networkClientHandler( SocketFD, ptr ),protocolParser(){ +servaRPCHadnler::servaRPCHadnler( int SocketFD, networkServiceEngine *ptr ):basicThread(),networkClientHandler( SocketFD, ptr ),protocolParser(){ m_pEngine = ptr; m_pMaster = (servaRemoteClient *)ptr; m_dRemoteMojoDBID = 0; m_dRemoteUpperDBID = 0; m_dRemoteBottomDBID = 0; + m_nInbondSerial = 0; + m_nOutbondSerial = 0; m_bSessionIsActive = false; + m_pDBC = servaMySQLDBC::getInstance(); m_pPort = new serverPort( SocketFD ); if ( m_pPort ) { if ( m_pPort->create() ) { setTransport(m_pPort); + init(); } else { delete( m_pPort ); m_pPort = NULL; @@ -32,6 +36,7 @@ servaRPCHadnler::servaRPCHadnler( int SocketFD, networkServiceEngine *ptr ):netw }; servaRPCHadnler::~servaRPCHadnler(){ + waitThreadEnd( true ); if( m_pPort ) delete( m_pPort ); }; @@ -41,8 +46,9 @@ bool servaRPCHadnler::attachEngine( networkServiceEngine *ptr ){ return true; }; -void servaRPCHadnler::dispatchEvent( EVENT_CONTAINER *Evt ){ +bool servaRPCHadnler::dispatchEvent( EVENT_CONTAINER *Evt ){ LOG("EVT"); + return true; }; bool servaRPCHadnler::getStatus( void ){ @@ -66,21 +72,17 @@ bool servaRPCHadnler::setRemotePeerIP( CSTR ptr ){ /********************PROTOCOL**************************/ int servaRPCHadnler::packetChecker( U8 *Buffer, size_t BufferSize ){ - //char tB[64]; + char tB[64]; if ( Buffer[0] == ARGUS_START_CLIENT_FLAG ) { if( BufferSize > ARGUS_DATA_MSG_MIN_SIZE ){ - uint32_t SIZE = Buffer[1]; - SIZE = ( SIZE << 8 ) | Buffer[2]; - SIZE = ( SIZE << 8 ) | Buffer[3]; - SIZE = ( SIZE << 8 ) | Buffer[4]; + uint32_t SIZE = Buffer[5]; + SIZE = ( SIZE << 8 ) | Buffer[6]; + SIZE = ( SIZE << 8 ) | Buffer[7]; + SIZE = ( SIZE << 8 ) | Buffer[8]; if ( ( SIZE + ARGUS_HEADER_SIZE + ARGUS_CHECKSUM_SIZE ) <= BufferSize ) { uint16_t tCRC = checksum16( Buffer, SIZE + ARGUS_HEADER_SIZE ); uint16_t cCRC = Buffer[SIZE + ARGUS_HEADER_SIZE]; cCRC = ( cCRC << 8 ) | Buffer[SIZE + ARGUS_HEADER_SIZE+1]; - //sprintf( tB, "Pack Size: %08X", SIZE ); - //LOG(tB); - //sprintf( tB, "cCRC: %04X tCRC: %04X", tCRC, cCRC ); - //LOG(tB); if ( tCRC == cCRC ) return 0; } else return 1; // to grou } else return 1; //to grow @@ -92,10 +94,10 @@ protocolPackage *servaRPCHadnler::packetExtractor(U8 *Buffer, size_t BufferSize) protocolPackage *tPack = (protocolPackage*) malloc( sizeof(protocolPackage)); if ( tPack ) { tPack->m_nCode = Buffer[ARGUS_HEADER_SIZE]; - tPack->m_nSize = Buffer[1]; - tPack->m_nSize = ( tPack->m_nSize << 8 ) | Buffer[2]; - tPack->m_nSize = ( tPack->m_nSize << 8 ) | Buffer[3]; - tPack->m_nSize = ( tPack->m_nSize << 8 ) | Buffer[4]; + tPack->m_nSize = Buffer[5]; + tPack->m_nSize = ( tPack->m_nSize << 8 ) | Buffer[6]; + tPack->m_nSize = ( tPack->m_nSize << 8 ) | Buffer[7]; + tPack->m_nSize = ( tPack->m_nSize << 8 ) | Buffer[8]; tPack->m_nSize = tPack->m_nSize + ARGUS_HEADER_SIZE + ARGUS_CHECKSUM_SIZE; tPack->m_pData = (U8 *) malloc( tPack->m_nSize ); if ( tPack->m_pData ) { @@ -109,30 +111,37 @@ protocolPackage *servaRPCHadnler::packetExtractor(U8 *Buffer, size_t BufferSize) }; bool servaRPCHadnler::packetHandler( protocolPackage *Package ){ - uint32_t tQueryMessage; - //m_mQueryProtector.lock(); - //tQueryMessage = m_nQueryMessage; - //m_mQueryProtector.unlock(); + + m_nInbondSerial = Package->m_pData[1]; + m_nInbondSerial = ( m_nInbondSerial << 8 ) | Package->m_pData[2]; + m_nInbondSerial = ( m_nInbondSerial << 8 ) | Package->m_pData[3]; + m_nInbondSerial = ( m_nInbondSerial << 8 ) | Package->m_pData[4]; + //char bB[129]; + //sprintf( bB, "Code: %02X", Package->m_nCode ); + //LOG( bB ); switch( Package->m_nCode ){ case ARGUS_DATA_MSG_REGISTER:{ strncpy( m_cRemoteIdentity, (const char*)(Package->m_pData+ARGUS_HEADER_SIZE+1), 32 ); m_cRemoteIdentity[32] = (char)0; +#ifdef DEBUG char tB[128]; sprintf(tB,"Registration request from[%s][%s]", m_cRemoteIP, m_cRemoteIdentity ); LOG(tB); +#endif m_dRemoteMojoDBID = m_pMaster->requestMojoRegistration( m_cRemoteIP, m_cRemoteIdentity ); if ( m_dRemoteMojoDBID ) { char WM = m_pMaster->getMojoWorkMode( m_dRemoteMojoDBID ); if ( WM == 'E') { +#ifdef DEBUG LOG("Module Enabled"); - - m_dRemoteUpperDBID = m_pMaster->m_pMaster->m_pDBC->getUpperLRF( m_dRemoteMojoDBID ); - m_dRemoteBottomDBID = m_pMaster->m_pMaster->m_pDBC->getBottomLRF( m_dRemoteMojoDBID ); - uint32_t lts = m_pMaster->m_pMaster->m_pDBC->getCloudLTS( ARGUS_OBJECT_MODULE, m_dRemoteMojoDBID ); +#endif + m_dRemoteUpperDBID = m_pDBC->getUpperLRF( m_dRemoteMojoDBID ); + m_dRemoteBottomDBID = m_pDBC->getBottomLRF( m_dRemoteMojoDBID ); + uint32_t lts = m_pDBC->getCloudLTS( ARGUS_OBJECT_MODULE, m_dRemoteMojoDBID ); uint32_t cts = time(NULL); - m_pMaster->m_pMaster->m_pDBC->setCloudStatus( ARGUS_OBJECT_MODULE, m_dRemoteMojoDBID, ARGUS_CLOUD_STATUS_ONLINE ); - if( m_dRemoteUpperDBID ) m_pMaster->m_pMaster->m_pDBC->setCloudStatus( ARGUS_OBJECT_SENSOR, m_dRemoteUpperDBID, ARGUS_CLOUD_STATUS_REG ); - if( m_dRemoteBottomDBID ) m_pMaster->m_pMaster->m_pDBC->setCloudStatus( ARGUS_OBJECT_SENSOR, m_dRemoteBottomDBID, ARGUS_CLOUD_STATUS_REG ); + m_pDBC->setCloudStatus( ARGUS_OBJECT_MODULE, m_dRemoteMojoDBID, ARGUS_CLOUD_STATUS_ONLINE ); + if( m_dRemoteUpperDBID ) m_pDBC->setCloudStatus( ARGUS_OBJECT_SENSOR, m_dRemoteUpperDBID, ARGUS_CLOUD_STATUS_REG ); + if( m_dRemoteBottomDBID ) m_pDBC->setCloudStatus( ARGUS_OBJECT_SENSOR, m_dRemoteBottomDBID, ARGUS_CLOUD_STATUS_REG ); peer_send_reg_status( ARGUS_DATA_MSG_REGISTER ); if ( ( cts - lts ) > ARGUS_SECONDS_TO_IGNORE_MODULE_COMMUNICATION_DROP ) { LOG("Download All Info From Module!"); @@ -152,9 +161,7 @@ bool servaRPCHadnler::packetHandler( protocolPackage *Package ){ }; case ARGUS_DATA_MSG_INFO:{ ARGUS_DATA_MOJO_INFO *tINFO = (ARGUS_DATA_MOJO_INFO *) (Package->m_pData+ARGUS_HEADER_SIZE+1); - char tB[128]; - sprintf(tB, "Remote WM[%d]", tINFO->MOJO_WORK_MODE ); - LOG( tB ); + peer_send_reg_status( ARGUS_DATA_MSG_INFO ); break; }; case ARGUS_DATA_MSG_EVT:{ @@ -165,6 +172,7 @@ bool servaRPCHadnler::packetHandler( protocolPackage *Package ){ strncpy( tB, tEVT->UUID, 64 ); tB[64] = (char)0; LOG( tB ); + peer_send_reg_status( ARGUS_DATA_MSG_EVT ); switch( tEVT->TYPE ){ }; @@ -177,6 +185,10 @@ bool servaRPCHadnler::packetHandler( protocolPackage *Package ){ //}; break; }; + case ARGUS_DATA_MSG_REQ_TIME_SYNC:{ + peer_send_reg_status( ARGUS_DATA_MSG_REQ_TIME_SYNC ); + break; + }; case ARGUS_DATA_MSG_TIME_SYNC:{ LOG( "Time Synchronization Request" ); ARGUS_DATA_TIME_SYNC_REQ *tTSR = ( ARGUS_DATA_TIME_SYNC_REQ *) (Package->m_pData+ARGUS_HEADER_SIZE+1); @@ -188,63 +200,116 @@ bool servaRPCHadnler::packetHandler( protocolPackage *Package ){ }; case ARGUS_DATA_MSG_KEEP_ALIVE:{ ARGUS_DATA_MOJO_STATUS *tSTATUS = (ARGUS_DATA_MOJO_STATUS *) (Package->m_pData+ARGUS_HEADER_SIZE+1); - m_pMaster->m_pMaster->m_pDBC->setCloudStatus( ARGUS_OBJECT_MODULE, m_dRemoteMojoDBID, ARGUS_CLOUD_STATUS_ONLINE ); + m_pDBC->setCloudStatus( ARGUS_OBJECT_MODULE, m_dRemoteMojoDBID, ARGUS_CLOUD_STATUS_ONLINE ); //char tB[128]; //sprintf(tB, "[%04X] CPU[%d] TEMO[%d]", tSTATUS->STATUSES, tSTATUS->CPU_LOAD, tSTATUS->CPU_TEMP ); //LOG( tB ); break; }; case ARGUS_DATA_MSG_VIDEO_INFO:{ - ARGUS_DATA_VIDEO_INFO *tVIF=(ARGUS_DATA_VIDEO_INFO *)(Package->m_pData+ARGUS_HEADER_SIZE+1); - peer_send_pack_ack( m_nPackID ); + LOG( "Received Video Record Info" ); + m_pVideoHelper.clear(); + if ( m_pVideoHelper.init( m_dRemoteMojoDBID, (ARGUS_DATA_VIDEO_INFO *)(Package->m_pData + ARGUS_HEADER_SIZE + 1) ) ) { + peer_send_vinfo_ack( m_pVideoHelper.getReferenceID() ); + } else { + peer_send_vinfo_ack( 0 ); + }; + break; + }; + case ARGUS_DATA_MSG_VIDEO_DATA:{ + uint32_t tt = m_pVideoHelper.saveNextChunk( Package->m_pData+ARGUS_HEADER_SIZE+1 ); + //char tK[128]; + //sprintf( tK, "Saved %d Bytes of Video!", tt ); + //LOG( tK ); + peer_send_vdata_ack( tt ); break; }; }; return true; }; -bool servaRPCHadnler::peer_send_pack_ack( uint64_t pid ){ +void servaRPCHadnler::m_fThreadProc( void ){ + time_t tTimeTSeconds = 0; + time_t cTimeTSeconds = 0; + uint32_t tSecondsCounter = 0; + + m_bThreadStatus = TH_WORKING; +#ifdef DEBUG + LOG("Connector Thread Started"); +#endif + while ( m_bThreadStatus < TH_ENDED ) { + // seconds Counter (for internal purposes) + cTimeTSeconds = time( NULL ); + //Process each second + if ( cTimeTSeconds != tTimeTSeconds ) { + tSecondsCounter++; + tTimeTSeconds = cTimeTSeconds; + }; + SLEEP( DEFAULT_THREAD_SLEEP_TIME ); + }; +#ifdef DEBUG + LOG("Connector Thread Ended!"); +#endif +}; + +bool servaRPCHadnler::peer_send_vdata_ack( uint8_t status ){ uint8_t Buffer[64]; - Buffer[5] = status; - for ( uint8_t i = 0; i<32; i++) Buffer[i+6] = (uint8_t) m_cRemoteIdentity[i]; - return m_pPort->sendData( Buffer, argus_rpc_finishupPackage( Buffer, 38 ) ); + Buffer[ARGUS_HEADER_SIZE] = ARGUS_DATA_MSG_VIDEO_DATA; + Buffer[ARGUS_HEADER_SIZE+1] = status; + m_nOutbondSerial++; + return m_pPort->sendData( Buffer, argus_rpc_finishupPackage( Buffer, m_nOutbondSerial, ARGUS_HEADER_SIZE+2 ) ); +}; + +bool servaRPCHadnler::peer_send_vinfo_ack( uint64_t pid ){ + uint8_t Buffer[64]; + Buffer[ARGUS_HEADER_SIZE] = ARGUS_DATA_MSG_VIDEO_INFO; + Buffer[ARGUS_HEADER_SIZE+1] = ( pid >> 56 ) & 0xff; + Buffer[ARGUS_HEADER_SIZE+2] = ( pid >> 48 ) & 0xff; + Buffer[ARGUS_HEADER_SIZE+3] = ( pid >> 40 ) & 0xff; + Buffer[ARGUS_HEADER_SIZE+4] = ( pid >> 32 ) & 0xff; + Buffer[ARGUS_HEADER_SIZE+5] = ( pid >> 24 ) & 0xff; + Buffer[ARGUS_HEADER_SIZE+6] = ( pid >> 16 ) & 0xff; + Buffer[ARGUS_HEADER_SIZE+7] = ( pid >> 8 ) & 0xff; + Buffer[ARGUS_HEADER_SIZE+8] = pid & 0xff; + m_nOutbondSerial++; + return m_pPort->sendData( Buffer, argus_rpc_finishupPackage( Buffer, m_nOutbondSerial, ARGUS_HEADER_SIZE+9 ) ); }; bool servaRPCHadnler::peer_send_reg_status( uint8_t status ){ uint8_t Buffer[64]; - Buffer[5] = status; - for ( uint8_t i = 0; i<32; i++) Buffer[i+6] = (uint8_t) m_cRemoteIdentity[i]; - return m_pPort->sendData( Buffer, argus_rpc_finishupPackage( Buffer, 38 ) ); + Buffer[ARGUS_HEADER_SIZE] = status; + m_nOutbondSerial++; + return m_pPort->sendData( Buffer, argus_rpc_finishupPackage( Buffer, m_nOutbondSerial, ARGUS_HEADER_SIZE+1 ) ); }; bool servaRPCHadnler::peer_send_req_draw( uint8_t sensor, uint8_t draw_type, bool getexisted ){ if ( sensor == ARGUS_RPC_MOJO_ITSELF ) return false; uint8_t Buffer[64]; - Buffer[5] = ARGUS_DATA_MSG_GET_DRAW; - Buffer[6] = sensor; + Buffer[ARGUS_HEADER_SIZE] = ARGUS_DATA_MSG_GET_DRAW; + Buffer[ARGUS_HEADER_SIZE+1] = sensor; if( !getexisted ) { - Buffer[7] = draw_type | 0x80; + Buffer[ARGUS_HEADER_SIZE+2] = draw_type | 0x80; } else { - Buffer[7] = draw_type; + Buffer[ARGUS_HEADER_SIZE+2] = draw_type; }; - return m_pPort->sendData( Buffer, argus_rpc_finishupPackage( Buffer, 8 ) ); + return m_pPort->sendData( Buffer, argus_rpc_finishupPackage( Buffer, m_nOutbondSerial, ARGUS_HEADER_SIZE+3 ) ); }; bool servaRPCHadnler::peer_send_ack_evt( uint64_t evt_dbid, CSTR uuid ){ uint8_t Buffer[128]; Buffer[ARGUS_HEADER_SIZE] = ARGUS_DATA_MSG_EVT; - Buffer[6] = ( evt_dbid >> 56 ) & 0xFF; - Buffer[7] = ( evt_dbid >> 48 ) & 0xFF; - Buffer[8] = ( evt_dbid >> 40 ) & 0xFF; - Buffer[9] = ( evt_dbid >> 32 ) & 0xFF; - Buffer[10] = ( evt_dbid >> 24 ) & 0xFF; - Buffer[11] = ( evt_dbid >> 16 ) & 0xFF; - Buffer[12] = ( evt_dbid >> 8 ) & 0xFF; - Buffer[13] = evt_dbid & 0xFF; - Buffer[14] = strlen( uuid ); + Buffer[ARGUS_HEADER_SIZE+1] = ( evt_dbid >> 56 ) & 0xFF; + Buffer[ARGUS_HEADER_SIZE+2] = ( evt_dbid >> 48 ) & 0xFF; + Buffer[ARGUS_HEADER_SIZE+3] = ( evt_dbid >> 40 ) & 0xFF; + Buffer[ARGUS_HEADER_SIZE+4] = ( evt_dbid >> 32 ) & 0xFF; + Buffer[ARGUS_HEADER_SIZE+5] = ( evt_dbid >> 24 ) & 0xFF; + Buffer[ARGUS_HEADER_SIZE+6] = ( evt_dbid >> 16 ) & 0xFF; + Buffer[ARGUS_HEADER_SIZE+7] = ( evt_dbid >> 8 ) & 0xFF; + Buffer[ARGUS_HEADER_SIZE+8] = evt_dbid & 0xFF; + Buffer[ARGUS_HEADER_SIZE+9] = strlen( uuid ); uint8_t i = 0; - for( ; i< Buffer[14]; i++ ) Buffer[15+i] = (uint8_t)uuid[i]; - return m_pPort->sendData(Buffer, argus_rpc_finishupPackage( Buffer, 15+i )); + for( ; i< Buffer[ARGUS_HEADER_SIZE+9]; i++ ) Buffer[ARGUS_HEADER_SIZE+10+i] = (uint8_t)uuid[i]; + return m_pPort->sendData(Buffer, argus_rpc_finishupPackage( Buffer, m_nOutbondSerial, ARGUS_HEADER_SIZE+11+i )); }; bool servaRPCHadnler::peer_send_time_sync_ack( ARGUS_DATA_TIME_SYNC_ACK *ptr ){ @@ -252,7 +317,89 @@ bool servaRPCHadnler::peer_send_time_sync_ack( ARGUS_DATA_TIME_SYNC_ACK *ptr ){ tBuffer[ARGUS_HEADER_SIZE] = ARGUS_DATA_MSG_TIME_SYNC; uint16_t i = 0; for(; i < sizeof(ARGUS_DATA_TIME_SYNC_ACK); i++) tBuffer[ARGUS_HEADER_SIZE+1+i] = ((uint8_t*)ptr)[i]; - return m_pPort->sendData(tBuffer, argus_rpc_finishupPackage(tBuffer, ARGUS_HEADER_SIZE+1+i )); + return m_pPort->sendData(tBuffer, argus_rpc_finishupPackage(tBuffer, m_nOutbondSerial, ARGUS_HEADER_SIZE+1+i )); +}; + + +servaVideoTransferHelper::servaVideoTransferHelper(){ + m_pFD = NULL; + clear(); +}; + +servaVideoTransferHelper::~servaVideoTransferHelper(){ + clear(); +}; + +bool servaVideoTransferHelper::init( uint64_t MID, ARGUS_DATA_VIDEO_INFO *ptr ){ + m_nRemoteRefID = 0; + if ( ptr ) { + memcpy( &m_sIn, ptr, sizeof(ARGUS_DATA_VIDEO_INFO) ); + servaKernel *pK = servaKernel::getInstance(); + if ( pK ) { + m_nRemoteRefID = pK->registerRemoteVideo( ptr->UUID, MID, ptr->DTS, ptr->DMS, ptr->WIDTH, ptr->HEIGHT, ptr->FMT ); + }; + sprintf( m_cCurrentFile, "data/%s.%s", ptr->UUID, ptr->FMT ); + m_pFD = fopen( m_cCurrentFile, "wb" ); + return true; + } else { + memset( m_cCurrentFile, 0, MAX_PATH ); + memset( &m_sIn, 0, sizeof(ARGUS_DATA_VIDEO_INFO) ); + }; + return false; +}; + +void servaVideoTransferHelper::clear(){ + if( m_pFD ) fclose( m_pFD ); + m_pFD = NULL; + m_nRemoteRefID = 0; + m_nSAVED = 0; + m_bOPerc = 0; + memset( m_cCurrentFile, 0, MAX_PATH ); + memset( &m_sIn, 0, sizeof(ARGUS_DATA_VIDEO_INFO) ); +}; + +uint32_t servaVideoTransferHelper::saveNextChunk( uint8_t *ptr ){ + if ( ptr ){ + uint64_t tDBID = ptr[0]; + tDBID = ( tDBID << 8 ) | ptr[1]; + tDBID = ( tDBID << 8 ) | ptr[2]; + tDBID = ( tDBID << 8 ) | ptr[3]; + tDBID = ( tDBID << 8 ) | ptr[4]; + tDBID = ( tDBID << 8 ) | ptr[5]; + tDBID = ( tDBID << 8 ) | ptr[6]; + tDBID = ( tDBID << 8 ) | ptr[7]; + uint32_t chusz = ptr[8]; + chusz = ( chusz << 8 ) | ptr[9]; + chusz = ( chusz << 8 ) | ptr[10]; + chusz = ( chusz << 8 ) | ptr[11]; + if ( m_pFD ) { + if ( chusz ) { + int rv = fwrite( ptr+12, 1, chusz, m_pFD ); + if ( rv != chusz ) { + fclose( m_pFD ); + m_pFD = NULL; + unlink( m_cCurrentFile ); + return 0; + }; + m_nSAVED += chusz; + if ( chusz < ARGUS_RPC_DEFAULT_MEDIA_CHUNK ) { + fclose( m_pFD ); + m_pFD = NULL; + servaKernel::getInstance()->updateEncodeStatus( tDBID, MEDIA_STORED, 100 ); + } else { + if ( m_sIn.DATA_SIZE ) { + uint8_t perc = (uint8_t)((m_nSAVED * 100) / m_sIn.DATA_SIZE); + if ( m_bOPerc != perc ) { + m_bOPerc = perc; + servaKernel::getInstance()->updateEncodeStatus(tDBID, MEDIA_TRANSFERING, perc); + }; + } else servaKernel::getInstance()->updateEncodeStatus( tDBID, MEDIA_TRANSFERING, 50 ); + }; + return chusz; + }; + }; + }; + return 0; }; #undef LOG diff --git a/lib/App/serva/servaRemoteClientHandler.h b/lib/App/serva/servaRemoteClientHandler.h index df27c9ad..1b2e9599 100644 --- a/lib/App/serva/servaRemoteClientHandler.h +++ b/lib/App/serva/servaRemoteClientHandler.h @@ -4,37 +4,75 @@ #include "../../data/net/netClientHandler.h" #include "../../data/protocol/protocol.h" #include "../../data/protocol/protocolARGUS_DATA.h" +#include "../../components/base/basicThread.h" +#include "../common/serverMySQL_dataBinder.h" class servaRemoteClient; + typedef struct S_SESSION_EVENT{ uint64_t db_id; }SESSION_EVENT; typedef std::vector V_SESSION_EVENTS; -class servaRPCHadnler: public networkClientHandler, public protocolParser{ + +typedef struct S_RPC_CMD_RECORD{ + uint8_t CMD; + size_t DATA_SIZE; + void * DATA; +}RPC_CMD_RECORD; + +typedef basicRing RPC_CMD_QUEUE; + +class servaVideoTransferHelper{ + private: + char m_cCurrentFile[MAX_PATH]; + uint64_t m_nRemoteRefID; + FILE * m_pFD; + ARGUS_DATA_VIDEO_INFO m_sIn; + uint64_t m_nSAVED; + uint8_t m_bOPerc; + //uint32_t m_nBufferSize; + //uint8_t * m_pBuffer; + //uint64_t m_nCTSMS; // future use for Target Binding ( history filtering ) + public: + servaVideoTransferHelper(); + ~servaVideoTransferHelper(); + uint32_t saveNextChunk( uint8_t *ptr ); + void clear(); + bool init( uint64_t MID, ARGUS_DATA_VIDEO_INFO *ptr ); + uint64_t getReferenceID(){ return m_nRemoteRefID; }; +}; + +class servaRPCHadnler: public basicThread, public networkClientHandler, public protocolParser{ private: - servaRemoteClient * m_pMaster; - char m_cRemoteIP[64]; - char m_cRemoteIdentity[64]; - uint64_t m_dRemoteMojoDBID; - uint64_t m_dRemoteUpperDBID; - uint64_t m_dRemoteBottomDBID; - bool m_bSessionIsActive; - V_SESSION_EVENTS m_vSessionPool; + servaRemoteClient * m_pMaster; + servaMySQLDBC * m_pDBC; + char m_cRemoteIP[64]; + char m_cRemoteIdentity[64]; + uint64_t m_dRemoteMojoDBID; + uint64_t m_dRemoteUpperDBID; + uint64_t m_dRemoteBottomDBID; + uint32_t m_nInbondSerial; + uint32_t m_nOutbondSerial; + bool m_bSessionIsActive; + V_SESSION_EVENTS m_vSessionPool; + servaVideoTransferHelper m_pVideoHelper; bool peer_send_ack_evt( uint64_t evt_dbid, CSTR uuid ); bool peer_send_req_draw( uint8_t sensor, uint8_t draw_type = ARGUS_RPC_DRAW_TYPE_FAST, bool getexisted = true ); bool peer_send_reg_status( uint8_t status ); bool peer_send_time_sync_ack( ARGUS_DATA_TIME_SYNC_ACK *ptr ); - bool peer_send_pack_ack( uint64_t pid ); + bool peer_send_vdata_ack( uint8_t status ); + bool peer_send_vinfo_ack( uint64_t pid ); protected: virtual int packetChecker(U8 *Buffer, size_t BufferSize); virtual protocolPackage * packetExtractor(U8 *Buffer, size_t BufferSize); virtual bool packetHandler( protocolPackage *Package ); + virtual void m_fThreadProc( void ); public: explicit servaRPCHadnler( int SocketFD, networkServiceEngine *ptr ); ~servaRPCHadnler(); virtual bool attachEngine( networkServiceEngine *ptr ); - virtual void dispatchEvent( EVENT_CONTAINER *Evt ); + virtual bool dispatchEvent( EVENT_CONTAINER *Evt ); virtual bool getStatus( void ); bool setRemotePeerIP( CSTR ptr ); }; diff --git a/lib/components/base/basicTransport.cpp b/lib/components/base/basicTransport.cpp index ed96698d..cbcce8d1 100644 --- a/lib/components/base/basicTransport.cpp +++ b/lib/components/base/basicTransport.cpp @@ -11,6 +11,9 @@ basicTransport::basicTransport() :m_mQueueProtectorMutex(), m_mBufferProtectorMu basicTransport::~basicTransport(){ //ToDo: Cleanup parsers vector + m_mQueueProtectorMutex.lock(); + m_vParsers.clear(); + m_mQueueProtectorMutex.unlock(); }; bool basicTransport::addRecipient( protocolParser *ProtoParser ){ diff --git a/lib/components/base/basicTransport.h b/lib/components/base/basicTransport.h index 35e3761f..c7b7c07b 100644 --- a/lib/components/base/basicTransport.h +++ b/lib/components/base/basicTransport.h @@ -37,6 +37,7 @@ class basicTransport{ bool getStatus( void ){ return m_eConnectionStatus == CS_CONNECTED; }; void setConnectionStatus( CONNECTION_STATUS ES); CONNECTION_STATUS getConnectionStatus( void ); + virtual int getRawHandle(void){ return -1;}; }; #endif diff --git a/lib/data/net/clientPort.cpp b/lib/data/net/clientPort.cpp index 3231f6aa..5b168ad1 100644 --- a/lib/data/net/clientPort.cpp +++ b/lib/data/net/clientPort.cpp @@ -64,12 +64,12 @@ clientPort::clientPort(CSTR Host, int Port, bool KeepALive ) :transportSocket(){ }; clientPort::~clientPort(){ - //if (m_sHostName)free(m_sHostName); -# ifdef DEBUG_EXTRA - LOG("Disconnecting on Destructor!"); +#ifdef DEBUG + LOG("Destructor!"); #endif disconnect(); -# ifdef DEBUG_EXTRA +#ifdef DEBUG + LOG("Disconnected!"); LOG("Destructor Done!"); #endif }; @@ -241,10 +241,10 @@ int clientPort::sendBlock(unsigned char *Data, int DataSize){ //LOG("Data writen into Socket"); if( ( RetVal == -1 ) && (errno != EINTR ) && ( errno != EWOULDBLOCK ) ) { LOG_ERROR("Error acures while writing data into the Socket"); - shutdown( m_nSocketFD, 2 ); - close( m_nSocketFD ); - m_nSocketFD = -1; - //setConnectionStatus(CS_DISCONNECTED); + //shutdown( m_nSocketFD, 2 ); + //close( m_nSocketFD ); + //m_nSocketFD = -1; + disconnect(); return -1; }; if( RetVal < 0 ) RetVal = 0; @@ -262,9 +262,7 @@ int clientPort::sendBlock(unsigned char *Data, int DataSize){ } #endif } else { - //LOG_ERROR("Not Connected!"); - //m_bStatus = 0; - //setConnectionStatus(CS_DISCONNECTED); + LOG_ERROR("Not Connected!"); return -1; }; #else @@ -305,30 +303,27 @@ int clientPort::recptBlock(unsigned char *Buffer, int *BufferLength){ #ifdef __linux__ int RetVal; if( m_nSocketFD > -1 ) { - //sprintf(cBuffer,"Read from Socket %p", Buffer ); - //LOG(cBuffer); - RetVal = recv( m_nSocketFD, Buffer, MAXIMAL_SOCKET_PACKET_LENGTH, 0 );//read(m_nSocketFD, Buffer, MAXIMAL_SOCKET_PACKET_LENGTH); + RetVal = recv( m_nSocketFD, Buffer, MAXIMAL_SOCKET_PACKET_LENGTH, 0 ); if( RetVal < 1 ){ if( errno!=EAGAIN && errno!=EINTR ) { LOG_ERROR("Peer Closes Connection!"); - shutdown( m_nSocketFD, 2 ); - close( m_nSocketFD ); + //shutdown( m_nSocketFD, 2 ); + //close( m_nSocketFD ); + disconnect(); *BufferLength = 0; - m_nSocketFD = -1; - //setConnectionStatus(CS_DISCONNECTED); + //m_nSocketFD = -1; return -1; - } + }; }; if( !m_bKeepAlive ){ - shutdown( m_nSocketFD, SHUT_RDWR ); //SD_RECEIVE - close( m_nSocketFD ); - m_nSocketFD = -1; - //setConnectionStatus(CS_DISCONNECTED); + //shutdown( m_nSocketFD, SHUT_RDWR ); //SD_RECEIVE + //close( m_nSocketFD ); + //m_nSocketFD = -1; + disconnect(); }; } else { LOG_ERROR("Not Connected!"); - *BufferLength = 0; - //setConnectionStatus(CS_DISCONNECTED); + *BufferLength = 0; return -1; }; #else @@ -338,7 +333,7 @@ int clientPort::recptBlock(unsigned char *Buffer, int *BufferLength){ RetVal = recv( m_nSocketFD, (char *)Buffer, MAXIMAL_SOCKET_PACKET_LENGTH, 0); if( RetVal < 1 ){ if( errno!=EAGAIN && errno!=EINTR ) { - setConnectionStatus(CS_DISCONNECTED); + //setConnectionStatus(CS_DISCONNECTED); closesocket(m_nSocketFD); WSACleanup(); *BufferLength = 0; @@ -348,14 +343,14 @@ int clientPort::recptBlock(unsigned char *Buffer, int *BufferLength){ }; }; if (!m_bKeepAlive){ - setConnectionStatus(CS_DISCONNECTED); + //setConnectionStatus(CS_DISCONNECTED); closesocket(m_nSocketFD); WSACleanup(); //m_bConnected = false; m_nSocketFD = INVALID_SOCKET; }; } else { - setConnectionStatus(CS_DISCONNECTED); + //setConnectionStatus(CS_DISCONNECTED); LOG_ERROR("Not Connected!"); *BufferLength = 0; //m_bConnected = false; @@ -378,8 +373,6 @@ int clientPort::recptBlock(unsigned char *Buffer, int *BufferLength){ return RetVal; }; - LOG("Exit from Receive"); - *BufferLength = 0; if (RetVal == -1) return 0; @@ -394,6 +387,7 @@ int clientPort::recptBlock(unsigned char *Buffer, int *BufferLength){ return 0; }; + bool clientPort::disconnect(void){ if( m_eConnectionStatus == CS_CONNECTED ){ setConnectionStatus(CS_DISCONNECTED); diff --git a/lib/data/net/clientPort.h b/lib/data/net/clientPort.h index ee237ba1..c5c7ee0d 100644 --- a/lib/data/net/clientPort.h +++ b/lib/data/net/clientPort.h @@ -55,6 +55,7 @@ public: // Destructor virtual ~clientPort(); virtual bool create(); + virtual int getRawHandle(void){ return m_nSocketFD; }; bool disconnect(void); bool connectTo(CSTR Host, int Port); bool reconnect(void){ diff --git a/lib/data/protocol/protocolARGUS_DATA.h b/lib/data/protocol/protocolARGUS_DATA.h index 0badd169..164baab0 100644 --- a/lib/data/protocol/protocolARGUS_DATA.h +++ b/lib/data/protocol/protocolARGUS_DATA.h @@ -13,7 +13,7 @@ #define ARGUS_CHECKSUM_SIZE 2 -#define ARGUS_DATA_MSG_MIN_SIZE 8 //1flag+4size+1content+2checksum +#define ARGUS_DATA_MSG_MIN_SIZE 10 //1flag+4serial+4size+0content+2checksum #define ARGUS_RPC_MOJO_ITSELF 0x00 @@ -23,6 +23,9 @@ #define ARGUS_RPC_DRAW_TYPE_FAST 0x00 #define ARGUS_RPC_DRAW_TYPE_FULL 0x01 + +#define ARGUS_RPC_DEFAULT_MEDIA_CHUNK 2048 + typedef enum E_ARGUS_RPC_TAGS{ ARGUS_DATA_MSG_REBOOT_PLATFORM = 0x01, ARGUS_DATA_MSG_EXEC_STUDY = 0x02, @@ -129,13 +132,17 @@ typedef struct S_ARGUS_PUSH_RBUS_CMD{ }ARGUS_PUSH_RBUS_CMD; typedef struct S_ARGUS_DATA_VIDEO_INFO{ - char UUID[64]; + char UUID[65]; + //char SRC[65]; uint8_t FPS; uint32_t DTS; uint16_t DMS; - char FMT[4]; + uint16_t WIDTH; + uint16_t HEIGHT; + char MD5[33]; + char FMT[6]; uint32_t EVTCNT; - uint32_t DATA_SIZE; + uint32_t DATA_SIZE; }ARGUS_DATA_VIDEO_INFO; typedef struct S_ARGUS_DATA_EVT_BINDING{ @@ -146,11 +153,11 @@ typedef struct S_ARGUS_DATA_EVT_BINDING{ uint16_t DMS; // milliseconds }ARGUS_DATA_EVT_BINDING; -typedef struct S_ARGUS_DATA_VIDEO_SEGMENT{ +typedef struct S_ARGUS_DATA_VIDEO_CHUNK{ uint64_t MDBID; // Media ID uint32_t CHUNK_ID; uint32_t CHUNK_SIZE; -}ARGUS_DATA_VIDEO_SEGMENT; +}ARGUS_DATA_VIDEO_CHUNK; size_t argus_rpc_finishupPackage( uint8_t *data, uint32_t serial, uint32_t size ); diff --git a/lib/data/transport/transportSocket.cpp b/lib/data/transport/transportSocket.cpp index c6910fd3..1c5a90cf 100644 --- a/lib/data/transport/transportSocket.cpp +++ b/lib/data/transport/transportSocket.cpp @@ -30,11 +30,11 @@ transportSocket::transportSocket() : basicTransport(), basicDualThread(){ // Destructor implementation transportSocket::~transportSocket(){ # ifdef DEBUG_EXTRA - LOG("Destruct: START"); + LOG("Destructor begin!"); # endif - m_mBufferProtectorMutex.unlock(); + uninit(); # ifdef DEBUG_EXTRA - LOG("Destruct: DONE"); + LOG("Destructor end!"); # endif }; @@ -71,15 +71,16 @@ void transportSocket::m_fThreadAProc(void){ m_mBufferProtectorMutex.unlock(); } else { m_mBufferProtectorMutex.unlock(); - SLEEP(5); + usleep(100); }; }; + LOG("Sender Thread End!"); }; void transportSocket::m_fThreadBProc(void){ m_bThreadBStatus = TH_WORKING; int RetVal; -# ifdef DEBUG_EXTRA +#ifdef DEBUG_EXTRA LOG("Recipient Thread Started!"); #endif while( m_bThreadBStatus < TH_ENDED ){ @@ -87,10 +88,8 @@ void transportSocket::m_fThreadBProc(void){ if( RetVal == -1 ){ setConnectionStatus(CS_DISCONNECTED); m_nInputBufferSize = 0; - //if(!getStatus()) { m_bThreadBStatus = TH_ENDED; - m_bThreadAStatus = TH_ENDED; - //} else SLEEP(100); + m_bThreadAStatus = TH_ENDED; LOG_ERROR("Connection Droped on Reception Data"); } else if( m_nInputBufferSize > 0 ){ do{ @@ -109,9 +108,10 @@ void transportSocket::m_fThreadBProc(void){ }; } while( ( m_vParsers.size() == 0 ) && ( m_bThreadBStatus < TH_ENDED ) && ( m_bThreadBStatus < TH_ENDED ) ); } else { - SLEEP(5); + usleep(100); }; }; + LOG("Recipient Thread End!"); }; bool transportSocket::sendData(unsigned char *Data, int DataSize){