GlobalVariable.h 12 KB

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