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.

94 lines
3.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __KERNEL_HELPER_MEDIA_MTX_HEADER__
  2. #define __KERNEL_HELPER_MEDIA_MTX_HEADER__
  3. #ifndef LRF_PROXY_ONLY
  4. #include "dataBinder.h"
  5. #include "../../components/base/basicThread.h"
  6. #include <sys/types.h>
  7. #include <sys/stat.h>
  8. #include <unistd.h>
  9. #include <vector>
  10. #define mtx_scratch_path "/dev/shm/argus/video_scratch"
  11. /*
  12. KH_MTX_EMBEDDED: la_mojo serves the live view and records by itself (kernelModuleEmbedVideo with the
  13. MediaMtx library). The helper no longer writes mediamtx.yml, restarts or reads the log of the MediaMTX
  14. service; it stops the service once (it would hold port 8889) and only indexes the recorded segments
  15. (<mtx_scratch_path>/stream_<node>/*.mp4). Undefine it to go back to the external MediaMTX service.
  16. The helper is to be removed once the indexing moved into kernelModuleEmbedVideo.
  17. */
  18. #define KH_MTX_EMBEDDED
  19. typedef struct S_StreamDescRecord{
  20. uint32_t cam_id;
  21. uint64_t node_id;
  22. uint32_t stream_id;
  23. uint8_t status;
  24. bool valid;
  25. char source_uri[512];
  26. }StreamDescRecord;
  27. typedef std::vector<StreamDescRecord *> V_StreamDescRecords;
  28. #define KH_STATUS_MTX_NA 0
  29. #define KH_STATUS_MTX_INIT 1
  30. #define KH_STATUS_MTX_AOK 2
  31. #define KH_STATUS_MTX_ERR 255
  32. #define KH_MTX_STREAM_LOADDED 0
  33. #define KH_MTX_STREAM_REGISTERED 1
  34. #define KH_MTX_STREAM_ONLINE 2
  35. #define KH_MTX_STREAM_OFFLINE 3
  36. #define KH_MTX_STREAM_ERROR 255
  37. typedef struct S_StreamSegmentRecord{
  38. bool keep;
  39. VIDEO_SEGMENT_INFO SI;
  40. }StreamSegmentRecord;
  41. typedef std::map<uint64_t, StreamSegmentRecord *> M_StreamMap; // inodes -> info
  42. typedef std::map<uint64_t, M_StreamMap *> M_VideoSegmentInfo; // stream_id -> map
  43. // At most one MediaMTX restart per this period (a config that keeps failing validation restarted it every second)
  44. #ifndef KH_MTX_RESTART_MIN_S
  45. #define KH_MTX_RESTART_MIN_S 30
  46. #endif
  47. class kernelHelperMediaMTX: public basicThread {
  48. private:
  49. basicLogCollection * m_pLog;
  50. dataBinder * m_pDBC;
  51. V_StreamDescRecords m_vStreamRecords;
  52. M_VideoSegmentInfo m_mVideoSegments;
  53. uint8_t m_bStatus;
  54. char m_sWorkDir[512];
  55. char m_sAppLogFile[512];
  56. char m_sAppConfigFile[512];
  57. char m_sRecordsBase[MAX_PATH_LEN];
  58. off_t m_nLastLogSize;
  59. bool m_bRecordMode;
  60. time_t m_tLastRestart; // last restart() (rate limit)
  61. bool loadConfig();
  62. bool loadStreams();
  63. StreamSegmentRecord * createSSR( uint32_t stream_id, uint32_t streamTSS, uint32_t streamTMS, CSTR path );
  64. void deleteSSR( StreamSegmentRecord *ptr );
  65. void validateSSR( StreamSegmentRecord *ptr );
  66. protected:
  67. virtual void m_fThreadProc(void);
  68. public:
  69. kernelHelperMediaMTX();
  70. virtual ~kernelHelperMediaMTX();
  71. bool create();
  72. bool validateConfig();
  73. bool assignStream( uint32_t stream_id );
  74. bool updateConfig();
  75. bool restart();
  76. bool validateService();
  77. uint8_t getStatus(){ return m_bStatus; };
  78. };
  79. #endif // ! LRF_PROXY_ONLY
  80. #endif