GlobalVariable.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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. enum class eRecordState
  55. {
  56. eRS_Init = 0, /* 初始化状态 */
  57. eRS_Recording, /* 录音中 */
  58. eRS_RecordCompleted, /* 录音完成 */
  59. eRS_Deleted, /* 录音已删除 */
  60. eRS_Error, /* 错误状态 */
  61. };
  62. /* ====================================================================
  63. * 结构体
  64. * ==================================================================== */
  65. /**
  66. * @brief 一条计划
  67. *
  68. */
  69. struct OnePlan_t
  70. {
  71. eWeekType weekType; /* 星期类型 */
  72. QDate date; /* 日期,格式为YYYY-MM-DD */
  73. QTime timeStart; /* 时间,格式为HH:mm:ss */
  74. QTime timeEnd; /* 时间,格式为HH:mm:ss */
  75. bool operator==(const OnePlan_t &other) const
  76. {
  77. return (weekType == other.weekType) && (date == other.date) && (timeStart == other.timeStart) && (timeEnd == other.timeEnd);
  78. }
  79. bool operator!=(const OnePlan_t &other) const
  80. {
  81. return !(*this == other);
  82. }
  83. };
  84. /* ====================================================================
  85. * 声卡相关信息结构体
  86. * ==================================================================== */
  87. /* 单个录音通道信息,带有频道信息 */
  88. struct OneRoadInfo_t
  89. {
  90. int nRoadNum = -1; /* 录音通道编号,是声卡在系统中的物理编号 */
  91. int nChannelID = -1; /* 频道ID */
  92. QString strChannelName; /* 频道名称 */
  93. };
  94. /**
  95. * @brief 声卡信息,这里的信息都是设备上和物理声卡相关的
  96. *
  97. */
  98. struct SoundCardInfo_t
  99. {
  100. int nSoundCardNum = -1; /* 声卡编号,系统上的物理编号 */
  101. QString strSoundCardID; /* 声卡ID,这个是声卡名称,可以用来打开 */
  102. QString strSoundCardName; /* 声卡名称 */
  103. QString strSoundCardDriver; /* 声卡驱动名称 */
  104. QList<OneRoadInfo_t> listRoad; /* 录音通道列表,存储通道编号 */
  105. };
  106. /**
  107. * @brief 单个声卡通道信息,带有声卡自身的信息
  108. *
  109. */
  110. struct SoundCardRoadInfo_t
  111. {
  112. int nSoundCardNum = -1; /* 声卡编号 */
  113. QString strSoundCardID; /* 声卡ID,这个是声卡名称,可以用来打开 */
  114. QString strSoundCardName; /* 声卡名称 */
  115. OneRoadInfo_t roadInfo; /* 单个通道信息 */
  116. bool operator<(const SoundCardRoadInfo_t &other) const;
  117. };
  118. /* 使用声卡通道最为Key的结构体 */
  119. struct SoundCardRoadKey_t
  120. {
  121. int nSoundCardNum = -1; /* 声卡编号 */
  122. int nRoadNum = -1; /* 通道编号 */
  123. bool operator==(const SoundCardRoadKey_t &other) const
  124. {
  125. return (nSoundCardNum == other.nSoundCardNum) && (nRoadNum == other.nRoadNum);
  126. }
  127. bool operator<(const SoundCardRoadKey_t &other) const
  128. {
  129. if(nSoundCardNum < other.nSoundCardNum)
  130. return true;
  131. if(nSoundCardNum > other.nSoundCardNum)
  132. return false;
  133. return nRoadNum < other.nRoadNum;
  134. }
  135. };
  136. /* 注册数据类型到系统 */
  137. Q_DECLARE_METATYPE(SoundCardRoadInfo_t)
  138. /* ====================================================================
  139. * CompareItemInfo_t对比项结构体
  140. * ==================================================================== */
  141. /**
  142. * @brief 对比项信息在表格中的显示结构体
  143. *
  144. */
  145. struct CompareItemTableItem_t
  146. {
  147. int nSerialNum; /* 序号,在表格中的序号 */
  148. int nID; /* 对比项ID */
  149. QString strName; /* 对比项名称 */
  150. bool isEnable; /* 对比项状态,是否启用 */
  151. int nChannelCount; /* 通道数 */
  152. };
  153. /* 对比项的通道信息 */
  154. struct CompareItemRoadInfo_t
  155. {
  156. bool isEnableRecord; /* 是否开启录音 */
  157. int nCompareRoadNum; /* 对比通道编号,1是主通道,其余往后排 */
  158. QString strCompareRoadName; /* 对比项通道名称,不是声卡的通道名 */
  159. SoundCardRoadInfo_t scRoadInfo; /* 声卡通道信息,包含声卡编号和通道编号 */
  160. bool operator==(const CompareItemRoadInfo_t &other) const;
  161. };
  162. /* 一个对比项通道信息,包含对比项信息 */
  163. struct OneCompareItemRoadInfo_t
  164. {
  165. int nCompareItemID = -1; /* 对比项ID */
  166. int nCompareRoadNum = -1; /* 对比项通道编号 */
  167. int nSoundCardNum = -1; /* 声卡编号 */
  168. int nSoundCardRoadNum = -1; /* 声卡通道编号 */
  169. QString strCompareItemName; /* 对比项名称 */
  170. QString strCompareRoadName; /* 对比项通道名称 */
  171. OneCompareItemRoadInfo_t() = default;
  172. OneCompareItemRoadInfo_t(const OneCompareItemRoadInfo_t &other);
  173. OneCompareItemRoadInfo_t& operator=(const OneCompareItemRoadInfo_t &other);
  174. bool operator==(const OneCompareItemRoadInfo_t &other) const;
  175. };
  176. /* 检测阈值,静音和过载是整数,反相是小数 */
  177. union Threshold_t
  178. {
  179. int64_t nThreshold; /* 静音和过载的阈值 */
  180. double dThreshold; /* 反相的阈值 */
  181. };
  182. /**
  183. * @brief 静音、过载、反相检测参数
  184. *
  185. */
  186. struct CompareItemDetectParam_t
  187. {
  188. bool isEnable = false; /* 是否启用检测 */
  189. Threshold_t threshold; /* 检测阈值 */
  190. int nLen = 0; /* 检测长度,单位秒 */
  191. int nSensitivity = 0; /* 敏感度,0-100,0最不敏感,100最敏感 */
  192. CompareItemDetectParam_t() = default;
  193. CompareItemDetectParam_t(const CompareItemDetectParam_t &other);
  194. CompareItemDetectParam_t& operator=(const CompareItemDetectParam_t &other);
  195. };
  196. /**
  197. * @brief 对比项信息
  198. *
  199. */
  200. struct CompareItemInfo_t
  201. {
  202. int nID = -1; /* 对比项ID,对比项唯一识别号,不可更改 */
  203. QString strName; /* 对比项名称 */
  204. bool isEnable = false; /* 对比项状态,是否启用 */
  205. QMap<int, CompareItemRoadInfo_t> mapRoad; /* 通道信息列表,int是通道编号,在对比项中的编号 */
  206. CompareItemDetectParam_t paramMute; /* 静音检测参数 */
  207. CompareItemDetectParam_t paramOverload; /* 过载检测参数 */
  208. CompareItemDetectParam_t paramPhase; /* 反相检测参数 */
  209. CompareItemInfo_t() = default;
  210. CompareItemInfo_t(const CompareItemInfo_t &other);
  211. CompareItemInfo_t& operator=(const CompareItemInfo_t &other);
  212. /* 判断对比想基础部分是否相等,不包含通道信息 */
  213. bool isEqualBase(const CompareItemInfo_t &other) const;
  214. /* 判断对比项的通道是否相同 */
  215. bool isEqualRoads(const CompareItemInfo_t &other) const;
  216. };
  217. /* =============================================================================
  218. * 检测时段配置
  219. * ============================================================================= */
  220. /**
  221. * @brief 一个对比项的检测计划
  222. *
  223. */
  224. struct DetectPeriodConfig_t
  225. {
  226. int nID = 0; /* ID */
  227. bool isApplySlient = false; /* 计划日期是否应用静音 */
  228. bool isApplyOverload = false; /* 计划日期是否应用超载 */
  229. bool isApplyPhase = false; /* 计划日期是否应用反相 */
  230. bool isApplyNoise = false; /* 计划日期是否应用噪音 */
  231. QList<OnePlan_t> listDetect; /* 检测计划列表 */
  232. QList<OnePlan_t> listNoDetect; /* 非检测计划列表 */
  233. bool operator==(const DetectPeriodConfig_t &other) const;
  234. /* 判断基础信息是否更改 */
  235. bool isBaseInfoChanged(const DetectPeriodConfig_t &other) const;
  236. };
  237. /**
  238. * @brief 非检测计划应用清空
  239. *
  240. */
  241. struct NoDetectPlanApply_t
  242. {
  243. int nID = 0; /* ID */
  244. bool isApplySlient = false; /* 非检测计划日期是否应用静音 */
  245. bool isApplyOverload = false; /* 非检测计划日期是否应用超载 */
  246. bool isApplyPhase = false; /* 非检测计划日期是否应用反相 */
  247. bool isApplyNoise = false; /* 非检测计划日期是否应用噪音 */
  248. };
  249. /* =========================================================================================
  250. * 线程信息相关枚举和结构体
  251. * =========================================================================================*/
  252. /**
  253. * @brief 线程状态枚举
  254. *
  255. */
  256. enum class EThreadState
  257. {
  258. State_None = 0, /* 无状态 */
  259. State_Inited, /* 已初始化 */
  260. State_Running, /* 运行中 */
  261. State_Stopped, /* 已停止 */
  262. State_Error /* 错误状态 */
  263. };
  264. /**
  265. * @brief 线程类型枚举
  266. *
  267. */
  268. enum class EThreadType
  269. {
  270. Type_None = 0, /* 无类型 */
  271. Type_RecordSrc, /* 录音源线程 */
  272. Type_AssignSrcData, /* 分派数据线程 */
  273. Type_CreateWAV, /* 生成WAV文件线程 */
  274. Type_CreateDB, /* 生成音量包的线程 */
  275. // Type_CreateNoise, /* 生成噪音数据线程 */
  276. Type_CreateLongWAV, /* 生成长文件线程 */
  277. Type_RtpSend, /* RTP发送线程 */
  278. Type_ConsistencyCheck, /* 一致性检查线程 */
  279. Type_CalculateDB, /* 计算音量的线程 */
  280. Type_CompareItem, /* 对比项线程 */
  281. };
  282. /**
  283. * @brief 录音线程信息结构体
  284. */
  285. struct RecordThreadInfo_t
  286. {
  287. SoundCardRoadInfo_t cardRoadInfo; /* 录音通道信息 */
  288. EThreadType threadType; /* 线程类型 */
  289. EThreadState threadState; /* 线程状态 */
  290. // BaseRecordThread* pThread = nullptr; /* 线程对象 */
  291. };
  292. /* =========================================================================================
  293. * 报警信息结构体
  294. * =========================================================================================*/
  295. class BaseCalculateThread;
  296. /**
  297. * @brief 计算线程信息结构体
  298. *
  299. */
  300. struct CalculateThreadInfo_t
  301. {
  302. CompareItemInfo_t compareItemInfo; /* 对比项信息 */
  303. EThreadType threadType; /* 线程类型 */
  304. EThreadState threadState; /* 线程状态 */
  305. // BaseCalculateThread* pThread = nullptr; /* 计算线程对象 */
  306. CalculateThreadInfo_t() = default;
  307. CalculateThreadInfo_t(const CalculateThreadInfo_t& info);
  308. CalculateThreadInfo_t& operator=(const CalculateThreadInfo_t& info);
  309. };
  310. /**
  311. * @brief 报警结构体
  312. *
  313. */
  314. struct AlarmInfo_t
  315. {
  316. bool isAlarm = false; /* 是否报警 */
  317. int CompareItemID = 0; /* 对比项ID */
  318. QString strCompareItemName; /* 对比项名称 */
  319. CompareItemRoadInfo_t RoadInfo; /* 录音通道信息 */
  320. ERoadType RoadType; /* 录音通道类型 */
  321. EAlarmType AlarmType = EAlarmType::EAT_None; /* 报警类型 */
  322. QDateTime StartTime; /* 报警开始时间 */
  323. QDateTime EndTime; /* 报警结束时间 */
  324. QString strAlarmFilePath; /* 报警文件路径 */
  325. int AlarmStartPos = 0; /* 报警开始位置 */
  326. QDateTime AlarmFileStartTime; /* 录音文件开始时间 */
  327. eRecordState fileState = eRecordState::eRS_Init; /* 录音文件状态 */
  328. int PKID = -1; /* 主键ID,数据库使用 */
  329. AlarmInfo_t() = default;
  330. AlarmInfo_t(const AlarmInfo_t& obj) { *this = obj; }
  331. AlarmInfo_t& operator=(const AlarmInfo_t& obj);
  332. /* 比较是否相等,主要是比较是否报警、通道ID,报警类型,报警时间 */
  333. bool operator==(const AlarmInfo_t& other) const;
  334. };
  335. /* =========================================================================================
  336. * 录音文件结构体
  337. * =========================================================================================*/
  338. struct RecordFileInfo_t
  339. {
  340. int ItemID = -1; /* 对比项ID */
  341. QString ItemName; /* 对比项名称 */
  342. int ItemRoadNum = -1; /* 对比项通道编号 */
  343. QString ItemRoadName; /* 对比项通道名称 */
  344. int SoundCardNum = -1; /* 声卡编号 */
  345. int SoundCardRoadNum = -1; /* 声卡通道编号 */
  346. QDateTime FileStartTime; /* 文件开始时间 */
  347. QDateTime FileEndTime; /* 文件结束时间 */
  348. int FileDuration = 0; /* 文件时长,单位秒 */
  349. QString FilePath; /* 文件路径 */
  350. eRecordState fileState; /* 录音文件状态 */
  351. RecordFileInfo_t() = default;
  352. RecordFileInfo_t(const RecordFileInfo_t& obj) { *this = obj; }
  353. RecordFileInfo_t& operator=(const RecordFileInfo_t& obj);
  354. };
  355. #endif // __GLOBAL_VARIABLE_H__