GlobalVariable.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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. /* 使用声卡通道最为Key的结构体 */
  104. struct SoundCardRoadKey_t
  105. {
  106. int nSoundCardNum = -1; /* 声卡编号 */
  107. int nRoadNum = -1; /* 通道编号 */
  108. bool operator==(const SoundCardRoadKey_t &other) const
  109. {
  110. return (nSoundCardNum == other.nSoundCardNum) && (nRoadNum == other.nRoadNum);
  111. }
  112. bool operator<(const SoundCardRoadKey_t &other) const
  113. {
  114. if(nSoundCardNum < other.nSoundCardNum)
  115. return true;
  116. if(nSoundCardNum > other.nSoundCardNum)
  117. return false;
  118. return nRoadNum < other.nRoadNum;
  119. }
  120. };
  121. /* 注册数据类型到系统 */
  122. Q_DECLARE_METATYPE(SoundCardRoadInfo_t)
  123. /* ====================================================================
  124. * CompareItemInfo_t对比项结构体
  125. * ==================================================================== */
  126. /**
  127. * @brief 对比项信息在表格中的显示结构体
  128. *
  129. */
  130. struct CompareItemTableItem_t
  131. {
  132. int nSerialNum; /* 序号,在表格中的序号 */
  133. int nID; /* 对比项ID */
  134. QString strName; /* 对比项名称 */
  135. bool isEnable; /* 对比项状态,是否启用 */
  136. int nChannelCount; /* 通道数 */
  137. };
  138. /* 对比项的通道信息 */
  139. struct CompareItemRoadInfo_t
  140. {
  141. bool isEnableRecord; /* 是否开启录音 */
  142. int nCompareRoadNum; /* 对比通道编号,1是主通道,其余往后排 */
  143. QString strCompareRoadName; /* 对比项通道名称,不是声卡的通道名 */
  144. SoundCardRoadInfo_t scRoadInfo; /* 声卡通道信息,包含声卡编号和通道编号 */
  145. bool operator==(const CompareItemRoadInfo_t &other) const;
  146. };
  147. /* 一个对比项通道信息,包含对比项信息 */
  148. struct OneCompareItemRoadInfo_t
  149. {
  150. int nCompareItemID = -1; /* 对比项ID */
  151. int nCompareRoadNum = -1; /* 对比项通道编号 */
  152. int nSoundCardNum = -1; /* 声卡编号 */
  153. int nRoadNum = -1; /* 声卡通道编号 */
  154. OneCompareItemRoadInfo_t() = default;
  155. OneCompareItemRoadInfo_t(const OneCompareItemRoadInfo_t &other);
  156. OneCompareItemRoadInfo_t& operator=(const OneCompareItemRoadInfo_t &other);
  157. bool operator==(const OneCompareItemRoadInfo_t &other) const;
  158. };
  159. /* 检测阈值,静音和过载是整数,反相是小数 */
  160. union Threshold_t
  161. {
  162. uint64_t nThreshold; /* 静音和过载的阈值 */
  163. double dThreshold; /* 反相的阈值 */
  164. };
  165. /**
  166. * @brief 静音、过载、反相检测参数
  167. *
  168. */
  169. struct CompareItemDetectParam_t
  170. {
  171. bool isEnable = false; /* 是否启用检测 */
  172. Threshold_t threshold; /* 检测阈值 */
  173. int nLen = 0; /* 检测长度,单位秒 */
  174. int nSensitivity = 0; /* 敏感度,0-100,0最不敏感,100最敏感 */
  175. CompareItemDetectParam_t() = default;
  176. CompareItemDetectParam_t(const CompareItemDetectParam_t &other);
  177. CompareItemDetectParam_t& operator=(const CompareItemDetectParam_t &other);
  178. };
  179. /**
  180. * @brief 对比项信息
  181. *
  182. */
  183. struct CompareItemInfo_t
  184. {
  185. int nID = -1; /* 对比项ID,对比项唯一识别号,不可更改 */
  186. QString strName; /* 对比项名称 */
  187. bool isEnable = false; /* 对比项状态,是否启用 */
  188. QMap<int, CompareItemRoadInfo_t> mapRoad; /* 通道信息列表,int是通道编号,在对比项中的编号 */
  189. CompareItemDetectParam_t paramMute; /* 静音检测参数 */
  190. CompareItemDetectParam_t paramOverload; /* 过载检测参数 */
  191. CompareItemDetectParam_t paramPhase; /* 反相检测参数 */
  192. CompareItemInfo_t() = default;
  193. CompareItemInfo_t(const CompareItemInfo_t &other);
  194. CompareItemInfo_t& operator=(const CompareItemInfo_t &other);
  195. /* 判断对比想基础部分是否相等,不包含通道信息 */
  196. bool isEqualBase(const CompareItemInfo_t &other) const;
  197. /* 判断对比项的通道是否相同 */
  198. bool isEqualRoads(const CompareItemInfo_t &other) const;
  199. };
  200. /* =============================================================================
  201. * 检测时段配置
  202. * ============================================================================= */
  203. /**
  204. * @brief 一个对比项的检测计划
  205. *
  206. */
  207. struct DetectPeriodConfig_t
  208. {
  209. int nID = 0; /* ID */
  210. bool isApplySlient = false; /* 计划日期是否应用静音 */
  211. bool isApplyOverload = false; /* 计划日期是否应用超载 */
  212. bool isApplyPhase = false; /* 计划日期是否应用反相 */
  213. bool isApplyNoise = false; /* 计划日期是否应用噪音 */
  214. QList<OnePlan_t> listDetect; /* 检测计划列表 */
  215. QList<OnePlan_t> listNoDetect; /* 非检测计划列表 */
  216. bool operator==(const DetectPeriodConfig_t &other) const;
  217. /* 判断基础信息是否更改 */
  218. bool isBaseInfoChanged(const DetectPeriodConfig_t &other) const;
  219. };
  220. /**
  221. * @brief 非检测计划应用清空
  222. *
  223. */
  224. struct NoDetectPlanApply_t
  225. {
  226. int nID = 0; /* ID */
  227. bool isApplySlient = false; /* 非检测计划日期是否应用静音 */
  228. bool isApplyOverload = false; /* 非检测计划日期是否应用超载 */
  229. bool isApplyPhase = false; /* 非检测计划日期是否应用反相 */
  230. bool isApplyNoise = false; /* 非检测计划日期是否应用噪音 */
  231. };
  232. /* =========================================================================================
  233. * 线程信息相关枚举和结构体
  234. * =========================================================================================*/
  235. /**
  236. * @brief 线程状态枚举
  237. *
  238. */
  239. enum class EThreadState
  240. {
  241. State_None = 0, /* 无状态 */
  242. State_Inited, /* 已初始化 */
  243. State_Running, /* 运行中 */
  244. State_Stopped, /* 已停止 */
  245. State_Error /* 错误状态 */
  246. };
  247. /**
  248. * @brief 线程类型枚举
  249. *
  250. */
  251. enum class EThreadType
  252. {
  253. Type_None = 0, /* 无类型 */
  254. Type_RecordSrc, /* 录音源线程 */
  255. Type_AssignSrcData, /* 分派数据线程 */
  256. Type_CreateWAV, /* 生成WAV文件线程 */
  257. Type_CreateDB, /* 生成音量包的线程 */
  258. // Type_CreateNoise, /* 生成噪音数据线程 */
  259. Type_CreateLongWAV, /* 生成长文件线程 */
  260. Type_RtpSend, /* RTP发送线程 */
  261. Type_ConsistencyCheck, /* 一致性检查线程 */
  262. Type_CalculateDB, /* 计算音量的线程 */
  263. Type_CompareItem, /* 对比项线程 */
  264. };
  265. /**
  266. * @brief 录音线程信息结构体
  267. */
  268. struct RecordThreadInfo_t
  269. {
  270. SoundCardRoadInfo_t cardRoadInfo; /* 录音通道信息 */
  271. EThreadType threadType; /* 线程类型 */
  272. EThreadState threadState; /* 线程状态 */
  273. // BaseRecordThread* pThread = nullptr; /* 线程对象 */
  274. };
  275. /* =========================================================================================
  276. * 报警信息结构体
  277. * =========================================================================================*/
  278. class BaseCalculateThread;
  279. /**
  280. * @brief 计算线程信息结构体
  281. *
  282. */
  283. struct CalculateThreadInfo_t
  284. {
  285. CompareItemInfo_t compareItemInfo; /* 对比项信息 */
  286. EThreadType threadType; /* 线程类型 */
  287. EThreadState threadState; /* 线程状态 */
  288. // BaseCalculateThread* pThread = nullptr; /* 计算线程对象 */
  289. CalculateThreadInfo_t() = default;
  290. CalculateThreadInfo_t(const CalculateThreadInfo_t& info);
  291. CalculateThreadInfo_t& operator=(const CalculateThreadInfo_t& info);
  292. };
  293. /**
  294. * @brief 报警结构体
  295. *
  296. */
  297. struct AlarmInfo_t
  298. {
  299. bool isAlarm = false; /* 是否报警 */
  300. int CompareItemID = 0; /* 对比项ID */
  301. std::string strCompareItemName; /* 对比项名称 */
  302. CompareItemRoadInfo_t RoadInfo; /* 录音通道信息 */
  303. ERoadType RoadType; /* 录音通道类型 */
  304. EAlarmType AlarmType = EAlarmType::EAT_None; /* 报警类型 */
  305. QDateTime StartTime; /* 报警开始时间 */
  306. QDateTime EndTime; /* 报警结束时间 */
  307. // std::string strAlarmStartTime; /* 报警发生时间 */
  308. // std::string strAlarmEndTime; /* 报警结束时间 */
  309. // std::string strAlarmExistTime; /* 报警持续时间 */
  310. std::string strAlarmFilePath; /* 报警文件路径 */
  311. int AlarmStartPos = 0; /* 报警开始位置 */
  312. QDateTime AlarmFileStartTime; /* 录音文件开始时间 */
  313. AlarmInfo_t() = default;
  314. AlarmInfo_t(const AlarmInfo_t& obj) { *this = obj; }
  315. AlarmInfo_t& operator=(const AlarmInfo_t& obj);
  316. /* 比较是否相等,主要是比较是否报警、通道ID,报警类型,报警时间 */
  317. bool operator==(const AlarmInfo_t& other) const;
  318. };
  319. #endif // __GLOBAL_VARIABLE_H__