GlobalVariable.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. struct OnePlan_t
  31. {
  32. eWeekType weekType; /* 星期类型 */
  33. QDate date; /* 日期,格式为YYYY-MM-DD */
  34. QTime timeStart; /* 时间,格式为HH:mm:ss */
  35. QTime timeEnd; /* 时间,格式为HH:mm:ss */
  36. bool operator==(const OnePlan_t &other) const
  37. {
  38. return (weekType == other.weekType) && (date == other.date) && (timeStart == other.timeStart) && (timeEnd == other.timeEnd);
  39. }
  40. bool operator!=(const OnePlan_t &other) const
  41. {
  42. return !(*this == other);
  43. }
  44. };
  45. /* ====================================================================
  46. * 声卡相关信息结构体
  47. * ==================================================================== */
  48. /* 单个录音通道信息,带有频道信息 */
  49. struct OneRoadInfo_t
  50. {
  51. int nRoadNum = -1; /* 录音通道编号,是声卡在系统中的物理编号 */
  52. int nChannelID = -1; /* 频道ID */
  53. QString strChannelName; /* 频道名称 */
  54. };
  55. /**
  56. * @brief 声卡信息,这里的信息都是设备上和物理声卡相关的
  57. *
  58. */
  59. struct SoundCardInfo_t
  60. {
  61. int nSoundCardNum = -1; /* 声卡编号,系统上的物理编号 */
  62. QString strSoundCardID; /* 声卡ID,这个是声卡名称,可以用来打开 */
  63. QString strSoundCardName; /* 声卡名称 */
  64. QString strSoundCardDriver; /* 声卡驱动名称 */
  65. QList<OneRoadInfo_t> listRoad; /* 录音通道列表,存储通道编号 */
  66. };
  67. /**
  68. * @brief 单个声卡通道信息,带有声卡自身的信息
  69. *
  70. */
  71. struct SoundCardRoadInfo_t
  72. {
  73. int nSoundCardNum = -1; /* 声卡编号 */
  74. QString strSoundCardID; /* 声卡ID,这个是声卡名称,可以用来打开 */
  75. QString strSoundCardName; /* 声卡名称 */
  76. OneRoadInfo_t roadInfo; /* 单个通道信息 */
  77. bool operator<(const SoundCardRoadInfo_t &other) const;
  78. };
  79. /* 注册数据类型到系统 */
  80. Q_DECLARE_METATYPE(SoundCardRoadInfo_t)
  81. /* ====================================================================
  82. * CompareItemInfo_t对比项结构体
  83. * ==================================================================== */
  84. /**
  85. * @brief 对比项信息在表格中的显示结构体
  86. *
  87. */
  88. struct CompareItemTableItem_t
  89. {
  90. int nSerialNum; /* 序号,在表格中的序号 */
  91. int nID; /* 对比项ID */
  92. QString strName; /* 对比项名称 */
  93. bool isEnable; /* 对比项状态,是否启用 */
  94. int nChannelCount; /* 通道数 */
  95. };
  96. /* 对比项的通道信息 */
  97. struct CompareItemRoadInfo_t
  98. {
  99. bool isEnableRecord; /* 是否开启录音 */
  100. int nCompareRoadNum; /* 对比通道编号,1是主通道,其余往后排 */
  101. QString strCompareRoadName; /* 对比项通道名称,不是声卡的通道名 */
  102. SoundCardRoadInfo_t scRoadInfo; /* 声卡通道信息,包含声卡编号和通道编号 */
  103. bool operator==(const CompareItemRoadInfo_t &other) const;
  104. };
  105. /* 检测阈值,静音和过载是整数,反相是小数 */
  106. union Threshold_t
  107. {
  108. uint64_t nThreshold; /* 静音和过载的阈值 */
  109. double dThreshold; /* 反相的阈值 */
  110. };
  111. /**
  112. * @brief 静音、过载、反相检测参数
  113. *
  114. */
  115. struct CompareItemDetectParam_t
  116. {
  117. bool isEnable = false; /* 是否启用检测 */
  118. Threshold_t threshold; /* 检测阈值 */
  119. int nLen = 0; /* 检测长度,单位秒 */
  120. int nSensitivity = 0; /* 敏感度,0-100,0最不敏感,100最敏感 */
  121. CompareItemDetectParam_t() = default;
  122. CompareItemDetectParam_t(const CompareItemDetectParam_t &other);
  123. CompareItemDetectParam_t& operator=(const CompareItemDetectParam_t &other);
  124. };
  125. /**
  126. * @brief 对比项信息
  127. *
  128. */
  129. struct CompareItemInfo_t
  130. {
  131. int nID = -1; /* 对比项ID,对比项唯一识别号,不可更改 */
  132. QString strName; /* 对比项名称 */
  133. bool isEnable = false; /* 对比项状态,是否启用 */
  134. QMap<int, CompareItemRoadInfo_t> mapRoad; /* 通道信息列表,int是通道编号,在对比项中的编号 */
  135. CompareItemDetectParam_t paramMute; /* 静音检测参数 */
  136. CompareItemDetectParam_t paramOverload; /* 过载检测参数 */
  137. CompareItemDetectParam_t paramPhase; /* 反相检测参数 */
  138. CompareItemInfo_t() = default;
  139. CompareItemInfo_t(const CompareItemInfo_t &other);
  140. CompareItemInfo_t& operator=(const CompareItemInfo_t &other);
  141. /* 判断对比想基础部分是否相等,不包含通道信息 */
  142. bool isEqualBase(const CompareItemInfo_t &other) const;
  143. /* 判断对比项的通道是否相同 */
  144. bool isEqualRoads(const CompareItemInfo_t &other) const;
  145. };
  146. /* =============================================================================
  147. * 检测时段配置
  148. * ============================================================================= */
  149. /**
  150. * @brief 一个对比项的检测计划
  151. *
  152. */
  153. struct DetectPeriodConfig_t
  154. {
  155. int nID = 0; /* ID */
  156. bool isApplySlient = false; /* 非检测计划日期是否应用静音 */
  157. bool isApplyOverload = false; /* 非检测计划日期是否应用超载 */
  158. bool isApplyPhase = false; /* 非检测计划日期是否应用反相 */
  159. bool isApplyNoise = false; /* 非检测计划日期是否应用噪音 */
  160. QList<OnePlan_t> listDetect; /* 检测计划列表 */
  161. QList<OnePlan_t> listNoDetect; /* 非检测计划列表 */
  162. bool operator==(const DetectPeriodConfig_t &other) const;
  163. /* 判断基础信息是否更改 */
  164. bool isBaseInfoChanged(const DetectPeriodConfig_t &other) const;
  165. };
  166. /**
  167. * @brief 非检测计划应用清空
  168. *
  169. */
  170. struct NoDetectPlanApply_t
  171. {
  172. int nID = 0; /* ID */
  173. bool isApplySlient = false; /* 非检测计划日期是否应用静音 */
  174. bool isApplyOverload = false; /* 非检测计划日期是否应用超载 */
  175. bool isApplyPhase = false; /* 非检测计划日期是否应用反相 */
  176. bool isApplyNoise = false; /* 非检测计划日期是否应用噪音 */
  177. };
  178. /* =========================================================================================
  179. * 线程信息相关枚举和结构体
  180. * =========================================================================================*/
  181. /**
  182. * @brief 线程状态枚举
  183. *
  184. */
  185. enum class EThreadState
  186. {
  187. State_None = 0, /* 无状态 */
  188. State_Inited, /* 已初始化 */
  189. State_Running, /* 运行中 */
  190. State_Stopped, /* 已停止 */
  191. State_Error /* 错误状态 */
  192. };
  193. /**
  194. * @brief 线程类型枚举
  195. *
  196. */
  197. enum class EThreadType
  198. {
  199. Type_None = 0, /* 无类型 */
  200. Type_RecordSrc, /* 录音源线程 */
  201. Type_AssignSrcData, /* 分派数据线程 */
  202. Type_CreateWAV, /* 生成WAV文件线程 */
  203. Type_CreateDB, /* 生成音量包的线程 */
  204. // Type_CreateNoise, /* 生成噪音数据线程 */
  205. Type_CreateLongWAV, /* 生成长文件线程 */
  206. Type_RtpSend, /* RTP发送线程 */
  207. Type_ConsistencyCheck, /* 一致性检查线程 */
  208. Type_CalculateDB, /* 计算音量的线程 */
  209. Type_CompareItem, /* 对比项线程 */
  210. };
  211. /**
  212. * @brief 录音线程信息结构体
  213. */
  214. struct RecordThreadInfo_t
  215. {
  216. SoundCardRoadInfo_t cardRoadInfo; /* 录音通道信息 */
  217. EThreadType threadType; /* 线程类型 */
  218. EThreadState threadState; /* 线程状态 */
  219. // BaseRecordThread* pThread = nullptr; /* 线程对象 */
  220. };
  221. class BaseCalculateThread;
  222. /**
  223. * @brief 计算线程信息结构体
  224. *
  225. */
  226. struct CalculateThreadInfo_t
  227. {
  228. CompareItemInfo_t compareItemInfo; /* 对比项信息 */
  229. EThreadType threadType; /* 线程类型 */
  230. EThreadState threadState; /* 线程状态 */
  231. // BaseCalculateThread* pThread = nullptr; /* 计算线程对象 */
  232. CalculateThreadInfo_t() = default;
  233. CalculateThreadInfo_t(const CalculateThreadInfo_t& info);
  234. CalculateThreadInfo_t& operator=(const CalculateThreadInfo_t& info);
  235. };
  236. #endif // __GLOBAL_VARIABLE_H__