RtpFilesCleaner.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #include <iostream>
  2. #include <string>
  3. #include <thread>
  4. #include <vector>
  5. #include <list>
  6. #include "CDiscHelper.h"
  7. #include "TSysThread.h"
  8. #include "CAppLife.h"
  9. #include "CTimer.h"
  10. #include "AnyCleaner.h"
  11. #define FRAME_CACHESIZE (3840*2160*16)
  12. #define GB(x) ((x.HighPart << 2) + (x.LowPart >> 20) / 1024.0) // 转换为GB单位显示
  13. typedef struct tagRTPFILEDESC {
  14. char file_name[256];
  15. int file_size;
  16. std::string name;
  17. char folder[256];
  18. unsigned int start_timesec; // recording time_sec
  19. unsigned int start_timeusec;
  20. unsigned int end_timesec;
  21. unsigned int end_timeusec;
  22. unsigned int duration_sec;
  23. } RTPFILEDESC;
  24. class CAppLifeThread : public TSysThreadImpl
  25. {
  26. public:
  27. CAppLifeThread() : m_AppLife(nullptr) {}
  28. ~CAppLifeThread()
  29. {
  30. Stop();
  31. if (m_AppLife) {
  32. delete m_AppLife;
  33. m_AppLife = nullptr;
  34. }
  35. }
  36. void PostQuit() { if (m_AppLife) m_AppLife->PostQuit(); }
  37. void Action()
  38. {
  39. m_AppLife = new CAppLife();
  40. //注意NVS_WATCHDOG_EVENT,NVS_EXIT_EVENT需要和软件狗里的cfg文件里的值相同
  41. #define NVS_INSTANCE_MUTEX "E3F9C076-84E6-4AF7-996A-1A0486BEBD79"
  42. #define NVS_WATCHDOG_EVENT "E3F9C076-84E6-4AF7-996A-1A0486BEBD79-heart"
  43. #define NVS_EXIT_EVENT "E3F9C076-84E6-4AF7-996A-1A0486BEBD79-quit"
  44. //"385222EF-7909-4D58-83B0-2FB8E5EA0960"
  45. if (m_AppLife->Begin((char*)NVS_INSTANCE_MUTEX, (char*)NVS_WATCHDOG_EVENT, (char*)NVS_EXIT_EVENT)) {
  46. //LOG4CXX_ERROR(app_logger, "failed to initialize life events.");
  47. return;
  48. }
  49. m_AppLife->WaitForQuit();
  50. OutputDebugStringA("Close m_AppLife");
  51. }
  52. private:
  53. CAppLife* m_AppLife;
  54. };
  55. class ClearRtpFiles : public TSysThreadImpl
  56. {
  57. public:
  58. ClearRtpFiles();
  59. ~ClearRtpFiles();
  60. void Action();
  61. CAppLifeThread* life_worker;
  62. int retension_day;
  63. int checktime;//最小单位min
  64. int remaining_memory;//最小单位GB字节
  65. std::string src_path;
  66. std::string backup_path;
  67. std::vector<char*> vec_src_foldernames;
  68. std::vector<char*> vec_back_foldernames;
  69. std::vector<char*> vec_src_date_folder;
  70. std::vector<char*> vec_back_date_folder;
  71. std::list<RTPFILEDESC*> list_src_rtpfiles;
  72. std::list<RTPFILEDESC*> list_backup_rtpfiles;
  73. void Delete_file(std::string filename);
  74. BOOL SHDeleteFolder(std::string pstrFolder, BOOL bAllowUndo);
  75. int Get_Date_List(std::vector<char*>* pVecFolderName, char* folder_name);
  76. void Get_DateFiles(std::vector<char*>* vec_foldernames, const char* src_folder);
  77. int Identical_file_check();
  78. bool LoadDeviceInfo();
  79. void Get_Channels(const char* backup_folder, const char* src_folder);
  80. void Get_Channel(std::vector<char*>* vec_foldernames, const char* src_folder);
  81. int Get_Channel_List(std::vector<char*>* pVecFolderName, char* folder_name);
  82. void init();
  83. // find src_folder all *.rtp within [start_time, end_time] to dst_folder with the same file structure
  84. int Get_List_File(const char* backup_folder, const char* src_folder);
  85. // int rtp_proc(RTPFILEDESC* rtp_filedesc, Buffer_t* mem_buffer, CRtpFrame* rtp_frame, FRAMEDATACALLBACK framedata_cb, void* user_data);
  86. int rtp_listfile(std::list<RTPFILEDESC*>* list_rtpfiles, const char* src_folder);
  87. int Get_Disk_Free(std::string serial);
  88. };