diff --git a/Projects/MediaMtx/internal/api/api.h b/Projects/MediaMtx/internal/api/api.h index d54d7cd7..fbb55644 100644 --- a/Projects/MediaMtx/internal/api/api.h +++ b/Projects/MediaMtx/internal/api/api.h @@ -20,7 +20,7 @@ #include "../conf/conf.h" #include "../core/pathManager.h" -#include "../protocols/httpp/httpServer.h" +#include namespace mtx { diff --git a/Projects/MediaMtx/internal/conf/conf.cpp b/Projects/MediaMtx/internal/conf/conf.cpp index cdae7a0e..0eea433c 100644 --- a/Projects/MediaMtx/internal/conf/conf.cpp +++ b/Projects/MediaMtx/internal/conf/conf.cpp @@ -34,44 +34,6 @@ static bool parseBool(const std::string & v, bool & out) return false; } -bool parseDurationMs(const std::string & s, int64_t & ms) -{ - if (s.empty()) - { - return false; - } - char * tEnd = nullptr; - double tV = strtod(s.c_str(), &tEnd); - if (tEnd == s.c_str() || tV < 0) - { - return false; - } - std::string tUnit(tEnd); - double tMul; - if (tUnit.empty() || tUnit == "s") - { - tMul = 1000.0; - } - else if (tUnit == "ms") - { - tMul = 1.0; - } - else if (tUnit == "m") - { - tMul = 60000.0; - } - else if (tUnit == "h") - { - tMul = 3600000.0; - } - else - { - return false; - } - ms = (int64_t) (tV * tMul + 0.5); - return true; -} - bool validPathName(const std::string & name) { if (name.empty() || name.size() > 128) @@ -88,44 +50,6 @@ bool validPathName(const std::string & name) return name != "." && name != ".."; } -bool splitHostPort(const std::string & addr, std::string & host, uint16_t & port) -{ - size_t tColon = addr.rfind(':'); - if (tColon == std::string::npos) - { - return false; - } - host = addr.substr(0, tColon); - int tPort = atoi(addr.c_str() + tColon + 1); - if (tPort <= 0 || tPort > 65535) - { - return false; - } - port = (uint16_t) tPort; - if (host.size() >= 2 && host.front() == '[' && host.back() == ']') - { - host = host.substr(1, host.size() - 2); - } - return true; -} - -std::string hideCredentials(const std::string & url) -{ - size_t tScheme = url.find("://"); - if (tScheme == std::string::npos) - { - return url; - } - size_t tHostStart = tScheme + 3; - size_t tSlash = url.find('/', tHostStart); - size_t tAt = url.rfind('@', tSlash == std::string::npos ? url.size() : tSlash); - if (tAt == std::string::npos || tAt < tHostStart) - { - return url; - } - return url.substr(0, tHostStart) + url.substr(tAt + 1); -} - static bool parsePathLine(const std::string & line, PathConf & pc, std::string & err) { std::istringstream tIn(line); diff --git a/Projects/MediaMtx/internal/conf/conf.h b/Projects/MediaMtx/internal/conf/conf.h index efabde9a..3d3e97f3 100644 --- a/Projects/MediaMtx/internal/conf/conf.h +++ b/Projects/MediaMtx/internal/conf/conf.h @@ -17,7 +17,8 @@ #include #include -#include "../logger/logger.h" +#include +#include namespace mtx { @@ -34,7 +35,7 @@ struct PathConf bool operator!=(const PathConf & o) const { return ! (*this == o); } }; -struct Conf +struct Conf : public ServerConf { // general LogLevel logLevel = LogLevel::Info; @@ -46,19 +47,6 @@ struct Conf // control API (empty address: disabled) std::string apiAddress = "127.0.0.1:9997"; - // WebRTC (WHEP) - std::string webrtcAddress = ":8889"; - std::string webrtcAllowOrigin = "*"; - std::vector webrtcICEServers; // e.g. stun:stun.l.google.com:19302 - std::string webrtcBindAddress; // ICE: bind to this local address (default: all) - uint16_t webrtcUDPPortMin = 8189; - uint16_t webrtcUDPPortMax = 8289; - - // recording - std::string recordPath = "./recordings/%path/%Y-%m-%d_%H-%M-%S-%f"; - int64_t recordSegmentDurationMs = 60000; - int64_t recordPartDurationMs = 1000; - // paths std::string pathsFile; std::vector paths; // paths file + command line @@ -73,12 +61,6 @@ struct Conf bool loadPathsFile(const std::string & file, std::vector & out, std::string & err); bool savePathsFile(const std::string & file, const std::vector & paths, std::string & err); -// "60s", "1m", "500ms", "1h", "1.5s"; plain number = seconds -bool parseDurationMs(const std::string & s, int64_t & ms); bool validPathName(const std::string & name); -// "host:port" / ":port" -> host ("" = any) and port -bool splitHostPort(const std::string & addr, std::string & host, uint16_t & port); -// rtsp://user:pass@host/... -> rtsp://host/... (for logs) -std::string hideCredentials(const std::string & url); } // namespace mtx diff --git a/Projects/MediaMtx/internal/core/core.h b/Projects/MediaMtx/internal/core/core.h index bf8f2c05..71a909ab 100644 --- a/Projects/MediaMtx/internal/core/core.h +++ b/Projects/MediaMtx/internal/core/core.h @@ -11,7 +11,7 @@ #include "../api/api.h" #include "../conf/conf.h" -#include "../servers/webrtc/webrtcServer.h" +#include #include "pathManager.h" namespace mtx { diff --git a/Projects/MediaMtx/internal/core/path.cpp b/Projects/MediaMtx/internal/core/path.cpp index c7bcbaf4..3685d2a6 100644 --- a/Projects/MediaMtx/internal/core/path.cpp +++ b/Projects/MediaMtx/internal/core/path.cpp @@ -1,10 +1,8 @@ #include "path.h" -#include "../recorder/recorder.h" - namespace mtx { -Path::Path(const PathConf & conf, const Conf & global) : LogParent("[path " + conf.name + "] "), m_conf(conf), m_global(global) {} +Path::Path(const PathConf & conf, const Conf & global) : MediaPath(conf.name, conf.record, global), m_conf(conf), m_fullConf(global) {} Path::~Path() { @@ -13,7 +11,7 @@ Path::~Path() void Path::start() { - m_pSource.reset(new RtspSource(m_conf, m_global, this)); + m_pSource.reset(new RtspSource(m_conf, m_fullConf, this)); m_pSource->start(); } @@ -28,92 +26,9 @@ void Path::stop() PathInfo Path::info() const { - std::lock_guard lock(m_mutex); - PathInfo tI; - tI.name = m_conf.name; - tI.source = m_conf.source; - tI.record = m_conf.record; - tI.ready = (m_pStream != nullptr); - tI.readySinceUs = m_tReadySinceUs; - tI.readers = m_readers.size(); - if (m_pStream) - { - tI.desc = m_pStream->desc(); - tI.bytesReceived = m_pStream->bytesReceived(); - } + PathInfo tI = MediaPath::info(); + tI.source = m_conf.source; return tI; } -bool Path::addReader(PathReader * r, StreamDesc & desc, std::string & err) -{ - std::lock_guard lock(m_mutex); - if (! m_pStream) - { - err = "no stream is available on path '" + m_conf.name + "'"; - return false; - } - desc = m_pStream->desc(); - m_readers.insert(r); - m_pStream->addReader(r); - return true; -} - -void Path::removeReader(PathReader * r) -{ - std::lock_guard lock(m_mutex); - if (m_readers.erase(r) > 0 && m_pStream) - { - m_pStream->removeReader(r); - } -} - -void Path::sourceSetReady(const StreamDesc & desc) -{ - std::lock_guard lock(m_mutex); - m_pStream = std::make_shared(desc); - m_tReadySinceUs = nowUs(); - log(LogLevel::Info, "stream is available and online, 1 track (H264 %dx%d)", desc.width, desc.height); - if (m_conf.record) - { - m_pRecorder.reset(new Recorder(m_conf.name, m_global, m_pStream, this)); - m_pRecorder->start(); - } -} - -void Path::sourceSetNotReady() -{ - std::unique_ptr tRec; - { - std::lock_guard lock(m_mutex); - if (! m_pStream) - { - return; - } - for (PathReader * r : m_readers) - { - m_pStream->removeReader(r); - r->pathNotReady(); - } - m_readers.clear(); - tRec = std::move(m_pRecorder); - m_pStream.reset(); - m_tReadySinceUs = 0; - } - tRec.reset(); // closes the segment - log(LogLevel::Info, "stream is not available anymore"); -} - -void Path::sourceWriteUnit(const UnitPtr & unit) -{ - std::shared_ptr tStream; - { - std::lock_guard lock(m_mutex); - tStream = m_pStream; - } - if (tStream) - { - tStream->writeUnit(unit); - } -} - } // namespace mtx diff --git a/Projects/MediaMtx/internal/core/path.h b/Projects/MediaMtx/internal/core/path.h index f780ade2..5469fa45 100644 --- a/Projects/MediaMtx/internal/core/path.h +++ b/Projects/MediaMtx/internal/core/path.h @@ -1,46 +1,20 @@ /* MediaMtx (C++) - path (MediaMTX: internal/core/path.go) - - A path has a static source (RTSP camera), a stream while the source is ready, an optional recorder and - the readers (WebRTC sessions). + A MediaPath (lib/data/media/mtx: stream, readers, recorder) with a static source (RTSP camera). */ #pragma once #include -#include -#include #include +#include + #include "../conf/conf.h" -#include "../logger/logger.h" #include "../staticsources/rtsp/rtspSource.h" -#include "../stream/stream.h" namespace mtx { -class Recorder; - -class PathReader : public StreamReader -{ - public: - // The source of the path is gone: the reader must close (called with the path locked: do not block, - // do not call back into the path) - virtual void pathNotReady() = 0; -}; - -struct PathInfo -{ - std::string name; - std::string source; - bool record = false; - bool ready = false; - int64_t readySinceUs = 0; - StreamDesc desc; - size_t readers = 0; - uint64_t bytesReceived = 0; -}; - -class Path : public SourceParent, public LogParent +class Path : public MediaPath { public: Path(const PathConf & conf, const Conf & global); @@ -52,24 +26,10 @@ class Path : public SourceParent, public LogParent const PathConf & conf() const { return m_conf; } PathInfo info() const; - // false + err when the path has no stream - bool addReader(PathReader * r, StreamDesc & desc, std::string & err); - void removeReader(PathReader * r); - - // SourceParent - void sourceSetReady(const StreamDesc & desc) override; - void sourceSetNotReady() override; - void sourceWriteUnit(const UnitPtr & unit) override; - private: PathConf m_conf; - Conf m_global; + Conf m_fullConf; std::unique_ptr m_pSource; - mutable std::mutex m_mutex; - std::shared_ptr m_pStream; - std::unique_ptr m_pRecorder; - std::set m_readers; - int64_t m_tReadySinceUs = 0; }; } // namespace mtx diff --git a/Projects/MediaMtx/internal/core/pathManager.h b/Projects/MediaMtx/internal/core/pathManager.h index 6940bb37..1a833b82 100644 --- a/Projects/MediaMtx/internal/core/pathManager.h +++ b/Projects/MediaMtx/internal/core/pathManager.h @@ -14,7 +14,7 @@ namespace mtx { -class PathManager : public LogParent +class PathManager : public LogParent, public PathProvider { public: explicit PathManager(const Conf & global); @@ -25,6 +25,8 @@ class PathManager : public LogParent void closeAll(); std::shared_ptr find(const std::string & name) const; + // PathProvider (WebRTC server) + std::shared_ptr findPath(const std::string & name) const override { return find(name); } std::vector list() const; std::vector confs() const; diff --git a/Projects/MediaMtx/internal/staticsources/rtsp/rtspSource.cpp b/Projects/MediaMtx/internal/staticsources/rtsp/rtspSource.cpp index cf02e8fd..d0f6bcc7 100644 --- a/Projects/MediaMtx/internal/staticsources/rtsp/rtspSource.cpp +++ b/Projects/MediaMtx/internal/staticsources/rtsp/rtspSource.cpp @@ -6,7 +6,7 @@ #include -#include "../../codecs/h264/h264.h" +#include namespace mtx { diff --git a/Projects/MediaMtx/internal/staticsources/rtsp/rtspSource.h b/Projects/MediaMtx/internal/staticsources/rtsp/rtspSource.h index c5f10b72..cbfeedce 100644 --- a/Projects/MediaMtx/internal/staticsources/rtsp/rtspSource.h +++ b/Projects/MediaMtx/internal/staticsources/rtsp/rtspSource.h @@ -14,23 +14,12 @@ #include #include "../../conf/conf.h" -#include "../../logger/logger.h" -#include "../../stream/stream.h" +#include +#include +#include namespace mtx { -class SourceParent -{ - public: - virtual ~SourceParent() {} - // The source has the codec parameters: the path creates its stream - virtual void sourceSetReady(const StreamDesc & desc) = 0; - // The source lost its connection: the path destroys its stream - virtual void sourceSetNotReady() = 0; - // A unit of the source (called from the source thread) - virtual void sourceWriteUnit(const UnitPtr & unit) = 0; -}; - class RtspSource : public LogParent { public: diff --git a/Projects/MediaMtx/makefile b/Projects/MediaMtx/makefile index f6645888..a72ab4d3 100644 --- a/Projects/MediaMtx/makefile +++ b/Projects/MediaMtx/makefile @@ -20,33 +20,38 @@ DATACHANNEL_LIBS ?= -ldatachannel CXX ?= g++ DFSL = ../.. -CXXFLAGS += -std=c++17 -Wall -Wextra -Wno-unused-parameter $(OPT) $(LIVE555_CFLAGS) $(DATACHANNEL_CFLAGS) -I$(DFSL)/lib/include +MTXLIB = $(DFSL)/lib/data/media/mtx +CXXFLAGS += -std=c++17 -Wall -Wextra -Wno-unused-parameter $(OPT) $(LIVE555_CFLAGS) $(DATACHANNEL_CFLAGS) -I$(DFSL)/lib/include -I$(MTXLIB) LIBS = $(DATACHANNEL_LIBS) $(LIVE555_LIBS) -lssl -lcrypto -lpthread TARGET = $(OUTDIR)/mediamtx SRCS = main.cpp \ - internal/logger/logger.cpp \ internal/conf/conf.cpp \ - internal/codecs/h264/h264.cpp \ - internal/stream/stream.cpp \ internal/staticsources/rtsp/rtspSource.cpp \ - internal/protocols/httpp/httpServer.cpp \ internal/core/path.cpp \ internal/core/pathManager.cpp \ internal/core/core.cpp \ - internal/recorder/fmp4Writer.cpp \ - internal/recorder/recorder.cpp \ - internal/servers/webrtc/session.cpp \ - internal/servers/webrtc/webrtcServer.cpp \ internal/api/api.cpp +# Shared with la_mojo (kernelModuleEmbedVideo): lib/data/media/mtx +LIB_SRCS = $(MTXLIB)/logger/logger.cpp \ + $(MTXLIB)/conf/serverConf.cpp \ + $(MTXLIB)/codecs/h264/h264.cpp \ + $(MTXLIB)/stream/stream.cpp \ + $(MTXLIB)/protocols/httpp/httpServer.cpp \ + $(MTXLIB)/core/mediaPath.cpp \ + $(MTXLIB)/recorder/fmp4Writer.cpp \ + $(MTXLIB)/recorder/recorder.cpp \ + $(MTXLIB)/servers/webrtc/session.cpp \ + $(MTXLIB)/servers/webrtc/webrtcServer.cpp + # JsonCpp from dr_frucht JSON_SRCS = $(DFSL)/lib/data/json/json_reader.cpp \ $(DFSL)/lib/data/json/json_value.cpp \ $(DFSL)/lib/data/json/json_writer.cpp -OBJS = $(patsubst %.cpp,$(OUTDIR)/obj/%.o,$(SRCS)) $(patsubst $(DFSL)/lib/data/json/%.cpp,$(OUTDIR)/obj/jsoncpp/%.o,$(JSON_SRCS)) +OBJS = $(patsubst %.cpp,$(OUTDIR)/obj/%.o,$(SRCS)) $(patsubst $(MTXLIB)/%.cpp,$(OUTDIR)/obj/mtxlib/%.o,$(LIB_SRCS)) $(patsubst $(DFSL)/lib/data/json/%.cpp,$(OUTDIR)/obj/jsoncpp/%.o,$(JSON_SRCS)) DEPS = $(OBJS:.o=.d) all: $(TARGET) @@ -58,6 +63,10 @@ $(OUTDIR)/obj/%.o: %.cpp @mkdir -p $(dir $@) $(CXX) $(CXXFLAGS) -MMD -MP -c $< -o $@ +$(OUTDIR)/obj/mtxlib/%.o: $(MTXLIB)/%.cpp + @mkdir -p $(dir $@) + $(CXX) $(CXXFLAGS) -MMD -MP -c $< -o $@ + $(OUTDIR)/obj/jsoncpp/%.o: $(DFSL)/lib/data/json/%.cpp @mkdir -p $(dir $@) $(CXX) $(CXXFLAGS) -w -MMD -MP -c $< -o $@ diff --git a/Projects/la_mojo/makefile b/Projects/la_mojo/makefile index bacdcc45..23c79712 100644 --- a/Projects/la_mojo/makefile +++ b/Projects/la_mojo/makefile @@ -1,1181 +1,1228 @@ -# SlickEdit generated file. Do not edit this file except in designated areas. - -# Make command to use for dependencies -MAKE=make -RM=rm -MKDIR=mkdir - -# -----Begin user-editable area----- - -# -----End user-editable area----- - -# If no configuration is specified, "Debug" will be used -ifndef CFG -CFG=Debug -endif - -# -# Configuration: Debug -# -ifeq "$(CFG)" "Debug" -OUTDIR=Debug -OUTFILE=$(OUTDIR)/mojo_d -CFG_INC= -CFG_LIB=-lsqlite3 -lpthread -lmysqlclient -lssl -lcurl -lm -lcrypto \ - -lconfig -lz -lv4l1 -lv4l2 -lhidapi-libusb `pkg-config libavcodec \ - libavdevice libavfilter libavformat libavutil libpostproc \ - libswresample libswscale --libs` -latomic `pkg-config --libs openssl \ - opencv4 rdkafka++` -L/usr/lib -lrdkafka++ -lrdkafka -lwiringx \ - -lliveMedia -lgroupsock -lBasicUsageEnvironment -lUsageEnvironment \ - -ldarknet -CFG_OBJ= -COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ - $(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ - $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ - $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ - $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ - $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicObject.o \ - $(OUTDIR)/basicPosition.o $(OUTDIR)/basicRing.o \ - $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ - $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ - $(OUTDIR)/bosch_rcp.o $(OUTDIR)/clientPort.o \ - $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \ - $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \ - $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \ - $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \ - $(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \ - $(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \ - $(OUTDIR)/deviceNodePresetCamControl.o \ - $(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \ - $(OUTDIR)/deviceNodeStaticCamControl.o $(OUTDIR)/fs_helper.o \ - $(OUTDIR)/FSClient.o $(OUTDIR)/hardwareManager.o \ - $(OUTDIR)/hardwareResource.o \ - $(OUTDIR)/hardwareResourceDryContactProvider.o \ - $(OUTDIR)/hardwareResourceNetworkProvider.o \ - $(OUTDIR)/hardwareResourceSerialProvider.o \ - $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ - $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ - $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ - $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterBubble.o \ - $(OUTDIR)/kernelEventFilterTrain.o $(OUTDIR)/kernelEventFilterYOLO.o \ - $(OUTDIR)/kernelHelperMediaMTX.o $(OUTDIR)/kernelModule.o \ - $(OUTDIR)/kernelModuleAttentionCloud.o $(OUTDIR)/kernelModuleBosch.o \ - $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ - $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ - $(OUTDIR)/kernelModuleModemManager.o \ - $(OUTDIR)/kernelModuleOnvifObserver.o \ - $(OUTDIR)/kernelModuleReportBackupper.o $(OUTDIR)/kernelModuleSSDP.o \ - $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ - $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ - $(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \ - $(OUTDIR)/mojoRemoteClient.o $(OUTDIR)/mysql_class.o \ - $(OUTDIR)/MySQL_dataBinder.o $(OUTDIR)/netClientHandler.o \ - $(OUTDIR)/netServer.o $(OUTDIR)/objectFileLoggingService.o \ - $(OUTDIR)/objectSystemAnchor.o $(OUTDIR)/ponvif.o \ - $(OUTDIR)/protocol.o $(OUTDIR)/protocolARGUS.o \ - $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/protocolBVMS.o \ - $(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolKAFKA.o \ - $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGS3D.o \ - $(OUTDIR)/protocolLGS3D_client.o $(OUTDIR)/protocolONVIF.o \ - $(OUTDIR)/protocolPTZ.o $(OUTDIR)/protocolPTZ_BRCP.o \ - $(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \ - $(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \ - $(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \ - $(OUTDIR)/streamHandler.o $(OUTDIR)/targetPipeLine.o \ - $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \ - $(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \ - $(OUTDIR)/xmlParser.o -OBJ=$(COMMON_OBJ) $(CFG_OBJ) -ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ - $(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ - $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ - $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ - $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ - $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicObject.o \ - $(OUTDIR)/basicPosition.o $(OUTDIR)/basicRing.o \ - $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ - $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ - $(OUTDIR)/bosch_rcp.o $(OUTDIR)/clientPort.o \ - $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \ - $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \ - $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \ - $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \ - $(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \ - $(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \ - $(OUTDIR)/deviceNodePresetCamControl.o \ - $(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \ - $(OUTDIR)/deviceNodeStaticCamControl.o $(OUTDIR)/fs_helper.o \ - $(OUTDIR)/FSClient.o $(OUTDIR)/hardwareManager.o \ - $(OUTDIR)/hardwareResource.o \ - $(OUTDIR)/hardwareResourceDryContactProvider.o \ - $(OUTDIR)/hardwareResourceNetworkProvider.o \ - $(OUTDIR)/hardwareResourceSerialProvider.o \ - $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ - $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ - $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ - $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterBubble.o \ - $(OUTDIR)/kernelEventFilterTrain.o $(OUTDIR)/kernelEventFilterYOLO.o \ - $(OUTDIR)/kernelHelperMediaMTX.o $(OUTDIR)/kernelModule.o \ - $(OUTDIR)/kernelModuleAttentionCloud.o $(OUTDIR)/kernelModuleBosch.o \ - $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ - $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ - $(OUTDIR)/kernelModuleModemManager.o \ - $(OUTDIR)/kernelModuleOnvifObserver.o \ - $(OUTDIR)/kernelModuleReportBackupper.o $(OUTDIR)/kernelModuleSSDP.o \ - $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ - $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ - $(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \ - $(OUTDIR)/mojoRemoteClient.o $(OUTDIR)/mysql_class.o \ - $(OUTDIR)/MySQL_dataBinder.o $(OUTDIR)/netClientHandler.o \ - $(OUTDIR)/netServer.o $(OUTDIR)/objectFileLoggingService.o \ - $(OUTDIR)/objectSystemAnchor.o $(OUTDIR)/ponvif.o \ - $(OUTDIR)/protocol.o $(OUTDIR)/protocolARGUS.o \ - $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/protocolBVMS.o \ - $(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolKAFKA.o \ - $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGS3D.o \ - $(OUTDIR)/protocolLGS3D_client.o $(OUTDIR)/protocolONVIF.o \ - $(OUTDIR)/protocolPTZ.o $(OUTDIR)/protocolPTZ_BRCP.o \ - $(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \ - $(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \ - $(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \ - $(OUTDIR)/streamHandler.o $(OUTDIR)/targetPipeLine.o \ - $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \ - $(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \ - $(OUTDIR)/xmlParser.o -lsqlite3 -lpthread -lmysqlclient -lssl -lcurl \ - -lm -lcrypto -lconfig -lz -lv4l1 -lv4l2 -lhidapi-libusb `pkg-config \ - libavcodec libavdevice libavfilter libavformat libavutil libpostproc \ - libswresample libswscale --libs` -latomic `pkg-config --libs openssl \ - opencv4 rdkafka++` -L/usr/lib -lrdkafka++ -lrdkafka -lwiringx \ - -lliveMedia -lgroupsock -lBasicUsageEnvironment -lUsageEnvironment \ - -ldarknet - -COMPILE=g++ -c -x c++ "-DDEBUG" "-D__STDC_CONSTANT_MACROS__" "-D_CLIENT_APPLICATION_" "-D_OPENCV_" "-DRASPI_HARDWARE" -O0 -w -Wpointer-arith -std=c++17 -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) - -# Pattern rules -$(OUTDIR)/%.o : ../../lib/components/object/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/json/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/transport/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/protocol/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/App/mojo/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/rfs/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/App/common/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/net/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/media/video/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/hardware/hid/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/alg/lgs/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/bosch_rcp/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/components/base/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/curl/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/sqlite/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/ponvif/%.cpp - $(COMPILE) - -# Build rules -all: $(OUTFILE) - -$(OUTFILE): $(OUTDIR) $(OBJ) - $(LINK) - -$(OUTDIR): - $(MKDIR) -p "$(OUTDIR)" - -# Rebuild this project -rebuild: cleanall - @$(MAKE) -f "$(strip $(MAKEFILE_LIST))" $(MAKEFLAGS) all - -# Clean this project -clean: - $(RM) -f $(OUTFILE) - $(RM) -f $(OBJ) - -# Clean this project and all dependencies -cleanall: clean -endif - -# -# Configuration: Release -# -ifeq "$(CFG)" "Release" -OUTDIR=Release -OUTFILE=$(OUTDIR)/mojo -CFG_INC= -CFG_LIB=-lconfig -lpthread -lmysqlclient -lelf -lcurses -lcdk -lcurl \ - `pkg-config --libs rdkafka++` -L/usr/lib -lrdkafka++ -lrdkafka \ - -lwiringx -lsqlite3 -ldarknet -lsensors -CFG_OBJ= -COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ - $(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ - $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ - $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ - $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ - $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicObject.o \ - $(OUTDIR)/basicPosition.o $(OUTDIR)/basicRing.o \ - $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ - $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ - $(OUTDIR)/bosch_rcp.o $(OUTDIR)/clientPort.o \ - $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \ - $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \ - $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \ - $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \ - $(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \ - $(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \ - $(OUTDIR)/deviceNodePresetCamControl.o \ - $(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \ - $(OUTDIR)/deviceNodeStaticCamControl.o $(OUTDIR)/fs_helper.o \ - $(OUTDIR)/FSClient.o $(OUTDIR)/hardwareManager.o \ - $(OUTDIR)/hardwareResource.o \ - $(OUTDIR)/hardwareResourceDryContactProvider.o \ - $(OUTDIR)/hardwareResourceNetworkProvider.o \ - $(OUTDIR)/hardwareResourceSerialProvider.o \ - $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ - $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ - $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ - $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterBubble.o \ - $(OUTDIR)/kernelEventFilterTrain.o $(OUTDIR)/kernelEventFilterYOLO.o \ - $(OUTDIR)/kernelHelperMediaMTX.o $(OUTDIR)/kernelModule.o \ - $(OUTDIR)/kernelModuleAttentionCloud.o $(OUTDIR)/kernelModuleBosch.o \ - $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ - $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ - $(OUTDIR)/kernelModuleModemManager.o \ - $(OUTDIR)/kernelModuleOnvifObserver.o \ - $(OUTDIR)/kernelModuleReportBackupper.o $(OUTDIR)/kernelModuleSSDP.o \ - $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ - $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ - $(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \ - $(OUTDIR)/mojoRemoteClient.o $(OUTDIR)/mysql_class.o \ - $(OUTDIR)/MySQL_dataBinder.o $(OUTDIR)/netClientHandler.o \ - $(OUTDIR)/netServer.o $(OUTDIR)/objectFileLoggingService.o \ - $(OUTDIR)/objectSystemAnchor.o $(OUTDIR)/ponvif.o \ - $(OUTDIR)/protocol.o $(OUTDIR)/protocolARGUS.o \ - $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/protocolBVMS.o \ - $(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolKAFKA.o \ - $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGS3D.o \ - $(OUTDIR)/protocolLGS3D_client.o $(OUTDIR)/protocolONVIF.o \ - $(OUTDIR)/protocolPTZ.o $(OUTDIR)/protocolPTZ_BRCP.o \ - $(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \ - $(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \ - $(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \ - $(OUTDIR)/streamHandler.o $(OUTDIR)/targetPipeLine.o \ - $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \ - $(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \ - $(OUTDIR)/xmlParser.o -OBJ=$(COMMON_OBJ) $(CFG_OBJ) -ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ - $(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ - $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ - $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ - $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ - $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicObject.o \ - $(OUTDIR)/basicPosition.o $(OUTDIR)/basicRing.o \ - $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ - $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ - $(OUTDIR)/bosch_rcp.o $(OUTDIR)/clientPort.o \ - $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \ - $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \ - $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \ - $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \ - $(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \ - $(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \ - $(OUTDIR)/deviceNodePresetCamControl.o \ - $(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \ - $(OUTDIR)/deviceNodeStaticCamControl.o $(OUTDIR)/fs_helper.o \ - $(OUTDIR)/FSClient.o $(OUTDIR)/hardwareManager.o \ - $(OUTDIR)/hardwareResource.o \ - $(OUTDIR)/hardwareResourceDryContactProvider.o \ - $(OUTDIR)/hardwareResourceNetworkProvider.o \ - $(OUTDIR)/hardwareResourceSerialProvider.o \ - $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ - $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ - $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ - $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterBubble.o \ - $(OUTDIR)/kernelEventFilterTrain.o $(OUTDIR)/kernelEventFilterYOLO.o \ - $(OUTDIR)/kernelHelperMediaMTX.o $(OUTDIR)/kernelModule.o \ - $(OUTDIR)/kernelModuleAttentionCloud.o $(OUTDIR)/kernelModuleBosch.o \ - $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ - $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ - $(OUTDIR)/kernelModuleModemManager.o \ - $(OUTDIR)/kernelModuleOnvifObserver.o \ - $(OUTDIR)/kernelModuleReportBackupper.o $(OUTDIR)/kernelModuleSSDP.o \ - $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ - $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ - $(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \ - $(OUTDIR)/mojoRemoteClient.o $(OUTDIR)/mysql_class.o \ - $(OUTDIR)/MySQL_dataBinder.o $(OUTDIR)/netClientHandler.o \ - $(OUTDIR)/netServer.o $(OUTDIR)/objectFileLoggingService.o \ - $(OUTDIR)/objectSystemAnchor.o $(OUTDIR)/ponvif.o \ - $(OUTDIR)/protocol.o $(OUTDIR)/protocolARGUS.o \ - $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/protocolBVMS.o \ - $(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolKAFKA.o \ - $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGS3D.o \ - $(OUTDIR)/protocolLGS3D_client.o $(OUTDIR)/protocolONVIF.o \ - $(OUTDIR)/protocolPTZ.o $(OUTDIR)/protocolPTZ_BRCP.o \ - $(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \ - $(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \ - $(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \ - $(OUTDIR)/streamHandler.o $(OUTDIR)/targetPipeLine.o \ - $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \ - $(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \ - $(OUTDIR)/xmlParser.o -lconfig -lpthread -lmysqlclient -lelf \ - -lcurses -lcdk -lcurl `pkg-config --libs rdkafka++` -L/usr/lib \ - -lrdkafka++ -lrdkafka -lwiringx -lsqlite3 -ldarknet -lsensors - -COMPILE=g++ -c -x c++ "-DSLIM_KERNEL" "-D_THREAD_SAFE" "-D_BSD_SOURCE" "-D_REENTRANT" -O3 -w -Wpointer-arith -std=gnu++17 -I../../lib/include -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $< -LINK=g++ -O3 -w -s -o "$(OUTFILE)" $(ALL_OBJ) - -# Pattern rules -$(OUTDIR)/%.o : ../../lib/components/object/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/json/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/transport/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/protocol/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/App/mojo/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/rfs/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/App/common/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/net/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/media/video/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/hardware/hid/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/alg/lgs/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/bosch_rcp/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/components/base/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/curl/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/sqlite/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/ponvif/%.cpp - $(COMPILE) - -# Build rules -all: $(OUTFILE) - -$(OUTFILE): $(OUTDIR) $(OBJ) - $(LINK) - -$(OUTDIR): - $(MKDIR) -p "$(OUTDIR)" - -# Rebuild this project -rebuild: cleanall - @$(MAKE) -f "$(strip $(MAKEFILE_LIST))" $(MAKEFLAGS) all - -# Clean this project -clean: - $(RM) -f $(OUTFILE) - $(RM) -f $(OBJ) - -# Clean this project and all dependencies -cleanall: clean -endif - -# -# Configuration: Debug86 -# -ifeq "$(CFG)" "Debug86" -OUTDIR=Debug86 -OUTFILE=$(OUTDIR)/mojo_d -CFG_INC= -CFG_LIB=-lsqlite3 -lpthread -lmysqlclient -lssl -lcurl -lm -lcrypto \ - -lconfig -lz -lv4l1 -lv4l2 -lhidapi-libusb `pkg-config libavcodec \ - libavdevice libavfilter libavformat libavutil libpostproc \ - libswresample libswscale --libs` -latomic `pkg-config --libs openssl \ - opencv4 rdkafka++` -lliveMedia -lgroupsock -lBasicUsageEnvironment \ - -lUsageEnvironment -ldarknet -lsensors -CFG_OBJ= -COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ - $(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ - $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ - $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ - $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ - $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicObject.o \ - $(OUTDIR)/basicPosition.o $(OUTDIR)/basicRing.o \ - $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ - $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ - $(OUTDIR)/bosch_rcp.o $(OUTDIR)/clientPort.o \ - $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \ - $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \ - $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \ - $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \ - $(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \ - $(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \ - $(OUTDIR)/deviceNodePresetCamControl.o \ - $(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \ - $(OUTDIR)/deviceNodeStaticCamControl.o $(OUTDIR)/fs_helper.o \ - $(OUTDIR)/FSClient.o $(OUTDIR)/hardwareManager.o \ - $(OUTDIR)/hardwareResource.o \ - $(OUTDIR)/hardwareResourceDryContactProvider.o \ - $(OUTDIR)/hardwareResourceNetworkProvider.o \ - $(OUTDIR)/hardwareResourceSerialProvider.o \ - $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ - $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ - $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ - $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterBubble.o \ - $(OUTDIR)/kernelEventFilterTrain.o $(OUTDIR)/kernelEventFilterYOLO.o \ - $(OUTDIR)/kernelHelperMediaMTX.o $(OUTDIR)/kernelModule.o \ - $(OUTDIR)/kernelModuleAttentionCloud.o $(OUTDIR)/kernelModuleBosch.o \ - $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ - $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ - $(OUTDIR)/kernelModuleModemManager.o \ - $(OUTDIR)/kernelModuleOnvifObserver.o \ - $(OUTDIR)/kernelModuleReportBackupper.o $(OUTDIR)/kernelModuleSSDP.o \ - $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ - $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ - $(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \ - $(OUTDIR)/mojoRemoteClient.o $(OUTDIR)/mysql_class.o \ - $(OUTDIR)/MySQL_dataBinder.o $(OUTDIR)/netClientHandler.o \ - $(OUTDIR)/netServer.o $(OUTDIR)/objectFileLoggingService.o \ - $(OUTDIR)/objectSystemAnchor.o $(OUTDIR)/ponvif.o \ - $(OUTDIR)/protocol.o $(OUTDIR)/protocolARGUS.o \ - $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/protocolBVMS.o \ - $(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolKAFKA.o \ - $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGS3D.o \ - $(OUTDIR)/protocolLGS3D_client.o $(OUTDIR)/protocolONVIF.o \ - $(OUTDIR)/protocolPTZ.o $(OUTDIR)/protocolPTZ_BRCP.o \ - $(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \ - $(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \ - $(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \ - $(OUTDIR)/streamHandler.o $(OUTDIR)/targetPipeLine.o \ - $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \ - $(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \ - $(OUTDIR)/xmlParser.o -OBJ=$(COMMON_OBJ) $(CFG_OBJ) -ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ - $(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ - $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ - $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ - $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ - $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicObject.o \ - $(OUTDIR)/basicPosition.o $(OUTDIR)/basicRing.o \ - $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ - $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ - $(OUTDIR)/bosch_rcp.o $(OUTDIR)/clientPort.o \ - $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \ - $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \ - $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \ - $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \ - $(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \ - $(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \ - $(OUTDIR)/deviceNodePresetCamControl.o \ - $(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \ - $(OUTDIR)/deviceNodeStaticCamControl.o $(OUTDIR)/fs_helper.o \ - $(OUTDIR)/FSClient.o $(OUTDIR)/hardwareManager.o \ - $(OUTDIR)/hardwareResource.o \ - $(OUTDIR)/hardwareResourceDryContactProvider.o \ - $(OUTDIR)/hardwareResourceNetworkProvider.o \ - $(OUTDIR)/hardwareResourceSerialProvider.o \ - $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ - $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ - $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ - $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterBubble.o \ - $(OUTDIR)/kernelEventFilterTrain.o $(OUTDIR)/kernelEventFilterYOLO.o \ - $(OUTDIR)/kernelHelperMediaMTX.o $(OUTDIR)/kernelModule.o \ - $(OUTDIR)/kernelModuleAttentionCloud.o $(OUTDIR)/kernelModuleBosch.o \ - $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ - $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ - $(OUTDIR)/kernelModuleModemManager.o \ - $(OUTDIR)/kernelModuleOnvifObserver.o \ - $(OUTDIR)/kernelModuleReportBackupper.o $(OUTDIR)/kernelModuleSSDP.o \ - $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ - $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ - $(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \ - $(OUTDIR)/mojoRemoteClient.o $(OUTDIR)/mysql_class.o \ - $(OUTDIR)/MySQL_dataBinder.o $(OUTDIR)/netClientHandler.o \ - $(OUTDIR)/netServer.o $(OUTDIR)/objectFileLoggingService.o \ - $(OUTDIR)/objectSystemAnchor.o $(OUTDIR)/ponvif.o \ - $(OUTDIR)/protocol.o $(OUTDIR)/protocolARGUS.o \ - $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/protocolBVMS.o \ - $(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolKAFKA.o \ - $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGS3D.o \ - $(OUTDIR)/protocolLGS3D_client.o $(OUTDIR)/protocolONVIF.o \ - $(OUTDIR)/protocolPTZ.o $(OUTDIR)/protocolPTZ_BRCP.o \ - $(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \ - $(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \ - $(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \ - $(OUTDIR)/streamHandler.o $(OUTDIR)/targetPipeLine.o \ - $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \ - $(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \ - $(OUTDIR)/xmlParser.o -lsqlite3 -lpthread -lmysqlclient -lssl -lcurl \ - -lm -lcrypto -lconfig -lz -lv4l1 -lv4l2 -lhidapi-libusb `pkg-config \ - libavcodec libavdevice libavfilter libavformat libavutil libpostproc \ - libswresample libswscale --libs` -latomic `pkg-config --libs openssl \ - opencv4 rdkafka++` -lliveMedia -lgroupsock -lBasicUsageEnvironment \ - -lUsageEnvironment -ldarknet -lsensors - -COMPILE=g++ -c -x c++ "-DDEBUG" "-DMEKOROT_PROJECT_" "-D__STDC_CONSTANT_MACROS" "-D_CLIENT_APPLICATION_" "-D_OPENCV_" -O0 -Wall -pedantic -W -std=c++17 -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 -Wall -pedantic -o "$(OUTFILE)" $(ALL_OBJ) - -# Pattern rules -$(OUTDIR)/%.o : ../../lib/components/object/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/json/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/transport/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/protocol/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/App/mojo/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/rfs/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/App/common/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/net/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/media/video/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/hardware/hid/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/alg/lgs/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/bosch_rcp/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/components/base/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/curl/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/sqlite/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/ponvif/%.cpp - $(COMPILE) - -# Build rules -all: $(OUTFILE) - -$(OUTFILE): $(OUTDIR) $(OBJ) - $(LINK) - -$(OUTDIR): - $(MKDIR) -p "$(OUTDIR)" - -# Rebuild this project -rebuild: cleanall - @$(MAKE) -f "$(strip $(MAKEFILE_LIST))" $(MAKEFLAGS) all - -# Clean this project -clean: - $(RM) -f $(OUTFILE) - $(RM) -f $(OBJ) - -# Clean this project and all dependencies -cleanall: clean -endif - -# -# Configuration: Release86 -# -ifeq "$(CFG)" "Release86" -OUTDIR=Release86 -OUTFILE=$(OUTDIR)/mojo -CFG_INC= -CFG_LIB=-lsqlite3 -lpthread -lmysqlclient -lssl -lcurl -lm -lcrypto \ - -lconfig -lz -lv4l1 -lv4l2 -lhidapi-libusb `pkg-config libavcodec \ - libavdevice libavfilter libavformat libavutil libpostproc \ - libswresample libswscale --libs` -latomic `pkg-config --libs openssl \ - opencv4 rdkafka++` -lliveMedia -lgroupsock -lBasicUsageEnvironment \ - -lUsageEnvironment -ldarknet -lsensors -CFG_OBJ= -COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ - $(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ - $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ - $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ - $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ - $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicObject.o \ - $(OUTDIR)/basicPosition.o $(OUTDIR)/basicRing.o \ - $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ - $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ - $(OUTDIR)/bosch_rcp.o $(OUTDIR)/clientPort.o \ - $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \ - $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \ - $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \ - $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \ - $(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \ - $(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \ - $(OUTDIR)/deviceNodePresetCamControl.o \ - $(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \ - $(OUTDIR)/deviceNodeStaticCamControl.o $(OUTDIR)/fs_helper.o \ - $(OUTDIR)/FSClient.o $(OUTDIR)/hardwareManager.o \ - $(OUTDIR)/hardwareResource.o \ - $(OUTDIR)/hardwareResourceDryContactProvider.o \ - $(OUTDIR)/hardwareResourceNetworkProvider.o \ - $(OUTDIR)/hardwareResourceSerialProvider.o \ - $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ - $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ - $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ - $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterBubble.o \ - $(OUTDIR)/kernelEventFilterTrain.o $(OUTDIR)/kernelEventFilterYOLO.o \ - $(OUTDIR)/kernelHelperMediaMTX.o $(OUTDIR)/kernelModule.o \ - $(OUTDIR)/kernelModuleAttentionCloud.o $(OUTDIR)/kernelModuleBosch.o \ - $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ - $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ - $(OUTDIR)/kernelModuleModemManager.o \ - $(OUTDIR)/kernelModuleOnvifObserver.o \ - $(OUTDIR)/kernelModuleReportBackupper.o $(OUTDIR)/kernelModuleSSDP.o \ - $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ - $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ - $(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \ - $(OUTDIR)/mojoRemoteClient.o $(OUTDIR)/mysql_class.o \ - $(OUTDIR)/MySQL_dataBinder.o $(OUTDIR)/netClientHandler.o \ - $(OUTDIR)/netServer.o $(OUTDIR)/objectFileLoggingService.o \ - $(OUTDIR)/objectSystemAnchor.o $(OUTDIR)/ponvif.o \ - $(OUTDIR)/protocol.o $(OUTDIR)/protocolARGUS.o \ - $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/protocolBVMS.o \ - $(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolKAFKA.o \ - $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGS3D.o \ - $(OUTDIR)/protocolLGS3D_client.o $(OUTDIR)/protocolONVIF.o \ - $(OUTDIR)/protocolPTZ.o $(OUTDIR)/protocolPTZ_BRCP.o \ - $(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \ - $(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \ - $(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \ - $(OUTDIR)/streamHandler.o $(OUTDIR)/targetPipeLine.o \ - $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \ - $(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \ - $(OUTDIR)/xmlParser.o -OBJ=$(COMMON_OBJ) $(CFG_OBJ) -ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ - $(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ - $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ - $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ - $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ - $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicObject.o \ - $(OUTDIR)/basicPosition.o $(OUTDIR)/basicRing.o \ - $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ - $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ - $(OUTDIR)/bosch_rcp.o $(OUTDIR)/clientPort.o \ - $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \ - $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \ - $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \ - $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \ - $(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \ - $(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \ - $(OUTDIR)/deviceNodePresetCamControl.o \ - $(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \ - $(OUTDIR)/deviceNodeStaticCamControl.o $(OUTDIR)/fs_helper.o \ - $(OUTDIR)/FSClient.o $(OUTDIR)/hardwareManager.o \ - $(OUTDIR)/hardwareResource.o \ - $(OUTDIR)/hardwareResourceDryContactProvider.o \ - $(OUTDIR)/hardwareResourceNetworkProvider.o \ - $(OUTDIR)/hardwareResourceSerialProvider.o \ - $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ - $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ - $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ - $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterBubble.o \ - $(OUTDIR)/kernelEventFilterTrain.o $(OUTDIR)/kernelEventFilterYOLO.o \ - $(OUTDIR)/kernelHelperMediaMTX.o $(OUTDIR)/kernelModule.o \ - $(OUTDIR)/kernelModuleAttentionCloud.o $(OUTDIR)/kernelModuleBosch.o \ - $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ - $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ - $(OUTDIR)/kernelModuleModemManager.o \ - $(OUTDIR)/kernelModuleOnvifObserver.o \ - $(OUTDIR)/kernelModuleReportBackupper.o $(OUTDIR)/kernelModuleSSDP.o \ - $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ - $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ - $(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \ - $(OUTDIR)/mojoRemoteClient.o $(OUTDIR)/mysql_class.o \ - $(OUTDIR)/MySQL_dataBinder.o $(OUTDIR)/netClientHandler.o \ - $(OUTDIR)/netServer.o $(OUTDIR)/objectFileLoggingService.o \ - $(OUTDIR)/objectSystemAnchor.o $(OUTDIR)/ponvif.o \ - $(OUTDIR)/protocol.o $(OUTDIR)/protocolARGUS.o \ - $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/protocolBVMS.o \ - $(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolKAFKA.o \ - $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGS3D.o \ - $(OUTDIR)/protocolLGS3D_client.o $(OUTDIR)/protocolONVIF.o \ - $(OUTDIR)/protocolPTZ.o $(OUTDIR)/protocolPTZ_BRCP.o \ - $(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \ - $(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \ - $(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \ - $(OUTDIR)/streamHandler.o $(OUTDIR)/targetPipeLine.o \ - $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \ - $(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \ - $(OUTDIR)/xmlParser.o -lsqlite3 -lpthread -lmysqlclient -lssl -lcurl \ - -lm -lcrypto -lconfig -lz -lv4l1 -lv4l2 -lhidapi-libusb `pkg-config \ - libavcodec libavdevice libavfilter libavformat libavutil libpostproc \ - libswresample libswscale --libs` -latomic `pkg-config --libs openssl \ - opencv4 rdkafka++` -lliveMedia -lgroupsock -lBasicUsageEnvironment \ - -lUsageEnvironment -ldarknet -lsensors - -COMPILE=g++ -c -x c++ "-D__STDC_CONSTANT_MACROS" "-D_CLIENT_APPLICATION_" "-D_OPENCV_" -O3 -w -Wpointer-arith -std=c++17 -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) - -# Pattern rules -$(OUTDIR)/%.o : ../../lib/components/object/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/json/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/transport/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/protocol/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/App/mojo/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/rfs/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/App/common/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/net/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/media/video/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/hardware/hid/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/alg/lgs/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/bosch_rcp/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/components/base/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/curl/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/sqlite/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/ponvif/%.cpp - $(COMPILE) - -# Build rules -all: $(OUTFILE) - -$(OUTFILE): $(OUTDIR) $(OBJ) - $(LINK) - -$(OUTDIR): - $(MKDIR) -p "$(OUTDIR)" - -# Rebuild this project -rebuild: cleanall - @$(MAKE) -f "$(strip $(MAKEFILE_LIST))" $(MAKEFLAGS) all - -# Clean this project -clean: - $(RM) -f $(OUTFILE) - $(RM) -f $(OBJ) - -# Clean this project and all dependencies -cleanall: clean -endif - -# -# Configuration: LRF_Proxy_ONLY -# -ifeq "$(CFG)" "LRF_Proxy_ONLY" -OUTDIR=LRF_Proxy_ONLY -OUTFILE=$(OUTDIR)/mojo_d -CFG_INC= -CFG_LIB=-lsqlite3 -lpthread -lmysqlclient -lssl -lcurl -lm -lcrypto \ - -lconfig -lz -lhidapi-libusb -latomic `pkg-config --libs openssl \ - rdkafka++` -lgroupsock -CFG_OBJ= -COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ - $(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ - $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ - $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ - $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ - $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicObject.o \ - $(OUTDIR)/basicPosition.o $(OUTDIR)/basicRing.o \ - $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ - $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ - $(OUTDIR)/bosch_rcp.o $(OUTDIR)/clientPort.o \ - $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \ - $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \ - $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \ - $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \ - $(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \ - $(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \ - $(OUTDIR)/deviceNodePresetCamControl.o \ - $(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \ - $(OUTDIR)/deviceNodeStaticCamControl.o $(OUTDIR)/fs_helper.o \ - $(OUTDIR)/FSClient.o $(OUTDIR)/hardwareManager.o \ - $(OUTDIR)/hardwareResource.o \ - $(OUTDIR)/hardwareResourceDryContactProvider.o \ - $(OUTDIR)/hardwareResourceNetworkProvider.o \ - $(OUTDIR)/hardwareResourceSerialProvider.o \ - $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ - $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ - $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ - $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterBubble.o \ - $(OUTDIR)/kernelEventFilterTrain.o $(OUTDIR)/kernelEventFilterYOLO.o \ - $(OUTDIR)/kernelHelperMediaMTX.o $(OUTDIR)/kernelModule.o \ - $(OUTDIR)/kernelModuleAttentionCloud.o $(OUTDIR)/kernelModuleBosch.o \ - $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ - $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ - $(OUTDIR)/kernelModuleModemManager.o \ - $(OUTDIR)/kernelModuleOnvifObserver.o \ - $(OUTDIR)/kernelModuleReportBackupper.o $(OUTDIR)/kernelModuleSSDP.o \ - $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ - $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ - $(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \ - $(OUTDIR)/mojoRemoteClient.o $(OUTDIR)/mysql_class.o \ - $(OUTDIR)/MySQL_dataBinder.o $(OUTDIR)/netClientHandler.o \ - $(OUTDIR)/netServer.o $(OUTDIR)/objectFileLoggingService.o \ - $(OUTDIR)/objectSystemAnchor.o $(OUTDIR)/ponvif.o \ - $(OUTDIR)/protocol.o $(OUTDIR)/protocolARGUS.o \ - $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/protocolBVMS.o \ - $(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolKAFKA.o \ - $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGS3D.o \ - $(OUTDIR)/protocolLGS3D_client.o $(OUTDIR)/protocolONVIF.o \ - $(OUTDIR)/protocolPTZ.o $(OUTDIR)/protocolPTZ_BRCP.o \ - $(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \ - $(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \ - $(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \ - $(OUTDIR)/streamHandler.o $(OUTDIR)/targetPipeLine.o \ - $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \ - $(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \ - $(OUTDIR)/xmlParser.o -OBJ=$(COMMON_OBJ) $(CFG_OBJ) -ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ - $(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ - $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ - $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ - $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ - $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicObject.o \ - $(OUTDIR)/basicPosition.o $(OUTDIR)/basicRing.o \ - $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ - $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ - $(OUTDIR)/bosch_rcp.o $(OUTDIR)/clientPort.o \ - $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \ - $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \ - $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \ - $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \ - $(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \ - $(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \ - $(OUTDIR)/deviceNodePresetCamControl.o \ - $(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \ - $(OUTDIR)/deviceNodeStaticCamControl.o $(OUTDIR)/fs_helper.o \ - $(OUTDIR)/FSClient.o $(OUTDIR)/hardwareManager.o \ - $(OUTDIR)/hardwareResource.o \ - $(OUTDIR)/hardwareResourceDryContactProvider.o \ - $(OUTDIR)/hardwareResourceNetworkProvider.o \ - $(OUTDIR)/hardwareResourceSerialProvider.o \ - $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ - $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ - $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ - $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterBubble.o \ - $(OUTDIR)/kernelEventFilterTrain.o $(OUTDIR)/kernelEventFilterYOLO.o \ - $(OUTDIR)/kernelHelperMediaMTX.o $(OUTDIR)/kernelModule.o \ - $(OUTDIR)/kernelModuleAttentionCloud.o $(OUTDIR)/kernelModuleBosch.o \ - $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ - $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ - $(OUTDIR)/kernelModuleModemManager.o \ - $(OUTDIR)/kernelModuleOnvifObserver.o \ - $(OUTDIR)/kernelModuleReportBackupper.o $(OUTDIR)/kernelModuleSSDP.o \ - $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ - $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ - $(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \ - $(OUTDIR)/mojoRemoteClient.o $(OUTDIR)/mysql_class.o \ - $(OUTDIR)/MySQL_dataBinder.o $(OUTDIR)/netClientHandler.o \ - $(OUTDIR)/netServer.o $(OUTDIR)/objectFileLoggingService.o \ - $(OUTDIR)/objectSystemAnchor.o $(OUTDIR)/ponvif.o \ - $(OUTDIR)/protocol.o $(OUTDIR)/protocolARGUS.o \ - $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/protocolBVMS.o \ - $(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolKAFKA.o \ - $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGS3D.o \ - $(OUTDIR)/protocolLGS3D_client.o $(OUTDIR)/protocolONVIF.o \ - $(OUTDIR)/protocolPTZ.o $(OUTDIR)/protocolPTZ_BRCP.o \ - $(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \ - $(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \ - $(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \ - $(OUTDIR)/streamHandler.o $(OUTDIR)/targetPipeLine.o \ - $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \ - $(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \ - $(OUTDIR)/xmlParser.o -lsqlite3 -lpthread -lmysqlclient -lssl -lcurl \ - -lm -lcrypto -lconfig -lz -lhidapi-libusb -latomic `pkg-config \ - --libs openssl rdkafka++` -lgroupsock - -COMPILE=g++ -c -x c++ "-DDEBUG" "-DLRF_PROXY_ONLY" "-D__STDC_CONSTANT_MACROS" "-D_CLIENT_APPLICATION_" "-D_OPENCV_" -O0 -Wall -pedantic -W -std=c++17 -Wno-write-strings -I../../lib/include -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $< -LINK=g++ -O0 -Wall -pedantic -o "$(OUTFILE)" $(ALL_OBJ) - -# Pattern rules -$(OUTDIR)/%.o : ../../lib/components/object/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/json/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/transport/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/protocol/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/App/mojo/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/rfs/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/App/common/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/net/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/media/video/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/hardware/hid/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/alg/lgs/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/bosch_rcp/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/components/base/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/curl/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/sqlite/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/ponvif/%.cpp - $(COMPILE) - -# Build rules -all: $(OUTFILE) - -$(OUTFILE): $(OUTDIR) $(OBJ) - $(LINK) - -$(OUTDIR): - $(MKDIR) -p "$(OUTDIR)" - -# Rebuild this project -rebuild: cleanall - @$(MAKE) -f "$(strip $(MAKEFILE_LIST))" $(MAKEFLAGS) all - -# Clean this project -clean: - $(RM) -f $(OUTFILE) - $(RM) -f $(OBJ) - -# Clean this project and all dependencies -cleanall: clean -endif - -# -# include dependencies: -# -$(OUTDIR)/base64.o: ../../lib/alg/generic/base64.cpp ../../lib/alg/generic/base64.h -$(OUTDIR)/basicCameraInfo.o: ../../lib/components/base/basicCameraInfo.cpp ../../lib/components/base/basicCameraInfo.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h -$(OUTDIR)/basicDualThread.o: ../../lib/components/base/basicDualThread.cpp ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h -$(OUTDIR)/basicEngine.o: ../../lib/components/base/basicEngine.cpp ../../lib/components/base/basicEngine.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicObject.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicValidatable.h -$(OUTDIR)/basicEvent.o: ../../lib/components/base/basicEvent.cpp ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h -$(OUTDIR)/basicEventHandler.o: ../../lib/components/base/basicEventHandler.cpp ../../lib/components/base/basicEventHandler.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h -$(OUTDIR)/basicEventHeap.o: ../../lib/components/base/basicEventHeap.cpp ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicEventHandler.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h -$(OUTDIR)/basicFunctionality.o: ../../lib/components/base/basicFunctionality.cpp ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/md5.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.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/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/alg/generic/heapDebug.h -$(OUTDIR)/basicLoggingService.o: ../../lib/components/base/basicLoggingService.cpp ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h -$(OUTDIR)/basicObject.o: ../../lib/components/base/basicObject.cpp ../../lib/components/base/basicObject.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicValidatable.h ../../lib/alg/generic/md5.h -$(OUTDIR)/basicPosition.o: ../../lib/components/base/basicPosition.cpp ../../lib/components/base/basicPosition.h -$(OUTDIR)/basicRing.o: ../../lib/components/base/basicRing.cpp ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h -$(OUTDIR)/basicSettings.o: ../../lib/components/base/basicSettings.cpp ../../lib/components/base/basicSettings.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h -$(OUTDIR)/basicSettingsProvider.o: ../../lib/components/base/basicSettingsProvider.cpp ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h -$(OUTDIR)/basicThread.o: ../../lib/components/base/basicThread.cpp ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h -$(OUTDIR)/basicTransport.o: ../../lib/components/base/basicTransport.cpp ../../lib/components/base/basicTransport.h ../../lib/data/protocol/protocol.h -$(OUTDIR)/bosch_rcp.o: ../../lib/data/bosch_rcp/bosch_rcp.cpp ../../lib/data/bosch_rcp/bosch_rcp.h -$(OUTDIR)/clientPort.o: ../../lib/data/net/clientPort.cpp ../../lib/data/net/clientPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h -$(OUTDIR)/cmdNodeConveyor.o: ../../lib/App/common/cmdNodeConveyor.cpp ../../lib/App/common/cmdNodeConveyor.h -$(OUTDIR)/curlRequest.o: ../../lib/data/curl/curlRequest.cpp ../../lib/data/curl/curlRequest.h -$(OUTDIR)/curlRequestsManager.o: ../../lib/data/curl/curlRequestsManager.cpp ../../lib/data/curl/curlRequestsManager.h -$(OUTDIR)/dataBinder.o: ../../lib/App/common/dataBinder.cpp ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h -$(OUTDIR)/dataBinder_ReportAux.o: ../../lib/App/common/dataBinder_ReportAux.cpp ../../lib/App/common/dataBinder_ReportAux.h -$(OUTDIR)/detector.o: ../../lib/alg/lgs/detector.cpp ../../lib/alg/lgs/detector.h ../../lib/components/base/basicObject.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicValidatable.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h -$(OUTDIR)/deviceNode.o: ../../lib/App/common/deviceNode.cpp ../../lib/App/common/deviceNode.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h -$(OUTDIR)/deviceNode2D.o: ../../lib/App/common/deviceNode2D.cpp ../../lib/App/common/deviceNode2D.h ../../lib/App/common/hardwareManager.h ../../lib/App/common/hardwareResourceSerialProvider.h ../../lib/App/common/kernelPrototype.h -$(OUTDIR)/deviceNode3D.o: ../../lib/App/common/deviceNode3D.cpp ../../lib/App/common/deviceNode3D.h ../../lib/App/common/kernelPrototype.h -$(OUTDIR)/deviceNodeCamera.o: ../../lib/App/common/deviceNodeCamera.cpp ../../lib/App/common/deviceNodeCamera.h ../../lib/components/base/basicCameraInfo.h ../../lib/components/object/objectSystemAnchor.h ../../lib/data/protocol/protocolPTZ_ONVIF.h ../../lib/data/protocol/protocolPTZ_PELCO.h ../../lib/data/protocol/protocolPTZ_VISCA.h ../../lib/data/protocol/protocolPTZ_BRCP.h ../../lib/App/mojo/mojoKernel.h ../../lib/alg/generic/md5.h ../../lib/alg/lgs/detector.h ../../lib/components/base/basicObject.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicValidatable.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/mask.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/hardware/soc/general/3DLRF.h ../../lib/gui/gui.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/kernelPrototype.h ../../lib/App/mojo/mojoRemoteClient.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/data/net/clientPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h ../../lib/data/protocol/protocol.h ../../lib/data/protocol/protocolARGUS_DATA.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/kernelHelperMediaMTX.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/hardwareManager.h ../../lib/App/common/hardwareResourceSerialProvider.h ../../lib/App/common/kernelModuleEmbedVideo.h -$(OUTDIR)/deviceNodeEthernet2Serial.o: ../../lib/App/common/deviceNodeEthernet2Serial.cpp ../../lib/App/common/deviceNodeEthernet2Serial.h ../../lib/data/protocol/protocol.h ../../lib/App/common/hardwareManager.h -$(OUTDIR)/deviceNodeFactory.o: ../../lib/App/common/deviceNodeFactory.cpp ../../lib/App/common/deviceNodeFactory.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h ../../lib/App/common/deviceNode2D.h ../../lib/App/common/deviceNode3D.h ../../lib/App/common/deviceNodeEthernet2Serial.h ../../lib/App/common/deviceNodePresetCamControl.h ../../lib/App/common/deviceNodePTZCamControl.h ../../lib/App/common/deviceNodeStaticCamControl.h -$(OUTDIR)/deviceNodePresetCamControl.o: ../../lib/App/common/deviceNodePresetCamControl.cpp ../../lib/App/common/deviceNodePresetCamControl.h ../../lib/App/mojo/mojoKernel.h ../../lib/alg/generic/md5.h ../../lib/alg/lgs/detector.h ../../lib/components/base/basicObject.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicValidatable.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/mask.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/hardware/soc/general/3DLRF.h ../../lib/gui/gui.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/kernelPrototype.h ../../lib/App/mojo/mojoRemoteClient.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/data/net/clientPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h ../../lib/data/protocol/protocol.h ../../lib/data/protocol/protocolARGUS_DATA.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/kernelHelperMediaMTX.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h -$(OUTDIR)/deviceNodePTZCamControl.o: ../../lib/App/common/deviceNodePTZCamControl.cpp ../../lib/App/common/deviceNodePTZCamControl.h ../../lib/App/mojo/mojoKernel.h ../../lib/alg/generic/md5.h ../../lib/alg/lgs/detector.h ../../lib/components/base/basicObject.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicValidatable.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/mask.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/hardware/soc/general/3DLRF.h ../../lib/gui/gui.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/kernelPrototype.h ../../lib/App/mojo/mojoRemoteClient.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/data/net/clientPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h ../../lib/data/protocol/protocol.h ../../lib/data/protocol/protocolARGUS_DATA.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/kernelHelperMediaMTX.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h -$(OUTDIR)/deviceNodeSensor.o: ../../lib/App/common/deviceNodeSensor.cpp ../../lib/App/common/deviceNodeSensor.h ../../lib/components/object/objectSystemAnchor.h ../../lib/App/common/kernelPrototype.h -$(OUTDIR)/deviceNodeStaticCamControl.o: ../../lib/App/common/deviceNodeStaticCamControl.cpp ../../lib/App/common/deviceNodeStaticCamControl.h -$(OUTDIR)/fs_helper.o: ../../lib/data/rfs/fs_helper.cpp ../../lib/data/rfs/fs_helper.h -$(OUTDIR)/FSClient.o: ../../lib/data/rfs/FSClient.cpp ../../lib/data/rfs/FSClient.h -$(OUTDIR)/hardwareManager.o: ../../lib/App/common/hardwareManager.cpp ../../lib/App/common/hardwareManager.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h ../../lib/App/common/hardwareResourceNetworkProvider.h ../../lib/App/common/hardwareResourceSerialProvider.h ../../lib/App/common/hardwareResourceVideoProvider.h -$(OUTDIR)/hardwareResource.o: ../../lib/App/common/hardwareResource.cpp ../../lib/App/common/hardwareResource.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h -$(OUTDIR)/hardwareResourceDryContactProvider.o: ../../lib/App/common/hardwareResourceDryContactProvider.cpp ../../lib/App/common/hardwareResourceDryContactProvider.h -$(OUTDIR)/hardwareResourceNetworkProvider.o: ../../lib/App/common/hardwareResourceNetworkProvider.cpp ../../lib/App/common/hardwareResourceNetworkProvider.h -$(OUTDIR)/hardwareResourceSerialProvider.o: ../../lib/App/common/hardwareResourceSerialProvider.cpp ../../lib/App/common/hardwareResourceSerialProvider.h -$(OUTDIR)/hardwareResourceVideoProvider.o: ../../lib/App/common/hardwareResourceVideoProvider.cpp ../../lib/App/common/hardwareResourceVideoProvider.h -$(OUTDIR)/heapDebug.o: ../../lib/alg/generic/heapDebug.cpp ../../lib/alg/generic/heapDebug.h -$(OUTDIR)/hid_dc.o: ../../lib/hardware/hid/hid_dc.cpp -$(OUTDIR)/json_reader.o: ../../lib/data/json/json_reader.cpp ../../lib/data/json/json_tool.h -$(OUTDIR)/json_value.o: ../../lib/data/json/json_value.cpp ../../lib/data/json/json_valueiterator.inl -$(OUTDIR)/json_writer.o: ../../lib/data/json/json_writer.cpp ../../lib/data/json/json_tool.h -$(OUTDIR)/kernelEventFilter.o: ../../lib/App/common/kernelEventFilter.cpp ../../lib/App/common/kernelEventFilter.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h -$(OUTDIR)/kernelEventFilterAPF.o: ../../lib/App/common/kernelEventFilterAPF.cpp ../../lib/App/common/kernelEventFilterAPF.h -$(OUTDIR)/kernelEventFilterBubble.o: ../../lib/App/common/kernelEventFilterBubble.cpp ../../lib/App/common/kernelEventFilterBubble.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/kernelEventFilter.h ../../lib/App/common/kernelPrototype.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/object/objectSystemAnchor.h -$(OUTDIR)/kernelEventFilterTrain.o: ../../lib/App/common/kernelEventFilterTrain.cpp ../../lib/App/common/kernelEventFilterTrain.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/App/common/deviceNodeFactory.h -$(OUTDIR)/kernelEventFilterYOLO.o: ../../lib/App/common/kernelEventFilterYOLO.cpp ../../lib/App/common/kernelEventFilterYOLO.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/kernelEventFilter.h ../../lib/App/common/kernelPrototype.h -$(OUTDIR)/kernelHelperMediaMTX.o: ../../lib/App/common/kernelHelperMediaMTX.cpp ../../lib/App/common/kernelHelperMediaMTX.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/SQLite_dataBinder.h -$(OUTDIR)/kernelModule.o: ../../lib/App/common/kernelModule.cpp ../../lib/App/common/kernelModule.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h -$(OUTDIR)/kernelModuleAttentionCloud.o: ../../lib/App/common/kernelModuleAttentionCloud.cpp ../../lib/App/common/kernelModuleAttentionCloud.h ../../lib/App/common/kernelModule.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/deviceNodeFactory.h ../../lib/App/common/deviceNodeCamera.h -$(OUTDIR)/kernelModuleBosch.o: ../../lib/App/common/kernelModuleBosch.cpp ../../lib/App/common/kernelModuleBosch.h -$(OUTDIR)/kernelModuleEmbedVideo.o: ../../lib/App/common/kernelModuleEmbedVideo.cpp ../../lib/App/common/kernelModuleEmbedVideo.h ../../lib/App/common/streamHandler.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/App/common/kernelModule.h ../../lib/components/base/basicMediaDestination.h ../../lib/components/base/basicMediaSource.h ../../lib/App/common/deviceNodeCamera.h ../../lib/App/common/deviceNodeFactory.h -$(OUTDIR)/kernelModuleFactory.o: ../../lib/App/common/kernelModuleFactory.cpp ../../lib/App/common/kernelModuleFactory.h ../../lib/App/common/kernelModuleEmbedVideo.h ../../lib/App/common/kernelModuleFlyHunter.h ../../lib/App/common/kernelModuleKafka.h ../../lib/App/common/kernelModuleModemManager.h ../../lib/App/common/kernelModuleOnvifObserver.h ../../lib/App/common/kernelModuleSSDP.h ../../lib/App/common/kernelModuleUSBRelay.h ../../lib/App/common/kernelModuleBosch.h ../../lib/App/common/kernelModuleAttentionCloud.h ../../lib/App/common/kernelModule.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h -$(OUTDIR)/kernelModuleFlyHunter.o: ../../lib/App/common/kernelModuleFlyHunter.cpp ../../lib/App/common/kernelModuleFlyHunter.h -$(OUTDIR)/kernelModuleKafka.o: ../../lib/App/common/kernelModuleKafka.cpp ../../lib/App/common/kernelModuleKafka.h -$(OUTDIR)/kernelModuleModemManager.o: ../../lib/App/common/kernelModuleModemManager.cpp ../../lib/App/common/kernelModuleModemManager.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h -$(OUTDIR)/kernelModuleOnvifObserver.o: ../../lib/App/common/kernelModuleOnvifObserver.cpp ../../lib/App/common/kernelModuleOnvifObserver.h ../../lib/App/common/hardwareManager.h ../../lib/App/common/hardwareResourceNetworkProvider.h -$(OUTDIR)/kernelModuleReportBackupper.o: ../../lib/App/common/kernelModuleReportBackupper.cpp ../../lib/App/common/kernelModuleReportBackupper.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h -$(OUTDIR)/kernelModuleSSDP.o: ../../lib/App/common/kernelModuleSSDP.cpp ../../lib/App/common/kernelModuleSSDP.h -$(OUTDIR)/kernelModuleUSBRelay.o: ../../lib/App/common/kernelModuleUSBRelay.cpp ../../lib/App/common/kernelModuleUSBRelay.h -$(OUTDIR)/kernelPrototype.o: ../../lib/App/common/kernelPrototype.cpp ../../lib/App/common/kernelPrototype.h -$(OUTDIR)/libzip.o: ../../lib/alg/generic/libzip.cpp ../../lib/alg/generic/libzip.h -$(OUTDIR)/mask.o: ../../lib/alg/lgs/mask.cpp ../../lib/alg/lgs/mask.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/hardware/soc/general/3DLRF.h ../../lib/gui/gui.h -$(OUTDIR)/md5.o: ../../lib/alg/generic/md5.cpp ../../lib/alg/generic/md5.h -$(OUTDIR)/mojoBackend.o: ../../lib/App/mojo/mojoBackend.cpp ../../lib/App/mojo/mojoBackend.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMemoryOperation.h ../../lib/components/base/basicSettings.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/object/objectFileLoggingService.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/App/mojo/mojoKernel.h ../../lib/alg/generic/md5.h ../../lib/alg/lgs/detector.h ../../lib/components/base/basicObject.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicValidatable.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/mask.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/hardware/soc/general/3DLRF.h ../../lib/gui/gui.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/kernelPrototype.h ../../lib/App/mojo/mojoRemoteClient.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/data/net/clientPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h ../../lib/data/protocol/protocol.h ../../lib/data/protocol/protocolARGUS_DATA.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/kernelHelperMediaMTX.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h -$(OUTDIR)/mojoKernel.o: ../../lib/App/mojo/mojoKernel.cpp ../../lib/App/mojo/mojoKernel.h ../../lib/alg/generic/md5.h ../../lib/alg/lgs/detector.h ../../lib/components/base/basicObject.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicValidatable.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/mask.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/hardware/soc/general/3DLRF.h ../../lib/gui/gui.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/kernelPrototype.h ../../lib/App/mojo/mojoRemoteClient.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/data/net/clientPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h ../../lib/data/protocol/protocol.h ../../lib/data/protocol/protocolARGUS_DATA.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/kernelHelperMediaMTX.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/kernelEventFilterAPF.h ../../lib/App/common/kernelEventFilterBubble.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/kernelEventFilter.h ../../lib/App/common/kernelPrototype.h ../../lib/App/common/kernelEventFilterTrain.h ../../lib/App/common/kernelModuleEmbedVideo.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h ../../lib/App/common/deviceNode2D.h -$(OUTDIR)/mojoRemoteClient.o: ../../lib/App/mojo/mojoRemoteClient.cpp ../../lib/App/mojo/mojoRemoteClient.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/data/net/clientPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h ../../lib/data/protocol/protocol.h ../../lib/data/protocol/protocolARGUS_DATA.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/mojo/mojoKernel.h ../../lib/alg/generic/md5.h ../../lib/alg/lgs/detector.h ../../lib/components/base/basicObject.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicValidatable.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/mask.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/hardware/soc/general/3DLRF.h ../../lib/gui/gui.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/kernelPrototype.h ../../lib/App/mojo/mojoRemoteClient.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/data/net/clientPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h ../../lib/data/protocol/protocol.h ../../lib/data/protocol/protocolARGUS_DATA.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/kernelHelperMediaMTX.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/deviceNodeCamera.h ../../lib/App/common/deviceNodeFactory.h ../../lib/App/common/deviceNodeSensor.h -$(OUTDIR)/mysql_class.o: ../../lib/data/mysql/mysql_class.cpp ../../lib/data/mysql/mysql_class.h -$(OUTDIR)/MySQL_dataBinder.o: ../../lib/App/common/MySQL_dataBinder.cpp ../../lib/App/common/MySQL_dataBinder.h -$(OUTDIR)/netClientHandler.o: ../../lib/data/net/netClientHandler.cpp ../../lib/data/net/netClientHandler.h ../../lib/data/protocol/protocol.h ../../lib/components/base/basicEventHandler.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/data/net/netServiceEngine.h ../../lib/data/net/serverPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h -$(OUTDIR)/netServer.o: ../../lib/data/net/netServer.cpp ../../lib/data/net/netServer.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/data/protocol/protocol.h ../../lib/data/net/netClientHandler.h ../../lib/data/protocol/protocol.h ../../lib/components/base/basicEventHandler.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/data/net/netServiceEngine.h ../../lib/data/net/serverPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h ../../lib/data/net/netServiceEngine.h ../../lib/data/net/netClientHandler.h ../../lib/data/protocol/protocol.h ../../lib/components/base/basicEventHandler.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/data/net/netServiceEngine.h ../../lib/data/net/serverPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h -$(OUTDIR)/objectFileLoggingService.o: ../../lib/components/object/objectFileLoggingService.cpp ../../lib/components/object/objectFileLoggingService.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h -$(OUTDIR)/objectSystemAnchor.o: ../../lib/components/object/objectSystemAnchor.cpp ../../lib/components/object/objectSystemAnchor.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h -$(OUTDIR)/ponvif.o: ../../lib/data/ponvif/ponvif.cpp ../../lib/data/ponvif/ponvif.h -$(OUTDIR)/protocol.o: ../../lib/data/protocol/protocol.cpp ../../lib/data/protocol/protocol.h -$(OUTDIR)/protocolARGUS.o: ../../lib/data/protocol/protocolARGUS.cpp ../../lib/data/protocol/protocolARGUS.h -$(OUTDIR)/protocolARGUS_DATA.o: ../../lib/data/protocol/protocolARGUS_DATA.cpp ../../lib/data/protocol/protocolARGUS_DATA.h -$(OUTDIR)/protocolBVMS.o: ../../lib/data/protocol/protocolBVMS.cpp ../../lib/data/protocol/protocolBVMS.h ../../lib/alg/generic/md5.h -$(OUTDIR)/protocolHTTP.o: ../../lib/data/protocol/protocolHTTP.cpp ../../lib/data/protocol/protocolHTTP.h -$(OUTDIR)/protocolKAFKA.o: ../../lib/data/protocol/protocolKAFKA.cpp ../../lib/data/protocol/protocolKAFKA.h ../../lib/alg/generic/md5.h ../../lib/data/json/json_tool.h -$(OUTDIR)/protocolLGS2D.o: ../../lib/data/protocol/protocolLGS2D.cpp ../../lib/data/protocol/protocolLGS2D.h -$(OUTDIR)/protocolLGS3D.o: ../../lib/data/protocol/protocolLGS3D.cpp ../../lib/data/protocol/protocolLGS3D.h -$(OUTDIR)/protocolLGS3D_client.o: ../../lib/data/protocol/protocolLGS3D_client.cpp ../../lib/data/protocol/protocolLGS3D_client.h -$(OUTDIR)/protocolONVIF.o: ../../lib/data/protocol/protocolONVIF.cpp ../../lib/data/protocol/protocolONVIF.h -$(OUTDIR)/protocolPTZ.o: ../../lib/data/protocol/protocolPTZ.cpp ../../lib/data/protocol/protocolPTZ.h -$(OUTDIR)/protocolPTZ_BRCP.o: ../../lib/data/protocol/protocolPTZ_BRCP.cpp ../../lib/data/protocol/protocolPTZ_BRCP.h ../../lib/hardware/uart/serialPort.h -$(OUTDIR)/protocolPTZ_ONVIF.o: ../../lib/data/protocol/protocolPTZ_ONVIF.cpp ../../lib/data/protocol/protocolPTZ_ONVIF.h ../../lib/hardware/uart/serialPort.h -$(OUTDIR)/protocolPTZ_PELCO.o: ../../lib/data/protocol/protocolPTZ_PELCO.cpp ../../lib/data/protocol/protocolPTZ_PELCO.h -$(OUTDIR)/protocolPTZ_VISCA.o: ../../lib/data/protocol/protocolPTZ_VISCA.cpp ../../lib/data/protocol/protocolPTZ_VISCA.h -$(OUTDIR)/serverPort.o: ../../lib/data/net/serverPort.cpp ../../lib/data/net/serverPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h -$(OUTDIR)/sqlite_class.o: ../../lib/data/sqlite/sqlite_class.cpp ../../lib/data/sqlite/sqlite_class.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h -$(OUTDIR)/SQLite_dataBinder.o: ../../lib/App/common/SQLite_dataBinder.cpp ../../lib/App/common/SQLite_dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h -$(OUTDIR)/streamHandler.o: ../../lib/App/common/streamHandler.cpp ../../lib/App/common/streamHandler.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/App/common/kernelModule.h ../../lib/components/base/basicMediaDestination.h ../../lib/components/base/basicMediaSource.h -$(OUTDIR)/targetPipeLine.o: ../../lib/App/common/targetPipeLine.cpp ../../lib/App/common/targetPipeLine.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/kernelEventFilter.h ../../lib/App/common/kernelPrototype.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h -$(OUTDIR)/Transform.o: ../../lib/alg/generic/Transform.cpp ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h -$(OUTDIR)/transportSocket.o: ../../lib/data/transport/transportSocket.cpp ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h ../../lib/data/protocol/protocol.h -$(OUTDIR)/utm.o: ../../lib/alg/generic/utm.cpp ../../lib/alg/generic/utm.h -$(OUTDIR)/videoAVLIBSource.o: ../../lib/data/media/video/videoAVLIBSource.cpp ../../lib/data/media/video/videoAVLIBSource.h -$(OUTDIR)/videoLive555AVLibSource.o: ../../lib/data/media/video/videoLive555AVLibSource.cpp ../../lib/data/media/video/videoLive555AVLibSource.h -$(OUTDIR)/xmlParser.o: ../../lib/data/protocol/xmlParser.cpp ../../lib/data/protocol/xmlParser.h +# SlickEdit generated file. Do not edit this file except in designated areas. + +# Make command to use for dependencies +MAKE=make +RM=rm +MKDIR=mkdir + +# -----Begin user-editable area----- + +# Live view (WebRTC / WHEP) and recording of kernelModuleEmbedVideo: MediaMtx library + libdatachannel +# (>= 0.20, default /usr/local). Other locations: make DATACHANNEL_CFLAGS=-I... DATACHANNEL_LIBS="-L... -ldatachannel" +DATACHANNEL_CFLAGS ?= +DATACHANNEL_LIBS ?= -ldatachannel + +# -----End user-editable area----- + +# If no configuration is specified, "Debug" will be used +ifndef CFG +CFG=Debug +endif + +# +# Configuration: Debug +# +ifeq "$(CFG)" "Debug" +OUTDIR=Debug +OUTFILE=$(OUTDIR)/mojo_d +CFG_INC= +CFG_LIB=-lsqlite3 -lpthread -lmysqlclient -lssl -lcurl -lm -lcrypto \ + -lconfig -lz -lv4l1 -lv4l2 -lhidapi-libusb `pkg-config libavcodec \ + libavdevice libavfilter libavformat libavutil libpostproc \ + libswresample libswscale --libs` -latomic `pkg-config --libs openssl \ + opencv4 rdkafka++` -L/usr/lib -lrdkafka++ -lrdkafka -lwiringx \ + -lliveMedia -lgroupsock -lBasicUsageEnvironment -lUsageEnvironment \ + -ldarknet +CFG_OBJ= +COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ + $(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ + $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ + $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ + $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ + $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicObject.o \ + $(OUTDIR)/basicPosition.o $(OUTDIR)/basicRing.o \ + $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ + $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ + $(OUTDIR)/bosch_rcp.o $(OUTDIR)/clientPort.o \ + $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \ + $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \ + $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \ + $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \ + $(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \ + $(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \ + $(OUTDIR)/deviceNodePresetCamControl.o \ + $(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \ + $(OUTDIR)/deviceNodeStaticCamControl.o $(OUTDIR)/fs_helper.o \ + $(OUTDIR)/FSClient.o $(OUTDIR)/hardwareManager.o \ + $(OUTDIR)/hardwareResource.o \ + $(OUTDIR)/hardwareResourceDryContactProvider.o \ + $(OUTDIR)/hardwareResourceNetworkProvider.o \ + $(OUTDIR)/hardwareResourceSerialProvider.o \ + $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ + $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ + $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ + $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterBubble.o \ + $(OUTDIR)/kernelEventFilterTrain.o $(OUTDIR)/kernelEventFilterYOLO.o \ + $(OUTDIR)/kernelHelperMediaMTX.o $(OUTDIR)/kernelModule.o \ + $(OUTDIR)/kernelModuleAttentionCloud.o $(OUTDIR)/kernelModuleBosch.o \ + $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ + $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ + $(OUTDIR)/kernelModuleModemManager.o \ + $(OUTDIR)/kernelModuleOnvifObserver.o \ + $(OUTDIR)/kernelModuleReportBackupper.o $(OUTDIR)/kernelModuleSSDP.o \ + $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ + $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ + $(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \ + $(OUTDIR)/mojoRemoteClient.o $(OUTDIR)/mysql_class.o \ + $(OUTDIR)/MySQL_dataBinder.o $(OUTDIR)/netClientHandler.o \ + $(OUTDIR)/netServer.o $(OUTDIR)/objectFileLoggingService.o \ + $(OUTDIR)/objectSystemAnchor.o $(OUTDIR)/ponvif.o \ + $(OUTDIR)/protocol.o $(OUTDIR)/protocolARGUS.o \ + $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/protocolBVMS.o \ + $(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolKAFKA.o \ + $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGS3D.o \ + $(OUTDIR)/protocolLGS3D_client.o $(OUTDIR)/protocolONVIF.o \ + $(OUTDIR)/protocolPTZ.o $(OUTDIR)/protocolPTZ_BRCP.o \ + $(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \ + $(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \ + $(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \ + $(OUTDIR)/streamHandler.o $(OUTDIR)/targetPipeLine.o \ + $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \ + $(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \ + $(OUTDIR)/xmlParser.o +OBJ=$(COMMON_OBJ) $(CFG_OBJ) +ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ + $(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ + $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ + $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ + $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ + $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicObject.o \ + $(OUTDIR)/basicPosition.o $(OUTDIR)/basicRing.o \ + $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ + $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ + $(OUTDIR)/bosch_rcp.o $(OUTDIR)/clientPort.o \ + $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \ + $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \ + $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \ + $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \ + $(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \ + $(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \ + $(OUTDIR)/deviceNodePresetCamControl.o \ + $(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \ + $(OUTDIR)/deviceNodeStaticCamControl.o $(OUTDIR)/fs_helper.o \ + $(OUTDIR)/FSClient.o $(OUTDIR)/hardwareManager.o \ + $(OUTDIR)/hardwareResource.o \ + $(OUTDIR)/hardwareResourceDryContactProvider.o \ + $(OUTDIR)/hardwareResourceNetworkProvider.o \ + $(OUTDIR)/hardwareResourceSerialProvider.o \ + $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ + $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ + $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ + $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterBubble.o \ + $(OUTDIR)/kernelEventFilterTrain.o $(OUTDIR)/kernelEventFilterYOLO.o \ + $(OUTDIR)/kernelHelperMediaMTX.o $(OUTDIR)/kernelModule.o \ + $(OUTDIR)/kernelModuleAttentionCloud.o $(OUTDIR)/kernelModuleBosch.o \ + $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ + $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ + $(OUTDIR)/kernelModuleModemManager.o \ + $(OUTDIR)/kernelModuleOnvifObserver.o \ + $(OUTDIR)/kernelModuleReportBackupper.o $(OUTDIR)/kernelModuleSSDP.o \ + $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ + $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ + $(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \ + $(OUTDIR)/mojoRemoteClient.o $(OUTDIR)/mysql_class.o \ + $(OUTDIR)/MySQL_dataBinder.o $(OUTDIR)/netClientHandler.o \ + $(OUTDIR)/netServer.o $(OUTDIR)/objectFileLoggingService.o \ + $(OUTDIR)/objectSystemAnchor.o $(OUTDIR)/ponvif.o \ + $(OUTDIR)/protocol.o $(OUTDIR)/protocolARGUS.o \ + $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/protocolBVMS.o \ + $(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolKAFKA.o \ + $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGS3D.o \ + $(OUTDIR)/protocolLGS3D_client.o $(OUTDIR)/protocolONVIF.o \ + $(OUTDIR)/protocolPTZ.o $(OUTDIR)/protocolPTZ_BRCP.o \ + $(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \ + $(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \ + $(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \ + $(OUTDIR)/streamHandler.o $(OUTDIR)/targetPipeLine.o \ + $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \ + $(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \ + $(OUTDIR)/xmlParser.o -lsqlite3 -lpthread -lmysqlclient -lssl -lcurl \ + -lm -lcrypto -lconfig -lz -lv4l1 -lv4l2 -lhidapi-libusb `pkg-config \ + libavcodec libavdevice libavfilter libavformat libavutil libpostproc \ + libswresample libswscale --libs` -latomic `pkg-config --libs openssl \ + opencv4 rdkafka++` -L/usr/lib -lrdkafka++ -lrdkafka -lwiringx \ + -lliveMedia -lgroupsock -lBasicUsageEnvironment -lUsageEnvironment \ + -ldarknet + +COMPILE=g++ -c -x c++ "-DDEBUG" "-D__STDC_CONSTANT_MACROS__" "-D_CLIENT_APPLICATION_" "-D_OPENCV_" "-DRASPI_HARDWARE" -O0 -w -Wpointer-arith -std=c++17 -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) + +# Pattern rules +$(OUTDIR)/%.o : ../../lib/components/object/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/json/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/transport/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/protocol/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/App/mojo/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/rfs/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/App/common/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/net/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/media/video/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/hardware/hid/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/alg/lgs/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/bosch_rcp/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/components/base/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/curl/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/sqlite/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/ponvif/%.cpp + $(COMPILE) + +# Build rules +all: $(OUTFILE) + +$(OUTFILE): $(OUTDIR) $(OBJ) + $(LINK) + +$(OUTDIR): + $(MKDIR) -p "$(OUTDIR)" + +# Rebuild this project +rebuild: cleanall + @$(MAKE) -f "$(strip $(MAKEFILE_LIST))" $(MAKEFLAGS) all + +# Clean this project +clean: + $(RM) -f $(OUTFILE) + $(RM) -f $(OBJ) + +# Clean this project and all dependencies +cleanall: clean +endif + +# +# Configuration: Release +# +ifeq "$(CFG)" "Release" +OUTDIR=Release +OUTFILE=$(OUTDIR)/mojo +CFG_INC= +CFG_LIB=-lconfig -lpthread -lmysqlclient -lelf -lcurses -lcdk -lcurl \ + `pkg-config --libs rdkafka++` -L/usr/lib -lrdkafka++ -lrdkafka \ + -lwiringx -lsqlite3 -ldarknet -lsensors +CFG_OBJ= +COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ + $(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ + $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ + $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ + $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ + $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicObject.o \ + $(OUTDIR)/basicPosition.o $(OUTDIR)/basicRing.o \ + $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ + $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ + $(OUTDIR)/bosch_rcp.o $(OUTDIR)/clientPort.o \ + $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \ + $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \ + $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \ + $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \ + $(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \ + $(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \ + $(OUTDIR)/deviceNodePresetCamControl.o \ + $(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \ + $(OUTDIR)/deviceNodeStaticCamControl.o $(OUTDIR)/fs_helper.o \ + $(OUTDIR)/FSClient.o $(OUTDIR)/hardwareManager.o \ + $(OUTDIR)/hardwareResource.o \ + $(OUTDIR)/hardwareResourceDryContactProvider.o \ + $(OUTDIR)/hardwareResourceNetworkProvider.o \ + $(OUTDIR)/hardwareResourceSerialProvider.o \ + $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ + $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ + $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ + $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterBubble.o \ + $(OUTDIR)/kernelEventFilterTrain.o $(OUTDIR)/kernelEventFilterYOLO.o \ + $(OUTDIR)/kernelHelperMediaMTX.o $(OUTDIR)/kernelModule.o \ + $(OUTDIR)/kernelModuleAttentionCloud.o $(OUTDIR)/kernelModuleBosch.o \ + $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ + $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ + $(OUTDIR)/kernelModuleModemManager.o \ + $(OUTDIR)/kernelModuleOnvifObserver.o \ + $(OUTDIR)/kernelModuleReportBackupper.o $(OUTDIR)/kernelModuleSSDP.o \ + $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ + $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ + $(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \ + $(OUTDIR)/mojoRemoteClient.o $(OUTDIR)/mysql_class.o \ + $(OUTDIR)/MySQL_dataBinder.o $(OUTDIR)/netClientHandler.o \ + $(OUTDIR)/netServer.o $(OUTDIR)/objectFileLoggingService.o \ + $(OUTDIR)/objectSystemAnchor.o $(OUTDIR)/ponvif.o \ + $(OUTDIR)/protocol.o $(OUTDIR)/protocolARGUS.o \ + $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/protocolBVMS.o \ + $(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolKAFKA.o \ + $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGS3D.o \ + $(OUTDIR)/protocolLGS3D_client.o $(OUTDIR)/protocolONVIF.o \ + $(OUTDIR)/protocolPTZ.o $(OUTDIR)/protocolPTZ_BRCP.o \ + $(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \ + $(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \ + $(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \ + $(OUTDIR)/streamHandler.o $(OUTDIR)/targetPipeLine.o \ + $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \ + $(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \ + $(OUTDIR)/xmlParser.o +OBJ=$(COMMON_OBJ) $(CFG_OBJ) +ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ + $(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ + $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ + $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ + $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ + $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicObject.o \ + $(OUTDIR)/basicPosition.o $(OUTDIR)/basicRing.o \ + $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ + $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ + $(OUTDIR)/bosch_rcp.o $(OUTDIR)/clientPort.o \ + $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \ + $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \ + $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \ + $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \ + $(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \ + $(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \ + $(OUTDIR)/deviceNodePresetCamControl.o \ + $(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \ + $(OUTDIR)/deviceNodeStaticCamControl.o $(OUTDIR)/fs_helper.o \ + $(OUTDIR)/FSClient.o $(OUTDIR)/hardwareManager.o \ + $(OUTDIR)/hardwareResource.o \ + $(OUTDIR)/hardwareResourceDryContactProvider.o \ + $(OUTDIR)/hardwareResourceNetworkProvider.o \ + $(OUTDIR)/hardwareResourceSerialProvider.o \ + $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ + $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ + $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ + $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterBubble.o \ + $(OUTDIR)/kernelEventFilterTrain.o $(OUTDIR)/kernelEventFilterYOLO.o \ + $(OUTDIR)/kernelHelperMediaMTX.o $(OUTDIR)/kernelModule.o \ + $(OUTDIR)/kernelModuleAttentionCloud.o $(OUTDIR)/kernelModuleBosch.o \ + $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ + $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ + $(OUTDIR)/kernelModuleModemManager.o \ + $(OUTDIR)/kernelModuleOnvifObserver.o \ + $(OUTDIR)/kernelModuleReportBackupper.o $(OUTDIR)/kernelModuleSSDP.o \ + $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ + $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ + $(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \ + $(OUTDIR)/mojoRemoteClient.o $(OUTDIR)/mysql_class.o \ + $(OUTDIR)/MySQL_dataBinder.o $(OUTDIR)/netClientHandler.o \ + $(OUTDIR)/netServer.o $(OUTDIR)/objectFileLoggingService.o \ + $(OUTDIR)/objectSystemAnchor.o $(OUTDIR)/ponvif.o \ + $(OUTDIR)/protocol.o $(OUTDIR)/protocolARGUS.o \ + $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/protocolBVMS.o \ + $(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolKAFKA.o \ + $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGS3D.o \ + $(OUTDIR)/protocolLGS3D_client.o $(OUTDIR)/protocolONVIF.o \ + $(OUTDIR)/protocolPTZ.o $(OUTDIR)/protocolPTZ_BRCP.o \ + $(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \ + $(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \ + $(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \ + $(OUTDIR)/streamHandler.o $(OUTDIR)/targetPipeLine.o \ + $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \ + $(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \ + $(OUTDIR)/xmlParser.o -lconfig -lpthread -lmysqlclient -lelf \ + -lcurses -lcdk -lcurl `pkg-config --libs rdkafka++` -L/usr/lib \ + -lrdkafka++ -lrdkafka -lwiringx -lsqlite3 -ldarknet -lsensors + +COMPILE=g++ -c -x c++ "-DSLIM_KERNEL" "-D_THREAD_SAFE" "-D_BSD_SOURCE" "-D_REENTRANT" -O3 -w -Wpointer-arith -std=gnu++17 -I../../lib/include -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $< +LINK=g++ -O3 -w -s -o "$(OUTFILE)" $(ALL_OBJ) + +# Pattern rules +$(OUTDIR)/%.o : ../../lib/components/object/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/json/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/transport/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/protocol/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/App/mojo/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/rfs/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/App/common/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/net/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/media/video/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/hardware/hid/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/alg/lgs/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/bosch_rcp/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/components/base/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/curl/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/sqlite/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/ponvif/%.cpp + $(COMPILE) + +# Build rules +all: $(OUTFILE) + +$(OUTFILE): $(OUTDIR) $(OBJ) + $(LINK) + +$(OUTDIR): + $(MKDIR) -p "$(OUTDIR)" + +# Rebuild this project +rebuild: cleanall + @$(MAKE) -f "$(strip $(MAKEFILE_LIST))" $(MAKEFLAGS) all + +# Clean this project +clean: + $(RM) -f $(OUTFILE) + $(RM) -f $(OBJ) + +# Clean this project and all dependencies +cleanall: clean +endif + +# +# Configuration: Debug86 +# +ifeq "$(CFG)" "Debug86" +OUTDIR=Debug86 +OUTFILE=$(OUTDIR)/mojo_d +CFG_INC= +CFG_LIB=-lsqlite3 -lpthread -lmysqlclient -lssl -lcurl -lm -lcrypto \ + -lconfig -lz -lv4l1 -lv4l2 -lhidapi-libusb `pkg-config libavcodec \ + libavdevice libavfilter libavformat libavutil libpostproc \ + libswresample libswscale --libs` -latomic `pkg-config --libs openssl \ + opencv4 rdkafka++` -lliveMedia -lgroupsock -lBasicUsageEnvironment \ + -lUsageEnvironment -ldarknet -lsensors +CFG_OBJ= +COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ + $(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ + $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ + $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ + $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ + $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicObject.o \ + $(OUTDIR)/basicPosition.o $(OUTDIR)/basicRing.o \ + $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ + $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ + $(OUTDIR)/bosch_rcp.o $(OUTDIR)/clientPort.o \ + $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \ + $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \ + $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \ + $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \ + $(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \ + $(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \ + $(OUTDIR)/deviceNodePresetCamControl.o \ + $(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \ + $(OUTDIR)/deviceNodeStaticCamControl.o $(OUTDIR)/fs_helper.o \ + $(OUTDIR)/FSClient.o $(OUTDIR)/hardwareManager.o \ + $(OUTDIR)/hardwareResource.o \ + $(OUTDIR)/hardwareResourceDryContactProvider.o \ + $(OUTDIR)/hardwareResourceNetworkProvider.o \ + $(OUTDIR)/hardwareResourceSerialProvider.o \ + $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ + $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ + $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ + $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterBubble.o \ + $(OUTDIR)/kernelEventFilterTrain.o $(OUTDIR)/kernelEventFilterYOLO.o \ + $(OUTDIR)/kernelHelperMediaMTX.o $(OUTDIR)/kernelModule.o \ + $(OUTDIR)/kernelModuleAttentionCloud.o $(OUTDIR)/kernelModuleBosch.o \ + $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ + $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ + $(OUTDIR)/kernelModuleModemManager.o \ + $(OUTDIR)/kernelModuleOnvifObserver.o \ + $(OUTDIR)/kernelModuleReportBackupper.o $(OUTDIR)/kernelModuleSSDP.o \ + $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ + $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ + $(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \ + $(OUTDIR)/mojoRemoteClient.o $(OUTDIR)/mysql_class.o \ + $(OUTDIR)/MySQL_dataBinder.o $(OUTDIR)/netClientHandler.o \ + $(OUTDIR)/netServer.o $(OUTDIR)/objectFileLoggingService.o \ + $(OUTDIR)/objectSystemAnchor.o $(OUTDIR)/ponvif.o \ + $(OUTDIR)/protocol.o $(OUTDIR)/protocolARGUS.o \ + $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/protocolBVMS.o \ + $(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolKAFKA.o \ + $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGS3D.o \ + $(OUTDIR)/protocolLGS3D_client.o $(OUTDIR)/protocolONVIF.o \ + $(OUTDIR)/protocolPTZ.o $(OUTDIR)/protocolPTZ_BRCP.o \ + $(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \ + $(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \ + $(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \ + $(OUTDIR)/streamHandler.o $(OUTDIR)/targetPipeLine.o \ + $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \ + $(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \ + $(OUTDIR)/xmlParser.o +OBJ=$(COMMON_OBJ) $(CFG_OBJ) +ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ + $(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ + $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ + $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ + $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ + $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicObject.o \ + $(OUTDIR)/basicPosition.o $(OUTDIR)/basicRing.o \ + $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ + $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ + $(OUTDIR)/bosch_rcp.o $(OUTDIR)/clientPort.o \ + $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \ + $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \ + $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \ + $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \ + $(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \ + $(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \ + $(OUTDIR)/deviceNodePresetCamControl.o \ + $(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \ + $(OUTDIR)/deviceNodeStaticCamControl.o $(OUTDIR)/fs_helper.o \ + $(OUTDIR)/FSClient.o $(OUTDIR)/hardwareManager.o \ + $(OUTDIR)/hardwareResource.o \ + $(OUTDIR)/hardwareResourceDryContactProvider.o \ + $(OUTDIR)/hardwareResourceNetworkProvider.o \ + $(OUTDIR)/hardwareResourceSerialProvider.o \ + $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ + $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ + $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ + $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterBubble.o \ + $(OUTDIR)/kernelEventFilterTrain.o $(OUTDIR)/kernelEventFilterYOLO.o \ + $(OUTDIR)/kernelHelperMediaMTX.o $(OUTDIR)/kernelModule.o \ + $(OUTDIR)/kernelModuleAttentionCloud.o $(OUTDIR)/kernelModuleBosch.o \ + $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ + $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ + $(OUTDIR)/kernelModuleModemManager.o \ + $(OUTDIR)/kernelModuleOnvifObserver.o \ + $(OUTDIR)/kernelModuleReportBackupper.o $(OUTDIR)/kernelModuleSSDP.o \ + $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ + $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ + $(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \ + $(OUTDIR)/mojoRemoteClient.o $(OUTDIR)/mysql_class.o \ + $(OUTDIR)/MySQL_dataBinder.o $(OUTDIR)/netClientHandler.o \ + $(OUTDIR)/netServer.o $(OUTDIR)/objectFileLoggingService.o \ + $(OUTDIR)/objectSystemAnchor.o $(OUTDIR)/ponvif.o \ + $(OUTDIR)/protocol.o $(OUTDIR)/protocolARGUS.o \ + $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/protocolBVMS.o \ + $(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolKAFKA.o \ + $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGS3D.o \ + $(OUTDIR)/protocolLGS3D_client.o $(OUTDIR)/protocolONVIF.o \ + $(OUTDIR)/protocolPTZ.o $(OUTDIR)/protocolPTZ_BRCP.o \ + $(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \ + $(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \ + $(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \ + $(OUTDIR)/streamHandler.o $(OUTDIR)/targetPipeLine.o \ + $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \ + $(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \ + $(OUTDIR)/xmlParser.o -lsqlite3 -lpthread -lmysqlclient -lssl -lcurl \ + -lm -lcrypto -lconfig -lz -lv4l1 -lv4l2 -lhidapi-libusb `pkg-config \ + libavcodec libavdevice libavfilter libavformat libavutil libpostproc \ + libswresample libswscale --libs` -latomic `pkg-config --libs openssl \ + opencv4 rdkafka++` -lliveMedia -lgroupsock -lBasicUsageEnvironment \ + -lUsageEnvironment -ldarknet -lsensors + +COMPILE=g++ -c -x c++ "-DDEBUG" "-DMEKOROT_PROJECT_" "-D__STDC_CONSTANT_MACROS" "-D_CLIENT_APPLICATION_" "-D_OPENCV_" -O0 -Wall -pedantic -W -std=c++17 -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 -Wall -pedantic -o "$(OUTFILE)" $(ALL_OBJ) + +# Pattern rules +$(OUTDIR)/%.o : ../../lib/components/object/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/json/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/transport/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/protocol/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/App/mojo/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/rfs/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/App/common/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/net/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/media/video/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/hardware/hid/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/alg/lgs/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/bosch_rcp/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/components/base/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/curl/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/sqlite/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/ponvif/%.cpp + $(COMPILE) + +# Build rules +all: $(OUTFILE) + +$(OUTFILE): $(OUTDIR) $(OBJ) + $(LINK) + +$(OUTDIR): + $(MKDIR) -p "$(OUTDIR)" + +# Rebuild this project +rebuild: cleanall + @$(MAKE) -f "$(strip $(MAKEFILE_LIST))" $(MAKEFLAGS) all + +# Clean this project +clean: + $(RM) -f $(OUTFILE) + $(RM) -f $(OBJ) + +# Clean this project and all dependencies +cleanall: clean +endif + +# +# Configuration: Release86 +# +ifeq "$(CFG)" "Release86" +OUTDIR=Release86 +OUTFILE=$(OUTDIR)/mojo +CFG_INC= +CFG_LIB=-lsqlite3 -lpthread -lmysqlclient -lssl -lcurl -lm -lcrypto \ + -lconfig -lz -lv4l1 -lv4l2 -lhidapi-libusb `pkg-config libavcodec \ + libavdevice libavfilter libavformat libavutil libpostproc \ + libswresample libswscale --libs` -latomic `pkg-config --libs openssl \ + opencv4 rdkafka++` -lliveMedia -lgroupsock -lBasicUsageEnvironment \ + -lUsageEnvironment -ldarknet -lsensors +CFG_OBJ= +COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ + $(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ + $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ + $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ + $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ + $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicObject.o \ + $(OUTDIR)/basicPosition.o $(OUTDIR)/basicRing.o \ + $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ + $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ + $(OUTDIR)/bosch_rcp.o $(OUTDIR)/clientPort.o \ + $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \ + $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \ + $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \ + $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \ + $(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \ + $(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \ + $(OUTDIR)/deviceNodePresetCamControl.o \ + $(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \ + $(OUTDIR)/deviceNodeStaticCamControl.o $(OUTDIR)/fs_helper.o \ + $(OUTDIR)/FSClient.o $(OUTDIR)/hardwareManager.o \ + $(OUTDIR)/hardwareResource.o \ + $(OUTDIR)/hardwareResourceDryContactProvider.o \ + $(OUTDIR)/hardwareResourceNetworkProvider.o \ + $(OUTDIR)/hardwareResourceSerialProvider.o \ + $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ + $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ + $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ + $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterBubble.o \ + $(OUTDIR)/kernelEventFilterTrain.o $(OUTDIR)/kernelEventFilterYOLO.o \ + $(OUTDIR)/kernelHelperMediaMTX.o $(OUTDIR)/kernelModule.o \ + $(OUTDIR)/kernelModuleAttentionCloud.o $(OUTDIR)/kernelModuleBosch.o \ + $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ + $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ + $(OUTDIR)/kernelModuleModemManager.o \ + $(OUTDIR)/kernelModuleOnvifObserver.o \ + $(OUTDIR)/kernelModuleReportBackupper.o $(OUTDIR)/kernelModuleSSDP.o \ + $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ + $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ + $(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \ + $(OUTDIR)/mojoRemoteClient.o $(OUTDIR)/mysql_class.o \ + $(OUTDIR)/MySQL_dataBinder.o $(OUTDIR)/netClientHandler.o \ + $(OUTDIR)/netServer.o $(OUTDIR)/objectFileLoggingService.o \ + $(OUTDIR)/objectSystemAnchor.o $(OUTDIR)/ponvif.o \ + $(OUTDIR)/protocol.o $(OUTDIR)/protocolARGUS.o \ + $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/protocolBVMS.o \ + $(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolKAFKA.o \ + $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGS3D.o \ + $(OUTDIR)/protocolLGS3D_client.o $(OUTDIR)/protocolONVIF.o \ + $(OUTDIR)/protocolPTZ.o $(OUTDIR)/protocolPTZ_BRCP.o \ + $(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \ + $(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \ + $(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \ + $(OUTDIR)/streamHandler.o $(OUTDIR)/targetPipeLine.o \ + $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \ + $(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \ + $(OUTDIR)/xmlParser.o +OBJ=$(COMMON_OBJ) $(CFG_OBJ) +ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ + $(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ + $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ + $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ + $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ + $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicObject.o \ + $(OUTDIR)/basicPosition.o $(OUTDIR)/basicRing.o \ + $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ + $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ + $(OUTDIR)/bosch_rcp.o $(OUTDIR)/clientPort.o \ + $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \ + $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \ + $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \ + $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \ + $(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \ + $(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \ + $(OUTDIR)/deviceNodePresetCamControl.o \ + $(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \ + $(OUTDIR)/deviceNodeStaticCamControl.o $(OUTDIR)/fs_helper.o \ + $(OUTDIR)/FSClient.o $(OUTDIR)/hardwareManager.o \ + $(OUTDIR)/hardwareResource.o \ + $(OUTDIR)/hardwareResourceDryContactProvider.o \ + $(OUTDIR)/hardwareResourceNetworkProvider.o \ + $(OUTDIR)/hardwareResourceSerialProvider.o \ + $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ + $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ + $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ + $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterBubble.o \ + $(OUTDIR)/kernelEventFilterTrain.o $(OUTDIR)/kernelEventFilterYOLO.o \ + $(OUTDIR)/kernelHelperMediaMTX.o $(OUTDIR)/kernelModule.o \ + $(OUTDIR)/kernelModuleAttentionCloud.o $(OUTDIR)/kernelModuleBosch.o \ + $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ + $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ + $(OUTDIR)/kernelModuleModemManager.o \ + $(OUTDIR)/kernelModuleOnvifObserver.o \ + $(OUTDIR)/kernelModuleReportBackupper.o $(OUTDIR)/kernelModuleSSDP.o \ + $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ + $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ + $(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \ + $(OUTDIR)/mojoRemoteClient.o $(OUTDIR)/mysql_class.o \ + $(OUTDIR)/MySQL_dataBinder.o $(OUTDIR)/netClientHandler.o \ + $(OUTDIR)/netServer.o $(OUTDIR)/objectFileLoggingService.o \ + $(OUTDIR)/objectSystemAnchor.o $(OUTDIR)/ponvif.o \ + $(OUTDIR)/protocol.o $(OUTDIR)/protocolARGUS.o \ + $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/protocolBVMS.o \ + $(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolKAFKA.o \ + $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGS3D.o \ + $(OUTDIR)/protocolLGS3D_client.o $(OUTDIR)/protocolONVIF.o \ + $(OUTDIR)/protocolPTZ.o $(OUTDIR)/protocolPTZ_BRCP.o \ + $(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \ + $(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \ + $(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \ + $(OUTDIR)/streamHandler.o $(OUTDIR)/targetPipeLine.o \ + $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \ + $(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \ + $(OUTDIR)/xmlParser.o -lsqlite3 -lpthread -lmysqlclient -lssl -lcurl \ + -lm -lcrypto -lconfig -lz -lv4l1 -lv4l2 -lhidapi-libusb `pkg-config \ + libavcodec libavdevice libavfilter libavformat libavutil libpostproc \ + libswresample libswscale --libs` -latomic `pkg-config --libs openssl \ + opencv4 rdkafka++` -lliveMedia -lgroupsock -lBasicUsageEnvironment \ + -lUsageEnvironment -ldarknet -lsensors + +COMPILE=g++ -c -x c++ "-D__STDC_CONSTANT_MACROS" "-D_CLIENT_APPLICATION_" "-D_OPENCV_" -O3 -w -Wpointer-arith -std=c++17 -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) + +# Pattern rules +$(OUTDIR)/%.o : ../../lib/components/object/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/json/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/transport/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/protocol/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/App/mojo/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/rfs/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/App/common/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/net/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/media/video/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/hardware/hid/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/alg/lgs/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/bosch_rcp/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/components/base/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/curl/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/sqlite/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/ponvif/%.cpp + $(COMPILE) + +# Build rules +all: $(OUTFILE) + +$(OUTFILE): $(OUTDIR) $(OBJ) + $(LINK) + +$(OUTDIR): + $(MKDIR) -p "$(OUTDIR)" + +# Rebuild this project +rebuild: cleanall + @$(MAKE) -f "$(strip $(MAKEFILE_LIST))" $(MAKEFLAGS) all + +# Clean this project +clean: + $(RM) -f $(OUTFILE) + $(RM) -f $(OBJ) + +# Clean this project and all dependencies +cleanall: clean +endif + +# +# Configuration: LRF_Proxy_ONLY +# +ifeq "$(CFG)" "LRF_Proxy_ONLY" +OUTDIR=LRF_Proxy_ONLY +OUTFILE=$(OUTDIR)/mojo_d +CFG_INC= +CFG_LIB=-lsqlite3 -lpthread -lmysqlclient -lssl -lcurl -lm -lcrypto \ + -lconfig -lz -lhidapi-libusb -latomic `pkg-config --libs openssl \ + rdkafka++` -lgroupsock +CFG_OBJ= +COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ + $(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ + $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ + $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ + $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ + $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicObject.o \ + $(OUTDIR)/basicPosition.o $(OUTDIR)/basicRing.o \ + $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ + $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ + $(OUTDIR)/bosch_rcp.o $(OUTDIR)/clientPort.o \ + $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \ + $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \ + $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \ + $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \ + $(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \ + $(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \ + $(OUTDIR)/deviceNodePresetCamControl.o \ + $(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \ + $(OUTDIR)/deviceNodeStaticCamControl.o $(OUTDIR)/fs_helper.o \ + $(OUTDIR)/FSClient.o $(OUTDIR)/hardwareManager.o \ + $(OUTDIR)/hardwareResource.o \ + $(OUTDIR)/hardwareResourceDryContactProvider.o \ + $(OUTDIR)/hardwareResourceNetworkProvider.o \ + $(OUTDIR)/hardwareResourceSerialProvider.o \ + $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ + $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ + $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ + $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterBubble.o \ + $(OUTDIR)/kernelEventFilterTrain.o $(OUTDIR)/kernelEventFilterYOLO.o \ + $(OUTDIR)/kernelHelperMediaMTX.o $(OUTDIR)/kernelModule.o \ + $(OUTDIR)/kernelModuleAttentionCloud.o $(OUTDIR)/kernelModuleBosch.o \ + $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ + $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ + $(OUTDIR)/kernelModuleModemManager.o \ + $(OUTDIR)/kernelModuleOnvifObserver.o \ + $(OUTDIR)/kernelModuleReportBackupper.o $(OUTDIR)/kernelModuleSSDP.o \ + $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ + $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ + $(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \ + $(OUTDIR)/mojoRemoteClient.o $(OUTDIR)/mysql_class.o \ + $(OUTDIR)/MySQL_dataBinder.o $(OUTDIR)/netClientHandler.o \ + $(OUTDIR)/netServer.o $(OUTDIR)/objectFileLoggingService.o \ + $(OUTDIR)/objectSystemAnchor.o $(OUTDIR)/ponvif.o \ + $(OUTDIR)/protocol.o $(OUTDIR)/protocolARGUS.o \ + $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/protocolBVMS.o \ + $(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolKAFKA.o \ + $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGS3D.o \ + $(OUTDIR)/protocolLGS3D_client.o $(OUTDIR)/protocolONVIF.o \ + $(OUTDIR)/protocolPTZ.o $(OUTDIR)/protocolPTZ_BRCP.o \ + $(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \ + $(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \ + $(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \ + $(OUTDIR)/streamHandler.o $(OUTDIR)/targetPipeLine.o \ + $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \ + $(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \ + $(OUTDIR)/xmlParser.o +OBJ=$(COMMON_OBJ) $(CFG_OBJ) +ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \ + $(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ + $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ + $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ + $(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \ + $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicObject.o \ + $(OUTDIR)/basicPosition.o $(OUTDIR)/basicRing.o \ + $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \ + $(OUTDIR)/basicThread.o $(OUTDIR)/basicTransport.o \ + $(OUTDIR)/bosch_rcp.o $(OUTDIR)/clientPort.o \ + $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \ + $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \ + $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \ + $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \ + $(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \ + $(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \ + $(OUTDIR)/deviceNodePresetCamControl.o \ + $(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \ + $(OUTDIR)/deviceNodeStaticCamControl.o $(OUTDIR)/fs_helper.o \ + $(OUTDIR)/FSClient.o $(OUTDIR)/hardwareManager.o \ + $(OUTDIR)/hardwareResource.o \ + $(OUTDIR)/hardwareResourceDryContactProvider.o \ + $(OUTDIR)/hardwareResourceNetworkProvider.o \ + $(OUTDIR)/hardwareResourceSerialProvider.o \ + $(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \ + $(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ + $(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \ + $(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelEventFilterBubble.o \ + $(OUTDIR)/kernelEventFilterTrain.o $(OUTDIR)/kernelEventFilterYOLO.o \ + $(OUTDIR)/kernelHelperMediaMTX.o $(OUTDIR)/kernelModule.o \ + $(OUTDIR)/kernelModuleAttentionCloud.o $(OUTDIR)/kernelModuleBosch.o \ + $(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \ + $(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \ + $(OUTDIR)/kernelModuleModemManager.o \ + $(OUTDIR)/kernelModuleOnvifObserver.o \ + $(OUTDIR)/kernelModuleReportBackupper.o $(OUTDIR)/kernelModuleSSDP.o \ + $(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \ + $(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ + $(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \ + $(OUTDIR)/mojoRemoteClient.o $(OUTDIR)/mysql_class.o \ + $(OUTDIR)/MySQL_dataBinder.o $(OUTDIR)/netClientHandler.o \ + $(OUTDIR)/netServer.o $(OUTDIR)/objectFileLoggingService.o \ + $(OUTDIR)/objectSystemAnchor.o $(OUTDIR)/ponvif.o \ + $(OUTDIR)/protocol.o $(OUTDIR)/protocolARGUS.o \ + $(OUTDIR)/protocolARGUS_DATA.o $(OUTDIR)/protocolBVMS.o \ + $(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolKAFKA.o \ + $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGS3D.o \ + $(OUTDIR)/protocolLGS3D_client.o $(OUTDIR)/protocolONVIF.o \ + $(OUTDIR)/protocolPTZ.o $(OUTDIR)/protocolPTZ_BRCP.o \ + $(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \ + $(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \ + $(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \ + $(OUTDIR)/streamHandler.o $(OUTDIR)/targetPipeLine.o \ + $(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \ + $(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \ + $(OUTDIR)/xmlParser.o -lsqlite3 -lpthread -lmysqlclient -lssl -lcurl \ + -lm -lcrypto -lconfig -lz -lhidapi-libusb -latomic `pkg-config \ + --libs openssl rdkafka++` -lgroupsock + +COMPILE=g++ -c -x c++ "-DDEBUG" "-DLRF_PROXY_ONLY" "-D__STDC_CONSTANT_MACROS" "-D_CLIENT_APPLICATION_" "-D_OPENCV_" -O0 -Wall -pedantic -W -std=c++17 -Wno-write-strings -I../../lib/include -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $< +LINK=g++ -O0 -Wall -pedantic -o "$(OUTFILE)" $(ALL_OBJ) + +# Pattern rules +$(OUTDIR)/%.o : ../../lib/components/object/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/json/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/transport/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/protocol/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/App/mojo/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/rfs/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/App/common/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/net/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/media/video/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/hardware/hid/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/alg/lgs/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/bosch_rcp/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/components/base/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/curl/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/sqlite/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/ponvif/%.cpp + $(COMPILE) + +# Build rules +all: $(OUTFILE) + +$(OUTFILE): $(OUTDIR) $(OBJ) + $(LINK) + +$(OUTDIR): + $(MKDIR) -p "$(OUTDIR)" + +# Rebuild this project +rebuild: cleanall + @$(MAKE) -f "$(strip $(MAKEFILE_LIST))" $(MAKEFLAGS) all + +# Clean this project +clean: + $(RM) -f $(OUTFILE) + $(RM) -f $(OBJ) + +# Clean this project and all dependencies +cleanall: clean +endif + +# +# MediaMtx library (lib/data/media/mtx): every configuration except the LRF proxy +# +ifneq "$(CFG)" "LRF_Proxy_ONLY" +MTX_OBJ=$(OUTDIR)/logger.o $(OUTDIR)/serverConf.o $(OUTDIR)/h264.o \ + $(OUTDIR)/stream.o $(OUTDIR)/httpServer.o $(OUTDIR)/mediaPath.o \ + $(OUTDIR)/h264Feeder.o $(OUTDIR)/fmp4Writer.o $(OUTDIR)/recorder.o \ + $(OUTDIR)/session.o $(OUTDIR)/webrtcServer.o $(OUTDIR)/streamLiveEncoder.o +OBJ+=$(MTX_OBJ) +ALL_OBJ+=$(MTX_OBJ) $(DATACHANNEL_LIBS) -lssl -lcrypto -lpthread +CFG_INC+=$(DATACHANNEL_CFLAGS) +# the rule of each configuration lists $(OBJ) as it was then: add the library objects +$(OUTFILE): $(MTX_OBJ) + +$(OUTDIR)/%.o : ../../lib/data/media/mtx/logger/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/media/mtx/conf/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/media/mtx/codecs/h264/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/media/mtx/stream/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/media/mtx/protocols/httpp/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/media/mtx/core/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/media/mtx/feeder/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/media/mtx/recorder/%.cpp + $(COMPILE) + +$(OUTDIR)/%.o : ../../lib/data/media/mtx/servers/webrtc/%.cpp + $(COMPILE) +endif + +# +# include dependencies: +# +$(OUTDIR)/base64.o: ../../lib/alg/generic/base64.cpp ../../lib/alg/generic/base64.h +$(OUTDIR)/basicCameraInfo.o: ../../lib/components/base/basicCameraInfo.cpp ../../lib/components/base/basicCameraInfo.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h +$(OUTDIR)/basicDualThread.o: ../../lib/components/base/basicDualThread.cpp ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h +$(OUTDIR)/basicEngine.o: ../../lib/components/base/basicEngine.cpp ../../lib/components/base/basicEngine.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicObject.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicValidatable.h +$(OUTDIR)/basicEvent.o: ../../lib/components/base/basicEvent.cpp ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h +$(OUTDIR)/basicEventHandler.o: ../../lib/components/base/basicEventHandler.cpp ../../lib/components/base/basicEventHandler.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h +$(OUTDIR)/basicEventHeap.o: ../../lib/components/base/basicEventHeap.cpp ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicEventHandler.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h +$(OUTDIR)/basicFunctionality.o: ../../lib/components/base/basicFunctionality.cpp ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/md5.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.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/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/alg/generic/heapDebug.h +$(OUTDIR)/basicLoggingService.o: ../../lib/components/base/basicLoggingService.cpp ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h +$(OUTDIR)/basicObject.o: ../../lib/components/base/basicObject.cpp ../../lib/components/base/basicObject.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicValidatable.h ../../lib/alg/generic/md5.h +$(OUTDIR)/basicPosition.o: ../../lib/components/base/basicPosition.cpp ../../lib/components/base/basicPosition.h +$(OUTDIR)/basicRing.o: ../../lib/components/base/basicRing.cpp ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h +$(OUTDIR)/basicSettings.o: ../../lib/components/base/basicSettings.cpp ../../lib/components/base/basicSettings.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h +$(OUTDIR)/basicSettingsProvider.o: ../../lib/components/base/basicSettingsProvider.cpp ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h +$(OUTDIR)/basicThread.o: ../../lib/components/base/basicThread.cpp ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h +$(OUTDIR)/basicTransport.o: ../../lib/components/base/basicTransport.cpp ../../lib/components/base/basicTransport.h ../../lib/data/protocol/protocol.h +$(OUTDIR)/bosch_rcp.o: ../../lib/data/bosch_rcp/bosch_rcp.cpp ../../lib/data/bosch_rcp/bosch_rcp.h +$(OUTDIR)/clientPort.o: ../../lib/data/net/clientPort.cpp ../../lib/data/net/clientPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h +$(OUTDIR)/cmdNodeConveyor.o: ../../lib/App/common/cmdNodeConveyor.cpp ../../lib/App/common/cmdNodeConveyor.h +$(OUTDIR)/curlRequest.o: ../../lib/data/curl/curlRequest.cpp ../../lib/data/curl/curlRequest.h +$(OUTDIR)/curlRequestsManager.o: ../../lib/data/curl/curlRequestsManager.cpp ../../lib/data/curl/curlRequestsManager.h +$(OUTDIR)/dataBinder.o: ../../lib/App/common/dataBinder.cpp ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h +$(OUTDIR)/dataBinder_ReportAux.o: ../../lib/App/common/dataBinder_ReportAux.cpp ../../lib/App/common/dataBinder_ReportAux.h +$(OUTDIR)/detector.o: ../../lib/alg/lgs/detector.cpp ../../lib/alg/lgs/detector.h ../../lib/components/base/basicObject.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicValidatable.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h +$(OUTDIR)/deviceNode.o: ../../lib/App/common/deviceNode.cpp ../../lib/App/common/deviceNode.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h +$(OUTDIR)/deviceNode2D.o: ../../lib/App/common/deviceNode2D.cpp ../../lib/App/common/deviceNode2D.h ../../lib/App/common/hardwareManager.h ../../lib/App/common/hardwareResourceSerialProvider.h ../../lib/App/common/kernelPrototype.h +$(OUTDIR)/deviceNode3D.o: ../../lib/App/common/deviceNode3D.cpp ../../lib/App/common/deviceNode3D.h ../../lib/App/common/kernelPrototype.h +$(OUTDIR)/deviceNodeCamera.o: ../../lib/App/common/deviceNodeCamera.cpp ../../lib/App/common/deviceNodeCamera.h ../../lib/components/base/basicCameraInfo.h ../../lib/components/object/objectSystemAnchor.h ../../lib/data/protocol/protocolPTZ_ONVIF.h ../../lib/data/protocol/protocolPTZ_PELCO.h ../../lib/data/protocol/protocolPTZ_VISCA.h ../../lib/data/protocol/protocolPTZ_BRCP.h ../../lib/App/mojo/mojoKernel.h ../../lib/alg/generic/md5.h ../../lib/alg/lgs/detector.h ../../lib/components/base/basicObject.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicValidatable.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/mask.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/hardware/soc/general/3DLRF.h ../../lib/gui/gui.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/kernelPrototype.h ../../lib/App/mojo/mojoRemoteClient.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/data/net/clientPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h ../../lib/data/protocol/protocol.h ../../lib/data/protocol/protocolARGUS_DATA.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/kernelHelperMediaMTX.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/hardwareManager.h ../../lib/App/common/hardwareResourceSerialProvider.h ../../lib/App/common/kernelModuleEmbedVideo.h +$(OUTDIR)/deviceNodeEthernet2Serial.o: ../../lib/App/common/deviceNodeEthernet2Serial.cpp ../../lib/App/common/deviceNodeEthernet2Serial.h ../../lib/data/protocol/protocol.h ../../lib/App/common/hardwareManager.h +$(OUTDIR)/deviceNodeFactory.o: ../../lib/App/common/deviceNodeFactory.cpp ../../lib/App/common/deviceNodeFactory.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h ../../lib/App/common/deviceNode2D.h ../../lib/App/common/deviceNode3D.h ../../lib/App/common/deviceNodeEthernet2Serial.h ../../lib/App/common/deviceNodePresetCamControl.h ../../lib/App/common/deviceNodePTZCamControl.h ../../lib/App/common/deviceNodeStaticCamControl.h +$(OUTDIR)/deviceNodePresetCamControl.o: ../../lib/App/common/deviceNodePresetCamControl.cpp ../../lib/App/common/deviceNodePresetCamControl.h ../../lib/App/mojo/mojoKernel.h ../../lib/alg/generic/md5.h ../../lib/alg/lgs/detector.h ../../lib/components/base/basicObject.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicValidatable.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/mask.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/hardware/soc/general/3DLRF.h ../../lib/gui/gui.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/kernelPrototype.h ../../lib/App/mojo/mojoRemoteClient.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/data/net/clientPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h ../../lib/data/protocol/protocol.h ../../lib/data/protocol/protocolARGUS_DATA.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/kernelHelperMediaMTX.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h +$(OUTDIR)/deviceNodePTZCamControl.o: ../../lib/App/common/deviceNodePTZCamControl.cpp ../../lib/App/common/deviceNodePTZCamControl.h ../../lib/App/mojo/mojoKernel.h ../../lib/alg/generic/md5.h ../../lib/alg/lgs/detector.h ../../lib/components/base/basicObject.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicValidatable.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/mask.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/hardware/soc/general/3DLRF.h ../../lib/gui/gui.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/kernelPrototype.h ../../lib/App/mojo/mojoRemoteClient.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/data/net/clientPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h ../../lib/data/protocol/protocol.h ../../lib/data/protocol/protocolARGUS_DATA.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/kernelHelperMediaMTX.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h +$(OUTDIR)/deviceNodeSensor.o: ../../lib/App/common/deviceNodeSensor.cpp ../../lib/App/common/deviceNodeSensor.h ../../lib/components/object/objectSystemAnchor.h ../../lib/App/common/kernelPrototype.h +$(OUTDIR)/deviceNodeStaticCamControl.o: ../../lib/App/common/deviceNodeStaticCamControl.cpp ../../lib/App/common/deviceNodeStaticCamControl.h +$(OUTDIR)/fs_helper.o: ../../lib/data/rfs/fs_helper.cpp ../../lib/data/rfs/fs_helper.h +$(OUTDIR)/FSClient.o: ../../lib/data/rfs/FSClient.cpp ../../lib/data/rfs/FSClient.h +$(OUTDIR)/hardwareManager.o: ../../lib/App/common/hardwareManager.cpp ../../lib/App/common/hardwareManager.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h ../../lib/App/common/hardwareResourceNetworkProvider.h ../../lib/App/common/hardwareResourceSerialProvider.h ../../lib/App/common/hardwareResourceVideoProvider.h +$(OUTDIR)/hardwareResource.o: ../../lib/App/common/hardwareResource.cpp ../../lib/App/common/hardwareResource.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h +$(OUTDIR)/hardwareResourceDryContactProvider.o: ../../lib/App/common/hardwareResourceDryContactProvider.cpp ../../lib/App/common/hardwareResourceDryContactProvider.h +$(OUTDIR)/hardwareResourceNetworkProvider.o: ../../lib/App/common/hardwareResourceNetworkProvider.cpp ../../lib/App/common/hardwareResourceNetworkProvider.h +$(OUTDIR)/hardwareResourceSerialProvider.o: ../../lib/App/common/hardwareResourceSerialProvider.cpp ../../lib/App/common/hardwareResourceSerialProvider.h +$(OUTDIR)/hardwareResourceVideoProvider.o: ../../lib/App/common/hardwareResourceVideoProvider.cpp ../../lib/App/common/hardwareResourceVideoProvider.h +$(OUTDIR)/heapDebug.o: ../../lib/alg/generic/heapDebug.cpp ../../lib/alg/generic/heapDebug.h +$(OUTDIR)/hid_dc.o: ../../lib/hardware/hid/hid_dc.cpp +$(OUTDIR)/json_reader.o: ../../lib/data/json/json_reader.cpp ../../lib/data/json/json_tool.h +$(OUTDIR)/json_value.o: ../../lib/data/json/json_value.cpp ../../lib/data/json/json_valueiterator.inl +$(OUTDIR)/json_writer.o: ../../lib/data/json/json_writer.cpp ../../lib/data/json/json_tool.h +$(OUTDIR)/kernelEventFilter.o: ../../lib/App/common/kernelEventFilter.cpp ../../lib/App/common/kernelEventFilter.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h +$(OUTDIR)/kernelEventFilterAPF.o: ../../lib/App/common/kernelEventFilterAPF.cpp ../../lib/App/common/kernelEventFilterAPF.h +$(OUTDIR)/kernelEventFilterBubble.o: ../../lib/App/common/kernelEventFilterBubble.cpp ../../lib/App/common/kernelEventFilterBubble.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/kernelEventFilter.h ../../lib/App/common/kernelPrototype.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/object/objectSystemAnchor.h +$(OUTDIR)/kernelEventFilterTrain.o: ../../lib/App/common/kernelEventFilterTrain.cpp ../../lib/App/common/kernelEventFilterTrain.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/App/common/deviceNodeFactory.h +$(OUTDIR)/kernelEventFilterYOLO.o: ../../lib/App/common/kernelEventFilterYOLO.cpp ../../lib/App/common/kernelEventFilterYOLO.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/kernelEventFilter.h ../../lib/App/common/kernelPrototype.h +$(OUTDIR)/kernelHelperMediaMTX.o: ../../lib/App/common/kernelHelperMediaMTX.cpp ../../lib/App/common/kernelHelperMediaMTX.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/SQLite_dataBinder.h +$(OUTDIR)/kernelModule.o: ../../lib/App/common/kernelModule.cpp ../../lib/App/common/kernelModule.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h +$(OUTDIR)/kernelModuleAttentionCloud.o: ../../lib/App/common/kernelModuleAttentionCloud.cpp ../../lib/App/common/kernelModuleAttentionCloud.h ../../lib/App/common/kernelModule.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/deviceNodeFactory.h ../../lib/App/common/deviceNodeCamera.h +$(OUTDIR)/kernelModuleBosch.o: ../../lib/App/common/kernelModuleBosch.cpp ../../lib/App/common/kernelModuleBosch.h +$(OUTDIR)/kernelModuleEmbedVideo.o: ../../lib/App/common/kernelModuleEmbedVideo.cpp ../../lib/App/common/kernelModuleEmbedVideo.h ../../lib/App/common/streamHandler.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/App/common/kernelModule.h ../../lib/components/base/basicMediaDestination.h ../../lib/components/base/basicMediaSource.h ../../lib/App/common/deviceNodeCamera.h ../../lib/App/common/deviceNodeFactory.h +$(OUTDIR)/kernelModuleFactory.o: ../../lib/App/common/kernelModuleFactory.cpp ../../lib/App/common/kernelModuleFactory.h ../../lib/App/common/kernelModuleEmbedVideo.h ../../lib/App/common/kernelModuleFlyHunter.h ../../lib/App/common/kernelModuleKafka.h ../../lib/App/common/kernelModuleModemManager.h ../../lib/App/common/kernelModuleOnvifObserver.h ../../lib/App/common/kernelModuleSSDP.h ../../lib/App/common/kernelModuleUSBRelay.h ../../lib/App/common/kernelModuleBosch.h ../../lib/App/common/kernelModuleAttentionCloud.h ../../lib/App/common/kernelModule.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h +$(OUTDIR)/kernelModuleFlyHunter.o: ../../lib/App/common/kernelModuleFlyHunter.cpp ../../lib/App/common/kernelModuleFlyHunter.h +$(OUTDIR)/kernelModuleKafka.o: ../../lib/App/common/kernelModuleKafka.cpp ../../lib/App/common/kernelModuleKafka.h +$(OUTDIR)/kernelModuleModemManager.o: ../../lib/App/common/kernelModuleModemManager.cpp ../../lib/App/common/kernelModuleModemManager.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h +$(OUTDIR)/kernelModuleOnvifObserver.o: ../../lib/App/common/kernelModuleOnvifObserver.cpp ../../lib/App/common/kernelModuleOnvifObserver.h ../../lib/App/common/hardwareManager.h ../../lib/App/common/hardwareResourceNetworkProvider.h +$(OUTDIR)/kernelModuleReportBackupper.o: ../../lib/App/common/kernelModuleReportBackupper.cpp ../../lib/App/common/kernelModuleReportBackupper.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h +$(OUTDIR)/kernelModuleSSDP.o: ../../lib/App/common/kernelModuleSSDP.cpp ../../lib/App/common/kernelModuleSSDP.h +$(OUTDIR)/kernelModuleUSBRelay.o: ../../lib/App/common/kernelModuleUSBRelay.cpp ../../lib/App/common/kernelModuleUSBRelay.h +$(OUTDIR)/kernelPrototype.o: ../../lib/App/common/kernelPrototype.cpp ../../lib/App/common/kernelPrototype.h +$(OUTDIR)/libzip.o: ../../lib/alg/generic/libzip.cpp ../../lib/alg/generic/libzip.h +$(OUTDIR)/mask.o: ../../lib/alg/lgs/mask.cpp ../../lib/alg/lgs/mask.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/hardware/soc/general/3DLRF.h ../../lib/gui/gui.h +$(OUTDIR)/md5.o: ../../lib/alg/generic/md5.cpp ../../lib/alg/generic/md5.h +$(OUTDIR)/mojoBackend.o: ../../lib/App/mojo/mojoBackend.cpp ../../lib/App/mojo/mojoBackend.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMemoryOperation.h ../../lib/components/base/basicSettings.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/object/objectFileLoggingService.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/App/mojo/mojoKernel.h ../../lib/alg/generic/md5.h ../../lib/alg/lgs/detector.h ../../lib/components/base/basicObject.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicValidatable.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/mask.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/hardware/soc/general/3DLRF.h ../../lib/gui/gui.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/kernelPrototype.h ../../lib/App/mojo/mojoRemoteClient.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/data/net/clientPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h ../../lib/data/protocol/protocol.h ../../lib/data/protocol/protocolARGUS_DATA.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/kernelHelperMediaMTX.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h +$(OUTDIR)/mojoKernel.o: ../../lib/App/mojo/mojoKernel.cpp ../../lib/App/mojo/mojoKernel.h ../../lib/alg/generic/md5.h ../../lib/alg/lgs/detector.h ../../lib/components/base/basicObject.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicValidatable.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/mask.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/hardware/soc/general/3DLRF.h ../../lib/gui/gui.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/kernelPrototype.h ../../lib/App/mojo/mojoRemoteClient.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/data/net/clientPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h ../../lib/data/protocol/protocol.h ../../lib/data/protocol/protocolARGUS_DATA.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/kernelHelperMediaMTX.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/kernelEventFilterAPF.h ../../lib/App/common/kernelEventFilterBubble.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/kernelEventFilter.h ../../lib/App/common/kernelPrototype.h ../../lib/App/common/kernelEventFilterTrain.h ../../lib/App/common/kernelModuleEmbedVideo.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h ../../lib/App/common/deviceNode2D.h +$(OUTDIR)/mojoRemoteClient.o: ../../lib/App/mojo/mojoRemoteClient.cpp ../../lib/App/mojo/mojoRemoteClient.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/data/net/clientPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h ../../lib/data/protocol/protocol.h ../../lib/data/protocol/protocolARGUS_DATA.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/mojo/mojoKernel.h ../../lib/alg/generic/md5.h ../../lib/alg/lgs/detector.h ../../lib/components/base/basicObject.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicValidatable.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/mask.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/hardware/soc/general/3DLRF.h ../../lib/gui/gui.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/kernelPrototype.h ../../lib/App/mojo/mojoRemoteClient.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/data/net/clientPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h ../../lib/data/protocol/protocol.h ../../lib/data/protocol/protocolARGUS_DATA.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/kernelHelperMediaMTX.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/deviceNodeCamera.h ../../lib/App/common/deviceNodeFactory.h ../../lib/App/common/deviceNodeSensor.h +$(OUTDIR)/mysql_class.o: ../../lib/data/mysql/mysql_class.cpp ../../lib/data/mysql/mysql_class.h +$(OUTDIR)/MySQL_dataBinder.o: ../../lib/App/common/MySQL_dataBinder.cpp ../../lib/App/common/MySQL_dataBinder.h +$(OUTDIR)/netClientHandler.o: ../../lib/data/net/netClientHandler.cpp ../../lib/data/net/netClientHandler.h ../../lib/data/protocol/protocol.h ../../lib/components/base/basicEventHandler.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/data/net/netServiceEngine.h ../../lib/data/net/serverPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h +$(OUTDIR)/netServer.o: ../../lib/data/net/netServer.cpp ../../lib/data/net/netServer.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/data/protocol/protocol.h ../../lib/data/net/netClientHandler.h ../../lib/data/protocol/protocol.h ../../lib/components/base/basicEventHandler.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/data/net/netServiceEngine.h ../../lib/data/net/serverPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h ../../lib/data/net/netServiceEngine.h ../../lib/data/net/netClientHandler.h ../../lib/data/protocol/protocol.h ../../lib/components/base/basicEventHandler.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/data/net/netServiceEngine.h ../../lib/data/net/serverPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h +$(OUTDIR)/objectFileLoggingService.o: ../../lib/components/object/objectFileLoggingService.cpp ../../lib/components/object/objectFileLoggingService.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h +$(OUTDIR)/objectSystemAnchor.o: ../../lib/components/object/objectSystemAnchor.cpp ../../lib/components/object/objectSystemAnchor.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h +$(OUTDIR)/ponvif.o: ../../lib/data/ponvif/ponvif.cpp ../../lib/data/ponvif/ponvif.h +$(OUTDIR)/protocol.o: ../../lib/data/protocol/protocol.cpp ../../lib/data/protocol/protocol.h +$(OUTDIR)/protocolARGUS.o: ../../lib/data/protocol/protocolARGUS.cpp ../../lib/data/protocol/protocolARGUS.h +$(OUTDIR)/protocolARGUS_DATA.o: ../../lib/data/protocol/protocolARGUS_DATA.cpp ../../lib/data/protocol/protocolARGUS_DATA.h +$(OUTDIR)/protocolBVMS.o: ../../lib/data/protocol/protocolBVMS.cpp ../../lib/data/protocol/protocolBVMS.h ../../lib/alg/generic/md5.h +$(OUTDIR)/protocolHTTP.o: ../../lib/data/protocol/protocolHTTP.cpp ../../lib/data/protocol/protocolHTTP.h +$(OUTDIR)/protocolKAFKA.o: ../../lib/data/protocol/protocolKAFKA.cpp ../../lib/data/protocol/protocolKAFKA.h ../../lib/alg/generic/md5.h ../../lib/data/json/json_tool.h +$(OUTDIR)/protocolLGS2D.o: ../../lib/data/protocol/protocolLGS2D.cpp ../../lib/data/protocol/protocolLGS2D.h +$(OUTDIR)/protocolLGS3D.o: ../../lib/data/protocol/protocolLGS3D.cpp ../../lib/data/protocol/protocolLGS3D.h +$(OUTDIR)/protocolLGS3D_client.o: ../../lib/data/protocol/protocolLGS3D_client.cpp ../../lib/data/protocol/protocolLGS3D_client.h +$(OUTDIR)/protocolONVIF.o: ../../lib/data/protocol/protocolONVIF.cpp ../../lib/data/protocol/protocolONVIF.h +$(OUTDIR)/protocolPTZ.o: ../../lib/data/protocol/protocolPTZ.cpp ../../lib/data/protocol/protocolPTZ.h +$(OUTDIR)/protocolPTZ_BRCP.o: ../../lib/data/protocol/protocolPTZ_BRCP.cpp ../../lib/data/protocol/protocolPTZ_BRCP.h ../../lib/hardware/uart/serialPort.h +$(OUTDIR)/protocolPTZ_ONVIF.o: ../../lib/data/protocol/protocolPTZ_ONVIF.cpp ../../lib/data/protocol/protocolPTZ_ONVIF.h ../../lib/hardware/uart/serialPort.h +$(OUTDIR)/protocolPTZ_PELCO.o: ../../lib/data/protocol/protocolPTZ_PELCO.cpp ../../lib/data/protocol/protocolPTZ_PELCO.h +$(OUTDIR)/protocolPTZ_VISCA.o: ../../lib/data/protocol/protocolPTZ_VISCA.cpp ../../lib/data/protocol/protocolPTZ_VISCA.h +$(OUTDIR)/serverPort.o: ../../lib/data/net/serverPort.cpp ../../lib/data/net/serverPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h +$(OUTDIR)/sqlite_class.o: ../../lib/data/sqlite/sqlite_class.cpp ../../lib/data/sqlite/sqlite_class.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h +$(OUTDIR)/SQLite_dataBinder.o: ../../lib/App/common/SQLite_dataBinder.cpp ../../lib/App/common/SQLite_dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h +$(OUTDIR)/streamHandler.o: ../../lib/App/common/streamHandler.cpp ../../lib/App/common/streamHandler.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/App/common/kernelModule.h ../../lib/components/base/basicMediaDestination.h ../../lib/components/base/basicMediaSource.h +$(OUTDIR)/targetPipeLine.o: ../../lib/App/common/targetPipeLine.cpp ../../lib/App/common/targetPipeLine.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/App/common/dataBinder.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicPosition.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/Transform.h ../../lib/App/common/dataBinder_ReportAux.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/kernelEventFilter.h ../../lib/App/common/kernelPrototype.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h +$(OUTDIR)/Transform.o: ../../lib/alg/generic/Transform.cpp ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h +$(OUTDIR)/transportSocket.o: ../../lib/data/transport/transportSocket.cpp ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h ../../lib/data/protocol/protocol.h +$(OUTDIR)/utm.o: ../../lib/alg/generic/utm.cpp ../../lib/alg/generic/utm.h +$(OUTDIR)/videoAVLIBSource.o: ../../lib/data/media/video/videoAVLIBSource.cpp ../../lib/data/media/video/videoAVLIBSource.h +$(OUTDIR)/videoLive555AVLibSource.o: ../../lib/data/media/video/videoLive555AVLibSource.cpp ../../lib/data/media/video/videoLive555AVLibSource.h +$(OUTDIR)/xmlParser.o: ../../lib/data/protocol/xmlParser.cpp ../../lib/data/protocol/xmlParser.h diff --git a/lib/App/common/MySQL_dataBinder.cpp b/lib/App/common/MySQL_dataBinder.cpp index 819df971..e225f569 100644 --- a/lib/App/common/MySQL_dataBinder.cpp +++ b/lib/App/common/MySQL_dataBinder.cpp @@ -5391,6 +5391,44 @@ DBC_MODULE_EMBED_VIDEO_DATA * mysqlDBC::getEmbedVideoData(uint32_t ID) strncpy(tPtr->logo_md5, it->second.c_str(), 32); tPtr->logo_md5[32] = (char) 0; }; + // Live view (optional columns) + dbcEmbedVideoLiveDefaults(tPtr); + it = cArr->find("live_mode"); + if (it != cArr->end() && ! it->second.empty()) + { + tPtr->live_mode = (uint8_t) atoi(it->second.c_str()); + }; + it = cArr->find("live_port"); + if (it != cArr->end() && atoi(it->second.c_str()) > 0) + { + tPtr->live_port = (uint16_t) atoi(it->second.c_str()); + }; + it = cArr->find("live_record"); + if (it != cArr->end() && ! it->second.empty()) + { + tPtr->live_record = (bool) atoi(it->second.c_str()); + }; + it = cArr->find("live_record_segment"); + if (it != cArr->end() && atoi(it->second.c_str()) > 0) + { + tPtr->live_record_segment = (uint16_t) atoi(it->second.c_str()); + }; + it = cArr->find("live_bitrate"); + if (it != cArr->end() && atoi(it->second.c_str()) > 0) + { + tPtr->live_bitrate = (uint16_t) atoi(it->second.c_str()); + }; + it = cArr->find("live_fps"); + if (it != cArr->end() && atoi(it->second.c_str()) > 0) + { + tPtr->live_fps = (uint8_t) atoi(it->second.c_str()); + }; + it = cArr->find("live_ice_servers"); + if (it != cArr->end()) + { + strncpy(tPtr->live_ice_servers, it->second.c_str(), sizeof(tPtr->live_ice_servers) - 1); + tPtr->live_ice_servers[sizeof(tPtr->live_ice_servers) - 1] = (char) 0; + }; }; }; }; diff --git a/lib/App/common/SQLite_dataBinder.cpp b/lib/App/common/SQLite_dataBinder.cpp index f65fec04..2c6f0c8e 100644 --- a/lib/App/common/SQLite_dataBinder.cpp +++ b/lib/App/common/SQLite_dataBinder.cpp @@ -1908,6 +1908,44 @@ DBC_MODULE_EMBED_VIDEO_DATA * sqliteDBC::getEmbedVideoData(uint32_t ID) strncpy(tPtr->logo_md5, it->second.c_str(), 32); tPtr->logo_md5[32] = (char) 0; }; + // Live view (optional columns) + dbcEmbedVideoLiveDefaults(tPtr); + it = cArr->find("live_mode"); + if (it != cArr->end() && ! it->second.empty()) + { + tPtr->live_mode = (uint8_t) atoi(it->second.c_str()); + }; + it = cArr->find("live_port"); + if (it != cArr->end() && atoi(it->second.c_str()) > 0) + { + tPtr->live_port = (uint16_t) atoi(it->second.c_str()); + }; + it = cArr->find("live_record"); + if (it != cArr->end() && ! it->second.empty()) + { + tPtr->live_record = (bool) atoi(it->second.c_str()); + }; + it = cArr->find("live_record_segment"); + if (it != cArr->end() && atoi(it->second.c_str()) > 0) + { + tPtr->live_record_segment = (uint16_t) atoi(it->second.c_str()); + }; + it = cArr->find("live_bitrate"); + if (it != cArr->end() && atoi(it->second.c_str()) > 0) + { + tPtr->live_bitrate = (uint16_t) atoi(it->second.c_str()); + }; + it = cArr->find("live_fps"); + if (it != cArr->end() && atoi(it->second.c_str()) > 0) + { + tPtr->live_fps = (uint8_t) atoi(it->second.c_str()); + }; + it = cArr->find("live_ice_servers"); + if (it != cArr->end()) + { + strncpy(tPtr->live_ice_servers, it->second.c_str(), sizeof(tPtr->live_ice_servers) - 1); + tPtr->live_ice_servers[sizeof(tPtr->live_ice_servers) - 1] = (char) 0; + }; }; }; }; diff --git a/lib/App/common/dataBinder_structures.h b/lib/App/common/dataBinder_structures.h index f7e15c52..f3719552 100644 --- a/lib/App/common/dataBinder_structures.h +++ b/lib/App/common/dataBinder_structures.h @@ -344,8 +344,33 @@ typedef struct S_DBC_MODULE_EMBED_VIDEO_DATA int logo_x; int logo_y; char logo_md5[33]; + // Live view (WebRTC / WHEP) and continuous recording, replacing MediaMTX (optional columns of + // module_eve: the defaults apply when a column does not exist) + uint8_t live_mode; // EVE_LIVE_OFF / EVE_LIVE_PASSTHROUGH (default) / EVE_LIVE_ENCODE + uint16_t live_port; // WHEP port (default 8889, as MediaMTX: the dashboard uses it) + bool live_record; // continuous fMP4 segments of every stream (default on) + uint16_t live_record_segment; // segment length, seconds (default 60) + uint16_t live_bitrate; // EVE_LIVE_ENCODE: kbit/s (default 2000) + uint8_t live_fps; // EVE_LIVE_ENCODE: frames per second (default 15) + char live_ice_servers[256]; // STUN / TURN servers, comma separated (default none: LAN) } DBC_MODULE_EMBED_VIDEO_DATA; +#define EVE_LIVE_OFF 0 // no WebRTC server, no recording +#define EVE_LIVE_PASSTHROUGH 1 // the camera's H264 as it is (no CPU, original quality, no overlays) +#define EVE_LIVE_ENCODE 2 // the processed frames (overlays) encoded to H264 again + +// The defaults of the live view settings (also when the module has no DB record) +inline void dbcEmbedVideoLiveDefaults(DBC_MODULE_EMBED_VIDEO_DATA * p) +{ + p->live_mode = EVE_LIVE_PASSTHROUGH; + p->live_port = 8889; + p->live_record = true; + p->live_record_segment = 60; + p->live_bitrate = 2000; + p->live_fps = 15; + p->live_ice_servers[0] = (char) 0; +} + /* typedef struct S_DBC_SOCKET_DATA{ uint32_t socket_id; diff --git a/lib/App/common/kernelHelperMediaMTX.cpp b/lib/App/common/kernelHelperMediaMTX.cpp index ffaac806..2b80cd22 100644 --- a/lib/App/common/kernelHelperMediaMTX.cpp +++ b/lib/App/common/kernelHelperMediaMTX.cpp @@ -1,600 +1,619 @@ -#ifndef LRF_PROXY_ONLY - -#include "kernelHelperMediaMTX.h" -#include "SQLite_dataBinder.h" - -#include - -#define LOG(X) m_pLog->Log("KHMTX", this, X) - -#ifdef DEBUG - #define LOG_ERROR(X) \ - { \ - char _tBfrErrMSG2w34[1024]; \ - sprintf(_tBfrErrMSG2w34, "In file %s[%d] in func:%s %s", __FILE__, __LINE__, __func__, X); \ - m_pLog->Log("KHMTX", this, _LOG_ERROR, _tBfrErrMSG2w34); \ - } -#else - #define LOG_ERROR(X) m_pLog->Log("KHMTX", this, _LOG_ERROR, X); -#endif - - -kernelHelperMediaMTX::kernelHelperMediaMTX(): basicThread() { - m_bStatus = KH_STATUS_MTX_NA; - m_pDBC = sqliteDBC::getInstance(); - m_pLog = basicLogCollection::getInstance(); - memset( m_sWorkDir, 0, 512 ); - memset( m_sAppLogFile, 0, 512 ); - memset( m_sAppConfigFile, 0, 512 ); - m_nLastLogSize = 0; - m_bRecordMode = false; - m_tLastRestart = 0; - if( loadConfig() ) m_bStatus = KH_STATUS_MTX_INIT; -} - -kernelHelperMediaMTX::~kernelHelperMediaMTX(){ - if( m_bStatus ){ - - }; -} - -bool kernelHelperMediaMTX::create(){ - LOG("Create!"); - if ( m_bStatus == KH_STATUS_MTX_NA ) return false; - struct stat tStatbuf; - if( stat( m_sAppLogFile, &tStatbuf ) == -1 ) return false; - m_nLastLogSize = tStatbuf.st_size; - char tB[128]; - sprintf( tB, "Initial Log Size: %ld", m_nLastLogSize ); - LOG( tB ); - return init(); -} - -/* - Called from the kernel loop (validateService, every second when the config does not validate). - "systemctl restart" waited for the service to stop and start (many seconds) - the kernel loop stalled - and the watchdog killed la_mojo. --no-block only queues the restart job; at most one restart per - KH_MTX_RESTART_MIN_S (a config that keeps failing validation restarted MediaMTX every second). -*/ -bool kernelHelperMediaMTX::restart(){ - time_t tNow = time( NULL ); - if ( m_tLastRestart != 0 && ( tNow - m_tLastRestart ) < KH_MTX_RESTART_MIN_S ) { - return true; // restarted a moment ago: the config is re-checked after the period - }; - m_tLastRestart = tNow; - LOG( "Restart MediaMTX (queued)" ); - int RetVal = system( "systemctl --no-block restart mediamtx.service" ); - if ( RetVal == -1 ) return false; - return true; -} - -bool kernelHelperMediaMTX::updateConfig(){ - if ( m_bStatus == KH_STATUS_MTX_NA ) return false; - FILE *fd = fopen( m_sAppConfigFile, "r+" ); - if ( fd ) { - CSTR cline = NULL; - size_t len = 0; - ssize_t read; - m_bRecordMode = false; - while (( read = getline( &cline, &len, fd )) != -1) { - cline = trim( cline ); - CSTR fPP = NULL; - if( ( fPP = strstr( cline, "paths:") ) ){ - free( cline ); - break; - } else { - free( cline ); - cline = NULL; - len = 0; - }; - }; - if ( fseek( fd , 0, SEEK_CUR ) != 0) { - LOG_ERROR("fseek failed"); - fclose( fd ); - return false; - }; - char tB[128]; - sprintf( tB,"Update %ld Stream Records", m_vStreamRecords.size() ); - LOG( tB ); - for ( uint16_t idx = 0; idx < m_vStreamRecords.size(); idx++ ){ - if ( m_vStreamRecords[idx]->node_id ) { - fprintf(fd, " stream_%ld:\n", m_vStreamRecords[idx]->node_id); - fprintf( fd, " source: %s\n", m_vStreamRecords[idx]->source_uri ); - } else LOG_ERROR("Some Junk in Stream List!!!"); - }; - - fprintf( fd, " all_others:\n\n" ); - fflush( fd ); - - // Get the descriptor and truncate the rest of the file - int fdi = fileno( fd ); - long final_pos = ftell( fd ); - ftruncate( fdi, final_pos ); - fclose( fd ); - }; - return true; -} - -bool kernelHelperMediaMTX::validateConfig(){ - if ( m_bStatus == KH_STATUS_MTX_NA ) return false; - FILE *fd = fopen( m_sAppConfigFile, "r" ); - bool retVal = true; - if ( fd ) { - CSTR cline = NULL; - CSTR fPP = NULL; - size_t len = 0; - ssize_t read; - bool bStreams = false; - uint16_t cNodeID = 0; - //Reset Statuses - for ( uint16_t idx = 0; idx < m_vStreamRecords.size(); idx++ ) m_vStreamRecords[idx]->valid = false; - - while (( read = getline( &cline, &len, fd )) != -1) { - cline = trim( cline ); - if ( !bStreams ) { - if( ( fPP = strstr( cline, "record:") ) ){ - CSTR tPP = strstr( cline, "#"); - if ( tPP == NULL || fPP < tPP ) { - fPP = strstr( cline, "true"); - if ( fPP ) { - if (tPP == NULL) { - m_bRecordMode = true; - } else { - if ( fPP < tPP ) { - m_bRecordMode = true; - }; - }; - }; - }; - }; - if ( m_bRecordMode ) { - if ( (fPP = strstr(cline, "recordPath:")) ) { - CSTR tPP = strstr( cline,"%path" ); - if ( tPP ) { - CSTR cP = trim( fPP + 11 ); - strncpy( m_sRecordsBase, cP, tPP - cP - 2 ); - m_sRecordsBase[tPP - cP-2] = (char) 0; - }; - }; - }; - if ( ( fPP = strstr(cline, "paths:")) ) bStreams = true; - } else { - if ( ( fPP = strstr(cline, "source: ")) ) { - if ( cNodeID ) { - fPP += 8; - for ( uint16_t idx = 0; idx < m_vStreamRecords.size(); idx++ ){ - if( m_vStreamRecords[idx]->node_id == cNodeID ) { - if( strcmp( m_vStreamRecords[idx]->source_uri, fPP ) == 0 ) m_vStreamRecords[idx]->valid = true; - break; - }; - }; - }; - } else { - cNodeID = 0; - if ( ( fPP = strstr(cline, "stream_") ) ){ - fPP += 7; - if( CSTR cPP = strstr(cline, ":") ){ - cPP[0] = (char)0; - cNodeID = atoi( fPP ); - }; - }; - }; - if ( ( fPP = strstr(cline, "all_others:") ) ) { - bStreams = false; - }; - }; - free( cline ); - cline = NULL; - len = 0; - }; - fclose( fd ); - }; - for ( uint16_t idx = 0; idx < m_vStreamRecords.size(); idx++ ) if( !m_vStreamRecords[idx]->valid ) retVal = false; - return retVal; -} - -bool kernelHelperMediaMTX::loadConfig(){ - FILE *fd = popen( "systemctl show mediamtx.service", "r" ); - if( fd ){ - CSTR cline = NULL; - size_t len = 0; - ssize_t read; - // Dynamically manages buffer size - while (( read = getline( &cline, &len, fd )) != -1) { - cline = trim( cline ); - CSTR fPP = NULL; - if( ( fPP = strstr( cline, "LoadState=") ) ){ - if( strncmp( fPP+10,"not-found", 9 ) == 0 ){ - LOG_ERROR( "No Service Defined!"); - break; - }; - if( strncmp( fPP+10,"loaded", 6 ) == 0 ){ - LOG( "Service is Loadded!"); - }; - }; - if( ( fPP = strstr( cline, "ActiveState=") ) ){ - if( strncmp( fPP+12,"inactive", 8 ) == 0 ){ - LOG_ERROR( "Service is Inactive!"); - }; - if( strncmp( fPP+12,"active", 6 ) == 0 ){ - LOG( "Service is Active!"); - }; - }; - if( ( fPP = strstr( cline, "SubState=") ) ){ - if( strncmp( fPP+9, "dead", 4 ) == 0 ){ - LOG( "Service is dead!"); - }; - if( strncmp( fPP+9, "running", 7 ) == 0 ){ - LOG( "Service is Running!"); - }; - }; - if( ( fPP = strstr( cline, "WorkingDirectory=") ) ){ - strncpy( m_sWorkDir, fPP+17, 512 ); - //m_sWorkDir = trim( m_sWorkDir ); - sprintf( m_sAppLogFile, "%s/mediamtx.log", m_sWorkDir ); - LOG( m_sWorkDir ); - LOG( m_sAppLogFile ); - }; - if( ( fPP = strstr( cline, "ExecStart=") ) ){ - if ( ( fPP = strstr( cline, "argv[]=") ) ) { - fPP = strstr( fPP, " " ); - CSTR sPP = strstr( fPP, ";"); - fPP++; - size_t len = sPP - fPP - 1; - strncpy( m_sAppConfigFile, fPP, len ); - LOG( m_sAppConfigFile ); - }; - }; - free( cline ); - cline = NULL; - len = 0; - }; - pclose( fd ); - }; - if ( m_sAppLogFile[0] != (char) 0 ) { - m_bStatus = KH_STATUS_MTX_INIT; - return true; - }; - return false; -} - -bool kernelHelperMediaMTX::loadStreams(){ - - DBC_INT_LIST * tL = m_pDBC->listCameras(); - if ( tL ) { - for (DBC_INT_LIST::iterator idx = tL->begin(); idx < tL->end(); idx++){ - DBC_CAM_DATA *tData = m_pDBC->getCamData( *idx ); - if ( tData ) { - if( tData->online ) assignStream( tData->stream_id ); - free( tData ); - }; - }; - delete( tL ); - }; - return true; -} - -#include -bool kernelHelperMediaMTX::validateService(){ - loadStreams(); - if( !validateConfig() ) { - updateConfig(); - return restart(); - } else { - if( m_bRecordMode ) { - uint32_t cSeconds = time( NULL ); - if( m_vStreamRecords.size() ) { - for( V_StreamDescRecords::iterator idx = m_vStreamRecords.begin(); idx != m_vStreamRecords.end(); idx++ ) { - char cStreamName[32]; - char cFolder[MAX_PATH_LEN]; - struct dirent *entry; - sprintf( cStreamName, "stream_%" PRIu64, (*idx)->node_id ); - sprintf( cFolder, "%s/%s", m_sRecordsBase, cStreamName ); - if( DIR *dir = opendir( cFolder ) ){ - M_StreamMap *tMap = NULL; - try { - tMap = m_mVideoSegments.at( (*idx)->node_id ); - } catch (const std::out_of_range & oor) { - tMap = new M_StreamMap(); - if( tMap ) { - m_mVideoSegments[(*idx)->node_id] = tMap; - } else { - LOG_ERROR("Can not create map[stream->map...]!"); - }; - }; - while( ( entry=readdir(dir) ) != NULL ){ - if ( entry->d_type == DT_REG ) { - char tFileName[MAX_PATH_LEN]; - sprintf( tFileName, "%s/%s", cFolder, entry->d_name ); - struct statx stx; - if( statx(AT_FDCWD, tFileName, AT_SYMLINK_NOFOLLOW, STATX_BTIME, &stx ) == 0 ){ - if( stx.stx_mask & STATX_BTIME ){ - uint32_t bSeconds = stx.stx_btime.tv_sec; - StreamSegmentRecord *tSI = NULL; - if( tMap ) { - try{ - tSI = tMap->at( stx.stx_ino ); - } catch( const std::out_of_range & oor ) { - tSI = createSSR( (*idx)->stream_id, stx.stx_btime.tv_sec, stx.stx_btime.tv_nsec / 1000, tFileName ); - if ( tSI ) { - (*tMap)[stx.stx_ino] = tSI; - }; - }; - }; - //More then 1 Minute - if( ( cSeconds - bSeconds ) > 61 ) { - // File Segment done - can be transfered to Report/History/RemoteServer - // In case of bonded events - if( tSI ){ - if ( tSI->keep ) { - //Create Event - }; - }; - }; - // More then 3 minutes - if ( ( cSeconds - bSeconds ) > 180 ) { - tMap->erase( stx.stx_ino ); - deleteSSR( tSI ); - unlink( tFileName ); - }; - }; - }; - }; - }; - closedir( dir ); - } else { - LOG_ERROR("Unable to open directory!"); - }; - }; - }; - }; - }; - return true; -} - -StreamSegmentRecord *kernelHelperMediaMTX::createSSR( uint32_t stream_id, uint32_t streamTSS, uint32_t streamTMS, CSTR path ){ - StreamSegmentRecord *retVal = new StreamSegmentRecord(); - if ( retVal ) { - retVal->keep = false; - retVal->SI.stream_id = stream_id; - retVal->SI.streamTSS = streamTSS; - retVal->SI.streamTMS = streamTMS; - strncpy( retVal->SI.scratchPath, path, PATH_MAX ); - CSTR tMD5 = getUniqID_MD5(); - if( tMD5 ) { - strncpy( retVal->SI.recordMD5, tMD5, 32 ); - free( tMD5 ); - }; - strncpy( retVal->SI.recordEXT, "mp4", 6); - retVal->SI.streamWidth = 1280; - retVal->SI.streamHeight = 720; - retVal->SI.streamFPS = 15; - }; - return retVal; -}; - -void kernelHelperMediaMTX::deleteSSR( StreamSegmentRecord *ptr ){ - if ( ptr == NULL ) return; - ptr->SI.eventIDS.clear(); - ptr->SI.eventFrames.clear(); - ptr->SI.eventTSS.clear(); - ptr->SI.eventTMS.clear(); - delete( ptr ); -}; - -// validateSSR - Creates Frame Records based on times -void kernelHelperMediaMTX::validateSSR( StreamSegmentRecord *ptr ){ - if ( ptr == NULL ) return; - if ( ptr->SI.eventIDS.size() ) { - uint64_t vStartMS = ptr->SI.streamTSS; - vStartMS = vStartMS * 1000 + ptr->SI.streamTMS; - float k = 1000.0f / ptr->SI.streamFPS; - for ( uint32_t i=0; i < ptr->SI.eventIDS.size(); i++ ) { - uint64_t cTS = ptr->SI.eventTSS[i]; - cTS = cTS * 1000 + ptr->SI.eventTMS[i]; - ptr->SI.eventFrames.push_back( cTS / k ); - }; - }; -}; - -bool kernelHelperMediaMTX::assignStream( uint32_t stream_id ){ - if( m_pDBC ){ - if( stream_id ){ - DBC_MEDIA_STREAM_DATA *tData = m_pDBC->getMediaStreamData( stream_id ); - if( tData ){ - StreamDescRecord *tRecord = NULL; - for ( int i = 0; i < m_vStreamRecords.size(); i++ ) { - if ( m_vStreamRecords[i]->cam_id == tData->source_id ) { - tRecord = m_vStreamRecords[i]; - break; - }; - }; - DBC_CAM_DATA * tCamData = m_pDBC->getCamData( tData->source_id ); - if( tCamData ){ - if ( tRecord ) { - sprintf( tRecord->source_uri, "%s://%s:%s@%s:%d%s", - tData->mrl_proto, - tCamData->username, - tCamData->password, - tCamData->ip, - tData->mrl_port, - tData->mrl - ); - tRecord->stream_id = stream_id; -#ifdef DEBUG_EXTRA - char tB[256]; - sprintf( tB, "Stream[%d] Updated. id: %d cam %d node %d", stream_id, tRecord->stream_id, tRecord->cam_id, tRecord->node_id ); - LOG( tB ); -#endif - } else { - tRecord = ( StreamDescRecord *) malloc( sizeof( StreamDescRecord ) ); - if( tRecord ){ - memset( tRecord, 0, sizeof( StreamDescRecord )); - sprintf( tRecord->source_uri, "%s://%s:%s@%s:%d%s", - tData->mrl_proto, - tCamData->username, - tCamData->password, - tCamData->ip, - tData->mrl_port, - tData->mrl - ); - tRecord->stream_id = stream_id; - tRecord->cam_id = tData->source_id; - tRecord->node_id = m_pDBC->getNodeIdByTypeAndAux( tCamData->type, tData->source_id ); - m_vStreamRecords.push_back( tRecord ); -#ifdef DEBUG_EXTRA - char tB[256]; - sprintf( tB, "Stream[%d] Created. id: %d cam %d node %d", stream_id, tRecord->stream_id, tRecord->cam_id, tRecord->node_id ); - LOG( tB ); -#endif - }; - }; - free( tCamData ); - }; - free( tData ); - }; - }; - }; - return false; -} - -void kernelHelperMediaMTX::m_fThreadProc(void){ - if (m_bStatus == KH_STATUS_MTX_INIT ) { - pthread_setname_np( pthread_self(), "MediaMTX_HLP" ); - m_bThreadStatus = TH_WORKING; - while (m_bThreadStatus < TH_ENDED){ - struct stat tStatbuf; - if( stat( m_sAppLogFile, &tStatbuf ) == -1 ){ - LOG_ERROR("Cannot Stat Log File!"); - //m_bThreadStatus = TH_ENDED; - } else if ( m_nLastLogSize != tStatbuf.st_size ) { - if ( m_nLastLogSize > tStatbuf.st_size ) { - // Reading at begin - m_nLastLogSize = 0; - }; - size_t RLen = tStatbuf.st_size - m_nLastLogSize; - FILE *fd = fopen( m_sAppLogFile, "r" ); - if ( fd ) { - fseek( fd, m_nLastLogSize, SEEK_SET ); - size_t len = 0; - ssize_t read; - CSTR cline = NULL; - while (( read = getline( &cline, &len, fd )) != -1) { - CSTR fPP = NULL; - if( ( fPP = strstr(cline, "ERR" ) ) ){ - //Error Message! - if ( ( fPP = strstr(cline,"RTSP source") ) ) { -#ifdef DEBUG_EXTRA - LOG("Error In Source!"); -#endif - if ( ( fPP = strstr(cline, "[path ") ) ) { - CSTR sPP = strstr( fPP, "]"); - fPP += 6; - size_t len = sPP - fPP; - char tStream_Name[128]; - strncpy( tStream_Name, fPP, len ); - tStream_Name[len] = (char)0; - if ( ( fPP = strstr( tStream_Name, "_") ) ) { - uint16_t NodeID = atoi( fPP+1 ); - if ( NodeID ) { - for ( uint16_t idx = 0; idx < m_vStreamRecords.size(); idx++ ) - if( m_vStreamRecords[idx]->node_id == NodeID ) { - m_vStreamRecords[idx]->status = KH_MTX_STREAM_ERROR; - break; - }; - }; - }; - }; - /*if ( fPP = strstr(cline, "dial tcp ")) { - CSTR sPP = strstr( fPP, ":"); - fPP += 9; - size_t len = sPP - fPP - 1; - char tIP[128]; - strncpy( tIP, fPP, len ); - tIP[len] = (char)0; - LOG( tIP ); - };*/ - }; - }; - if( ( fPP = strstr(cline, "INF" ) ) ){ - if ( ( fPP = strstr(cline,"online") ) ) { -#ifdef DEBUG_EXTRA - LOG("Source is Online!"); -#endif - if ( ( fPP = strstr(cline, "[path ") ) ) { - CSTR sPP = strstr( fPP, "]"); - fPP += 6; - size_t len = sPP - fPP; - char tStream_Name[128]; - strncpy( tStream_Name, fPP, len ); - tStream_Name[len] = (char)0; - LOG( tStream_Name ); - if ( ( fPP = strstr( tStream_Name, "_") ) ) { - uint16_t NodeID = atoi( fPP+1 ); - if ( NodeID ) { - for ( uint16_t idx = 0; idx < m_vStreamRecords.size(); idx++ ) - if( m_vStreamRecords[idx]->node_id == NodeID ) { - m_vStreamRecords[idx]->status = KH_MTX_STREAM_ONLINE; - break; - }; - }; - }; - }; - }; - if ( ( fPP = strstr(cline,"RTSP source") ) ) { - uint8_t tStatus = KH_MTX_STREAM_LOADDED; - if ( ( fPP = strstr(cline,"stopped") ) ) { - LOG("Source is Disconnected!"); - uint8_t tStatus = KH_MTX_STREAM_OFFLINE; - }; - if ( ( fPP = strstr(cline,"started") ) ) { - LOG("Source is Connected!"); - uint8_t tStatus = KH_MTX_STREAM_ONLINE; - }; - if ( ( fPP = strstr(cline, "[path ") ) ) { - CSTR sPP = strstr( fPP, "]"); - fPP += 6; - size_t len = sPP - fPP; - char tStream_Name[128]; - strncpy( tStream_Name, fPP, len ); - tStream_Name[len] = (char)0; - if ( ( fPP = strstr( tStream_Name, "_") ) ) { - uint16_t NodeID = atoi( fPP+1 ); - if ( NodeID ) { - for ( uint16_t idx = 0; idx < m_vStreamRecords.size(); idx++ ) - if( m_vStreamRecords[idx]->node_id == NodeID ) { - m_vStreamRecords[idx]->status = tStatus; - break; - }; - }; - }; - }; - }; - }; - free( cline ); - cline = NULL; - len = 0; - }; - fclose(fd); - if ( m_nLastLogSize > 40960 ) { // Clean Log > 40 KB - LOG("Cleanup Log!"); - if (truncate( m_sAppLogFile, 0) == -1) { - char tB[256]; - sprintf( tB, "Truncate failed: %s\n", strerror(errno)); - LOG_ERROR( tB ); - }; - }; - } else { - LOG_ERROR("Cannot Open Log File!"); - }; - m_nLastLogSize = tStatbuf.st_size; - }; - for( uint8_t llo=0; m_bThreadStatus < TH_ENDED, llo < 20; llo++) SLEEP(50);//One Second - }; - }; -} - -#undef LOG_ERROR -#undef LOG - -#endif // !LRF_PROXY_ONLY +#ifndef LRF_PROXY_ONLY + +#include "kernelHelperMediaMTX.h" +#include "SQLite_dataBinder.h" + +#include +#include + +#define LOG(X) m_pLog->Log("KHMTX", this, X) + +#ifdef DEBUG + #define LOG_ERROR(X) \ + { \ + char _tBfrErrMSG2w34[1024]; \ + sprintf(_tBfrErrMSG2w34, "In file %s[%d] in func:%s %s", __FILE__, __LINE__, __func__, X); \ + m_pLog->Log("KHMTX", this, _LOG_ERROR, _tBfrErrMSG2w34); \ + } +#else + #define LOG_ERROR(X) m_pLog->Log("KHMTX", this, _LOG_ERROR, X); +#endif + + +kernelHelperMediaMTX::kernelHelperMediaMTX(): basicThread() { + m_bStatus = KH_STATUS_MTX_NA; + m_pDBC = sqliteDBC::getInstance(); + m_pLog = basicLogCollection::getInstance(); + memset( m_sWorkDir, 0, 512 ); + memset( m_sAppLogFile, 0, 512 ); + memset( m_sAppConfigFile, 0, 512 ); + m_nLastLogSize = 0; + m_bRecordMode = false; + m_tLastRestart = 0; +#ifdef KH_MTX_EMBEDDED + // la_mojo records: segments of kernelModuleEmbedVideo (live_record), base folder fixed + m_bRecordMode = true; + strncpy( m_sRecordsBase, mtx_scratch_path, sizeof( m_sRecordsBase ) - 1 ); + m_sRecordsBase[sizeof( m_sRecordsBase ) - 1] = (char) 0; + m_bStatus = KH_STATUS_MTX_INIT; +#else + if( loadConfig() ) m_bStatus = KH_STATUS_MTX_INIT; +#endif +} + +kernelHelperMediaMTX::~kernelHelperMediaMTX(){ + if( m_bStatus ){ + + }; +} + +bool kernelHelperMediaMTX::create(){ + LOG("Create!"); + if ( m_bStatus == KH_STATUS_MTX_NA ) return false; +#ifdef KH_MTX_EMBEDDED + // The live view is served by la_mojo: the MediaMTX service would hold the WebRTC port (8889) + LOG( "Embedded live view: stopping the MediaMTX service (queued)" ); + if ( system( "systemctl --no-block stop mediamtx.service >/dev/null 2>&1" ) == -1 ) LOG_ERROR( "systemctl failed" ); + return true; // no log to follow +#endif + struct stat tStatbuf; + if( stat( m_sAppLogFile, &tStatbuf ) == -1 ) return false; + m_nLastLogSize = tStatbuf.st_size; + char tB[128]; + sprintf( tB, "Initial Log Size: %ld", m_nLastLogSize ); + LOG( tB ); + return init(); +} + +/* + Called from the kernel loop (validateService, every second when the config does not validate). + "systemctl restart" waited for the service to stop and start (many seconds) - the kernel loop stalled + and the watchdog killed la_mojo. --no-block only queues the restart job; at most one restart per + KH_MTX_RESTART_MIN_S (a config that keeps failing validation restarted MediaMTX every second). +*/ +bool kernelHelperMediaMTX::restart(){ + time_t tNow = time( NULL ); + if ( m_tLastRestart != 0 && ( tNow - m_tLastRestart ) < KH_MTX_RESTART_MIN_S ) { + return true; // restarted a moment ago: the config is re-checked after the period + }; + m_tLastRestart = tNow; + LOG( "Restart MediaMTX (queued)" ); + int RetVal = system( "systemctl --no-block restart mediamtx.service" ); + if ( RetVal == -1 ) return false; + return true; +} + +bool kernelHelperMediaMTX::updateConfig(){ + if ( m_bStatus == KH_STATUS_MTX_NA ) return false; + FILE *fd = fopen( m_sAppConfigFile, "r+" ); + if ( fd ) { + CSTR cline = NULL; + size_t len = 0; + ssize_t read; + m_bRecordMode = false; + while (( read = getline( &cline, &len, fd )) != -1) { + cline = trim( cline ); + CSTR fPP = NULL; + if( ( fPP = strstr( cline, "paths:") ) ){ + free( cline ); + break; + } else { + free( cline ); + cline = NULL; + len = 0; + }; + }; + if ( fseek( fd , 0, SEEK_CUR ) != 0) { + LOG_ERROR("fseek failed"); + fclose( fd ); + return false; + }; + char tB[128]; + sprintf( tB,"Update %ld Stream Records", m_vStreamRecords.size() ); + LOG( tB ); + for ( uint16_t idx = 0; idx < m_vStreamRecords.size(); idx++ ){ + if ( m_vStreamRecords[idx]->node_id ) { + fprintf(fd, " stream_%ld:\n", m_vStreamRecords[idx]->node_id); + fprintf( fd, " source: %s\n", m_vStreamRecords[idx]->source_uri ); + } else LOG_ERROR("Some Junk in Stream List!!!"); + }; + + fprintf( fd, " all_others:\n\n" ); + fflush( fd ); + + // Get the descriptor and truncate the rest of the file + int fdi = fileno( fd ); + long final_pos = ftell( fd ); + ftruncate( fdi, final_pos ); + fclose( fd ); + }; + return true; +} + +bool kernelHelperMediaMTX::validateConfig(){ + if ( m_bStatus == KH_STATUS_MTX_NA ) return false; + FILE *fd = fopen( m_sAppConfigFile, "r" ); + bool retVal = true; + if ( fd ) { + CSTR cline = NULL; + CSTR fPP = NULL; + size_t len = 0; + ssize_t read; + bool bStreams = false; + uint16_t cNodeID = 0; + //Reset Statuses + for ( uint16_t idx = 0; idx < m_vStreamRecords.size(); idx++ ) m_vStreamRecords[idx]->valid = false; + + while (( read = getline( &cline, &len, fd )) != -1) { + cline = trim( cline ); + if ( !bStreams ) { + if( ( fPP = strstr( cline, "record:") ) ){ + CSTR tPP = strstr( cline, "#"); + if ( tPP == NULL || fPP < tPP ) { + fPP = strstr( cline, "true"); + if ( fPP ) { + if (tPP == NULL) { + m_bRecordMode = true; + } else { + if ( fPP < tPP ) { + m_bRecordMode = true; + }; + }; + }; + }; + }; + if ( m_bRecordMode ) { + if ( (fPP = strstr(cline, "recordPath:")) ) { + CSTR tPP = strstr( cline,"%path" ); + if ( tPP ) { + CSTR cP = trim( fPP + 11 ); + strncpy( m_sRecordsBase, cP, tPP - cP - 2 ); + m_sRecordsBase[tPP - cP-2] = (char) 0; + }; + }; + }; + if ( ( fPP = strstr(cline, "paths:")) ) bStreams = true; + } else { + if ( ( fPP = strstr(cline, "source: ")) ) { + if ( cNodeID ) { + fPP += 8; + for ( uint16_t idx = 0; idx < m_vStreamRecords.size(); idx++ ){ + if( m_vStreamRecords[idx]->node_id == cNodeID ) { + if( strcmp( m_vStreamRecords[idx]->source_uri, fPP ) == 0 ) m_vStreamRecords[idx]->valid = true; + break; + }; + }; + }; + } else { + cNodeID = 0; + if ( ( fPP = strstr(cline, "stream_") ) ){ + fPP += 7; + if( CSTR cPP = strstr(cline, ":") ){ + cPP[0] = (char)0; + cNodeID = atoi( fPP ); + }; + }; + }; + if ( ( fPP = strstr(cline, "all_others:") ) ) { + bStreams = false; + }; + }; + free( cline ); + cline = NULL; + len = 0; + }; + fclose( fd ); + }; + for ( uint16_t idx = 0; idx < m_vStreamRecords.size(); idx++ ) if( !m_vStreamRecords[idx]->valid ) retVal = false; + return retVal; +} + +bool kernelHelperMediaMTX::loadConfig(){ + FILE *fd = popen( "systemctl show mediamtx.service", "r" ); + if( fd ){ + CSTR cline = NULL; + size_t len = 0; + ssize_t read; + // Dynamically manages buffer size + while (( read = getline( &cline, &len, fd )) != -1) { + cline = trim( cline ); + CSTR fPP = NULL; + if( ( fPP = strstr( cline, "LoadState=") ) ){ + if( strncmp( fPP+10,"not-found", 9 ) == 0 ){ + LOG_ERROR( "No Service Defined!"); + break; + }; + if( strncmp( fPP+10,"loaded", 6 ) == 0 ){ + LOG( "Service is Loadded!"); + }; + }; + if( ( fPP = strstr( cline, "ActiveState=") ) ){ + if( strncmp( fPP+12,"inactive", 8 ) == 0 ){ + LOG_ERROR( "Service is Inactive!"); + }; + if( strncmp( fPP+12,"active", 6 ) == 0 ){ + LOG( "Service is Active!"); + }; + }; + if( ( fPP = strstr( cline, "SubState=") ) ){ + if( strncmp( fPP+9, "dead", 4 ) == 0 ){ + LOG( "Service is dead!"); + }; + if( strncmp( fPP+9, "running", 7 ) == 0 ){ + LOG( "Service is Running!"); + }; + }; + if( ( fPP = strstr( cline, "WorkingDirectory=") ) ){ + strncpy( m_sWorkDir, fPP+17, 512 ); + //m_sWorkDir = trim( m_sWorkDir ); + sprintf( m_sAppLogFile, "%s/mediamtx.log", m_sWorkDir ); + LOG( m_sWorkDir ); + LOG( m_sAppLogFile ); + }; + if( ( fPP = strstr( cline, "ExecStart=") ) ){ + if ( ( fPP = strstr( cline, "argv[]=") ) ) { + fPP = strstr( fPP, " " ); + CSTR sPP = strstr( fPP, ";"); + fPP++; + size_t len = sPP - fPP - 1; + strncpy( m_sAppConfigFile, fPP, len ); + LOG( m_sAppConfigFile ); + }; + }; + free( cline ); + cline = NULL; + len = 0; + }; + pclose( fd ); + }; + if ( m_sAppLogFile[0] != (char) 0 ) { + m_bStatus = KH_STATUS_MTX_INIT; + return true; + }; + return false; +} + +bool kernelHelperMediaMTX::loadStreams(){ + + DBC_INT_LIST * tL = m_pDBC->listCameras(); + if ( tL ) { + for (DBC_INT_LIST::iterator idx = tL->begin(); idx < tL->end(); idx++){ + DBC_CAM_DATA *tData = m_pDBC->getCamData( *idx ); + if ( tData ) { + if( tData->online ) assignStream( tData->stream_id ); + free( tData ); + }; + }; + delete( tL ); + }; + return true; +} + +#include +bool kernelHelperMediaMTX::validateService(){ + loadStreams(); +#ifdef KH_MTX_EMBEDDED + if( false ) { +#else + if( !validateConfig() ) { +#endif + updateConfig(); + return restart(); + } else { + if( m_bRecordMode ) { + uint32_t cSeconds = time( NULL ); + if( m_vStreamRecords.size() ) { + for( V_StreamDescRecords::iterator idx = m_vStreamRecords.begin(); idx != m_vStreamRecords.end(); idx++ ) { + char cStreamName[32]; + char cFolder[MAX_PATH_LEN]; + struct dirent *entry; + sprintf( cStreamName, "stream_%" PRIu64, (*idx)->node_id ); + sprintf( cFolder, "%s/%s", m_sRecordsBase, cStreamName ); + if( DIR *dir = opendir( cFolder ) ){ + M_StreamMap *tMap = NULL; + try { + tMap = m_mVideoSegments.at( (*idx)->node_id ); + } catch (const std::out_of_range & oor) { + tMap = new M_StreamMap(); + if( tMap ) { + m_mVideoSegments[(*idx)->node_id] = tMap; + } else { + LOG_ERROR("Can not create map[stream->map...]!"); + }; + }; + while( ( entry=readdir(dir) ) != NULL ){ + if ( entry->d_type == DT_REG ) { + char tFileName[MAX_PATH_LEN]; + sprintf( tFileName, "%s/%s", cFolder, entry->d_name ); + struct statx stx; + if( statx(AT_FDCWD, tFileName, AT_SYMLINK_NOFOLLOW, STATX_BTIME, &stx ) == 0 ){ + if( stx.stx_mask & STATX_BTIME ){ + uint32_t bSeconds = stx.stx_btime.tv_sec; + StreamSegmentRecord *tSI = NULL; + if( tMap ) { + try{ + tSI = tMap->at( stx.stx_ino ); + } catch( const std::out_of_range & oor ) { + tSI = createSSR( (*idx)->stream_id, stx.stx_btime.tv_sec, stx.stx_btime.tv_nsec / 1000, tFileName ); + if ( tSI ) { + (*tMap)[stx.stx_ino] = tSI; + }; + }; + }; + //More then 1 Minute + if( ( cSeconds - bSeconds ) > 61 ) { + // File Segment done - can be transfered to Report/History/RemoteServer + // In case of bonded events + if( tSI ){ + if ( tSI->keep ) { + //Create Event + }; + }; + }; + // More then 3 minutes + if ( ( cSeconds - bSeconds ) > 180 ) { + tMap->erase( stx.stx_ino ); + deleteSSR( tSI ); + unlink( tFileName ); + }; + }; + }; + }; + }; + closedir( dir ); + } else if ( errno != ENOENT ) { // no folder: nothing recorded yet (stream not online) + LOG_ERROR("Unable to open directory!"); + }; + }; + }; + }; + }; + return true; +} + +StreamSegmentRecord *kernelHelperMediaMTX::createSSR( uint32_t stream_id, uint32_t streamTSS, uint32_t streamTMS, CSTR path ){ + StreamSegmentRecord *retVal = new StreamSegmentRecord(); + if ( retVal ) { + retVal->keep = false; + retVal->SI.stream_id = stream_id; + retVal->SI.streamTSS = streamTSS; + retVal->SI.streamTMS = streamTMS; + strncpy( retVal->SI.scratchPath, path, PATH_MAX ); + CSTR tMD5 = getUniqID_MD5(); + if( tMD5 ) { + strncpy( retVal->SI.recordMD5, tMD5, 32 ); + free( tMD5 ); + }; + strncpy( retVal->SI.recordEXT, "mp4", 6); + retVal->SI.streamWidth = 1280; + retVal->SI.streamHeight = 720; + retVal->SI.streamFPS = 15; + }; + return retVal; +}; + +void kernelHelperMediaMTX::deleteSSR( StreamSegmentRecord *ptr ){ + if ( ptr == NULL ) return; + ptr->SI.eventIDS.clear(); + ptr->SI.eventFrames.clear(); + ptr->SI.eventTSS.clear(); + ptr->SI.eventTMS.clear(); + delete( ptr ); +}; + +// validateSSR - Creates Frame Records based on times +void kernelHelperMediaMTX::validateSSR( StreamSegmentRecord *ptr ){ + if ( ptr == NULL ) return; + if ( ptr->SI.eventIDS.size() ) { + uint64_t vStartMS = ptr->SI.streamTSS; + vStartMS = vStartMS * 1000 + ptr->SI.streamTMS; + float k = 1000.0f / ptr->SI.streamFPS; + for ( uint32_t i=0; i < ptr->SI.eventIDS.size(); i++ ) { + uint64_t cTS = ptr->SI.eventTSS[i]; + cTS = cTS * 1000 + ptr->SI.eventTMS[i]; + ptr->SI.eventFrames.push_back( cTS / k ); + }; + }; +}; + +bool kernelHelperMediaMTX::assignStream( uint32_t stream_id ){ + if( m_pDBC ){ + if( stream_id ){ + DBC_MEDIA_STREAM_DATA *tData = m_pDBC->getMediaStreamData( stream_id ); + if( tData ){ + StreamDescRecord *tRecord = NULL; + for ( int i = 0; i < m_vStreamRecords.size(); i++ ) { + if ( m_vStreamRecords[i]->cam_id == tData->source_id ) { + tRecord = m_vStreamRecords[i]; + break; + }; + }; + DBC_CAM_DATA * tCamData = m_pDBC->getCamData( tData->source_id ); + if( tCamData ){ + if ( tRecord ) { + sprintf( tRecord->source_uri, "%s://%s:%s@%s:%d%s", + tData->mrl_proto, + tCamData->username, + tCamData->password, + tCamData->ip, + tData->mrl_port, + tData->mrl + ); + tRecord->stream_id = stream_id; +#ifdef DEBUG_EXTRA + char tB[256]; + sprintf( tB, "Stream[%d] Updated. id: %d cam %d node %d", stream_id, tRecord->stream_id, tRecord->cam_id, tRecord->node_id ); + LOG( tB ); +#endif + } else { + tRecord = ( StreamDescRecord *) malloc( sizeof( StreamDescRecord ) ); + if( tRecord ){ + memset( tRecord, 0, sizeof( StreamDescRecord )); + sprintf( tRecord->source_uri, "%s://%s:%s@%s:%d%s", + tData->mrl_proto, + tCamData->username, + tCamData->password, + tCamData->ip, + tData->mrl_port, + tData->mrl + ); + tRecord->stream_id = stream_id; + tRecord->cam_id = tData->source_id; + tRecord->node_id = m_pDBC->getNodeIdByTypeAndAux( tCamData->type, tData->source_id ); + m_vStreamRecords.push_back( tRecord ); +#ifdef DEBUG_EXTRA + char tB[256]; + sprintf( tB, "Stream[%d] Created. id: %d cam %d node %d", stream_id, tRecord->stream_id, tRecord->cam_id, tRecord->node_id ); + LOG( tB ); +#endif + }; + }; + free( tCamData ); + }; + free( tData ); + }; + }; + }; + return false; +} + +void kernelHelperMediaMTX::m_fThreadProc(void){ + if (m_bStatus == KH_STATUS_MTX_INIT ) { + pthread_setname_np( pthread_self(), "MediaMTX_HLP" ); + m_bThreadStatus = TH_WORKING; + while (m_bThreadStatus < TH_ENDED){ + struct stat tStatbuf; + if( stat( m_sAppLogFile, &tStatbuf ) == -1 ){ + LOG_ERROR("Cannot Stat Log File!"); + //m_bThreadStatus = TH_ENDED; + } else if ( m_nLastLogSize != tStatbuf.st_size ) { + if ( m_nLastLogSize > tStatbuf.st_size ) { + // Reading at begin + m_nLastLogSize = 0; + }; + size_t RLen = tStatbuf.st_size - m_nLastLogSize; + FILE *fd = fopen( m_sAppLogFile, "r" ); + if ( fd ) { + fseek( fd, m_nLastLogSize, SEEK_SET ); + size_t len = 0; + ssize_t read; + CSTR cline = NULL; + while (( read = getline( &cline, &len, fd )) != -1) { + CSTR fPP = NULL; + if( ( fPP = strstr(cline, "ERR" ) ) ){ + //Error Message! + if ( ( fPP = strstr(cline,"RTSP source") ) ) { +#ifdef DEBUG_EXTRA + LOG("Error In Source!"); +#endif + if ( ( fPP = strstr(cline, "[path ") ) ) { + CSTR sPP = strstr( fPP, "]"); + fPP += 6; + size_t len = sPP - fPP; + char tStream_Name[128]; + strncpy( tStream_Name, fPP, len ); + tStream_Name[len] = (char)0; + if ( ( fPP = strstr( tStream_Name, "_") ) ) { + uint16_t NodeID = atoi( fPP+1 ); + if ( NodeID ) { + for ( uint16_t idx = 0; idx < m_vStreamRecords.size(); idx++ ) + if( m_vStreamRecords[idx]->node_id == NodeID ) { + m_vStreamRecords[idx]->status = KH_MTX_STREAM_ERROR; + break; + }; + }; + }; + }; + /*if ( fPP = strstr(cline, "dial tcp ")) { + CSTR sPP = strstr( fPP, ":"); + fPP += 9; + size_t len = sPP - fPP - 1; + char tIP[128]; + strncpy( tIP, fPP, len ); + tIP[len] = (char)0; + LOG( tIP ); + };*/ + }; + }; + if( ( fPP = strstr(cline, "INF" ) ) ){ + if ( ( fPP = strstr(cline,"online") ) ) { +#ifdef DEBUG_EXTRA + LOG("Source is Online!"); +#endif + if ( ( fPP = strstr(cline, "[path ") ) ) { + CSTR sPP = strstr( fPP, "]"); + fPP += 6; + size_t len = sPP - fPP; + char tStream_Name[128]; + strncpy( tStream_Name, fPP, len ); + tStream_Name[len] = (char)0; + LOG( tStream_Name ); + if ( ( fPP = strstr( tStream_Name, "_") ) ) { + uint16_t NodeID = atoi( fPP+1 ); + if ( NodeID ) { + for ( uint16_t idx = 0; idx < m_vStreamRecords.size(); idx++ ) + if( m_vStreamRecords[idx]->node_id == NodeID ) { + m_vStreamRecords[idx]->status = KH_MTX_STREAM_ONLINE; + break; + }; + }; + }; + }; + }; + if ( ( fPP = strstr(cline,"RTSP source") ) ) { + uint8_t tStatus = KH_MTX_STREAM_LOADDED; + if ( ( fPP = strstr(cline,"stopped") ) ) { + LOG("Source is Disconnected!"); + uint8_t tStatus = KH_MTX_STREAM_OFFLINE; + }; + if ( ( fPP = strstr(cline,"started") ) ) { + LOG("Source is Connected!"); + uint8_t tStatus = KH_MTX_STREAM_ONLINE; + }; + if ( ( fPP = strstr(cline, "[path ") ) ) { + CSTR sPP = strstr( fPP, "]"); + fPP += 6; + size_t len = sPP - fPP; + char tStream_Name[128]; + strncpy( tStream_Name, fPP, len ); + tStream_Name[len] = (char)0; + if ( ( fPP = strstr( tStream_Name, "_") ) ) { + uint16_t NodeID = atoi( fPP+1 ); + if ( NodeID ) { + for ( uint16_t idx = 0; idx < m_vStreamRecords.size(); idx++ ) + if( m_vStreamRecords[idx]->node_id == NodeID ) { + m_vStreamRecords[idx]->status = tStatus; + break; + }; + }; + }; + }; + }; + }; + free( cline ); + cline = NULL; + len = 0; + }; + fclose(fd); + if ( m_nLastLogSize > 40960 ) { // Clean Log > 40 KB + LOG("Cleanup Log!"); + if (truncate( m_sAppLogFile, 0) == -1) { + char tB[256]; + sprintf( tB, "Truncate failed: %s\n", strerror(errno)); + LOG_ERROR( tB ); + }; + }; + } else { + LOG_ERROR("Cannot Open Log File!"); + }; + m_nLastLogSize = tStatbuf.st_size; + }; + for( uint8_t llo=0; m_bThreadStatus < TH_ENDED, llo < 20; llo++) SLEEP(50);//One Second + }; + }; +} + +#undef LOG_ERROR +#undef LOG + +#endif // !LRF_PROXY_ONLY diff --git a/lib/App/common/kernelHelperMediaMTX.h b/lib/App/common/kernelHelperMediaMTX.h index a4abd84c..bd9e9fd4 100644 --- a/lib/App/common/kernelHelperMediaMTX.h +++ b/lib/App/common/kernelHelperMediaMTX.h @@ -1,86 +1,95 @@ -#ifndef __KERNEL_HELPER_MEDIA_MTX_HEADER__ -#define __KERNEL_HELPER_MEDIA_MTX_HEADER__ - -#ifndef LRF_PROXY_ONLY - -#include "dataBinder.h" -#include "../../components/base/basicThread.h" -#include -#include -#include -#include - - -#define mtx_scratch_path "/dev/shm/argus/video_scratch" - -typedef struct S_StreamDescRecord{ - uint32_t cam_id; - uint64_t node_id; - uint32_t stream_id; - uint8_t status; - bool valid; - char source_uri[512]; -}StreamDescRecord; - -typedef std::vector V_StreamDescRecords; - -#define KH_STATUS_MTX_NA 0 -#define KH_STATUS_MTX_INIT 1 -#define KH_STATUS_MTX_AOK 2 -#define KH_STATUS_MTX_ERR 255 - -#define KH_MTX_STREAM_LOADDED 0 -#define KH_MTX_STREAM_REGISTERED 1 -#define KH_MTX_STREAM_ONLINE 2 -#define KH_MTX_STREAM_OFFLINE 3 -#define KH_MTX_STREAM_ERROR 255 - -typedef struct S_StreamSegmentRecord{ - bool keep; - VIDEO_SEGMENT_INFO SI; -}StreamSegmentRecord; - -typedef std::map M_StreamMap; // inodes -> info -typedef std::map M_VideoSegmentInfo; // stream_id -> map - - -// At most one MediaMTX restart per this period (a config that keeps failing validation restarted it every second) -#ifndef KH_MTX_RESTART_MIN_S - #define KH_MTX_RESTART_MIN_S 30 -#endif - -class kernelHelperMediaMTX: public basicThread { - private: - basicLogCollection * m_pLog; - dataBinder * m_pDBC; - V_StreamDescRecords m_vStreamRecords; - M_VideoSegmentInfo m_mVideoSegments; - uint8_t m_bStatus; - char m_sWorkDir[512]; - char m_sAppLogFile[512]; - char m_sAppConfigFile[512]; - char m_sRecordsBase[MAX_PATH_LEN]; - off_t m_nLastLogSize; - bool m_bRecordMode; - time_t m_tLastRestart; // last restart() (rate limit) - bool loadConfig(); - bool loadStreams(); - StreamSegmentRecord * createSSR( uint32_t stream_id, uint32_t streamTSS, uint32_t streamTMS, CSTR path ); - void deleteSSR( StreamSegmentRecord *ptr ); - void validateSSR( StreamSegmentRecord *ptr ); - protected: - virtual void m_fThreadProc(void); - public: - kernelHelperMediaMTX(); - virtual ~kernelHelperMediaMTX(); - bool create(); - bool validateConfig(); - bool assignStream( uint32_t stream_id ); - bool updateConfig(); - bool restart(); - bool validateService(); - uint8_t getStatus(){ return m_bStatus; }; -}; - -#endif // ! LRF_PROXY_ONLY +#ifndef __KERNEL_HELPER_MEDIA_MTX_HEADER__ +#define __KERNEL_HELPER_MEDIA_MTX_HEADER__ + +#ifndef LRF_PROXY_ONLY + +#include "dataBinder.h" +#include "../../components/base/basicThread.h" +#include +#include +#include +#include + + +#define mtx_scratch_path "/dev/shm/argus/video_scratch" + +/* + KH_MTX_EMBEDDED: la_mojo serves the live view and records by itself (kernelModuleEmbedVideo with the + MediaMtx library). The helper no longer writes mediamtx.yml, restarts or reads the log of the MediaMTX + service; it stops the service once (it would hold port 8889) and only indexes the recorded segments + (/stream_/*.mp4). Undefine it to go back to the external MediaMTX service. + The helper is to be removed once the indexing moved into kernelModuleEmbedVideo. +*/ +#define KH_MTX_EMBEDDED + +typedef struct S_StreamDescRecord{ + uint32_t cam_id; + uint64_t node_id; + uint32_t stream_id; + uint8_t status; + bool valid; + char source_uri[512]; +}StreamDescRecord; + +typedef std::vector V_StreamDescRecords; + +#define KH_STATUS_MTX_NA 0 +#define KH_STATUS_MTX_INIT 1 +#define KH_STATUS_MTX_AOK 2 +#define KH_STATUS_MTX_ERR 255 + +#define KH_MTX_STREAM_LOADDED 0 +#define KH_MTX_STREAM_REGISTERED 1 +#define KH_MTX_STREAM_ONLINE 2 +#define KH_MTX_STREAM_OFFLINE 3 +#define KH_MTX_STREAM_ERROR 255 + +typedef struct S_StreamSegmentRecord{ + bool keep; + VIDEO_SEGMENT_INFO SI; +}StreamSegmentRecord; + +typedef std::map M_StreamMap; // inodes -> info +typedef std::map M_VideoSegmentInfo; // stream_id -> map + + +// At most one MediaMTX restart per this period (a config that keeps failing validation restarted it every second) +#ifndef KH_MTX_RESTART_MIN_S + #define KH_MTX_RESTART_MIN_S 30 +#endif + +class kernelHelperMediaMTX: public basicThread { + private: + basicLogCollection * m_pLog; + dataBinder * m_pDBC; + V_StreamDescRecords m_vStreamRecords; + M_VideoSegmentInfo m_mVideoSegments; + uint8_t m_bStatus; + char m_sWorkDir[512]; + char m_sAppLogFile[512]; + char m_sAppConfigFile[512]; + char m_sRecordsBase[MAX_PATH_LEN]; + off_t m_nLastLogSize; + bool m_bRecordMode; + time_t m_tLastRestart; // last restart() (rate limit) + bool loadConfig(); + bool loadStreams(); + StreamSegmentRecord * createSSR( uint32_t stream_id, uint32_t streamTSS, uint32_t streamTMS, CSTR path ); + void deleteSSR( StreamSegmentRecord *ptr ); + void validateSSR( StreamSegmentRecord *ptr ); + protected: + virtual void m_fThreadProc(void); + public: + kernelHelperMediaMTX(); + virtual ~kernelHelperMediaMTX(); + bool create(); + bool validateConfig(); + bool assignStream( uint32_t stream_id ); + bool updateConfig(); + bool restart(); + bool validateService(); + uint8_t getStatus(){ return m_bStatus; }; +}; + +#endif // ! LRF_PROXY_ONLY #endif \ No newline at end of file diff --git a/lib/App/common/kernelModuleEmbedVideo.cpp b/lib/App/common/kernelModuleEmbedVideo.cpp index f6f4af18..7f304ade 100644 --- a/lib/App/common/kernelModuleEmbedVideo.cpp +++ b/lib/App/common/kernelModuleEmbedVideo.cpp @@ -20,6 +20,7 @@ #include "../alg/generic/base64.h" #include "../data/media/video/videoAVLIBSource.h" #include "../data/media/video/videoLive555AVLibSource.h" +#include "../../data/media/mtx/servers/webrtc/webrtcServer.h" #include #include @@ -100,6 +101,7 @@ kernelModuleEmbedVideo::kernelModuleEmbedVideo(uint32_t moduleID) : LOG_ERROR("No DB Data Error!"); memset(&m_sEmbedVideoData, 0, sizeof(DBC_MODULE_EMBED_VIDEO_DATA)); m_sEmbedVideoData.port = 8972; + dbcEmbedVideoLiveDefaults(&m_sEmbedVideoData); }; } else @@ -107,6 +109,24 @@ kernelModuleEmbedVideo::kernelModuleEmbedVideo(uint32_t moduleID) : LOG_ERROR("DB Error!"); }; m_bDetached = true; + m_tLiveRetry = 0; + // The MediaMtx library logs into the la_mojo log (tag MTX) + mtx::Logger::instance().setDestinations(false, std::string()); + mtx::Logger::instance().setSink([](mtx::LogLevel level, const char * line) { + if (level == mtx::LogLevel::Debug) + { + return; + } + if (level == mtx::LogLevel::Error) + { + basicLogCollection::getInstance()->Log("MTX", NULL, _LOG_ERROR, line); + } + else + { + basicLogCollection::getInstance()->Log("MTX", NULL, line); + } + }); + applyLiveSettings(); n_pNoSignalData = NULL; m_nNoSignalSize = 0; #ifdef HAVE_SMAL_PREVIEW_STREAMS @@ -194,6 +214,7 @@ kernelModuleEmbedVideo::~kernelModuleEmbedVideo() { stopService(true); }; + stopLive(); // the WebRTC server uses this object (PathProvider): stop it before the members go // Sanity check LOG("Sanity check in Destructor!"); @@ -1536,6 +1557,8 @@ bool kernelModuleEmbedVideo::startService() #else // !EVE_WORK_WITH_MEDIAMTX m_bEnabled = true; #endif // !EVE_WORK_WITH_MEDIAMTX + applyLiveSettings(); + startLive(); // a failure (port in use) is retried by validate() return m_bEnabled; } @@ -1567,6 +1590,7 @@ bool kernelModuleEmbedVideo::stopService(bool force) m_mapHANDLERS.clear(); }; m_mStreamHandlersProtector.unlock(); + stopLive(); // after the handlers: they released their feeds #ifndef EVE_WORK_WITH_MEDIAMTX @@ -1691,6 +1715,11 @@ bool kernelModuleEmbedVideo::reloadSettings() bool kernelModuleEmbedVideo::validate() { bool RetVal = true; + // The WebRTC server could not start (e.g. the port was still used by the MediaMTX service): retry + if (m_bEnabled && m_sEmbedVideoData.live_mode != EVE_LIVE_OFF && ! m_pWebrtc && time(NULL) >= m_tLiveRetry) + { + startLive(); + }; deviceNode ** tA = NULL; uint32_t tCNT = deviceNodeFactory::getInstance()->fetchNodes(ARGUS_ANALOG_STATIC_CAMERA, tA); if( tCNT ){ @@ -2424,6 +2453,106 @@ cv::Mat *kernelModuleEmbedVideo::getCurrentFrame( uint32_t streamID ){ return retVal; } +/* ---------------------------------------------------------------- live view (WebRTC) and recording */ + +void kernelModuleEmbedVideo::applyLiveSettings() +{ + m_sLiveConf = mtx::ServerConf(); + m_sLiveConf.webrtcAddress = ":" + std::to_string(m_sEmbedVideoData.live_port ? m_sEmbedVideoData.live_port : 8889); + // next to the module's own clips; kernelHelperMediaMTX indexes /stream_/*.mp4 + m_sLiveConf.recordPath = std::string(m_pVideoScratchPath) + "/%path/%Y-%m-%d_%H-%M-%S-%f"; + m_sLiveConf.recordSegmentDurationMs = (int64_t) (m_sEmbedVideoData.live_record_segment ? m_sEmbedVideoData.live_record_segment : 60) * 1000; + m_sLiveConf.recordPartDurationMs = 1000; + m_sLiveConf.webrtcICEServers.clear(); + std::string tIce(m_sEmbedVideoData.live_ice_servers); + size_t tPos = 0; + while (tPos < tIce.size()) + { + size_t tEnd = tIce.find_first_of(", ", tPos); + std::string tOne = tIce.substr(tPos, tEnd == std::string::npos ? std::string::npos : tEnd - tPos); + if (! tOne.empty()) + { + m_sLiveConf.webrtcICEServers.push_back(tOne); + }; + if (tEnd == std::string::npos) + { + break; + }; + tPos = tEnd + 1; + }; +} + +bool kernelModuleEmbedVideo::startLive() +{ + if (m_sEmbedVideoData.live_mode == EVE_LIVE_OFF) + { + return true; + }; + if (m_pWebrtc) + { + return true; + }; + std::unique_ptr tServer(new mtx::WebrtcServer(m_sLiveConf, this)); + std::string tErr; + if (! tServer->start(tErr)) + { + char tB[512]; + snprintf(tB, sizeof(tB), "Live view: the WebRTC server cannot listen on %s (%s) - retry in 10 s", m_sLiveConf.webrtcAddress.c_str(), tErr.c_str()); + LOG_ERROR(tB); + m_tLiveRetry = time(NULL) + 10; + return false; + }; + m_pWebrtc = std::move(tServer); + char tB[256]; + snprintf(tB, sizeof(tB), "Live view: WebRTC (WHEP) on %s, %s, recording %s", m_sLiveConf.webrtcAddress.c_str(), + m_sEmbedVideoData.live_mode == EVE_LIVE_ENCODE ? "processed frames (encoded)" : "camera H264 (passthrough)", m_sEmbedVideoData.live_record ? "on" : "off"); + LOG(tB); + return true; +} + +void kernelModuleEmbedVideo::stopLive() +{ + if (m_pWebrtc) + { + m_pWebrtc->stop(); // closes the sessions (they hold their paths) + m_pWebrtc.reset(); + }; + std::map> tPaths; + { + std::lock_guard lock(m_mLivePaths); + tPaths.swap(m_mapLivePaths); + } + for (auto & p : tPaths) + { + p.second->sourceSetNotReady(); // closes the recording + }; +} + +std::shared_ptr kernelModuleEmbedVideo::livePath(uint32_t nodeID) +{ + if (m_sEmbedVideoData.live_mode == EVE_LIVE_OFF || nodeID == 0) + { + return nullptr; + }; + std::string tName = "stream_" + std::to_string(nodeID); + std::lock_guard lock(m_mLivePaths); + auto it = m_mapLivePaths.find(tName); + if (it != m_mapLivePaths.end()) + { + return it->second; + }; + auto tPath = std::make_shared(tName, m_sEmbedVideoData.live_record, m_sLiveConf); + m_mapLivePaths[tName] = tPath; + return tPath; +} + +std::shared_ptr kernelModuleEmbedVideo::findPath(const std::string & name) const +{ + std::lock_guard lock(m_mLivePaths); + auto it = m_mapLivePaths.find(name); + return (it == m_mapLivePaths.end()) ? nullptr : it->second; +} + #undef TLOG #undef TLOG_ERROR diff --git a/lib/App/common/kernelModuleEmbedVideo.h b/lib/App/common/kernelModuleEmbedVideo.h index e4492fe9..f70c4819 100644 --- a/lib/App/common/kernelModuleEmbedVideo.h +++ b/lib/App/common/kernelModuleEmbedVideo.h @@ -18,6 +18,12 @@ extern const char * m_pVideoScratchPath; // #include "../../data/media/video/videoAVLIBDestination.h" #include "../../components/base/basicMediaDestination.h" #include "../../components/base/basicMediaSource.h" + #include "../../data/media/mtx/core/mediaPath.h" + #include + #include + #include + #include + namespace mtx { class WebrtcServer; } class streamHandler; typedef map mapSTREAMHANDLERS; #ifndef EVE_WORK_WITH_MEDIAMTX @@ -72,7 +78,18 @@ typedef struct S_VIDEO_EVT typedef map mapSTREAMMAPS; -class kernelModuleEmbedVideo : public kernelModule +/* + Live view and continuous recording (replaces the MediaMTX service) + + Every stream handler feeds a path "stream_" (the names MediaMTX had: the dashboard + plays http://:8889/stream_/whep). live_mode selects what the path carries: + - EVE_LIVE_PASSTHROUGH: the camera's H264 as the source receives it (no CPU, original quality) + - EVE_LIVE_ENCODE: the processed frames of this module (time stamp, label, logo, event marks) + encoded to H264 (streamLiveEncoder) + The paths outlive the stream handlers (a stalled stream is rebuilt; the viewers reconnect to the same + path). The WebRTC (WHEP) server and the recorder are the MediaMtx library (lib/data/media/mtx). +*/ +class kernelModuleEmbedVideo : public kernelModule, public mtx::PathProvider #ifndef EVE_WORK_WITH_MEDIAMTX , public basicDualThread @@ -113,6 +130,16 @@ class kernelModuleEmbedVideo : public kernelModule bool saveStreamPicture(uint32_t id); bool saveStreamPicture(DBC_SNAPSHOT_DATA * ptr); bool generateSavePicPath(CSTR MD5, CSTR Output); + + // Live view (WebRTC) and recording + mtx::ServerConf m_sLiveConf; + std::unique_ptr m_pWebrtc; + time_t m_tLiveRetry; // next start attempt of the WebRTC server + mutable std::mutex m_mLivePaths; + std::map> m_mapLivePaths; + void applyLiveSettings(); + bool startLive(); + void stopLive(); #ifndef EVE_WORK_WITH_MEDIAMTX protected: @@ -144,6 +171,13 @@ class kernelModuleEmbedVideo : public kernelModule uint8_t getMediaMode(void); bool isProcessingVideoStream(); cv::Mat * getCurrentFrame( uint32_t streamID ); + // Live view: the mode, and the path of a camera node (created on first use; nullptr: live view off) + uint8_t getLiveMode(void) const { return m_sEmbedVideoData.live_mode; } + uint8_t getLiveFps(void) const { return m_sEmbedVideoData.live_fps; } + uint16_t getLiveBitrate(void) const { return m_sEmbedVideoData.live_bitrate; } + std::shared_ptr livePath(uint32_t nodeID); + // mtx::PathProvider (the WebRTC server looks up the path of a WHEP request) + std::shared_ptr findPath(const std::string & name) const override; friend class streamHandler; }; #else //LRF_PROXY_ONLY diff --git a/lib/App/common/streamHandler.cpp b/lib/App/common/streamHandler.cpp index 6239e6fe..86aa31ee 100644 --- a/lib/App/common/streamHandler.cpp +++ b/lib/App/common/streamHandler.cpp @@ -1,3810 +1,3901 @@ -#include "streamHandler.h" - -//#define DEBUG_EXTRA - -#ifndef LRF_PROXY_ONLY -// #include "rgooseHardwareResourceNetworkProvider.h" -// #include "mojoKernel.h" -#include "../alg/generic/base64.h" -#include "../data/media/video/videoAVLIBSource.h" -#include "../data/media/video/videoLive555AVLibSource.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include /* MIN() */ -#include -#include -#include - -// #define DEBUG -// #undef DEBUG_EXTRA - - -#ifndef STORAGE_DIR_MODE - #define STORAGE_DIR_MODE 0x1FF -#endif - -#ifndef STORAGE_FILE_MODE - #define STORAGE_FILE_MODE 0x1B6 -#endif - -#define LOG(X) m_pLog->Log("MEV_STR", this, X) -#ifdef DEBUG - #define LOG_ERROR(X) \ - { \ - char _tBfrErrMSG2w34[256]; \ - sprintf(_tBfrErrMSG2w34, "In file %s[%d] in func:%s %s", __FILE__, __LINE__, __func__, X); \ - m_pLog->Log("MEV_STR", this, _LOG_ERROR, _tBfrErrMSG2w34); \ - } -#else - #define LOG_ERROR(X) m_pLog->Log("MEV_STR", this, _LOG_ERROR, X); -#endif - -streamHandler::streamHandler(kernelModuleEmbedVideo * ptr, MS_WORK_MODE M, uint8_t flip_mode) : - basicMediaDestination() -#ifdef EVE_ENABLE_VIDEO - , basicThread() -#endif -{ - m_pMaster = ptr; - m_eWM = M; - m_pLog = basicLogCollection::getInstance(); - - LOG("Constructor Begin!"); - - memset(&m_sStreamData, 0, sizeof(DBC_MEDIA_STREAM_DATA)); - m_pSource = NULL; - m_nValidatorFrameCounter = 0; - m_nStallChecks = 0; - m_tLastFrameProgress = time(NULL); - m_bEvtMarkerCounter = 0; - m_bCamMoveCounter = 0; - m_bFlipMode = flip_mode; - -#ifdef EVE_ENABLE_VIDEO - #ifdef EVE_SEQUENTAL_OUTPUT - m_nSegFrameCounter = 0; - m_nGlobalFrameCounter = 0; - m_nSegShiftFrames = 0; - m_nSegSkippedFrames = 0; - m_bSegActive = false; - m_bSegDelete = true; - m_bNSegDelete = true; - #else - m_nPreAlarmFrames = 0; - m_nPostAlarmFrames = 0; - m_nSegmentLimitFrames = 0; - m_nHardLimitFrames = 0; - m_nSegAFrameCounter = 0; - m_nSegBFrameCounter = 0; - m_nGlobalFrameCounter = 0; - - m_nSegAShiftFrames = 0; - m_nSegBShiftFrames = 0; - m_nSegASkippedFrames = m_nSegBSkippedFrames = 0; - - m_bActiveEncoderStream = 0; - m_bSegAActive = false; - m_bSegADelete = true; - m_bSegBActive = false; - m_bSegBDelete = true; - #endif // !EVE_SEQUENTAL_OUTPUT - - m_bCOP = 0; - m_cSourceType = 'A'; - - //todo: must be writen helper function to clean VIDEO_SEGMENT_INFO - //that is not dynamicaly created by NEW operator - - //memset(&m_sStreamSegmentInfo[0], 0, sizeof(VIDEO_SEGMENT_INFO)); - //memset(&m_sStreamSegmentInfo[1], 0, sizeof(VIDEO_SEGMENT_INFO)); - #ifdef DIRECT_MJPEG_COMPOSING - #ifndef EVE_SEQUENTAL_OUTPUT - m_pOutputFD[0] = NULL; - m_pOutputFD[1] = NULL; - #else - m_pOutputFD = NULL; - #endif - #else // !DIRECT_MJPEG_COMPOSING - #ifdef OPENCV_VIDEO_OUTPUT - #ifndef EVE_SEQUENTAL_OUTPUT - m_pEncoderA = NULL; - m_pEncoderB = NULL; - #else - m_pEncoder = NULL; - #endif - #endif - #endif -#endif // EVE_ENABLE_VIDEO - // if( M == MS_MODE_DECODE_FRAMES ) 1=1; -#ifdef DEBUG_EXTRA - LOG("Constructor Done!"); -#endif -} - -streamHandler::~streamHandler() -{ - if (m_sStreamData.id) - { - if (m_pSource != NULL) - { - switch (m_cSourceType) - { // m_sStreamData.source_type[0] ) { - case 'D': delete((videoLIVE555Source *) m_pSource); break; - case 'A': delete((videoAVLIBSource *) m_pSource); break; - }; - }; -#ifdef EVE_ENABLE_VIDEO - closeAll(); -#endif // EVE_ENABLE_VIDEO - }; -#ifdef EVE_ENABLE_VIDEO - // Encoder thread is stopped at this point - release frames still waiting in the queue - waitThreadEnd(true); - m_mEncodingQueueProtector.lock(); - while (! m_qEncodingQueue.empty()) - { - ENCODING_BUFFER * tData = m_qEncodingQueue.front(); - m_qEncodingQueue.pop(); - if (tData) - { - #if defined(DIRECT_MJPEG_COMPOSING) || defined(OPENCV_VIDEO_OUTPUT) - if (tData->data) - { - free(tData->data); - } - #else - if (tData->data[0]) - { - free(tData->data[0]); - } - #endif - free(tData); - }; - }; - m_mEncodingQueueProtector.unlock(); -#endif // EVE_ENABLE_VIDEO -} - -bool streamHandler::create(dataBinder * ptr, uint32_t stremID) -{ - if (ptr == NULL) - { - return false; - } - m_pDBC = ptr; - if (stremID) - { - DBC_MEDIA_STREAM_DATA * tData = m_pDBC->getMediaStreamData(stremID); - if (tData) - { -#ifdef DEBUG_EXTRA - LOG("Have Stream Info"); -#endif - memcpy(&m_sStreamData, tData, sizeof(DBC_MEDIA_STREAM_DATA)); - free(tData); - DBC_CAM_DATA * tCAM = m_pDBC->getCamData(m_sStreamData.source_id); - if (tCAM) - { -#ifdef DEBUG_EXTRA - LOG("Have Cam Info"); -#endif - m_sSourceDesc.mediaStreamId = stremID; - - m_sSourceDesc.mediaSourceId = m_sStreamData.source_id; - uint32_t tNID = m_pDBC->getNodeIdByTypeAndAux(tCAM->type, m_sStreamData.source_id); - // ToDo: Check Camera Addition - // Just Work around to handle Wrong tyoe 12 instead of 13 - if (tNID == 0) - { - tNID = m_pDBC->getNodeIdByTypeAndAux(13, m_sStreamData.source_id); - }; - if (tNID) - { - CSTR tNAM = m_pDBC->getNodeName(tNID); - if (tNAM != NULL) - { - strncpy(m_sSourceDesc.mediaName, tNAM, 127); - m_sSourceDesc.mediaName[127] = (char) 0; - free(tNAM); - } - else - { - sprintf(m_sSourceDesc.mediaName, "No Name Cam"); - }; - } - else - { - sprintf(m_sSourceDesc.mediaName, "No-Name-Cam"); - }; - - m_cSourceType = m_sStreamData.source_type[0]; - - switch (m_cSourceType) - { - case 'A': m_pSource = (basicMediaSource *) new videoAVLIBSource(&m_sSourceDesc); break; - case 'D': - { - - // Check Auth mode if basic - Override and use AVLIB - // To Debug LIVE555 ONLY - if( tCAM->auth_mode == 0){ - m_cSourceType = 'A'; - m_pSource = (basicMediaSource *) new videoAVLIBSource(&m_sSourceDesc); - break; - } else{ - - m_pSource = (basicMediaSource *) new videoLIVE555Source(&m_sSourceDesc); - break; - }; - //m_pSource = (basicMediaSource *) new videoLIVE555Source(&m_sSourceDesc); - //m_cSourceType = 'A'; // To use corect Destructor! - //m_pSource = (basicMediaSource *) new videoAVLIBSource(&m_sSourceDesc); - break; - }; - }; - if (m_pSource != NULL) - { - char tMRL[1024]; -#ifdef DEBUG_EXTRA - LOG("Source OK"); -#endif - int tW = m_pMaster->getWidh(); - int tH = m_pMaster->getHeight(); - int pix = -1; - bool in_16_9 = (((m_sStreamData.width * 100) / m_sStreamData.height) > 140); - bool out_16_9 = (((tW * 100) / tH) > 140); - // if( tW > 0 ){ - // //m_pSource->setProportionalByWidth( tW ); - // m_pSource->setSize( tW, tH ); - // }; - if (in_16_9 != out_16_9) - { - if (in_16_9) - { - tH = (((tW * 1000) / 16) * 9) / 1000; - } - else - { - tW = (((tH * 1000) / 3) * 4) / 1000; - }; - }; - // export PATH=/usr/sbin:$PATH - if (strncmp(m_sStreamData.mrl_proto, "v4l2", 4) == 0) - { - sprintf(tMRL, m_sStreamData.mrl); - pix = atoi(m_sStreamData.c_type); - } - else - { - sprintf(tMRL, "%s://%s:%s@%s:%d%s", m_sStreamData.mrl_proto, tCAM->username, tCAM->password, tCAM->ip, m_sStreamData.mrl_port, m_sStreamData.mrl); - }; -#ifdef DEBUG_EXTRA - LOG( tMRL ); -#endif - if (m_pSource->_open(tMRL, false, -1.0f, pix, m_sStreamData.width, m_sStreamData.height, tW, tH)){ - if (! m_pSource->attachDestination(this)){ - switch (m_cSourceType){ - case 'D': delete((videoLIVE555Source *) m_pSource); break; - case 'A': delete((videoAVLIBSource *) m_pSource); break; - }; - m_pSource = NULL; - } else { -#ifdef DEBUG_EXTRA - LOG("Source is Connected to Output."); -#endif - }; - } else { - LOG_ERROR("Can not Open Video Source!"); - switch (m_cSourceType) { - case 'D': delete((videoLIVE555Source *) m_pSource); break; - case 'A': delete((videoAVLIBSource *) m_pSource); break; - }; - m_pSource = NULL; - }; - } else { - LOG_ERROR("Video Source Stream Failure!"); - }; - free(tCAM); - } else { - LOG_ERROR("Error Getting CAM Data!"); - m_pSource = NULL; - return false; - }; - }; - }; - - if ( m_pSource ){ -#ifdef EVE_ENABLE_VIDEO - return initVideoOutput(); -#else - return true; -#endif // EVE_ENABLE_VIDEO - }; - - return false; -} - -bool streamHandler::pushFrame(AVFrame * Frame, void * src) -{ - if( !Frame ) return false; - if( !m_pMaster )return false; - - MEDIA_SOURCE_DESC * tMD = (MEDIA_SOURCE_DESC *) src; - if (tMD) - { - }; - return true; -} - -bool streamHandler::pushFrame(cv::Mat & Frame, void * src) -{ - - /// @todo Valgrind is reporting an important memory leak in this method. - if (m_pMaster == NULL) - { - return false; - } - MEDIA_SOURCE_DESC * tMD = (MEDIA_SOURCE_DESC *) src; - char tBuffer[512]; - if (tMD) - { - float mK, oK; - cv::Rect ROI; - - m_pMaster->m_mPictureProtector.lock(); - - if (m_pMaster->m_mapMATS[tMD->mediaStreamId].cols == 0) - { - LOG("First Frame Enqueued"); - sprintf(tBuffer, "INP: [%dx%d] SrcID:%d StreamID:%d", Frame.cols, Frame.rows, tMD->mediaSourceId, tMD->mediaStreamId); - LOG(tBuffer); - - m_pMaster->m_mapMATS[tMD->mediaStreamId].create(m_pMaster->m_sEmbedVideoData.height, m_pMaster->m_sEmbedVideoData.width, CV_8UC3); - cv::rectangle(m_pMaster->m_mapMATS[tMD->mediaStreamId], cv::Point(0, 0), cv::Point(m_pMaster->m_sEmbedVideoData.height, m_pMaster->m_sEmbedVideoData.width), cv::Scalar(0, 0, 0), cv::FILLED); - }; - -#ifdef USE_SCALING_IN - oK = ((float) m_pMaster->m_sEmbedVideoData.height) / ((float) m_pMaster->m_sEmbedVideoData.width); - mK = ((float) Frame.rows) / ((float) Frame.cols); - // sprintf( tBuffer, "INP: [%dx%d] IK:%0.3f OK:%0.3f", Frame.cols, Frame.rows, mK, oK ); - if ((fabsf(mK - oK) < 0.1f) || (fabsf(oK - mK) < 0.1f)) - { - ROI.width = (int) m_pMaster->m_sEmbedVideoData.width; - ROI.height = (int) m_pMaster->m_sEmbedVideoData.height; - ROI.x = (int) 0; - ROI.y = (int) 0; - } - else - { - if (mK < oK) - { - ROI.width = (int) m_pMaster->m_sEmbedVideoData.width; - ROI.height = (int) (((float) m_pMaster->m_sEmbedVideoData.width) * mK); - ROI.x = (int) 0; - ROI.y = (int) (m_pMaster->m_sEmbedVideoData.height - ROI.height) >> 1; - } - else - { - ROI.height = (int) m_pMaster->m_sEmbedVideoData.height; - ROI.width = (int) (((float) m_pMaster->m_sEmbedVideoData.height) / mK); - ROI.y = (int) 0; - ROI.x = (int) (m_pMaster->m_sEmbedVideoData.width - ROI.width) >> 1; - }; - }; - cv::Mat mROI = m_pMaster->m_mapMATS[tMD->mediaStreamId](ROI); - #ifndef USE_CV_DENOISE - cv::resize(Frame, mROI, mROI.size(), 0, 0, cv::INTER_LINEAR); - #else - cv::Mat mDenoiser; - cv::resize(Frame, mDenoiser, mROI.size(), 0, 0, cv::INTER_LINEAR); - cv::fastNlMeansDenoisingColored(mDenoiser, mROI, 10, 10, 7, 17); - #endif - #ifdef USE_CV_TONEMAP - cv::Mat ldrReinhard; - cv::Ptr tonemapReinhard = cv::createTonemapReinhard(1.5, 0, 0, 0); - tonemapReinhard->process(mROI, ldrReinhard); - ldrReinhard = ldrReinhard * 255; - ldrReinhard.copyTo(mROI); - #endif -#else - if ((m_pMaster->m_sEmbedVideoData.height == Frame.rows) && (m_pMaster->m_sEmbedVideoData.width == Frame.cols)) - { - Frame.copyTo(m_pMaster->m_mapMATS[tMD->mediaStreamId]); - } - else - { - // Mat dst_roi = dst(Rect(left, top, src.cols, src.rows)); - // src.copyTo(dst_roi); - - if (m_pMaster->m_sEmbedVideoData.width == Frame.cols) - { - ROI.width = Frame.cols; - ROI.height = Frame.rows; - ROI.x = 0; - ROI.y = (m_pMaster->m_sEmbedVideoData.height - Frame.rows) >> 1; - cv::Mat mROI = m_pMaster->m_mapMATS[tMD->mediaStreamId](ROI); - #ifdef USE_CV_DENOISE - cv::fastNlMeansDenoisingColored(Frame, mROI, 10, 10, 7, 17); - #else - Frame.copyTo(mROI); - #endif - #ifdef USE_CV_TONEMAP - cv::Mat ldrReinhard; - cv::Ptr tonemapReinhard = cv::createTonemapReinhard(1.5, 0, 0, 0); - tonemapReinhard->process(mROI, ldrReinhard); - ldrReinhard = ldrReinhard * 255; - ldrReinhard.copyTo(mROI); - #endif - } - else - { - ROI.width = Frame.cols; - ROI.height = Frame.rows; - ROI.x = (m_pMaster->m_sEmbedVideoData.width - Frame.cols) >> 1; - ROI.y = 0; - cv::Mat mROI = m_pMaster->m_mapMATS[tMD->mediaStreamId](ROI); - #ifdef USE_CV_DENOISE - cv::fastNlMeansDenoisingColored(Frame, mROI, 10, 10, 7, 17); - #else - Frame.copyTo(mROI); - #endif - #ifdef USE_CV_TONEMAP - cv::Mat ldrReinhard; - cv::Ptr tonemapReinhard = cv::createTonemapReinhard(1.5, 0, 0, 0); - tonemapReinhard->process(mROI, ldrReinhard); - ldrReinhard = ldrReinhard * 255; - ldrReinhard.copyTo(mROI); - #endif - }; - }; -#endif - // 0 - dis .. 1 - Hor ... 2 - vert 3 - both - if (m_bFlipMode) - { - // Flip Horizontally = 1 vertically = 0 both = -1 - cv::Mat mirroredImage; - cv::flip(m_pMaster->m_mapMATS[tMD->mediaStreamId], mirroredImage, 2 - m_bFlipMode); - mirroredImage.copyTo(m_pMaster->m_mapMATS[tMD->mediaStreamId]); - }; - -#ifdef EVE_ENABLE_DROP_OUTPUT_FPS - // LOG("T"); - m_mEncodingQueueProtector.lock(); - if (m_qEncodingQueue.size() > 10) - { - m_mEncodingQueueProtector.unlock(); - m_pMaster->m_mPictureProtector.unlock(); - // LOG("D"); - return true; - }; - m_mEncodingQueueProtector.unlock(); - // LOG("Q"); -#endif - - if (m_bCamMoveCounter > m_bEvtMarkerCounter) - { - cv::rectangle(m_pMaster->m_mapMATS[tMD->mediaStreamId], cv::Rect(10, 10, 20, 20), cv::Scalar(m_bCamMoveCounter, 0, 0), cv::FILLED); - m_bCamMoveCounter -= 4; - if (m_bCamMoveCounter < 4) - { - m_bCamMoveCounter = 0; - } - } - else - { - if (m_bEvtMarkerCounter) - { - m_bCamMoveCounter = 0; - cv::rectangle(m_pMaster->m_mapMATS[tMD->mediaStreamId], cv::Rect(10, 10, 20, 20), cv::Scalar(0, 0, m_bEvtMarkerCounter), cv::FILLED); - m_bEvtMarkerCounter -= 4; - if (m_bEvtMarkerCounter < 4) - { - m_bEvtMarkerCounter = 0; - } - }; - }; - if (m_pMaster->m_sEmbedVideoData.show_label) - { - time_t t = time(NULL); - // struct tm * tmp = gmtime( &t ); - struct tm * tmp = localtime(&t); - if (tmp) - { - char tsb[64]; - // if( strftime( tsb, sizeof(tsb), "%F %T GMT", tmp )!=0 ){ - if (strftime(tsb, sizeof(tsb), "%F %T", tmp) != 0) - { - - // sprintf( tBuffer, ">>%d>%d>%s>%s>", tMD->mediaSourceId, tMD->mediaStreamId, tMD->mediaName, tsb ); - sprintf(tBuffer, ">>>%s>%s>", tMD->mediaName, tsb); - int baseline = 0; - cv::Size textSize = cv::getTextSize(tBuffer, m_pMaster->m_sEmbedVideoData.label_font_face, m_pMaster->m_sEmbedVideoData.label_font_scale, m_pMaster->m_sEmbedVideoData.label_font_thickness, &baseline); - int x = m_pMaster->m_sEmbedVideoData.label_x; - int y = m_pMaster->m_sEmbedVideoData.label_y; - if (x < 0) - { - x = m_pMaster->m_sEmbedVideoData.width + x - textSize.width; - }; - if (y < 0) - { - y = m_pMaster->m_sEmbedVideoData.height + y - baseline; // - }; - if (! m_pMaster->m_sEmbedVideoData.label_transperant) - { - cv::rectangle(m_pMaster->m_mapMATS[tMD->mediaStreamId], cv::Rect(x, y - textSize.height - 4, textSize.width, textSize.height + baseline + 4), cv::Scalar(0, 0, 0), cv::FILLED); - }; - cv::putText(m_pMaster->m_mapMATS[tMD->mediaStreamId], tBuffer, cv::Point(x, y), (cv::HersheyFonts) m_pMaster->m_sEmbedVideoData.label_font_face, m_pMaster->m_sEmbedVideoData.label_font_scale, cv::Scalar(0, 255, 0), - m_pMaster->m_sEmbedVideoData.label_font_thickness, m_pMaster->m_sEmbedVideoData.label_line_type); - }; - }; - } - else - { - if (m_pMaster->m_sEmbedVideoData.show_ts) - { - time_t t = time(NULL); - // struct tm * tmp = gmtime( &t ); - struct tm * tmp = localtime(&t); - if (tmp) - { - if (strftime(tBuffer, sizeof(tBuffer), "%F %T GMT", tmp) != 0) - { - uint8_t shift_x = 0; - uint8_t shift_y = 15; - if (! m_pMaster->m_sEmbedVideoData.ts_transperant) - { - if (m_pMaster->m_sEmbedVideoData.ts_font_face) - { - shift_y = 15; - cv::rectangle(m_pMaster->m_mapMATS[tMD->mediaStreamId], cv::Point(m_pMaster->m_sEmbedVideoData.ts_x, m_pMaster->m_sEmbedVideoData.ts_y), cv::Point(490, 60), cv::Scalar(0, 0, 0), cv::FILLED); - } - else - { - shift_y = 23; - cv::rectangle(m_pMaster->m_mapMATS[tMD->mediaStreamId], cv::Point(m_pMaster->m_sEmbedVideoData.ts_x, m_pMaster->m_sEmbedVideoData.ts_y), cv::Point(490, 60), cv::Scalar(0, 0, 0), cv::FILLED); - }; - cv::putText(m_pMaster->m_mapMATS[tMD->mediaStreamId], tBuffer, cv::Point(m_pMaster->m_sEmbedVideoData.ts_x + shift_x, m_pMaster->m_sEmbedVideoData.ts_y + shift_y), - (cv::HersheyFonts) m_pMaster->m_sEmbedVideoData.ts_font_face, m_pMaster->m_sEmbedVideoData.ts_font_scale, cv::Scalar(0, 255, 255), m_pMaster->m_sEmbedVideoData.ts_font_thickness, - m_pMaster->m_sEmbedVideoData.ts_line_type); - } - else - { - if (m_pMaster->m_sEmbedVideoData.ts_font_face) - { - shift_y = 15; - } - else - { - shift_y = 23; - }; - cv::putText(m_pMaster->m_mapMATS[tMD->mediaStreamId], tBuffer, cv::Point(m_pMaster->m_sEmbedVideoData.ts_x + shift_x - 1, m_pMaster->m_sEmbedVideoData.ts_y + shift_y - 1), - (cv::HersheyFonts) m_pMaster->m_sEmbedVideoData.ts_font_face, m_pMaster->m_sEmbedVideoData.ts_font_scale, cv::Scalar(0, 0, 0), m_pMaster->m_sEmbedVideoData.ts_font_thickness, m_pMaster->m_sEmbedVideoData.ts_line_type); - cv::putText(m_pMaster->m_mapMATS[tMD->mediaStreamId], tBuffer, cv::Point(m_pMaster->m_sEmbedVideoData.ts_x + shift_x + 1, m_pMaster->m_sEmbedVideoData.ts_y + shift_y - 1), - (cv::HersheyFonts) m_pMaster->m_sEmbedVideoData.ts_font_face, m_pMaster->m_sEmbedVideoData.ts_font_scale, cv::Scalar(0, 0, 0), m_pMaster->m_sEmbedVideoData.ts_font_thickness, m_pMaster->m_sEmbedVideoData.ts_line_type); - cv::putText(m_pMaster->m_mapMATS[tMD->mediaStreamId], tBuffer, cv::Point(m_pMaster->m_sEmbedVideoData.ts_x + shift_x - 1, m_pMaster->m_sEmbedVideoData.ts_y + shift_y + 1), - (cv::HersheyFonts) m_pMaster->m_sEmbedVideoData.ts_font_face, m_pMaster->m_sEmbedVideoData.ts_font_scale, cv::Scalar(0, 0, 0), m_pMaster->m_sEmbedVideoData.ts_font_thickness, m_pMaster->m_sEmbedVideoData.ts_line_type); - cv::putText(m_pMaster->m_mapMATS[tMD->mediaStreamId], tBuffer, cv::Point(m_pMaster->m_sEmbedVideoData.ts_x + shift_x - 1, m_pMaster->m_sEmbedVideoData.ts_y + shift_y + 2), - (cv::HersheyFonts) m_pMaster->m_sEmbedVideoData.ts_font_face, m_pMaster->m_sEmbedVideoData.ts_font_scale, cv::Scalar(0, 0, 0), m_pMaster->m_sEmbedVideoData.ts_font_thickness, m_pMaster->m_sEmbedVideoData.ts_line_type); - cv::putText(m_pMaster->m_mapMATS[tMD->mediaStreamId], tBuffer, cv::Point(m_pMaster->m_sEmbedVideoData.ts_x + shift_x, m_pMaster->m_sEmbedVideoData.ts_y + shift_y), - (cv::HersheyFonts) m_pMaster->m_sEmbedVideoData.ts_font_face, m_pMaster->m_sEmbedVideoData.ts_font_scale, cv::Scalar(0, 255, 255), m_pMaster->m_sEmbedVideoData.ts_font_thickness, - m_pMaster->m_sEmbedVideoData.ts_line_type); - } - }; - }; - }; - }; - if (m_pMaster->m_sEmbedVideoData.show_logo) - { - cv::Rect roi(cv::Point(m_pMaster->m_sEmbedVideoData.logo_x, m_pMaster->m_sEmbedVideoData.logo_y), cv::Size(m_pMaster->m_sEmbedVideoData.logo_w, m_pMaster->m_sEmbedVideoData.logo_h)); - cv::Mat destinationROI = m_pMaster->m_mapMATS[tMD->mediaStreamId](roi); - m_pMaster->m_mLogoPic.copyTo(destinationROI, m_pMaster->m_mLogoMask); - }; - -#ifndef EVE_WORK_WITH_MEDIAMTX - vector compression_params; - // compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION); - // compression_params.push_back(9); - compression_params.push_back(cv::IMWRITE_JPEG_QUALITY); - compression_params.push_back(50); // m_pMaster->m_sEmbedVideoData.compression_quality ); - - m_pMaster->m_mEncodedProtector.lock(); - m_pMaster->m_mapCAPTURES[tMD->mediaStreamId].clear(); - cv::imencode(".jpg", m_pMaster->m_mapMATS[tMD->mediaStreamId], m_pMaster->m_mapCAPTURES[tMD->mediaStreamId], compression_params); - - // cv::Mat bw_dst; - // cv::cvtColor( m_pMaster->m_mapMATS[tMD->mediaStreamId], bw_dst, cv::COLOR_BGR2GRAY ); - // cv::imencode( ".jpg", bw_dst, m_pMaster->m_mapCAPTURES[tMD->mediaStreamId], compression_params ); - - #ifdef HAVE_SMAL_PREVIEW_STREAMS - // Make Small Preview Thumb - cv::Mat dst; - cv::resize(m_pMaster->m_mapMATS[tMD->mediaStreamId], dst, cv::Size(PREVIEW_SIZE_WIDTH, PREVIEW_SIZE_HEIGHT)); - // cv::resize( bw_dst, dst, cv::Size( PREVIEW_SIZE_WIDTH, PREVIEW_SIZE_HEIGHT )); - - m_pMaster->m_mapPREVIEWS[tMD->mediaStreamId].clear(); - cv::imencode(".jpg", dst, m_pMaster->m_mapPREVIEWS[tMD->mediaStreamId], compression_params); - #endif -#endif // !EVE_WORK_WITH_MEDIAMTX - m_pMaster->m_mEncodedProtector.unlock(); - -#ifdef EVE_ENABLE_VIDEO - // if only decode Video Stream -> Exit - // To handle video recording elsewhere (For Steph) - if (m_eWM == MS_MODE_DECODE_FRAMES) - { - m_pMaster->m_mPictureProtector.unlock(); - return true; - }; - // encode Video Stream - - // m_nPreAlarmFrames - // m_nPostAlarmFrames - // m_nNoAlarmSegmentFrames - // m_nSegmentLimitFrames - // m_nHardLimitFrames - #ifdef EVE_SEQUENTAL_OUTPUT - if ( m_bSegActive ) - { // The Open/Close is management ath Encoder Thread Procedure - #else // !EVE_SEQUENTAL_OUTPUT - if (m_bSegAActive || m_bSegBActive) - { - m_mFrameCounterProtector.lock(); - if( m_bSegAActive ) { - if (m_nSegAFrameCounter > m_nHardLimitFrames) { - #ifdef DEBUG_EXTRA - LOG("HardLimit Reached!(A)"); - #endif - closeSegmentA(); - // break; - }; - if (m_nSegAFrameCounter > (m_nSegmentLimitFrames - (m_nPostAlarmFrames + m_nPreAlarmFrames))){ - if (! m_bSegBActive){ - #ifdef DEBUG_EXTRA - LOG("Start Alt!(A)"); - #endif - openSegmentB(); - }; - }; - if (m_nSegAFrameCounter > (m_nSegmentLimitFrames - m_nPostAlarmFrames) && ! m_bActiveEncoderStream){ - #ifdef DEBUG_EXTRA - LOG("Swap Active!(A)"); - #endif - swapActiveStreams(); - }; - }; - - if( m_bSegBActive ){ - if (m_nSegBFrameCounter > m_nBHardLimitFrames){ - #ifdef DEBUG_EXTRA - LOG("HardLimit Reached!(B)"); - #endif - closeSegmentB(); - }; - if (m_nSegBFrameCounter > (m_nBSegmentLimitFrames - (m_nBPostAlarmFrames + m_nAPreAlarmFrames))){ - if (! m_bSegAActive){ - #ifdef DEBUG_EXTRA - LOG("Start Alt!(B)"); - #endif - openSegmentA(); - }; - }; - if (m_nSegBFrameCounter > (m_nBSegmentLimitFrames - m_nBPostAlarmFrames) && m_bActiveEncoderStream){ - #ifdef DEBUG_EXTRA - LOG("Swap Active!(B)"); - #endif - swapActiveStreams(); - }; - }; - m_mFrameCounterProtector.unlock(); - #endif // !EVE_SEQUENTAL_OUTPUT - - - // Transfer Data to Encoder Thread - - ENCODING_BUFFER * tData = (ENCODING_BUFFER *) malloc(sizeof(ENCODING_BUFFER)); - if (tData) - { - #ifdef DIRECT_MJPEG_COMPOSING - tData->size = m_pMaster->m_mapCAPTURES[tMD->mediaStreamId].size(); - tData->data = (uint8_t *) malloc(tData->size); - if (tData->data) - { - memcpy(tData->data, m_pMaster->m_mapCAPTURES[tMD->mediaStreamId].data(), tData->size); - // Aproach to reference and not copy data ... was not such a good idea - // tData->data = m_pMaster->m_mapCAPTURES[tMD->mediaStreamId].data(); - // if ( tData->data ) { - #else - #ifdef OPENCV_VIDEO_OUTPUT - tData->rows = m_pMaster->m_mapMATS[tMD->mediaStreamId].rows; - tData->cols = m_pMaster->m_mapMATS[tMD->mediaStreamId].cols; - tData->size = m_pMaster->m_mapMATS[tMD->mediaStreamId].cols * m_pMaster->m_mapMATS[tMD->mediaStreamId].elemSize() * tData->rows; - tData->data = (uint8_t *) malloc(tData->size); - if (tData->data) - { - memcpy(tData->data, m_pMaster->m_mapMATS[tMD->mediaStreamId].data, tData->size); - #else // OPENCV_VIDEO_OUTPUT - tData->linesize[0] = m_pMaster->m_mapMATS[tMD->mediaStreamId].cols * m_pMaster->m_mapMATS[tMD->mediaStreamId].elemSize(); - tData->linesize[1] = 0; - tData->rows = m_pMaster->m_mapMATS[tMD->mediaStreamId].rows; - tData->size = tData->linesize[0] * tData->rows; - tData->data[1] = NULL; - tData->data[0] = (uint8_t *) malloc(tData->size); - if (tData->data[0]) - { - memcpy(tData->data[0], m_pMaster->m_mapMATS[tMD->mediaStreamId].data, tData->size); - #endif // OPENCV_VIDEO_OUTPUT - #endif //! DIRECT_MJPEG_COMPOSING - m_mEncodingQueueProtector.lock(); - m_qEncodingQueue.push(tData); - m_mEncodingQueueProtector.unlock(); - } - else - { - LOG_ERROR("MAT_CPY malloc Error!"); - free(tData); - }; - } - else - { - LOG_ERROR("ENC_BUF malloc Error!"); - } - }; -#endif // EVE_ENABLE_VIDEO - m_pMaster->m_mPictureProtector.unlock(); - } - else - { - LOG_ERROR("No PayLoad!"); - }; - return true; -} - -#ifdef EVE_ENABLE_VIDEO - #ifdef EVE_SEQUENTAL_OUTPUT - /* - bool streamHandler::openSegment(void){ - if (!m_bSegActive) - { - CSTR tAM = getUniqID_MD5(); - if(tAM) - { - sprintf(m_sStreamSegmentInfo.scratchPath, "%s/%s.%s", m_pVideoScratchPath, tAM, VIDEO_OUTPUT_CONTAINER); - strncpy(m_sStreamSegmentInfo.recordMD5, tAM, 32); - m_sStreamSegmentInfo.recordMD5[32] = (char) 0; - free(tAM); - m_sStreamSegmentInfo.stream_id = m_sStreamData.id; - PF_TIMESTAMP ts; - getPFTS(&ts); - m_sStreamSegmentInfo.streamTSS = ts.seconds; - m_sStreamSegmentInfo.streamTMS = ts.milliseconds; - #ifdef DEBUG_EXTRA - char tB[128]; - sprintf(tB, "A opened %d.%d", m_sStreamSegmentInfo.streamTSS, m_sStreamSegmentInfo.streamTMS); - LOG(tB); - #endif - strncpy(m_sStreamSegmentInfo.recordEXT, VIDEO_OUTPUT_CONTAINER, 6); - m_sStreamSegmentInfo.streamFPS = m_sStreamData.fps; - m_sStreamSegmentInfo.streamWidth = m_pMaster->getWidh(); - m_sStreamSegmentInfo.streamHeight = m_pMaster->getHeight(); - m_sStreamSegmentInfo.eventIDS.clear(); - m_sStreamSegmentInfo.eventTSS.clear(); - m_sStreamSegmentInfo.eventTMS.clear(); - m_sStreamSegmentInfo.eventFrames.clear(); - m_sStreamSegmentInfo.dataSize = 0; - m_sStreamSegmentInfo.db_id = 0; - #ifdef DIRECT_MJPEG_COMPOSING - m_pOutputFD = fopen(m_sStreamSegmentInfo.scratchPath, "wb+"); - m_nSegFrameCounter = 0; - m_nSegShiftFrames = 0; - m_bSegActive = true; - m_bSegDelete = m_bNSegDelete; - m_bNSegDelete = true; - #else // !DIRECT_MJPEG_COMPOSING - #ifdef OPENCV_VIDEO_OUTPUT - if (m_pEncoderA) - { - // int fourcc = cv::VideoWriter::fourcc('H', '2', '6', '4'); - int fourcc = cv::VideoWriter::fourcc('M', 'J', 'P', 'G'); - double fps = m_sStreamData.fps; - cv::String mn(m_sStreamSegmentInfo.scratchPath); - cv::Size fz(m_sStreamData.width, m_sStreamData.height); - // open (const String &filename, int fourcc, double fps, Size frameSize, bool isColor=true) - if (! m_pEncoder->open(mn, fourcc, fps, fz)) - { - LOG_ERROR("Cannot Open Output Segment A!"); - return false; - #ifdef DEBUG_EXTRA - } - else - { - char tB[256]; - sprintf(tB, "VideoStream A is Created [%s] %.2f fps", m_sStreamSegmentInfo.scratchPath, fps); - LOG(tB); - #endif - }; - m_bSegActive = true; - m_bSegDelete = m_bNSegDelete; - m_bNSegDelete = true; - m_nSegFrameCounter = 0; - m_nSegShiftFrames = 0; - } - else - { - LOG_ERROR("No Encoder(A) Object!"); - return false; - }; - #else // !OPENCV_VIDEO_OUTPUT - // Check if Encoder is Ready - if (m_pFormat == NULL) - { - return false; - } - - #ifdef SEPARATED_VIDEO_ENCODERS - if (avformat_alloc_output_context2(&m_pFormatCtx, m_pFormat, NULL, "test." VIDEO_OUTPUT_CONTAINER) < 0) - { - LOG_ERROR("Format CTX A alloc error!"); - return false; - } - else - { - av_dict_set(&m_pFormatCtx->metadata, "Author", "Argus Sec. System", 0); - m_pFormatCtx->flags |= AVFMT_NOTIMESTAMPS | AVFMT_TS_NONSTRICT; - }; - - m_pVideoStr = avformat_new_stream(m_pFormatCtx, m_pVideoACodec); - if (m_pVideoStr == NULL) - { - avformat_free_context(m_pFormatCtx); - return false; - #ifdef DEBUG_EXTRA - } - else - { - LOG("VideoStream A is Created"); - #endif - }; - const AVRational dst_fps = {m_sStreamData.fps, 1}; - m_pVideoStr->r_frame_rate = m_pVideoStrA->avg_frame_rate = dst_fps; - m_pVideoStr->time_base = m_pCodecCtx->time_base; - avcodec_parameters_from_context(m_pVideoStr->codecpar, m_pCodecACtx); - #ifdef DEBUG_EXTRA - LOG("Opening Stream A"); - LOG(m_cSegName); - char tB[128]; - sprintf(tB, "FFPTS:%llu FNUM:%llu S2KF:%llu", m_pVideoStr->start_time, m_pVideoStr->nb_frames, m_pVideoStr->first_dts); - LOG(tB); - sprintf(tB, "CON ST:%llu DUR:%llu", m_pFormatCtx->start_time, m_pFormatCtx->duration); - LOG(tB); - #endif - // if (avio_open(&m_pFormatCtx->pb, m_cSegNameA, AVIO_FLAG_WRITE) < 0) { - if (avio_open(&m_pFormatCtx->pb, m_sStreamSegmentInfo.scratchPath, AVIO_FLAG_WRITE) < 0) - { - LOG_ERROR("Could not open output file."); - return m_bSegActive; - }; - if (avformat_write_header(m_pFormatCtx, &m_pFormatOpts) < 0) - { - LOG_ERROR("Error occurred when writing header to output file."); - return m_bSegActive; - }; - // m_mFrameCounterProtector.lock(); - m_nSegFrameCounter = 0; - m_nSegShiftFrames = 0; - m_bSegActive = true; - m_bSegDelete = m_bNSegDelete; - m_bNSegDelete = true; - // m_mFrameCounterProtector.unlock(); - #else // SEPARATED_VIDEO_ENCODERS - m_nSegSkippedFrames = m_pVideoStr->nb_frames + 1; - if (m_pVideoStr->nb_frames) - { - m_pVideoStr->nb_frames = 0; - m_pVideoStr->start_time = 0; - m_pVideoStr->first_dts = 0; - m_pFormatCtx->start_time = 0; - }; - #ifdef DEBUG_EXTRA - LOG("Opening Stream"); - LOG(m_cSegName); - char tB[128]; - sprintf(tB, "FFPTS:%llu FNUM:%llu S2KF:%llu", m_pVideoStr->start_time, m_pVideoStr->nb_frames, m_pVideoStr->first_dts); - LOG(tB); - sprintf(tB, "CON ST:%llu DUR:%llu", m_pFormatCtx->start_time, m_pFormatCtx->duration); - LOG(tB); - #endif - if (avio_open(&m_pFormatCtx->pb, m_cSegName, AVIO_FLAG_WRITE) < 0) - { - LOG_ERROR("Could not open output file."); - return m_bSegActive; - }; - if (avformat_write_header(m_pFormatCtx, &m_pFormatOpts) < 0) - { - LOG_ERROR("Error occurred when writing header to output file."); - return m_bSegActive; - }; - // m_mFrameCounterProtector.lock(); - m_nSegFrameCounter = 0; - m_nSegShiftFrames = 0; - m_bSegActive = true; - m_bSegDelete = m_bNSegDelete; - m_bNSegDelete = true; - // m_mFrameCounterProtector.unlock(); - #endif // SEPARATED_VIDEO_ENCODERS - #ifdef DEBUG_EXTRA - LOG("Stream Opened"); - #endif - #endif // !OPENCV_VIDEO_OUTPUT - #endif // !DIRECT_MJPEG_COMPOSING - }; - }; - return m_bSegActive; - } - void streamHandler::closeSegment(void){ - #ifdef DEBUG - LOG("Closing Stream"); - #endif - #ifdef DEBUG_EXTRA - LOG("Actual Closing Video Stream"); - LOG(m_sStreamSegmentInfo.scratchPath); - #endif - m_bSegActive = false; - if( !m_bSegDelete ){ - #ifdef DIRECT_MJPEG_COMPOSING - if (m_pOutputFD){ - fclose(m_pOutputFD); - m_pOutputFD = NULL; - }; - #else // !DIRECT_MJPEG_COMPOSING - #ifdef OPENCV_VIDEO_OUTPUT - if (m_pEncoder->isOpened()){ - m_pEncoder->release(); - #ifdef DEBUG_EXTRA - }else{ - LOG(" Encoder is NOT Opened!"); - #endif - }; - #else // !OpenCV - av_write_trailer(m_pFormatCtx); - avio_close(m_pFormatCtx->pb); - #endif // !OPENCV_VIDEO_OUTPUT - #endif // !DIRECT_MJPEG_COMPOSING - EVENT_CONTAINER * bEVT = createBasicEvent(m_sStreamData.source_id, EVT_CLASS_VIDEO, EVT_CAPTURE_DONE, NULL, NULL, &m_sStreamSegmentInfo); - if (bEVT){ - basicEventHeap::getInstance()->broadcast(bEVT); - }else{ - LOG_ERROR("Event Creation failure!"); - } - #ifdef DEBUG_EXTRA - LOG("Stream is Saved"); - #endif - } else { - #ifdef DIRECT_MJPEG_COMPOSING - if ( m_pOutputFD ){ - fclose(m_pOutputFD); - m_pOutputFD = NULL; - }; - #else - #ifdef OPENCV_VIDEO_OUTPUT - if (m_pEncoder->isOpened()) { - m_pEncoder->release(); - #ifdef DEBUG_EXTRA - } else { - LOG(" Encoder is NOT Opened!"); - #endif - }; - #else // !OPenCV - #ifdef EVE_DONT_DELETE_SEGMENTS - av_write_trailer(m_pFormatCtx); - #endif - avio_close(m_pFormatCtx->pb); - #endif // !OPENCV_VIDEO_OUTPUT - #endif // !DIRECT_MJPEG_COMPOSING - #ifndef EVE_DONT_DELETE_SEGMENTS - unlink(m_sStreamSegmentInfo.scratchPath); - #endif - #ifdef DEBUG_EXTRA - LOG("Stream is Closed!"); - #endif - }; - } - */ - // Final Closing All + Thread - void streamHandler::closeAll() - { - waitThreadEnd(true); - #ifdef OPENCV_VIDEO_OUTPUT - if (m_pEncoder){ - if (m_pEncoder->isOpened()){ - m_pEncoder->release(); - }; - delete(m_pEncoder); - }; - #else // !OPENCV_VIDEO_OUTPUT - #ifdef DIRECT_MJPEG_COMPOSING - if (m_pOutputFD ){ - fclose(m_pOutputFD); - m_pOutputFD = NULL; - }; - #else // ! DIRECT_MJPEG_COMPOSING - if(( m_pCodecCtx != NULL ) && m_bSegActive ){ - if (m_pCodecCtx != NULL){ - avcodec_send_frame(m_pCodecCtx, NULL); - int ret = 0; - AVPacket * avp = av_packet_alloc(); - if (avp){ - do{ - av_packet_unref(avp); - ret = avcodec_receive_packet(m_pCodecACtx, avp); - if (! ret){ - if (m_bSegActive){ - av_write_frame(m_pFormatCtxA, avp); - }; - }; - } while (! ret); - av_packet_unref(avp); - av_packet_free(&avp); - }; - }; - if (m_bSegActive){ - av_write_trailer(m_pFormatCtx); - avformat_close_input(&m_pFormatCtx); - m_bSegActive = false; - }; - }; - #endif // !DIRECT_MJPEG_COMPOSING - #endif // !OPENCV_VIDEO_OUTPUT - } - bool streamHandler::initVideoOutput() - { - - m_nPreAlarmFrames = (PRE_ALARM_TIME_MILSECONDS * m_sStreamData.fps) / 1000; - m_nPostAlarmFrames = (POST_ALARM_TIME_MILSECONDS * m_sStreamData.fps) / 1000; - m_nSegmentLimitFrames = (ENCODING_SEGMENT_MILSECONDS * m_sStreamData.fps) / 1000; - m_nHardLimitFrames = (ENCODING_SEGMENT_LIMIT_MILSECONDS * m_sStreamData.fps) / 1000; - - #ifndef DIRECT_MJPEG_COMPOSING - #ifdef OPENCV_VIDEO_OUTPUT - //cv::VideoWriter out( m_sEncoderVS.m_pFileName, cv::VideoWriter::fourcc('a', 'v', 'c', '1'), 15.0, mat.size() ); - m_pEncoder = new cv::VideoWriter(); - if (m_pEncoder == NULL) - { - LOG_ERROR("Encoder A Create Failure!"); - return false; - }; - - //m_pEncoder->set(cv::VIDEOWRITER_PROP_QUALITY, 10.0); - //m_pEncoder->set(cv::VIDEOWRITER_PROP_NSTRIPES, -1.0); - - #else - if (! initLibAV()) - { - return false; - } - - m_pFormat = av_guess_format(VIDEO_OUTPUT_CONTAINER, "test." VIDEO_OUTPUT_CONTAINER, NULL); - - if (m_pFormat == NULL) - { - LOG_ERROR("Out VideoFormat Not Found!"); - return false; - #ifdef DEBUG_EXTRA - } else { - LOG("Output video Format"); - LOG(VIDEO_OUTPUT_CONTAINER); - #endif - }; - - #ifdef SEPARATED_VIDEO_ENCODERS - /* Stream A */ - m_pVideoCodec = avcodec_find_encoder(VIDEO_OUTPUT_CODEC); - if (m_pVideoCodec == NULL) - { - LOG_ERROR("Encoder Video Codec Not Found!"); - return false; - #ifdef DEBUG_EXTRA - } else { - LOG("Video Encoder Created"); - #endif - }; - m_pCodecCtx = avcodec_alloc_context3(m_pVideoACodec); - if (m_pCodecCtx == NULL) - { - LOG_ERROR("Video Encoder Context Memory Allocation Error!"); - av_free(m_pVideoCodec); - avformat_free_context(m_pFormatCtx); - return false; - #ifdef DEBUG_EXTRA - } else { - LOG("Video Encoder Context A Allocated"); - #endif - }; - m_pCodecCtx->codec_id = VIDEO_OUTPUT_CODEC; - m_pCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO; - m_pCodecCtx->pix_fmt = VIDEO_OUTPUT_PIX_FMT; - m_pCodecCtx->bit_rate = VIDEO_OUTPUT_BITRATE; - m_pCodecCtx->max_b_frames = 1; - m_pCodecCtx->width = m_pMaster->m_sEmbedVideoData.width; - m_pCodecCtx->height = m_pMaster->m_sEmbedVideoData.height; - m_pCodecCtx->time_base.num = 1; - m_pCodecCtx->time_base.den = m_sStreamData.fps; - m_pCodecCtx->framerate.num = m_sStreamData.fps; - m_pCodecCtx->framerate.den = 1; - #if (LIBAVCODEC_VERSION_MAJOR > 54) - // m_pCodecACtx->codec_tag = av_codec_get_tag( m_pFormatCtxA->oformat->codec_tag, VIDEO_OUTPUT_CODEC ); - #endif - m_pFormatOpts = NULL; - if ((m_pCodecCtx->codec_id == AV_CODEC_ID_H264) || (m_pCodecCtx->codec_id == AV_CODEC_ID_H265)) - { - #ifdef DEBUG_EXTRA - LOG("Begin Options!"); - #endif - if (av_dict_set(&m_pFormatOpts, "movflags", "isml+faststart+frag_keyframe+empty_moov+omit_tfhd_offset", 0) < 0) - { - LOG_ERROR("av_dict_set movflags!"); - #ifdef DEBUG_EXTRA - } else { - LOG("MOV FLAG SET!"); - #endif - }; - // if( av_dict_set( &m_pFormatOpts, "live", "1", 0 ) < 0 ){ - // LOG_ERROR( "av_dict_set live!" ); - // }; - - // default brand is "isom", which fails on some devices - if (av_dict_set(&m_pFormatOpts, "brand", "mp42", 0) < 0) - { - LOG_ERROR("av_dict_set brand!"); - }; - // m_pCodecCtx->max_b_frames = 1; - // m_pCodecCtx->level = 31; - m_pCodecCtx->gop_size = m_sStreamData.fps << 1; // VIDEO_OUTPUT_GOP; // emit one intra frame every X frames - // P-frames, generated by referencing data from prev and future frames. - // [Compression up, CPU usage up] - // [use 3/gop] - m_pCodecCtx->max_b_frames = 5; - // Can be used by a P-frame(predictive, partial frame) to help define a future frame in a compressed video. - // [use 3?5 ref per P] - m_pCodecCtx->refs = 3; - // Compression efficiency (slower -> better quality + higher cpu%) - // [ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow] - // Set this option to "ultrafast" is critical for realtime encoding - av_opt_set(m_pCodecCtx->priv_data, "preset", "ultrafast", 0); - // av_opt_set( m_pCodecCtx->priv_data, "preset", "fast", 0 ); - // av_opt_set( m_pCodecCtx->priv_data, "preset", "slow", 0 ); - - // Compression rate (lower -> higher compression) compress to lower size, makes decoded image more noisy - // Range: [0; 51], sane range: [18; 26]. I used 35 as good compression/quality compromise. This option also critical for realtime encoding - av_opt_set(m_pCodecCtx->priv_data, "crf", "32", 0); - // Change settings based upon the specifics of input - // [psnr, ssim, grain, zerolatency, fastdecode, animation] - // This option is most critical for realtime encoding, because it removes delay between 1th input frame and 1th output packet. - av_opt_set(m_pCodecCtx->priv_data, "tune", "zerolatency", 0); - // Disable b-pyramid. CLI options for this is "-b-pyramid 0" - // Because Quicktime (ie. iOS) doesn't support this option - av_opt_set(m_pCodecACtx->priv_data, "b-pyramid", "0", 0); - #ifdef DEBUG_EXTRA - LOG("End Options!"); - #endif - } else { // codec is not AV_CODEC_ID_H264 || AV_CODEC_ID_H265 - if( m_pFormat->flags & AVFMT_GLOBALHEADER ) - { - m_pCodecCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; - } - }; - const AVRational dst_fps = {m_sStreamData.fps, 1}; - - #ifdef DEBUG_EXTRA - char TB[129]; - sprintf(TB, "TimeBaseA: num[%d]/den[%d]", m_pCodecACtx->time_base.num, m_pCodecACtx->time_base.den); - LOG(TB); - sprintf(TB, "TimeBaseB: num[%d]/den[%d]", m_pCodecBCtx->time_base.num, m_pCodecBCtx->time_base.den); - LOG(TB); - #endif - ////m_pVideoStr->time_base = m_pCodecCtx->time_base; - // avcodec_get_context_defaults3( m_pVideoStr->codec, m_pVideoCodec ); - - // m_pVideoStr->codec->width = m_pMaster->m_sEmbedVideoData.width; - // m_pVideoStr->codec->height = m_pMaster->m_sEmbedVideoData.height; - // m_pVideoStr->codec->pix_fmt = VIDEO_OUTPUT_PIX_FMT; - // m_pVideoStr->codec->time_base = m_pVideoStrB->time_base = av_inv_q(dst_fps); - //// m_pVideoStr->r_frame_rate = m_pVideoStrA->avg_frame_rate = - ////dst_fps; - - // if ( m_pFormatCtx->oformat->flags & AVFMT_GLOBALHEADER ) m_pVideoStrA->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; - - //// avcodec_parameters_from_context( m_pVideoStr->codecpar, - ////m_pCodecCtx ); - // m_pVideoStr->codecpar->format = VIDEO_OUTPUT_PIX_FMT; - // m_pVideoStr->codecpar->extradata = m_pCodecCtx->extradata; - // m_pVideoStr->codecpar->extradata_size = m_pCodecCtx->extradata_size; - - if (avcodec_is_open(m_pCodecCtx) == 0) - { - LOG("output codec context is closed, opening"); - if (avcodec_open2(m_pCodecCtx, m_pVideoCodec, NULL) < 0) - { - LOG_ERROR("Error opening2 encoder"); - return false; - #ifdef DEBUG_EXTRA - } else { - LOG("output codec context is opened"); - #endif - }; - - #ifdef DEBUG_EXTRA - } else { - LOG("output codec context is already opened"); - #endif - }; - #else // !SEPARATED_VIDEO_ENCODERS - if (avformat_alloc_output_context2(&m_pFormatCtx, m_pFormat, NULL, "test." VIDEO_OUTPUT_CONTAINER) < 0) - { - LOG_ERROR("Format CTX alloc error!"); - return false; - } else { - av_dict_set(&m_pFormatCtx->metadata, "Author", "Argus Sec. System", 0); - m_pFormatCtx->flags |= AVFMT_NOTIMESTAMPS | AVFMT_TS_NONSTRICT; - }; - m_pVideoCodec = avcodec_find_encoder(VIDEO_OUTPUT_CODEC); - if (m_pVideoCodec == NULL) - { - LOG_ERROR("Output VideoCodec Not Found!"); - avformat_free_context(m_pFormatCtxA); - avformat_free_context(m_pFormatCtxB); - return false; - #ifdef DEBUG_EXTRA - } else { - LOG("Output Video Codec Found"); - #endif - }; - - m_pCodecCtx = avcodec_alloc_context3(m_pVideoCodec); - if (m_pCodecCtx == NULL) - { - LOG_ERROR("Out VideoCodec Context Memory Allocation Error"); - av_free(m_pVideoCodec); - avformat_free_context(m_pFormatCtx); - return false; - #ifdef DEBUG_EXTRA - } else { - LOG("Out Codec Context3 Allocated"); - #endif - }; - m_pVideoStr = avformat_new_stream(m_pFormatCtx, m_pVideoCodec); - if (m_pVideoStr == NULL) - { - LOG_ERROR("VideoStream A Not Created!"); - avcodec_free_context(&m_pCodecCtx); - av_free(m_pCodecCtx); - av_free(m_pVideoCodec); - // avformat_close_input ( &m_pFormatCtx ); - avformat_free_context(m_pFormatCtx); - return false; - #ifdef DEBUG_EXTRA - } else { - LOG("VideoStream A is Created"); - #endif - }; - - m_pCodecCtx->codec_id = VIDEO_OUTPUT_CODEC; - m_pCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO; - m_pCodecCtx->pix_fmt = VIDEO_OUTPUT_PIX_FMT; - m_pCodecCtx->bit_rate = VIDEO_OUTPUT_BITRATE; - // m_pCodecCtx->thread_count = 1; - // m_pCodecCtx->bit_rate_tolerance = 1; - // m_pCodecCtx->global_quality = 100; - // m_pCodecCtx->compression_level = 2; - m_pCodecCtx->max_b_frames = 1; - m_pCodecCtx->width = m_pMaster->m_sEmbedVideoData.width; - m_pCodecCtx->height = m_pMaster->m_sEmbedVideoData.height; - m_pCodecCtx->time_base.num = 1; - m_pCodecCtx->time_base.den = m_sStreamData.fps; - m_pCodecCtx->framerate.num = m_sStreamData.fps; - m_pCodecCtx->framerate.den = 1; - - #if (LIBAVCODEC_VERSION_MAJOR > 54) - m_pCodecCtx->codec_tag = av_codec_get_tag(m_pFormatCtx->oformat->codec_tag, VIDEO_OUTPUT_CODEC); - #endif - m_pFormatOpts = NULL; - - if ((m_pCodecCtx->codec_id == AV_CODEC_ID_H264) || (m_pCodecCtx->codec_id == AV_CODEC_ID_H265)) - { - #ifdef DEBUG_EXTRA - LOG("Begin Options!"); - #endif - if (av_dict_set(&m_pFormatOpts, "movflags", "isml+faststart+frag_keyframe+empty_moov+omit_tfhd_offset", 0) < 0) - { - LOG_ERROR("av_dict_set movflags!"); - #ifdef DEBUG_EXTRA - } else { - LOG("MOV FLAG SET!"); - #endif - }; - - // if( av_dict_set( &m_pFormatOpts, "live", "1", 0 ) < 0 ){ - // LOG_ERROR( "av_dict_set live!" ); - // }; - - // default brand is "isom", which fails on some devices - if (av_dict_set(&m_pFormatOpts, "brand", "mp42", 0) < 0) - { - LOG_ERROR("av_dict_set brand!"); - }; - // m_pCodecCtx->max_b_frames = 1; - // m_pCodecCtx->level = 31; - - m_pCodecCtx->gop_size = m_sStreamData.fps << 1; // VIDEO_OUTPUT_GOP; // emit one intra frame every X frames - /// P-frames, generated by referencing data from prev and future frames. - /// [Compression up, CPU usage up] - /// [use 3/gop] - m_pCodecCtx->max_b_frames = 5; - - /// Can be used by a P-frame(predictive, partial frame) to help define a future frame in a compressed video. - /// [use 3?5 ref per P] - m_pCodecCtx->refs = 3; - - /// Compression efficiency (slower -> better quality + higher cpu%) - /// [ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow] - /// Set this option to "ultrafast" is critical for realtime encoding - av_opt_set(m_pCodecCtx->priv_data, "preset", "ultrafast", 0); - // av_opt_set( m_pCodecCtx->priv_data, "preset", "fast", 0 ); - // av_opt_set( m_pCodecCtx->priv_data, "preset", "slow", 0 ); - - /// Compression rate (lower -> higher compression) compress to lower size, makes decoded image more noisy - /// Range: [0; 51], sane range: [18; 26]. I used 35 as good compression/quality compromise. This option also critical for realtime encoding - av_opt_set(m_pCodecCtx->priv_data, "crf", "32", 0); - - /// Change settings based upon the specifics of input - /// [psnr, ssim, grain, zerolatency, fastdecode, animation] - /// This option is most critical for realtime encoding, because it removes delay between 1th input frame and 1th output packet. - av_opt_set(m_pCodecCtx->priv_data, "tune", "zerolatency", 0); - - /// Disable b-pyramid. CLI options for this is "-b-pyramid 0" - /// Because Quicktime (ie. iOS) doesn't support this option - av_opt_set(m_pCodecCtx->priv_data, "b-pyramid", "0", 0); - #ifdef DEBUG_EXTRA - LOG("End Options!"); - #endif - } else { - if (m_pFormat->flags & AVFMT_GLOBALHEADER) - { - m_pCodecCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; - } - }; - - const AVRational dst_fps = {m_sStreamData.fps, 1}; - - #ifdef DEBUG_EXTRA - char TB[129]; - sprintf(TB, "TimeBase: num[%d]/den[%d]", m_pCodecCtx->time_base.num, m_pCodecCtx->time_base.den); - LOG(TB); - #endif - m_pVideoStr->time_base = m_pCodecCtx->time_base; - - // avcodec_get_context_defaults3( m_pVideoStr->codec, m_pVideoCodec ); - - // m_pVideoStr->codec->width = m_pMaster->m_sEmbedVideoData.width; - // m_pVideoStr->codec->height = m_pMaster->m_sEmbedVideoData.height; - // m_pVideoStr->codec->pix_fmt = VIDEO_OUTPUT_PIX_FMT; - // m_pVideoStr->codec->time_base = m_pVideoStrB->time_base = av_inv_q(dst_fps); - m_pVideoStr->r_frame_rate = dst_fps; - // if ( m_pFormatCtx->oformat->flags & AVFMT_GLOBALHEADER ) m_pVideoStr->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; - avcodec_parameters_from_context(m_pVideoStr->codecpar, m_pCodecCtx); - // m_pVideoStr->codecpar->format = VIDEO_OUTPUT_PIX_FMT; - // m_pVideoStr->codecpar->extradata = m_pCodecCtx->extradata; - // m_pVideoStr->codecpar->extradata_size = m_pCodecCtx->extradata_size; - if (avcodec_is_open(m_pCodecCtx) == 0) - { - LOG("output codec context is closed, opening"); - if (avcodec_open2(m_pCodecCtx, m_pVideoCodec, NULL) < 0) - { - LOG_ERROR("Error opening2 encoder"); - return false; - #ifdef DEBUG_EXTRA - } else { - LOG("output codec context is opened"); - #endif - }; - #ifdef DEBUG_EXTRA - } else { - LOG("output codec context is already opened"); - #endif - }; - #endif // SEPARATED_VIDEO_ENCODERS - m_pConvertCtx = - sws_getContext(m_pMaster->m_sEmbedVideoData.width, m_pMaster->m_sEmbedVideoData.height, AV_PIX_FMT_BGR24, m_pMaster->m_sEmbedVideoData.width, m_pMaster->m_sEmbedVideoData.height, VIDEO_OUTPUT_PIX_FMT, SWS_FAST_BILINEAR, NULL, NULL, NULL); - if (m_pConvertCtx == NULL) - { - return false; - } - m_pAVFrame = av_frame_alloc(); - if (m_pAVFrame == NULL) - { - return false; - }; - m_pOutBuffer = (uint8_t *) av_malloc(av_image_get_buffer_size(VIDEO_OUTPUT_PIX_FMT, m_pMaster->m_sEmbedVideoData.width, m_pMaster->m_sEmbedVideoData.height, BUFFER_ALIGN)); - if (m_pOutBuffer == NULL) - { - return false; - }; - m_pAVFrame->width = m_pMaster->m_sEmbedVideoData.width; - m_pAVFrame->height = m_pMaster->m_sEmbedVideoData.height; - m_pAVFrame->format = VIDEO_OUTPUT_PIX_FMT; - // av_frame_get_buffer( m_pAVFrame, 0 ); - av_image_fill_arrays(m_pAVFrame->data, m_pAVFrame->linesize, m_pOutBuffer, VIDEO_OUTPUT_PIX_FMT, m_pMaster->m_sEmbedVideoData.width, m_pMaster->m_sEmbedVideoData.height, 1); - - // av_frame_make_writable( m_pAVFrame ); - #endif // !OPENCV_VIDEO_OUTPUT - #endif // !DIRECT_MJPEG_COMPOSING - return init(); - } - #else // !EVE_SEQUENTAL_OUTPUT - void streamHandler::closeSegmentA(void) - { - m_mCurrentOperationProtector.lock(); - if (m_bCOP == 0) - { - m_bCOP = 0x01; - } - m_mCurrentOperationProtector.unlock(); - #ifdef DEBUG_EXTRA - LOG("Closing Stream A"); - #endif - } - - void streamHandler::closeSegmentB(void) - { - m_mCurrentOperationProtector.lock(); - if (m_bCOP == 0) - { - m_bCOP = 0x02; - } - m_mCurrentOperationProtector.unlock(); - #ifdef DEBUG_EXTRA - LOG("Closing Stream B"); - #endif - } - - void streamHandler::closeAll() - { - waitThreadEnd(true); - #ifdef OPENCV_VIDEO_OUTPUT - if (m_pEncoderA) - { - if (m_pEncoderA->isOpened()) - { - m_pEncoderA->release(); - }; - delete(m_pEncoderA); - }; - if (m_pEncoderB) - { - if (m_pEncoderB->isOpened()) - { - m_pEncoderB->release(); - }; - delete(m_pEncoderB); - }; - #else // !OPENCV_VIDEO_OUTPUT - #ifdef DIRECT_MJPEG_COMPOSING - if (m_pOutputFD[0]) - { - fclose(m_pOutputFD[0]); - m_pOutputFD[0] = NULL; - }; - if (m_pOutputFD[1]) - { - fclose(m_pOutputFD[1]); - m_pOutputFD[1] = NULL; - }; - #else // ! DIRECT_MJPEG_COMPOSING - #ifdef SEPARATED_VIDEO_ENCODERS - if ((m_pCodecACtx != NULL || m_pCodecBCtx != NULL) && (m_bSegAActive || m_bSegBActive)) - { - if (m_pCodecACtx != NULL) - { - avcodec_send_frame(m_pCodecACtx, NULL); - int ret = 0; - AVPacket * avp = av_packet_alloc(); - if (avp) - { - do - { - av_packet_unref(avp); - ret = avcodec_receive_packet(m_pCodecACtx, avp); - if (! ret) - { - if (m_bSegAActive) - { - av_write_frame(m_pFormatCtxA, avp); - } - }; - } - while (! ret); - av_packet_unref(avp); - av_packet_free(&avp); - }; - }; - if (m_pCodecBCtx != NULL) - { - avcodec_send_frame(m_pCodecBCtx, NULL); - int ret = 0; - AVPacket * avp = av_packet_alloc(); - if (avp) - { - do - { - av_packet_unref(avp); - ret = avcodec_receive_packet(m_pCodecBCtx, avp); - if (! ret) - { - if (m_bSegBActive) - { - av_write_frame(m_pFormatCtxB, avp); - } - }; - } - while (! ret); - av_packet_unref(avp); - av_packet_free(&avp); - }; - }; - if (m_bSegAActive) - { - av_write_trailer(m_pFormatCtxA); - avformat_close_input(&m_pFormatCtxA); - m_bSegAActive = false; - }; - if (m_bSegBActive) - { - av_write_trailer(m_pFormatCtxB); - avformat_close_input(&m_pFormatCtxB); - m_bSegBActive = false; - }; - }; - #else // !SEPARATED_VIDEO_ENCODERS - if (m_pCodecCtx != NULL && (m_bSegAActive || m_bSegBActive)) - { - avcodec_send_frame(m_pCodecCtx, NULL); - int ret = 0; - AVPacket * avp = av_packet_alloc(); - if (avp) - { - do - { - av_packet_unref(avp); - ret = avcodec_receive_packet(m_pCodecCtx, avp); - if (! ret) - { - if (m_bSegAActive) - { - av_write_frame(m_pFormatCtxA, avp); - } - if (m_bSegBActive) - { - av_write_frame(m_pFormatCtxB, avp); - } - }; - } - while (! ret); - av_packet_unref(avp); - av_packet_free(&avp); - }; - if (m_bSegAActive) - { - av_write_trailer(m_pFormatCtxA); - avformat_close_input(&m_pFormatCtxA); - m_bSegAActive = false; - }; - if (m_bSegBActive) - { - av_write_trailer(m_pFormatCtxB); - avformat_close_input(&m_pFormatCtxB); - m_bSegBActive = false; - }; - }; - #endif // !SEPARATED_VIDEO_ENCODERS - #endif // !DIRECT_MJPEG_COMPOSING - // if( m_pFormat != NULL ) { - // av_free( m_pFormat ); - //}; - #endif // OPENCV_VIDEO_OUTPUT - } - bool streamHandler::openSegmentA(void) - { - if (! m_bSegAActive) - { - CSTR tAM = getUniqID_MD5(); - if (tAM) - { - sprintf(m_sStreamSegmentInfo[0].scratchPath, "%s/%s.%s", m_pVideoScratchPath, tAM, VIDEO_OUTPUT_CONTAINER); - strncpy(m_sStreamSegmentInfo[0].recordMD5, tAM, 32); - m_sStreamSegmentInfo[0].recordMD5[32] = (char) 0; - free(tAM); - m_sStreamSegmentInfo[0].stream_id = m_sStreamData.id; - PF_TIMESTAMP ts; - getPFTS(&ts); - m_sStreamSegmentInfo[0].streamTSS = ts.seconds; - m_sStreamSegmentInfo[0].streamTMS = ts.milliseconds; - #ifdef DEBUG_EXTRA - char tB[128]; - sprintf(tB, "A opened %d.%d", m_sStreamSegmentInfo[0].streamTSS, m_sStreamSegmentInfo[0].streamTMS); - LOG(tB); - #endif - 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].streamHeight = m_pMaster->getHeight(); - m_sStreamSegmentInfo[0].eventIDS.clear(); - m_sStreamSegmentInfo[0].eventTSS.clear(); - m_sStreamSegmentInfo[0].eventTMS.clear(); - m_sStreamSegmentInfo[0].eventFrames.clear(); - m_sStreamSegmentInfo[0].dataSize = 0; - m_sStreamSegmentInfo[0].db_id = 0; - #ifdef DIRECT_MJPEG_COMPOSING - m_pOutputFD[0] = fopen(m_sStreamSegmentInfo[0].scratchPath, "wb+"); - m_nSegAFrameCounter = 0; - m_nSegAShiftFrames = 0; - m_bSegAActive = true; - m_bSegADelete = true; - #else // !DIRECT_MJPEG_COMPOSING - #ifdef OPENCV_VIDEO_OUTPUT - if (m_pEncoderA) - { - // int fourcc = cv::VideoWriter::fourcc('H', '2', '6', '4'); - int fourcc =cv::VideoWriter::fourcc('a', 'v', 'c', '1'); - // int fourcc = cv::VideoWriter::fourcc('M', 'J', 'P', 'G'); - double fps = m_sStreamData.fps; - cv::String mn(m_sStreamSegmentInfo[0].scratchPath); - cv::Size fz(m_sStreamData.width, m_sStreamData.height); - // open (const String &filename, int fourcc, double fps, Size frameSize, bool isColor=true) - if (! m_pEncoderA->open(mn, fourcc, fps, fz)) - { - LOG_ERROR("Cannot Open Output Segment A!"); - return false; - #ifdef DEBUG_EXTRA - } - else - { - char tB[256]; - sprintf(tB, "VideoStream A is Created [%s] %.2f fps", m_sStreamSegmentInfo[0].scratchPath, fps); - LOG(tB); - #endif - }; - m_bSegAActive = true; - m_bSegADelete = true; - m_nSegAFrameCounter = 0; - m_nSegAShiftFrames = 0; - } - else - { - LOG_ERROR("No Encoder(A) Object!"); - return false; - }; - #else // !OPENCV_VIDEO_OUTPUT - // Check if Encoder is Ready - if (m_pFormat == NULL) - { - return false; - } - - #ifdef SEPARATED_VIDEO_ENCODERS - if (avformat_alloc_output_context2(&m_pFormatCtxA, m_pFormat, NULL, "test." VIDEO_OUTPUT_CONTAINER) < 0) - { - LOG_ERROR("Format CTX A alloc error!"); - return false; - } - else - { - av_dict_set(&m_pFormatCtxA->metadata, "Author", "Argus Sec. System", 0); - m_pFormatCtxA->flags |= AVFMT_NOTIMESTAMPS | AVFMT_TS_NONSTRICT; - }; - - m_pVideoStrA = avformat_new_stream(m_pFormatCtxA, m_pVideoACodec); - if (m_pVideoStrA == NULL) - { - avformat_free_context(m_pFormatCtxA); - return false; - #ifdef DEBUG_EXTRA - } - else - { - LOG("VideoStream A is Created"); - #endif - }; - const AVRational dst_fps = {m_sStreamData.fps, 1}; - m_pVideoStrA->r_frame_rate = m_pVideoStrA->avg_frame_rate = dst_fps; - m_pVideoStrA->time_base = m_pCodecACtx->time_base; - avcodec_parameters_from_context(m_pVideoStrA->codecpar, m_pCodecACtx); - #ifdef DEBUG_EXTRA - LOG("Opening Stream A"); - LOG(m_cSegNameA); - char tB[128]; - sprintf(tB, "FFPTS:%llu FNUM:%llu S2KF:%llu", m_pVideoStrA->start_time, m_pVideoStrA->nb_frames, m_pVideoStrA->first_dts); - LOG(tB); - sprintf(tB, "CON ST:%llu DUR:%llu", m_pFormatCtxA->start_time, m_pFormatCtxA->duration); - LOG(tB); - #endif - // if (avio_open(&m_pFormatCtxA->pb, m_cSegNameA, AVIO_FLAG_WRITE) < 0) { - if (avio_open(&m_pFormatCtxA->pb, m_sStreamSegmentInfo[0].scratchPath, AVIO_FLAG_WRITE) < 0) - { - LOG_ERROR("Could not open output file."); - return m_bSegAActive; - }; - if (avformat_write_header(m_pFormatCtxA, &m_pFormatOpts) < 0) - { - LOG_ERROR("Error occurred when writing header to output file."); - return m_bSegAActive; - }; - // m_mFrameCounterProtector.lock(); - m_nSegAFrameCounter = 0; - m_nSegAShiftFrames = 0; - m_bSegAActive = true; - m_bSegADelete = true; - // m_mFrameCounterProtector.unlock(); - #else // SEPARATED_VIDEO_ENCODERS - m_nSegASkippedFrames = m_pVideoStrA->nb_frames + 1; - if (m_pVideoStrA->nb_frames) - { - m_pVideoStrA->nb_frames = 0; - m_pVideoStrA->start_time = 0; - m_pVideoStrA->first_dts = 0; - m_pFormatCtxA->start_time = 0; - }; - #ifdef DEBUG_EXTRA - LOG("Opening Stream A"); - LOG(m_cSegNameA); - char tB[128]; - sprintf(tB, "FFPTS:%llu FNUM:%llu S2KF:%llu", m_pVideoStrA->start_time, m_pVideoStrA->nb_frames, m_pVideoStrA->first_dts); - LOG(tB); - sprintf(tB, "CON ST:%llu DUR:%llu", m_pFormatCtxA->start_time, m_pFormatCtxA->duration); - LOG(tB); - #endif - if (avio_open(&m_pFormatCtxA->pb, m_cSegNameA, AVIO_FLAG_WRITE) < 0) - { - LOG_ERROR("Could not open output file."); - return m_bSegAActive; - }; - if (avformat_write_header(m_pFormatCtxA, &m_pFormatOpts) < 0) - { - LOG_ERROR("Error occurred when writing header to output file."); - return m_bSegAActive; - }; - // m_mFrameCounterProtector.lock(); - m_nSegAFrameCounter = 0; - m_nSegAShiftFrames = 0; - m_bSegAActive = true; - m_bSegADelete = true; - // m_mFrameCounterProtector.unlock(); - #endif // SEPARATED_VIDEO_ENCODERS - #ifdef DEBUG_EXTRA - LOG("Stream A Opened"); - #endif - #endif // !OPENCV_VIDEO_OUTPUT - #endif // !DIRECT_MJPEG_COMPOSING - }; - }; - return m_bSegAActive; - } - - bool streamHandler::openSegmentB(void) - { - if (! m_bSegBActive) - { - CSTR tAM = getUniqID_MD5(); - if (tAM) - { - sprintf(m_sStreamSegmentInfo[1].scratchPath, "%s/%s.%s", m_pVideoScratchPath, tAM, VIDEO_OUTPUT_CONTAINER); - strncpy(m_sStreamSegmentInfo[1].recordMD5, tAM, 32); - m_sStreamSegmentInfo[1].recordMD5[32] = (char) 0; - free(tAM); - m_sStreamSegmentInfo[1].stream_id = m_sStreamData.id; - PF_TIMESTAMP ts; - getPFTS(&ts); - m_sStreamSegmentInfo[1].streamTSS = ts.seconds; - m_sStreamSegmentInfo[1].streamTMS = ts.milliseconds; - #ifdef DEBUG_EXTRA - char tB[128]; - sprintf(tB, "B opened %d.%d", m_sStreamSegmentInfo[1].streamTSS, m_sStreamSegmentInfo[1].streamTMS); - LOG(tB); - #endif - strncpy(m_sStreamSegmentInfo[1].recordEXT, VIDEO_OUTPUT_CONTAINER, 6); - m_sStreamSegmentInfo[1].streamFPS = m_sStreamData.fps; - m_sStreamSegmentInfo[1].streamWidth = m_pMaster->getWidh(); - m_sStreamSegmentInfo[1].streamHeight = m_pMaster->getHeight(); - m_sStreamSegmentInfo[1].eventIDS.clear(); - m_sStreamSegmentInfo[1].eventTSS.clear(); - m_sStreamSegmentInfo[1].eventTMS.clear(); - m_sStreamSegmentInfo[1].eventFrames.clear(); - m_sStreamSegmentInfo[1].dataSize = 0; - m_sStreamSegmentInfo[1].db_id = 0; - - #ifdef DIRECT_MJPEG_COMPOSING - m_pOutputFD[1] = fopen(m_sStreamSegmentInfo[1].scratchPath, "wb+"); - m_nSegBFrameCounter = 0; - m_nSegBShiftFrames = 0; - m_bSegBActive = true; - m_bSegBDelete = true; - #else // !DIRECT_MJPEG_COMPOSING - #ifdef OPENCV_VIDEO_OUTPUT - if (m_pEncoderB) - { - // int fourcc = cv::VideoWriter::fourcc('H', '2', '6', '4'); - int fourcc =cv::VideoWriter::fourcc('a', 'v', 'c', '1'); - //int fourcc = cv::VideoWriter::fourcc('M', 'J', 'P', 'G'); - double fps = m_sStreamData.fps; - cv::String mn(m_sStreamSegmentInfo[1].scratchPath); - cv::Size fz(m_sStreamData.width, m_sStreamData.height); - // open (const String &filename, int fourcc, double fps, Size frameSize, bool isColor=true) - if (! m_pEncoderB->open(mn, fourcc, fps, fz)) - { - LOG_ERROR("Cannot Open Output Segment B!"); - return false; - #ifdef DEBUG_EXTRA - } - else - { - char tB[256]; - sprintf(tB, "VideoStream B is Created [%s] %.2f fps", m_sStreamSegmentInfo[1].scratchPath, fps); - LOG(tB); - #endif - }; - m_bSegBActive = true; - m_bSegBDelete = true; - m_nSegBFrameCounter = 0; - m_nSegBShiftFrames = 0; - } - else - { - LOG_ERROR("No Encoder(B) Object!"); - return false; - }; - #else // !OPENCV - // Check if Encoder is Ready - if (m_pFormat == NULL) - { - return false; - } - #ifdef SEPARATED_VIDEO_ENCODERS - if (avformat_alloc_output_context2(&m_pFormatCtxB, m_pFormat, NULL, "test." VIDEO_OUTPUT_CONTAINER) < 0) - { - LOG_ERROR("Format CTX B alloc error!"); - return false; - } - else - { - av_dict_set(&m_pFormatCtxB->metadata, "Author", "Argus Sec. System", 0); - m_pFormatCtxB->flags |= AVFMT_NOTIMESTAMPS | AVFMT_TS_NONSTRICT; - }; - - m_pVideoStrB = avformat_new_stream(m_pFormatCtxB, m_pVideoBCodec); - if (m_pVideoStrB == NULL) - { - avformat_free_context(m_pFormatCtxB); - return false; - #ifdef DEBUG_EXTRA - } - else - { - LOG("VideoStream B is Created"); - #endif - }; - const AVRational dst_fps = {m_sStreamData.fps, 1}; - m_pVideoStrB->r_frame_rate = m_pVideoStrB->avg_frame_rate = dst_fps; - m_pVideoStrB->time_base = m_pCodecBCtx->time_base; - avcodec_parameters_from_context(m_pVideoStrB->codecpar, m_pCodecBCtx); - #ifdef DEBUG_EXTRA - LOG("Opening Stream B"); - LOG(m_cSegNameB); - char tB[128]; - sprintf(tB, "FFPTS:%llu FNUM:%llu S2KF:%llu", m_pVideoStrB->start_time, m_pVideoStrB->nb_frames, m_pVideoStrB->first_dts); - LOG(tB); - sprintf(tB, "CON ST:%llu DUR:%llu", m_pFormatCtxB->start_time, m_pFormatCtxB->duration); - LOG(tB); - #endif - - // if ( avio_open( &m_pFormatCtxB->pb, m_cSegNameB, AVIO_FLAG_WRITE ) < 0 ){ - if (avio_open(&m_pFormatCtxB->pb, m_sStreamSegmentInfo[1].scratchPath, AVIO_FLAG_WRITE) < 0) - { - LOG_ERROR("Could not open output file."); - avformat_free_context(m_pFormatCtxB); - return false; - }; - if (avformat_write_header(m_pFormatCtxB, &m_pFormatOpts) < 0) - { - LOG_ERROR("Error occurred when writing header to output file."); - avio_close(m_pFormatCtxB->pb); - avformat_free_context(m_pFormatCtxB); - return false; - }; - // m_mFrameCounterProtector.lock(); - m_nSegBFrameCounter = 0; - m_nSegBShiftFrames = 0; - m_bSegBActive = true; - m_bSegBDelete = true; - // m_mFrameCounterProtector.unlock(); - #else // SEPARATED_VIDEO_ENCODERS - m_nSegBSkippedFrames = m_pVideoStrB->nb_frames + 1; - if (m_pVideoStrB->nb_frames) - { - m_pVideoStrB->nb_frames = 0; - m_pVideoStrB->start_time = 0; - m_pVideoStrB->first_dts = 0; - m_pFormatCtxB->start_time = 0; - }; - if (avio_open(&m_pFormatCtxB->pb, m_cSegNameB, AVIO_FLAG_WRITE) < 0) - { - LOG_ERROR("Could not open output file."); - return m_bSegBActive; - }; - if (avformat_write_header(m_pFormatCtxB, &m_pFormatOpts) < 0) - { - LOG_ERROR("Error occurred when writing header to output file."); - return m_bSegBActive; - }; - // m_mFrameCounterProtector.lock(); - m_nSegBFrameCounter = 0; - m_nSegBShiftFrames = 0; - m_bSegBActive = true; - m_bSegBDelete = true; - // m_mFrameCounterProtector.unlock(); - #endif // SEPARATED_VIDEO_ENCODERS - #ifdef DEBUG_EXTRA - LOG("Stream B Opened"); - #endif - #endif // !OPENCV_VIDEO_OUTPUT - #endif // !DIRECT_MJPEG_COMPOSING - }; - }; - return m_bSegBActive; - } - - bool streamHandler::initVideoOutput() - { - - m_nPreAlarmFrames = (PRE_ALARM_TIME_MILSECONDS * m_sStreamData.fps) / 1000; - m_nPostAlarmFrames = (POST_ALARM_TIME_MILSECONDS * m_sStreamData.fps) / 1000; - m_nSegmentLimitFrames = (ENCODING_SEGMENT_MILSECONDS * m_sStreamData.fps) / 1000; - m_nHardLimitFrames = (ENCODING_SEGMENT_LIMIT_MILSECONDS * m_sStreamData.fps) / 1000; - - #ifndef DIRECT_MJPEG_COMPOSING - #ifdef OPENCV_VIDEO_OUTPUT - m_pEncoderA = new cv::VideoWriter(); - if (m_pEncoderA == NULL) - { - LOG_ERROR("Encoder A Create Failure!"); - return false; - }; - - //m_pEncoderA->set(cv::VIDEOWRITER_PROP_QUALITY, 10.0); - //m_pEncoderA->set(cv::VIDEOWRITER_PROP_NSTRIPES, -1.0); - - m_pEncoderB = new cv::VideoWriter(); - if (m_pEncoderA == NULL) - { - LOG_ERROR("Encoder B Create Failure!"); - return false; - }; - - //m_pEncoderB->set(cv::VIDEOWRITER_PROP_QUALITY, 10.0); - //m_pEncoderB->set(cv::VIDEOWRITER_PROP_NSTRIPES, -1.0); - - #else - if (! initLibAV()) - { - return false; - } - - m_pFormat = av_guess_format(VIDEO_OUTPUT_CONTAINER, "test." VIDEO_OUTPUT_CONTAINER, NULL); - - if (m_pFormat == NULL) - { - LOG_ERROR("Out VideoFormat Not Found!"); - return false; - #ifdef DEBUG_EXTRA - } - else - { - LOG("Output video Format"); - LOG(VIDEO_OUTPUT_CONTAINER); - #endif - }; - - #ifdef SEPARATED_VIDEO_ENCODERS - /* Stream A */ - m_pVideoACodec = avcodec_find_encoder(VIDEO_OUTPUT_CODEC); - if (m_pVideoACodec == NULL) - { - LOG_ERROR("Encoder Video Codec Not Found!"); - return false; - #ifdef DEBUG_EXTRA - } - else - { - LOG("Video Encoder A Created"); - #endif - }; - m_pCodecACtx = avcodec_alloc_context3(m_pVideoACodec); - if (m_pCodecACtx == NULL) - { - LOG_ERROR("Video Encoder A Context Memory Allocation Error!"); - av_free(m_pVideoACodec); - avformat_free_context(m_pFormatCtxA); - return false; - #ifdef DEBUG_EXTRA - } - else - { - LOG("Video Encoder Context A Allocated"); - #endif - }; - /* Stream B */ - m_pVideoBCodec = avcodec_find_encoder(VIDEO_OUTPUT_CODEC); - if (m_pVideoBCodec == NULL) - { - LOG_ERROR("Out VideoCodec Not Found!"); - av_free(m_pVideoACodec); - return false; - #ifdef DEBUG_EXTRA - } - else - { - LOG("Video Encoder B Created"); - #endif - }; - m_pCodecBCtx = avcodec_alloc_context3(m_pVideoBCodec); - if (m_pCodecBCtx == NULL) - { - LOG_ERROR("Video Encoder B Context Memory Allocation Error!"); - av_free(m_pVideoACodec); - av_free(m_pVideoBCodec); - avformat_free_context(m_pFormatCtxA); - avformat_free_context(m_pFormatCtxB); - return false; - #ifdef DEBUG_EXTRA - } - else - { - LOG("Video Encoder Context B Allocated"); - #endif - }; - - m_pCodecACtx->codec_id = VIDEO_OUTPUT_CODEC; - m_pCodecACtx->codec_type = AVMEDIA_TYPE_VIDEO; - m_pCodecACtx->pix_fmt = VIDEO_OUTPUT_PIX_FMT; - m_pCodecACtx->bit_rate = VIDEO_OUTPUT_BITRATE; - m_pCodecACtx->max_b_frames = 1; - m_pCodecACtx->width = m_pMaster->m_sEmbedVideoData.width; - m_pCodecACtx->height = m_pMaster->m_sEmbedVideoData.height; - m_pCodecACtx->time_base.num = 1; - m_pCodecACtx->time_base.den = m_sStreamData.fps; - m_pCodecACtx->framerate.num = m_sStreamData.fps; - m_pCodecACtx->framerate.den = 1; - - m_pCodecBCtx->codec_id = VIDEO_OUTPUT_CODEC; - m_pCodecBCtx->codec_type = AVMEDIA_TYPE_VIDEO; - m_pCodecBCtx->pix_fmt = VIDEO_OUTPUT_PIX_FMT; - m_pCodecBCtx->bit_rate = VIDEO_OUTPUT_BITRATE; - m_pCodecBCtx->max_b_frames = 1; - m_pCodecBCtx->width = m_pMaster->m_sEmbedVideoData.width; - m_pCodecBCtx->height = m_pMaster->m_sEmbedVideoData.height; - m_pCodecBCtx->time_base.num = 1; - m_pCodecBCtx->time_base.den = m_sStreamData.fps; - m_pCodecBCtx->framerate.num = m_sStreamData.fps; - m_pCodecBCtx->framerate.den = 1; - - // https://pastebin.com/yG37YhWW - - // https://stackoverflow.com/questions/49276997/raw-h264-frames-in-mp4-container-using-libavcodec - // G@ avcodec encode NALU mp4 - - #if (LIBAVCODEC_VERSION_MAJOR > 54) - ////m_pCodecACtx->codec_tag = av_codec_get_tag( m_pFormatCtxA->oformat->codec_tag, VIDEO_OUTPUT_CODEC ); - #endif - - #if (LIBAVCODEC_VERSION_MAJOR > 54) - ////m_pCodecBCtx->codec_tag = av_codec_get_tag( m_pFormatCtxB->oformat->codec_tag, VIDEO_OUTPUT_CODEC ); - #endif - m_pFormatOpts = NULL; - - // https://stackoverflow.com/questions/70060148/libav-producing-mp4-file-with-extremely-high-frame-rate - - if ((m_pCodecACtx->codec_id == AV_CODEC_ID_H264) || (m_pCodecACtx->codec_id == AV_CODEC_ID_H265)) - { - #ifdef DEBUG_EXTRA - LOG("Begin Options!"); - #endif - // Reference for AvFormatContext options : https://ffmpeg.org/doxygen/2.8/movenc_8c_source.html - // Set format's privater options, to be passed to avformat_write_header() - - /* - - mp4 muxer AVOptions: - -movflags E..... MOV muxer flags (default 0) - rtphint E..... Add RTP hint tracks - empty_moov E..... Make the initial moov atom empty (not supported by QuickTime) - frag_keyframe E..... Fragment at video keyframes - separate_moof E..... Write separate moof/mdat atoms for each track - frag_custom E..... Flush fragments on caller requests - isml E..... Create a live smooth streaming feed (for pushing to a publishing point) - faststart E..... Run a second pass to put the index (moov atom) at the beginning of the file - omit_tfhd_offset E..... Omit the base data offset in tfhd atoms - delay_moov ?? - -moov_size E..... maximum moov size so it can be placed at the begin (from 0 to INT_MAX) (default 0) - -rtpflags E..... RTP muxer flags (default 0) - latm E..... Use MP4A-LATM packetization instead of MPEG4-GENERIC for AAC - rfc2190 E..... Use RFC 2190 packetization instead of RFC 4629 for H.263 - skip_rtcp E..... Don't send RTCP sender reports - h264_mode0 E..... Use mode 0 for H264 in RTP - send_bye E..... Send RTCP BYE packets when finishing - -skip_iods E..... Skip writing iods atom. (from 0 to 1) (default 1) - -iods_audio_profile E..... iods audio profile atom. (from -1 to 255) (default -1) - -iods_video_profile E..... iods video profile atom. (from -1 to 255) (default -1) - -frag_duration E..... Maximum fragment duration (from 0 to INT_MAX) (default 0) - -min_frag_duration E..... Minimum fragment duration (from 0 to INT_MAX) (default 0) - -frag_size E..... Maximum fragment size (from 0 to INT_MAX) (default 0) - -ism_lookahead E..... Number of lookahead entries for ISM files (from 0 to INT_MAX) (default 0) - -use_editlist E..... use edit list (from -1 to 1) (default -1) - -video_track_timescale E..... set timescale of all video tracks (from 0 to INT_MAX) (default 0) - - - */ - if (av_dict_set(&m_pFormatOpts, "movflags", "isml+faststart+frag_keyframe+empty_moov+omit_tfhd_offset", 0) < 0) - { - LOG_ERROR("av_dict_set movflags!"); - #ifdef DEBUG_EXTRA - } - else - { - LOG("MOV FLAG SET!"); - #endif - }; - - // if( av_dict_set( &m_pFormatOpts, "live", "1", 0 ) < 0 ){ - // LOG_ERROR( "av_dict_set live!" ); - // }; - - // default brand is "isom", which fails on some devices - if (av_dict_set(&m_pFormatOpts, "brand", "mp42", 0) < 0) - { - LOG_ERROR("av_dict_set brand!"); - }; - // m_pCodecCtx->max_b_frames = 1; - // m_pCodecCtx->level = 31; - - m_pCodecACtx->gop_size = m_sStreamData.fps << 1; // VIDEO_OUTPUT_GOP; // emit one intra frame every X frames - /// P-frames, generated by referencing data from prev and future frames. - /// [Compression up, CPU usage up] - /// [use 3/gop] - m_pCodecACtx->max_b_frames = 5; - - /// Can be used by a P-frame(predictive, partial frame) to help define a future frame in a compressed video. - /// [use 3?5 ref per P] - m_pCodecACtx->refs = 3; - - /// Compression efficiency (slower -> better quality + higher cpu%) - /// [ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow] - /// Set this option to "ultrafast" is critical for realtime encoding - av_opt_set(m_pCodecACtx->priv_data, "preset", "ultrafast", 0); - // av_opt_set( m_pCodecCtx->priv_data, "preset", "fast", 0 ); - // av_opt_set( m_pCodecCtx->priv_data, "preset", "slow", 0 ); - - /// Compression rate (lower -> higher compression) compress to lower size, makes decoded image more noisy - /// Range: [0; 51], sane range: [18; 26]. I used 35 as good compression/quality compromise. This option also critical for realtime encoding - av_opt_set(m_pCodecACtx->priv_data, "crf", "32", 0); - - /// Change settings based upon the specifics of input - /// [psnr, ssim, grain, zerolatency, fastdecode, animation] - /// This option is most critical for realtime encoding, because it removes delay between 1th input frame and 1th output packet. - av_opt_set(m_pCodecACtx->priv_data, "tune", "zerolatency", 0); - - /// Disable b-pyramid. CLI options for this is "-b-pyramid 0" - /// Because Quicktime (ie. iOS) doesn't support this option - av_opt_set(m_pCodecACtx->priv_data, "b-pyramid", "0", 0); - #ifdef DEBUG_EXTRA - LOG("End Options!"); - #endif - } - else - { - if (m_pFormat->flags & AVFMT_GLOBALHEADER) - { - m_pCodecACtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; - } - }; - - if ((m_pCodecBCtx->codec_id == AV_CODEC_ID_H264) || (m_pCodecBCtx->codec_id == AV_CODEC_ID_H265)) - { - #ifdef DEBUG_EXTRA - LOG("Begin Options!"); - #endif - // Reference for AvFormatContext options : https://ffmpeg.org/doxygen/2.8/movenc_8c_source.html - // Set format's privater options, to be passed to avformat_write_header() - - /* - - mp4 muxer AVOptions: - -movflags E..... MOV muxer flags (default 0) - rtphint E..... Add RTP hint tracks - empty_moov E..... Make the initial moov atom empty (not supported by QuickTime) - frag_keyframe E..... Fragment at video keyframes - separate_moof E..... Write separate moof/mdat atoms for each track - frag_custom E..... Flush fragments on caller requests - isml E..... Create a live smooth streaming feed (for pushing to a publishing point) - faststart E..... Run a second pass to put the index (moov atom) at the beginning of the file - omit_tfhd_offset E..... Omit the base data offset in tfhd atoms - delay_moov ?? - -moov_size E..... maximum moov size so it can be placed at the begin (from 0 to INT_MAX) (default 0) - -rtpflags E..... RTP muxer flags (default 0) - latm E..... Use MP4A-LATM packetization instead of MPEG4-GENERIC for AAC - rfc2190 E..... Use RFC 2190 packetization instead of RFC 4629 for H.263 - skip_rtcp E..... Don't send RTCP sender reports - h264_mode0 E..... Use mode 0 for H264 in RTP - send_bye E..... Send RTCP BYE packets when finishing - -skip_iods E..... Skip writing iods atom. (from 0 to 1) (default 1) - -iods_audio_profile E..... iods audio profile atom. (from -1 to 255) (default -1) - -iods_video_profile E..... iods video profile atom. (from -1 to 255) (default -1) - -frag_duration E..... Maximum fragment duration (from 0 to INT_MAX) (default 0) - -min_frag_duration E..... Minimum fragment duration (from 0 to INT_MAX) (default 0) - -frag_size E..... Maximum fragment size (from 0 to INT_MAX) (default 0) - -ism_lookahead E..... Number of lookahead entries for ISM files (from 0 to INT_MAX) (default 0) - -use_editlist E..... use edit list (from -1 to 1) (default -1) - -video_track_timescale E..... set timescale of all video tracks (from 0 to INT_MAX) (default 0) - - - */ - // m_pCodecCtx->max_b_frames = 1; - // m_pCodecCtx->level = 31; - - m_pCodecBCtx->gop_size = m_sStreamData.fps << 1; // VIDEO_OUTPUT_GOP; // emit one intra frame every X frames - /// P-frames, generated by referencing data from prev and future frames. - /// [Compression up, CPU usage up] - /// [use 3/gop] - m_pCodecBCtx->max_b_frames = 5; - - /// Can be used by a P-frame(predictive, partial frame) to help define a future frame in a compressed video. - /// [use 3?5 ref per P] - m_pCodecBCtx->refs = 3; - - /// Compression efficiency (slower -> better quality + higher cpu%) - /// [ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow] - /// Set this option to "ultrafast" is critical for realtime encoding - av_opt_set(m_pCodecBCtx->priv_data, "preset", "ultrafast", 0); - // av_opt_set( m_pCodecCtx->priv_data, "preset", "fast", 0 ); - // av_opt_set( m_pCodecCtx->priv_data, "preset", "slow", 0 ); - - /// Compression rate (lower -> higher compression) compress to lower size, makes decoded image more noisy - /// Range: [0; 51], sane range: [18; 26]. I used 35 as good compression/quality compromise. This option also critical for realtime encoding - av_opt_set(m_pCodecBCtx->priv_data, "crf", "32", 0); - - /// Change settings based upon the specifics of input - /// [psnr, ssim, grain, zerolatency, fastdecode, animation] - /// This option is most critical for realtime encoding, because it removes delay between 1th input frame and 1th output packet. - av_opt_set(m_pCodecBCtx->priv_data, "tune", "zerolatency", 0); - - /// Disable b-pyramid. CLI options for this is "-b-pyramid 0" - /// Because Quicktime (ie. iOS) doesn't support this option - av_opt_set(m_pCodecBCtx->priv_data, "b-pyramid", "0", 0); - #ifdef DEBUG_EXTRA - LOG("End Options!"); - #endif - } - else - { - if (m_pFormat->flags & AVFMT_GLOBALHEADER) - { - m_pCodecBCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; - } - }; - - const AVRational dst_fps = {m_sStreamData.fps, 1}; - - #ifdef DEBUG_EXTRA - char TB[129]; - sprintf(TB, "TimeBaseA: num[%d]/den[%d]", m_pCodecACtx->time_base.num, m_pCodecACtx->time_base.den); - LOG(TB); - sprintf(TB, "TimeBaseB: num[%d]/den[%d]", m_pCodecBCtx->time_base.num, m_pCodecBCtx->time_base.den); - LOG(TB); - #endif - - ////m_pVideoStrA->time_base = m_pCodecACtx->time_base; - ////m_pVideoStrB->time_base = m_pCodecBCtx->time_base; - - // avcodec_get_context_defaults3( m_pVideoStrA->codec, m_pVideoCodec ); - - // m_pVideoStrA->codec->width = m_pMaster->m_sEmbedVideoData.width; - // m_pVideoStrA->codec->height = m_pMaster->m_sEmbedVideoData.height; - // m_pVideoStrA->codec->pix_fmt = VIDEO_OUTPUT_PIX_FMT; - // m_pVideoStrA->codec->time_base = m_pVideoStrB->time_base = av_inv_q(dst_fps); - //// m_pVideoStrA->r_frame_rate = m_pVideoStrA->avg_frame_rate = - ////dst_fps; - - // avcodec_get_context_defaults3( m_pVideoStrB->codec, m_pVideoCodec ); - - // m_pVideoStrB->codec->width = m_pMaster->m_sEmbedVideoData.width; - // m_pVideoStrB->codec->height = m_pMaster->m_sEmbedVideoData.height; - // m_pVideoStrB->codec->pix_fmt = VIDEO_OUTPUT_PIX_FMT; - // m_pVideoStrB->codec->time_base = m_pVideoStrB->time_base = av_inv_q(dst_fps); - //// m_pVideoStrB->r_frame_rate = m_pVideoStrB->avg_frame_rate = - ////dst_fps; - - // if ( m_pFormatCtxA->oformat->flags & AVFMT_GLOBALHEADER ) m_pVideoStrA->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; - // if ( m_pFormatCtxB->oformat->flags & AVFMT_GLOBALHEADER ) m_pVideoStrB->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; - - //// avcodec_parameters_from_context( m_pVideoStrA->codecpar, - ////m_pCodecACtx ); - // m_pVideoStrA->codecpar->format = VIDEO_OUTPUT_PIX_FMT; - // m_pVideoStrA->codecpar->extradata = m_pCodecCtx->extradata; - // m_pVideoStrA->codecpar->extradata_size = m_pCodecCtx->extradata_size; - - //// avcodec_parameters_from_context( m_pVideoStrB->codecpar, - ////m_pCodecBCtx ); - // m_pVideoStrB->codecpar->format = VIDEO_OUTPUT_PIX_FMT; - // m_pVideoStrB->codecpar->extradata = m_pCodecCtx->extradata; - // m_pVideoStrB->codecpar->extradata_size = m_pCodecCtx->extradata_size; - - if (avcodec_is_open(m_pCodecACtx) == 0) - { - LOG("output codec context is closed, opening"); - if (avcodec_open2(m_pCodecACtx, m_pVideoACodec, NULL) < 0) - { - LOG_ERROR("Error opening2 encoder"); - return false; - #ifdef DEBUG_EXTRA - } - else - { - LOG("output codec context is opened"); - #endif - }; - - #ifdef DEBUG_EXTRA - } - else - { - LOG("output codec context is already opened"); - #endif - }; - - if (avcodec_is_open(m_pCodecBCtx) == 0) - { - LOG("output codec context is closed, opening"); - if (avcodec_open2(m_pCodecBCtx, m_pVideoBCodec, NULL) < 0) - { - LOG_ERROR("Error opening2 encoder"); - return false; - #ifdef DEBUG_EXTRA - } - else - { - LOG("output codec context is opened"); - #endif - }; - - #ifdef DEBUG_EXTRA - } - else - { - LOG("output codec context is already opened"); - #endif - }; - #else // SEPARATED_VIDEO_ENCODERS - if (avformat_alloc_output_context2(&m_pFormatCtxA, m_pFormat, NULL, "test." VIDEO_OUTPUT_CONTAINER) < 0) - { - LOG_ERROR("Format CTX A alloc error!"); - return false; - } - else - { - av_dict_set(&m_pFormatCtxA->metadata, "Author", "Argus Sec. System", 0); - m_pFormatCtxA->flags |= AVFMT_NOTIMESTAMPS | AVFMT_TS_NONSTRICT; - }; - - if (avformat_alloc_output_context2(&m_pFormatCtxB, m_pFormat, NULL, "test." VIDEO_OUTPUT_CONTAINER) < 0) - { - LOG_ERROR("Format CTX B alloc error!"); - avformat_free_context(m_pFormatCtxA); - return false; - } - else - { - av_dict_set(&m_pFormatCtxB->metadata, "Author", "Argus Sec. System", 0); - m_pFormatCtxB->flags |= AVFMT_NOTIMESTAMPS | AVFMT_TS_NONSTRICT; - }; - m_pVideoCodec = avcodec_find_encoder(VIDEO_OUTPUT_CODEC); - if (m_pVideoCodec == NULL) - { - LOG_ERROR("Output VideoCodec Not Found!"); - avformat_free_context(m_pFormatCtxA); - avformat_free_context(m_pFormatCtxB); - return false; - #ifdef DEBUG_EXTRA - } - else - { - LOG("Output Video Codec Found"); - #endif - }; - - m_pCodecCtx = avcodec_alloc_context3(m_pVideoCodec); - if (m_pCodecCtx == NULL) - { - LOG_ERROR("Out VideoCodec Context Memory Allocation Error"); - av_free(m_pVideoCodec); - avformat_free_context(m_pFormatCtxA); - avformat_free_context(m_pFormatCtxB); - return false; - #ifdef DEBUG_EXTRA - } - else - { - LOG("Out Codec Context3 Allocated"); - #endif - }; - m_pVideoStrA = avformat_new_stream(m_pFormatCtxA, m_pVideoCodec); - if (m_pVideoStrA == NULL) - { - LOG_ERROR("VideoStream A Not Created!"); - avcodec_free_context(&m_pCodecCtx); - av_free(m_pCodecCtx); - av_free(m_pVideoCodec); - // avformat_close_input ( &m_pFormatCtxA ); - // avformat_close_input ( &m_pFormatCtxB ); - avformat_free_context(m_pFormatCtxA); - avformat_free_context(m_pFormatCtxB); - return false; - #ifdef DEBUG_EXTRA - } - else - { - LOG("VideoStream A is Created"); - #endif - }; - - m_pVideoStrB = avformat_new_stream(m_pFormatCtxB, m_pVideoCodec); - if (m_pVideoStrB == NULL) - { - LOG_ERROR("VideoStream B Not Created!"); - - avcodec_free_context(&m_pCodecCtx); - av_free(m_pCodecCtx); - av_free(m_pVideoCodec); - // avformat_close_input ( &m_pFormatCtxA ); - // avformat_close_input ( &m_pFormatCtxB ); - avformat_free_context(m_pFormatCtxA); - avformat_free_context(m_pFormatCtxB); - return false; - #ifdef DEBUG_EXTRA - } - else - { - LOG("VideoStream B is Created"); - #endif - }; - m_pCodecCtx->codec_id = VIDEO_OUTPUT_CODEC; - m_pCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO; - m_pCodecCtx->pix_fmt = VIDEO_OUTPUT_PIX_FMT; - m_pCodecCtx->bit_rate = VIDEO_OUTPUT_BITRATE; - // m_pCodecCtx->thread_count = 1; - // m_pCodecCtx->bit_rate_tolerance = 1; - // m_pCodecCtx->global_quality = 100; - // m_pCodecCtx->compression_level = 2; - m_pCodecCtx->max_b_frames = 1; - m_pCodecCtx->width = m_pMaster->m_sEmbedVideoData.width; - m_pCodecCtx->height = m_pMaster->m_sEmbedVideoData.height; - m_pCodecCtx->time_base.num = 1; - m_pCodecCtx->time_base.den = m_sStreamData.fps; - m_pCodecCtx->framerate.num = m_sStreamData.fps; - m_pCodecCtx->framerate.den = 1; - - // https://pastebin.com/yG37YhWW - - // https://stackoverflow.com/questions/49276997/raw-h264-frames-in-mp4-container-using-libavcodec - // G@ avcodec encode NALU mp4 - - #if (LIBAVCODEC_VERSION_MAJOR > 54) - m_pCodecCtx->codec_tag = av_codec_get_tag(m_pFormatCtxA->oformat->codec_tag, VIDEO_OUTPUT_CODEC); - #endif - m_pFormatOpts = NULL; - - // https://stackoverflow.com/questions/70060148/libav-producing-mp4-file-with-extremely-high-frame-rate - - if ((m_pCodecCtx->codec_id == AV_CODEC_ID_H264) || (m_pCodecCtx->codec_id == AV_CODEC_ID_H265)) - { - #ifdef DEBUG_EXTRA - LOG("Begin Options!"); - #endif - // Reference for AvFormatContext options : https://ffmpeg.org/doxygen/2.8/movenc_8c_source.html - // Set format's privater options, to be passed to avformat_write_header() - - /* - - mp4 muxer AVOptions: - -movflags E..... MOV muxer flags (default 0) - rtphint E..... Add RTP hint tracks - empty_moov E..... Make the initial moov atom empty (not supported by QuickTime) - frag_keyframe E..... Fragment at video keyframes - separate_moof E..... Write separate moof/mdat atoms for each track - frag_custom E..... Flush fragments on caller requests - isml E..... Create a live smooth streaming feed (for pushing to a publishing point) - faststart E..... Run a second pass to put the index (moov atom) at the beginning of the file - omit_tfhd_offset E..... Omit the base data offset in tfhd atoms - delay_moov ?? - -moov_size E..... maximum moov size so it can be placed at the begin (from 0 to INT_MAX) (default 0) - -rtpflags E..... RTP muxer flags (default 0) - latm E..... Use MP4A-LATM packetization instead of MPEG4-GENERIC for AAC - rfc2190 E..... Use RFC 2190 packetization instead of RFC 4629 for H.263 - skip_rtcp E..... Don't send RTCP sender reports - h264_mode0 E..... Use mode 0 for H264 in RTP - send_bye E..... Send RTCP BYE packets when finishing - -skip_iods E..... Skip writing iods atom. (from 0 to 1) (default 1) - -iods_audio_profile E..... iods audio profile atom. (from -1 to 255) (default -1) - -iods_video_profile E..... iods video profile atom. (from -1 to 255) (default -1) - -frag_duration E..... Maximum fragment duration (from 0 to INT_MAX) (default 0) - -min_frag_duration E..... Minimum fragment duration (from 0 to INT_MAX) (default 0) - -frag_size E..... Maximum fragment size (from 0 to INT_MAX) (default 0) - -ism_lookahead E..... Number of lookahead entries for ISM files (from 0 to INT_MAX) (default 0) - -use_editlist E..... use edit list (from -1 to 1) (default -1) - -video_track_timescale E..... set timescale of all video tracks (from 0 to INT_MAX) (default 0) - - - */ - if (av_dict_set(&m_pFormatOpts, "movflags", "isml+faststart+frag_keyframe+empty_moov+omit_tfhd_offset", 0) < 0) - { - LOG_ERROR("av_dict_set movflags!"); - #ifdef DEBUG_EXTRA - } - else - { - LOG("MOV FLAG SET!"); - #endif - }; - - // if( av_dict_set( &m_pFormatOpts, "live", "1", 0 ) < 0 ){ - // LOG_ERROR( "av_dict_set live!" ); - // }; - - // default brand is "isom", which fails on some devices - if (av_dict_set(&m_pFormatOpts, "brand", "mp42", 0) < 0) - { - LOG_ERROR("av_dict_set brand!"); - }; - // m_pCodecCtx->max_b_frames = 1; - // m_pCodecCtx->level = 31; - - m_pCodecCtx->gop_size = m_sStreamData.fps << 1; // VIDEO_OUTPUT_GOP; // emit one intra frame every X frames - /// P-frames, generated by referencing data from prev and future frames. - /// [Compression up, CPU usage up] - /// [use 3/gop] - m_pCodecCtx->max_b_frames = 5; - - /// Can be used by a P-frame(predictive, partial frame) to help define a future frame in a compressed video. - /// [use 3?5 ref per P] - m_pCodecCtx->refs = 3; - - /// Compression efficiency (slower -> better quality + higher cpu%) - /// [ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow] - /// Set this option to "ultrafast" is critical for realtime encoding - av_opt_set(m_pCodecCtx->priv_data, "preset", "ultrafast", 0); - // av_opt_set( m_pCodecCtx->priv_data, "preset", "fast", 0 ); - // av_opt_set( m_pCodecCtx->priv_data, "preset", "slow", 0 ); - - /// Compression rate (lower -> higher compression) compress to lower size, makes decoded image more noisy - /// Range: [0; 51], sane range: [18; 26]. I used 35 as good compression/quality compromise. This option also critical for realtime encoding - av_opt_set(m_pCodecCtx->priv_data, "crf", "32", 0); - - /// Change settings based upon the specifics of input - /// [psnr, ssim, grain, zerolatency, fastdecode, animation] - /// This option is most critical for realtime encoding, because it removes delay between 1th input frame and 1th output packet. - av_opt_set(m_pCodecCtx->priv_data, "tune", "zerolatency", 0); - - /// Disable b-pyramid. CLI options for this is "-b-pyramid 0" - /// Because Quicktime (ie. iOS) doesn't support this option - av_opt_set(m_pCodecCtx->priv_data, "b-pyramid", "0", 0); - #ifdef DEBUG_EXTRA - LOG("End Options!"); - #endif - } - else - { - if (m_pFormat->flags & AVFMT_GLOBALHEADER) - { - m_pCodecCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; - } - }; - - const AVRational dst_fps = {m_sStreamData.fps, 1}; - - #ifdef DEBUG_EXTRA - char TB[129]; - sprintf(TB, "TimeBase: num[%d]/den[%d]", m_pCodecCtx->time_base.num, m_pCodecCtx->time_base.den); - LOG(TB); - #endif - - m_pVideoStrA->time_base = m_pCodecCtx->time_base; - m_pVideoStrB->time_base = m_pCodecCtx->time_base; - - // avcodec_get_context_defaults3( m_pVideoStrA->codec, m_pVideoCodec ); - - // m_pVideoStrA->codec->width = m_pMaster->m_sEmbedVideoData.width; - // m_pVideoStrA->codec->height = m_pMaster->m_sEmbedVideoData.height; - // m_pVideoStrA->codec->pix_fmt = VIDEO_OUTPUT_PIX_FMT; - // m_pVideoStrA->codec->time_base = m_pVideoStrB->time_base = av_inv_q(dst_fps); - m_pVideoStrA->r_frame_rate = m_pVideoStrB->avg_frame_rate = dst_fps; - - // avcodec_get_context_defaults3( m_pVideoStrB->codec, m_pVideoCodec ); - - // m_pVideoStrB->codec->width = m_pMaster->m_sEmbedVideoData.width; - // m_pVideoStrB->codec->height = m_pMaster->m_sEmbedVideoData.height; - // m_pVideoStrB->codec->pix_fmt = VIDEO_OUTPUT_PIX_FMT; - // m_pVideoStrB->codec->time_base = m_pVideoStrB->time_base = av_inv_q(dst_fps); - m_pVideoStrB->r_frame_rate = m_pVideoStrB->avg_frame_rate = dst_fps; - - // if ( m_pFormatCtxA->oformat->flags & AVFMT_GLOBALHEADER ) m_pVideoStrA->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; - // if ( m_pFormatCtxB->oformat->flags & AVFMT_GLOBALHEADER ) m_pVideoStrB->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; - - avcodec_parameters_from_context(m_pVideoStrA->codecpar, m_pCodecCtx); - // m_pVideoStrA->codecpar->format = VIDEO_OUTPUT_PIX_FMT; - // m_pVideoStrA->codecpar->extradata = m_pCodecCtx->extradata; - // m_pVideoStrA->codecpar->extradata_size = m_pCodecCtx->extradata_size; - - avcodec_parameters_from_context(m_pVideoStrB->codecpar, m_pCodecCtx); - // m_pVideoStrB->codecpar->format = VIDEO_OUTPUT_PIX_FMT; - // m_pVideoStrB->codecpar->extradata = m_pCodecCtx->extradata; - // m_pVideoStrB->codecpar->extradata_size = m_pCodecCtx->extradata_size; - - if (avcodec_is_open(m_pCodecCtx) == 0) - { - LOG("output codec context is closed, opening"); - if (avcodec_open2(m_pCodecCtx, m_pVideoCodec, NULL) < 0) - { - LOG_ERROR("Error opening2 encoder"); - return false; - #ifdef DEBUG_EXTRA - } - else - { - LOG("output codec context is opened"); - #endif - }; - - #ifdef DEBUG_EXTRA - } - else - { - LOG("output codec context is already opened"); - #endif - }; - #endif // SEPARATED_VIDEO_ENCODERS - m_pConvertCtx = - sws_getContext(m_pMaster->m_sEmbedVideoData.width, m_pMaster->m_sEmbedVideoData.height, AV_PIX_FMT_BGR24, m_pMaster->m_sEmbedVideoData.width, m_pMaster->m_sEmbedVideoData.height, VIDEO_OUTPUT_PIX_FMT, SWS_FAST_BILINEAR, NULL, NULL, NULL); - if (m_pConvertCtx == NULL) - { - return false; - } - m_pAVFrame = av_frame_alloc(); - if (m_pAVFrame == NULL) - { - return false; - }; - m_pOutBuffer = (uint8_t *) av_malloc(av_image_get_buffer_size(VIDEO_OUTPUT_PIX_FMT, m_pMaster->m_sEmbedVideoData.width, m_pMaster->m_sEmbedVideoData.height, BUFFER_ALIGN)); - if (m_pOutBuffer == NULL) - { - return false; - }; - m_pAVFrame->width = m_pMaster->m_sEmbedVideoData.width; - m_pAVFrame->height = m_pMaster->m_sEmbedVideoData.height; - m_pAVFrame->format = VIDEO_OUTPUT_PIX_FMT; - // av_frame_get_buffer( m_pAVFrame, 0 ); - av_image_fill_arrays(m_pAVFrame->data, m_pAVFrame->linesize, m_pOutBuffer, VIDEO_OUTPUT_PIX_FMT, m_pMaster->m_sEmbedVideoData.width, m_pMaster->m_sEmbedVideoData.height, 1); - - // av_frame_make_writable( m_pAVFrame ); - #endif // !OPENCV_VIDEO_OUTPUT - #endif // !DIRECT_MJPEG_COMPOSING - return init(); - } -#endif // !EVE_SEQUENTAL_OUTPUT - - // encoding thread - - void streamHandler::m_fThreadProc(void) - { - size_t nQueueSize; - #ifndef DIRECT_MJPEG_COMPOSING - #ifndef OPENCV_VIDEO_OUTPUT - AVPacket mPacket; - int bGotPacket; - int rVal = 0; - av_init_packet(&mPacket); - #endif - #endif - pthread_setname_np(pthread_self(), "VideoStream"); - while (m_bThreadStatus != TH_ENDED) - { - // At the begining All streams are closed --> try to Open - if (m_bThreadStatus < TH_WORKING){ - #ifdef EVE_SEQUENTAL_OUTPUT - CSTR tAM = getUniqID_MD5(); - if( tAM ){ - sprintf(m_sStreamSegmentInfo.scratchPath, "%s/%s.%s", m_pVideoScratchPath, tAM, VIDEO_OUTPUT_CONTAINER); - strncpy(m_sStreamSegmentInfo.recordMD5, tAM, 32); - m_sStreamSegmentInfo.recordMD5[32] = (char) 0; - free(tAM); - m_sStreamSegmentInfo.stream_id = m_sStreamData.id; - PF_TIMESTAMP ts; - getPFTS(&ts); - m_sStreamSegmentInfo.streamTSS = ts.seconds; - m_sStreamSegmentInfo.streamTMS = ts.milliseconds; - #ifdef DEBUG_EXTRA - char tB[128]; - sprintf(tB, "First Time opened %d.%d", m_sStreamSegmentInfo.streamTSS, m_sStreamSegmentInfo.streamTMS); - LOG(tB); - #endif - strncpy(m_sStreamSegmentInfo.recordEXT, VIDEO_OUTPUT_CONTAINER, 6); - m_sStreamSegmentInfo.streamFPS = m_sStreamData.fps; - m_sStreamSegmentInfo.streamWidth = m_pMaster->getWidh(); - m_sStreamSegmentInfo.streamHeight = m_pMaster->getHeight(); - m_sStreamSegmentInfo.eventIDS.clear(); - m_sStreamSegmentInfo.eventTSS.clear(); - m_sStreamSegmentInfo.eventTMS.clear(); - m_sStreamSegmentInfo.eventFrames.clear(); - m_sStreamSegmentInfo.dataSize = 0; - m_sStreamSegmentInfo.db_id = 0; - #ifdef DIRECT_MJPEG_COMPOSING - m_pOutputFD = fopen(m_sStreamSegmentInfo.scratchPath, "wb+"); - m_nSegFrameCounter = 0; - m_nSegShiftFrames = 0; - m_bSegActive = true; - m_bSegDelete = m_bNSegDelete; - m_bNSegDelete = true; - #else // !DIRECT_MJPEG_COMPOSING - #ifdef OPENCV_VIDEO_OUTPUT - if ( m_pEncoder ){ - //int fourcc = cv::VideoWriter::fourcc('H', '2', '6', '4'); - int fourcc =cv::VideoWriter::fourcc('a', 'v', 'c', '1'); - //int fourcc = cv::VideoWriter::fourcc('M', 'J', 'P', 'G'); - double fps = m_sStreamData.fps; - cv::String mn(m_sStreamSegmentInfo.scratchPath); - cv::Size fz(m_sStreamData.width, m_sStreamData.height); - // open (const String &filename, int fourcc, double fps, Size frameSize, bool isColor=true) - if (! m_pEncoder->open(mn, fourcc, fps, fz) ) { - LOG_ERROR("Cannot Open Output VideoStream!"); - m_bThreadStatus = TH_ENDED; - continue; - #ifdef DEBUG_EXTRA - } else { - char tB[256]; - sprintf(tB, "VideoStream is Created [%s] %.2f fps", m_sStreamSegmentInfo.scratchPath, fps); - LOG(tB); - #endif - }; - m_bSegActive = true; - m_bSegDelete = m_bNSegDelete; - m_bNSegDelete = true; - m_nSegFrameCounter = 0; - m_nSegShiftFrames = 0; - } else { - LOG_ERROR("No Encoder Object!"); - m_bThreadStatus = TH_ENDED; - continue; - }; - #else // !OPENCV_VIDEO_OUTPUT - // Check if Encoder is Ready - if (m_pFormat == NULL){ - m_bThreadStatus = TH_ENDED; - continue; - } - - #ifdef SEPARATED_VIDEO_ENCODERS - if (avformat_alloc_output_context2(&m_pFormatCtx, m_pFormat, NULL, "test." VIDEO_OUTPUT_CONTAINER) < 0){ - LOG_ERROR("Format CTX alloc error!"); - m_bThreadStatus = TH_ENDED; - continue; - } else { - av_dict_set(&m_pFormatCtx->metadata, "Author", "Argus Sec. System", 0); - m_pFormatCtx->flags |= AVFMT_NOTIMESTAMPS | AVFMT_TS_NONSTRICT; - }; - - m_pVideoStr = avformat_new_stream(m_pFormatCtx, m_pVideoACodec); - if (m_pVideoStr == NULL){ - avformat_free_context(m_pFormatCtx); - m_bThreadStatus = TH_ENDED; - continue; - #ifdef DEBUG_EXTRA - } else { - LOG("VideoStream is Created"); - #endif - }; - const AVRational dst_fps = {m_sStreamData.fps, 1}; - m_pVideoStr->r_frame_rate = m_pVideoStrA->avg_frame_rate = dst_fps; - m_pVideoStr->time_base = m_pCodecCtx->time_base; - avcodec_parameters_from_context(m_pVideoStr->codecpar, m_pCodecACtx); - #ifdef DEBUG_EXTRA - LOG("Opening Stream"); - LOG(m_cSegName); - char tB[128]; - sprintf(tB, "FFPTS:%llu FNUM:%llu S2KF:%llu", m_pVideoStr->start_time, m_pVideoStr->nb_frames, m_pVideoStr->first_dts); - LOG(tB); - sprintf(tB, "CON ST:%llu DUR:%llu", m_pFormatCtx->start_time, m_pFormatCtx->duration); - LOG(tB); - #endif - // if (avio_open(&m_pFormatCtx->pb, m_cSegNameA, AVIO_FLAG_WRITE) < 0) { - if (avio_open(&m_pFormatCtx->pb, m_sStreamSegmentInfo.scratchPath, AVIO_FLAG_WRITE) < 0) - { - LOG_ERROR("Could not open output file."); - m_bThreadStatus = TH_ENDED; - continue; - }; - if (avformat_write_header(m_pFormatCtx, &m_pFormatOpts) < 0) - { - LOG_ERROR("Error occurred when writing header to output file."); - m_bThreadStatus = TH_ENDED; - continue; - }; - // m_mFrameCounterProtector.lock(); - m_nSegFrameCounter = 0; - m_nSegShiftFrames = 0; - m_bSegActive = true; - m_bSegDelete = m_bNSegDelete; - m_bNSegDelete = true; - // m_mFrameCounterProtector.unlock(); - #else // SEPARATED_VIDEO_ENCODERS - m_nSegSkippedFrames = m_pVideoStr->nb_frames + 1; - if (m_pVideoStr->nb_frames) - { - m_pVideoStr->nb_frames = 0; - m_pVideoStr->start_time = 0; - m_pVideoStr->first_dts = 0; - m_pFormatCtx->start_time = 0; - }; - #ifdef DEBUG_EXTRA - LOG("Opening Stream"); - LOG(m_cSegName); - char tB[128]; - sprintf(tB, "FFPTS:%llu FNUM:%llu S2KF:%llu", m_pVideoStr->start_time, m_pVideoStr->nb_frames, m_pVideoStr->first_dts); - LOG(tB); - sprintf(tB, "CON ST:%llu DUR:%llu", m_pFormatCtx->start_time, m_pFormatCtx->duration); - LOG(tB); - #endif - if (avio_open(&m_pFormatCtx->pb, m_cSegName, AVIO_FLAG_WRITE) < 0) - { - LOG_ERROR("Could not open output file."); - m_bThreadStatus = TH_ENDED; - continue; - }; - if (avformat_write_header(m_pFormatCtx, &m_pFormatOpts) < 0) - { - LOG_ERROR("Error occurred when writing header to output file."); - m_bThreadStatus = TH_ENDED; - continue; - }; - // m_mFrameCounterProtector.lock(); - m_nSegFrameCounter = 0; - m_nSegShiftFrames = 0; - m_bSegActive = true; - m_bSegDelete = m_bNSegDelete; - m_bNSegDelete = true; - // m_mFrameCounterProtector.unlock(); - #endif // SEPARATED_VIDEO_ENCODERS - #ifdef DEBUG_EXTRA - LOG("Stream Opened"); - #endif - #endif // !OPENCV_VIDEO_OUTPUT - #endif // !DIRECT_MJPEG_COMPOSING - }; - // If was not sucessfull - exit ?? - if( !m_bSegActive ){ - LOG_ERROR("Can not Open VideoStream for first time!"); - m_bThreadStatus = TH_ENDED; - continue; - }; - #else - if (! openSegmentA()){ - m_bThreadStatus = TH_ENDED; - LOG_ERROR("Can not Open VideoStream A for first time!"); - continue; - }; - #endif - m_bThreadStatus = TH_WORKING; - continue; - }; - - m_mEncodingQueueProtector.lock(); - nQueueSize = m_qEncodingQueue.size(); - m_mEncodingQueueProtector.unlock(); - - if (nQueueSize) - { - m_mEncodingQueueProtector.lock(); - ENCODING_BUFFER * tData = m_qEncodingQueue.front(); - if (tData) - { - m_qEncodingQueue.pop(); - m_mEncodingQueueProtector.unlock(); - #ifdef DIRECT_MJPEG_COMPOSING - #ifdef EVE_SEQUENTAL_OUTPUT - if( m_pOutputFD ) - { - fwrite(tData->data, 1, tData->size, m_pOutputFD); - m_mFrameCounterProtector.lock(); - m_nSegFrameCounter++; - m_mFrameCounterProtector.unlock(); - }; - #else // ! EVE_SEQUENTAL_OUTPUT - - if (m_bSegAActive) - { - if (m_pOutputFD[0]) - { - fwrite(tData->data, 1, tData->size, m_pOutputFD[0]); - m_mFrameCounterProtector.lock(); - m_nSegAFrameCounter++; - m_mFrameCounterProtector.unlock(); - }; - } - - if (m_bSegBActive) - { - if (m_pOutputFD[1]) - { - fwrite(tData->data, 1, tData->size, m_pOutputFD[1]); - m_mFrameCounterProtector.lock(); - m_nSegBFrameCounter++; - m_mFrameCounterProtector.unlock(); - }; - } - #endif // ! EVE_SEQUENTAL_OUTPUT - // Don't free tData->data since is pointer on static data - free(tData->data); - #else // !DIRECT_MJPEG_COMPOSING - #ifdef OPENCV_VIDEO_OUTPUT - - cv::Mat image(tData->rows, tData->cols, CV_8UC3); - memcpy(image.data, tData->data, tData->size); - free(tData->data); - #ifdef EVE_SEQUENTAL_OUTPUT - if (m_bSegActive) - { - if (m_pEncoder->isOpened()) - { - m_pEncoder->write(image); - m_mFrameCounterProtector.lock(); - m_nSegFrameCounter++; - m_mFrameCounterProtector.unlock(); - }; - } - #else //!EVE_SEQUENTAL_OUTPUT - if (m_bSegAActive) - { - if (m_pEncoderA->isOpened()) - { - m_pEncoderA->write(image); - m_mFrameCounterProtector.lock(); - m_nSegAFrameCounter++; - m_mFrameCounterProtector.unlock(); - }; - } - if (m_bSegBActive) - { - if (m_pEncoderB->isOpened()) - { - m_pEncoderB->write(image); - m_mFrameCounterProtector.lock(); - m_nSegBFrameCounter++; - m_mFrameCounterProtector.unlock(); - }; - } - #endif // !EVE_SEQUENTAL_OUTPUT - #else //! OPENCV_VIDEO_OUTPUT - // av_frame_make_writable( m_pAVFrame ); - // m_qEncodingQueue.pop(); - // m_mEncodingQueueProtector.unlock(); - sws_scale(m_pConvertCtx, tData->data, tData->linesize, 0, tData->rows, m_pAVFrame->data, m_pAVFrame->linesize); - free(tData->data[0]); - /* - - - AV_PICTURE_TYPE_NONE Undefined. - AV_PICTURE_TYPE_I Intra. - AV_PICTURE_TYPE_P Predicted. - AV_PICTURE_TYPE_B Bi-dir predicted. - AV_PICTURE_TYPE_S S(GMC)-VOP MPEG4. - AV_PICTURE_TYPE_SI Switching Intra. - AV_PICTURE_TYPE_SP Switching Predicted. - AV_PICTURE_TYPE_BI BI type. - - - */ - if ((m_nGlobalFrameCounter % m_sStreamData.fps) == 0) - { - m_pAVFrame->key_frame = 1; - m_pAVFrame->pict_type = AVPictureType::AV_PICTURE_TYPE_I; - } - else - { - m_pAVFrame->key_frame = 0; - m_pAVFrame->pict_type = AVPictureType::AV_PICTURE_TYPE_NONE; - }; - m_pAVFrame->pts = m_nGlobalFrameCounter + 1; - #ifdef SEPARATED_VIDEO_ENCODERS - if (m_bSegAActive) - { - rVal = avcodec_send_frame(m_pCodecACtx, m_pAVFrame); - } - if (m_bSegBActive) - { - rVal = avcodec_send_frame(m_pCodecBCtx, m_pAVFrame); - } - #else //! SEPARATED_VIDEO_ENCODERS - rVal = avcodec_send_frame(m_pCodecCtx, m_pAVFrame); - #endif //! SEPARATED_VIDEO_ENCODERS - #endif //! OPENCV_VIDEO_OUTPUT - #endif //! DIRECT_MJPEG_COMPOSING - free(tData); - m_mFrameCounterProtector.lock(); - m_nGlobalFrameCounter++; - m_mFrameCounterProtector.unlock(); - } else { - m_mEncodingQueueProtector.unlock(); - }; - }; - #ifdef EVE_SEQUENTAL_OUTPUT - if ( m_bSegActive ) { - m_mFrameCounterProtector.lock(); - if ( m_nSegFrameCounter == m_nHardLimitFrames ) { - #ifdef DEBUG_EXTRA - LOG("Actual Closing Video Stream"); - LOG( m_sStreamSegmentInfo.scratchPath ); - #endif - m_bSegActive = false; - if( !m_bSegDelete ){ - #ifdef DIRECT_MJPEG_COMPOSING - if( m_pOutputFD ){ - fclose(m_pOutputFD); - m_pOutputFD = NULL; - }; - #else //! DIRECT_MJPEG_COMPOSING - #ifdef OPENCV_VIDEO_OUTPUT - if( m_pEncoder->isOpened() ){ - m_pEncoder->release(); - #ifdef DEBUG_EXTRA - } else { - LOG("Encoder is NOT Opened!"); - #endif - }; - #else //! OPENCV_VIDEO_OUTPUT - av_write_trailer( m_pFormatCtx ); - avio_close( m_pFormatCtx->pb ); - #endif //! OPENCV_VIDEO_OUTPUT - #endif //! DIRECT_MJPEG_COMPOSING - VIDEO_SEGMENT_INFO *tData = (VIDEO_SEGMENT_INFO*) malloc( sizeof(VIDEO_SEGMENT_INFO)); - if( tData ){ - memcpy( tData, &m_sStreamSegmentInfo, sizeof( VIDEO_SEGMENT_INFO )); - EVENT_CONTAINER * bEVT = createBasicEvent( m_sStreamData.source_id, EVT_CLASS_VIDEO, EVT_CAPTURE_DONE, NULL, NULL, tData ); - if( bEVT ){ - basicEventHeap::getInstance()->broadcast(bEVT); - } else { - LOG_ERROR("Event Creation failure!"); - free(tData); - }; - }; - #ifdef DEBUG_EXTRA - LOG("Stream is Saved"); - #endif - } else { - #ifdef DIRECT_MJPEG_COMPOSING - if( m_pOutputFD ){ - fclose(m_pOutputFD); - m_pOutputFD = NULL; - }; - #else // !DIRECT_MJPEG_COMPOSING - #ifdef OPENCV_VIDEO_OUTPUT - if (m_pEncoder->isOpened()){ - m_pEncoder->release(); - #ifdef DEBUG_EXTRA - } else { - LOG("Encoder is NOT Opened!"); - #endif - }; - #else // !OPENCV - #ifdef EVE_DONT_DELETE_SEGMENTS - av_write_trailer(m_pFormatCtx); - #endif - avio_close(m_pFormatCtx->pb); - #endif // !OPENCV_VIDEO_OUTPUT - #endif // !DIRECT_MJPEG_COMPOSING - #ifndef EVE_DONT_DELETE_SEGMENTS - unlink(m_sStreamSegmentInfo.scratchPath); - #endif - #ifdef DEBUG_EXTRA - LOG("Stream is Closed and Deleted!"); - #endif - }; - #ifndef DIRECT_MJPEG_COMPOSING - #ifndef OPENCV_VIDEO_OUTPUT - #ifdef SEPARATED_VIDEO_ENCODERS - #ifdef DEBUG_EXTRA - LOG("Del FCTX"); - #endif - avformat_free_context( m_pFormatCtx ); - m_pVideoStr = NULL; - #ifdef DEBUG_EXTRA - LOG("Del FCTX DONE"); - #endif - #endif // SEPARATED_VIDEO_ENCODERS - #endif // !OPENCV - #endif // !DIRECT_MJPEG_COMPOSING - }; - m_mFrameCounterProtector.unlock(); - //If we closed Stream then open new - if (!m_bSegActive ) { - CSTR tAM = getUniqID_MD5(); - if( tAM ){ - sprintf(m_sStreamSegmentInfo.scratchPath, "%s/%s.%s", m_pVideoScratchPath, tAM, VIDEO_OUTPUT_CONTAINER); - strncpy(m_sStreamSegmentInfo.recordMD5, tAM, 32); - m_sStreamSegmentInfo.recordMD5[32] = (char) 0; - free(tAM); - m_sStreamSegmentInfo.stream_id = m_sStreamData.id; - PF_TIMESTAMP ts; - getPFTS(&ts); - m_sStreamSegmentInfo.streamTSS = ts.seconds; - m_sStreamSegmentInfo.streamTMS = ts.milliseconds; - #ifdef DEBUG_EXTRA - char tB[128]; - sprintf(tB, "VideoStream opened %d.%d", m_sStreamSegmentInfo.streamTSS, m_sStreamSegmentInfo.streamTMS); - LOG(tB); - LOG( m_sStreamSegmentInfo.scratchPath ); - #endif - strncpy(m_sStreamSegmentInfo.recordEXT, VIDEO_OUTPUT_CONTAINER, 6); - m_sStreamSegmentInfo.streamFPS = m_sStreamData.fps; - m_sStreamSegmentInfo.streamWidth = m_pMaster->getWidh(); - m_sStreamSegmentInfo.streamHeight = m_pMaster->getHeight(); - m_sStreamSegmentInfo.eventIDS.clear(); - m_sStreamSegmentInfo.eventTSS.clear(); - m_sStreamSegmentInfo.eventTMS.clear(); - m_sStreamSegmentInfo.eventFrames.clear(); - m_sStreamSegmentInfo.dataSize = 0; - m_sStreamSegmentInfo.db_id = 0; - #ifdef DIRECT_MJPEG_COMPOSING - m_pOutputFD = fopen(m_sStreamSegmentInfo.scratchPath, "wb+"); - m_nSegFrameCounter = 0; - m_nSegShiftFrames = 0; - m_bSegActive = true; - m_bSegDelete = m_bNSegDelete; - m_bNSegDelete = true; - #else // !DIRECT_MJPEG_COMPOSING - #ifdef OPENCV_VIDEO_OUTPUT - if ( m_pEncoder ){ - //int fourcc = cv::VideoWriter::fourcc('H', '2', '6', '4'); - int fourcc =cv::VideoWriter::fourcc('a', 'v', 'c', '1'); - //int fourcc = cv::VideoWriter::fourcc('M', 'J', 'P', 'G'); - double fps = m_sStreamData.fps; - cv::String mn(m_sStreamSegmentInfo.scratchPath); - cv::Size fz(m_sStreamData.width, m_sStreamData.height); - // open (const String &filename, int fourcc, double fps, Size frameSize, bool isColor=true) - if (! m_pEncoder->open(mn, fourcc, fps, fz) ) { - LOG_ERROR("Cannot Open Output VideoStream!"); - m_bThreadStatus = TH_ENDED; - continue; - #ifdef DEBUG_EXTRA - } else { - char tB[256]; - sprintf(tB, "VideoStream is Created [%s] %.2f fps", m_sStreamSegmentInfo.scratchPath, fps); - LOG(tB); - #endif - }; - m_bSegActive = true; - m_bSegDelete = m_bNSegDelete; - m_bNSegDelete = true; - m_nSegFrameCounter = 0; - m_nSegShiftFrames = 0; - } else { - LOG_ERROR("No Encoder Object!"); - m_bThreadStatus = TH_ENDED; - continue; - }; - #else // !OPENCV_VIDEO_OUTPUT - // Check if Encoder is Ready - if (m_pFormat == NULL){ - m_bThreadStatus = TH_ENDED; - continue; - } - - #ifdef SEPARATED_VIDEO_ENCODERS - if (avformat_alloc_output_context2(&m_pFormatCtx, m_pFormat, NULL, "test." VIDEO_OUTPUT_CONTAINER) < 0){ - LOG_ERROR("Format CTX alloc error!"); - m_bThreadStatus = TH_ENDED; - continue; - } else { - av_dict_set(&m_pFormatCtx->metadata, "Author", "Argus Sec. System", 0); - m_pFormatCtx->flags |= AVFMT_NOTIMESTAMPS | AVFMT_TS_NONSTRICT; - }; - - m_pVideoStr = avformat_new_stream(m_pFormatCtx, m_pVideoACodec); - if (m_pVideoStr == NULL){ - avformat_free_context(m_pFormatCtx); - m_bThreadStatus = TH_ENDED; - continue; - #ifdef DEBUG_EXTRA - } else { - LOG("VideoStream is Created"); - #endif - }; - const AVRational dst_fps = {m_sStreamData.fps, 1}; - m_pVideoStr->r_frame_rate = m_pVideoStrA->avg_frame_rate = dst_fps; - m_pVideoStr->time_base = m_pCodecCtx->time_base; - avcodec_parameters_from_context(m_pVideoStr->codecpar, m_pCodecACtx); - #ifdef DEBUG_EXTRA - LOG("Opening Stream"); - LOG(m_cSegName); - char tB[128]; - sprintf(tB, "FFPTS:%llu FNUM:%llu S2KF:%llu", m_pVideoStr->start_time, m_pVideoStr->nb_frames, m_pVideoStr->first_dts); - LOG(tB); - sprintf(tB, "CON ST:%llu DUR:%llu", m_pFormatCtx->start_time, m_pFormatCtx->duration); - LOG(tB); - #endif - // if (avio_open(&m_pFormatCtx->pb, m_cSegNameA, AVIO_FLAG_WRITE) < 0) { - if (avio_open(&m_pFormatCtx->pb, m_sStreamSegmentInfo.scratchPath, AVIO_FLAG_WRITE) < 0) - { - LOG_ERROR("Could not open output file."); - m_bThreadStatus = TH_ENDED; - continue; - }; - if (avformat_write_header(m_pFormatCtx, &m_pFormatOpts) < 0) - { - LOG_ERROR("Error occurred when writing header to output file."); - m_bThreadStatus = TH_ENDED; - continue; - }; - // m_mFrameCounterProtector.lock(); - m_nSegFrameCounter = 0; - m_nSegShiftFrames = 0; - m_bSegActive = true; - m_bSegDelete = m_bNSegDelete; - m_bNSegDelete = true; - // m_mFrameCounterProtector.unlock(); - #else // SEPARATED_VIDEO_ENCODERS - m_nSegSkippedFrames = m_pVideoStr->nb_frames + 1; - if (m_pVideoStr->nb_frames) - { - m_pVideoStr->nb_frames = 0; - m_pVideoStr->start_time = 0; - m_pVideoStr->first_dts = 0; - m_pFormatCtx->start_time = 0; - }; - #ifdef DEBUG_EXTRA - LOG("Opening Stream"); - LOG(m_cSegName); - char tB[128]; - sprintf(tB, "FFPTS:%llu FNUM:%llu S2KF:%llu", m_pVideoStr->start_time, m_pVideoStr->nb_frames, m_pVideoStr->first_dts); - LOG(tB); - sprintf(tB, "CON ST:%llu DUR:%llu", m_pFormatCtx->start_time, m_pFormatCtx->duration); - LOG(tB); - #endif - if (avio_open(&m_pFormatCtx->pb, m_cSegName, AVIO_FLAG_WRITE) < 0) - { - LOG_ERROR("Could not open output file."); - m_bThreadStatus = TH_ENDED; - continue; - }; - if (avformat_write_header(m_pFormatCtx, &m_pFormatOpts) < 0) - { - LOG_ERROR("Error occurred when writing header to output file."); - m_bThreadStatus = TH_ENDED; - continue; - }; - // m_mFrameCounterProtector.lock(); - m_nSegFrameCounter = 0; - m_nSegShiftFrames = 0; - m_bSegActive = true; - m_bSegDelete = m_bNSegDelete; - m_bNSegDelete = true; - // m_mFrameCounterProtector.unlock(); - #endif // SEPARATED_VIDEO_ENCODERS - #ifdef DEBUG_EXTRA - LOG("Stream Opened"); - #endif - #endif // !OPENCV_VIDEO_OUTPUT - #endif // !DIRECT_MJPEG_COMPOSING - }; - }; - }; - #else //! EVE_SEQUENTAL_OUTPUT - // Test Commands! - m_mCurrentOperationProtector.lock(); - switch (m_bCOP){ - case 0x01:{ - #ifdef DEBUG_EXTRA - LOG("Actual Closing Video Stream A!"); - LOG(m_sStreamSegmentInfo[0].scratchPath); - #endif - m_bSegAActive = false; - if (! m_bSegADelete) - { - #ifdef DIRECT_MJPEG_COMPOSING - if (m_pOutputFD[0]) - { - fclose(m_pOutputFD[0]); - m_pOutputFD[0] = NULL; - }; - #else //! DIRECT_MJPEG_COMPOSING - #ifdef OPENCV_VIDEO_OUTPUT - if (m_pEncoderA->isOpened()) - { - m_pEncoderA->release(); - #ifdef DEBUG_EXTRA - } - else - { - LOG(" Encoder A is NOT Opened!"); - #endif - }; - #else //! OPENCV_VIDEO_OUTPUT - av_write_trailer(m_pFormatCtxA); - avio_close(m_pFormatCtxA->pb); - #endif //! OPENCV_VIDEO_OUTPUT - #endif //! DIRECT_MJPEG_COMPOSING - EVENT_CONTAINER * bEVT = createBasicEvent(m_sStreamData.source_id, EVT_CLASS_VIDEO, EVT_CAPTURE_DONE, NULL, NULL, &m_sStreamSegmentInfo[0]); - if (bEVT) - { - basicEventHeap::getInstance()->broadcast(bEVT); - } - else - { - LOG_ERROR("Event Creation failure!"); - } - #ifdef DEBUG_EXTRA - LOG("Stream A is Saved"); - #endif - } - else - { - #ifdef DIRECT_MJPEG_COMPOSING - if (m_pOutputFD[0]) - { - fclose(m_pOutputFD[0]); - m_pOutputFD[0] = NULL; - }; - #else // !DIRECT_MJPEG_COMPOSING - #ifdef OPENCV_VIDEO_OUTPUT - if (m_pEncoderA->isOpened()) - { - m_pEncoderA->release(); - #ifdef DEBUG_EXTRA - } - else - { - LOG(" Encoder A is NOT Opened!"); - #endif - }; - #else // !OPENCV - #ifdef EVE_DONT_DELETE_SEGMENTS - av_write_trailer(m_pFormatCtxA); - #endif - avio_close(m_pFormatCtxA->pb); - #endif // !OPENCV_VIDEO_OUTPUT - #endif // !DIRECT_MJPEG_COMPOSING - #ifndef EVE_DONT_DELETE_SEGMENTS - unlink(m_sStreamSegmentInfo[0].scratchPath); - #endif - #ifdef DEBUG_EXTRA - LOG("Stream A is Closed!"); - #endif - }; - #ifndef DIRECT_MJPEG_COMPOSING - #ifndef OPENCV_VIDEO_OUTPUT - #ifdef SEPARATED_VIDEO_ENCODERS - #ifdef DEBUG_EXTRA - LOG("Del FCTX"); - #endif - avformat_free_context(m_pFormatCtxA); - m_pVideoStrA = NULL; - #ifdef DEBUG_EXTRA - LOG("Del FCTX DONE"); - #endif - #endif // SEPARATED_VIDEO_ENCODERS - #endif // !OPENCV - #endif // !DIRECT_MJPEG_COMPOSING - break; - }; - case 0x02:{ - #ifdef DEBUG_EXTRA - LOG("Actual Closing Video Stream B!"); - LOG(m_sStreamSegmentInfo[1].scratchPath); - #endif - m_bSegBActive = false; - if (! m_bSegBDelete) - { - #ifdef DIRECT_MJPEG_COMPOSING - if (m_pOutputFD[1]) - { - fclose(m_pOutputFD[1]); - m_pOutputFD[1] = NULL; - }; - #else // !DIRECT_MJPEG_COMPOSING - #ifdef OPENCV_VIDEO_OUTPUT - if (m_pEncoderB->isOpened()) - { - m_pEncoderB->release(); - #ifdef DEBUG_EXTRA - } - else - { - LOG(" Encoder B is NOT Opened!"); - #endif - }; - #else // !OpenCV - av_write_trailer(m_pFormatCtxB); - avio_close(m_pFormatCtxB->pb); - #endif // !OPENCV_VIDEO_OUTPUT - #endif // !DIRECT_MJPEG_COMPOSING - EVENT_CONTAINER * bEVT = createBasicEvent(m_sStreamData.source_id, EVT_CLASS_VIDEO, EVT_CAPTURE_DONE, NULL, NULL, &m_sStreamSegmentInfo[1]); - if (bEVT) - { - basicEventHeap::getInstance()->broadcast(bEVT); - } - else - { - LOG_ERROR("Event Creation failure!"); - } - #ifdef DEBUG_EXTRA - LOG("Stream B is Saved"); - - #endif - } - else - { - #ifdef DIRECT_MJPEG_COMPOSING - if (m_pOutputFD[1]) - { - fclose(m_pOutputFD[1]); - m_pOutputFD[1] = NULL; - }; - #else - #ifdef OPENCV_VIDEO_OUTPUT - if (m_pEncoderB->isOpened()) - { - m_pEncoderB->release(); - #ifdef DEBUG_EXTRA - } - else - { - LOG(" Encoder B is NOT Opened!"); - #endif - }; - #else // !OPenCV - #ifdef EVE_DONT_DELETE_SEGMENTS - av_write_trailer(m_pFormatCtxB); - #endif - avio_close(m_pFormatCtxB->pb); - #endif // !OPENCV_VIDEO_OUTPUT - #endif // !DIRECT_MJPEG_COMPOSING - #ifndef EVE_DONT_DELETE_SEGMENTS - unlink(m_sStreamSegmentInfo[1].scratchPath); - #endif - #ifdef DEBUG_EXTRA - LOG("Stream B is Closed!"); - #endif - }; - #ifndef DIRECT_MJPEG_COMPOSING - #ifndef OPENCV_VIDEO_OUTPUT - #ifdef SEPARATED_VIDEO_ENCODERS - avformat_free_context(m_pFormatCtxB); - m_pVideoStrB = NULL; - #endif // SEPARATED_VIDEO_ENCODERS - #endif // !OPENCV - #endif // !DIRECT_MJPEG_COMPOSING - break; - }; - }; - m_bCOP = 0; - m_mCurrentOperationProtector.unlock(); - #endif // !EVE_SEQUENTAL_OUTPUT - -#ifndef DIRECT_MJPEG_COMPOSING - #ifndef OPENCV_VIDEO_OUTPUT - #ifdef SEPARATED_VIDEO_ENCODERS - do - { - mPacket.data = NULL; - mPacket.size = 0; - rVal = avcodec_receive_packet(m_pCodecACtx, &mPacket); - if (rVal == AVERROR(EAGAIN) || rVal == AVERROR_EOF) - { - break; - } - else if (rVal < 0) - { - LOG_ERROR("Error during encoding "); - m_bThreadStatus = TH_ENDED; - break; - }; - if (! rVal) - { - if (m_bSegAActive) - { - mPacket.stream_index = m_pVideoStrA->index; - mPacket.duration = 1; - m_mFrameCounterProtector.lock(); - m_nSegAFrameCounter++; - m_mFrameCounterProtector.unlock(); - mPacket.pts = av_rescale_q(m_nSegAFrameCounter, m_pCodecACtx->time_base, m_pVideoStrA->time_base); - // mPacket.pts = AV_NOPTS_VALUE; - // mPacket.pts = av_rescale_q( m_nSegASkippedFrames + m_nSegAFrameCounter, m_pCodecCtx->time_base, m_pVideoStrA->time_base ); - mPacket.dts = mPacket.pts; - int rc = av_write_frame(m_pFormatCtxA, &mPacket); - if (rc < 0) - { - // if( av_interleaved_write_frame( m_pFormatCtxA, &mPacket) < 0 ) { - m_bThreadStatus = TH_ENDED; - LOG_ERROR("Trouble with Video Output A!"); - av_strerror(rc, tB, 128); - LOG_ERROR(tB); - break; // continue (changed since embed into do-while) - }; - }; - if (m_bSegBActive) - { - mPacket.stream_index = m_pVideoStrB->index; - mPacket.duration = 1; - m_mFrameCounterProtector.lock(); - m_nSegBFrameCounter++; - m_mFrameCounterProtector.unlock(); - mPacket.pts = av_rescale_q(m_nSegBFrameCounter, m_pCodecBCtx->time_base, m_pVideoStrB->time_base); - // mPacket.pts = AV_NOPTS_VALUE; - // mPacket.pts = av_rescale_q( m_nSegBSkippedFrames + m_nSegBFrameCounter, m_pCodecCtx->time_base, m_pVideoStrB->time_base ); - mPacket.dts = mPacket.pts; - int rc = av_write_frame(m_pFormatCtxB, &mPacket); - if (rc < 0) - { - // if( av_interleaved_write_frame( m_pFormatCtxB, &mPacket) < 0 ) { - m_bThreadStatus = TH_ENDED; - LOG_ERROR("Trouble with Video Output B!"); - av_strerror(rc, tB, 128); - LOG_ERROR(tB); - break; // continue (changed since embed into do-while) - }; - }; - av_packet_unref(&mPacket); - }; - } - while (rVal >= 0 && m_bThreadStatus != TH_ENDED); - #else // !SEPARATED_VIDEO_ENCODERS - do - { - mPacket.data = NULL; - mPacket.size = 0; - rVal = avcodec_receive_packet(m_pCodecCtx, &mPacket); - if (rVal == AVERROR(EAGAIN) || rVal == AVERROR_EOF) - { - break; - } - else if (rVal < 0) - { - LOG_ERROR("Error during encoding "); - m_bThreadStatus = TH_ENDED; - break; - }; - if (! rVal) - { - if (m_bSegAActive) - { - mPacket.stream_index = m_pVideoStrA->index; - mPacket.duration = 1; - mPacket.pts = av_rescale_q(m_nGlobalFrameCounter, m_pCodecCtx->time_base, m_pVideoStrA->time_base); - // mPacket.pts = AV_NOPTS_VALUE; - // mPacket.pts = av_rescale_q( m_nSegASkippedFrames + m_nSegAFrameCounter, m_pCodecCtx->time_base, m_pVideoStrA->time_base ); - mPacket.dts = mPacket.pts; - int rc = av_write_frame(m_pFormatCtxA, &mPacket); - if (rc < 0) - { - // if( av_interleaved_write_frame( m_pFormatCtxA, &mPacket) < 0 ) { - m_bThreadStatus = TH_ENDED; - LOG_ERROR("Trouble with Video Output A!"); - av_strerror(rc, tB, 128); - LOG_ERROR(tB); - break; // continue (changed since embed into do-while) - }; - }; - if (m_bSegBActive) - { - mPacket.stream_index = m_pVideoStrB->index; - mPacket.duration = 1; - mPacket.pts = av_rescale_q(m_nGlobalFrameCounter, m_pCodecCtx->time_base, m_pVideoStrA->time_base); - // mPacket.pts = AV_NOPTS_VALUE; - // mPacket.pts = av_rescale_q( m_nSegBSkippedFrames + m_nSegBFrameCounter, m_pCodecCtx->time_base, m_pVideoStrB->time_base ); - mPacket.dts = mPacket.pts; - int rc = av_write_frame(m_pFormatCtxB, &mPacket); - if (rc < 0) - { - // if( av_interleaved_write_frame( m_pFormatCtxB, &mPacket) < 0 ) { - m_bThreadStatus = TH_ENDED; - LOG_ERROR("Trouble with Video Output B!"); - av_strerror(rc, tB, 128); - LOG_ERROR(tB); - break; // continue (changed since embed into do-while) - }; - }; - av_packet_unref(&mPacket); - }; - } - while (rVal >= 0 && m_bThreadStatus != TH_ENDED); - #endif // ! SEPARATED_VIDEO_ENCODERS - #endif // !OPENCV_VIDEO_OUTPUT -#endif // !DIRECT_MJPEG_COMPOSING - SLEEP(10); - }; -#ifdef DEBUG_EXTRA - LOG("Encoder Loop Ended!"); -#endif - } - - #ifndef EVE_SEQUENTAL_OUTPUT - void streamHandler::swapActiveStreams(void) - { - if (m_bSegDelete) - { - closeSegment(); - } - // m_mFrameCounterProtector.lock(); - m_bActiveEncoderStream = 1 - m_bActiveEncoderStream; - if (m_bActiveEncoderStream) - { - if (m_bSegADelete) - { - closeSegmentA(); - } - } - else - { - if (m_bSegBDelete) - { - closeSegmentB(); - } - }; - // m_mFrameCounterProtector.unlock(); - } - #endif // !EVE_SEQUENTAL_OUTPUT -#endif // EVE_ENABLE_VIDEO - -bool streamHandler::triggerEvent(uint32_t eid, uint32_t & dbid, uint32_t & frame) -{ - -#ifdef DEBUG_EXTRA - LOG("Trig Evt"); -#endif - -#ifdef EVE_ENABLE_VIDEO - m_mFrameCounterProtector.lock(); - // To Mark Events on the Frames - m_bEvtMarkerCounter = 255; - PF_TIMESTAMP ts; - getPFTS(&ts); - if ( dbid ) dbid = dbid; - #ifdef EVE_SEQUENTAL_OUTPUT - m_bSegDelete = false; - // Keep Also Next Segment if close to a end - if ( ( m_nSegmentLimitFrames - m_nSegFrameCounter ) < m_nPostAlarmFrames ) m_bNSegDelete = false; - m_nSegShiftFrames = frame = m_nSegFrameCounter; - m_sStreamSegmentInfo.eventIDS.push_back(eid); - m_sStreamSegmentInfo.eventTSS.push_back(ts.seconds); - m_sStreamSegmentInfo.eventTMS.push_back(ts.milliseconds); - m_sStreamSegmentInfo.eventFrames.push_back(frame); - // dbid = m_sStreamSegmentInfo.db_id;// = m_nVideoRegisteredDBID; - #else // !EVE_SEQUENTAL_OUTPUT - if (!m_bActiveEncoderStream) - { // Stream A is Active - m_bSegADelete = false; - m_nSegAShiftFrames = frame = m_nSegAFrameCounter; - } - else - { // Stream B is Active - m_bSegBDelete = false; - m_nSegBShiftFrames = frame = m_nSegBFrameCounter; - }; - m_sStreamSegmentInfo[m_bActiveEncoderStream].eventIDS.push_back(eid); - m_sStreamSegmentInfo[m_bActiveEncoderStream].eventTSS.push_back(ts.seconds); - m_sStreamSegmentInfo[m_bActiveEncoderStream].eventTMS.push_back(ts.milliseconds); - m_sStreamSegmentInfo[m_bActiveEncoderStream].eventFrames.push_back(frame); - // dbid = m_sStreamSegmentInfo[m_bActiveEncoderStream].db_id;// = m_nVideoRegisteredDBID; - #endif // !EVE_SEQUENTAL_OUTPUT - m_mFrameCounterProtector.unlock(); - // if ( dbid == 0 ) return false; - #ifdef DEBUG_EXTRA - LOG("Event Registered!"); - #endif -#endif // EVE_ENABLE_VIDEO - return true; -} - -bool streamHandler::triggerCamMove(void) -{ -#ifdef DEBUG_EXTRA - LOG("Trig Cammove"); -#endif - m_bCamMoveCounter = 255; - return true; -} - -bool streamHandler::validate(void) -{ - if (m_pSource) - { - if (m_pSource->getStatus() < MS_CLOSING) - { -#ifdef EVE_ENABLE_VIDEO - if (m_nGlobalFrameCounter) - { // Frames Received from a source - if (m_nGlobalFrameCounter == m_nValidatorFrameCounter) - { - // No new frame since the last validation: restart only when it lasts (STREAM_STALL_CHECKS) - char tB[128]; - long tSec = (long) (time(NULL) - m_tLastFrameProgress); - if (++m_nStallChecks < STREAM_STALL_CHECKS) - { - snprintf(tB, sizeof(tB), "Video: no new frame for %ld s (%u/%u)", tSec, (unsigned) m_nStallChecks, (unsigned) STREAM_STALL_CHECKS); - LOG(tB); - } - else - { - snprintf(tB, sizeof(tB), "Video Stalled (no frame for %ld s) - restarting the stream", tSec); - LOG_ERROR(tB); - return false; // Try use System to recuperate - }; - } - else - { - if (m_nStallChecks) - { - char tB[96]; - snprintf(tB, sizeof(tB), "Video: frames again after %ld s", (long) (time(NULL) - m_tLastFrameProgress)); - LOG(tB); - }; - m_nStallChecks = 0; - m_tLastFrameProgress = time(NULL); - m_nValidatorFrameCounter = m_nGlobalFrameCounter; - } - }; - if (m_bThreadStatus < TH_ENDED) - { - return true; - } - else - { - LOG_ERROR("Thread Ended!"); - } -#endif - } - else - { - LOG_ERROR("Video Ended"); - } - }; - return false; -} - - -#undef LOG -#undef LOG_ERROR - -#endif // !LRF_PROXY_ONLY - -//#undef DEBUG_EXTRA - +#include "streamHandler.h" + +//#define DEBUG_EXTRA + +#ifndef LRF_PROXY_ONLY +// #include "rgooseHardwareResourceNetworkProvider.h" +// #include "mojoKernel.h" +#include "../alg/generic/base64.h" +#include "../data/media/video/videoAVLIBSource.h" +#include "../data/media/video/videoLive555AVLibSource.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* MIN() */ +#include +#include +#include + +// #define DEBUG +// #undef DEBUG_EXTRA + + +#ifndef STORAGE_DIR_MODE + #define STORAGE_DIR_MODE 0x1FF +#endif + +#ifndef STORAGE_FILE_MODE + #define STORAGE_FILE_MODE 0x1B6 +#endif + +#define LOG(X) m_pLog->Log("MEV_STR", this, X) +#ifdef DEBUG + #define LOG_ERROR(X) \ + { \ + char _tBfrErrMSG2w34[256]; \ + sprintf(_tBfrErrMSG2w34, "In file %s[%d] in func:%s %s", __FILE__, __LINE__, __func__, X); \ + m_pLog->Log("MEV_STR", this, _LOG_ERROR, _tBfrErrMSG2w34); \ + } +#else + #define LOG_ERROR(X) m_pLog->Log("MEV_STR", this, _LOG_ERROR, X); +#endif + +streamHandler::streamHandler(kernelModuleEmbedVideo * ptr, MS_WORK_MODE M, uint8_t flip_mode) : + basicMediaDestination() +#ifdef EVE_ENABLE_VIDEO + , basicThread() +#endif +{ + m_pMaster = ptr; + m_eWM = M; + m_pLog = basicLogCollection::getInstance(); + + LOG("Constructor Begin!"); + + memset(&m_sStreamData, 0, sizeof(DBC_MEDIA_STREAM_DATA)); + m_pSource = NULL; + m_nValidatorFrameCounter = 0; + m_nStallChecks = 0; + m_tLastFrameProgress = time(NULL); + m_bEvtMarkerCounter = 0; + m_bCamMoveCounter = 0; + m_bFlipMode = flip_mode; + m_bLiveMode = EVE_LIVE_OFF; + +#ifdef EVE_ENABLE_VIDEO + #ifdef EVE_SEQUENTAL_OUTPUT + m_nSegFrameCounter = 0; + m_nGlobalFrameCounter = 0; + m_nSegShiftFrames = 0; + m_nSegSkippedFrames = 0; + m_bSegActive = false; + m_bSegDelete = true; + m_bNSegDelete = true; + #else + m_nPreAlarmFrames = 0; + m_nPostAlarmFrames = 0; + m_nSegmentLimitFrames = 0; + m_nHardLimitFrames = 0; + m_nSegAFrameCounter = 0; + m_nSegBFrameCounter = 0; + m_nGlobalFrameCounter = 0; + + m_nSegAShiftFrames = 0; + m_nSegBShiftFrames = 0; + m_nSegASkippedFrames = m_nSegBSkippedFrames = 0; + + m_bActiveEncoderStream = 0; + m_bSegAActive = false; + m_bSegADelete = true; + m_bSegBActive = false; + m_bSegBDelete = true; + #endif // !EVE_SEQUENTAL_OUTPUT + + m_bCOP = 0; + m_cSourceType = 'A'; + + //todo: must be writen helper function to clean VIDEO_SEGMENT_INFO + //that is not dynamicaly created by NEW operator + + //memset(&m_sStreamSegmentInfo[0], 0, sizeof(VIDEO_SEGMENT_INFO)); + //memset(&m_sStreamSegmentInfo[1], 0, sizeof(VIDEO_SEGMENT_INFO)); + #ifdef DIRECT_MJPEG_COMPOSING + #ifndef EVE_SEQUENTAL_OUTPUT + m_pOutputFD[0] = NULL; + m_pOutputFD[1] = NULL; + #else + m_pOutputFD = NULL; + #endif + #else // !DIRECT_MJPEG_COMPOSING + #ifdef OPENCV_VIDEO_OUTPUT + #ifndef EVE_SEQUENTAL_OUTPUT + m_pEncoderA = NULL; + m_pEncoderB = NULL; + #else + m_pEncoder = NULL; + #endif + #endif + #endif +#endif // EVE_ENABLE_VIDEO + // if( M == MS_MODE_DECODE_FRAMES ) 1=1; +#ifdef DEBUG_EXTRA + LOG("Constructor Done!"); +#endif +} + +streamHandler::~streamHandler() +{ + if (m_sStreamData.id) + { + if (m_pSource != NULL) + { + switch (m_cSourceType) + { // m_sStreamData.source_type[0] ) { + case 'D': delete((videoLIVE555Source *) m_pSource); break; + case 'A': delete((videoAVLIBSource *) m_pSource); break; + }; + }; + stopLive(); // the source no longer pushes: the path is set not ready (viewers are closed) +#ifdef EVE_ENABLE_VIDEO + closeAll(); +#endif // EVE_ENABLE_VIDEO + }; +#ifdef EVE_ENABLE_VIDEO + // Encoder thread is stopped at this point - release frames still waiting in the queue + waitThreadEnd(true); + m_mEncodingQueueProtector.lock(); + while (! m_qEncodingQueue.empty()) + { + ENCODING_BUFFER * tData = m_qEncodingQueue.front(); + m_qEncodingQueue.pop(); + if (tData) + { + #if defined(DIRECT_MJPEG_COMPOSING) || defined(OPENCV_VIDEO_OUTPUT) + if (tData->data) + { + free(tData->data); + } + #else + if (tData->data[0]) + { + free(tData->data[0]); + } + #endif + free(tData); + }; + }; + m_mEncodingQueueProtector.unlock(); +#endif // EVE_ENABLE_VIDEO +} + +bool streamHandler::create(dataBinder * ptr, uint32_t stremID) +{ + if (ptr == NULL) + { + return false; + } + m_pDBC = ptr; + if (stremID) + { + DBC_MEDIA_STREAM_DATA * tData = m_pDBC->getMediaStreamData(stremID); + if (tData) + { +#ifdef DEBUG_EXTRA + LOG("Have Stream Info"); +#endif + memcpy(&m_sStreamData, tData, sizeof(DBC_MEDIA_STREAM_DATA)); + free(tData); + DBC_CAM_DATA * tCAM = m_pDBC->getCamData(m_sStreamData.source_id); + if (tCAM) + { +#ifdef DEBUG_EXTRA + LOG("Have Cam Info"); +#endif + m_sSourceDesc.mediaStreamId = stremID; + + m_sSourceDesc.mediaSourceId = m_sStreamData.source_id; + uint32_t tNID = m_pDBC->getNodeIdByTypeAndAux(tCAM->type, m_sStreamData.source_id); + // ToDo: Check Camera Addition + // Just Work around to handle Wrong tyoe 12 instead of 13 + if (tNID == 0) + { + tNID = m_pDBC->getNodeIdByTypeAndAux(13, m_sStreamData.source_id); + }; + if (tNID) + { + CSTR tNAM = m_pDBC->getNodeName(tNID); + if (tNAM != NULL) + { + strncpy(m_sSourceDesc.mediaName, tNAM, 127); + m_sSourceDesc.mediaName[127] = (char) 0; + free(tNAM); + } + else + { + sprintf(m_sSourceDesc.mediaName, "No Name Cam"); + }; + } + else + { + sprintf(m_sSourceDesc.mediaName, "No-Name-Cam"); + }; + + initLive(tNID); + + m_cSourceType = m_sStreamData.source_type[0]; + + switch (m_cSourceType) + { + case 'A': m_pSource = (basicMediaSource *) new videoAVLIBSource(&m_sSourceDesc); break; + case 'D': + { + + // Check Auth mode if basic - Override and use AVLIB + // To Debug LIVE555 ONLY + if( tCAM->auth_mode == 0){ + m_cSourceType = 'A'; + m_pSource = (basicMediaSource *) new videoAVLIBSource(&m_sSourceDesc); + break; + } else{ + + m_pSource = (basicMediaSource *) new videoLIVE555Source(&m_sSourceDesc); + break; + }; + //m_pSource = (basicMediaSource *) new videoLIVE555Source(&m_sSourceDesc); + //m_cSourceType = 'A'; // To use corect Destructor! + //m_pSource = (basicMediaSource *) new videoAVLIBSource(&m_sSourceDesc); + break; + }; + }; + if (m_pSource != NULL) + { + char tMRL[1024]; +#ifdef DEBUG_EXTRA + LOG("Source OK"); +#endif + int tW = m_pMaster->getWidh(); + int tH = m_pMaster->getHeight(); + int pix = -1; + bool in_16_9 = (((m_sStreamData.width * 100) / m_sStreamData.height) > 140); + bool out_16_9 = (((tW * 100) / tH) > 140); + // if( tW > 0 ){ + // //m_pSource->setProportionalByWidth( tW ); + // m_pSource->setSize( tW, tH ); + // }; + if (in_16_9 != out_16_9) + { + if (in_16_9) + { + tH = (((tW * 1000) / 16) * 9) / 1000; + } + else + { + tW = (((tH * 1000) / 3) * 4) / 1000; + }; + }; + // export PATH=/usr/sbin:$PATH + if (strncmp(m_sStreamData.mrl_proto, "v4l2", 4) == 0) + { + sprintf(tMRL, m_sStreamData.mrl); + pix = atoi(m_sStreamData.c_type); + } + else + { + sprintf(tMRL, "%s://%s:%s@%s:%d%s", m_sStreamData.mrl_proto, tCAM->username, tCAM->password, tCAM->ip, m_sStreamData.mrl_port, m_sStreamData.mrl); + }; +#ifdef DEBUG_EXTRA + LOG( tMRL ); +#endif + if (m_pSource->_open(tMRL, false, -1.0f, pix, m_sStreamData.width, m_sStreamData.height, tW, tH)){ + if (! m_pSource->attachDestination(this)){ + switch (m_cSourceType){ + case 'D': delete((videoLIVE555Source *) m_pSource); break; + case 'A': delete((videoAVLIBSource *) m_pSource); break; + }; + m_pSource = NULL; + } else { +#ifdef DEBUG_EXTRA + LOG("Source is Connected to Output."); +#endif + }; + } else { + LOG_ERROR("Can not Open Video Source!"); + switch (m_cSourceType) { + case 'D': delete((videoLIVE555Source *) m_pSource); break; + case 'A': delete((videoAVLIBSource *) m_pSource); break; + }; + m_pSource = NULL; + }; + } else { + LOG_ERROR("Video Source Stream Failure!"); + }; + free(tCAM); + } else { + LOG_ERROR("Error Getting CAM Data!"); + m_pSource = NULL; + return false; + }; + }; + }; + + if ( m_pSource ){ +#ifdef EVE_ENABLE_VIDEO + return initVideoOutput(); +#else + return true; +#endif // EVE_ENABLE_VIDEO + }; + + return false; +} + +/* ---------------------------------------------------------------- live view / recording */ + +void streamHandler::initLive(uint32_t nodeID) +{ + m_bLiveMode = m_pMaster->getLiveMode(); + m_pLivePath = m_pMaster->livePath(nodeID); + if (! m_pLivePath) + { + m_bLiveMode = EVE_LIVE_OFF; + return; + }; + char tB[160]; + if (m_bLiveMode == EVE_LIVE_ENCODE) + { + m_pLiveEncoder.reset(new streamLiveEncoder(m_pLivePath, m_pMaster->getLiveFps(), m_pMaster->getLiveBitrate())); + snprintf(tB, sizeof(tB), "Live view: path %s, processed frames (encoded)", m_pLivePath->name().c_str()); + } + else + { + m_oLiveFeeder.setParent(m_pLivePath.get()); + snprintf(tB, sizeof(tB), "Live view: path %s, camera H264", m_pLivePath->name().c_str()); + }; + LOG(tB); +} + +void streamHandler::stopLive(void) +{ + m_pLiveEncoder.reset(); // its feeder sets the path not ready + m_oLiveFeeder.setParent(nullptr); // passthrough: the same + m_pLivePath.reset(); + m_bLiveMode = EVE_LIVE_OFF; +} + +void streamHandler::pushEncodedParams(const uint8_t * data, size_t size, bool extradata, void * src) +{ + if (src) src = NULL; + if (m_bLiveMode != EVE_LIVE_PASSTHROUGH || data == NULL || size == 0) + { + return; + }; + if (extradata) + { + m_oLiveFeeder.setExtradata(data, size); + } + else + { + m_oLiveFeeder.setParameterSets(std::vector(1, mtx::Bytes(data, data + size))); + }; +} + +void streamHandler::pushEncodedNalu(const uint8_t * data, size_t size, int64_t ptUs, bool marker, bool synced, void * src) +{ + if (src) src = NULL; + if (m_bLiveMode == EVE_LIVE_PASSTHROUGH) + { + m_oLiveFeeder.pushNalu(data, size, ptUs, marker, synced); + }; +} + +void streamHandler::pushEncodedPacket(const uint8_t * data, size_t size, int64_t ptsUs, void * src) +{ + if (src) src = NULL; + if (m_bLiveMode != EVE_LIVE_PASSTHROUGH) + { + return; + }; + if (m_oLiveFeeder.avccLengthSize() > 0) + { + m_oLiveFeeder.pushAvcc(data, size, m_oLiveFeeder.avccLengthSize(), ptsUs); + } + else + { + m_oLiveFeeder.pushAnnexB(data, size, ptsUs); + }; +} + +void streamHandler::encodedSourceStopped(void * src) +{ + if (src) src = NULL; + m_oLiveFeeder.reset(); +} + +bool streamHandler::pushFrame(AVFrame * Frame, void * src) +{ + if( !Frame ) return false; + if( !m_pMaster )return false; + + MEDIA_SOURCE_DESC * tMD = (MEDIA_SOURCE_DESC *) src; + if (tMD) + { + }; + return true; +} + +bool streamHandler::pushFrame(cv::Mat & Frame, void * src) +{ + + /// @todo Valgrind is reporting an important memory leak in this method. + if (m_pMaster == NULL) + { + return false; + } + MEDIA_SOURCE_DESC * tMD = (MEDIA_SOURCE_DESC *) src; + char tBuffer[512]; + if (tMD) + { + float mK, oK; + cv::Rect ROI; + + m_pMaster->m_mPictureProtector.lock(); + + if (m_pMaster->m_mapMATS[tMD->mediaStreamId].cols == 0) + { + LOG("First Frame Enqueued"); + sprintf(tBuffer, "INP: [%dx%d] SrcID:%d StreamID:%d", Frame.cols, Frame.rows, tMD->mediaSourceId, tMD->mediaStreamId); + LOG(tBuffer); + + m_pMaster->m_mapMATS[tMD->mediaStreamId].create(m_pMaster->m_sEmbedVideoData.height, m_pMaster->m_sEmbedVideoData.width, CV_8UC3); + cv::rectangle(m_pMaster->m_mapMATS[tMD->mediaStreamId], cv::Point(0, 0), cv::Point(m_pMaster->m_sEmbedVideoData.height, m_pMaster->m_sEmbedVideoData.width), cv::Scalar(0, 0, 0), cv::FILLED); + }; + +#ifdef USE_SCALING_IN + oK = ((float) m_pMaster->m_sEmbedVideoData.height) / ((float) m_pMaster->m_sEmbedVideoData.width); + mK = ((float) Frame.rows) / ((float) Frame.cols); + // sprintf( tBuffer, "INP: [%dx%d] IK:%0.3f OK:%0.3f", Frame.cols, Frame.rows, mK, oK ); + if ((fabsf(mK - oK) < 0.1f) || (fabsf(oK - mK) < 0.1f)) + { + ROI.width = (int) m_pMaster->m_sEmbedVideoData.width; + ROI.height = (int) m_pMaster->m_sEmbedVideoData.height; + ROI.x = (int) 0; + ROI.y = (int) 0; + } + else + { + if (mK < oK) + { + ROI.width = (int) m_pMaster->m_sEmbedVideoData.width; + ROI.height = (int) (((float) m_pMaster->m_sEmbedVideoData.width) * mK); + ROI.x = (int) 0; + ROI.y = (int) (m_pMaster->m_sEmbedVideoData.height - ROI.height) >> 1; + } + else + { + ROI.height = (int) m_pMaster->m_sEmbedVideoData.height; + ROI.width = (int) (((float) m_pMaster->m_sEmbedVideoData.height) / mK); + ROI.y = (int) 0; + ROI.x = (int) (m_pMaster->m_sEmbedVideoData.width - ROI.width) >> 1; + }; + }; + cv::Mat mROI = m_pMaster->m_mapMATS[tMD->mediaStreamId](ROI); + #ifndef USE_CV_DENOISE + cv::resize(Frame, mROI, mROI.size(), 0, 0, cv::INTER_LINEAR); + #else + cv::Mat mDenoiser; + cv::resize(Frame, mDenoiser, mROI.size(), 0, 0, cv::INTER_LINEAR); + cv::fastNlMeansDenoisingColored(mDenoiser, mROI, 10, 10, 7, 17); + #endif + #ifdef USE_CV_TONEMAP + cv::Mat ldrReinhard; + cv::Ptr tonemapReinhard = cv::createTonemapReinhard(1.5, 0, 0, 0); + tonemapReinhard->process(mROI, ldrReinhard); + ldrReinhard = ldrReinhard * 255; + ldrReinhard.copyTo(mROI); + #endif +#else + if ((m_pMaster->m_sEmbedVideoData.height == Frame.rows) && (m_pMaster->m_sEmbedVideoData.width == Frame.cols)) + { + Frame.copyTo(m_pMaster->m_mapMATS[tMD->mediaStreamId]); + } + else + { + // Mat dst_roi = dst(Rect(left, top, src.cols, src.rows)); + // src.copyTo(dst_roi); + + if (m_pMaster->m_sEmbedVideoData.width == Frame.cols) + { + ROI.width = Frame.cols; + ROI.height = Frame.rows; + ROI.x = 0; + ROI.y = (m_pMaster->m_sEmbedVideoData.height - Frame.rows) >> 1; + cv::Mat mROI = m_pMaster->m_mapMATS[tMD->mediaStreamId](ROI); + #ifdef USE_CV_DENOISE + cv::fastNlMeansDenoisingColored(Frame, mROI, 10, 10, 7, 17); + #else + Frame.copyTo(mROI); + #endif + #ifdef USE_CV_TONEMAP + cv::Mat ldrReinhard; + cv::Ptr tonemapReinhard = cv::createTonemapReinhard(1.5, 0, 0, 0); + tonemapReinhard->process(mROI, ldrReinhard); + ldrReinhard = ldrReinhard * 255; + ldrReinhard.copyTo(mROI); + #endif + } + else + { + ROI.width = Frame.cols; + ROI.height = Frame.rows; + ROI.x = (m_pMaster->m_sEmbedVideoData.width - Frame.cols) >> 1; + ROI.y = 0; + cv::Mat mROI = m_pMaster->m_mapMATS[tMD->mediaStreamId](ROI); + #ifdef USE_CV_DENOISE + cv::fastNlMeansDenoisingColored(Frame, mROI, 10, 10, 7, 17); + #else + Frame.copyTo(mROI); + #endif + #ifdef USE_CV_TONEMAP + cv::Mat ldrReinhard; + cv::Ptr tonemapReinhard = cv::createTonemapReinhard(1.5, 0, 0, 0); + tonemapReinhard->process(mROI, ldrReinhard); + ldrReinhard = ldrReinhard * 255; + ldrReinhard.copyTo(mROI); + #endif + }; + }; +#endif + // 0 - dis .. 1 - Hor ... 2 - vert 3 - both + if (m_bFlipMode) + { + // Flip Horizontally = 1 vertically = 0 both = -1 + cv::Mat mirroredImage; + cv::flip(m_pMaster->m_mapMATS[tMD->mediaStreamId], mirroredImage, 2 - m_bFlipMode); + mirroredImage.copyTo(m_pMaster->m_mapMATS[tMD->mediaStreamId]); + }; + +#ifdef EVE_ENABLE_DROP_OUTPUT_FPS + // LOG("T"); + m_mEncodingQueueProtector.lock(); + if (m_qEncodingQueue.size() > 10) + { + m_mEncodingQueueProtector.unlock(); + m_pMaster->m_mPictureProtector.unlock(); + // LOG("D"); + return true; + }; + m_mEncodingQueueProtector.unlock(); + // LOG("Q"); +#endif + + if (m_bCamMoveCounter > m_bEvtMarkerCounter) + { + cv::rectangle(m_pMaster->m_mapMATS[tMD->mediaStreamId], cv::Rect(10, 10, 20, 20), cv::Scalar(m_bCamMoveCounter, 0, 0), cv::FILLED); + m_bCamMoveCounter -= 4; + if (m_bCamMoveCounter < 4) + { + m_bCamMoveCounter = 0; + } + } + else + { + if (m_bEvtMarkerCounter) + { + m_bCamMoveCounter = 0; + cv::rectangle(m_pMaster->m_mapMATS[tMD->mediaStreamId], cv::Rect(10, 10, 20, 20), cv::Scalar(0, 0, m_bEvtMarkerCounter), cv::FILLED); + m_bEvtMarkerCounter -= 4; + if (m_bEvtMarkerCounter < 4) + { + m_bEvtMarkerCounter = 0; + } + }; + }; + if (m_pMaster->m_sEmbedVideoData.show_label) + { + time_t t = time(NULL); + // struct tm * tmp = gmtime( &t ); + struct tm * tmp = localtime(&t); + if (tmp) + { + char tsb[64]; + // if( strftime( tsb, sizeof(tsb), "%F %T GMT", tmp )!=0 ){ + if (strftime(tsb, sizeof(tsb), "%F %T", tmp) != 0) + { + + // sprintf( tBuffer, ">>%d>%d>%s>%s>", tMD->mediaSourceId, tMD->mediaStreamId, tMD->mediaName, tsb ); + sprintf(tBuffer, ">>>%s>%s>", tMD->mediaName, tsb); + int baseline = 0; + cv::Size textSize = cv::getTextSize(tBuffer, m_pMaster->m_sEmbedVideoData.label_font_face, m_pMaster->m_sEmbedVideoData.label_font_scale, m_pMaster->m_sEmbedVideoData.label_font_thickness, &baseline); + int x = m_pMaster->m_sEmbedVideoData.label_x; + int y = m_pMaster->m_sEmbedVideoData.label_y; + if (x < 0) + { + x = m_pMaster->m_sEmbedVideoData.width + x - textSize.width; + }; + if (y < 0) + { + y = m_pMaster->m_sEmbedVideoData.height + y - baseline; // + }; + if (! m_pMaster->m_sEmbedVideoData.label_transperant) + { + cv::rectangle(m_pMaster->m_mapMATS[tMD->mediaStreamId], cv::Rect(x, y - textSize.height - 4, textSize.width, textSize.height + baseline + 4), cv::Scalar(0, 0, 0), cv::FILLED); + }; + cv::putText(m_pMaster->m_mapMATS[tMD->mediaStreamId], tBuffer, cv::Point(x, y), (cv::HersheyFonts) m_pMaster->m_sEmbedVideoData.label_font_face, m_pMaster->m_sEmbedVideoData.label_font_scale, cv::Scalar(0, 255, 0), + m_pMaster->m_sEmbedVideoData.label_font_thickness, m_pMaster->m_sEmbedVideoData.label_line_type); + }; + }; + } + else + { + if (m_pMaster->m_sEmbedVideoData.show_ts) + { + time_t t = time(NULL); + // struct tm * tmp = gmtime( &t ); + struct tm * tmp = localtime(&t); + if (tmp) + { + if (strftime(tBuffer, sizeof(tBuffer), "%F %T GMT", tmp) != 0) + { + uint8_t shift_x = 0; + uint8_t shift_y = 15; + if (! m_pMaster->m_sEmbedVideoData.ts_transperant) + { + if (m_pMaster->m_sEmbedVideoData.ts_font_face) + { + shift_y = 15; + cv::rectangle(m_pMaster->m_mapMATS[tMD->mediaStreamId], cv::Point(m_pMaster->m_sEmbedVideoData.ts_x, m_pMaster->m_sEmbedVideoData.ts_y), cv::Point(490, 60), cv::Scalar(0, 0, 0), cv::FILLED); + } + else + { + shift_y = 23; + cv::rectangle(m_pMaster->m_mapMATS[tMD->mediaStreamId], cv::Point(m_pMaster->m_sEmbedVideoData.ts_x, m_pMaster->m_sEmbedVideoData.ts_y), cv::Point(490, 60), cv::Scalar(0, 0, 0), cv::FILLED); + }; + cv::putText(m_pMaster->m_mapMATS[tMD->mediaStreamId], tBuffer, cv::Point(m_pMaster->m_sEmbedVideoData.ts_x + shift_x, m_pMaster->m_sEmbedVideoData.ts_y + shift_y), + (cv::HersheyFonts) m_pMaster->m_sEmbedVideoData.ts_font_face, m_pMaster->m_sEmbedVideoData.ts_font_scale, cv::Scalar(0, 255, 255), m_pMaster->m_sEmbedVideoData.ts_font_thickness, + m_pMaster->m_sEmbedVideoData.ts_line_type); + } + else + { + if (m_pMaster->m_sEmbedVideoData.ts_font_face) + { + shift_y = 15; + } + else + { + shift_y = 23; + }; + cv::putText(m_pMaster->m_mapMATS[tMD->mediaStreamId], tBuffer, cv::Point(m_pMaster->m_sEmbedVideoData.ts_x + shift_x - 1, m_pMaster->m_sEmbedVideoData.ts_y + shift_y - 1), + (cv::HersheyFonts) m_pMaster->m_sEmbedVideoData.ts_font_face, m_pMaster->m_sEmbedVideoData.ts_font_scale, cv::Scalar(0, 0, 0), m_pMaster->m_sEmbedVideoData.ts_font_thickness, m_pMaster->m_sEmbedVideoData.ts_line_type); + cv::putText(m_pMaster->m_mapMATS[tMD->mediaStreamId], tBuffer, cv::Point(m_pMaster->m_sEmbedVideoData.ts_x + shift_x + 1, m_pMaster->m_sEmbedVideoData.ts_y + shift_y - 1), + (cv::HersheyFonts) m_pMaster->m_sEmbedVideoData.ts_font_face, m_pMaster->m_sEmbedVideoData.ts_font_scale, cv::Scalar(0, 0, 0), m_pMaster->m_sEmbedVideoData.ts_font_thickness, m_pMaster->m_sEmbedVideoData.ts_line_type); + cv::putText(m_pMaster->m_mapMATS[tMD->mediaStreamId], tBuffer, cv::Point(m_pMaster->m_sEmbedVideoData.ts_x + shift_x - 1, m_pMaster->m_sEmbedVideoData.ts_y + shift_y + 1), + (cv::HersheyFonts) m_pMaster->m_sEmbedVideoData.ts_font_face, m_pMaster->m_sEmbedVideoData.ts_font_scale, cv::Scalar(0, 0, 0), m_pMaster->m_sEmbedVideoData.ts_font_thickness, m_pMaster->m_sEmbedVideoData.ts_line_type); + cv::putText(m_pMaster->m_mapMATS[tMD->mediaStreamId], tBuffer, cv::Point(m_pMaster->m_sEmbedVideoData.ts_x + shift_x - 1, m_pMaster->m_sEmbedVideoData.ts_y + shift_y + 2), + (cv::HersheyFonts) m_pMaster->m_sEmbedVideoData.ts_font_face, m_pMaster->m_sEmbedVideoData.ts_font_scale, cv::Scalar(0, 0, 0), m_pMaster->m_sEmbedVideoData.ts_font_thickness, m_pMaster->m_sEmbedVideoData.ts_line_type); + cv::putText(m_pMaster->m_mapMATS[tMD->mediaStreamId], tBuffer, cv::Point(m_pMaster->m_sEmbedVideoData.ts_x + shift_x, m_pMaster->m_sEmbedVideoData.ts_y + shift_y), + (cv::HersheyFonts) m_pMaster->m_sEmbedVideoData.ts_font_face, m_pMaster->m_sEmbedVideoData.ts_font_scale, cv::Scalar(0, 255, 255), m_pMaster->m_sEmbedVideoData.ts_font_thickness, + m_pMaster->m_sEmbedVideoData.ts_line_type); + } + }; + }; + }; + }; + if (m_pMaster->m_sEmbedVideoData.show_logo) + { + cv::Rect roi(cv::Point(m_pMaster->m_sEmbedVideoData.logo_x, m_pMaster->m_sEmbedVideoData.logo_y), cv::Size(m_pMaster->m_sEmbedVideoData.logo_w, m_pMaster->m_sEmbedVideoData.logo_h)); + cv::Mat destinationROI = m_pMaster->m_mapMATS[tMD->mediaStreamId](roi); + m_pMaster->m_mLogoPic.copyTo(destinationROI, m_pMaster->m_mLogoMask); + }; + // Live view of the processed frame (EVE_LIVE_ENCODE): copied for the encoder thread + if (m_pLiveEncoder) + { + m_pLiveEncoder->push(m_pMaster->m_mapMATS[tMD->mediaStreamId]); + }; + +#ifndef EVE_WORK_WITH_MEDIAMTX + vector compression_params; + // compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION); + // compression_params.push_back(9); + compression_params.push_back(cv::IMWRITE_JPEG_QUALITY); + compression_params.push_back(50); // m_pMaster->m_sEmbedVideoData.compression_quality ); + + m_pMaster->m_mEncodedProtector.lock(); + m_pMaster->m_mapCAPTURES[tMD->mediaStreamId].clear(); + cv::imencode(".jpg", m_pMaster->m_mapMATS[tMD->mediaStreamId], m_pMaster->m_mapCAPTURES[tMD->mediaStreamId], compression_params); + + // cv::Mat bw_dst; + // cv::cvtColor( m_pMaster->m_mapMATS[tMD->mediaStreamId], bw_dst, cv::COLOR_BGR2GRAY ); + // cv::imencode( ".jpg", bw_dst, m_pMaster->m_mapCAPTURES[tMD->mediaStreamId], compression_params ); + + #ifdef HAVE_SMAL_PREVIEW_STREAMS + // Make Small Preview Thumb + cv::Mat dst; + cv::resize(m_pMaster->m_mapMATS[tMD->mediaStreamId], dst, cv::Size(PREVIEW_SIZE_WIDTH, PREVIEW_SIZE_HEIGHT)); + // cv::resize( bw_dst, dst, cv::Size( PREVIEW_SIZE_WIDTH, PREVIEW_SIZE_HEIGHT )); + + m_pMaster->m_mapPREVIEWS[tMD->mediaStreamId].clear(); + cv::imencode(".jpg", dst, m_pMaster->m_mapPREVIEWS[tMD->mediaStreamId], compression_params); + #endif +#endif // !EVE_WORK_WITH_MEDIAMTX + m_pMaster->m_mEncodedProtector.unlock(); + +#ifdef EVE_ENABLE_VIDEO + // if only decode Video Stream -> Exit + // To handle video recording elsewhere (For Steph) + if (m_eWM == MS_MODE_DECODE_FRAMES) + { + m_pMaster->m_mPictureProtector.unlock(); + return true; + }; + // encode Video Stream + + // m_nPreAlarmFrames + // m_nPostAlarmFrames + // m_nNoAlarmSegmentFrames + // m_nSegmentLimitFrames + // m_nHardLimitFrames + #ifdef EVE_SEQUENTAL_OUTPUT + if ( m_bSegActive ) + { // The Open/Close is management ath Encoder Thread Procedure + #else // !EVE_SEQUENTAL_OUTPUT + if (m_bSegAActive || m_bSegBActive) + { + m_mFrameCounterProtector.lock(); + if( m_bSegAActive ) { + if (m_nSegAFrameCounter > m_nHardLimitFrames) { + #ifdef DEBUG_EXTRA + LOG("HardLimit Reached!(A)"); + #endif + closeSegmentA(); + // break; + }; + if (m_nSegAFrameCounter > (m_nSegmentLimitFrames - (m_nPostAlarmFrames + m_nPreAlarmFrames))){ + if (! m_bSegBActive){ + #ifdef DEBUG_EXTRA + LOG("Start Alt!(A)"); + #endif + openSegmentB(); + }; + }; + if (m_nSegAFrameCounter > (m_nSegmentLimitFrames - m_nPostAlarmFrames) && ! m_bActiveEncoderStream){ + #ifdef DEBUG_EXTRA + LOG("Swap Active!(A)"); + #endif + swapActiveStreams(); + }; + }; + + if( m_bSegBActive ){ + if (m_nSegBFrameCounter > m_nBHardLimitFrames){ + #ifdef DEBUG_EXTRA + LOG("HardLimit Reached!(B)"); + #endif + closeSegmentB(); + }; + if (m_nSegBFrameCounter > (m_nBSegmentLimitFrames - (m_nBPostAlarmFrames + m_nAPreAlarmFrames))){ + if (! m_bSegAActive){ + #ifdef DEBUG_EXTRA + LOG("Start Alt!(B)"); + #endif + openSegmentA(); + }; + }; + if (m_nSegBFrameCounter > (m_nBSegmentLimitFrames - m_nBPostAlarmFrames) && m_bActiveEncoderStream){ + #ifdef DEBUG_EXTRA + LOG("Swap Active!(B)"); + #endif + swapActiveStreams(); + }; + }; + m_mFrameCounterProtector.unlock(); + #endif // !EVE_SEQUENTAL_OUTPUT + + + // Transfer Data to Encoder Thread + + ENCODING_BUFFER * tData = (ENCODING_BUFFER *) malloc(sizeof(ENCODING_BUFFER)); + if (tData) + { + #ifdef DIRECT_MJPEG_COMPOSING + tData->size = m_pMaster->m_mapCAPTURES[tMD->mediaStreamId].size(); + tData->data = (uint8_t *) malloc(tData->size); + if (tData->data) + { + memcpy(tData->data, m_pMaster->m_mapCAPTURES[tMD->mediaStreamId].data(), tData->size); + // Aproach to reference and not copy data ... was not such a good idea + // tData->data = m_pMaster->m_mapCAPTURES[tMD->mediaStreamId].data(); + // if ( tData->data ) { + #else + #ifdef OPENCV_VIDEO_OUTPUT + tData->rows = m_pMaster->m_mapMATS[tMD->mediaStreamId].rows; + tData->cols = m_pMaster->m_mapMATS[tMD->mediaStreamId].cols; + tData->size = m_pMaster->m_mapMATS[tMD->mediaStreamId].cols * m_pMaster->m_mapMATS[tMD->mediaStreamId].elemSize() * tData->rows; + tData->data = (uint8_t *) malloc(tData->size); + if (tData->data) + { + memcpy(tData->data, m_pMaster->m_mapMATS[tMD->mediaStreamId].data, tData->size); + #else // OPENCV_VIDEO_OUTPUT + tData->linesize[0] = m_pMaster->m_mapMATS[tMD->mediaStreamId].cols * m_pMaster->m_mapMATS[tMD->mediaStreamId].elemSize(); + tData->linesize[1] = 0; + tData->rows = m_pMaster->m_mapMATS[tMD->mediaStreamId].rows; + tData->size = tData->linesize[0] * tData->rows; + tData->data[1] = NULL; + tData->data[0] = (uint8_t *) malloc(tData->size); + if (tData->data[0]) + { + memcpy(tData->data[0], m_pMaster->m_mapMATS[tMD->mediaStreamId].data, tData->size); + #endif // OPENCV_VIDEO_OUTPUT + #endif //! DIRECT_MJPEG_COMPOSING + m_mEncodingQueueProtector.lock(); + m_qEncodingQueue.push(tData); + m_mEncodingQueueProtector.unlock(); + } + else + { + LOG_ERROR("MAT_CPY malloc Error!"); + free(tData); + }; + } + else + { + LOG_ERROR("ENC_BUF malloc Error!"); + } + }; +#endif // EVE_ENABLE_VIDEO + m_pMaster->m_mPictureProtector.unlock(); + } + else + { + LOG_ERROR("No PayLoad!"); + }; + return true; +} + +#ifdef EVE_ENABLE_VIDEO + #ifdef EVE_SEQUENTAL_OUTPUT + /* + bool streamHandler::openSegment(void){ + if (!m_bSegActive) + { + CSTR tAM = getUniqID_MD5(); + if(tAM) + { + sprintf(m_sStreamSegmentInfo.scratchPath, "%s/%s.%s", m_pVideoScratchPath, tAM, VIDEO_OUTPUT_CONTAINER); + strncpy(m_sStreamSegmentInfo.recordMD5, tAM, 32); + m_sStreamSegmentInfo.recordMD5[32] = (char) 0; + free(tAM); + m_sStreamSegmentInfo.stream_id = m_sStreamData.id; + PF_TIMESTAMP ts; + getPFTS(&ts); + m_sStreamSegmentInfo.streamTSS = ts.seconds; + m_sStreamSegmentInfo.streamTMS = ts.milliseconds; + #ifdef DEBUG_EXTRA + char tB[128]; + sprintf(tB, "A opened %d.%d", m_sStreamSegmentInfo.streamTSS, m_sStreamSegmentInfo.streamTMS); + LOG(tB); + #endif + strncpy(m_sStreamSegmentInfo.recordEXT, VIDEO_OUTPUT_CONTAINER, 6); + m_sStreamSegmentInfo.streamFPS = m_sStreamData.fps; + m_sStreamSegmentInfo.streamWidth = m_pMaster->getWidh(); + m_sStreamSegmentInfo.streamHeight = m_pMaster->getHeight(); + m_sStreamSegmentInfo.eventIDS.clear(); + m_sStreamSegmentInfo.eventTSS.clear(); + m_sStreamSegmentInfo.eventTMS.clear(); + m_sStreamSegmentInfo.eventFrames.clear(); + m_sStreamSegmentInfo.dataSize = 0; + m_sStreamSegmentInfo.db_id = 0; + #ifdef DIRECT_MJPEG_COMPOSING + m_pOutputFD = fopen(m_sStreamSegmentInfo.scratchPath, "wb+"); + m_nSegFrameCounter = 0; + m_nSegShiftFrames = 0; + m_bSegActive = true; + m_bSegDelete = m_bNSegDelete; + m_bNSegDelete = true; + #else // !DIRECT_MJPEG_COMPOSING + #ifdef OPENCV_VIDEO_OUTPUT + if (m_pEncoderA) + { + // int fourcc = cv::VideoWriter::fourcc('H', '2', '6', '4'); + int fourcc = cv::VideoWriter::fourcc('M', 'J', 'P', 'G'); + double fps = m_sStreamData.fps; + cv::String mn(m_sStreamSegmentInfo.scratchPath); + cv::Size fz(m_sStreamData.width, m_sStreamData.height); + // open (const String &filename, int fourcc, double fps, Size frameSize, bool isColor=true) + if (! m_pEncoder->open(mn, fourcc, fps, fz)) + { + LOG_ERROR("Cannot Open Output Segment A!"); + return false; + #ifdef DEBUG_EXTRA + } + else + { + char tB[256]; + sprintf(tB, "VideoStream A is Created [%s] %.2f fps", m_sStreamSegmentInfo.scratchPath, fps); + LOG(tB); + #endif + }; + m_bSegActive = true; + m_bSegDelete = m_bNSegDelete; + m_bNSegDelete = true; + m_nSegFrameCounter = 0; + m_nSegShiftFrames = 0; + } + else + { + LOG_ERROR("No Encoder(A) Object!"); + return false; + }; + #else // !OPENCV_VIDEO_OUTPUT + // Check if Encoder is Ready + if (m_pFormat == NULL) + { + return false; + } + + #ifdef SEPARATED_VIDEO_ENCODERS + if (avformat_alloc_output_context2(&m_pFormatCtx, m_pFormat, NULL, "test." VIDEO_OUTPUT_CONTAINER) < 0) + { + LOG_ERROR("Format CTX A alloc error!"); + return false; + } + else + { + av_dict_set(&m_pFormatCtx->metadata, "Author", "Argus Sec. System", 0); + m_pFormatCtx->flags |= AVFMT_NOTIMESTAMPS | AVFMT_TS_NONSTRICT; + }; + + m_pVideoStr = avformat_new_stream(m_pFormatCtx, m_pVideoACodec); + if (m_pVideoStr == NULL) + { + avformat_free_context(m_pFormatCtx); + return false; + #ifdef DEBUG_EXTRA + } + else + { + LOG("VideoStream A is Created"); + #endif + }; + const AVRational dst_fps = {m_sStreamData.fps, 1}; + m_pVideoStr->r_frame_rate = m_pVideoStrA->avg_frame_rate = dst_fps; + m_pVideoStr->time_base = m_pCodecCtx->time_base; + avcodec_parameters_from_context(m_pVideoStr->codecpar, m_pCodecACtx); + #ifdef DEBUG_EXTRA + LOG("Opening Stream A"); + LOG(m_cSegName); + char tB[128]; + sprintf(tB, "FFPTS:%llu FNUM:%llu S2KF:%llu", m_pVideoStr->start_time, m_pVideoStr->nb_frames, m_pVideoStr->first_dts); + LOG(tB); + sprintf(tB, "CON ST:%llu DUR:%llu", m_pFormatCtx->start_time, m_pFormatCtx->duration); + LOG(tB); + #endif + // if (avio_open(&m_pFormatCtx->pb, m_cSegNameA, AVIO_FLAG_WRITE) < 0) { + if (avio_open(&m_pFormatCtx->pb, m_sStreamSegmentInfo.scratchPath, AVIO_FLAG_WRITE) < 0) + { + LOG_ERROR("Could not open output file."); + return m_bSegActive; + }; + if (avformat_write_header(m_pFormatCtx, &m_pFormatOpts) < 0) + { + LOG_ERROR("Error occurred when writing header to output file."); + return m_bSegActive; + }; + // m_mFrameCounterProtector.lock(); + m_nSegFrameCounter = 0; + m_nSegShiftFrames = 0; + m_bSegActive = true; + m_bSegDelete = m_bNSegDelete; + m_bNSegDelete = true; + // m_mFrameCounterProtector.unlock(); + #else // SEPARATED_VIDEO_ENCODERS + m_nSegSkippedFrames = m_pVideoStr->nb_frames + 1; + if (m_pVideoStr->nb_frames) + { + m_pVideoStr->nb_frames = 0; + m_pVideoStr->start_time = 0; + m_pVideoStr->first_dts = 0; + m_pFormatCtx->start_time = 0; + }; + #ifdef DEBUG_EXTRA + LOG("Opening Stream"); + LOG(m_cSegName); + char tB[128]; + sprintf(tB, "FFPTS:%llu FNUM:%llu S2KF:%llu", m_pVideoStr->start_time, m_pVideoStr->nb_frames, m_pVideoStr->first_dts); + LOG(tB); + sprintf(tB, "CON ST:%llu DUR:%llu", m_pFormatCtx->start_time, m_pFormatCtx->duration); + LOG(tB); + #endif + if (avio_open(&m_pFormatCtx->pb, m_cSegName, AVIO_FLAG_WRITE) < 0) + { + LOG_ERROR("Could not open output file."); + return m_bSegActive; + }; + if (avformat_write_header(m_pFormatCtx, &m_pFormatOpts) < 0) + { + LOG_ERROR("Error occurred when writing header to output file."); + return m_bSegActive; + }; + // m_mFrameCounterProtector.lock(); + m_nSegFrameCounter = 0; + m_nSegShiftFrames = 0; + m_bSegActive = true; + m_bSegDelete = m_bNSegDelete; + m_bNSegDelete = true; + // m_mFrameCounterProtector.unlock(); + #endif // SEPARATED_VIDEO_ENCODERS + #ifdef DEBUG_EXTRA + LOG("Stream Opened"); + #endif + #endif // !OPENCV_VIDEO_OUTPUT + #endif // !DIRECT_MJPEG_COMPOSING + }; + }; + return m_bSegActive; + } + void streamHandler::closeSegment(void){ + #ifdef DEBUG + LOG("Closing Stream"); + #endif + #ifdef DEBUG_EXTRA + LOG("Actual Closing Video Stream"); + LOG(m_sStreamSegmentInfo.scratchPath); + #endif + m_bSegActive = false; + if( !m_bSegDelete ){ + #ifdef DIRECT_MJPEG_COMPOSING + if (m_pOutputFD){ + fclose(m_pOutputFD); + m_pOutputFD = NULL; + }; + #else // !DIRECT_MJPEG_COMPOSING + #ifdef OPENCV_VIDEO_OUTPUT + if (m_pEncoder->isOpened()){ + m_pEncoder->release(); + #ifdef DEBUG_EXTRA + }else{ + LOG(" Encoder is NOT Opened!"); + #endif + }; + #else // !OpenCV + av_write_trailer(m_pFormatCtx); + avio_close(m_pFormatCtx->pb); + #endif // !OPENCV_VIDEO_OUTPUT + #endif // !DIRECT_MJPEG_COMPOSING + EVENT_CONTAINER * bEVT = createBasicEvent(m_sStreamData.source_id, EVT_CLASS_VIDEO, EVT_CAPTURE_DONE, NULL, NULL, &m_sStreamSegmentInfo); + if (bEVT){ + basicEventHeap::getInstance()->broadcast(bEVT); + }else{ + LOG_ERROR("Event Creation failure!"); + } + #ifdef DEBUG_EXTRA + LOG("Stream is Saved"); + #endif + } else { + #ifdef DIRECT_MJPEG_COMPOSING + if ( m_pOutputFD ){ + fclose(m_pOutputFD); + m_pOutputFD = NULL; + }; + #else + #ifdef OPENCV_VIDEO_OUTPUT + if (m_pEncoder->isOpened()) { + m_pEncoder->release(); + #ifdef DEBUG_EXTRA + } else { + LOG(" Encoder is NOT Opened!"); + #endif + }; + #else // !OPenCV + #ifdef EVE_DONT_DELETE_SEGMENTS + av_write_trailer(m_pFormatCtx); + #endif + avio_close(m_pFormatCtx->pb); + #endif // !OPENCV_VIDEO_OUTPUT + #endif // !DIRECT_MJPEG_COMPOSING + #ifndef EVE_DONT_DELETE_SEGMENTS + unlink(m_sStreamSegmentInfo.scratchPath); + #endif + #ifdef DEBUG_EXTRA + LOG("Stream is Closed!"); + #endif + }; + } + */ + // Final Closing All + Thread + void streamHandler::closeAll() + { + waitThreadEnd(true); + #ifdef OPENCV_VIDEO_OUTPUT + if (m_pEncoder){ + if (m_pEncoder->isOpened()){ + m_pEncoder->release(); + }; + delete(m_pEncoder); + }; + #else // !OPENCV_VIDEO_OUTPUT + #ifdef DIRECT_MJPEG_COMPOSING + if (m_pOutputFD ){ + fclose(m_pOutputFD); + m_pOutputFD = NULL; + }; + #else // ! DIRECT_MJPEG_COMPOSING + if(( m_pCodecCtx != NULL ) && m_bSegActive ){ + if (m_pCodecCtx != NULL){ + avcodec_send_frame(m_pCodecCtx, NULL); + int ret = 0; + AVPacket * avp = av_packet_alloc(); + if (avp){ + do{ + av_packet_unref(avp); + ret = avcodec_receive_packet(m_pCodecACtx, avp); + if (! ret){ + if (m_bSegActive){ + av_write_frame(m_pFormatCtxA, avp); + }; + }; + } while (! ret); + av_packet_unref(avp); + av_packet_free(&avp); + }; + }; + if (m_bSegActive){ + av_write_trailer(m_pFormatCtx); + avformat_close_input(&m_pFormatCtx); + m_bSegActive = false; + }; + }; + #endif // !DIRECT_MJPEG_COMPOSING + #endif // !OPENCV_VIDEO_OUTPUT + } + bool streamHandler::initVideoOutput() + { + + m_nPreAlarmFrames = (PRE_ALARM_TIME_MILSECONDS * m_sStreamData.fps) / 1000; + m_nPostAlarmFrames = (POST_ALARM_TIME_MILSECONDS * m_sStreamData.fps) / 1000; + m_nSegmentLimitFrames = (ENCODING_SEGMENT_MILSECONDS * m_sStreamData.fps) / 1000; + m_nHardLimitFrames = (ENCODING_SEGMENT_LIMIT_MILSECONDS * m_sStreamData.fps) / 1000; + + #ifndef DIRECT_MJPEG_COMPOSING + #ifdef OPENCV_VIDEO_OUTPUT + //cv::VideoWriter out( m_sEncoderVS.m_pFileName, cv::VideoWriter::fourcc('a', 'v', 'c', '1'), 15.0, mat.size() ); + m_pEncoder = new cv::VideoWriter(); + if (m_pEncoder == NULL) + { + LOG_ERROR("Encoder A Create Failure!"); + return false; + }; + + //m_pEncoder->set(cv::VIDEOWRITER_PROP_QUALITY, 10.0); + //m_pEncoder->set(cv::VIDEOWRITER_PROP_NSTRIPES, -1.0); + + #else + if (! initLibAV()) + { + return false; + } + + m_pFormat = av_guess_format(VIDEO_OUTPUT_CONTAINER, "test." VIDEO_OUTPUT_CONTAINER, NULL); + + if (m_pFormat == NULL) + { + LOG_ERROR("Out VideoFormat Not Found!"); + return false; + #ifdef DEBUG_EXTRA + } else { + LOG("Output video Format"); + LOG(VIDEO_OUTPUT_CONTAINER); + #endif + }; + + #ifdef SEPARATED_VIDEO_ENCODERS + /* Stream A */ + m_pVideoCodec = avcodec_find_encoder(VIDEO_OUTPUT_CODEC); + if (m_pVideoCodec == NULL) + { + LOG_ERROR("Encoder Video Codec Not Found!"); + return false; + #ifdef DEBUG_EXTRA + } else { + LOG("Video Encoder Created"); + #endif + }; + m_pCodecCtx = avcodec_alloc_context3(m_pVideoACodec); + if (m_pCodecCtx == NULL) + { + LOG_ERROR("Video Encoder Context Memory Allocation Error!"); + av_free(m_pVideoCodec); + avformat_free_context(m_pFormatCtx); + return false; + #ifdef DEBUG_EXTRA + } else { + LOG("Video Encoder Context A Allocated"); + #endif + }; + m_pCodecCtx->codec_id = VIDEO_OUTPUT_CODEC; + m_pCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO; + m_pCodecCtx->pix_fmt = VIDEO_OUTPUT_PIX_FMT; + m_pCodecCtx->bit_rate = VIDEO_OUTPUT_BITRATE; + m_pCodecCtx->max_b_frames = 1; + m_pCodecCtx->width = m_pMaster->m_sEmbedVideoData.width; + m_pCodecCtx->height = m_pMaster->m_sEmbedVideoData.height; + m_pCodecCtx->time_base.num = 1; + m_pCodecCtx->time_base.den = m_sStreamData.fps; + m_pCodecCtx->framerate.num = m_sStreamData.fps; + m_pCodecCtx->framerate.den = 1; + #if (LIBAVCODEC_VERSION_MAJOR > 54) + // m_pCodecACtx->codec_tag = av_codec_get_tag( m_pFormatCtxA->oformat->codec_tag, VIDEO_OUTPUT_CODEC ); + #endif + m_pFormatOpts = NULL; + if ((m_pCodecCtx->codec_id == AV_CODEC_ID_H264) || (m_pCodecCtx->codec_id == AV_CODEC_ID_H265)) + { + #ifdef DEBUG_EXTRA + LOG("Begin Options!"); + #endif + if (av_dict_set(&m_pFormatOpts, "movflags", "isml+faststart+frag_keyframe+empty_moov+omit_tfhd_offset", 0) < 0) + { + LOG_ERROR("av_dict_set movflags!"); + #ifdef DEBUG_EXTRA + } else { + LOG("MOV FLAG SET!"); + #endif + }; + // if( av_dict_set( &m_pFormatOpts, "live", "1", 0 ) < 0 ){ + // LOG_ERROR( "av_dict_set live!" ); + // }; + + // default brand is "isom", which fails on some devices + if (av_dict_set(&m_pFormatOpts, "brand", "mp42", 0) < 0) + { + LOG_ERROR("av_dict_set brand!"); + }; + // m_pCodecCtx->max_b_frames = 1; + // m_pCodecCtx->level = 31; + m_pCodecCtx->gop_size = m_sStreamData.fps << 1; // VIDEO_OUTPUT_GOP; // emit one intra frame every X frames + // P-frames, generated by referencing data from prev and future frames. + // [Compression up, CPU usage up] + // [use 3/gop] + m_pCodecCtx->max_b_frames = 5; + // Can be used by a P-frame(predictive, partial frame) to help define a future frame in a compressed video. + // [use 3?5 ref per P] + m_pCodecCtx->refs = 3; + // Compression efficiency (slower -> better quality + higher cpu%) + // [ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow] + // Set this option to "ultrafast" is critical for realtime encoding + av_opt_set(m_pCodecCtx->priv_data, "preset", "ultrafast", 0); + // av_opt_set( m_pCodecCtx->priv_data, "preset", "fast", 0 ); + // av_opt_set( m_pCodecCtx->priv_data, "preset", "slow", 0 ); + + // Compression rate (lower -> higher compression) compress to lower size, makes decoded image more noisy + // Range: [0; 51], sane range: [18; 26]. I used 35 as good compression/quality compromise. This option also critical for realtime encoding + av_opt_set(m_pCodecCtx->priv_data, "crf", "32", 0); + // Change settings based upon the specifics of input + // [psnr, ssim, grain, zerolatency, fastdecode, animation] + // This option is most critical for realtime encoding, because it removes delay between 1th input frame and 1th output packet. + av_opt_set(m_pCodecCtx->priv_data, "tune", "zerolatency", 0); + // Disable b-pyramid. CLI options for this is "-b-pyramid 0" + // Because Quicktime (ie. iOS) doesn't support this option + av_opt_set(m_pCodecACtx->priv_data, "b-pyramid", "0", 0); + #ifdef DEBUG_EXTRA + LOG("End Options!"); + #endif + } else { // codec is not AV_CODEC_ID_H264 || AV_CODEC_ID_H265 + if( m_pFormat->flags & AVFMT_GLOBALHEADER ) + { + m_pCodecCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; + } + }; + const AVRational dst_fps = {m_sStreamData.fps, 1}; + + #ifdef DEBUG_EXTRA + char TB[129]; + sprintf(TB, "TimeBaseA: num[%d]/den[%d]", m_pCodecACtx->time_base.num, m_pCodecACtx->time_base.den); + LOG(TB); + sprintf(TB, "TimeBaseB: num[%d]/den[%d]", m_pCodecBCtx->time_base.num, m_pCodecBCtx->time_base.den); + LOG(TB); + #endif + ////m_pVideoStr->time_base = m_pCodecCtx->time_base; + // avcodec_get_context_defaults3( m_pVideoStr->codec, m_pVideoCodec ); + + // m_pVideoStr->codec->width = m_pMaster->m_sEmbedVideoData.width; + // m_pVideoStr->codec->height = m_pMaster->m_sEmbedVideoData.height; + // m_pVideoStr->codec->pix_fmt = VIDEO_OUTPUT_PIX_FMT; + // m_pVideoStr->codec->time_base = m_pVideoStrB->time_base = av_inv_q(dst_fps); + //// m_pVideoStr->r_frame_rate = m_pVideoStrA->avg_frame_rate = + ////dst_fps; + + // if ( m_pFormatCtx->oformat->flags & AVFMT_GLOBALHEADER ) m_pVideoStrA->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; + + //// avcodec_parameters_from_context( m_pVideoStr->codecpar, + ////m_pCodecCtx ); + // m_pVideoStr->codecpar->format = VIDEO_OUTPUT_PIX_FMT; + // m_pVideoStr->codecpar->extradata = m_pCodecCtx->extradata; + // m_pVideoStr->codecpar->extradata_size = m_pCodecCtx->extradata_size; + + if (avcodec_is_open(m_pCodecCtx) == 0) + { + LOG("output codec context is closed, opening"); + if (avcodec_open2(m_pCodecCtx, m_pVideoCodec, NULL) < 0) + { + LOG_ERROR("Error opening2 encoder"); + return false; + #ifdef DEBUG_EXTRA + } else { + LOG("output codec context is opened"); + #endif + }; + + #ifdef DEBUG_EXTRA + } else { + LOG("output codec context is already opened"); + #endif + }; + #else // !SEPARATED_VIDEO_ENCODERS + if (avformat_alloc_output_context2(&m_pFormatCtx, m_pFormat, NULL, "test." VIDEO_OUTPUT_CONTAINER) < 0) + { + LOG_ERROR("Format CTX alloc error!"); + return false; + } else { + av_dict_set(&m_pFormatCtx->metadata, "Author", "Argus Sec. System", 0); + m_pFormatCtx->flags |= AVFMT_NOTIMESTAMPS | AVFMT_TS_NONSTRICT; + }; + m_pVideoCodec = avcodec_find_encoder(VIDEO_OUTPUT_CODEC); + if (m_pVideoCodec == NULL) + { + LOG_ERROR("Output VideoCodec Not Found!"); + avformat_free_context(m_pFormatCtxA); + avformat_free_context(m_pFormatCtxB); + return false; + #ifdef DEBUG_EXTRA + } else { + LOG("Output Video Codec Found"); + #endif + }; + + m_pCodecCtx = avcodec_alloc_context3(m_pVideoCodec); + if (m_pCodecCtx == NULL) + { + LOG_ERROR("Out VideoCodec Context Memory Allocation Error"); + av_free(m_pVideoCodec); + avformat_free_context(m_pFormatCtx); + return false; + #ifdef DEBUG_EXTRA + } else { + LOG("Out Codec Context3 Allocated"); + #endif + }; + m_pVideoStr = avformat_new_stream(m_pFormatCtx, m_pVideoCodec); + if (m_pVideoStr == NULL) + { + LOG_ERROR("VideoStream A Not Created!"); + avcodec_free_context(&m_pCodecCtx); + av_free(m_pCodecCtx); + av_free(m_pVideoCodec); + // avformat_close_input ( &m_pFormatCtx ); + avformat_free_context(m_pFormatCtx); + return false; + #ifdef DEBUG_EXTRA + } else { + LOG("VideoStream A is Created"); + #endif + }; + + m_pCodecCtx->codec_id = VIDEO_OUTPUT_CODEC; + m_pCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO; + m_pCodecCtx->pix_fmt = VIDEO_OUTPUT_PIX_FMT; + m_pCodecCtx->bit_rate = VIDEO_OUTPUT_BITRATE; + // m_pCodecCtx->thread_count = 1; + // m_pCodecCtx->bit_rate_tolerance = 1; + // m_pCodecCtx->global_quality = 100; + // m_pCodecCtx->compression_level = 2; + m_pCodecCtx->max_b_frames = 1; + m_pCodecCtx->width = m_pMaster->m_sEmbedVideoData.width; + m_pCodecCtx->height = m_pMaster->m_sEmbedVideoData.height; + m_pCodecCtx->time_base.num = 1; + m_pCodecCtx->time_base.den = m_sStreamData.fps; + m_pCodecCtx->framerate.num = m_sStreamData.fps; + m_pCodecCtx->framerate.den = 1; + + #if (LIBAVCODEC_VERSION_MAJOR > 54) + m_pCodecCtx->codec_tag = av_codec_get_tag(m_pFormatCtx->oformat->codec_tag, VIDEO_OUTPUT_CODEC); + #endif + m_pFormatOpts = NULL; + + if ((m_pCodecCtx->codec_id == AV_CODEC_ID_H264) || (m_pCodecCtx->codec_id == AV_CODEC_ID_H265)) + { + #ifdef DEBUG_EXTRA + LOG("Begin Options!"); + #endif + if (av_dict_set(&m_pFormatOpts, "movflags", "isml+faststart+frag_keyframe+empty_moov+omit_tfhd_offset", 0) < 0) + { + LOG_ERROR("av_dict_set movflags!"); + #ifdef DEBUG_EXTRA + } else { + LOG("MOV FLAG SET!"); + #endif + }; + + // if( av_dict_set( &m_pFormatOpts, "live", "1", 0 ) < 0 ){ + // LOG_ERROR( "av_dict_set live!" ); + // }; + + // default brand is "isom", which fails on some devices + if (av_dict_set(&m_pFormatOpts, "brand", "mp42", 0) < 0) + { + LOG_ERROR("av_dict_set brand!"); + }; + // m_pCodecCtx->max_b_frames = 1; + // m_pCodecCtx->level = 31; + + m_pCodecCtx->gop_size = m_sStreamData.fps << 1; // VIDEO_OUTPUT_GOP; // emit one intra frame every X frames + /// P-frames, generated by referencing data from prev and future frames. + /// [Compression up, CPU usage up] + /// [use 3/gop] + m_pCodecCtx->max_b_frames = 5; + + /// Can be used by a P-frame(predictive, partial frame) to help define a future frame in a compressed video. + /// [use 3?5 ref per P] + m_pCodecCtx->refs = 3; + + /// Compression efficiency (slower -> better quality + higher cpu%) + /// [ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow] + /// Set this option to "ultrafast" is critical for realtime encoding + av_opt_set(m_pCodecCtx->priv_data, "preset", "ultrafast", 0); + // av_opt_set( m_pCodecCtx->priv_data, "preset", "fast", 0 ); + // av_opt_set( m_pCodecCtx->priv_data, "preset", "slow", 0 ); + + /// Compression rate (lower -> higher compression) compress to lower size, makes decoded image more noisy + /// Range: [0; 51], sane range: [18; 26]. I used 35 as good compression/quality compromise. This option also critical for realtime encoding + av_opt_set(m_pCodecCtx->priv_data, "crf", "32", 0); + + /// Change settings based upon the specifics of input + /// [psnr, ssim, grain, zerolatency, fastdecode, animation] + /// This option is most critical for realtime encoding, because it removes delay between 1th input frame and 1th output packet. + av_opt_set(m_pCodecCtx->priv_data, "tune", "zerolatency", 0); + + /// Disable b-pyramid. CLI options for this is "-b-pyramid 0" + /// Because Quicktime (ie. iOS) doesn't support this option + av_opt_set(m_pCodecCtx->priv_data, "b-pyramid", "0", 0); + #ifdef DEBUG_EXTRA + LOG("End Options!"); + #endif + } else { + if (m_pFormat->flags & AVFMT_GLOBALHEADER) + { + m_pCodecCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; + } + }; + + const AVRational dst_fps = {m_sStreamData.fps, 1}; + + #ifdef DEBUG_EXTRA + char TB[129]; + sprintf(TB, "TimeBase: num[%d]/den[%d]", m_pCodecCtx->time_base.num, m_pCodecCtx->time_base.den); + LOG(TB); + #endif + m_pVideoStr->time_base = m_pCodecCtx->time_base; + + // avcodec_get_context_defaults3( m_pVideoStr->codec, m_pVideoCodec ); + + // m_pVideoStr->codec->width = m_pMaster->m_sEmbedVideoData.width; + // m_pVideoStr->codec->height = m_pMaster->m_sEmbedVideoData.height; + // m_pVideoStr->codec->pix_fmt = VIDEO_OUTPUT_PIX_FMT; + // m_pVideoStr->codec->time_base = m_pVideoStrB->time_base = av_inv_q(dst_fps); + m_pVideoStr->r_frame_rate = dst_fps; + // if ( m_pFormatCtx->oformat->flags & AVFMT_GLOBALHEADER ) m_pVideoStr->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; + avcodec_parameters_from_context(m_pVideoStr->codecpar, m_pCodecCtx); + // m_pVideoStr->codecpar->format = VIDEO_OUTPUT_PIX_FMT; + // m_pVideoStr->codecpar->extradata = m_pCodecCtx->extradata; + // m_pVideoStr->codecpar->extradata_size = m_pCodecCtx->extradata_size; + if (avcodec_is_open(m_pCodecCtx) == 0) + { + LOG("output codec context is closed, opening"); + if (avcodec_open2(m_pCodecCtx, m_pVideoCodec, NULL) < 0) + { + LOG_ERROR("Error opening2 encoder"); + return false; + #ifdef DEBUG_EXTRA + } else { + LOG("output codec context is opened"); + #endif + }; + #ifdef DEBUG_EXTRA + } else { + LOG("output codec context is already opened"); + #endif + }; + #endif // SEPARATED_VIDEO_ENCODERS + m_pConvertCtx = + sws_getContext(m_pMaster->m_sEmbedVideoData.width, m_pMaster->m_sEmbedVideoData.height, AV_PIX_FMT_BGR24, m_pMaster->m_sEmbedVideoData.width, m_pMaster->m_sEmbedVideoData.height, VIDEO_OUTPUT_PIX_FMT, SWS_FAST_BILINEAR, NULL, NULL, NULL); + if (m_pConvertCtx == NULL) + { + return false; + } + m_pAVFrame = av_frame_alloc(); + if (m_pAVFrame == NULL) + { + return false; + }; + m_pOutBuffer = (uint8_t *) av_malloc(av_image_get_buffer_size(VIDEO_OUTPUT_PIX_FMT, m_pMaster->m_sEmbedVideoData.width, m_pMaster->m_sEmbedVideoData.height, BUFFER_ALIGN)); + if (m_pOutBuffer == NULL) + { + return false; + }; + m_pAVFrame->width = m_pMaster->m_sEmbedVideoData.width; + m_pAVFrame->height = m_pMaster->m_sEmbedVideoData.height; + m_pAVFrame->format = VIDEO_OUTPUT_PIX_FMT; + // av_frame_get_buffer( m_pAVFrame, 0 ); + av_image_fill_arrays(m_pAVFrame->data, m_pAVFrame->linesize, m_pOutBuffer, VIDEO_OUTPUT_PIX_FMT, m_pMaster->m_sEmbedVideoData.width, m_pMaster->m_sEmbedVideoData.height, 1); + + // av_frame_make_writable( m_pAVFrame ); + #endif // !OPENCV_VIDEO_OUTPUT + #endif // !DIRECT_MJPEG_COMPOSING + return init(); + } + #else // !EVE_SEQUENTAL_OUTPUT + void streamHandler::closeSegmentA(void) + { + m_mCurrentOperationProtector.lock(); + if (m_bCOP == 0) + { + m_bCOP = 0x01; + } + m_mCurrentOperationProtector.unlock(); + #ifdef DEBUG_EXTRA + LOG("Closing Stream A"); + #endif + } + + void streamHandler::closeSegmentB(void) + { + m_mCurrentOperationProtector.lock(); + if (m_bCOP == 0) + { + m_bCOP = 0x02; + } + m_mCurrentOperationProtector.unlock(); + #ifdef DEBUG_EXTRA + LOG("Closing Stream B"); + #endif + } + + void streamHandler::closeAll() + { + waitThreadEnd(true); + #ifdef OPENCV_VIDEO_OUTPUT + if (m_pEncoderA) + { + if (m_pEncoderA->isOpened()) + { + m_pEncoderA->release(); + }; + delete(m_pEncoderA); + }; + if (m_pEncoderB) + { + if (m_pEncoderB->isOpened()) + { + m_pEncoderB->release(); + }; + delete(m_pEncoderB); + }; + #else // !OPENCV_VIDEO_OUTPUT + #ifdef DIRECT_MJPEG_COMPOSING + if (m_pOutputFD[0]) + { + fclose(m_pOutputFD[0]); + m_pOutputFD[0] = NULL; + }; + if (m_pOutputFD[1]) + { + fclose(m_pOutputFD[1]); + m_pOutputFD[1] = NULL; + }; + #else // ! DIRECT_MJPEG_COMPOSING + #ifdef SEPARATED_VIDEO_ENCODERS + if ((m_pCodecACtx != NULL || m_pCodecBCtx != NULL) && (m_bSegAActive || m_bSegBActive)) + { + if (m_pCodecACtx != NULL) + { + avcodec_send_frame(m_pCodecACtx, NULL); + int ret = 0; + AVPacket * avp = av_packet_alloc(); + if (avp) + { + do + { + av_packet_unref(avp); + ret = avcodec_receive_packet(m_pCodecACtx, avp); + if (! ret) + { + if (m_bSegAActive) + { + av_write_frame(m_pFormatCtxA, avp); + } + }; + } + while (! ret); + av_packet_unref(avp); + av_packet_free(&avp); + }; + }; + if (m_pCodecBCtx != NULL) + { + avcodec_send_frame(m_pCodecBCtx, NULL); + int ret = 0; + AVPacket * avp = av_packet_alloc(); + if (avp) + { + do + { + av_packet_unref(avp); + ret = avcodec_receive_packet(m_pCodecBCtx, avp); + if (! ret) + { + if (m_bSegBActive) + { + av_write_frame(m_pFormatCtxB, avp); + } + }; + } + while (! ret); + av_packet_unref(avp); + av_packet_free(&avp); + }; + }; + if (m_bSegAActive) + { + av_write_trailer(m_pFormatCtxA); + avformat_close_input(&m_pFormatCtxA); + m_bSegAActive = false; + }; + if (m_bSegBActive) + { + av_write_trailer(m_pFormatCtxB); + avformat_close_input(&m_pFormatCtxB); + m_bSegBActive = false; + }; + }; + #else // !SEPARATED_VIDEO_ENCODERS + if (m_pCodecCtx != NULL && (m_bSegAActive || m_bSegBActive)) + { + avcodec_send_frame(m_pCodecCtx, NULL); + int ret = 0; + AVPacket * avp = av_packet_alloc(); + if (avp) + { + do + { + av_packet_unref(avp); + ret = avcodec_receive_packet(m_pCodecCtx, avp); + if (! ret) + { + if (m_bSegAActive) + { + av_write_frame(m_pFormatCtxA, avp); + } + if (m_bSegBActive) + { + av_write_frame(m_pFormatCtxB, avp); + } + }; + } + while (! ret); + av_packet_unref(avp); + av_packet_free(&avp); + }; + if (m_bSegAActive) + { + av_write_trailer(m_pFormatCtxA); + avformat_close_input(&m_pFormatCtxA); + m_bSegAActive = false; + }; + if (m_bSegBActive) + { + av_write_trailer(m_pFormatCtxB); + avformat_close_input(&m_pFormatCtxB); + m_bSegBActive = false; + }; + }; + #endif // !SEPARATED_VIDEO_ENCODERS + #endif // !DIRECT_MJPEG_COMPOSING + // if( m_pFormat != NULL ) { + // av_free( m_pFormat ); + //}; + #endif // OPENCV_VIDEO_OUTPUT + } + bool streamHandler::openSegmentA(void) + { + if (! m_bSegAActive) + { + CSTR tAM = getUniqID_MD5(); + if (tAM) + { + sprintf(m_sStreamSegmentInfo[0].scratchPath, "%s/%s.%s", m_pVideoScratchPath, tAM, VIDEO_OUTPUT_CONTAINER); + strncpy(m_sStreamSegmentInfo[0].recordMD5, tAM, 32); + m_sStreamSegmentInfo[0].recordMD5[32] = (char) 0; + free(tAM); + m_sStreamSegmentInfo[0].stream_id = m_sStreamData.id; + PF_TIMESTAMP ts; + getPFTS(&ts); + m_sStreamSegmentInfo[0].streamTSS = ts.seconds; + m_sStreamSegmentInfo[0].streamTMS = ts.milliseconds; + #ifdef DEBUG_EXTRA + char tB[128]; + sprintf(tB, "A opened %d.%d", m_sStreamSegmentInfo[0].streamTSS, m_sStreamSegmentInfo[0].streamTMS); + LOG(tB); + #endif + 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].streamHeight = m_pMaster->getHeight(); + m_sStreamSegmentInfo[0].eventIDS.clear(); + m_sStreamSegmentInfo[0].eventTSS.clear(); + m_sStreamSegmentInfo[0].eventTMS.clear(); + m_sStreamSegmentInfo[0].eventFrames.clear(); + m_sStreamSegmentInfo[0].dataSize = 0; + m_sStreamSegmentInfo[0].db_id = 0; + #ifdef DIRECT_MJPEG_COMPOSING + m_pOutputFD[0] = fopen(m_sStreamSegmentInfo[0].scratchPath, "wb+"); + m_nSegAFrameCounter = 0; + m_nSegAShiftFrames = 0; + m_bSegAActive = true; + m_bSegADelete = true; + #else // !DIRECT_MJPEG_COMPOSING + #ifdef OPENCV_VIDEO_OUTPUT + if (m_pEncoderA) + { + // int fourcc = cv::VideoWriter::fourcc('H', '2', '6', '4'); + int fourcc =cv::VideoWriter::fourcc('a', 'v', 'c', '1'); + // int fourcc = cv::VideoWriter::fourcc('M', 'J', 'P', 'G'); + double fps = m_sStreamData.fps; + cv::String mn(m_sStreamSegmentInfo[0].scratchPath); + cv::Size fz(m_sStreamData.width, m_sStreamData.height); + // open (const String &filename, int fourcc, double fps, Size frameSize, bool isColor=true) + if (! m_pEncoderA->open(mn, fourcc, fps, fz)) + { + LOG_ERROR("Cannot Open Output Segment A!"); + return false; + #ifdef DEBUG_EXTRA + } + else + { + char tB[256]; + sprintf(tB, "VideoStream A is Created [%s] %.2f fps", m_sStreamSegmentInfo[0].scratchPath, fps); + LOG(tB); + #endif + }; + m_bSegAActive = true; + m_bSegADelete = true; + m_nSegAFrameCounter = 0; + m_nSegAShiftFrames = 0; + } + else + { + LOG_ERROR("No Encoder(A) Object!"); + return false; + }; + #else // !OPENCV_VIDEO_OUTPUT + // Check if Encoder is Ready + if (m_pFormat == NULL) + { + return false; + } + + #ifdef SEPARATED_VIDEO_ENCODERS + if (avformat_alloc_output_context2(&m_pFormatCtxA, m_pFormat, NULL, "test." VIDEO_OUTPUT_CONTAINER) < 0) + { + LOG_ERROR("Format CTX A alloc error!"); + return false; + } + else + { + av_dict_set(&m_pFormatCtxA->metadata, "Author", "Argus Sec. System", 0); + m_pFormatCtxA->flags |= AVFMT_NOTIMESTAMPS | AVFMT_TS_NONSTRICT; + }; + + m_pVideoStrA = avformat_new_stream(m_pFormatCtxA, m_pVideoACodec); + if (m_pVideoStrA == NULL) + { + avformat_free_context(m_pFormatCtxA); + return false; + #ifdef DEBUG_EXTRA + } + else + { + LOG("VideoStream A is Created"); + #endif + }; + const AVRational dst_fps = {m_sStreamData.fps, 1}; + m_pVideoStrA->r_frame_rate = m_pVideoStrA->avg_frame_rate = dst_fps; + m_pVideoStrA->time_base = m_pCodecACtx->time_base; + avcodec_parameters_from_context(m_pVideoStrA->codecpar, m_pCodecACtx); + #ifdef DEBUG_EXTRA + LOG("Opening Stream A"); + LOG(m_cSegNameA); + char tB[128]; + sprintf(tB, "FFPTS:%llu FNUM:%llu S2KF:%llu", m_pVideoStrA->start_time, m_pVideoStrA->nb_frames, m_pVideoStrA->first_dts); + LOG(tB); + sprintf(tB, "CON ST:%llu DUR:%llu", m_pFormatCtxA->start_time, m_pFormatCtxA->duration); + LOG(tB); + #endif + // if (avio_open(&m_pFormatCtxA->pb, m_cSegNameA, AVIO_FLAG_WRITE) < 0) { + if (avio_open(&m_pFormatCtxA->pb, m_sStreamSegmentInfo[0].scratchPath, AVIO_FLAG_WRITE) < 0) + { + LOG_ERROR("Could not open output file."); + return m_bSegAActive; + }; + if (avformat_write_header(m_pFormatCtxA, &m_pFormatOpts) < 0) + { + LOG_ERROR("Error occurred when writing header to output file."); + return m_bSegAActive; + }; + // m_mFrameCounterProtector.lock(); + m_nSegAFrameCounter = 0; + m_nSegAShiftFrames = 0; + m_bSegAActive = true; + m_bSegADelete = true; + // m_mFrameCounterProtector.unlock(); + #else // SEPARATED_VIDEO_ENCODERS + m_nSegASkippedFrames = m_pVideoStrA->nb_frames + 1; + if (m_pVideoStrA->nb_frames) + { + m_pVideoStrA->nb_frames = 0; + m_pVideoStrA->start_time = 0; + m_pVideoStrA->first_dts = 0; + m_pFormatCtxA->start_time = 0; + }; + #ifdef DEBUG_EXTRA + LOG("Opening Stream A"); + LOG(m_cSegNameA); + char tB[128]; + sprintf(tB, "FFPTS:%llu FNUM:%llu S2KF:%llu", m_pVideoStrA->start_time, m_pVideoStrA->nb_frames, m_pVideoStrA->first_dts); + LOG(tB); + sprintf(tB, "CON ST:%llu DUR:%llu", m_pFormatCtxA->start_time, m_pFormatCtxA->duration); + LOG(tB); + #endif + if (avio_open(&m_pFormatCtxA->pb, m_cSegNameA, AVIO_FLAG_WRITE) < 0) + { + LOG_ERROR("Could not open output file."); + return m_bSegAActive; + }; + if (avformat_write_header(m_pFormatCtxA, &m_pFormatOpts) < 0) + { + LOG_ERROR("Error occurred when writing header to output file."); + return m_bSegAActive; + }; + // m_mFrameCounterProtector.lock(); + m_nSegAFrameCounter = 0; + m_nSegAShiftFrames = 0; + m_bSegAActive = true; + m_bSegADelete = true; + // m_mFrameCounterProtector.unlock(); + #endif // SEPARATED_VIDEO_ENCODERS + #ifdef DEBUG_EXTRA + LOG("Stream A Opened"); + #endif + #endif // !OPENCV_VIDEO_OUTPUT + #endif // !DIRECT_MJPEG_COMPOSING + }; + }; + return m_bSegAActive; + } + + bool streamHandler::openSegmentB(void) + { + if (! m_bSegBActive) + { + CSTR tAM = getUniqID_MD5(); + if (tAM) + { + sprintf(m_sStreamSegmentInfo[1].scratchPath, "%s/%s.%s", m_pVideoScratchPath, tAM, VIDEO_OUTPUT_CONTAINER); + strncpy(m_sStreamSegmentInfo[1].recordMD5, tAM, 32); + m_sStreamSegmentInfo[1].recordMD5[32] = (char) 0; + free(tAM); + m_sStreamSegmentInfo[1].stream_id = m_sStreamData.id; + PF_TIMESTAMP ts; + getPFTS(&ts); + m_sStreamSegmentInfo[1].streamTSS = ts.seconds; + m_sStreamSegmentInfo[1].streamTMS = ts.milliseconds; + #ifdef DEBUG_EXTRA + char tB[128]; + sprintf(tB, "B opened %d.%d", m_sStreamSegmentInfo[1].streamTSS, m_sStreamSegmentInfo[1].streamTMS); + LOG(tB); + #endif + strncpy(m_sStreamSegmentInfo[1].recordEXT, VIDEO_OUTPUT_CONTAINER, 6); + m_sStreamSegmentInfo[1].streamFPS = m_sStreamData.fps; + m_sStreamSegmentInfo[1].streamWidth = m_pMaster->getWidh(); + m_sStreamSegmentInfo[1].streamHeight = m_pMaster->getHeight(); + m_sStreamSegmentInfo[1].eventIDS.clear(); + m_sStreamSegmentInfo[1].eventTSS.clear(); + m_sStreamSegmentInfo[1].eventTMS.clear(); + m_sStreamSegmentInfo[1].eventFrames.clear(); + m_sStreamSegmentInfo[1].dataSize = 0; + m_sStreamSegmentInfo[1].db_id = 0; + + #ifdef DIRECT_MJPEG_COMPOSING + m_pOutputFD[1] = fopen(m_sStreamSegmentInfo[1].scratchPath, "wb+"); + m_nSegBFrameCounter = 0; + m_nSegBShiftFrames = 0; + m_bSegBActive = true; + m_bSegBDelete = true; + #else // !DIRECT_MJPEG_COMPOSING + #ifdef OPENCV_VIDEO_OUTPUT + if (m_pEncoderB) + { + // int fourcc = cv::VideoWriter::fourcc('H', '2', '6', '4'); + int fourcc =cv::VideoWriter::fourcc('a', 'v', 'c', '1'); + //int fourcc = cv::VideoWriter::fourcc('M', 'J', 'P', 'G'); + double fps = m_sStreamData.fps; + cv::String mn(m_sStreamSegmentInfo[1].scratchPath); + cv::Size fz(m_sStreamData.width, m_sStreamData.height); + // open (const String &filename, int fourcc, double fps, Size frameSize, bool isColor=true) + if (! m_pEncoderB->open(mn, fourcc, fps, fz)) + { + LOG_ERROR("Cannot Open Output Segment B!"); + return false; + #ifdef DEBUG_EXTRA + } + else + { + char tB[256]; + sprintf(tB, "VideoStream B is Created [%s] %.2f fps", m_sStreamSegmentInfo[1].scratchPath, fps); + LOG(tB); + #endif + }; + m_bSegBActive = true; + m_bSegBDelete = true; + m_nSegBFrameCounter = 0; + m_nSegBShiftFrames = 0; + } + else + { + LOG_ERROR("No Encoder(B) Object!"); + return false; + }; + #else // !OPENCV + // Check if Encoder is Ready + if (m_pFormat == NULL) + { + return false; + } + #ifdef SEPARATED_VIDEO_ENCODERS + if (avformat_alloc_output_context2(&m_pFormatCtxB, m_pFormat, NULL, "test." VIDEO_OUTPUT_CONTAINER) < 0) + { + LOG_ERROR("Format CTX B alloc error!"); + return false; + } + else + { + av_dict_set(&m_pFormatCtxB->metadata, "Author", "Argus Sec. System", 0); + m_pFormatCtxB->flags |= AVFMT_NOTIMESTAMPS | AVFMT_TS_NONSTRICT; + }; + + m_pVideoStrB = avformat_new_stream(m_pFormatCtxB, m_pVideoBCodec); + if (m_pVideoStrB == NULL) + { + avformat_free_context(m_pFormatCtxB); + return false; + #ifdef DEBUG_EXTRA + } + else + { + LOG("VideoStream B is Created"); + #endif + }; + const AVRational dst_fps = {m_sStreamData.fps, 1}; + m_pVideoStrB->r_frame_rate = m_pVideoStrB->avg_frame_rate = dst_fps; + m_pVideoStrB->time_base = m_pCodecBCtx->time_base; + avcodec_parameters_from_context(m_pVideoStrB->codecpar, m_pCodecBCtx); + #ifdef DEBUG_EXTRA + LOG("Opening Stream B"); + LOG(m_cSegNameB); + char tB[128]; + sprintf(tB, "FFPTS:%llu FNUM:%llu S2KF:%llu", m_pVideoStrB->start_time, m_pVideoStrB->nb_frames, m_pVideoStrB->first_dts); + LOG(tB); + sprintf(tB, "CON ST:%llu DUR:%llu", m_pFormatCtxB->start_time, m_pFormatCtxB->duration); + LOG(tB); + #endif + + // if ( avio_open( &m_pFormatCtxB->pb, m_cSegNameB, AVIO_FLAG_WRITE ) < 0 ){ + if (avio_open(&m_pFormatCtxB->pb, m_sStreamSegmentInfo[1].scratchPath, AVIO_FLAG_WRITE) < 0) + { + LOG_ERROR("Could not open output file."); + avformat_free_context(m_pFormatCtxB); + return false; + }; + if (avformat_write_header(m_pFormatCtxB, &m_pFormatOpts) < 0) + { + LOG_ERROR("Error occurred when writing header to output file."); + avio_close(m_pFormatCtxB->pb); + avformat_free_context(m_pFormatCtxB); + return false; + }; + // m_mFrameCounterProtector.lock(); + m_nSegBFrameCounter = 0; + m_nSegBShiftFrames = 0; + m_bSegBActive = true; + m_bSegBDelete = true; + // m_mFrameCounterProtector.unlock(); + #else // SEPARATED_VIDEO_ENCODERS + m_nSegBSkippedFrames = m_pVideoStrB->nb_frames + 1; + if (m_pVideoStrB->nb_frames) + { + m_pVideoStrB->nb_frames = 0; + m_pVideoStrB->start_time = 0; + m_pVideoStrB->first_dts = 0; + m_pFormatCtxB->start_time = 0; + }; + if (avio_open(&m_pFormatCtxB->pb, m_cSegNameB, AVIO_FLAG_WRITE) < 0) + { + LOG_ERROR("Could not open output file."); + return m_bSegBActive; + }; + if (avformat_write_header(m_pFormatCtxB, &m_pFormatOpts) < 0) + { + LOG_ERROR("Error occurred when writing header to output file."); + return m_bSegBActive; + }; + // m_mFrameCounterProtector.lock(); + m_nSegBFrameCounter = 0; + m_nSegBShiftFrames = 0; + m_bSegBActive = true; + m_bSegBDelete = true; + // m_mFrameCounterProtector.unlock(); + #endif // SEPARATED_VIDEO_ENCODERS + #ifdef DEBUG_EXTRA + LOG("Stream B Opened"); + #endif + #endif // !OPENCV_VIDEO_OUTPUT + #endif // !DIRECT_MJPEG_COMPOSING + }; + }; + return m_bSegBActive; + } + + bool streamHandler::initVideoOutput() + { + + m_nPreAlarmFrames = (PRE_ALARM_TIME_MILSECONDS * m_sStreamData.fps) / 1000; + m_nPostAlarmFrames = (POST_ALARM_TIME_MILSECONDS * m_sStreamData.fps) / 1000; + m_nSegmentLimitFrames = (ENCODING_SEGMENT_MILSECONDS * m_sStreamData.fps) / 1000; + m_nHardLimitFrames = (ENCODING_SEGMENT_LIMIT_MILSECONDS * m_sStreamData.fps) / 1000; + + #ifndef DIRECT_MJPEG_COMPOSING + #ifdef OPENCV_VIDEO_OUTPUT + m_pEncoderA = new cv::VideoWriter(); + if (m_pEncoderA == NULL) + { + LOG_ERROR("Encoder A Create Failure!"); + return false; + }; + + //m_pEncoderA->set(cv::VIDEOWRITER_PROP_QUALITY, 10.0); + //m_pEncoderA->set(cv::VIDEOWRITER_PROP_NSTRIPES, -1.0); + + m_pEncoderB = new cv::VideoWriter(); + if (m_pEncoderA == NULL) + { + LOG_ERROR("Encoder B Create Failure!"); + return false; + }; + + //m_pEncoderB->set(cv::VIDEOWRITER_PROP_QUALITY, 10.0); + //m_pEncoderB->set(cv::VIDEOWRITER_PROP_NSTRIPES, -1.0); + + #else + if (! initLibAV()) + { + return false; + } + + m_pFormat = av_guess_format(VIDEO_OUTPUT_CONTAINER, "test." VIDEO_OUTPUT_CONTAINER, NULL); + + if (m_pFormat == NULL) + { + LOG_ERROR("Out VideoFormat Not Found!"); + return false; + #ifdef DEBUG_EXTRA + } + else + { + LOG("Output video Format"); + LOG(VIDEO_OUTPUT_CONTAINER); + #endif + }; + + #ifdef SEPARATED_VIDEO_ENCODERS + /* Stream A */ + m_pVideoACodec = avcodec_find_encoder(VIDEO_OUTPUT_CODEC); + if (m_pVideoACodec == NULL) + { + LOG_ERROR("Encoder Video Codec Not Found!"); + return false; + #ifdef DEBUG_EXTRA + } + else + { + LOG("Video Encoder A Created"); + #endif + }; + m_pCodecACtx = avcodec_alloc_context3(m_pVideoACodec); + if (m_pCodecACtx == NULL) + { + LOG_ERROR("Video Encoder A Context Memory Allocation Error!"); + av_free(m_pVideoACodec); + avformat_free_context(m_pFormatCtxA); + return false; + #ifdef DEBUG_EXTRA + } + else + { + LOG("Video Encoder Context A Allocated"); + #endif + }; + /* Stream B */ + m_pVideoBCodec = avcodec_find_encoder(VIDEO_OUTPUT_CODEC); + if (m_pVideoBCodec == NULL) + { + LOG_ERROR("Out VideoCodec Not Found!"); + av_free(m_pVideoACodec); + return false; + #ifdef DEBUG_EXTRA + } + else + { + LOG("Video Encoder B Created"); + #endif + }; + m_pCodecBCtx = avcodec_alloc_context3(m_pVideoBCodec); + if (m_pCodecBCtx == NULL) + { + LOG_ERROR("Video Encoder B Context Memory Allocation Error!"); + av_free(m_pVideoACodec); + av_free(m_pVideoBCodec); + avformat_free_context(m_pFormatCtxA); + avformat_free_context(m_pFormatCtxB); + return false; + #ifdef DEBUG_EXTRA + } + else + { + LOG("Video Encoder Context B Allocated"); + #endif + }; + + m_pCodecACtx->codec_id = VIDEO_OUTPUT_CODEC; + m_pCodecACtx->codec_type = AVMEDIA_TYPE_VIDEO; + m_pCodecACtx->pix_fmt = VIDEO_OUTPUT_PIX_FMT; + m_pCodecACtx->bit_rate = VIDEO_OUTPUT_BITRATE; + m_pCodecACtx->max_b_frames = 1; + m_pCodecACtx->width = m_pMaster->m_sEmbedVideoData.width; + m_pCodecACtx->height = m_pMaster->m_sEmbedVideoData.height; + m_pCodecACtx->time_base.num = 1; + m_pCodecACtx->time_base.den = m_sStreamData.fps; + m_pCodecACtx->framerate.num = m_sStreamData.fps; + m_pCodecACtx->framerate.den = 1; + + m_pCodecBCtx->codec_id = VIDEO_OUTPUT_CODEC; + m_pCodecBCtx->codec_type = AVMEDIA_TYPE_VIDEO; + m_pCodecBCtx->pix_fmt = VIDEO_OUTPUT_PIX_FMT; + m_pCodecBCtx->bit_rate = VIDEO_OUTPUT_BITRATE; + m_pCodecBCtx->max_b_frames = 1; + m_pCodecBCtx->width = m_pMaster->m_sEmbedVideoData.width; + m_pCodecBCtx->height = m_pMaster->m_sEmbedVideoData.height; + m_pCodecBCtx->time_base.num = 1; + m_pCodecBCtx->time_base.den = m_sStreamData.fps; + m_pCodecBCtx->framerate.num = m_sStreamData.fps; + m_pCodecBCtx->framerate.den = 1; + + // https://pastebin.com/yG37YhWW + + // https://stackoverflow.com/questions/49276997/raw-h264-frames-in-mp4-container-using-libavcodec + // G@ avcodec encode NALU mp4 + + #if (LIBAVCODEC_VERSION_MAJOR > 54) + ////m_pCodecACtx->codec_tag = av_codec_get_tag( m_pFormatCtxA->oformat->codec_tag, VIDEO_OUTPUT_CODEC ); + #endif + + #if (LIBAVCODEC_VERSION_MAJOR > 54) + ////m_pCodecBCtx->codec_tag = av_codec_get_tag( m_pFormatCtxB->oformat->codec_tag, VIDEO_OUTPUT_CODEC ); + #endif + m_pFormatOpts = NULL; + + // https://stackoverflow.com/questions/70060148/libav-producing-mp4-file-with-extremely-high-frame-rate + + if ((m_pCodecACtx->codec_id == AV_CODEC_ID_H264) || (m_pCodecACtx->codec_id == AV_CODEC_ID_H265)) + { + #ifdef DEBUG_EXTRA + LOG("Begin Options!"); + #endif + // Reference for AvFormatContext options : https://ffmpeg.org/doxygen/2.8/movenc_8c_source.html + // Set format's privater options, to be passed to avformat_write_header() + + /* + + mp4 muxer AVOptions: + -movflags E..... MOV muxer flags (default 0) + rtphint E..... Add RTP hint tracks + empty_moov E..... Make the initial moov atom empty (not supported by QuickTime) + frag_keyframe E..... Fragment at video keyframes + separate_moof E..... Write separate moof/mdat atoms for each track + frag_custom E..... Flush fragments on caller requests + isml E..... Create a live smooth streaming feed (for pushing to a publishing point) + faststart E..... Run a second pass to put the index (moov atom) at the beginning of the file + omit_tfhd_offset E..... Omit the base data offset in tfhd atoms + delay_moov ?? + -moov_size E..... maximum moov size so it can be placed at the begin (from 0 to INT_MAX) (default 0) + -rtpflags E..... RTP muxer flags (default 0) + latm E..... Use MP4A-LATM packetization instead of MPEG4-GENERIC for AAC + rfc2190 E..... Use RFC 2190 packetization instead of RFC 4629 for H.263 + skip_rtcp E..... Don't send RTCP sender reports + h264_mode0 E..... Use mode 0 for H264 in RTP + send_bye E..... Send RTCP BYE packets when finishing + -skip_iods E..... Skip writing iods atom. (from 0 to 1) (default 1) + -iods_audio_profile E..... iods audio profile atom. (from -1 to 255) (default -1) + -iods_video_profile E..... iods video profile atom. (from -1 to 255) (default -1) + -frag_duration E..... Maximum fragment duration (from 0 to INT_MAX) (default 0) + -min_frag_duration E..... Minimum fragment duration (from 0 to INT_MAX) (default 0) + -frag_size E..... Maximum fragment size (from 0 to INT_MAX) (default 0) + -ism_lookahead E..... Number of lookahead entries for ISM files (from 0 to INT_MAX) (default 0) + -use_editlist E..... use edit list (from -1 to 1) (default -1) + -video_track_timescale E..... set timescale of all video tracks (from 0 to INT_MAX) (default 0) + + + */ + if (av_dict_set(&m_pFormatOpts, "movflags", "isml+faststart+frag_keyframe+empty_moov+omit_tfhd_offset", 0) < 0) + { + LOG_ERROR("av_dict_set movflags!"); + #ifdef DEBUG_EXTRA + } + else + { + LOG("MOV FLAG SET!"); + #endif + }; + + // if( av_dict_set( &m_pFormatOpts, "live", "1", 0 ) < 0 ){ + // LOG_ERROR( "av_dict_set live!" ); + // }; + + // default brand is "isom", which fails on some devices + if (av_dict_set(&m_pFormatOpts, "brand", "mp42", 0) < 0) + { + LOG_ERROR("av_dict_set brand!"); + }; + // m_pCodecCtx->max_b_frames = 1; + // m_pCodecCtx->level = 31; + + m_pCodecACtx->gop_size = m_sStreamData.fps << 1; // VIDEO_OUTPUT_GOP; // emit one intra frame every X frames + /// P-frames, generated by referencing data from prev and future frames. + /// [Compression up, CPU usage up] + /// [use 3/gop] + m_pCodecACtx->max_b_frames = 5; + + /// Can be used by a P-frame(predictive, partial frame) to help define a future frame in a compressed video. + /// [use 3?5 ref per P] + m_pCodecACtx->refs = 3; + + /// Compression efficiency (slower -> better quality + higher cpu%) + /// [ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow] + /// Set this option to "ultrafast" is critical for realtime encoding + av_opt_set(m_pCodecACtx->priv_data, "preset", "ultrafast", 0); + // av_opt_set( m_pCodecCtx->priv_data, "preset", "fast", 0 ); + // av_opt_set( m_pCodecCtx->priv_data, "preset", "slow", 0 ); + + /// Compression rate (lower -> higher compression) compress to lower size, makes decoded image more noisy + /// Range: [0; 51], sane range: [18; 26]. I used 35 as good compression/quality compromise. This option also critical for realtime encoding + av_opt_set(m_pCodecACtx->priv_data, "crf", "32", 0); + + /// Change settings based upon the specifics of input + /// [psnr, ssim, grain, zerolatency, fastdecode, animation] + /// This option is most critical for realtime encoding, because it removes delay between 1th input frame and 1th output packet. + av_opt_set(m_pCodecACtx->priv_data, "tune", "zerolatency", 0); + + /// Disable b-pyramid. CLI options for this is "-b-pyramid 0" + /// Because Quicktime (ie. iOS) doesn't support this option + av_opt_set(m_pCodecACtx->priv_data, "b-pyramid", "0", 0); + #ifdef DEBUG_EXTRA + LOG("End Options!"); + #endif + } + else + { + if (m_pFormat->flags & AVFMT_GLOBALHEADER) + { + m_pCodecACtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; + } + }; + + if ((m_pCodecBCtx->codec_id == AV_CODEC_ID_H264) || (m_pCodecBCtx->codec_id == AV_CODEC_ID_H265)) + { + #ifdef DEBUG_EXTRA + LOG("Begin Options!"); + #endif + // Reference for AvFormatContext options : https://ffmpeg.org/doxygen/2.8/movenc_8c_source.html + // Set format's privater options, to be passed to avformat_write_header() + + /* + + mp4 muxer AVOptions: + -movflags E..... MOV muxer flags (default 0) + rtphint E..... Add RTP hint tracks + empty_moov E..... Make the initial moov atom empty (not supported by QuickTime) + frag_keyframe E..... Fragment at video keyframes + separate_moof E..... Write separate moof/mdat atoms for each track + frag_custom E..... Flush fragments on caller requests + isml E..... Create a live smooth streaming feed (for pushing to a publishing point) + faststart E..... Run a second pass to put the index (moov atom) at the beginning of the file + omit_tfhd_offset E..... Omit the base data offset in tfhd atoms + delay_moov ?? + -moov_size E..... maximum moov size so it can be placed at the begin (from 0 to INT_MAX) (default 0) + -rtpflags E..... RTP muxer flags (default 0) + latm E..... Use MP4A-LATM packetization instead of MPEG4-GENERIC for AAC + rfc2190 E..... Use RFC 2190 packetization instead of RFC 4629 for H.263 + skip_rtcp E..... Don't send RTCP sender reports + h264_mode0 E..... Use mode 0 for H264 in RTP + send_bye E..... Send RTCP BYE packets when finishing + -skip_iods E..... Skip writing iods atom. (from 0 to 1) (default 1) + -iods_audio_profile E..... iods audio profile atom. (from -1 to 255) (default -1) + -iods_video_profile E..... iods video profile atom. (from -1 to 255) (default -1) + -frag_duration E..... Maximum fragment duration (from 0 to INT_MAX) (default 0) + -min_frag_duration E..... Minimum fragment duration (from 0 to INT_MAX) (default 0) + -frag_size E..... Maximum fragment size (from 0 to INT_MAX) (default 0) + -ism_lookahead E..... Number of lookahead entries for ISM files (from 0 to INT_MAX) (default 0) + -use_editlist E..... use edit list (from -1 to 1) (default -1) + -video_track_timescale E..... set timescale of all video tracks (from 0 to INT_MAX) (default 0) + + + */ + // m_pCodecCtx->max_b_frames = 1; + // m_pCodecCtx->level = 31; + + m_pCodecBCtx->gop_size = m_sStreamData.fps << 1; // VIDEO_OUTPUT_GOP; // emit one intra frame every X frames + /// P-frames, generated by referencing data from prev and future frames. + /// [Compression up, CPU usage up] + /// [use 3/gop] + m_pCodecBCtx->max_b_frames = 5; + + /// Can be used by a P-frame(predictive, partial frame) to help define a future frame in a compressed video. + /// [use 3?5 ref per P] + m_pCodecBCtx->refs = 3; + + /// Compression efficiency (slower -> better quality + higher cpu%) + /// [ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow] + /// Set this option to "ultrafast" is critical for realtime encoding + av_opt_set(m_pCodecBCtx->priv_data, "preset", "ultrafast", 0); + // av_opt_set( m_pCodecCtx->priv_data, "preset", "fast", 0 ); + // av_opt_set( m_pCodecCtx->priv_data, "preset", "slow", 0 ); + + /// Compression rate (lower -> higher compression) compress to lower size, makes decoded image more noisy + /// Range: [0; 51], sane range: [18; 26]. I used 35 as good compression/quality compromise. This option also critical for realtime encoding + av_opt_set(m_pCodecBCtx->priv_data, "crf", "32", 0); + + /// Change settings based upon the specifics of input + /// [psnr, ssim, grain, zerolatency, fastdecode, animation] + /// This option is most critical for realtime encoding, because it removes delay between 1th input frame and 1th output packet. + av_opt_set(m_pCodecBCtx->priv_data, "tune", "zerolatency", 0); + + /// Disable b-pyramid. CLI options for this is "-b-pyramid 0" + /// Because Quicktime (ie. iOS) doesn't support this option + av_opt_set(m_pCodecBCtx->priv_data, "b-pyramid", "0", 0); + #ifdef DEBUG_EXTRA + LOG("End Options!"); + #endif + } + else + { + if (m_pFormat->flags & AVFMT_GLOBALHEADER) + { + m_pCodecBCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; + } + }; + + const AVRational dst_fps = {m_sStreamData.fps, 1}; + + #ifdef DEBUG_EXTRA + char TB[129]; + sprintf(TB, "TimeBaseA: num[%d]/den[%d]", m_pCodecACtx->time_base.num, m_pCodecACtx->time_base.den); + LOG(TB); + sprintf(TB, "TimeBaseB: num[%d]/den[%d]", m_pCodecBCtx->time_base.num, m_pCodecBCtx->time_base.den); + LOG(TB); + #endif + + ////m_pVideoStrA->time_base = m_pCodecACtx->time_base; + ////m_pVideoStrB->time_base = m_pCodecBCtx->time_base; + + // avcodec_get_context_defaults3( m_pVideoStrA->codec, m_pVideoCodec ); + + // m_pVideoStrA->codec->width = m_pMaster->m_sEmbedVideoData.width; + // m_pVideoStrA->codec->height = m_pMaster->m_sEmbedVideoData.height; + // m_pVideoStrA->codec->pix_fmt = VIDEO_OUTPUT_PIX_FMT; + // m_pVideoStrA->codec->time_base = m_pVideoStrB->time_base = av_inv_q(dst_fps); + //// m_pVideoStrA->r_frame_rate = m_pVideoStrA->avg_frame_rate = + ////dst_fps; + + // avcodec_get_context_defaults3( m_pVideoStrB->codec, m_pVideoCodec ); + + // m_pVideoStrB->codec->width = m_pMaster->m_sEmbedVideoData.width; + // m_pVideoStrB->codec->height = m_pMaster->m_sEmbedVideoData.height; + // m_pVideoStrB->codec->pix_fmt = VIDEO_OUTPUT_PIX_FMT; + // m_pVideoStrB->codec->time_base = m_pVideoStrB->time_base = av_inv_q(dst_fps); + //// m_pVideoStrB->r_frame_rate = m_pVideoStrB->avg_frame_rate = + ////dst_fps; + + // if ( m_pFormatCtxA->oformat->flags & AVFMT_GLOBALHEADER ) m_pVideoStrA->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; + // if ( m_pFormatCtxB->oformat->flags & AVFMT_GLOBALHEADER ) m_pVideoStrB->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; + + //// avcodec_parameters_from_context( m_pVideoStrA->codecpar, + ////m_pCodecACtx ); + // m_pVideoStrA->codecpar->format = VIDEO_OUTPUT_PIX_FMT; + // m_pVideoStrA->codecpar->extradata = m_pCodecCtx->extradata; + // m_pVideoStrA->codecpar->extradata_size = m_pCodecCtx->extradata_size; + + //// avcodec_parameters_from_context( m_pVideoStrB->codecpar, + ////m_pCodecBCtx ); + // m_pVideoStrB->codecpar->format = VIDEO_OUTPUT_PIX_FMT; + // m_pVideoStrB->codecpar->extradata = m_pCodecCtx->extradata; + // m_pVideoStrB->codecpar->extradata_size = m_pCodecCtx->extradata_size; + + if (avcodec_is_open(m_pCodecACtx) == 0) + { + LOG("output codec context is closed, opening"); + if (avcodec_open2(m_pCodecACtx, m_pVideoACodec, NULL) < 0) + { + LOG_ERROR("Error opening2 encoder"); + return false; + #ifdef DEBUG_EXTRA + } + else + { + LOG("output codec context is opened"); + #endif + }; + + #ifdef DEBUG_EXTRA + } + else + { + LOG("output codec context is already opened"); + #endif + }; + + if (avcodec_is_open(m_pCodecBCtx) == 0) + { + LOG("output codec context is closed, opening"); + if (avcodec_open2(m_pCodecBCtx, m_pVideoBCodec, NULL) < 0) + { + LOG_ERROR("Error opening2 encoder"); + return false; + #ifdef DEBUG_EXTRA + } + else + { + LOG("output codec context is opened"); + #endif + }; + + #ifdef DEBUG_EXTRA + } + else + { + LOG("output codec context is already opened"); + #endif + }; + #else // SEPARATED_VIDEO_ENCODERS + if (avformat_alloc_output_context2(&m_pFormatCtxA, m_pFormat, NULL, "test." VIDEO_OUTPUT_CONTAINER) < 0) + { + LOG_ERROR("Format CTX A alloc error!"); + return false; + } + else + { + av_dict_set(&m_pFormatCtxA->metadata, "Author", "Argus Sec. System", 0); + m_pFormatCtxA->flags |= AVFMT_NOTIMESTAMPS | AVFMT_TS_NONSTRICT; + }; + + if (avformat_alloc_output_context2(&m_pFormatCtxB, m_pFormat, NULL, "test." VIDEO_OUTPUT_CONTAINER) < 0) + { + LOG_ERROR("Format CTX B alloc error!"); + avformat_free_context(m_pFormatCtxA); + return false; + } + else + { + av_dict_set(&m_pFormatCtxB->metadata, "Author", "Argus Sec. System", 0); + m_pFormatCtxB->flags |= AVFMT_NOTIMESTAMPS | AVFMT_TS_NONSTRICT; + }; + m_pVideoCodec = avcodec_find_encoder(VIDEO_OUTPUT_CODEC); + if (m_pVideoCodec == NULL) + { + LOG_ERROR("Output VideoCodec Not Found!"); + avformat_free_context(m_pFormatCtxA); + avformat_free_context(m_pFormatCtxB); + return false; + #ifdef DEBUG_EXTRA + } + else + { + LOG("Output Video Codec Found"); + #endif + }; + + m_pCodecCtx = avcodec_alloc_context3(m_pVideoCodec); + if (m_pCodecCtx == NULL) + { + LOG_ERROR("Out VideoCodec Context Memory Allocation Error"); + av_free(m_pVideoCodec); + avformat_free_context(m_pFormatCtxA); + avformat_free_context(m_pFormatCtxB); + return false; + #ifdef DEBUG_EXTRA + } + else + { + LOG("Out Codec Context3 Allocated"); + #endif + }; + m_pVideoStrA = avformat_new_stream(m_pFormatCtxA, m_pVideoCodec); + if (m_pVideoStrA == NULL) + { + LOG_ERROR("VideoStream A Not Created!"); + avcodec_free_context(&m_pCodecCtx); + av_free(m_pCodecCtx); + av_free(m_pVideoCodec); + // avformat_close_input ( &m_pFormatCtxA ); + // avformat_close_input ( &m_pFormatCtxB ); + avformat_free_context(m_pFormatCtxA); + avformat_free_context(m_pFormatCtxB); + return false; + #ifdef DEBUG_EXTRA + } + else + { + LOG("VideoStream A is Created"); + #endif + }; + + m_pVideoStrB = avformat_new_stream(m_pFormatCtxB, m_pVideoCodec); + if (m_pVideoStrB == NULL) + { + LOG_ERROR("VideoStream B Not Created!"); + + avcodec_free_context(&m_pCodecCtx); + av_free(m_pCodecCtx); + av_free(m_pVideoCodec); + // avformat_close_input ( &m_pFormatCtxA ); + // avformat_close_input ( &m_pFormatCtxB ); + avformat_free_context(m_pFormatCtxA); + avformat_free_context(m_pFormatCtxB); + return false; + #ifdef DEBUG_EXTRA + } + else + { + LOG("VideoStream B is Created"); + #endif + }; + m_pCodecCtx->codec_id = VIDEO_OUTPUT_CODEC; + m_pCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO; + m_pCodecCtx->pix_fmt = VIDEO_OUTPUT_PIX_FMT; + m_pCodecCtx->bit_rate = VIDEO_OUTPUT_BITRATE; + // m_pCodecCtx->thread_count = 1; + // m_pCodecCtx->bit_rate_tolerance = 1; + // m_pCodecCtx->global_quality = 100; + // m_pCodecCtx->compression_level = 2; + m_pCodecCtx->max_b_frames = 1; + m_pCodecCtx->width = m_pMaster->m_sEmbedVideoData.width; + m_pCodecCtx->height = m_pMaster->m_sEmbedVideoData.height; + m_pCodecCtx->time_base.num = 1; + m_pCodecCtx->time_base.den = m_sStreamData.fps; + m_pCodecCtx->framerate.num = m_sStreamData.fps; + m_pCodecCtx->framerate.den = 1; + + // https://pastebin.com/yG37YhWW + + // https://stackoverflow.com/questions/49276997/raw-h264-frames-in-mp4-container-using-libavcodec + // G@ avcodec encode NALU mp4 + + #if (LIBAVCODEC_VERSION_MAJOR > 54) + m_pCodecCtx->codec_tag = av_codec_get_tag(m_pFormatCtxA->oformat->codec_tag, VIDEO_OUTPUT_CODEC); + #endif + m_pFormatOpts = NULL; + + // https://stackoverflow.com/questions/70060148/libav-producing-mp4-file-with-extremely-high-frame-rate + + if ((m_pCodecCtx->codec_id == AV_CODEC_ID_H264) || (m_pCodecCtx->codec_id == AV_CODEC_ID_H265)) + { + #ifdef DEBUG_EXTRA + LOG("Begin Options!"); + #endif + // Reference for AvFormatContext options : https://ffmpeg.org/doxygen/2.8/movenc_8c_source.html + // Set format's privater options, to be passed to avformat_write_header() + + /* + + mp4 muxer AVOptions: + -movflags E..... MOV muxer flags (default 0) + rtphint E..... Add RTP hint tracks + empty_moov E..... Make the initial moov atom empty (not supported by QuickTime) + frag_keyframe E..... Fragment at video keyframes + separate_moof E..... Write separate moof/mdat atoms for each track + frag_custom E..... Flush fragments on caller requests + isml E..... Create a live smooth streaming feed (for pushing to a publishing point) + faststart E..... Run a second pass to put the index (moov atom) at the beginning of the file + omit_tfhd_offset E..... Omit the base data offset in tfhd atoms + delay_moov ?? + -moov_size E..... maximum moov size so it can be placed at the begin (from 0 to INT_MAX) (default 0) + -rtpflags E..... RTP muxer flags (default 0) + latm E..... Use MP4A-LATM packetization instead of MPEG4-GENERIC for AAC + rfc2190 E..... Use RFC 2190 packetization instead of RFC 4629 for H.263 + skip_rtcp E..... Don't send RTCP sender reports + h264_mode0 E..... Use mode 0 for H264 in RTP + send_bye E..... Send RTCP BYE packets when finishing + -skip_iods E..... Skip writing iods atom. (from 0 to 1) (default 1) + -iods_audio_profile E..... iods audio profile atom. (from -1 to 255) (default -1) + -iods_video_profile E..... iods video profile atom. (from -1 to 255) (default -1) + -frag_duration E..... Maximum fragment duration (from 0 to INT_MAX) (default 0) + -min_frag_duration E..... Minimum fragment duration (from 0 to INT_MAX) (default 0) + -frag_size E..... Maximum fragment size (from 0 to INT_MAX) (default 0) + -ism_lookahead E..... Number of lookahead entries for ISM files (from 0 to INT_MAX) (default 0) + -use_editlist E..... use edit list (from -1 to 1) (default -1) + -video_track_timescale E..... set timescale of all video tracks (from 0 to INT_MAX) (default 0) + + + */ + if (av_dict_set(&m_pFormatOpts, "movflags", "isml+faststart+frag_keyframe+empty_moov+omit_tfhd_offset", 0) < 0) + { + LOG_ERROR("av_dict_set movflags!"); + #ifdef DEBUG_EXTRA + } + else + { + LOG("MOV FLAG SET!"); + #endif + }; + + // if( av_dict_set( &m_pFormatOpts, "live", "1", 0 ) < 0 ){ + // LOG_ERROR( "av_dict_set live!" ); + // }; + + // default brand is "isom", which fails on some devices + if (av_dict_set(&m_pFormatOpts, "brand", "mp42", 0) < 0) + { + LOG_ERROR("av_dict_set brand!"); + }; + // m_pCodecCtx->max_b_frames = 1; + // m_pCodecCtx->level = 31; + + m_pCodecCtx->gop_size = m_sStreamData.fps << 1; // VIDEO_OUTPUT_GOP; // emit one intra frame every X frames + /// P-frames, generated by referencing data from prev and future frames. + /// [Compression up, CPU usage up] + /// [use 3/gop] + m_pCodecCtx->max_b_frames = 5; + + /// Can be used by a P-frame(predictive, partial frame) to help define a future frame in a compressed video. + /// [use 3?5 ref per P] + m_pCodecCtx->refs = 3; + + /// Compression efficiency (slower -> better quality + higher cpu%) + /// [ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow] + /// Set this option to "ultrafast" is critical for realtime encoding + av_opt_set(m_pCodecCtx->priv_data, "preset", "ultrafast", 0); + // av_opt_set( m_pCodecCtx->priv_data, "preset", "fast", 0 ); + // av_opt_set( m_pCodecCtx->priv_data, "preset", "slow", 0 ); + + /// Compression rate (lower -> higher compression) compress to lower size, makes decoded image more noisy + /// Range: [0; 51], sane range: [18; 26]. I used 35 as good compression/quality compromise. This option also critical for realtime encoding + av_opt_set(m_pCodecCtx->priv_data, "crf", "32", 0); + + /// Change settings based upon the specifics of input + /// [psnr, ssim, grain, zerolatency, fastdecode, animation] + /// This option is most critical for realtime encoding, because it removes delay between 1th input frame and 1th output packet. + av_opt_set(m_pCodecCtx->priv_data, "tune", "zerolatency", 0); + + /// Disable b-pyramid. CLI options for this is "-b-pyramid 0" + /// Because Quicktime (ie. iOS) doesn't support this option + av_opt_set(m_pCodecCtx->priv_data, "b-pyramid", "0", 0); + #ifdef DEBUG_EXTRA + LOG("End Options!"); + #endif + } + else + { + if (m_pFormat->flags & AVFMT_GLOBALHEADER) + { + m_pCodecCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; + } + }; + + const AVRational dst_fps = {m_sStreamData.fps, 1}; + + #ifdef DEBUG_EXTRA + char TB[129]; + sprintf(TB, "TimeBase: num[%d]/den[%d]", m_pCodecCtx->time_base.num, m_pCodecCtx->time_base.den); + LOG(TB); + #endif + + m_pVideoStrA->time_base = m_pCodecCtx->time_base; + m_pVideoStrB->time_base = m_pCodecCtx->time_base; + + // avcodec_get_context_defaults3( m_pVideoStrA->codec, m_pVideoCodec ); + + // m_pVideoStrA->codec->width = m_pMaster->m_sEmbedVideoData.width; + // m_pVideoStrA->codec->height = m_pMaster->m_sEmbedVideoData.height; + // m_pVideoStrA->codec->pix_fmt = VIDEO_OUTPUT_PIX_FMT; + // m_pVideoStrA->codec->time_base = m_pVideoStrB->time_base = av_inv_q(dst_fps); + m_pVideoStrA->r_frame_rate = m_pVideoStrB->avg_frame_rate = dst_fps; + + // avcodec_get_context_defaults3( m_pVideoStrB->codec, m_pVideoCodec ); + + // m_pVideoStrB->codec->width = m_pMaster->m_sEmbedVideoData.width; + // m_pVideoStrB->codec->height = m_pMaster->m_sEmbedVideoData.height; + // m_pVideoStrB->codec->pix_fmt = VIDEO_OUTPUT_PIX_FMT; + // m_pVideoStrB->codec->time_base = m_pVideoStrB->time_base = av_inv_q(dst_fps); + m_pVideoStrB->r_frame_rate = m_pVideoStrB->avg_frame_rate = dst_fps; + + // if ( m_pFormatCtxA->oformat->flags & AVFMT_GLOBALHEADER ) m_pVideoStrA->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; + // if ( m_pFormatCtxB->oformat->flags & AVFMT_GLOBALHEADER ) m_pVideoStrB->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; + + avcodec_parameters_from_context(m_pVideoStrA->codecpar, m_pCodecCtx); + // m_pVideoStrA->codecpar->format = VIDEO_OUTPUT_PIX_FMT; + // m_pVideoStrA->codecpar->extradata = m_pCodecCtx->extradata; + // m_pVideoStrA->codecpar->extradata_size = m_pCodecCtx->extradata_size; + + avcodec_parameters_from_context(m_pVideoStrB->codecpar, m_pCodecCtx); + // m_pVideoStrB->codecpar->format = VIDEO_OUTPUT_PIX_FMT; + // m_pVideoStrB->codecpar->extradata = m_pCodecCtx->extradata; + // m_pVideoStrB->codecpar->extradata_size = m_pCodecCtx->extradata_size; + + if (avcodec_is_open(m_pCodecCtx) == 0) + { + LOG("output codec context is closed, opening"); + if (avcodec_open2(m_pCodecCtx, m_pVideoCodec, NULL) < 0) + { + LOG_ERROR("Error opening2 encoder"); + return false; + #ifdef DEBUG_EXTRA + } + else + { + LOG("output codec context is opened"); + #endif + }; + + #ifdef DEBUG_EXTRA + } + else + { + LOG("output codec context is already opened"); + #endif + }; + #endif // SEPARATED_VIDEO_ENCODERS + m_pConvertCtx = + sws_getContext(m_pMaster->m_sEmbedVideoData.width, m_pMaster->m_sEmbedVideoData.height, AV_PIX_FMT_BGR24, m_pMaster->m_sEmbedVideoData.width, m_pMaster->m_sEmbedVideoData.height, VIDEO_OUTPUT_PIX_FMT, SWS_FAST_BILINEAR, NULL, NULL, NULL); + if (m_pConvertCtx == NULL) + { + return false; + } + m_pAVFrame = av_frame_alloc(); + if (m_pAVFrame == NULL) + { + return false; + }; + m_pOutBuffer = (uint8_t *) av_malloc(av_image_get_buffer_size(VIDEO_OUTPUT_PIX_FMT, m_pMaster->m_sEmbedVideoData.width, m_pMaster->m_sEmbedVideoData.height, BUFFER_ALIGN)); + if (m_pOutBuffer == NULL) + { + return false; + }; + m_pAVFrame->width = m_pMaster->m_sEmbedVideoData.width; + m_pAVFrame->height = m_pMaster->m_sEmbedVideoData.height; + m_pAVFrame->format = VIDEO_OUTPUT_PIX_FMT; + // av_frame_get_buffer( m_pAVFrame, 0 ); + av_image_fill_arrays(m_pAVFrame->data, m_pAVFrame->linesize, m_pOutBuffer, VIDEO_OUTPUT_PIX_FMT, m_pMaster->m_sEmbedVideoData.width, m_pMaster->m_sEmbedVideoData.height, 1); + + // av_frame_make_writable( m_pAVFrame ); + #endif // !OPENCV_VIDEO_OUTPUT + #endif // !DIRECT_MJPEG_COMPOSING + return init(); + } +#endif // !EVE_SEQUENTAL_OUTPUT + + // encoding thread + + void streamHandler::m_fThreadProc(void) + { + size_t nQueueSize; + #ifndef DIRECT_MJPEG_COMPOSING + #ifndef OPENCV_VIDEO_OUTPUT + AVPacket mPacket; + int bGotPacket; + int rVal = 0; + av_init_packet(&mPacket); + #endif + #endif + pthread_setname_np(pthread_self(), "VideoStream"); + while (m_bThreadStatus != TH_ENDED) + { + // At the begining All streams are closed --> try to Open + if (m_bThreadStatus < TH_WORKING){ + #ifdef EVE_SEQUENTAL_OUTPUT + CSTR tAM = getUniqID_MD5(); + if( tAM ){ + sprintf(m_sStreamSegmentInfo.scratchPath, "%s/%s.%s", m_pVideoScratchPath, tAM, VIDEO_OUTPUT_CONTAINER); + strncpy(m_sStreamSegmentInfo.recordMD5, tAM, 32); + m_sStreamSegmentInfo.recordMD5[32] = (char) 0; + free(tAM); + m_sStreamSegmentInfo.stream_id = m_sStreamData.id; + PF_TIMESTAMP ts; + getPFTS(&ts); + m_sStreamSegmentInfo.streamTSS = ts.seconds; + m_sStreamSegmentInfo.streamTMS = ts.milliseconds; + #ifdef DEBUG_EXTRA + char tB[128]; + sprintf(tB, "First Time opened %d.%d", m_sStreamSegmentInfo.streamTSS, m_sStreamSegmentInfo.streamTMS); + LOG(tB); + #endif + strncpy(m_sStreamSegmentInfo.recordEXT, VIDEO_OUTPUT_CONTAINER, 6); + m_sStreamSegmentInfo.streamFPS = m_sStreamData.fps; + m_sStreamSegmentInfo.streamWidth = m_pMaster->getWidh(); + m_sStreamSegmentInfo.streamHeight = m_pMaster->getHeight(); + m_sStreamSegmentInfo.eventIDS.clear(); + m_sStreamSegmentInfo.eventTSS.clear(); + m_sStreamSegmentInfo.eventTMS.clear(); + m_sStreamSegmentInfo.eventFrames.clear(); + m_sStreamSegmentInfo.dataSize = 0; + m_sStreamSegmentInfo.db_id = 0; + #ifdef DIRECT_MJPEG_COMPOSING + m_pOutputFD = fopen(m_sStreamSegmentInfo.scratchPath, "wb+"); + m_nSegFrameCounter = 0; + m_nSegShiftFrames = 0; + m_bSegActive = true; + m_bSegDelete = m_bNSegDelete; + m_bNSegDelete = true; + #else // !DIRECT_MJPEG_COMPOSING + #ifdef OPENCV_VIDEO_OUTPUT + if ( m_pEncoder ){ + //int fourcc = cv::VideoWriter::fourcc('H', '2', '6', '4'); + int fourcc =cv::VideoWriter::fourcc('a', 'v', 'c', '1'); + //int fourcc = cv::VideoWriter::fourcc('M', 'J', 'P', 'G'); + double fps = m_sStreamData.fps; + cv::String mn(m_sStreamSegmentInfo.scratchPath); + cv::Size fz(m_sStreamData.width, m_sStreamData.height); + // open (const String &filename, int fourcc, double fps, Size frameSize, bool isColor=true) + if (! m_pEncoder->open(mn, fourcc, fps, fz) ) { + LOG_ERROR("Cannot Open Output VideoStream!"); + m_bThreadStatus = TH_ENDED; + continue; + #ifdef DEBUG_EXTRA + } else { + char tB[256]; + sprintf(tB, "VideoStream is Created [%s] %.2f fps", m_sStreamSegmentInfo.scratchPath, fps); + LOG(tB); + #endif + }; + m_bSegActive = true; + m_bSegDelete = m_bNSegDelete; + m_bNSegDelete = true; + m_nSegFrameCounter = 0; + m_nSegShiftFrames = 0; + } else { + LOG_ERROR("No Encoder Object!"); + m_bThreadStatus = TH_ENDED; + continue; + }; + #else // !OPENCV_VIDEO_OUTPUT + // Check if Encoder is Ready + if (m_pFormat == NULL){ + m_bThreadStatus = TH_ENDED; + continue; + } + + #ifdef SEPARATED_VIDEO_ENCODERS + if (avformat_alloc_output_context2(&m_pFormatCtx, m_pFormat, NULL, "test." VIDEO_OUTPUT_CONTAINER) < 0){ + LOG_ERROR("Format CTX alloc error!"); + m_bThreadStatus = TH_ENDED; + continue; + } else { + av_dict_set(&m_pFormatCtx->metadata, "Author", "Argus Sec. System", 0); + m_pFormatCtx->flags |= AVFMT_NOTIMESTAMPS | AVFMT_TS_NONSTRICT; + }; + + m_pVideoStr = avformat_new_stream(m_pFormatCtx, m_pVideoACodec); + if (m_pVideoStr == NULL){ + avformat_free_context(m_pFormatCtx); + m_bThreadStatus = TH_ENDED; + continue; + #ifdef DEBUG_EXTRA + } else { + LOG("VideoStream is Created"); + #endif + }; + const AVRational dst_fps = {m_sStreamData.fps, 1}; + m_pVideoStr->r_frame_rate = m_pVideoStrA->avg_frame_rate = dst_fps; + m_pVideoStr->time_base = m_pCodecCtx->time_base; + avcodec_parameters_from_context(m_pVideoStr->codecpar, m_pCodecACtx); + #ifdef DEBUG_EXTRA + LOG("Opening Stream"); + LOG(m_cSegName); + char tB[128]; + sprintf(tB, "FFPTS:%llu FNUM:%llu S2KF:%llu", m_pVideoStr->start_time, m_pVideoStr->nb_frames, m_pVideoStr->first_dts); + LOG(tB); + sprintf(tB, "CON ST:%llu DUR:%llu", m_pFormatCtx->start_time, m_pFormatCtx->duration); + LOG(tB); + #endif + // if (avio_open(&m_pFormatCtx->pb, m_cSegNameA, AVIO_FLAG_WRITE) < 0) { + if (avio_open(&m_pFormatCtx->pb, m_sStreamSegmentInfo.scratchPath, AVIO_FLAG_WRITE) < 0) + { + LOG_ERROR("Could not open output file."); + m_bThreadStatus = TH_ENDED; + continue; + }; + if (avformat_write_header(m_pFormatCtx, &m_pFormatOpts) < 0) + { + LOG_ERROR("Error occurred when writing header to output file."); + m_bThreadStatus = TH_ENDED; + continue; + }; + // m_mFrameCounterProtector.lock(); + m_nSegFrameCounter = 0; + m_nSegShiftFrames = 0; + m_bSegActive = true; + m_bSegDelete = m_bNSegDelete; + m_bNSegDelete = true; + // m_mFrameCounterProtector.unlock(); + #else // SEPARATED_VIDEO_ENCODERS + m_nSegSkippedFrames = m_pVideoStr->nb_frames + 1; + if (m_pVideoStr->nb_frames) + { + m_pVideoStr->nb_frames = 0; + m_pVideoStr->start_time = 0; + m_pVideoStr->first_dts = 0; + m_pFormatCtx->start_time = 0; + }; + #ifdef DEBUG_EXTRA + LOG("Opening Stream"); + LOG(m_cSegName); + char tB[128]; + sprintf(tB, "FFPTS:%llu FNUM:%llu S2KF:%llu", m_pVideoStr->start_time, m_pVideoStr->nb_frames, m_pVideoStr->first_dts); + LOG(tB); + sprintf(tB, "CON ST:%llu DUR:%llu", m_pFormatCtx->start_time, m_pFormatCtx->duration); + LOG(tB); + #endif + if (avio_open(&m_pFormatCtx->pb, m_cSegName, AVIO_FLAG_WRITE) < 0) + { + LOG_ERROR("Could not open output file."); + m_bThreadStatus = TH_ENDED; + continue; + }; + if (avformat_write_header(m_pFormatCtx, &m_pFormatOpts) < 0) + { + LOG_ERROR("Error occurred when writing header to output file."); + m_bThreadStatus = TH_ENDED; + continue; + }; + // m_mFrameCounterProtector.lock(); + m_nSegFrameCounter = 0; + m_nSegShiftFrames = 0; + m_bSegActive = true; + m_bSegDelete = m_bNSegDelete; + m_bNSegDelete = true; + // m_mFrameCounterProtector.unlock(); + #endif // SEPARATED_VIDEO_ENCODERS + #ifdef DEBUG_EXTRA + LOG("Stream Opened"); + #endif + #endif // !OPENCV_VIDEO_OUTPUT + #endif // !DIRECT_MJPEG_COMPOSING + }; + // If was not sucessfull - exit ?? + if( !m_bSegActive ){ + LOG_ERROR("Can not Open VideoStream for first time!"); + m_bThreadStatus = TH_ENDED; + continue; + }; + #else + if (! openSegmentA()){ + m_bThreadStatus = TH_ENDED; + LOG_ERROR("Can not Open VideoStream A for first time!"); + continue; + }; + #endif + m_bThreadStatus = TH_WORKING; + continue; + }; + + m_mEncodingQueueProtector.lock(); + nQueueSize = m_qEncodingQueue.size(); + m_mEncodingQueueProtector.unlock(); + + if (nQueueSize) + { + m_mEncodingQueueProtector.lock(); + ENCODING_BUFFER * tData = m_qEncodingQueue.front(); + if (tData) + { + m_qEncodingQueue.pop(); + m_mEncodingQueueProtector.unlock(); + #ifdef DIRECT_MJPEG_COMPOSING + #ifdef EVE_SEQUENTAL_OUTPUT + if( m_pOutputFD ) + { + fwrite(tData->data, 1, tData->size, m_pOutputFD); + m_mFrameCounterProtector.lock(); + m_nSegFrameCounter++; + m_mFrameCounterProtector.unlock(); + }; + #else // ! EVE_SEQUENTAL_OUTPUT + + if (m_bSegAActive) + { + if (m_pOutputFD[0]) + { + fwrite(tData->data, 1, tData->size, m_pOutputFD[0]); + m_mFrameCounterProtector.lock(); + m_nSegAFrameCounter++; + m_mFrameCounterProtector.unlock(); + }; + } + + if (m_bSegBActive) + { + if (m_pOutputFD[1]) + { + fwrite(tData->data, 1, tData->size, m_pOutputFD[1]); + m_mFrameCounterProtector.lock(); + m_nSegBFrameCounter++; + m_mFrameCounterProtector.unlock(); + }; + } + #endif // ! EVE_SEQUENTAL_OUTPUT + // Don't free tData->data since is pointer on static data + free(tData->data); + #else // !DIRECT_MJPEG_COMPOSING + #ifdef OPENCV_VIDEO_OUTPUT + + cv::Mat image(tData->rows, tData->cols, CV_8UC3); + memcpy(image.data, tData->data, tData->size); + free(tData->data); + #ifdef EVE_SEQUENTAL_OUTPUT + if (m_bSegActive) + { + if (m_pEncoder->isOpened()) + { + m_pEncoder->write(image); + m_mFrameCounterProtector.lock(); + m_nSegFrameCounter++; + m_mFrameCounterProtector.unlock(); + }; + } + #else //!EVE_SEQUENTAL_OUTPUT + if (m_bSegAActive) + { + if (m_pEncoderA->isOpened()) + { + m_pEncoderA->write(image); + m_mFrameCounterProtector.lock(); + m_nSegAFrameCounter++; + m_mFrameCounterProtector.unlock(); + }; + } + if (m_bSegBActive) + { + if (m_pEncoderB->isOpened()) + { + m_pEncoderB->write(image); + m_mFrameCounterProtector.lock(); + m_nSegBFrameCounter++; + m_mFrameCounterProtector.unlock(); + }; + } + #endif // !EVE_SEQUENTAL_OUTPUT + #else //! OPENCV_VIDEO_OUTPUT + // av_frame_make_writable( m_pAVFrame ); + // m_qEncodingQueue.pop(); + // m_mEncodingQueueProtector.unlock(); + sws_scale(m_pConvertCtx, tData->data, tData->linesize, 0, tData->rows, m_pAVFrame->data, m_pAVFrame->linesize); + free(tData->data[0]); + /* + + + AV_PICTURE_TYPE_NONE Undefined. + AV_PICTURE_TYPE_I Intra. + AV_PICTURE_TYPE_P Predicted. + AV_PICTURE_TYPE_B Bi-dir predicted. + AV_PICTURE_TYPE_S S(GMC)-VOP MPEG4. + AV_PICTURE_TYPE_SI Switching Intra. + AV_PICTURE_TYPE_SP Switching Predicted. + AV_PICTURE_TYPE_BI BI type. + + + */ + if ((m_nGlobalFrameCounter % m_sStreamData.fps) == 0) + { + m_pAVFrame->key_frame = 1; + m_pAVFrame->pict_type = AVPictureType::AV_PICTURE_TYPE_I; + } + else + { + m_pAVFrame->key_frame = 0; + m_pAVFrame->pict_type = AVPictureType::AV_PICTURE_TYPE_NONE; + }; + m_pAVFrame->pts = m_nGlobalFrameCounter + 1; + #ifdef SEPARATED_VIDEO_ENCODERS + if (m_bSegAActive) + { + rVal = avcodec_send_frame(m_pCodecACtx, m_pAVFrame); + } + if (m_bSegBActive) + { + rVal = avcodec_send_frame(m_pCodecBCtx, m_pAVFrame); + } + #else //! SEPARATED_VIDEO_ENCODERS + rVal = avcodec_send_frame(m_pCodecCtx, m_pAVFrame); + #endif //! SEPARATED_VIDEO_ENCODERS + #endif //! OPENCV_VIDEO_OUTPUT + #endif //! DIRECT_MJPEG_COMPOSING + free(tData); + m_mFrameCounterProtector.lock(); + m_nGlobalFrameCounter++; + m_mFrameCounterProtector.unlock(); + } else { + m_mEncodingQueueProtector.unlock(); + }; + }; + #ifdef EVE_SEQUENTAL_OUTPUT + if ( m_bSegActive ) { + m_mFrameCounterProtector.lock(); + if ( m_nSegFrameCounter == m_nHardLimitFrames ) { + #ifdef DEBUG_EXTRA + LOG("Actual Closing Video Stream"); + LOG( m_sStreamSegmentInfo.scratchPath ); + #endif + m_bSegActive = false; + if( !m_bSegDelete ){ + #ifdef DIRECT_MJPEG_COMPOSING + if( m_pOutputFD ){ + fclose(m_pOutputFD); + m_pOutputFD = NULL; + }; + #else //! DIRECT_MJPEG_COMPOSING + #ifdef OPENCV_VIDEO_OUTPUT + if( m_pEncoder->isOpened() ){ + m_pEncoder->release(); + #ifdef DEBUG_EXTRA + } else { + LOG("Encoder is NOT Opened!"); + #endif + }; + #else //! OPENCV_VIDEO_OUTPUT + av_write_trailer( m_pFormatCtx ); + avio_close( m_pFormatCtx->pb ); + #endif //! OPENCV_VIDEO_OUTPUT + #endif //! DIRECT_MJPEG_COMPOSING + VIDEO_SEGMENT_INFO *tData = (VIDEO_SEGMENT_INFO*) malloc( sizeof(VIDEO_SEGMENT_INFO)); + if( tData ){ + memcpy( tData, &m_sStreamSegmentInfo, sizeof( VIDEO_SEGMENT_INFO )); + EVENT_CONTAINER * bEVT = createBasicEvent( m_sStreamData.source_id, EVT_CLASS_VIDEO, EVT_CAPTURE_DONE, NULL, NULL, tData ); + if( bEVT ){ + basicEventHeap::getInstance()->broadcast(bEVT); + } else { + LOG_ERROR("Event Creation failure!"); + free(tData); + }; + }; + #ifdef DEBUG_EXTRA + LOG("Stream is Saved"); + #endif + } else { + #ifdef DIRECT_MJPEG_COMPOSING + if( m_pOutputFD ){ + fclose(m_pOutputFD); + m_pOutputFD = NULL; + }; + #else // !DIRECT_MJPEG_COMPOSING + #ifdef OPENCV_VIDEO_OUTPUT + if (m_pEncoder->isOpened()){ + m_pEncoder->release(); + #ifdef DEBUG_EXTRA + } else { + LOG("Encoder is NOT Opened!"); + #endif + }; + #else // !OPENCV + #ifdef EVE_DONT_DELETE_SEGMENTS + av_write_trailer(m_pFormatCtx); + #endif + avio_close(m_pFormatCtx->pb); + #endif // !OPENCV_VIDEO_OUTPUT + #endif // !DIRECT_MJPEG_COMPOSING + #ifndef EVE_DONT_DELETE_SEGMENTS + unlink(m_sStreamSegmentInfo.scratchPath); + #endif + #ifdef DEBUG_EXTRA + LOG("Stream is Closed and Deleted!"); + #endif + }; + #ifndef DIRECT_MJPEG_COMPOSING + #ifndef OPENCV_VIDEO_OUTPUT + #ifdef SEPARATED_VIDEO_ENCODERS + #ifdef DEBUG_EXTRA + LOG("Del FCTX"); + #endif + avformat_free_context( m_pFormatCtx ); + m_pVideoStr = NULL; + #ifdef DEBUG_EXTRA + LOG("Del FCTX DONE"); + #endif + #endif // SEPARATED_VIDEO_ENCODERS + #endif // !OPENCV + #endif // !DIRECT_MJPEG_COMPOSING + }; + m_mFrameCounterProtector.unlock(); + //If we closed Stream then open new + if (!m_bSegActive ) { + CSTR tAM = getUniqID_MD5(); + if( tAM ){ + sprintf(m_sStreamSegmentInfo.scratchPath, "%s/%s.%s", m_pVideoScratchPath, tAM, VIDEO_OUTPUT_CONTAINER); + strncpy(m_sStreamSegmentInfo.recordMD5, tAM, 32); + m_sStreamSegmentInfo.recordMD5[32] = (char) 0; + free(tAM); + m_sStreamSegmentInfo.stream_id = m_sStreamData.id; + PF_TIMESTAMP ts; + getPFTS(&ts); + m_sStreamSegmentInfo.streamTSS = ts.seconds; + m_sStreamSegmentInfo.streamTMS = ts.milliseconds; + #ifdef DEBUG_EXTRA + char tB[128]; + sprintf(tB, "VideoStream opened %d.%d", m_sStreamSegmentInfo.streamTSS, m_sStreamSegmentInfo.streamTMS); + LOG(tB); + LOG( m_sStreamSegmentInfo.scratchPath ); + #endif + strncpy(m_sStreamSegmentInfo.recordEXT, VIDEO_OUTPUT_CONTAINER, 6); + m_sStreamSegmentInfo.streamFPS = m_sStreamData.fps; + m_sStreamSegmentInfo.streamWidth = m_pMaster->getWidh(); + m_sStreamSegmentInfo.streamHeight = m_pMaster->getHeight(); + m_sStreamSegmentInfo.eventIDS.clear(); + m_sStreamSegmentInfo.eventTSS.clear(); + m_sStreamSegmentInfo.eventTMS.clear(); + m_sStreamSegmentInfo.eventFrames.clear(); + m_sStreamSegmentInfo.dataSize = 0; + m_sStreamSegmentInfo.db_id = 0; + #ifdef DIRECT_MJPEG_COMPOSING + m_pOutputFD = fopen(m_sStreamSegmentInfo.scratchPath, "wb+"); + m_nSegFrameCounter = 0; + m_nSegShiftFrames = 0; + m_bSegActive = true; + m_bSegDelete = m_bNSegDelete; + m_bNSegDelete = true; + #else // !DIRECT_MJPEG_COMPOSING + #ifdef OPENCV_VIDEO_OUTPUT + if ( m_pEncoder ){ + //int fourcc = cv::VideoWriter::fourcc('H', '2', '6', '4'); + int fourcc =cv::VideoWriter::fourcc('a', 'v', 'c', '1'); + //int fourcc = cv::VideoWriter::fourcc('M', 'J', 'P', 'G'); + double fps = m_sStreamData.fps; + cv::String mn(m_sStreamSegmentInfo.scratchPath); + cv::Size fz(m_sStreamData.width, m_sStreamData.height); + // open (const String &filename, int fourcc, double fps, Size frameSize, bool isColor=true) + if (! m_pEncoder->open(mn, fourcc, fps, fz) ) { + LOG_ERROR("Cannot Open Output VideoStream!"); + m_bThreadStatus = TH_ENDED; + continue; + #ifdef DEBUG_EXTRA + } else { + char tB[256]; + sprintf(tB, "VideoStream is Created [%s] %.2f fps", m_sStreamSegmentInfo.scratchPath, fps); + LOG(tB); + #endif + }; + m_bSegActive = true; + m_bSegDelete = m_bNSegDelete; + m_bNSegDelete = true; + m_nSegFrameCounter = 0; + m_nSegShiftFrames = 0; + } else { + LOG_ERROR("No Encoder Object!"); + m_bThreadStatus = TH_ENDED; + continue; + }; + #else // !OPENCV_VIDEO_OUTPUT + // Check if Encoder is Ready + if (m_pFormat == NULL){ + m_bThreadStatus = TH_ENDED; + continue; + } + + #ifdef SEPARATED_VIDEO_ENCODERS + if (avformat_alloc_output_context2(&m_pFormatCtx, m_pFormat, NULL, "test." VIDEO_OUTPUT_CONTAINER) < 0){ + LOG_ERROR("Format CTX alloc error!"); + m_bThreadStatus = TH_ENDED; + continue; + } else { + av_dict_set(&m_pFormatCtx->metadata, "Author", "Argus Sec. System", 0); + m_pFormatCtx->flags |= AVFMT_NOTIMESTAMPS | AVFMT_TS_NONSTRICT; + }; + + m_pVideoStr = avformat_new_stream(m_pFormatCtx, m_pVideoACodec); + if (m_pVideoStr == NULL){ + avformat_free_context(m_pFormatCtx); + m_bThreadStatus = TH_ENDED; + continue; + #ifdef DEBUG_EXTRA + } else { + LOG("VideoStream is Created"); + #endif + }; + const AVRational dst_fps = {m_sStreamData.fps, 1}; + m_pVideoStr->r_frame_rate = m_pVideoStrA->avg_frame_rate = dst_fps; + m_pVideoStr->time_base = m_pCodecCtx->time_base; + avcodec_parameters_from_context(m_pVideoStr->codecpar, m_pCodecACtx); + #ifdef DEBUG_EXTRA + LOG("Opening Stream"); + LOG(m_cSegName); + char tB[128]; + sprintf(tB, "FFPTS:%llu FNUM:%llu S2KF:%llu", m_pVideoStr->start_time, m_pVideoStr->nb_frames, m_pVideoStr->first_dts); + LOG(tB); + sprintf(tB, "CON ST:%llu DUR:%llu", m_pFormatCtx->start_time, m_pFormatCtx->duration); + LOG(tB); + #endif + // if (avio_open(&m_pFormatCtx->pb, m_cSegNameA, AVIO_FLAG_WRITE) < 0) { + if (avio_open(&m_pFormatCtx->pb, m_sStreamSegmentInfo.scratchPath, AVIO_FLAG_WRITE) < 0) + { + LOG_ERROR("Could not open output file."); + m_bThreadStatus = TH_ENDED; + continue; + }; + if (avformat_write_header(m_pFormatCtx, &m_pFormatOpts) < 0) + { + LOG_ERROR("Error occurred when writing header to output file."); + m_bThreadStatus = TH_ENDED; + continue; + }; + // m_mFrameCounterProtector.lock(); + m_nSegFrameCounter = 0; + m_nSegShiftFrames = 0; + m_bSegActive = true; + m_bSegDelete = m_bNSegDelete; + m_bNSegDelete = true; + // m_mFrameCounterProtector.unlock(); + #else // SEPARATED_VIDEO_ENCODERS + m_nSegSkippedFrames = m_pVideoStr->nb_frames + 1; + if (m_pVideoStr->nb_frames) + { + m_pVideoStr->nb_frames = 0; + m_pVideoStr->start_time = 0; + m_pVideoStr->first_dts = 0; + m_pFormatCtx->start_time = 0; + }; + #ifdef DEBUG_EXTRA + LOG("Opening Stream"); + LOG(m_cSegName); + char tB[128]; + sprintf(tB, "FFPTS:%llu FNUM:%llu S2KF:%llu", m_pVideoStr->start_time, m_pVideoStr->nb_frames, m_pVideoStr->first_dts); + LOG(tB); + sprintf(tB, "CON ST:%llu DUR:%llu", m_pFormatCtx->start_time, m_pFormatCtx->duration); + LOG(tB); + #endif + if (avio_open(&m_pFormatCtx->pb, m_cSegName, AVIO_FLAG_WRITE) < 0) + { + LOG_ERROR("Could not open output file."); + m_bThreadStatus = TH_ENDED; + continue; + }; + if (avformat_write_header(m_pFormatCtx, &m_pFormatOpts) < 0) + { + LOG_ERROR("Error occurred when writing header to output file."); + m_bThreadStatus = TH_ENDED; + continue; + }; + // m_mFrameCounterProtector.lock(); + m_nSegFrameCounter = 0; + m_nSegShiftFrames = 0; + m_bSegActive = true; + m_bSegDelete = m_bNSegDelete; + m_bNSegDelete = true; + // m_mFrameCounterProtector.unlock(); + #endif // SEPARATED_VIDEO_ENCODERS + #ifdef DEBUG_EXTRA + LOG("Stream Opened"); + #endif + #endif // !OPENCV_VIDEO_OUTPUT + #endif // !DIRECT_MJPEG_COMPOSING + }; + }; + }; + #else //! EVE_SEQUENTAL_OUTPUT + // Test Commands! + m_mCurrentOperationProtector.lock(); + switch (m_bCOP){ + case 0x01:{ + #ifdef DEBUG_EXTRA + LOG("Actual Closing Video Stream A!"); + LOG(m_sStreamSegmentInfo[0].scratchPath); + #endif + m_bSegAActive = false; + if (! m_bSegADelete) + { + #ifdef DIRECT_MJPEG_COMPOSING + if (m_pOutputFD[0]) + { + fclose(m_pOutputFD[0]); + m_pOutputFD[0] = NULL; + }; + #else //! DIRECT_MJPEG_COMPOSING + #ifdef OPENCV_VIDEO_OUTPUT + if (m_pEncoderA->isOpened()) + { + m_pEncoderA->release(); + #ifdef DEBUG_EXTRA + } + else + { + LOG(" Encoder A is NOT Opened!"); + #endif + }; + #else //! OPENCV_VIDEO_OUTPUT + av_write_trailer(m_pFormatCtxA); + avio_close(m_pFormatCtxA->pb); + #endif //! OPENCV_VIDEO_OUTPUT + #endif //! DIRECT_MJPEG_COMPOSING + EVENT_CONTAINER * bEVT = createBasicEvent(m_sStreamData.source_id, EVT_CLASS_VIDEO, EVT_CAPTURE_DONE, NULL, NULL, &m_sStreamSegmentInfo[0]); + if (bEVT) + { + basicEventHeap::getInstance()->broadcast(bEVT); + } + else + { + LOG_ERROR("Event Creation failure!"); + } + #ifdef DEBUG_EXTRA + LOG("Stream A is Saved"); + #endif + } + else + { + #ifdef DIRECT_MJPEG_COMPOSING + if (m_pOutputFD[0]) + { + fclose(m_pOutputFD[0]); + m_pOutputFD[0] = NULL; + }; + #else // !DIRECT_MJPEG_COMPOSING + #ifdef OPENCV_VIDEO_OUTPUT + if (m_pEncoderA->isOpened()) + { + m_pEncoderA->release(); + #ifdef DEBUG_EXTRA + } + else + { + LOG(" Encoder A is NOT Opened!"); + #endif + }; + #else // !OPENCV + #ifdef EVE_DONT_DELETE_SEGMENTS + av_write_trailer(m_pFormatCtxA); + #endif + avio_close(m_pFormatCtxA->pb); + #endif // !OPENCV_VIDEO_OUTPUT + #endif // !DIRECT_MJPEG_COMPOSING + #ifndef EVE_DONT_DELETE_SEGMENTS + unlink(m_sStreamSegmentInfo[0].scratchPath); + #endif + #ifdef DEBUG_EXTRA + LOG("Stream A is Closed!"); + #endif + }; + #ifndef DIRECT_MJPEG_COMPOSING + #ifndef OPENCV_VIDEO_OUTPUT + #ifdef SEPARATED_VIDEO_ENCODERS + #ifdef DEBUG_EXTRA + LOG("Del FCTX"); + #endif + avformat_free_context(m_pFormatCtxA); + m_pVideoStrA = NULL; + #ifdef DEBUG_EXTRA + LOG("Del FCTX DONE"); + #endif + #endif // SEPARATED_VIDEO_ENCODERS + #endif // !OPENCV + #endif // !DIRECT_MJPEG_COMPOSING + break; + }; + case 0x02:{ + #ifdef DEBUG_EXTRA + LOG("Actual Closing Video Stream B!"); + LOG(m_sStreamSegmentInfo[1].scratchPath); + #endif + m_bSegBActive = false; + if (! m_bSegBDelete) + { + #ifdef DIRECT_MJPEG_COMPOSING + if (m_pOutputFD[1]) + { + fclose(m_pOutputFD[1]); + m_pOutputFD[1] = NULL; + }; + #else // !DIRECT_MJPEG_COMPOSING + #ifdef OPENCV_VIDEO_OUTPUT + if (m_pEncoderB->isOpened()) + { + m_pEncoderB->release(); + #ifdef DEBUG_EXTRA + } + else + { + LOG(" Encoder B is NOT Opened!"); + #endif + }; + #else // !OpenCV + av_write_trailer(m_pFormatCtxB); + avio_close(m_pFormatCtxB->pb); + #endif // !OPENCV_VIDEO_OUTPUT + #endif // !DIRECT_MJPEG_COMPOSING + EVENT_CONTAINER * bEVT = createBasicEvent(m_sStreamData.source_id, EVT_CLASS_VIDEO, EVT_CAPTURE_DONE, NULL, NULL, &m_sStreamSegmentInfo[1]); + if (bEVT) + { + basicEventHeap::getInstance()->broadcast(bEVT); + } + else + { + LOG_ERROR("Event Creation failure!"); + } + #ifdef DEBUG_EXTRA + LOG("Stream B is Saved"); + + #endif + } + else + { + #ifdef DIRECT_MJPEG_COMPOSING + if (m_pOutputFD[1]) + { + fclose(m_pOutputFD[1]); + m_pOutputFD[1] = NULL; + }; + #else + #ifdef OPENCV_VIDEO_OUTPUT + if (m_pEncoderB->isOpened()) + { + m_pEncoderB->release(); + #ifdef DEBUG_EXTRA + } + else + { + LOG(" Encoder B is NOT Opened!"); + #endif + }; + #else // !OPenCV + #ifdef EVE_DONT_DELETE_SEGMENTS + av_write_trailer(m_pFormatCtxB); + #endif + avio_close(m_pFormatCtxB->pb); + #endif // !OPENCV_VIDEO_OUTPUT + #endif // !DIRECT_MJPEG_COMPOSING + #ifndef EVE_DONT_DELETE_SEGMENTS + unlink(m_sStreamSegmentInfo[1].scratchPath); + #endif + #ifdef DEBUG_EXTRA + LOG("Stream B is Closed!"); + #endif + }; + #ifndef DIRECT_MJPEG_COMPOSING + #ifndef OPENCV_VIDEO_OUTPUT + #ifdef SEPARATED_VIDEO_ENCODERS + avformat_free_context(m_pFormatCtxB); + m_pVideoStrB = NULL; + #endif // SEPARATED_VIDEO_ENCODERS + #endif // !OPENCV + #endif // !DIRECT_MJPEG_COMPOSING + break; + }; + }; + m_bCOP = 0; + m_mCurrentOperationProtector.unlock(); + #endif // !EVE_SEQUENTAL_OUTPUT + +#ifndef DIRECT_MJPEG_COMPOSING + #ifndef OPENCV_VIDEO_OUTPUT + #ifdef SEPARATED_VIDEO_ENCODERS + do + { + mPacket.data = NULL; + mPacket.size = 0; + rVal = avcodec_receive_packet(m_pCodecACtx, &mPacket); + if (rVal == AVERROR(EAGAIN) || rVal == AVERROR_EOF) + { + break; + } + else if (rVal < 0) + { + LOG_ERROR("Error during encoding "); + m_bThreadStatus = TH_ENDED; + break; + }; + if (! rVal) + { + if (m_bSegAActive) + { + mPacket.stream_index = m_pVideoStrA->index; + mPacket.duration = 1; + m_mFrameCounterProtector.lock(); + m_nSegAFrameCounter++; + m_mFrameCounterProtector.unlock(); + mPacket.pts = av_rescale_q(m_nSegAFrameCounter, m_pCodecACtx->time_base, m_pVideoStrA->time_base); + // mPacket.pts = AV_NOPTS_VALUE; + // mPacket.pts = av_rescale_q( m_nSegASkippedFrames + m_nSegAFrameCounter, m_pCodecCtx->time_base, m_pVideoStrA->time_base ); + mPacket.dts = mPacket.pts; + int rc = av_write_frame(m_pFormatCtxA, &mPacket); + if (rc < 0) + { + // if( av_interleaved_write_frame( m_pFormatCtxA, &mPacket) < 0 ) { + m_bThreadStatus = TH_ENDED; + LOG_ERROR("Trouble with Video Output A!"); + av_strerror(rc, tB, 128); + LOG_ERROR(tB); + break; // continue (changed since embed into do-while) + }; + }; + if (m_bSegBActive) + { + mPacket.stream_index = m_pVideoStrB->index; + mPacket.duration = 1; + m_mFrameCounterProtector.lock(); + m_nSegBFrameCounter++; + m_mFrameCounterProtector.unlock(); + mPacket.pts = av_rescale_q(m_nSegBFrameCounter, m_pCodecBCtx->time_base, m_pVideoStrB->time_base); + // mPacket.pts = AV_NOPTS_VALUE; + // mPacket.pts = av_rescale_q( m_nSegBSkippedFrames + m_nSegBFrameCounter, m_pCodecCtx->time_base, m_pVideoStrB->time_base ); + mPacket.dts = mPacket.pts; + int rc = av_write_frame(m_pFormatCtxB, &mPacket); + if (rc < 0) + { + // if( av_interleaved_write_frame( m_pFormatCtxB, &mPacket) < 0 ) { + m_bThreadStatus = TH_ENDED; + LOG_ERROR("Trouble with Video Output B!"); + av_strerror(rc, tB, 128); + LOG_ERROR(tB); + break; // continue (changed since embed into do-while) + }; + }; + av_packet_unref(&mPacket); + }; + } + while (rVal >= 0 && m_bThreadStatus != TH_ENDED); + #else // !SEPARATED_VIDEO_ENCODERS + do + { + mPacket.data = NULL; + mPacket.size = 0; + rVal = avcodec_receive_packet(m_pCodecCtx, &mPacket); + if (rVal == AVERROR(EAGAIN) || rVal == AVERROR_EOF) + { + break; + } + else if (rVal < 0) + { + LOG_ERROR("Error during encoding "); + m_bThreadStatus = TH_ENDED; + break; + }; + if (! rVal) + { + if (m_bSegAActive) + { + mPacket.stream_index = m_pVideoStrA->index; + mPacket.duration = 1; + mPacket.pts = av_rescale_q(m_nGlobalFrameCounter, m_pCodecCtx->time_base, m_pVideoStrA->time_base); + // mPacket.pts = AV_NOPTS_VALUE; + // mPacket.pts = av_rescale_q( m_nSegASkippedFrames + m_nSegAFrameCounter, m_pCodecCtx->time_base, m_pVideoStrA->time_base ); + mPacket.dts = mPacket.pts; + int rc = av_write_frame(m_pFormatCtxA, &mPacket); + if (rc < 0) + { + // if( av_interleaved_write_frame( m_pFormatCtxA, &mPacket) < 0 ) { + m_bThreadStatus = TH_ENDED; + LOG_ERROR("Trouble with Video Output A!"); + av_strerror(rc, tB, 128); + LOG_ERROR(tB); + break; // continue (changed since embed into do-while) + }; + }; + if (m_bSegBActive) + { + mPacket.stream_index = m_pVideoStrB->index; + mPacket.duration = 1; + mPacket.pts = av_rescale_q(m_nGlobalFrameCounter, m_pCodecCtx->time_base, m_pVideoStrA->time_base); + // mPacket.pts = AV_NOPTS_VALUE; + // mPacket.pts = av_rescale_q( m_nSegBSkippedFrames + m_nSegBFrameCounter, m_pCodecCtx->time_base, m_pVideoStrB->time_base ); + mPacket.dts = mPacket.pts; + int rc = av_write_frame(m_pFormatCtxB, &mPacket); + if (rc < 0) + { + // if( av_interleaved_write_frame( m_pFormatCtxB, &mPacket) < 0 ) { + m_bThreadStatus = TH_ENDED; + LOG_ERROR("Trouble with Video Output B!"); + av_strerror(rc, tB, 128); + LOG_ERROR(tB); + break; // continue (changed since embed into do-while) + }; + }; + av_packet_unref(&mPacket); + }; + } + while (rVal >= 0 && m_bThreadStatus != TH_ENDED); + #endif // ! SEPARATED_VIDEO_ENCODERS + #endif // !OPENCV_VIDEO_OUTPUT +#endif // !DIRECT_MJPEG_COMPOSING + SLEEP(10); + }; +#ifdef DEBUG_EXTRA + LOG("Encoder Loop Ended!"); +#endif + } + + #ifndef EVE_SEQUENTAL_OUTPUT + void streamHandler::swapActiveStreams(void) + { + if (m_bSegDelete) + { + closeSegment(); + } + // m_mFrameCounterProtector.lock(); + m_bActiveEncoderStream = 1 - m_bActiveEncoderStream; + if (m_bActiveEncoderStream) + { + if (m_bSegADelete) + { + closeSegmentA(); + } + } + else + { + if (m_bSegBDelete) + { + closeSegmentB(); + } + }; + // m_mFrameCounterProtector.unlock(); + } + #endif // !EVE_SEQUENTAL_OUTPUT +#endif // EVE_ENABLE_VIDEO + +bool streamHandler::triggerEvent(uint32_t eid, uint32_t & dbid, uint32_t & frame) +{ + +#ifdef DEBUG_EXTRA + LOG("Trig Evt"); +#endif + +#ifdef EVE_ENABLE_VIDEO + m_mFrameCounterProtector.lock(); + // To Mark Events on the Frames + m_bEvtMarkerCounter = 255; + PF_TIMESTAMP ts; + getPFTS(&ts); + if ( dbid ) dbid = dbid; + #ifdef EVE_SEQUENTAL_OUTPUT + m_bSegDelete = false; + // Keep Also Next Segment if close to a end + if ( ( m_nSegmentLimitFrames - m_nSegFrameCounter ) < m_nPostAlarmFrames ) m_bNSegDelete = false; + m_nSegShiftFrames = frame = m_nSegFrameCounter; + m_sStreamSegmentInfo.eventIDS.push_back(eid); + m_sStreamSegmentInfo.eventTSS.push_back(ts.seconds); + m_sStreamSegmentInfo.eventTMS.push_back(ts.milliseconds); + m_sStreamSegmentInfo.eventFrames.push_back(frame); + // dbid = m_sStreamSegmentInfo.db_id;// = m_nVideoRegisteredDBID; + #else // !EVE_SEQUENTAL_OUTPUT + if (!m_bActiveEncoderStream) + { // Stream A is Active + m_bSegADelete = false; + m_nSegAShiftFrames = frame = m_nSegAFrameCounter; + } + else + { // Stream B is Active + m_bSegBDelete = false; + m_nSegBShiftFrames = frame = m_nSegBFrameCounter; + }; + m_sStreamSegmentInfo[m_bActiveEncoderStream].eventIDS.push_back(eid); + m_sStreamSegmentInfo[m_bActiveEncoderStream].eventTSS.push_back(ts.seconds); + m_sStreamSegmentInfo[m_bActiveEncoderStream].eventTMS.push_back(ts.milliseconds); + m_sStreamSegmentInfo[m_bActiveEncoderStream].eventFrames.push_back(frame); + // dbid = m_sStreamSegmentInfo[m_bActiveEncoderStream].db_id;// = m_nVideoRegisteredDBID; + #endif // !EVE_SEQUENTAL_OUTPUT + m_mFrameCounterProtector.unlock(); + // if ( dbid == 0 ) return false; + #ifdef DEBUG_EXTRA + LOG("Event Registered!"); + #endif +#endif // EVE_ENABLE_VIDEO + return true; +} + +bool streamHandler::triggerCamMove(void) +{ +#ifdef DEBUG_EXTRA + LOG("Trig Cammove"); +#endif + m_bCamMoveCounter = 255; + return true; +} + +bool streamHandler::validate(void) +{ + if (m_pSource) + { + if (m_pSource->getStatus() < MS_CLOSING) + { +#ifdef EVE_ENABLE_VIDEO + if (m_nGlobalFrameCounter) + { // Frames Received from a source + if (m_nGlobalFrameCounter == m_nValidatorFrameCounter) + { + // No new frame since the last validation: restart only when it lasts (STREAM_STALL_CHECKS) + char tB[128]; + long tSec = (long) (time(NULL) - m_tLastFrameProgress); + if (++m_nStallChecks < STREAM_STALL_CHECKS) + { + snprintf(tB, sizeof(tB), "Video: no new frame for %ld s (%u/%u)", tSec, (unsigned) m_nStallChecks, (unsigned) STREAM_STALL_CHECKS); + LOG(tB); + } + else + { + snprintf(tB, sizeof(tB), "Video Stalled (no frame for %ld s) - restarting the stream", tSec); + LOG_ERROR(tB); + return false; // Try use System to recuperate + }; + } + else + { + if (m_nStallChecks) + { + char tB[96]; + snprintf(tB, sizeof(tB), "Video: frames again after %ld s", (long) (time(NULL) - m_tLastFrameProgress)); + LOG(tB); + }; + m_nStallChecks = 0; + m_tLastFrameProgress = time(NULL); + m_nValidatorFrameCounter = m_nGlobalFrameCounter; + } + }; + if (m_bThreadStatus < TH_ENDED) + { + return true; + } + else + { + LOG_ERROR("Thread Ended!"); + } +#endif + } + else + { + LOG_ERROR("Video Ended"); + } + }; + return false; +} + + +#undef LOG +#undef LOG_ERROR + +#endif // !LRF_PROXY_ONLY + +//#undef DEBUG_EXTRA + diff --git a/lib/App/common/streamHandler.h b/lib/App/common/streamHandler.h index 7e114b87..be688384 100644 --- a/lib/App/common/streamHandler.h +++ b/lib/App/common/streamHandler.h @@ -1,386 +1,403 @@ -#ifndef __STREAM_HANDLER_EMBED_VIDEO_HEADER__ -#define __STREAM_HANDLER_EMBED_VIDEO_HEADER__ - -#include "kernelModuleEmbedVideo.h" - -#ifndef LRF_PROXY_ONLY - -#include "../../components/base/basicDualThread.h" -#include "../../components/base/basicEventHeap.h" -#include "../../components/base/basicMutex.h" -#include "kernelModule.h" -#define EVE_SEQUENTAL_OUTPUT - -#ifndef EVE_SEQUENTAL_OUTPUT - //#define EVE_ENABLE_EASE_OUTPUT_FPS -#endif - -// #include "../../data/media/video/videoAVLIBDestination.h" -#include "../../components/base/basicMediaDestination.h" -#include "../../components/base/basicMediaSource.h" - -#ifndef DB_SHMEM_POINT - #define DB_SHMEM_POINT "/dev/shm/argus" -#endif - -#define VIDEO_SCRATCHPAD_PATH (DB_SHMEM_POINT "/video_scratch") - -//Predefine Classess -class kernelModuleEmbedVideo; -// A stream is restarted only after this many validations in a row (module factory: every ~5 s) without a -// new frame. One gap of ~5 s (a camera on a mobile link) restarted the stream and cut the recording. -#ifndef STREAM_STALL_CHECKS - #define STREAM_STALL_CHECKS 3 -#endif - -class streamHandler; - -#define FILESTREAMBUFFERSZ 1048576 - -#ifndef MEKOROT_PROJECT__ - #define EVE_ENABLE_VIDEO -#endif - -#define USE_SCALING_IN -// #define USE_CV_DENOISE -// #define USE_CV_TONEMAP - -#ifdef EVE_ENABLE_VIDEO - #define VIDEO_OUTPUT_FPS 15 - - #ifndef EVE_SEQUENTAL_OUTPUT - // In case of sequental video files - no need two encoders - #define SEPARATED_VIDEO_ENCODERS - #endif - // #define EVE_DONT_DELETE_SEGMENTS - - /* Video CODECS */ - #define VC_VPX 0 - #define VC_X264 1 - #define VC_MP4 2 - #define VC_MJPEG 3 - #define VC_FLV 4 - - /* Video FORMATS */ - #define VF_WEBM 0 - #define VF_MP4 1 - #define VF_MP3 2 - #define VF_AAC 3 - #define VF_OGG 4 - #define VF_MJPEG 5 - #define VF_FLV 6 - - /* Encoder PROFILES */ - #define VP_ULTRAFAST 0 - #define VP_VERYFAST 1 - #define VP_FAST 2 - #define VP_MEDIUM 3 - #define VP_SLOW 4 - #define VP_VERYSLOW 5 - #define VP_ULTRASLOW 6 - - #define VO_MJPEG 1 - #define VO_MPEG4 2 - #define VO_H264 3 - #define VO_H265 4 - #define VO_FLV 5 - #define VO_DIRECT_MJPG 6 - - #ifndef EVE_WORK_WITH_MEDIAMTX - #define DIRECT_MJPEG_COMPOSING - #endif - - #ifdef DIRECT_MJPEG_COMPOSING - #define VIDEO_OUTPUT VO_DIRECT_MJPG - #else - #define OPENCV_VIDEO_OUTPUT - //#define VIDEO_OUTPUT VO_DIRECT_MJPG - #ifndef OPENCV_VIDEO_OUTPUT - // #define VIDEO_OUTPUT VO_MJPEG - #define VIDEO_OUTPUT VO_MPEG4 - // #define VIDEO_OUTPUT VO_H264 - // #define VIDEO_OUTPUT VO_H265 - // #define VIDEO_OUTPUT VO_FLV - // #define VIDEO_OUTPUT_WIDTH 640 //1920 - // #define VIDEO_OUTPUT_HEIGHT 480 //1080 - // #define VIDEO_OUTPUT_FPS 10 - // #define VIDEO_OUTPUT_GOP 15 - #else // OPENCV_VIDEO_OUTPUT - //#define VIDEO_OUTPUT VO_MJPEG // VO_CV_MP4 - #define VIDEO_OUTPUT VO_CV_MP4 - #endif - #endif // DIRECT_MJPEG_COMPOSING - - #if (LIBAVCODEC_VERSION_MAJOR < 54) - #define VIDEO_OUTPUT_CODEC CODEC_ID_MJPEG - #define VIDEO_OUTPUT_PIX_FMT PIX_FMT_YUVJ422P - #else - #if VIDEO_OUTPUT == VO_MJPEG - #define VIDEO_OUTPUT_CODEC AV_CODEC_ID_MJPEG - #define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P // AV_PIX_FMT_YUVJ422P - #define VIDEO_OUTPUT_CONTAINER_LONG "mjpeg" - #define VIDEO_OUTPUT_BITRATE 4000000 - #define VIDEO_OUTPUT_CONTAINER "mjpeg" - #elif VIDEO_OUTPUT == VO_MPEG4 - #define VIDEO_OUTPUT_CODEC AV_CODEC_ID_MPEG4 - #define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P - #define VIDEO_OUTPUT_CONTAINER_LONG "mp4" - #define VIDEO_OUTPUT_BITRATE 4000000 - #define VIDEO_OUTPUT_CONTAINER "mp4" - #elif VIDEO_OUTPUT == VO_H264 - #define VIDEO_OUTPUT_CODEC AV_CODEC_ID_H264 - #define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P - #define VIDEO_OUTPUT_BITRATE 4000000 - #define VIDEO_OUTPUT_CONTAINER_LONG "mp4" - #define VIDEO_OUTPUT_CONTAINER "mp4" - #elif VIDEO_OUTPUT == VO_H265 - #define VIDEO_OUTPUT_CODEC AV_CODEC_ID_H265 - #define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P - #define VIDEO_OUTPUT_BITRATE 4000000 - #define VIDEO_OUTPUT_CONTAINER_LONG "mp4" - #define VIDEO_OUTPUT_CONTAINER "mp4" - #elif VIDEO_OUTPUT == VO_FLV - #define VIDEO_OUTPUT_CODEC AV_CODEC_ID_FLV1 - #define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P - #define VIDEO_OUTPUT_CONTAINER_LONG "flv" - #define VIDEO_OUTPUT_BITRATE 4000000 - #define VIDEO_OUTPUT_CONTAINER "flv" - #elif VIDEO_OUTPUT == VO_CV_MP4 - #define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P - #define VIDEO_OUTPUT_BITRATE 4000000 - #define VIDEO_OUTPUT_CONTAINER_LONG "mp4" - #define VIDEO_OUTPUT_CONTAINER "mp4" - #elif VIDEO_OUTPUT == VO_DIRECT_MJPG - #define VIDEO_OUTPUT_CONTAINER_LONG "mjpeg" - #define VIDEO_OUTPUT_CONTAINER "mjpeg" - #endif - #endif -#endif // EVE_ENABLE_VIDEO - -typedef struct S_buffer_data -{ - uint8_t * buf; - int size; - uint8_t * ptr; - size_t room; ///< size left in the buffer -} buffer_data; - -#define NR_COLORS 4 -#define AVIO_BUFFER_SIZE 4096 -#define BD_BUFFER_SIZE 1024 - -#define PRE_ALARM_TIME_MILSECONDS 5000 // 5 sec -#define POST_ALARM_TIME_MILSECONDS 5000 // 5 sec -#define ENCODING_SEGMENT_MILSECONDS 50000 // 50 sec -#define ENCODING_SEGMENT_LIMIT_MILSECONDS 60000 // 1 minute -// #define ENCODING_SEGMENT_LIMIT_MILSECONDS 900000 // 15 minutes - - -// #define ENCODER_DISABLED 0 -// #define ENCODER_ENABLED 1 - -#define EVE_ENABLE_DROP_OUTPUT_FPS - -#ifdef EVE_ENABLE_VIDEO - #ifdef DIRECT_MJPEG_COMPOSING - typedef struct S_ENCODING_BUFFER - { - uint8_t * data; - size_t size; - } ENCODING_BUFFER; - #else //! DIRECT_MJPEG_COMPOSING - #ifdef OPENCV_VIDEO_OUTPUT - typedef struct S_ENCODING_BUFFER - { - int cols; - int rows; - uint8_t * data; - size_t size; - } ENCODING_BUFFER; - #else //! OPENCV_VIDEO_OUTPUT - typedef struct S_ENCODING_BUFFER - { - int linesize[2]; - int rows; - uint8_t * data[2]; - size_t size; - } ENCODING_BUFFER; - #endif //! OPENCV_VIDEO_OUTPUT - #endif //! DIRECT_MJPEG_COMPOSING - -typedef std::queue Q_ENCODING_BUFFER; -#endif // EVE_ENABLE_VIDEO - -class streamHandler : - public basicMediaDestination -#ifdef EVE_ENABLE_VIDEO - , public basicThread -#endif -{ - private: - - basicLogCollection * m_pLog; - basicMediaSource * m_pSource; - MEDIA_SOURCE_DESC m_sSourceDesc; - char m_cSourceType; - DBC_MEDIA_STREAM_DATA m_sStreamData; - basicMutex m_mProtector; - kernelModuleEmbedVideo * m_pMaster; - uint8_t m_bEvtMarkerCounter; - uint8_t m_bCamMoveCounter; - - dataBinder * m_pDBC; - MS_WORK_MODE m_eWM; - basicMutex m_mEvtIDS_Protector; - -#ifdef EVE_ENABLE_VIDEO - - #ifdef EVE_SEQUENTAL_OUTPUT - basicMutex m_mEventBindingBlocker; - #endif - - uint32_t m_nPreAlarmFrames; - uint32_t m_nPostAlarmFrames; - uint32_t m_nSegmentLimitFrames; - uint32_t m_nHardLimitFrames; - - basicMutex m_mFrameCounterProtector; - uint64_t m_nGlobalFrameCounter; - uint64_t m_nValidatorFrameCounter; - uint8_t m_nStallChecks; // validate() calls in a row without a new frame - time_t m_tLastFrameProgress; // last validate() that saw new frames - #ifndef EVE_SEQUENTAL_OUTPUT - uint32_t m_nSegAFrameCounter; - uint32_t m_nSegBFrameCounter; - uint32_t m_nSegAShiftFrames; - uint32_t m_nSegBShiftFrames; - uint32_t m_nSegASkippedFrames; - uint32_t m_nSegBSkippedFrames; - - uint8_t m_bActiveEncoderStream; - bool m_bSegAActive; - bool m_bSegADelete; - bool m_bSegBActive; - bool m_bSegBDelete; - VIDEO_SEGMENT_INFO m_sStreamSegmentInfo[2]; - #else - uint32_t m_nSegFrameCounter; - uint32_t m_nSegShiftFrames; - uint32_t m_nSegSkippedFrames; - bool m_bSegActive; - bool m_bSegDelete; - bool m_bNSegDelete; - VIDEO_SEGMENT_INFO m_sStreamSegmentInfo; - #endif - uint8_t m_bFlipMode; - basicMutex m_mCurrentOperationProtector; - uint8_t m_bCOP; - - - #ifdef DIRECT_MJPEG_COMPOSING - #ifndef EVE_SEQUENTAL_OUTPUT - FILE * m_pOutputFD[2]; - #else - FILE * m_pOutputFD; - #endif - #else // !DIRECT_MJPEG_COMPOSING - #ifdef OPENCV_VIDEO_OUTPUT - #ifndef EVE_SEQUENTAL_OUTPUT - cv::VideoWriter * m_pEncoderA; - cv::VideoWriter * m_pEncoderB; - #else - cv::VideoWriter * m_pEncoder; - #endif - #else //! OPENCV_VIDEO_OUTPUT - // char m_pVideoScratchPath[PATH_MAX]; - #ifdef SEPARATED_VIDEO_ENCODERS - // LibAV encoding video stuff - #ifndef EVE_SEQUENTAL_OUTPUT - // Stream A - AVCodec * m_pVideoACodec; - AVCodecContext * m_pCodecACtx; - AVFrame * m_pAVAFrame; - uint8_t * m_pOutABuffer; - // Stream B - AVCodec * m_pVideoBCodec; - AVCodecContext * m_pCodecBCtx; - AVFrame * m_pAVBFrame; - uint8_t * m_pOutBBuffer; - #else - AVCodec * m_pVideoCodec; - AVCodecContext * m_pCodecCtx; - AVFrame * m_pAVFrame; - uint8_t * m_pOutBuffer; - #endif - #else //! SEPARATED_VIDEO_ENCODERS - // LibAV encoding video stuff - AVCodec * m_pVideoCodec; - AVCodecContext * m_pCodecCtx; - AVFrame * m_pAVFrame; - uint8_t * m_pOutBuffer; - #endif //! SEPARATED_VIDEO_ENCODERS - // Common Pix Converter ( for both streams ) - SwsContext * m_pConvertCtx; - #endif //! OPENCV_VIDEO_OUTPUT - - // char m_cSegNameA[128]; - // char m_cSegMD5A[33]; - // char m_cSegNameB[128]; - // char m_cSegMD5B[33]; - - AVOutputFormat * m_pFormat; - #ifdef SEPARATED_VIDEO_ENCODERS - // File Context 2 units - AVFormatContext * m_pFormatCtxA; - AVFormatContext * m_pFormatCtxB; - AVStream * m_pVideoStrA; - AVStream * m_pVideoStrB; - #else - // File Context 1 units - AVFormatContext * m_pFormatCtx; - AVStream * m_pVideoStr; - #endif - // common output options - AVDictionary * m_pFormatOpts; - #endif //! DIRECT_MJPEG_COMPOSING - basicMutex m_mEncodingQueueProtector; - Q_ENCODING_BUFFER m_qEncodingQueue; - #ifndef EVE_SEQUENTAL_OUTPUT - bool openSegmentA(void); - void closeSegmentA(void); - bool openSegmentB(void); - void closeSegmentB(void); - void swapActiveStreams(void); - #endif - void closeAll(); - bool initVideoOutput(); - - protected: - - void m_fThreadProc(void); -#endif //! EVE_ENABLE_VIDEO - - public: - - explicit streamHandler(kernelModuleEmbedVideo * ptr, MS_WORK_MODE M = MS_MODE_DECODE_FRAMES, uint8_t flip_mode = 0); - virtual ~streamHandler(); - bool create(dataBinder * ptr, uint32_t stremID); - /* from Media Destination */ - virtual bool pushFrame(AVFrame * Frame, void * src = NULL); - // virtual void pushFrame( cv::Mat* Frame, void* src = NULL); - virtual bool pushFrame(cv::Mat & Frame, void * src = NULL); - bool triggerEvent(uint32_t eid, uint32_t & dbid, uint32_t & frame); - bool triggerCamMove(void); - bool validate(void); - bool preservingCurrentRecording(){ -#ifdef EVE_SEQUENTAL_OUTPUT - return !m_bSegDelete; -#else - return !( m_bSegADelete || m_bSegBDelete ); -#endif - }; -}; - -#endif // !LRF_PROXY_ONLY - -#endif +#ifndef __STREAM_HANDLER_EMBED_VIDEO_HEADER__ +#define __STREAM_HANDLER_EMBED_VIDEO_HEADER__ + +#include "kernelModuleEmbedVideo.h" + +#ifndef LRF_PROXY_ONLY + +#include "../../components/base/basicDualThread.h" +#include "../../components/base/basicEventHeap.h" +#include "../../components/base/basicMutex.h" +#include "kernelModule.h" +#define EVE_SEQUENTAL_OUTPUT + +#ifndef EVE_SEQUENTAL_OUTPUT + //#define EVE_ENABLE_EASE_OUTPUT_FPS +#endif + +// #include "../../data/media/video/videoAVLIBDestination.h" +#include "../../components/base/basicMediaDestination.h" +#include "../../components/base/basicMediaSource.h" +#include "../../data/media/mtx/feeder/h264Feeder.h" +#include "streamLiveEncoder.h" +#include + +#ifndef DB_SHMEM_POINT + #define DB_SHMEM_POINT "/dev/shm/argus" +#endif + +#define VIDEO_SCRATCHPAD_PATH (DB_SHMEM_POINT "/video_scratch") + +//Predefine Classess +class kernelModuleEmbedVideo; +// A stream is restarted only after this many validations in a row (module factory: every ~5 s) without a +// new frame. One gap of ~5 s (a camera on a mobile link) restarted the stream and cut the recording. +#ifndef STREAM_STALL_CHECKS + #define STREAM_STALL_CHECKS 3 +#endif + +class streamHandler; + +#define FILESTREAMBUFFERSZ 1048576 + +#ifndef MEKOROT_PROJECT__ + #define EVE_ENABLE_VIDEO +#endif + +#define USE_SCALING_IN +// #define USE_CV_DENOISE +// #define USE_CV_TONEMAP + +#ifdef EVE_ENABLE_VIDEO + #define VIDEO_OUTPUT_FPS 15 + + #ifndef EVE_SEQUENTAL_OUTPUT + // In case of sequental video files - no need two encoders + #define SEPARATED_VIDEO_ENCODERS + #endif + // #define EVE_DONT_DELETE_SEGMENTS + + /* Video CODECS */ + #define VC_VPX 0 + #define VC_X264 1 + #define VC_MP4 2 + #define VC_MJPEG 3 + #define VC_FLV 4 + + /* Video FORMATS */ + #define VF_WEBM 0 + #define VF_MP4 1 + #define VF_MP3 2 + #define VF_AAC 3 + #define VF_OGG 4 + #define VF_MJPEG 5 + #define VF_FLV 6 + + /* Encoder PROFILES */ + #define VP_ULTRAFAST 0 + #define VP_VERYFAST 1 + #define VP_FAST 2 + #define VP_MEDIUM 3 + #define VP_SLOW 4 + #define VP_VERYSLOW 5 + #define VP_ULTRASLOW 6 + + #define VO_MJPEG 1 + #define VO_MPEG4 2 + #define VO_H264 3 + #define VO_H265 4 + #define VO_FLV 5 + #define VO_DIRECT_MJPG 6 + + #ifndef EVE_WORK_WITH_MEDIAMTX + #define DIRECT_MJPEG_COMPOSING + #endif + + #ifdef DIRECT_MJPEG_COMPOSING + #define VIDEO_OUTPUT VO_DIRECT_MJPG + #else + #define OPENCV_VIDEO_OUTPUT + //#define VIDEO_OUTPUT VO_DIRECT_MJPG + #ifndef OPENCV_VIDEO_OUTPUT + // #define VIDEO_OUTPUT VO_MJPEG + #define VIDEO_OUTPUT VO_MPEG4 + // #define VIDEO_OUTPUT VO_H264 + // #define VIDEO_OUTPUT VO_H265 + // #define VIDEO_OUTPUT VO_FLV + // #define VIDEO_OUTPUT_WIDTH 640 //1920 + // #define VIDEO_OUTPUT_HEIGHT 480 //1080 + // #define VIDEO_OUTPUT_FPS 10 + // #define VIDEO_OUTPUT_GOP 15 + #else // OPENCV_VIDEO_OUTPUT + //#define VIDEO_OUTPUT VO_MJPEG // VO_CV_MP4 + #define VIDEO_OUTPUT VO_CV_MP4 + #endif + #endif // DIRECT_MJPEG_COMPOSING + + #if (LIBAVCODEC_VERSION_MAJOR < 54) + #define VIDEO_OUTPUT_CODEC CODEC_ID_MJPEG + #define VIDEO_OUTPUT_PIX_FMT PIX_FMT_YUVJ422P + #else + #if VIDEO_OUTPUT == VO_MJPEG + #define VIDEO_OUTPUT_CODEC AV_CODEC_ID_MJPEG + #define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P // AV_PIX_FMT_YUVJ422P + #define VIDEO_OUTPUT_CONTAINER_LONG "mjpeg" + #define VIDEO_OUTPUT_BITRATE 4000000 + #define VIDEO_OUTPUT_CONTAINER "mjpeg" + #elif VIDEO_OUTPUT == VO_MPEG4 + #define VIDEO_OUTPUT_CODEC AV_CODEC_ID_MPEG4 + #define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P + #define VIDEO_OUTPUT_CONTAINER_LONG "mp4" + #define VIDEO_OUTPUT_BITRATE 4000000 + #define VIDEO_OUTPUT_CONTAINER "mp4" + #elif VIDEO_OUTPUT == VO_H264 + #define VIDEO_OUTPUT_CODEC AV_CODEC_ID_H264 + #define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P + #define VIDEO_OUTPUT_BITRATE 4000000 + #define VIDEO_OUTPUT_CONTAINER_LONG "mp4" + #define VIDEO_OUTPUT_CONTAINER "mp4" + #elif VIDEO_OUTPUT == VO_H265 + #define VIDEO_OUTPUT_CODEC AV_CODEC_ID_H265 + #define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P + #define VIDEO_OUTPUT_BITRATE 4000000 + #define VIDEO_OUTPUT_CONTAINER_LONG "mp4" + #define VIDEO_OUTPUT_CONTAINER "mp4" + #elif VIDEO_OUTPUT == VO_FLV + #define VIDEO_OUTPUT_CODEC AV_CODEC_ID_FLV1 + #define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P + #define VIDEO_OUTPUT_CONTAINER_LONG "flv" + #define VIDEO_OUTPUT_BITRATE 4000000 + #define VIDEO_OUTPUT_CONTAINER "flv" + #elif VIDEO_OUTPUT == VO_CV_MP4 + #define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P + #define VIDEO_OUTPUT_BITRATE 4000000 + #define VIDEO_OUTPUT_CONTAINER_LONG "mp4" + #define VIDEO_OUTPUT_CONTAINER "mp4" + #elif VIDEO_OUTPUT == VO_DIRECT_MJPG + #define VIDEO_OUTPUT_CONTAINER_LONG "mjpeg" + #define VIDEO_OUTPUT_CONTAINER "mjpeg" + #endif + #endif +#endif // EVE_ENABLE_VIDEO + +typedef struct S_buffer_data +{ + uint8_t * buf; + int size; + uint8_t * ptr; + size_t room; ///< size left in the buffer +} buffer_data; + +#define NR_COLORS 4 +#define AVIO_BUFFER_SIZE 4096 +#define BD_BUFFER_SIZE 1024 + +#define PRE_ALARM_TIME_MILSECONDS 5000 // 5 sec +#define POST_ALARM_TIME_MILSECONDS 5000 // 5 sec +#define ENCODING_SEGMENT_MILSECONDS 50000 // 50 sec +#define ENCODING_SEGMENT_LIMIT_MILSECONDS 60000 // 1 minute +// #define ENCODING_SEGMENT_LIMIT_MILSECONDS 900000 // 15 minutes + + +// #define ENCODER_DISABLED 0 +// #define ENCODER_ENABLED 1 + +#define EVE_ENABLE_DROP_OUTPUT_FPS + +#ifdef EVE_ENABLE_VIDEO + #ifdef DIRECT_MJPEG_COMPOSING + typedef struct S_ENCODING_BUFFER + { + uint8_t * data; + size_t size; + } ENCODING_BUFFER; + #else //! DIRECT_MJPEG_COMPOSING + #ifdef OPENCV_VIDEO_OUTPUT + typedef struct S_ENCODING_BUFFER + { + int cols; + int rows; + uint8_t * data; + size_t size; + } ENCODING_BUFFER; + #else //! OPENCV_VIDEO_OUTPUT + typedef struct S_ENCODING_BUFFER + { + int linesize[2]; + int rows; + uint8_t * data[2]; + size_t size; + } ENCODING_BUFFER; + #endif //! OPENCV_VIDEO_OUTPUT + #endif //! DIRECT_MJPEG_COMPOSING + +typedef std::queue Q_ENCODING_BUFFER; +#endif // EVE_ENABLE_VIDEO + +class streamHandler : + public basicMediaDestination +#ifdef EVE_ENABLE_VIDEO + , public basicThread +#endif +{ + private: + + basicLogCollection * m_pLog; + basicMediaSource * m_pSource; + MEDIA_SOURCE_DESC m_sSourceDesc; + char m_cSourceType; + DBC_MEDIA_STREAM_DATA m_sStreamData; + basicMutex m_mProtector; + kernelModuleEmbedVideo * m_pMaster; + uint8_t m_bEvtMarkerCounter; + uint8_t m_bCamMoveCounter; + + dataBinder * m_pDBC; + MS_WORK_MODE m_eWM; + + // Live view / recording (kernelModuleEmbedVideo::livePath): the camera's H264 through the feeder, + // or the processed frames through the encoder + uint8_t m_bLiveMode; + std::shared_ptr m_pLivePath; + mtx::H264Feeder m_oLiveFeeder; + std::unique_ptr m_pLiveEncoder; + void initLive(uint32_t nodeID); + void stopLive(void); + basicMutex m_mEvtIDS_Protector; + +#ifdef EVE_ENABLE_VIDEO + + #ifdef EVE_SEQUENTAL_OUTPUT + basicMutex m_mEventBindingBlocker; + #endif + + uint32_t m_nPreAlarmFrames; + uint32_t m_nPostAlarmFrames; + uint32_t m_nSegmentLimitFrames; + uint32_t m_nHardLimitFrames; + + basicMutex m_mFrameCounterProtector; + uint64_t m_nGlobalFrameCounter; + uint64_t m_nValidatorFrameCounter; + uint8_t m_nStallChecks; // validate() calls in a row without a new frame + time_t m_tLastFrameProgress; // last validate() that saw new frames + #ifndef EVE_SEQUENTAL_OUTPUT + uint32_t m_nSegAFrameCounter; + uint32_t m_nSegBFrameCounter; + uint32_t m_nSegAShiftFrames; + uint32_t m_nSegBShiftFrames; + uint32_t m_nSegASkippedFrames; + uint32_t m_nSegBSkippedFrames; + + uint8_t m_bActiveEncoderStream; + bool m_bSegAActive; + bool m_bSegADelete; + bool m_bSegBActive; + bool m_bSegBDelete; + VIDEO_SEGMENT_INFO m_sStreamSegmentInfo[2]; + #else + uint32_t m_nSegFrameCounter; + uint32_t m_nSegShiftFrames; + uint32_t m_nSegSkippedFrames; + bool m_bSegActive; + bool m_bSegDelete; + bool m_bNSegDelete; + VIDEO_SEGMENT_INFO m_sStreamSegmentInfo; + #endif + uint8_t m_bFlipMode; + basicMutex m_mCurrentOperationProtector; + uint8_t m_bCOP; + + + #ifdef DIRECT_MJPEG_COMPOSING + #ifndef EVE_SEQUENTAL_OUTPUT + FILE * m_pOutputFD[2]; + #else + FILE * m_pOutputFD; + #endif + #else // !DIRECT_MJPEG_COMPOSING + #ifdef OPENCV_VIDEO_OUTPUT + #ifndef EVE_SEQUENTAL_OUTPUT + cv::VideoWriter * m_pEncoderA; + cv::VideoWriter * m_pEncoderB; + #else + cv::VideoWriter * m_pEncoder; + #endif + #else //! OPENCV_VIDEO_OUTPUT + // char m_pVideoScratchPath[PATH_MAX]; + #ifdef SEPARATED_VIDEO_ENCODERS + // LibAV encoding video stuff + #ifndef EVE_SEQUENTAL_OUTPUT + // Stream A + AVCodec * m_pVideoACodec; + AVCodecContext * m_pCodecACtx; + AVFrame * m_pAVAFrame; + uint8_t * m_pOutABuffer; + // Stream B + AVCodec * m_pVideoBCodec; + AVCodecContext * m_pCodecBCtx; + AVFrame * m_pAVBFrame; + uint8_t * m_pOutBBuffer; + #else + AVCodec * m_pVideoCodec; + AVCodecContext * m_pCodecCtx; + AVFrame * m_pAVFrame; + uint8_t * m_pOutBuffer; + #endif + #else //! SEPARATED_VIDEO_ENCODERS + // LibAV encoding video stuff + AVCodec * m_pVideoCodec; + AVCodecContext * m_pCodecCtx; + AVFrame * m_pAVFrame; + uint8_t * m_pOutBuffer; + #endif //! SEPARATED_VIDEO_ENCODERS + // Common Pix Converter ( for both streams ) + SwsContext * m_pConvertCtx; + #endif //! OPENCV_VIDEO_OUTPUT + + // char m_cSegNameA[128]; + // char m_cSegMD5A[33]; + // char m_cSegNameB[128]; + // char m_cSegMD5B[33]; + + AVOutputFormat * m_pFormat; + #ifdef SEPARATED_VIDEO_ENCODERS + // File Context 2 units + AVFormatContext * m_pFormatCtxA; + AVFormatContext * m_pFormatCtxB; + AVStream * m_pVideoStrA; + AVStream * m_pVideoStrB; + #else + // File Context 1 units + AVFormatContext * m_pFormatCtx; + AVStream * m_pVideoStr; + #endif + // common output options + AVDictionary * m_pFormatOpts; + #endif //! DIRECT_MJPEG_COMPOSING + basicMutex m_mEncodingQueueProtector; + Q_ENCODING_BUFFER m_qEncodingQueue; + #ifndef EVE_SEQUENTAL_OUTPUT + bool openSegmentA(void); + void closeSegmentA(void); + bool openSegmentB(void); + void closeSegmentB(void); + void swapActiveStreams(void); + #endif + void closeAll(); + bool initVideoOutput(); + + protected: + + void m_fThreadProc(void); +#endif //! EVE_ENABLE_VIDEO + + public: + + explicit streamHandler(kernelModuleEmbedVideo * ptr, MS_WORK_MODE M = MS_MODE_DECODE_FRAMES, uint8_t flip_mode = 0); + virtual ~streamHandler(); + bool create(dataBinder * ptr, uint32_t stremID); + /* from Media Destination */ + virtual bool pushFrame(AVFrame * Frame, void * src = NULL); + // virtual void pushFrame( cv::Mat* Frame, void* src = NULL); + virtual bool pushFrame(cv::Mat & Frame, void * src = NULL); + /* compressed H264 of the source (live view passthrough) */ + virtual void pushEncodedParams(const uint8_t * data, size_t size, bool extradata, void * src = NULL); + virtual void pushEncodedNalu(const uint8_t * data, size_t size, int64_t ptUs, bool marker, bool synced, void * src = NULL); + virtual void pushEncodedPacket(const uint8_t * data, size_t size, int64_t ptsUs, void * src = NULL); + virtual void encodedSourceStopped(void * src = NULL); + bool triggerEvent(uint32_t eid, uint32_t & dbid, uint32_t & frame); + bool triggerCamMove(void); + bool validate(void); + bool preservingCurrentRecording(){ +#ifdef EVE_SEQUENTAL_OUTPUT + return !m_bSegDelete; +#else + return !( m_bSegADelete || m_bSegBDelete ); +#endif + }; +}; + +#endif // !LRF_PROXY_ONLY + +#endif diff --git a/lib/App/common/streamLiveEncoder.cpp b/lib/App/common/streamLiveEncoder.cpp new file mode 100644 index 00000000..588f3dfa --- /dev/null +++ b/lib/App/common/streamLiveEncoder.cpp @@ -0,0 +1,236 @@ +#ifndef LRF_PROXY_ONLY + +#include "streamLiveEncoder.h" + +extern "C" +{ +#include +} + +#define LOG(X) m_pLog->Log("LIVE_ENC", this, X) +#define LOG_ERROR(X) m_pLog->Log("LIVE_ENC", this, _LOG_ERROR, X) + +streamLiveEncoder::streamLiveEncoder(std::shared_ptr path, int fps, int bitrateKbps) : + m_pLog(basicLogCollection::getInstance()), m_pPath(std::move(path)), m_oFeeder(m_pPath.get()), m_nFps(fps > 0 ? fps : 15), m_nBitrateKbps(bitrateKbps > 0 ? bitrateKbps : 2000), + m_bHavePending(false), m_bRun(true), m_nNextFrameUs(0), m_pCtx(NULL), m_pFrame(NULL), m_pPacket(NULL), m_pSws(NULL), m_nWidth(0), m_nHeight(0), m_nFrameIndex(0), m_nLastReaders(0), + m_bOpenFailed(false) +{ + m_thread = std::thread(&streamLiveEncoder::run, this); +} + +streamLiveEncoder::~streamLiveEncoder() +{ + { + std::lock_guard lock(m_mutex); + m_bRun = false; + } + m_cond.notify_all(); + if (m_thread.joinable()) + { + m_thread.join(); + } + m_oFeeder.setParent(nullptr); // the path is not ready any more + closeEncoder(); +} + +void streamLiveEncoder::push(const cv::Mat & bgr) +{ + if (bgr.empty() || m_bOpenFailed) + { + return; + } + // Nobody watches, nothing is recorded: no CPU for encoding + if (m_pPath->readerCount() == 0 && ! m_pPath->recording()) + { + return; + } + int64_t tNow = mtx::nowUs(); + std::lock_guard lock(m_mutex); + if (tNow < m_nNextFrameUs) + { + return; // above the frame rate of the live stream + } + m_nNextFrameUs = (m_nNextFrameUs == 0 || tNow - m_nNextFrameUs > 1000000) ? tNow + 1000000 / m_nFps : m_nNextFrameUs + 1000000 / m_nFps; + bgr.copyTo(m_mPending); // replaces a frame the encoder did not take yet (it is late: drop) + m_bHavePending = true; + m_cond.notify_one(); +} + +void streamLiveEncoder::run() +{ + pthread_setname_np(pthread_self(), "LiveEncoder"); + cv::Mat tFrame; + while (true) + { + { + std::unique_lock lock(m_mutex); + m_cond.wait(lock, [this] { return ! m_bRun || m_bHavePending; }); + if (! m_bRun) + { + break; + } + cv::swap(tFrame, m_mPending); + m_bHavePending = false; + } + size_t tReaders = m_pPath->readerCount(); + bool tIdr = tReaders > m_nLastReaders; // a new viewer: start it now, not at the next GOP + m_nLastReaders = tReaders; + if (m_pCtx != NULL && (tFrame.cols != m_nWidth || tFrame.rows != m_nHeight)) + { + closeEncoder(); // the frame size changed (module settings) + } + if (m_pCtx == NULL) + { + if (! openEncoder(tFrame.cols, tFrame.rows)) + { + m_bOpenFailed = true; + break; + } + tIdr = true; + } + if (! encode(tFrame, tIdr)) + { + closeEncoder(); // opened again with the next frame + } + } +} + +bool streamLiveEncoder::openEncoder(int width, int height) +{ + const AVCodec * tCodec = avcodec_find_encoder_by_name("libx264"); + if (tCodec == NULL) + { + tCodec = avcodec_find_encoder(AV_CODEC_ID_H264); + } + if (tCodec == NULL) + { + LOG_ERROR("No H264 encoder in libavcodec: live view of the processed frames is not possible"); + return false; + } + m_pCtx = avcodec_alloc_context3(tCodec); + if (m_pCtx == NULL) + { + return false; + } + m_nWidth = width & ~1; // 4:2:0 needs even sizes + m_nHeight = height & ~1; + m_pCtx->width = m_nWidth; + m_pCtx->height = m_nHeight; + m_pCtx->pix_fmt = AV_PIX_FMT_YUV420P; + m_pCtx->time_base = AVRational {1, 90000}; + m_pCtx->framerate = AVRational {m_nFps, 1}; + m_pCtx->gop_size = m_nFps * 2; // a new viewer waits at most 2 s (and gets one at once, see run()) + m_pCtx->max_b_frames = 0; // WebRTC / fMP4 writer: dts = pts + m_pCtx->bit_rate = (int64_t) m_nBitrateKbps * 1000; + m_pCtx->rc_max_rate = m_pCtx->bit_rate; + m_pCtx->rc_buffer_size = (int) m_pCtx->bit_rate; // 1 s + m_pCtx->thread_count = 2; + m_pCtx->profile = FF_PROFILE_H264_CONSTRAINED_BASELINE; + if (strcmp(tCodec->name, "libx264") == 0) + { + av_opt_set(m_pCtx->priv_data, "preset", "veryfast", 0); + av_opt_set(m_pCtx->priv_data, "tune", "zerolatency", 0); + av_opt_set(m_pCtx->priv_data, "profile", "baseline", 0); + av_opt_set(m_pCtx->priv_data, "x264-params", "repeat-headers=1", 0); // SPS / PPS with every IDR + av_opt_set(m_pCtx->priv_data, "forced-idr", "1", 0); // a forced key frame is an IDR + } + int tRet = avcodec_open2(m_pCtx, tCodec, NULL); + if (tRet < 0) + { + char tE[128], tB[256]; + av_strerror(tRet, tE, sizeof(tE)); + snprintf(tB, sizeof(tB), "Cannot open the H264 encoder %s: %s", tCodec->name, tE); + LOG_ERROR(tB); + avcodec_free_context(&m_pCtx); + return false; + } + m_pFrame = av_frame_alloc(); + m_pPacket = av_packet_alloc(); + m_pSws = sws_getContext(width, height, AV_PIX_FMT_BGR24, m_nWidth, m_nHeight, AV_PIX_FMT_YUV420P, SWS_BILINEAR, NULL, NULL, NULL); + if (m_pFrame == NULL || m_pPacket == NULL || m_pSws == NULL) + { + LOG_ERROR("Live encoder: allocation failed"); + closeEncoder(); + return false; + } + m_pFrame->format = AV_PIX_FMT_YUV420P; + m_pFrame->width = m_nWidth; + m_pFrame->height = m_nHeight; + if (av_frame_get_buffer(m_pFrame, 32) < 0) + { + closeEncoder(); + return false; + } + if (m_pCtx->extradata != NULL && m_pCtx->extradata_size > 0) + { + m_oFeeder.setExtradata(m_pCtx->extradata, m_pCtx->extradata_size); + } + char tB[200]; + snprintf(tB, sizeof(tB), "H264 encoder %s opened: %dx%d, %d fps, %d kbit/s", tCodec->name, m_nWidth, m_nHeight, m_nFps, m_nBitrateKbps); + LOG(tB); + return true; +} + +void streamLiveEncoder::closeEncoder() +{ + if (m_pSws != NULL) + { + sws_freeContext(m_pSws); + m_pSws = NULL; + } + av_frame_free(&m_pFrame); + av_packet_free(&m_pPacket); + avcodec_free_context(&m_pCtx); + m_nWidth = 0; + m_nHeight = 0; +} + +bool streamLiveEncoder::encode(const cv::Mat & bgr, bool forceIdr) +{ + if (av_frame_make_writable(m_pFrame) < 0) + { + return false; + } + const uint8_t * tSrc[1] = {bgr.data}; + int tStep[1] = {(int) bgr.step[0]}; + sws_scale(m_pSws, tSrc, tStep, 0, bgr.rows, m_pFrame->data, m_pFrame->linesize); + int64_t tNowUs = mtx::nowUs(); + m_pFrame->pts = tNowUs * 9 / 100; // 90 kHz wall clock: the real frame timing + m_pFrame->pict_type = forceIdr ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_NONE; + int tRet = avcodec_send_frame(m_pCtx, m_pFrame); + if (tRet < 0) + { + LOG_ERROR("Live encoder: send frame failed"); + return false; + } + while (true) + { + tRet = avcodec_receive_packet(m_pCtx, m_pPacket); + if (tRet == AVERROR(EAGAIN) || tRet == AVERROR_EOF) + { + break; + } + if (tRet < 0) + { + LOG_ERROR("Live encoder: receive packet failed"); + return false; + } + int64_t tPtsUs = (m_pPacket->pts != AV_NOPTS_VALUE) ? m_pPacket->pts * 100 / 9 : tNowUs; + if (m_oFeeder.avccLengthSize() > 0) + { + m_oFeeder.pushAvcc(m_pPacket->data, m_pPacket->size, m_oFeeder.avccLengthSize(), tPtsUs); + } + else + { + m_oFeeder.pushAnnexB(m_pPacket->data, m_pPacket->size, tPtsUs); + } + av_packet_unref(m_pPacket); + } + m_nFrameIndex++; + return true; +} + +#undef LOG +#undef LOG_ERROR + +#endif // !LRF_PROXY_ONLY diff --git a/lib/App/common/streamLiveEncoder.h b/lib/App/common/streamLiveEncoder.h new file mode 100644 index 00000000..4b1992b5 --- /dev/null +++ b/lib/App/common/streamLiveEncoder.h @@ -0,0 +1,68 @@ +#ifndef __STREAM_LIVE_ENCODER_HEADER__ +#define __STREAM_LIVE_ENCODER_HEADER__ + +#ifndef LRF_PROXY_ONLY + +/* + Live view of the processed frames (kernelModuleEmbedVideo live_mode EVE_LIVE_ENCODE) + + streamHandler hands every processed frame (scaled, flipped, with the time stamp / label / logo / event + marks) to push(); the encoder thread encodes the newest one to H264 (libx264 when available, zero + latency, no B-frames, constrained baseline: every browser decodes it) and feeds the path (WebRTC + readers, recorder). A slow encoder drops frames, it never blocks the source. + Nothing is encoded while the path has no reader and does not record. A new reader gets an IDR at once. +*/ + +#include +#include +#include +#include + +#include "../../components/base/basicLIBAV.h" +#include "../../components/base/basicLogCollection.h" +#include "../../data/media/mtx/core/mediaPath.h" +#include "../../data/media/mtx/feeder/h264Feeder.h" + +class streamLiveEncoder +{ + public: + streamLiveEncoder(std::shared_ptr path, int fps, int bitrateKbps); + ~streamLiveEncoder(); + + // From the frame thread: copies the frame when the encoder wants one (frame rate, readers) + void push(const cv::Mat & bgr); + + private: + void run(); + bool openEncoder(int width, int height); + void closeEncoder(); + bool encode(const cv::Mat & bgr, bool forceIdr); + + basicLogCollection * m_pLog; + std::shared_ptr m_pPath; + mtx::H264Feeder m_oFeeder; + int m_nFps; + int m_nBitrateKbps; + + std::mutex m_mutex; + std::condition_variable m_cond; + cv::Mat m_mPending; + bool m_bHavePending; + bool m_bRun; + int64_t m_nNextFrameUs; // frame rate limit + std::thread m_thread; + + // encoder (encoder thread only) + AVCodecContext * m_pCtx; + AVFrame * m_pFrame; + AVPacket * m_pPacket; + SwsContext * m_pSws; + int m_nWidth; + int m_nHeight; + int64_t m_nFrameIndex; + size_t m_nLastReaders; + bool m_bOpenFailed; +}; + +#endif // !LRF_PROXY_ONLY +#endif diff --git a/lib/components/base/basicMediaDestination.h b/lib/components/base/basicMediaDestination.h index bd203e5d..17acd311 100644 --- a/lib/components/base/basicMediaDestination.h +++ b/lib/components/base/basicMediaDestination.h @@ -63,6 +63,34 @@ class basicMediaDestination { return false; } + + /* + Compressed H264 of the source, before it is decoded (live view / recording without re-encoding, + see streamHandler). A destination that does not need it ignores these calls. + */ + // Parameter sets: SPS / PPS NAL units (sprop-parameter-sets of the SDP) or libav extradata + // (Annex-B or avcC). Called when the source (re)connects, before the first packet. + virtual void pushEncodedParams(const uint8_t * data, size_t size, bool extradata, void * src = NULL) + { + if (data || size || extradata || src) return; + } + // One NAL unit without start code (RTP depacketizer, live555). marker: last NAL unit of the + // picture; synced: the presentation times are RTCP synchronised + virtual void pushEncodedNalu(const uint8_t * data, size_t size, int64_t ptUs, bool marker, bool synced, void * src = NULL) + { + if (data || size || ptUs || marker || synced || src) return; + } + // One access unit (libav packet): Annex-B, or length prefixed when the extradata was avcC. + // ptsUs < 0: not known + virtual void pushEncodedPacket(const uint8_t * data, size_t size, int64_t ptsUs, void * src = NULL) + { + if (data || size || ptsUs || src) return; + } + // The source lost its stream (it reconnects): the next data starts again with the parameters + virtual void encodedSourceStopped(void * src = NULL) + { + if (src) return; + } }; inline basicMediaDestination::basicMediaDestination() diff --git a/Projects/MediaMtx/internal/codecs/h264/h264.cpp b/lib/data/media/mtx/codecs/h264/h264.cpp similarity index 72% rename from Projects/MediaMtx/internal/codecs/h264/h264.cpp rename to lib/data/media/mtx/codecs/h264/h264.cpp index fd459d4c..ba6ee686 100644 --- a/Projects/MediaMtx/internal/codecs/h264/h264.cpp +++ b/lib/data/media/mtx/codecs/h264/h264.cpp @@ -356,5 +356,136 @@ Bytes buildAvcC(const Bytes & sps, const Bytes & pps) return r; } +std::vector splitAnnexB(const uint8_t * data, size_t size) +{ + std::vector tOut; + if (data == nullptr) + { + return tOut; + } + size_t tStart = std::string::npos; // first byte of the current NAL unit + size_t i = 0; + auto tEmit = [&](size_t end) { + // trailing zero bytes belong to the next start code (00 00 00 01) + while (end > tStart && data[end - 1] == 0) + { + end--; + } + if (end > tStart && (data[tStart] & 0x1f) != NALU_AUD) + { + tOut.emplace_back(data + tStart, data + end); + } + }; + while (i + 2 < size) + { + if (data[i] == 0 && data[i + 1] == 0 && data[i + 2] == 1) + { + if (tStart != std::string::npos) + { + tEmit(i); + } + i += 3; + tStart = i; + continue; + } + i++; + } + if (tStart != std::string::npos) + { + tEmit(size); + } + else if (size > 0) + { + tOut.emplace_back(data, data + size); // no start code: one bare NAL unit + } + return tOut; +} + +std::vector splitAvcc(const uint8_t * data, size_t size, int lengthSize) +{ + std::vector tOut; + if (data == nullptr || lengthSize < 1 || lengthSize > 4) + { + return tOut; + } + size_t i = 0; + while (i + (size_t) lengthSize <= size) + { + size_t tLen = 0; + for (int k = 0; k < lengthSize; k++) + { + tLen = (tLen << 8) | data[i + k]; + } + i += lengthSize; + if (tLen == 0 || i + tLen > size) + { + break; + } + if ((data[i] & 0x1f) != NALU_AUD) + { + tOut.emplace_back(data + i, data + i + tLen); + } + i += tLen; + } + return tOut; +} + +std::vector parameterSetsFromExtradata(const uint8_t * data, size_t size, int * avccLengthSize) +{ + std::vector tOut; + if (avccLengthSize) + { + *avccLengthSize = 0; + } + if (data == nullptr || size < 4) + { + return tOut; + } + if (data[0] != 1) + { + // Annex-B extradata (RTSP / raw H264 sources) + for (Bytes & n : splitAnnexB(data, size)) + { + int t = naluType(n); + if (t == NALU_SPS || t == NALU_PPS) + { + tOut.push_back(std::move(n)); + } + } + return tOut; + } + // AVCDecoderConfigurationRecord + if (size < 7) + { + return tOut; + } + if (avccLengthSize) + { + *avccLengthSize = (data[4] & 0x03) + 1; + } + size_t i = 5; + for (int tKind = 0; tKind < 2; tKind++) + { + if (i >= size) + { + break; + } + int tCount = (tKind == 0) ? (data[i] & 0x1f) : data[i]; + i++; + for (int k = 0; k < tCount && i + 2 <= size; k++) + { + size_t tLen = ((size_t) data[i] << 8) | data[i + 1]; + i += 2; + if (i + tLen > size) + { + return tOut; + } + tOut.emplace_back(data + i, data + i + tLen); + i += tLen; + } + } + return tOut; +} + } // namespace h264 } // namespace mtx diff --git a/Projects/MediaMtx/internal/codecs/h264/h264.h b/lib/data/media/mtx/codecs/h264/h264.h similarity index 69% rename from Projects/MediaMtx/internal/codecs/h264/h264.h rename to lib/data/media/mtx/codecs/h264/h264.h index 83c3d59d..3d43fcf0 100644 --- a/Projects/MediaMtx/internal/codecs/h264/h264.h +++ b/lib/data/media/mtx/codecs/h264/h264.h @@ -44,6 +44,12 @@ std::string profileLevelId(const Bytes & sps); std::vector decodeSpropParameterSets(const char * sprop); // Annex-B byte stream (00 00 00 01 start codes) Bytes toAnnexB(const std::vector & nalus); +// Annex-B byte stream -> NAL units (3 or 4 byte start codes; AUD and empty units are dropped) +std::vector splitAnnexB(const uint8_t * data, size_t size); +// Length prefixed NAL units (lengthSize 1..4, MP4 / avcC style) -> NAL units +std::vector splitAvcc(const uint8_t * data, size_t size, int lengthSize = 4); +// SPS / PPS of an avcC record (libav extradata of MP4 sources) or of Annex-B extradata +std::vector parameterSetsFromExtradata(const uint8_t * data, size_t size, int * avccLengthSize = nullptr); // AVCC: 4 byte big-endian lengths (MP4 samples) Bytes toAvcc(const std::vector & nalus); // AVCDecoderConfigurationRecord (avcC box payload) diff --git a/lib/data/media/mtx/conf/serverConf.cpp b/lib/data/media/mtx/conf/serverConf.cpp new file mode 100644 index 00000000..426ad7fa --- /dev/null +++ b/lib/data/media/mtx/conf/serverConf.cpp @@ -0,0 +1,83 @@ +#include "serverConf.h" + +#include + +namespace mtx { + +bool parseDurationMs(const std::string & s, int64_t & ms) +{ + if (s.empty()) + { + return false; + } + char * tEnd = nullptr; + double tV = strtod(s.c_str(), &tEnd); + if (tEnd == s.c_str() || tV < 0) + { + return false; + } + std::string tUnit(tEnd); + double tMul; + if (tUnit.empty() || tUnit == "s") + { + tMul = 1000.0; + } + else if (tUnit == "ms") + { + tMul = 1.0; + } + else if (tUnit == "m") + { + tMul = 60000.0; + } + else if (tUnit == "h") + { + tMul = 3600000.0; + } + else + { + return false; + } + ms = (int64_t) (tV * tMul + 0.5); + return true; +} + +bool splitHostPort(const std::string & addr, std::string & host, uint16_t & port) +{ + size_t tColon = addr.rfind(':'); + if (tColon == std::string::npos) + { + return false; + } + host = addr.substr(0, tColon); + int tPort = atoi(addr.c_str() + tColon + 1); + if (tPort <= 0 || tPort > 65535) + { + return false; + } + port = (uint16_t) tPort; + if (host.size() >= 2 && host.front() == '[' && host.back() == ']') + { + host = host.substr(1, host.size() - 2); + } + return true; +} + +std::string hideCredentials(const std::string & url) +{ + size_t tScheme = url.find("://"); + if (tScheme == std::string::npos) + { + return url; + } + size_t tHostStart = tScheme + 3; + size_t tSlash = url.find('/', tHostStart); + size_t tAt = url.rfind('@', tSlash == std::string::npos ? url.size() : tSlash); + if (tAt == std::string::npos || tAt < tHostStart) + { + return url; + } + return url.substr(0, tHostStart) + url.substr(tAt + 1); +} + +} // namespace mtx diff --git a/lib/data/media/mtx/conf/serverConf.h b/lib/data/media/mtx/conf/serverConf.h new file mode 100644 index 00000000..05cdae9e --- /dev/null +++ b/lib/data/media/mtx/conf/serverConf.h @@ -0,0 +1,39 @@ +/* + MediaMtx (C++) - settings of the reusable parts (WebRTC server, recorder) + + Shared by the stand-alone server (Projects/MediaMtx, which adds the command line, the paths file, the + RTSP sources and the API) and la_mojo (kernelModuleEmbedVideo, which feeds the streams itself). + The names follow MediaMTX (webrtcAddress, recordPath, ...). +*/ +#pragma once + +#include +#include +#include + +namespace mtx { + +struct ServerConf +{ + // WebRTC (WHEP) + std::string webrtcAddress = ":8889"; + std::string webrtcAllowOrigin = "*"; + std::vector webrtcICEServers; // e.g. stun:stun.l.google.com:19302 + std::string webrtcBindAddress; // ICE: bind to this local address (default: all) + uint16_t webrtcUDPPortMin = 8189; + uint16_t webrtcUDPPortMax = 8289; + + // recording + std::string recordPath = "./recordings/%path/%Y-%m-%d_%H-%M-%S-%f"; + int64_t recordSegmentDurationMs = 60000; + int64_t recordPartDurationMs = 1000; +}; + +// "60s", "1m", "500ms", "1h", "1.5s"; plain number = seconds +bool parseDurationMs(const std::string & s, int64_t & ms); +// "host:port" / ":port" -> host ("" = any) and port +bool splitHostPort(const std::string & addr, std::string & host, uint16_t & port); +// rtsp://user:pass@host/... -> rtsp://host/... (for logs) +std::string hideCredentials(const std::string & url); + +} // namespace mtx diff --git a/lib/data/media/mtx/core/mediaPath.cpp b/lib/data/media/mtx/core/mediaPath.cpp new file mode 100644 index 00000000..387d091f --- /dev/null +++ b/lib/data/media/mtx/core/mediaPath.cpp @@ -0,0 +1,145 @@ +#include "mediaPath.h" + +#include "../recorder/recorder.h" + +namespace mtx { + +MediaPath::MediaPath(const std::string & name, bool record, const ServerConf & global) : LogParent("[path " + name + "] "), m_sName(name), m_bRecord(record), m_global(global) {} + +MediaPath::~MediaPath() +{ + sourceSetNotReady(); +} + +PathInfo MediaPath::info() const +{ + std::lock_guard lock(m_mutex); + PathInfo tI; + tI.name = m_sName; + tI.record = m_bRecord; + tI.ready = (m_pStream != nullptr); + tI.readySinceUs = m_tReadySinceUs; + tI.readers = m_readers.size(); + if (m_pStream) + { + tI.desc = m_pStream->desc(); + tI.bytesReceived = m_pStream->bytesReceived(); + } + return tI; +} + +bool MediaPath::isReady() const +{ + std::lock_guard lock(m_mutex); + return m_pStream != nullptr; +} + +size_t MediaPath::readerCount() const +{ + std::lock_guard lock(m_mutex); + return m_readers.size(); +} + +bool MediaPath::recording() const +{ + std::lock_guard lock(m_mutex); + return m_bRecord; +} + +void MediaPath::setRecord(bool record) +{ + std::unique_ptr tOld; + { + std::lock_guard lock(m_mutex); + if (m_bRecord == record) + { + return; + } + m_bRecord = record; + if (! record) + { + tOld = std::move(m_pRecorder); + } + else if (m_pStream) + { + m_pRecorder.reset(new Recorder(m_sName, m_global, m_pStream, this)); + m_pRecorder->start(); + } + } + tOld.reset(); // closes the segment (not under the lock) + log(LogLevel::Info, "recording %s", record ? "enabled" : "disabled"); +} + +bool MediaPath::addReader(PathReader * r, StreamDesc & desc, std::string & err) +{ + std::lock_guard lock(m_mutex); + if (! m_pStream) + { + err = "no stream is available on path '" + m_sName + "'"; + return false; + } + desc = m_pStream->desc(); + m_readers.insert(r); + m_pStream->addReader(r); + return true; +} + +void MediaPath::removeReader(PathReader * r) +{ + std::lock_guard lock(m_mutex); + if (m_readers.erase(r) > 0 && m_pStream) + { + m_pStream->removeReader(r); + } +} + +void MediaPath::sourceSetReady(const StreamDesc & desc) +{ + std::lock_guard lock(m_mutex); + m_pStream = std::make_shared(desc); + m_tReadySinceUs = nowUs(); + log(LogLevel::Info, "stream is available and online, 1 track (H264 %dx%d)", desc.width, desc.height); + if (m_bRecord) + { + m_pRecorder.reset(new Recorder(m_sName, m_global, m_pStream, this)); + m_pRecorder->start(); + } +} + +void MediaPath::sourceSetNotReady() +{ + std::unique_ptr tRec; + { + std::lock_guard lock(m_mutex); + if (! m_pStream) + { + return; + } + for (PathReader * r : m_readers) + { + m_pStream->removeReader(r); + r->pathNotReady(); + } + m_readers.clear(); + tRec = std::move(m_pRecorder); + m_pStream.reset(); + m_tReadySinceUs = 0; + } + tRec.reset(); // closes the segment + log(LogLevel::Info, "stream is not available anymore"); +} + +void MediaPath::sourceWriteUnit(const UnitPtr & unit) +{ + std::shared_ptr tStream; + { + std::lock_guard lock(m_mutex); + tStream = m_pStream; + } + if (tStream) + { + tStream->writeUnit(unit); + } +} + +} // namespace mtx diff --git a/lib/data/media/mtx/core/mediaPath.h b/lib/data/media/mtx/core/mediaPath.h new file mode 100644 index 00000000..eea61677 --- /dev/null +++ b/lib/data/media/mtx/core/mediaPath.h @@ -0,0 +1,100 @@ +/* + MediaMtx (C++) - media path (MediaMTX: internal/core/path.go, without the source) + + A path has a stream while its source is ready, an optional recorder and the readers (WebRTC sessions). + The source is whatever feeds it: an RTSP client (Projects/MediaMtx) or la_mojo's streamHandler + (camera H264 as it is, or the processed frames encoded again). +*/ +#pragma once + +#include +#include +#include +#include + +#include "../conf/serverConf.h" +#include "../logger/logger.h" +#include "../stream/stream.h" + +namespace mtx { + +class Recorder; + +class PathReader : public StreamReader +{ + public: + // The source of the path is gone: the reader must close (called with the path locked: do not block, + // do not call back into the path) + virtual void pathNotReady() = 0; +}; + +// What a source calls on its path +class SourceParent +{ + public: + virtual ~SourceParent() {} + // The source has the codec parameters: the path creates its stream + virtual void sourceSetReady(const StreamDesc & desc) = 0; + // The source lost its connection: the path destroys its stream + virtual void sourceSetNotReady() = 0; + // A unit of the source (called from the source thread) + virtual void sourceWriteUnit(const UnitPtr & unit) = 0; +}; + +struct PathInfo +{ + std::string name; + std::string source; + bool record = false; + bool ready = false; + int64_t readySinceUs = 0; + StreamDesc desc; + size_t readers = 0; + uint64_t bytesReceived = 0; +}; + +class MediaPath : public SourceParent, public LogParent +{ + public: + MediaPath(const std::string & name, bool record, const ServerConf & global); + ~MediaPath() override; + + const std::string & name() const { return m_sName; } + PathInfo info() const; + bool isReady() const; + size_t readerCount() const; + bool recording() const; + // Starts / stops the recorder (a running stream is recorded from its next IDR) + void setRecord(bool record); + + // false + err when the path has no stream + bool addReader(PathReader * r, StreamDesc & desc, std::string & err); + void removeReader(PathReader * r); + + // SourceParent + void sourceSetReady(const StreamDesc & desc) override; + void sourceSetNotReady() override; + void sourceWriteUnit(const UnitPtr & unit) override; + + protected: + std::string m_sName; + bool m_bRecord; + ServerConf m_global; + + private: + mutable std::mutex m_mutex; + std::shared_ptr m_pStream; + std::unique_ptr m_pRecorder; + std::set m_readers; + int64_t m_tReadySinceUs = 0; +}; + +// Finds a path by name (the WebRTC server asks it for the path of a WHEP request) +class PathProvider +{ + public: + virtual ~PathProvider() {} + virtual std::shared_ptr findPath(const std::string & name) const = 0; +}; + +} // namespace mtx diff --git a/lib/data/media/mtx/feeder/h264Feeder.cpp b/lib/data/media/mtx/feeder/h264Feeder.cpp new file mode 100644 index 00000000..010ddfe1 --- /dev/null +++ b/lib/data/media/mtx/feeder/h264Feeder.cpp @@ -0,0 +1,209 @@ +#include "h264Feeder.h" + +#include + +#include "../codecs/h264/h264.h" + +namespace mtx { + +void H264Feeder::setParent(SourceParent * parent) +{ + std::lock_guard lock(m_mutex); + if (parent == m_pParent) + { + return; + } + if (m_pParent != nullptr && m_bReady) + { + m_pParent->sourceSetNotReady(); + } + m_pParent = parent; + m_bReady = false; + m_vNalus.clear(); +} + +void H264Feeder::setParameterSets(const std::vector & nalus) +{ + std::lock_guard lock(m_mutex); + for (const Bytes & n : nalus) + { + if (h264::naluType(n) == h264::NALU_SPS) + { + m_sps = n; + } + else if (h264::naluType(n) == h264::NALU_PPS) + { + m_pps = n; + } + } +} + +void H264Feeder::setExtradata(const uint8_t * data, size_t size) +{ + int tLen = 0; + std::vector tSets = h264::parameterSetsFromExtradata(data, size, &tLen); + m_nAvccLengthSize = tLen; + setParameterSets(tSets); +} + +void H264Feeder::pushNalu(const uint8_t * data, size_t size, int64_t ptUs, bool marker, bool synced) +{ + std::lock_guard lock(m_mutex); + // A new presentation time starts a new unit (a camera that does not set the marker bit). Small changes + // are not a new unit: every RTCP sender report moves live555's mapping a little, also within a picture. + if (! m_vNalus.empty() && (ptUs - m_nPtUs > 2000 || m_nPtUs - ptUs > 2000)) + { + flushLocked(); + } + if (data != nullptr && size > 0) + { + int tType = data[0] & 0x1f; + if (tType != h264::NALU_AUD && tType != 0) + { + m_vNalus.emplace_back(data, data + size); + } + } + if (m_vNalus.size() <= 1) + { + m_nPtUs = ptUs; // the time of the unit is the time of its first NAL unit + m_bSynced = synced; + } + if (marker) + { + flushLocked(); + } +} + +void H264Feeder::pushAnnexB(const uint8_t * data, size_t size, int64_t ptsUs) +{ + std::vector tNalus = h264::splitAnnexB(data, size); + std::lock_guard lock(m_mutex); + m_bSynced = false; + unitLocked(std::move(tNalus), ptsUs >= 0 ? ptsUs : nowUs(), nowUs()); +} + +void H264Feeder::pushAvcc(const uint8_t * data, size_t size, int lengthSize, int64_t ptsUs) +{ + std::vector tNalus = h264::splitAvcc(data, size, lengthSize); + std::lock_guard lock(m_mutex); + m_bSynced = false; + unitLocked(std::move(tNalus), ptsUs >= 0 ? ptsUs : nowUs(), nowUs()); +} + +void H264Feeder::flushLocked() +{ + if (m_vNalus.empty()) + { + return; + } + std::vector tNalus; + tNalus.swap(m_vNalus); + unitLocked(std::move(tNalus), m_nPtUs, m_nPtUs); +} + +void H264Feeder::unitLocked(std::vector && nalus, int64_t ptUs, int64_t wallUs) +{ + if (nalus.empty() || m_pParent == nullptr) + { + return; + } + bool tIdr = false; + for (const Bytes & n : nalus) + { + int t = h264::naluType(n); + if (t == h264::NALU_SPS) + { + m_sps = n; + } + else if (t == h264::NALU_PPS) + { + m_pps = n; + } + else if (t == h264::NALU_IDR) + { + tIdr = true; + } + } + // 90 kHz pts starting at 0. A jump (RTCP synchronisation, a restarted source, a clock step) is replaced + // by one frame interval: the readers need increasing time stamps. + int64_t tRaw = ptUs * 9 / 100; + if (! m_bHavePts) + { + m_bHavePts = true; + m_bLastSynced = m_bSynced; + m_nOffset = -tRaw; + } + else if (m_bSynced != m_bLastSynced) + { + m_bLastSynced = m_bSynced; + m_nOffset = m_nLastPts + m_nLastDelta - tRaw; + } + int64_t tPts = tRaw + m_nOffset; + if (tPts <= m_nLastPts && m_nUnits > 0) + { + if (tPts == m_nLastPts) + { + tPts = m_nLastPts + 1; // same time stamp (should not happen): keep increasing + } + else + { + m_nOffset = m_nLastPts + m_nLastDelta - tRaw; + tPts = tRaw + m_nOffset; + } + } + else if (tPts - m_nLastPts >= 90000 * 5 && m_nUnits > 0) + { + m_nOffset = m_nLastPts + m_nLastDelta - tRaw; // a gap of 5 s or more: a clock step, not a pause + tPts = tRaw + m_nOffset; + } + else if (m_nUnits > 0 && tPts - m_nLastPts < 90000) + { + m_nLastDelta = tPts - m_nLastPts; + } + m_nLastPts = tPts; + + if (! m_bReady) + { + if (m_sps.empty() || m_pps.empty()) + { + return; // a reader cannot use the stream without the codec parameters + } + StreamDesc tDesc; + h264::SpsInfo tInfo; + tDesc.sps = m_sps; + tDesc.pps = m_pps; + if (h264::parseSps(m_sps, tInfo)) + { + tDesc.width = tInfo.width; + tDesc.height = tInfo.height; + } + m_bReady = true; + m_pParent->sourceSetReady(tDesc); + } + auto tUnit = std::make_shared(); + tUnit->pts = tPts; + tUnit->ntpUs = wallUs; + tUnit->idr = tIdr; + tUnit->nalus = std::move(nalus); + m_nUnits++; + m_pParent->sourceWriteUnit(tUnit); +} + +void H264Feeder::reset() +{ + std::lock_guard lock(m_mutex); + m_vNalus.clear(); + if (m_pParent != nullptr && m_bReady) + { + m_pParent->sourceSetNotReady(); + } + m_bReady = false; +} + +bool H264Feeder::ready() const +{ + std::lock_guard lock(m_mutex); + return m_bReady; +} + +} // namespace mtx diff --git a/lib/data/media/mtx/feeder/h264Feeder.h b/lib/data/media/mtx/feeder/h264Feeder.h new file mode 100644 index 00000000..28d38d9a --- /dev/null +++ b/lib/data/media/mtx/feeder/h264Feeder.h @@ -0,0 +1,77 @@ +/* + MediaMtx (C++) - H264 feeder + + Turns the H264 an application already receives into units of a path (MediaPath): + - NAL units one at a time, as an RTP depacketizer (live555) gives them: grouped into access units by + the RTP marker bit / a new presentation time; + - whole access units in Annex-B (libav RTSP demuxer, H264 encoders) or length prefixed (MP4 / avcC). + The pts is made continuous (90 kHz, starting at 0, always increasing): a reader (recorder, WebRTC) sees + no jumps when the presentation times move onto the RTCP clock or a source restarts. + The path becomes ready when SPS and PPS are known (out of band from the SDP / extradata, or in-band), + and not ready on reset() (the source stopped). + Thread safe: the source thread pushes, any thread may reset() / setParent(). +*/ +#pragma once + +#include +#include +#include + +#include "../core/mediaPath.h" +#include "../unit/unit.h" + +namespace mtx { + +class H264Feeder +{ + public: + explicit H264Feeder(SourceParent * parent = nullptr) : m_pParent(parent) {} + ~H264Feeder() { reset(); } + + // The path to feed (nullptr: none). The previous path is set not ready. + void setParent(SourceParent * parent); + + // Out of band parameter sets (sprop-parameter-sets of the SDP, libav extradata) + void setParameterSets(const std::vector & nalus); + void setExtradata(const uint8_t * data, size_t size); + + // One NAL unit (no start code). ptUs: presentation time (us); marker: last NAL unit of the access + // unit (RTP marker bit); synced: the presentation times are RTCP synchronised (a change = a jump) + void pushNalu(const uint8_t * data, size_t size, int64_t ptUs, bool marker, bool synced = false); + // One access unit. ptsUs: presentation time (us, any origin); < 0: use the wall clock + void pushAnnexB(const uint8_t * data, size_t size, int64_t ptsUs); + void pushAvcc(const uint8_t * data, size_t size, int lengthSize, int64_t ptsUs); + // length prefix size of the avcC extradata (0: the packets are Annex-B) + int avccLengthSize() const { return m_nAvccLengthSize; } + + // The source stopped (or reconnects): the path is set not ready, the parameter sets are kept + void reset(); + bool ready() const; + uint64_t units() const { return m_nUnits; } + + private: + void flushLocked(); + void unitLocked(std::vector && nalus, int64_t ptUs, int64_t wallUs); + + mutable std::mutex m_mutex; + SourceParent * m_pParent = nullptr; + Bytes m_sps; + Bytes m_pps; + bool m_bReady = false; + int m_nAvccLengthSize = 0; + uint64_t m_nUnits = 0; + + // NAL unit assembly + std::vector m_vNalus; + int64_t m_nPtUs = 0; + bool m_bSynced = false; + + // pts continuity + bool m_bHavePts = false; + bool m_bLastSynced = false; + int64_t m_nOffset = 0; + int64_t m_nLastPts = 0; + int64_t m_nLastDelta = 3000; +}; + +} // namespace mtx diff --git a/Projects/MediaMtx/internal/logger/logger.cpp b/lib/data/media/mtx/logger/logger.cpp similarity index 84% rename from Projects/MediaMtx/internal/logger/logger.cpp rename to lib/data/media/mtx/logger/logger.cpp index 1c5f51ed..f85d33f1 100644 --- a/Projects/MediaMtx/internal/logger/logger.cpp +++ b/lib/data/media/mtx/logger/logger.cpp @@ -24,6 +24,12 @@ void Logger::setDestinations(bool toStdout, const std::string & file) m_file = file; } +void Logger::setSink(Sink sink) +{ + std::lock_guard lock(m_mutex); + m_sink = std::move(sink); +} + void Logger::log(LogLevel level, const char * fmt, ...) { va_list ap; @@ -43,7 +49,8 @@ void Logger::vlog(LogLevel level, const char * fmt, va_list ap) time_t tNow = time(nullptr); struct tm tTm; localtime_r(&tNow, &tTm); - int tLen = (int) strftime(tLine, sizeof(tLine), "%Y/%m/%d %H:%M:%S ", &tTm); + int tLen = (int) strftime(tLine, sizeof(tLine), "%Y/%m/%d %H:%M:%S ", &tTm); + int tStart = tLen; // the message without the time stamp starts here (sink) tLen += snprintf(tLine + tLen, sizeof(tLine) - tLen, "%s ", s_tags[(int) level]); if (tLen < (int) sizeof(tLine)) { @@ -58,6 +65,12 @@ void Logger::vlog(LogLevel level, const char * fmt, va_list ap) tLine[tLen] = 0; std::lock_guard lock(m_mutex); + if (m_sink) + { + tLine[tLen - 1] = 0; + m_sink(level, tLine + tStart); + tLine[tLen - 1] = '\n'; + } if (m_toStdout) { fwrite(tLine, 1, tLen, stdout); diff --git a/Projects/MediaMtx/internal/logger/logger.h b/lib/data/media/mtx/logger/logger.h similarity index 84% rename from Projects/MediaMtx/internal/logger/logger.h rename to lib/data/media/mtx/logger/logger.h index f4fe49bc..329c307e 100644 --- a/Projects/MediaMtx/internal/logger/logger.h +++ b/lib/data/media/mtx/logger/logger.h @@ -6,6 +6,7 @@ #pragma once #include +#include #include #include @@ -24,6 +25,10 @@ class Logger // by another process (la_mojo cleans the log above 40 KB). void setDestinations(bool toStdout, const std::string & file); + // Every line (without the time stamp and the new line) also goes to this function, e.g. to the + // application's log (la_mojo: basicLogCollection). Empty: none. + typedef std::function Sink; + void setSink(Sink sink); void log(LogLevel level, const char * fmt, ...) __attribute__((format(printf, 3, 4))); void vlog(LogLevel level, const char * fmt, va_list ap); @@ -33,6 +38,7 @@ class Logger LogLevel m_level = LogLevel::Info; bool m_toStdout = true; std::string m_file; + Sink m_sink; }; // Prefixes every line with a tag, e.g. "[path stream_3] [RTSP source] " diff --git a/Projects/MediaMtx/internal/protocols/httpp/httpServer.cpp b/lib/data/media/mtx/protocols/httpp/httpServer.cpp similarity index 99% rename from Projects/MediaMtx/internal/protocols/httpp/httpServer.cpp rename to lib/data/media/mtx/protocols/httpp/httpServer.cpp index a4b6f6ac..f0068f5d 100644 --- a/Projects/MediaMtx/internal/protocols/httpp/httpServer.cpp +++ b/lib/data/media/mtx/protocols/httpp/httpServer.cpp @@ -13,7 +13,7 @@ #include -#include "../../conf/conf.h" +#include "../../conf/serverConf.h" namespace mtx { diff --git a/Projects/MediaMtx/internal/protocols/httpp/httpServer.h b/lib/data/media/mtx/protocols/httpp/httpServer.h similarity index 100% rename from Projects/MediaMtx/internal/protocols/httpp/httpServer.h rename to lib/data/media/mtx/protocols/httpp/httpServer.h diff --git a/Projects/MediaMtx/internal/recorder/fmp4Writer.cpp b/lib/data/media/mtx/recorder/fmp4Writer.cpp similarity index 100% rename from Projects/MediaMtx/internal/recorder/fmp4Writer.cpp rename to lib/data/media/mtx/recorder/fmp4Writer.cpp diff --git a/Projects/MediaMtx/internal/recorder/fmp4Writer.h b/lib/data/media/mtx/recorder/fmp4Writer.h similarity index 100% rename from Projects/MediaMtx/internal/recorder/fmp4Writer.h rename to lib/data/media/mtx/recorder/fmp4Writer.h diff --git a/Projects/MediaMtx/internal/recorder/recorder.cpp b/lib/data/media/mtx/recorder/recorder.cpp similarity index 95% rename from Projects/MediaMtx/internal/recorder/recorder.cpp rename to lib/data/media/mtx/recorder/recorder.cpp index 3f22555c..0be45bfa 100644 --- a/Projects/MediaMtx/internal/recorder/recorder.cpp +++ b/lib/data/media/mtx/recorder/recorder.cpp @@ -4,7 +4,7 @@ namespace mtx { -Recorder::Recorder(const std::string & pathName, const Conf & global, std::shared_ptr stream, const LogParent * pathLog) +Recorder::Recorder(const std::string & pathName, const ServerConf & global, std::shared_ptr stream, const LogParent * pathLog) : LogParent(pathLog->logPrefix() + "[recorder] "), m_sPath(pathName), m_global(global), m_pStream(std::move(stream)), m_reader(this, 1024) { } diff --git a/Projects/MediaMtx/internal/recorder/recorder.h b/lib/data/media/mtx/recorder/recorder.h similarity index 82% rename from Projects/MediaMtx/internal/recorder/recorder.h rename to lib/data/media/mtx/recorder/recorder.h index 9d6f6f4b..44106bd7 100644 --- a/Projects/MediaMtx/internal/recorder/recorder.h +++ b/lib/data/media/mtx/recorder/recorder.h @@ -11,7 +11,7 @@ #include #include -#include "../conf/conf.h" +#include "../conf/serverConf.h" #include "../logger/logger.h" #include "../stream/stream.h" #include "fmp4Writer.h" @@ -21,7 +21,7 @@ namespace mtx { class Recorder : public LogParent { public: - Recorder(const std::string & pathName, const Conf & global, std::shared_ptr stream, const LogParent * pathLog); + Recorder(const std::string & pathName, const ServerConf & global, std::shared_ptr stream, const LogParent * pathLog); ~Recorder(); void start(); @@ -31,7 +31,7 @@ class Recorder : public LogParent void closeSegment(); std::string m_sPath; - Conf m_global; + ServerConf m_global; std::shared_ptr m_pStream; AsyncReader m_reader; Fmp4Writer m_writer; diff --git a/Projects/MediaMtx/internal/servers/webrtc/session.cpp b/lib/data/media/mtx/servers/webrtc/session.cpp similarity index 97% rename from Projects/MediaMtx/internal/servers/webrtc/session.cpp rename to lib/data/media/mtx/servers/webrtc/session.cpp index 56f9b8f5..ccbae3ab 100644 --- a/Projects/MediaMtx/internal/servers/webrtc/session.cpp +++ b/lib/data/media/mtx/servers/webrtc/session.cpp @@ -32,7 +32,7 @@ std::string fmtpValue(const std::string & fmtp, const std::string & key) } // namespace -WebrtcSession::WebrtcSession(const std::string & secret, std::shared_ptr path, const Conf & global, const std::string & remoteAddr) +WebrtcSession::WebrtcSession(const std::string & secret, std::shared_ptr path, const ServerConf & global, const std::string & remoteAddr) : LogParent("[WebRTC] [session " + secret.substr(0, 8) + "] "), m_sSecret(secret), m_pPath(std::move(path)), m_global(global), m_sRemote(remoteAddr), m_reader(this, 512) { @@ -197,7 +197,7 @@ bool WebrtcSession::create(const std::string & offerSdp, std::string & answer, i } answer = std::string(*tLocal); m_reader.start([this](const UnitPtr & u) { onUnit(u); }); - log(LogLevel::Info, "is reading from path '%s', 1 track (H264 %dx%d, payload type %d)", m_pPath->conf().name.c_str(), m_desc.width, m_desc.height, tPt); + log(LogLevel::Info, "is reading from path '%s', 1 track (H264 %dx%d, payload type %d)", m_pPath->name().c_str(), m_desc.width, m_desc.height, tPt); status = 201; return true; } @@ -244,7 +244,7 @@ void WebrtcSession::pathNotReady() m_bReading = false; if (! m_bClosing.exchange(true)) { - log(LogLevel::Info, "the source of path '%s' is gone", m_pPath->conf().name.c_str()); + log(LogLevel::Info, "the source of path '%s' is gone", m_pPath->name().c_str()); } } diff --git a/Projects/MediaMtx/internal/servers/webrtc/session.h b/lib/data/media/mtx/servers/webrtc/session.h similarity index 86% rename from Projects/MediaMtx/internal/servers/webrtc/session.h rename to lib/data/media/mtx/servers/webrtc/session.h index dc148495..fea6d272 100644 --- a/Projects/MediaMtx/internal/servers/webrtc/session.h +++ b/lib/data/media/mtx/servers/webrtc/session.h @@ -15,8 +15,8 @@ #include -#include "../../conf/conf.h" -#include "../../core/path.h" +#include "../../conf/serverConf.h" +#include "../../core/mediaPath.h" #include "../../logger/logger.h" #include "../../stream/stream.h" @@ -25,7 +25,7 @@ namespace mtx { class WebrtcSession : public PathReader, public LogParent { public: - WebrtcSession(const std::string & secret, std::shared_ptr path, const Conf & global, const std::string & remoteAddr); + WebrtcSession(const std::string & secret, std::shared_ptr path, const ServerConf & global, const std::string & remoteAddr); ~WebrtcSession() override; // Returns the answer SDP; on failure false + http status + error @@ -37,7 +37,7 @@ class WebrtcSession : public PathReader, public LogParent bool isClosing() const { return m_bClosing; } bool connectTimedOut(int64_t nowMsValue) const { return ! m_bConnected && nowMsValue - m_tCreated > 20000; } const std::string & secret() const { return m_sSecret; } - const std::string & pathName() const { return m_pPath->conf().name; } + const std::string & pathName() const { return m_pPath->name(); } // PathReader void push(const UnitPtr & unit) override { m_reader.push(unit); } @@ -47,8 +47,8 @@ class WebrtcSession : public PathReader, public LogParent void onUnit(const UnitPtr & unit); std::string m_sSecret; - std::shared_ptr m_pPath; - Conf m_global; + std::shared_ptr m_pPath; + ServerConf m_global; std::string m_sRemote; AsyncReader m_reader; std::shared_ptr m_pPc; diff --git a/Projects/MediaMtx/internal/servers/webrtc/webrtcServer.cpp b/lib/data/media/mtx/servers/webrtc/webrtcServer.cpp similarity index 97% rename from Projects/MediaMtx/internal/servers/webrtc/webrtcServer.cpp rename to lib/data/media/mtx/servers/webrtc/webrtcServer.cpp index 8f76eb8f..61edeff0 100644 --- a/Projects/MediaMtx/internal/servers/webrtc/webrtcServer.cpp +++ b/lib/data/media/mtx/servers/webrtc/webrtcServer.cpp @@ -61,7 +61,7 @@ std::vector splitPath(const std::string & p) } // namespace -WebrtcServer::WebrtcServer(const Conf & global, PathManager * paths) : LogParent("[WebRTC] "), m_global(global), m_pPaths(paths), m_http(this) {} +WebrtcServer::WebrtcServer(const ServerConf & global, PathProvider * paths) : LogParent("[WebRTC] "), m_global(global), m_pPaths(paths), m_http(this) {} WebrtcServer::~WebrtcServer() { @@ -202,7 +202,7 @@ void WebrtcServer::handle(const HttpRequest & req, HttpResponse & res) res.body = "invalid Content-Type"; return; } - std::shared_ptr tPath = m_pPaths->find(tPathName); + std::shared_ptr tPath = m_pPaths->findPath(tPathName); if (! tPath) { res.status = 404; diff --git a/Projects/MediaMtx/internal/servers/webrtc/webrtcServer.h b/lib/data/media/mtx/servers/webrtc/webrtcServer.h similarity index 84% rename from Projects/MediaMtx/internal/servers/webrtc/webrtcServer.h rename to lib/data/media/mtx/servers/webrtc/webrtcServer.h index cb1922a7..e8eb882c 100644 --- a/Projects/MediaMtx/internal/servers/webrtc/webrtcServer.h +++ b/lib/data/media/mtx/servers/webrtc/webrtcServer.h @@ -14,8 +14,8 @@ #include #include -#include "../../conf/conf.h" -#include "../../core/pathManager.h" +#include "../../conf/serverConf.h" +#include "../../core/mediaPath.h" #include "../../protocols/httpp/httpServer.h" #include "session.h" @@ -24,7 +24,7 @@ namespace mtx { class WebrtcServer : public LogParent { public: - WebrtcServer(const Conf & global, PathManager * paths); + WebrtcServer(const ServerConf & global, PathProvider * paths); ~WebrtcServer(); bool start(std::string & err); @@ -35,8 +35,8 @@ class WebrtcServer : public LogParent void handle(const HttpRequest & req, HttpResponse & res); void janitor(); - Conf m_global; - PathManager * m_pPaths; + ServerConf m_global; + PathProvider * m_pPaths; HttpServer m_http; mutable std::mutex m_mutex; std::map> m_sessions; diff --git a/Projects/MediaMtx/internal/stream/stream.cpp b/lib/data/media/mtx/stream/stream.cpp similarity index 100% rename from Projects/MediaMtx/internal/stream/stream.cpp rename to lib/data/media/mtx/stream/stream.cpp diff --git a/Projects/MediaMtx/internal/stream/stream.h b/lib/data/media/mtx/stream/stream.h similarity index 100% rename from Projects/MediaMtx/internal/stream/stream.h rename to lib/data/media/mtx/stream/stream.h diff --git a/Projects/MediaMtx/internal/unit/unit.h b/lib/data/media/mtx/unit/unit.h similarity index 100% rename from Projects/MediaMtx/internal/unit/unit.h rename to lib/data/media/mtx/unit/unit.h diff --git a/lib/data/media/video/videoAVLIBSource.cpp b/lib/data/media/video/videoAVLIBSource.cpp index 1709622b..02a846a5 100644 --- a/lib/data/media/video/videoAVLIBSource.cpp +++ b/lib/data/media/video/videoAVLIBSource.cpp @@ -940,6 +940,7 @@ void videoAVLIBSource::m_fThreadProc(void) uint8_t * pBGRbuffer = NULL; int dec_ret; char tB[2048]; + bool tEncodedParamsSent = false; // H264 extradata given to the destination (compressed feed) /** @todo Valgrind is reporting several important memory leaks in this method. * @@ -1021,6 +1022,22 @@ void videoAVLIBSource::m_fThreadProc(void) if (Packet->stream_index == m_pVideoState->m_iVideoStreamID) { m_pVideoState->m_bStatus = MS_PRESENT; + // The packet as it came from the camera: live view / recording without re-encoding + AVStream * tVS = m_pVideoState->m_pFormatCtx->streams[Packet->stream_index]; + if (m_pMediaDestination != NULL && tVS->codecpar->codec_id == AV_CODEC_ID_H264) + { + if (! tEncodedParamsSent) + { + tEncodedParamsSent = true; + m_pMediaDestination->pushEncodedParams(tVS->codecpar->extradata, tVS->codecpar->extradata_size, true, m_pOpaque); + }; + int64_t tPtsUs = -1; + if (Packet->pts != AV_NOPTS_VALUE) + { + tPtsUs = av_rescale_q(Packet->pts, tVS->time_base, AVRational {1, 1000000}); + }; + m_pMediaDestination->pushEncodedPacket(Packet->data, Packet->size, tPtsUs, m_pOpaque); + }; dec_ret = avcodec_send_packet(m_pVideoState->m_pCodecCtx, Packet); if (dec_ret < 0 && dec_ret != AVERROR(EAGAIN) /* && dec_ret != AVERROR_EOF */) { @@ -1085,6 +1102,11 @@ void videoAVLIBSource::m_fThreadProc(void) { if (dec_ret == AVERROR_EOF) { + if (m_pMediaDestination != NULL && tEncodedParamsSent) + { + m_pMediaDestination->encodedSourceStopped(m_pOpaque); + }; + tEncodedParamsSent = false; avformat_close_input(&m_pVideoState->m_pFormatCtx); if ((dec_ret = avformat_open_input(&m_pVideoState->m_pFormatCtx, m_pVideoState->m_pFileName, NULL, &m_pVideoState->m_pFormatOpts)) != 0) { @@ -1107,6 +1129,10 @@ void videoAVLIBSource::m_fThreadProc(void) #ifdef DEBUG LOG("Video Source Ended!"); #endif + if (m_pMediaDestination != NULL && tEncodedParamsSent) + { + m_pMediaDestination->encodedSourceStopped(m_pOpaque); + }; if ( Packet ) { av_packet_free( &Packet ); }; diff --git a/lib/data/media/video/videoLive555AVLibSource.cpp b/lib/data/media/video/videoLive555AVLibSource.cpp index 0a2c88ed..2beb48e0 100644 --- a/lib/data/media/video/videoLive555AVLibSource.cpp +++ b/lib/data/media/video/videoLive555AVLibSource.cpp @@ -498,6 +498,13 @@ void DummySink::afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes //LOG("FRM"); if ( presentationTime.tv_sec ) presentationTime.tv_sec = presentationTime.tv_sec; if ( numTruncatedBytes ) numTruncatedBytes = numTruncatedBytes; + if (m_eCodecProbe == AV_CODEC_ID_H264 && frameSize > 0) + { + // The NAL unit as it came from the camera: live view / recording without re-encoding + RTPSource * tRtp = m_sSubSession.rtpSource(); + int64_t tPt = (int64_t) presentationTime.tv_sec * 1000000 + presentationTime.tv_usec; + m_pSession->consumeEncodedNalu(m_pReceiveBuffer, frameSize, tPt, tRtp != NULL && tRtp->curPacketMarkerBit(), tRtp != NULL && tRtp->hasBeenSynchronizedUsingRTCP()); + }; if ( m_eCodecProbe != AV_CODEC_ID_NONE) { int got_picture = 0; @@ -709,6 +716,10 @@ void DummySink::setSprop(const u_int8_t * prop, unsigned size) }; memcpy(buf_start, prop, size); m_sAvPkt.size = size + 4; + if (m_eCodecProbe == AV_CODEC_ID_H264) + { + m_pSession->consumeEncodedParams(prop, size); // SPS / PPS of the SDP + }; if ((m_pSession->getWM() & MS_MODE_DECODE_FRAMES) && canDecode()){ int ret = avcodec_send_packet( m_pCodecContext, &m_sAvPkt ); if( ret < 0 ){ @@ -1208,6 +1219,10 @@ void videoLIVE555Source::shutdownStream(RTSPClient * rtspClient, int exitCode) LOG("Shutdown EVT"); #endif StreamClientState & streamClientState = MM->getStreamClientState(); // alias + if (m_pMediaDestination != NULL) + { + m_pMediaDestination->encodedSourceStopped(m_pOpaque); // the compressed stream ends here + }; // First, check whether any subsessions have still to be closed (as live555 testRTSPClient): // the sinks were never closed before - they leaked and kept reading a deleted source @@ -1290,6 +1305,22 @@ bool videoLIVE555Source::_open(CSTR URI, bool ShowDeviceMenu, float framerate, i return true; } +void videoLIVE555Source::consumeEncodedParams(const uint8_t * nalu, size_t size) +{ + if (m_pMediaDestination != NULL) + { + m_pMediaDestination->pushEncodedParams(nalu, size, false, m_pOpaque); + }; +} + +void videoLIVE555Source::consumeEncodedNalu(const uint8_t * nalu, size_t size, int64_t ptUs, bool marker, bool synced) +{ + if (m_pMediaDestination != NULL) + { + m_pMediaDestination->pushEncodedNalu(nalu, size, ptUs, marker, synced, m_pOpaque); + }; +} + void videoLIVE555Source::consumeFrame(cv::Mat * frm) { if (m_pMediaDestination == NULL) diff --git a/lib/data/media/video/videoLive555AVLibSource.h b/lib/data/media/video/videoLive555AVLibSource.h index 6d24caf9..4bb25e78 100644 --- a/lib/data/media/video/videoLive555AVLibSource.h +++ b/lib/data/media/video/videoLive555AVLibSource.h @@ -22,6 +22,12 @@ class videoLIVE555Source; +// live555 changed the event loop watch variable from "char volatile" to std::atomic_char (2023): take the +// type from TaskScheduler::doEventLoop so both versions build +#include +template A live555WatchArgType(void (C::*)(A)); +typedef std::remove_pointer::type LIVE555_WATCH_VARIABLE; + class StreamClientState { public: @@ -158,7 +164,7 @@ class videoLIVE555Source : public basicMediaSource, public basicThread UsageEnvironment * m_pUsageEnvironment; MediaSession * m_pMediaSession; - volatile char _eventLoopWatchVariable; + LIVE555_WATCH_VARIABLE _eventLoopWatchVariable; CustomRTSPClient * m_pRtspClient; DummySink * m_pSink; @@ -224,6 +230,9 @@ class videoLIVE555Source : public basicMediaSource, public basicThread bool setName(CSTR Name); bool setFrameAspectRatio(FrameAspectRatio AspectRatio); void consumeFrame(cv::Mat * frm); + // Compressed H264 for the destination (live view / recording without re-encoding) + void consumeEncodedParams(const uint8_t * nalu, size_t size); + void consumeEncodedNalu(const uint8_t * nalu, size_t size, int64_t ptUs, bool marker, bool synced); MediaSession * getMS(void) {