You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

192 lines
6.7 KiB

​
​
​
​
​
2 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 days ago
​
5 days ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __KERNEL_MODULE_EMBED_VIDEO_HEADER__
  2. #define __KERNEL_MODULE_EMBED_VIDEO_HEADER__
  3. #include "../../components/base/basicDualThread.h"
  4. #include "../../components/base/basicEventHeap.h"
  5. #include "../../components/base/basicMutex.h"
  6. #include "kernelModule.h"
  7. //#include "streamHandler.h"
  8. extern const char * m_pVideoScratchPath;
  9. #define EVE_WORK_WITH_MEDIAMTX
  10. #define EVE_OUTPUT_PICTURES 1
  11. #define EVE_OUTPUT_VIDEO 2
  12. #define EVE_OUTPUT_PIC_AND_VID 3
  13. #ifndef LRF_PROXY_ONLY
  14. // #include "../../data/media/video/videoAVLIBDestination.h"
  15. #include "../../components/base/basicMediaDestination.h"
  16. #include "../../components/base/basicMediaSource.h"
  17. #include "../../data/media/mtx/core/mediaPath.h"
  18. #include <map>
  19. #include <memory>
  20. #include <mutex>
  21. #include <string>
  22. namespace mtx { class WebrtcServer; }
  23. class streamHandler;
  24. typedef map<uint32_t, streamHandler *> mapSTREAMHANDLERS;
  25. #ifndef EVE_WORK_WITH_MEDIAMTX
  26. class kernelModuleEmbedVideo;
  27. typedef struct S_WEB_CLIENT_CTX
  28. {
  29. int m_iSocketFID;
  30. int m_iEncoderPipe[2];
  31. bool bValid;
  32. bool initDone;
  33. bool headerIsSent;
  34. uint32_t mediaStreamId;
  35. #ifdef HAVE_SMAL_PREVIEW_STREAMS
  36. bool bPreviewMode;
  37. #endif
  38. streamHandler * m_pHandler;
  39. kernelModuleEmbedVideo * ModulePtr;
  40. } WEB_CLIENT_CTX;
  41. typedef struct S_WEB_HANDLER
  42. {
  43. DWORD m_dwThreadID;
  44. #ifdef __linux__
  45. pthread_t m_hThreadHandle;
  46. #else
  47. HANDLE m_hThreadHandle;
  48. #endif
  49. WEB_CLIENT_CTX * CTX;
  50. } WEB_HANDLER;
  51. typedef vector<WEB_HANDLER *> vectorHANDLERS;
  52. #endif // !EVE_WORK_WITH_MEDIAMTX
  53. // typedef vector<STREAM_CTX*> vectorSTREAMS;
  54. typedef struct S_STREAM_CAP
  55. {
  56. uint32_t stream_id;
  57. uint32_t buffer_size;
  58. uint8_t picture_buffer;
  59. } STREAM_CAP;
  60. typedef struct S_VIDEO_EVT
  61. {
  62. uint32_t dbid;
  63. uint32_t frame;
  64. } VIDEO_EVT;
  65. #ifndef EVE_WORK_WITH_MEDIAMTX
  66. typedef vector<uchar> compressedFRAME;
  67. typedef map<uint32_t, compressedFRAME> mapSTREAMCAPS;
  68. #endif // !EVE_WORK_WITH_MEDIAMTX
  69. typedef map<uint32_t, cv::Mat> mapSTREAMMAPS;
  70. /*
  71. Live view and continuous recording (replaces the MediaMTX service)
  72. Every stream handler feeds a path "stream_<camera node id>" (the names MediaMTX had: the dashboard
  73. plays http://<host>:8889/stream_<node>/whep). live_mode selects what the path carries:
  74. - EVE_LIVE_PASSTHROUGH: the camera's H264 as the source receives it (no CPU, original quality)
  75. - EVE_LIVE_ENCODE: the processed frames of this module (time stamp, label, logo, event marks)
  76. encoded to H264 (streamLiveEncoder)
  77. The paths outlive the stream handlers (a stalled stream is rebuilt; the viewers reconnect to the same
  78. path). The WebRTC (WHEP) server and the recorder are the MediaMtx library (lib/data/media/mtx).
  79. */
  80. class kernelModuleEmbedVideo : public kernelModule, public mtx::PathProvider
  81. #ifndef EVE_WORK_WITH_MEDIAMTX
  82. , public basicDualThread
  83. #endif
  84. {
  85. private:
  86. basicEventHeap * m_pEventHeap;
  87. #ifndef EVE_WORK_WITH_MEDIAMTX
  88. static void * webClientProc(void * ptr);
  89. static void * viewClientProc(void * ptr);
  90. vectorHANDLERS m_vHandlersPool;
  91. mapSTREAMCAPS m_mapCAPTURES;
  92. vectorHANDLERS m_vViewHandlersPool;
  93. basicMutex m_mViewHandlersProtector;
  94. int m_nViewSocketDescriptor;
  95. basicMutex m_mWebHandlersProtector;
  96. bool registerForMediaStream(uint32_t id, WEB_CLIENT_CTX *& CTX);
  97. #endif // !EVE_WORK_WITH_MEDIAMTX
  98. int m_nSocketDescriptor;
  99. basicMutex m_mStreamHandlersProtector;
  100. basicMutex m_mPictureProtector;
  101. basicMutex m_mEncodedProtector;
  102. DBC_MODULE_EMBED_VIDEO_DATA m_sEmbedVideoData;
  103. mapSTREAMMAPS m_mapMATS;
  104. mapSTREAMHANDLERS m_mapHANDLERS;
  105. uint8_t * n_pNoSignalData;
  106. uint32_t m_nNoSignalSize;
  107. #ifdef HAVE_SMAL_PREVIEW_STREAMS
  108. mapSTREAMCAPS m_mapPREVIEWS;
  109. uint8_t * n_pNoSignalSmallData;
  110. uint32_t m_nNoSignalSmallSize;
  111. #endif
  112. cv::Mat m_mLogoPic;
  113. cv::Mat m_mLogoMask;
  114. char m_pBaseSavePath[PATH_MAX];
  115. bool saveStreamPicture(uint32_t id);
  116. bool saveStreamPicture(DBC_SNAPSHOT_DATA * ptr);
  117. bool generateSavePicPath(CSTR MD5, CSTR Output);
  118. // Live view (WebRTC) and recording
  119. mtx::ServerConf m_sLiveConf;
  120. std::unique_ptr<mtx::WebrtcServer> m_pWebrtc;
  121. time_t m_tLiveRetry; // next start attempt of the WebRTC server
  122. mutable std::mutex m_mLivePaths;
  123. std::map<std::string, std::shared_ptr<mtx::MediaPath>> m_mapLivePaths;
  124. void applyLiveSettings();
  125. bool startLive();
  126. void stopLive();
  127. #ifndef EVE_WORK_WITH_MEDIAMTX
  128. protected:
  129. /* From Basic Dual Thread */
  130. virtual void m_fThreadAProc(void);
  131. virtual void m_fThreadBProc(void);
  132. #endif // !EVE_WORK_WITH_MEDIAMTX
  133. public:
  134. explicit kernelModuleEmbedVideo(uint32_t moduleID);
  135. virtual ~kernelModuleEmbedVideo();
  136. /* From Kernel Module */
  137. virtual bool reloadSettings();
  138. virtual bool startService();
  139. virtual bool stopService(bool force = false);
  140. virtual bool dispatchEvent(EVENT_CONTAINER * Evt);
  141. virtual bool validate();
  142. /*
  143. //from Media Destination
  144. virtual bool pushFrame( AVFrame *Frame, void* src = NULL);
  145. //virtual void pushFrame( cv::Mat* Frame, void* src = NULL);
  146. virtual bool pushFrame( cv::Mat &Frame, void* src = NULL);
  147. // Module Specific Functionality
  148. */
  149. int getWidh(void);
  150. int getHeight(void);
  151. bool registerStream( uint32_t streamID, uint8_t flip_mode = 0 );
  152. bool unregisterStream( uint32_t streamID );
  153. uint8_t getMediaMode(void);
  154. bool isProcessingVideoStream();
  155. cv::Mat * getCurrentFrame( uint32_t streamID );
  156. // Live view: the mode, and the path of a camera node (created on first use; nullptr: live view off)
  157. uint8_t getLiveMode(void) const { return m_sEmbedVideoData.live_mode; }
  158. uint8_t getLiveFps(void) const { return m_sEmbedVideoData.live_fps; }
  159. uint16_t getLiveBitrate(void) const { return m_sEmbedVideoData.live_bitrate; }
  160. std::shared_ptr<mtx::MediaPath> livePath(uint32_t nodeID);
  161. // mtx::PathProvider (the WebRTC server looks up the path of a WHEP request)
  162. std::shared_ptr<mtx::MediaPath> findPath(const std::string & name) const override;
  163. friend class streamHandler;
  164. };
  165. #else //LRF_PROXY_ONLY
  166. class kernelModuleEmbedVideo : public kernelModule{
  167. public:
  168. explicit kernelModuleEmbedVideo(uint32_t moduleID);
  169. virtual ~kernelModuleEmbedVideo();
  170. };
  171. #endif //LRF_PROXY_ONLY
  172. #endif