|
|
#ifndef __KERNEL_MODULE_EMBED_VIDEO_HEADER__
#define __KERNEL_MODULE_EMBED_VIDEO_HEADER__
#include "../../components/base/basicDualThread.h"
#include "../../components/base/basicEventHeap.h"
#include "../../components/base/basicMutex.h"
#include "kernelModule.h"
//#include "streamHandler.h"
extern const char * m_pVideoScratchPath;
#define EVE_WORK_WITH_MEDIAMTX
#define EVE_OUTPUT_PICTURES 1
#define EVE_OUTPUT_VIDEO 2
#define EVE_OUTPUT_PIC_AND_VID 3
#ifndef LRF_PROXY_ONLY
// #include "../../data/media/video/videoAVLIBDestination.h"
#include "../../components/base/basicMediaDestination.h"
#include "../../components/base/basicMediaSource.h"
#include "../../data/media/mtx/core/mediaPath.h"
#include <map>
#include <memory>
#include <mutex>
#include <string>
namespace mtx { class WebrtcServer; } class streamHandler; typedef map<uint32_t, streamHandler *> mapSTREAMHANDLERS;#ifndef EVE_WORK_WITH_MEDIAMTX
class kernelModuleEmbedVideo; typedef struct S_WEB_CLIENT_CTX { int m_iSocketFID; int m_iEncoderPipe[2]; bool bValid; bool initDone; bool headerIsSent; uint32_t mediaStreamId; #ifdef HAVE_SMAL_PREVIEW_STREAMS
bool bPreviewMode; #endif
streamHandler * m_pHandler; kernelModuleEmbedVideo * ModulePtr; } WEB_CLIENT_CTX;
typedef struct S_WEB_HANDLER { DWORD m_dwThreadID; #ifdef __linux__
pthread_t m_hThreadHandle; #else
HANDLE m_hThreadHandle; #endif
WEB_CLIENT_CTX * CTX; } WEB_HANDLER;
typedef vector<WEB_HANDLER *> vectorHANDLERS;#endif // !EVE_WORK_WITH_MEDIAMTX
// typedef vector<STREAM_CTX*> vectorSTREAMS;
typedef struct S_STREAM_CAP{ uint32_t stream_id; uint32_t buffer_size; uint8_t picture_buffer;} STREAM_CAP;
typedef struct S_VIDEO_EVT{ uint32_t dbid; uint32_t frame;} VIDEO_EVT;
#ifndef EVE_WORK_WITH_MEDIAMTX
typedef vector<uchar> compressedFRAME; typedef map<uint32_t, compressedFRAME> mapSTREAMCAPS;#endif // !EVE_WORK_WITH_MEDIAMTX
typedef map<uint32_t, cv::Mat> mapSTREAMMAPS;
/*
Live view and continuous recording (replaces the MediaMTX service)
Every stream handler feeds a path "stream_<camera node id>" (the names MediaMTX had: the dashboard plays http://<host>:8889/stream_<node>/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#endif
{ private:
basicEventHeap * m_pEventHeap; #ifndef EVE_WORK_WITH_MEDIAMTX
static void * webClientProc(void * ptr); static void * viewClientProc(void * ptr); vectorHANDLERS m_vHandlersPool; mapSTREAMCAPS m_mapCAPTURES; vectorHANDLERS m_vViewHandlersPool; basicMutex m_mViewHandlersProtector; int m_nViewSocketDescriptor; basicMutex m_mWebHandlersProtector; bool registerForMediaStream(uint32_t id, WEB_CLIENT_CTX *& CTX); #endif // !EVE_WORK_WITH_MEDIAMTX
int m_nSocketDescriptor; basicMutex m_mStreamHandlersProtector; basicMutex m_mPictureProtector; basicMutex m_mEncodedProtector; DBC_MODULE_EMBED_VIDEO_DATA m_sEmbedVideoData; mapSTREAMMAPS m_mapMATS; mapSTREAMHANDLERS m_mapHANDLERS; uint8_t * n_pNoSignalData; uint32_t m_nNoSignalSize;#ifdef HAVE_SMAL_PREVIEW_STREAMS
mapSTREAMCAPS m_mapPREVIEWS; uint8_t * n_pNoSignalSmallData; uint32_t m_nNoSignalSmallSize;#endif
cv::Mat m_mLogoPic; cv::Mat m_mLogoMask; char m_pBaseSavePath[PATH_MAX]; 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<mtx::WebrtcServer> m_pWebrtc; time_t m_tLiveRetry; // next start attempt of the WebRTC server
mutable std::mutex m_mLivePaths; std::map<std::string, std::shared_ptr<mtx::MediaPath>> m_mapLivePaths; void applyLiveSettings(); bool startLive(); void stopLive();#ifndef EVE_WORK_WITH_MEDIAMTX
protected:
/* From Basic Dual Thread */ virtual void m_fThreadAProc(void); virtual void m_fThreadBProc(void);#endif // !EVE_WORK_WITH_MEDIAMTX
public:
explicit kernelModuleEmbedVideo(uint32_t moduleID); virtual ~kernelModuleEmbedVideo(); /* From Kernel Module */ virtual bool reloadSettings(); virtual bool startService(); virtual bool stopService(bool force = false); virtual bool dispatchEvent(EVENT_CONTAINER * Evt); virtual bool validate(); /*
//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); // Module Specific Functionality
*/ int getWidh(void); int getHeight(void); bool registerStream( uint32_t streamID, uint8_t flip_mode = 0 ); bool unregisterStream( uint32_t streamID ); 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<mtx::MediaPath> livePath(uint32_t nodeID); // mtx::PathProvider (the WebRTC server looks up the path of a WHEP request)
std::shared_ptr<mtx::MediaPath> findPath(const std::string & name) const override; friend class streamHandler;};#else //LRF_PROXY_ONLY
class kernelModuleEmbedVideo : public kernelModule{ public: explicit kernelModuleEmbedVideo(uint32_t moduleID); virtual ~kernelModuleEmbedVideo();};#endif //LRF_PROXY_ONLY
#endif
|