GlobalVariable.h 16 KB

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