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.

85 lines
2.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Kernel loop: move long blocking work out of it Every pass of the mojo kernel loop ran these synchronously; each could stall the loop (and get la_mojo killed by the watchdog): - Report cleanup (validateReports -> deleteReportDate): deleteRDFDir ran "rm -f -R <whole day>" (seconds to minutes on an SD card), daily or every second while the disk is above preserve_empty. The day is now deleted in a background thread (one at a time; calls during it return false). ~sqliteDBC waits for a running deletion (max 60 s). - MediaMTX (validateService -> restart): "systemctl restart" waited for the service to stop and start, every second if the config kept failing validation. Now "systemctl --no-block restart" (only queues the job), at most once per KH_MTX_RESTART_MIN_S (30 s). - IP UART serial provider (hardwareManager::validate -> create_SOL): a blocking connect() to an address that doesn't answer took ~2 min (SYN retries). Now non-blocking with SERIAL_SOL_CONNECT_TIMEOUT_MS (5 s), the socket mode restored afterwards, and the socket closed on failure (it leaked). - Ethernet2UART gateway nodes: hardwareManager::validate (kernel loop) validated and reconnected them again, although the node factory thread does it (deviceNode::validate). Connects of up to 5 s blocked the kernel loop, plus the wait for the node's connection lock. hardwareResource::selfValidating() (default false) is true for deviceETH2UART, and the hardware manager skips such resources. Tested: the connect timeout on its own (extracted unchanged). A peer that drops the SYN failed after 5002 ms ("Connection timed out") instead of ~2 min; refused and accepted connects are immediate; the socket is blocking again in every case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
10 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Kernel loop: move long blocking work out of it Every pass of the mojo kernel loop ran these synchronously; each could stall the loop (and get la_mojo killed by the watchdog): - Report cleanup (validateReports -> deleteReportDate): deleteRDFDir ran "rm -f -R <whole day>" (seconds to minutes on an SD card), daily or every second while the disk is above preserve_empty. The day is now deleted in a background thread (one at a time; calls during it return false). ~sqliteDBC waits for a running deletion (max 60 s). - MediaMTX (validateService -> restart): "systemctl restart" waited for the service to stop and start, every second if the config kept failing validation. Now "systemctl --no-block restart" (only queues the job), at most once per KH_MTX_RESTART_MIN_S (30 s). - IP UART serial provider (hardwareManager::validate -> create_SOL): a blocking connect() to an address that doesn't answer took ~2 min (SYN retries). Now non-blocking with SERIAL_SOL_CONNECT_TIMEOUT_MS (5 s), the socket mode restored afterwards, and the socket closed on failure (it leaked). - Ethernet2UART gateway nodes: hardwareManager::validate (kernel loop) validated and reconnected them again, although the node factory thread does it (deviceNode::validate). Connects of up to 5 s blocked the kernel loop, plus the wait for the node's connection lock. hardwareResource::selfValidating() (default false) is true for deviceETH2UART, and the hardware manager skips such resources. Tested: the connect timeout on its own (extracted unchanged). A peer that drops the SYN failed after 5002 ms ("Connection timed out") instead of ~2 min; refused and accepted connects are immediate; the socket is blocking again in every case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
10 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. typedef struct S_StreamDescRecord{
  12. uint32_t cam_id;
  13. uint64_t node_id;
  14. uint32_t stream_id;
  15. uint8_t status;
  16. bool valid;
  17. char source_uri[512];
  18. }StreamDescRecord;
  19. typedef std::vector<StreamDescRecord *> V_StreamDescRecords;
  20. #define KH_STATUS_MTX_NA 0
  21. #define KH_STATUS_MTX_INIT 1
  22. #define KH_STATUS_MTX_AOK 2
  23. #define KH_STATUS_MTX_ERR 255
  24. #define KH_MTX_STREAM_LOADDED 0
  25. #define KH_MTX_STREAM_REGISTERED 1
  26. #define KH_MTX_STREAM_ONLINE 2
  27. #define KH_MTX_STREAM_OFFLINE 3
  28. #define KH_MTX_STREAM_ERROR 255
  29. typedef struct S_StreamSegmentRecord{
  30. bool keep;
  31. VIDEO_SEGMENT_INFO SI;
  32. }StreamSegmentRecord;
  33. typedef std::map<uint64_t, StreamSegmentRecord *> M_StreamMap; // inodes -> info
  34. typedef std::map<uint64_t, M_StreamMap *> M_VideoSegmentInfo; // stream_id -> map
  35. // At most one MediaMTX restart per this period (a config that keeps failing validation restarted it every second)
  36. #ifndef KH_MTX_RESTART_MIN_S
  37. #define KH_MTX_RESTART_MIN_S 30
  38. #endif
  39. class kernelHelperMediaMTX: public basicThread {
  40. private:
  41. basicLogCollection * m_pLog;
  42. dataBinder * m_pDBC;
  43. V_StreamDescRecords m_vStreamRecords;
  44. M_VideoSegmentInfo m_mVideoSegments;
  45. uint8_t m_bStatus;
  46. char m_sWorkDir[512];
  47. char m_sAppLogFile[512];
  48. char m_sAppConfigFile[512];
  49. char m_sRecordsBase[MAX_PATH_LEN];
  50. off_t m_nLastLogSize;
  51. bool m_bRecordMode;
  52. time_t m_tLastRestart; // last restart() (rate limit)
  53. bool loadConfig();
  54. bool loadStreams();
  55. StreamSegmentRecord * createSSR( uint32_t stream_id, uint32_t streamTSS, uint32_t streamTMS, CSTR path );
  56. void deleteSSR( StreamSegmentRecord *ptr );
  57. void validateSSR( StreamSegmentRecord *ptr );
  58. protected:
  59. virtual void m_fThreadProc(void);
  60. public:
  61. kernelHelperMediaMTX();
  62. virtual ~kernelHelperMediaMTX();
  63. bool create();
  64. bool validateConfig();
  65. bool assignStream( uint32_t stream_id );
  66. bool updateConfig();
  67. bool restart();
  68. bool validateService();
  69. uint8_t getStatus(){ return m_bStatus; };
  70. };
  71. #endif // ! LRF_PROXY_ONLY
  72. #endif