GlobalVariable.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. #ifndef __GLOBAL_VARIABLE_H__
  2. #define __GLOBAL_VARIABLE_H__
  3. #include <QString>
  4. #include <QList>
  5. #include <QChar>
  6. #include <QMap>
  7. #include <QMetaType>
  8. #include <QDateTime>
  9. /**
  10. * @brief 星期枚举定义,星期八是带有日期的特殊日
  11. *
  12. */
  13. enum class eWeekType
  14. {
  15. Week_Monday = 1, /* 星期一 */
  16. Week_Tuesday, /* 星期二 */
  17. Week_Wednesday, /* 星期三 */
  18. Week_Thursday, /* 星期四 */
  19. Week_Friday, /* 星期五 */
  20. Week_Saturday, /* 星期六 */
  21. Week_Sunday, /* 星期日 */
  22. Week_Special, /* 特殊日期 */
  23. };
  24. Q_DECLARE_METATYPE(eWeekType)
  25. extern const QMap<eWeekType, QString> MapWeekTypeToString;
  26. /**
  27. * @brief 录音通道类型
  28. *
  29. */
  30. enum class ERoadType
  31. {
  32. RoadType_Main = 0, /* 主输出 */
  33. RoadType_SpaceReceive, /* 空间接收 */
  34. RoadType_SpaceSend, /* 空间发送 */
  35. };
  36. /**
  37. * @brief 报警类型
  38. *
  39. */
  40. enum class EAlarmType
  41. {
  42. EAT_None = 0, /* 无报警 */
  43. EAT_Silent, /* 静音报警 */
  44. EAT_Overload, /* 过载报警 */
  45. EAT_Reversed, /* 反相报警 */
  46. EAR_Consistency, /* 一致性报警 */
  47. EAT_Noise, /* 噪音报警 */
  48. EAT_Unknown, /* 未知报警 */
  49. };
  50. /**
  51. * @brief 一条计划
  52. *
  53. */
  54. struct OnePlan_t
  55. {
  56. eWeekType weekType; /* 星期类型 */
  57. QDate date; /* 日期,格式为YYYY-MM-DD */
  58. QTime timeStart; /* 时间,格式为HH:mm:ss */
  59. QTime timeEnd; /* 时间,格式为HH:mm:ss */
  60. bool operator==(const OnePlan_t &other) const
  61. {
  62. return (weekType == other.weekType) && (date == other.date) && (timeStart == other.timeStart) && (timeEnd == other.timeEnd);
  63. }
  64. bool operator!=(const OnePlan_t &other) const
  65. {
  66. return !(*this == other);
  67. }
  68. };
  69. /* ====================================================================
  70. * 声卡相关信息结构体
  71. * ==================================================================== */
  72. /* 单个录音通道信息,带有频道信息 */
  73. struct OneRoadInfo_t
  74. {
  75. int nRoadNum = -1; /* 录音通道编号,是声卡在系统中的物理编号 */
  76. int nChannelID = -1; /* 频道ID */
  77. QString strChannelName; /* 频道名称 */
  78. };
  79. /**
  80. * @brief 声卡信息,这里的信息都是设备上和物理声卡相关的
  81. *
  82. */
  83. struct SoundCardInfo_t
  84. {
  85. int nSoundCardNum = -1; /* 声卡编号,系统上的物理编号 */
  86. QString strSoundCardID; /* 声卡ID,这个是声卡名称,可以用来打开 */
  87. QString strSoundCardName; /* 声卡名称 */
  88. QString strSoundCardDriver; /* 声卡驱动名称 */
  89. QList<OneRoadInfo_t> listRoad; /* 录音通道列表,存储通道编号 */
  90. };
  91. /**
  92. * @brief 单个声卡通道信息,带有声卡自身的信息
  93. *
  94. */
  95. struct SoundCardRoadInfo_t
  96. {
  97. int nSoundCardNum = -1; /* 声卡编号 */
  98. QString strSoundCardID; /* 声卡ID,这个是声卡名称,可以用来打开 */
  99. QString strSoundCardName; /* 声卡名称 */
  100. OneRoadInfo_t roadInfo; /* 单个通道信息 */
  101. bool operator<(const SoundCardRoadInfo_t &other) const;
  102. };
  103. /* 注册数据类型到系统 */
  104. Q_DECLARE_METATYPE(SoundCardRoadInfo_t)
  105. /* ====================================================================
  106. * CompareItemInfo_t对比项结构体
  107. * ==================================================================== */
  108. /**
  109. * @brief 对比项信息在表格中的显示结构体
  110. *
  111. */
  112. struct CompareItemTableItem_t
  113. {
  114. int nSerialNum; /* 序号,在表格中的序号 */
  115. int nID; /* 对比项ID */
  116. QString strName; /* 对比项名称 */
  117. bool isEnable; /* 对比项状态,是否启用 */
  118. int nChannelCount; /* 通道数 */
  119. };
  120. /* 对比项的通道信息 */
  121. struct CompareItemRoadInfo_t
  122. {
  123. bool isEnableRecord; /* 是否开启录音 */
  124. int nCompareRoadNum; /* 对比通道编号,1是主通道,其余往后排 */
  125. QString strCompareRoadName; /* 对比项通道名称,不是声卡的通道名 */
  126. SoundCardRoadInfo_t scRoadInfo; /* 声卡通道信息,包含声卡编号和通道编号 */
  127. bool operator==(const CompareItemRoadInfo_t &other) const;
  128. };
  129. /* 检测阈值,静音和过载是整数,反相是小数 */
  130. union Threshold_t
  131. {
  132. uint64_t nThreshold; /* 静音和过载的阈值 */
  133. double dThreshold; /* 反相的阈值 */
  134. };
  135. /**
  136. * @brief 静音、过载、反相检测参数
  137. *
  138. */
  139. struct CompareItemDetectParam_t
  140. {
  141. bool isEnable = false; /* 是否启用检测 */
  142. Threshold_t threshold; /* 检测阈值 */
  143. int nLen = 0; /* 检测长度,单位秒 */
  144. int nSensitivity = 0; /* 敏感度,0-100,0最不敏感,100最敏感 */
  145. CompareItemDetectParam_t() = default;
  146. CompareItemDetectParam_t(const CompareItemDetectParam_t &other);
  147. CompareItemDetectParam_t& operator=(const CompareItemDetectParam_t &other);
  148. };
  149. /**
  150. * @brief 对比项信息
  151. *
  152. */
  153. struct CompareItemInfo_t
  154. {
  155. int nID = -1; /* 对比项ID,对比项唯一识别号,不可更改 */
  156. QString strName; /* 对比项名称 */
  157. bool isEnable = false; /* 对比项状态,是否启用 */
  158. QMap<int, CompareItemRoadInfo_t> mapRoad; /* 通道信息列表,int是通道编号,在对比项中的编号 */
  159. CompareItemDetectParam_t paramMute; /* 静音检测参数 */
  160. CompareItemDetectParam_t paramOverload; /* 过载检测参数 */
  161. CompareItemDetectParam_t paramPhase; /* 反相检测参数 */
  162. CompareItemInfo_t() = default;
  163. CompareItemInfo_t(const CompareItemInfo_t &other);
  164. CompareItemInfo_t& operator=(const CompareItemInfo_t &other);
  165. /* 判断对比想基础部分是否相等,不包含通道信息 */
  166. bool isEqualBase(const CompareItemInfo_t &other) const;
  167. /* 判断对比项的通道是否相同 */
  168. bool isEqualRoads(const CompareItemInfo_t &other) const;
  169. };
  170. /* =============================================================================
  171. * 检测时段配置
  172. * ============================================================================= */
  173. /**
  174. * @brief 一个对比项的检测计划
  175. *
  176. */
  177. struct DetectPeriodConfig_t
  178. {
  179. int nID = 0; /* ID */
  180. bool isApplySlient = false; /* 非检测计划日期是否应用静音 */
  181. bool isApplyOverload = false; /* 非检测计划日期是否应用超载 */
  182. bool isApplyPhase = false; /* 非检测计划日期是否应用反相 */
  183. bool isApplyNoise = false; /* 非检测计划日期是否应用噪音 */
  184. QList<OnePlan_t> listDetect; /* 检测计划列表 */
  185. QList<OnePlan_t> listNoDetect; /* 非检测计划列表 */
  186. bool operator==(const DetectPeriodConfig_t &other) const;
  187. /* 判断基础信息是否更改 */
  188. bool isBaseInfoChanged(const DetectPeriodConfig_t &other) const;
  189. };
  190. /**
  191. * @brief 非检测计划应用清空
  192. *
  193. */
  194. struct NoDetectPlanApply_t
  195. {
  196. int nID = 0; /* ID */
  197. bool isApplySlient = false; /* 非检测计划日期是否应用静音 */
  198. bool isApplyOverload = false; /* 非检测计划日期是否应用超载 */
  199. bool isApplyPhase = false; /* 非检测计划日期是否应用反相 */
  200. bool isApplyNoise = false; /* 非检测计划日期是否应用噪音 */
  201. };
  202. /* =========================================================================================
  203. * 线程信息相关枚举和结构体
  204. * =========================================================================================*/
  205. /**
  206. * @brief 线程状态枚举
  207. *
  208. */
  209. enum class EThreadState
  210. {
  211. State_None = 0, /* 无状态 */
  212. State_Inited, /* 已初始化 */
  213. State_Running, /* 运行中 */
  214. State_Stopped, /* 已停止 */
  215. State_Error /* 错误状态 */
  216. };
  217. /**
  218. * @brief 线程类型枚举
  219. *
  220. */
  221. enum class EThreadType
  222. {
  223. Type_None = 0, /* 无类型 */
  224. Type_RecordSrc, /* 录音源线程 */
  225. Type_AssignSrcData, /* 分派数据线程 */
  226. Type_CreateWAV, /* 生成WAV文件线程 */
  227. Type_CreateDB, /* 生成音量包的线程 */
  228. // Type_CreateNoise, /* 生成噪音数据线程 */
  229. Type_CreateLongWAV, /* 生成长文件线程 */
  230. Type_RtpSend, /* RTP发送线程 */
  231. Type_ConsistencyCheck, /* 一致性检查线程 */
  232. Type_CalculateDB, /* 计算音量的线程 */
  233. Type_CompareItem, /* 对比项线程 */
  234. };
  235. /**
  236. * @brief 录音线程信息结构体
  237. */
  238. struct RecordThreadInfo_t
  239. {
  240. SoundCardRoadInfo_t cardRoadInfo; /* 录音通道信息 */
  241. EThreadType threadType; /* 线程类型 */
  242. EThreadState threadState; /* 线程状态 */
  243. // BaseRecordThread* pThread = nullptr; /* 线程对象 */
  244. };
  245. /* =========================================================================================
  246. * 报警信息结构体
  247. * =========================================================================================*/
  248. class BaseCalculateThread;
  249. /**
  250. * @brief 计算线程信息结构体
  251. *
  252. */
  253. struct CalculateThreadInfo_t
  254. {
  255. CompareItemInfo_t compareItemInfo; /* 对比项信息 */
  256. EThreadType threadType; /* 线程类型 */
  257. EThreadState threadState; /* 线程状态 */
  258. // BaseCalculateThread* pThread = nullptr; /* 计算线程对象 */
  259. CalculateThreadInfo_t() = default;
  260. CalculateThreadInfo_t(const CalculateThreadInfo_t& info);
  261. CalculateThreadInfo_t& operator=(const CalculateThreadInfo_t& info);
  262. };
  263. /**
  264. * @brief 报警结构体
  265. *
  266. */
  267. struct AlarmInfo_t
  268. {
  269. bool isAlarm = false; /* 是否报警 */
  270. int CompareItemID = 0; /* 对比项ID */
  271. std::string strCompareItemName; /* 对比项名称 */
  272. CompareItemRoadInfo_t RoadInfo; /* 录音通道信息 */
  273. ERoadType RoadType; /* 录音通道类型 */
  274. EAlarmType AlarmType = EAlarmType::EAT_None; /* 报警类型 */
  275. QDateTime StartTime; /* 报警开始时间 */
  276. QDateTime EndTime; /* 报警结束时间 */
  277. // std::string strAlarmStartTime; /* 报警发生时间 */
  278. // std::string strAlarmEndTime; /* 报警结束时间 */
  279. // std::string strAlarmExistTime; /* 报警持续时间 */
  280. std::string strAlarmFilePath; /* 报警文件路径 */
  281. int AlarmStartPos = 0; /* 报警开始位置 */
  282. QDateTime AlarmFileStartTime; /* 录音文件开始时间 */
  283. AlarmInfo_t() = default;
  284. AlarmInfo_t(const AlarmInfo_t& obj) { *this = obj; }
  285. AlarmInfo_t& operator=(const AlarmInfo_t& obj);
  286. /* 比较是否相等,主要是比较是否报警、通道ID,报警类型,报警时间 */
  287. bool operator==(const AlarmInfo_t& other) const;
  288. };
  289. #endif // __GLOBAL_VARIABLE_H__