RtpFilesCleaner.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #include <iostream>
  2. #include <string>
  3. #include <thread>
  4. #include <vector>
  5. #include <list>
  6. #include "Buffer.h"
  7. #include "CDiscHelper.h"
  8. #include "TSysThread.h"
  9. #include "CAppLife.h"
  10. #include "CTimer.h"
  11. #include "AnyCleaner.h"
  12. #define FRAME_CACHESIZE 1024*1024*1024
  13. #define GB(x) ((x.HighPart << 2) + (x.LowPart >> 20) / 1024.0) // 转换为GB单位显示
  14. typedef void (*FRAMEDATACALLBACK)(char* frame_data, int frame_size, \
  15. unsigned int frame_timesec, unsigned int frame_timeusec, bool is_iframe, \
  16. void* user_data);
  17. typedef struct tagRTPFILEDESC {
  18. char file_name[256];
  19. int file_size;
  20. char name[256];
  21. char folder[256];
  22. ULONGLONG file_number;
  23. unsigned int start_timesec; // recording time_sec
  24. unsigned int start_timeusec;
  25. unsigned int end_timesec;
  26. unsigned int end_timeusec;
  27. unsigned int duration_sec;
  28. } RTPFILEDESC;
  29. typedef struct tagTIME_SPAN {
  30. unsigned int start_timesec;
  31. //unsigned int start_timeusec;
  32. unsigned int end_timesec;
  33. //unsigned int end_timeusec;
  34. //unsigned int duration_sec;
  35. } TIME_SPAN;
  36. class CAppLifeThread : public TSysThreadImpl
  37. {
  38. public:
  39. CAppLifeThread() : m_AppLife(nullptr) {}
  40. ~CAppLifeThread()
  41. {
  42. Stop();
  43. if (m_AppLife) {
  44. delete m_AppLife;
  45. m_AppLife = nullptr;
  46. }
  47. }
  48. void PostQuit() { if (m_AppLife) m_AppLife->PostQuit(); }
  49. void Action()
  50. {
  51. m_AppLife = new CAppLife();
  52. //注意NVS_WATCHDOG_EVENT,NVS_EXIT_EVENT需要和软件狗里的cfg文件里的值相同
  53. #define NVS_INSTANCE_MUTEX "E3F9C076-84E6-4AF7-996A-1A0486BEBD79"
  54. #define NVS_WATCHDOG_EVENT "E3F9C076-84E6-4AF7-996A-1A0486BEBD79-heart"
  55. #define NVS_EXIT_EVENT "E3F9C076-84E6-4AF7-996A-1A0486BEBD79-quit"
  56. //"385222EF-7909-4D58-83B0-2FB8E5EA0960"
  57. if (m_AppLife->Begin((char*)NVS_INSTANCE_MUTEX, (char*)NVS_WATCHDOG_EVENT, (char*)NVS_EXIT_EVENT)) {
  58. //LOG4CXX_ERROR(app_logger, "failed to initialize life events.");
  59. return;
  60. }
  61. m_AppLife->WaitForQuit();
  62. OutputDebugStringA("Close m_AppLife");
  63. }
  64. private:
  65. CAppLife* m_AppLife;
  66. };
  67. class ClearRtpFiles : public TSysThreadImpl
  68. {
  69. public:
  70. ClearRtpFiles();
  71. ~ClearRtpFiles();
  72. void Action();
  73. CAppLifeThread* life_worker;
  74. int retension_day;
  75. int checktime;//最小单位min
  76. int remaining_memory;//最小单位GB字节
  77. std::string src_path;
  78. std::string backup_path;
  79. TIME_SPAN src_time_span;
  80. TIME_SPAN back_time_span;
  81. std::vector<char*> vec_src_foldernames;
  82. std::vector<char*> vec_back_foldernames;
  83. std::vector<char*> vec_src_date_folder;
  84. std::vector<char*> vec_back_date_folder;
  85. std::list<RTPFILEDESC*> list_src_rtpfiles;
  86. std::list<RTPFILEDESC*> list_localDay_rtpfiles;
  87. std::list<RTPFILEDESC*> list_lastDay_rtpfiles;
  88. std::list<RTPFILEDESC*> list_nextDay_rtpfiles;
  89. std::list<RTPFILEDESC*> list_backup_rtpfiles;
  90. void Is_NextSame_Times(std::list<RTPFILEDESC*>* list_rtpfiles, RTPFILEDESC* paramer, unsigned int starttime, unsigned int endtime);
  91. void Is_LastSame_Times(std::list<RTPFILEDESC*>* list_rtpfiles, RTPFILEDESC* paramer, unsigned int starttime, unsigned int endtime);
  92. void Is_Same_Times(std::list<RTPFILEDESC*>* list_rtpfiles, RTPFILEDESC* paramer,unsigned int starttime, unsigned int endtime,bool &check_last,bool &check_next);
  93. void Delete_file(std::string filename);
  94. void Check_Channels(std::string src,std::string backup);
  95. BOOL SHDeleteFolder(std::string pstrFolder, BOOL bAllowUndo);
  96. int Get_Date_List(std::vector<char*>* pVecFolderName, char* folder_name);
  97. void Get_DateFiles(std::vector<char*>* vec_foldernames, const char* src_folder);
  98. bool LoadDeviceInfo();
  99. void Get_Channels(const char* backup_folder, const char* src_folder);
  100. void Get_Folder(std::vector<char*>* vec_foldernames, const char* src_folder);
  101. int Get_Folder_List(std::vector<char*>* pVecFolderName, char* folder_name);
  102. void init();
  103. int Rtp_Listfile(std::list<RTPFILEDESC*>* list_rtpfiles, const char* src_folder);
  104. int Get_Disk_Free(std::string serial);
  105. void File_Sort(std::list<RTPFILEDESC*>* src_rtpfiles, std::list<RTPFILEDESC*>* dst_rtpfiles);
  106. void Folder_Sort(std::vector<char*>* src_folder, std::vector<char*>* dst_folder);
  107. std::string Get_Filename_Time(std::string src);
  108. int Get_MaxSize_File(std::list<RTPFILEDESC*>* list_rtpfiles);
  109. void Clear_EmptyDirectory(std::vector<char*>::iterator it_char);
  110. void Free_Rtpfiles();
  111. };