#ifndef __GLOBAL_VARIABLE_H__ #define __GLOBAL_VARIABLE_H__ #include #include #include #include #include #include #include /* 声卡识别符号,在PCM通道中通过这个字符识别是属于哪些声卡的 */ #define SC_System "SystemDefault" /* 不需要识别的声卡 */ #define SC_AlpDANTE "AlpDANTE" /* dante声卡 */ /** * @brief 星期枚举定义,星期八是带有日期的特殊日 * */ enum class eWeekType { Week_Monday = 1, /* 星期一 */ Week_Tuesday, /* 星期二 */ Week_Wednesday, /* 星期三 */ Week_Thursday, /* 星期四 */ Week_Friday, /* 星期五 */ Week_Saturday, /* 星期六 */ Week_Sunday, /* 星期日 */ Week_Special, /* 特殊日期 */ }; Q_DECLARE_METATYPE(eWeekType) extern const QMap MapWeekTypeToString; /** * @brief 录音通道类型 * */ enum class ERoadType { RoadType_Main = 0, /* 主输出 */ RoadType_SpaceReceive, /* 空间接收 */ RoadType_SpaceSend, /* 空间发送 */ }; /** * @brief 报警类型 * */ enum class EAlarmType { EAT_None = 0, /* 无报警 */ EAT_Silent, /* 静音报警 */ EAT_Overload, /* 过载报警 */ EAT_Reversed, /* 反相报警 */ EAR_Consistency, /* 一致性报警 */ EAT_Noise, /* 噪音报警 */ EAT_Unknown, /* 未知报警 */ }; /** * @brief 录音状态,录音中、录音完成,已删除这三个是和客户端的协议,不能更改 * */ enum class eRecordState { eRS_Init = 0, /* 初始化状态 */ eRS_Recording, /* 录音中 */ eRS_RecordCompleted, /* 录音完成 */ eRS_Deleted, /* 录音已删除 */ eRS_Error, /* 错误状态 */ }; /* ==================================================================== * 结构体 * ==================================================================== */ /** * @brief 一条计划 * */ struct OnePlan_t { eWeekType weekType; /* 星期类型 */ QDate date; /* 日期,格式为YYYY-MM-DD */ QTime timeStart; /* 时间,格式为HH:mm:ss */ QTime timeEnd; /* 时间,格式为HH:mm:ss */ bool operator==(const OnePlan_t &other) const { return (weekType == other.weekType) && (date == other.date) && (timeStart == other.timeStart) && (timeEnd == other.timeEnd); } bool operator!=(const OnePlan_t &other) const { return !(*this == other); } }; /* ==================================================================== * 声卡相关信息结构体 * ==================================================================== */ /* 单个录音通道信息,带有频道信息 */ // struct OneRoadInfo_t // { // int nRoadNum = -1; /* 录音通道编号,是声卡在系统中的物理编号 */ // int nChannelID = -1; /* 频道ID */ // QString strChannelName; /* 频道名称 */ // }; /** * @brief 声卡信息,这里的信息都是设备上和物理声卡相关的 * */ // struct SoundCardInfo_t // { // int nSoundCardNum = -1; /* 声卡编号,系统上的物理编号 */ // QString strSoundCardID; /* 声卡ID,这个是声卡名称,可以用来打开 */ // QString strSoundCardName; /* 声卡名称 */ // QString strSoundCardDriver; /* 声卡驱动名称 */ // QList listRoad; /* 录音通道列表,存储通道编号 */ // }; /** * @brief 单个声卡通道信息,带有声卡自身的信息 * */ // struct SoundCardRoadInfo_t // { // int nSoundCardNum = -1; /* 声卡编号 */ // QString strSoundCardID; /* 声卡ID,这个是声卡名称,可以用来打开 */ // QString strSoundCardName; /* 声卡名称 */ // OneRoadInfo_t roadInfo; /* 单个通道信息 */ // bool operator<(const SoundCardRoadInfo_t &other) const; // }; /* 使用声卡通道最为Key的结构体 */ struct SoundCardRoadKey_t { int nSoundCardNum = -1; /* 声卡编号 */ int nRoadNum = -1; /* 通道编号 */ bool operator==(const SoundCardRoadKey_t &other) const { return (nSoundCardNum == other.nSoundCardNum) && (nRoadNum == other.nRoadNum); } bool operator<(const SoundCardRoadKey_t &other) const { if(nSoundCardNum < other.nSoundCardNum) return true; if(nSoundCardNum > other.nSoundCardNum) return false; return nRoadNum < other.nRoadNum; } }; /* 注册数据类型到系统 */ // Q_DECLARE_METATYPE(SoundCardRoadInfo_t) /** * @brief 声卡PCM通道信息 * */ struct OnePCMChannelInfo_t { std::string strPCMName; /* PCM名称,可以使用这个直接打开录音通道,这个在系统中是唯一的 */ std::string strPCMDesc; /* PCM描述 */ std::string strIO; /* 输入输出 */ }; /** * @brief 声卡描述符信息,声卡名称这里不定义,从设置动态库中定义 * */ struct SoundCardPCMInfo_t { std::string strSoundCardName; /* 声卡名称,这个是自定义的,用来识别系统中的PCM通道 */ std::list listPCM; /* PCM信息列表 */ }; /* 带有声卡名称信息的PCM通道 */ struct OneSoundCardPCMInfo_t { std::string strSoundCardName; /* 声卡名称,这个是自定义的,用来识别系统中的PCM通道 */ OnePCMChannelInfo_t pcmInfo; /* PCM信息 */ bool operator==(const OneSoundCardPCMInfo_t& obj) const; }; /* ==================================================================== * CompareItemInfo_t对比项结构体 * ==================================================================== */ /** * @brief 对比项信息在表格中的显示结构体 * */ struct CompareItemTableItem_t { int nSerialNum; /* 序号,在表格中的序号 */ int nID; /* 对比项ID */ QString strName; /* 对比项名称 */ bool isEnable; /* 对比项状态,是否启用 */ int nChannelCount; /* 通道数 */ }; /* 对比项的通道信息 */ struct CompareItemRoadInfo_t { bool isEnableRecord; /* 是否开启录音 */ int nCompareRoadNum; /* 对比通道编号,1是主通道,其余往后排 */ QString strCompareRoadName; /* 对比项通道名称,不是声卡的通道名 */ // SoundCardRoadInfo_t scRoadInfo; /* 声卡通道信息,包含声卡编号和通道编号 */ OneSoundCardPCMInfo_t scRoadInfo; /* 声卡通道信息,包含声卡名称和PCM名称 */ bool operator==(const CompareItemRoadInfo_t &other) const; }; /* 一个对比项通道信息,包含对比项信息 */ struct OneCompareItemRoadInfo_t { int nCompareItemID = -1; /* 对比项ID */ int nCompareRoadNum = -1; /* 对比项通道编号 */ QString strCompareItemName; /* 对比项名称 */ QString strCompareRoadName; /* 对比项通道名称 */ OneSoundCardPCMInfo_t scRoadInfo; /* 声卡通道信息,包含声卡名称和PCM名称 */ OneCompareItemRoadInfo_t() = default; OneCompareItemRoadInfo_t(const OneCompareItemRoadInfo_t &other); OneCompareItemRoadInfo_t& operator=(const OneCompareItemRoadInfo_t &other); bool operator==(const OneCompareItemRoadInfo_t &other) const; }; /* 检测阈值,静音和过载是整数,反相是小数 */ union Threshold_t { int64_t nThreshold; /* 静音和过载的阈值 */ double dThreshold; /* 反相的阈值 */ }; /** * @brief 静音、过载、反相检测参数 * */ struct CompareItemDetectParam_t { bool isEnable = false; /* 是否启用检测 */ Threshold_t threshold; /* 检测阈值 */ int nLen = 0; /* 检测长度,单位秒 */ int nSensitivity = 0; /* 敏感度,0-100,0最不敏感,100最敏感 */ CompareItemDetectParam_t() = default; CompareItemDetectParam_t(const CompareItemDetectParam_t &other); CompareItemDetectParam_t& operator=(const CompareItemDetectParam_t &other); }; /** * @brief 对比项信息 * */ struct CompareItemInfo_t { int nID = -1; /* 对比项ID,对比项唯一识别号,不可更改 */ QString strName; /* 对比项名称 */ bool isEnable = false; /* 对比项状态,是否启用 */ QMap mapRoad; /* 通道信息列表,int是通道编号,在对比项中的编号 */ CompareItemDetectParam_t paramMute; /* 静音检测参数 */ CompareItemDetectParam_t paramOverload; /* 过载检测参数 */ CompareItemDetectParam_t paramPhase; /* 反相检测参数 */ CompareItemInfo_t() = default; CompareItemInfo_t(const CompareItemInfo_t &other); CompareItemInfo_t& operator=(const CompareItemInfo_t &other); /* 判断对比想基础部分是否相等,不包含通道信息 */ bool isEqualBase(const CompareItemInfo_t &other) const; /* 判断对比项的通道是否相同 */ bool isEqualRoads(const CompareItemInfo_t &other) const; }; /* ============================================================================= * 检测时段配置 * ============================================================================= */ /** * @brief 一个对比项的检测计划 * */ struct DetectPeriodConfig_t { int nID = 0; /* ID */ bool isApplySlient = false; /* 计划日期是否应用静音 */ bool isApplyOverload = false; /* 计划日期是否应用超载 */ bool isApplyPhase = false; /* 计划日期是否应用反相 */ bool isApplyNoise = false; /* 计划日期是否应用噪音 */ QList listDetect; /* 检测计划列表 */ QList listNoDetect; /* 非检测计划列表 */ bool operator==(const DetectPeriodConfig_t &other) const; /* 判断基础信息是否更改 */ bool isBaseInfoChanged(const DetectPeriodConfig_t &other) const; }; /** * @brief 非检测计划应用清空 * */ struct NoDetectPlanApply_t { int nID = 0; /* ID */ bool isApplySlient = false; /* 非检测计划日期是否应用静音 */ bool isApplyOverload = false; /* 非检测计划日期是否应用超载 */ bool isApplyPhase = false; /* 非检测计划日期是否应用反相 */ bool isApplyNoise = false; /* 非检测计划日期是否应用噪音 */ }; /* ========================================================================================= * 线程信息相关枚举和结构体 * =========================================================================================*/ /** * @brief 线程状态枚举 * */ enum class EThreadState { State_None = 0, /* 无状态 */ State_Inited, /* 已初始化 */ State_Running, /* 运行中 */ State_Stopped, /* 已停止 */ State_Error /* 错误状态 */ }; /** * @brief 线程类型枚举 * */ enum class EThreadType { Type_None = 0, /* 无类型 */ Type_RecordSrc, /* 录音源线程 */ Type_AssignSrcData, /* 分派数据线程 */ Type_CreateWAV, /* 生成WAV文件线程 */ Type_CreateDB, /* 生成音量包的线程 */ // Type_CreateNoise, /* 生成噪音数据线程 */ Type_CreateLongWAV, /* 生成长文件线程 */ Type_RtpSend, /* RTP发送线程 */ Type_ConsistencyCheck, /* 一致性检查线程 */ Type_CalculateDB, /* 计算音量的线程 */ Type_CompareItem, /* 对比项线程 */ }; /** * @brief 录音线程信息结构体 */ struct RecordThreadInfo_t { // SoundCardRoadInfo_t cardRoadInfo; /* 录音通道信息 */ OneSoundCardPCMInfo_t cardRoadInfo; /* 录音通道信息,包含声卡名称和PCM名称 */ EThreadType threadType; /* 线程类型 */ std::atomic threadState; /* 线程状态 */ // BaseRecordThread* pThread = nullptr; /* 线程对象 */ RecordThreadInfo_t() = default; RecordThreadInfo_t(const RecordThreadInfo_t& obj) { *this = obj; } RecordThreadInfo_t& operator=(const RecordThreadInfo_t& obj); }; /* ========================================================================================= * 报警信息结构体 * =========================================================================================*/ class BaseCalculateThread; /** * @brief 计算线程信息结构体 * */ struct CalculateThreadInfo_t { CompareItemInfo_t compareItemInfo; /* 对比项信息 */ EThreadType threadType; /* 线程类型 */ std::atomic threadState; /* 线程状态 */ // BaseCalculateThread* pThread = nullptr; /* 计算线程对象 */ CalculateThreadInfo_t() = default; CalculateThreadInfo_t(const CalculateThreadInfo_t& info); CalculateThreadInfo_t& operator=(const CalculateThreadInfo_t& info); }; /** * @brief 报警结构体 * */ struct AlarmInfo_t { bool isAlarm = false; /* 是否报警 */ int CompareItemID = 0; /* 对比项ID */ QString strCompareItemName; /* 对比项名称 */ CompareItemRoadInfo_t RoadInfo; /* 录音通道信息 */ ERoadType RoadType; /* 录音通道类型 */ EAlarmType AlarmType = EAlarmType::EAT_None; /* 报警类型 */ QDateTime StartTime; /* 报警开始时间 */ QDateTime EndTime; /* 报警结束时间 */ QString strAlarmFilePath; /* 报警文件路径 */ int AlarmStartPos = 0; /* 报警开始位置 */ QDateTime AlarmFileStartTime; /* 录音文件开始时间 */ eRecordState fileState = eRecordState::eRS_Init; /* 录音文件状态 */ int PKID = -1; /* 主键ID,数据库使用 */ AlarmInfo_t() = default; AlarmInfo_t(const AlarmInfo_t& obj) { *this = obj; } AlarmInfo_t& operator=(const AlarmInfo_t& obj); /* 比较是否相等,主要是比较是否报警、通道ID,报警类型,报警时间 */ bool operator==(const AlarmInfo_t& other) const; }; /* ========================================================================================= * 录音文件结构体 * =========================================================================================*/ struct RecordFileInfo_t { int ItemID = -1; /* 对比项ID */ QString ItemName; /* 对比项名称 */ int ItemRoadNum = -1; /* 对比项通道编号 */ QString ItemRoadName; /* 对比项通道名称 */ OneSoundCardPCMInfo_t scRoadInfo;/* 声卡PCM通道信息,包含声卡名称和PCM名称 */ QDateTime FileStartTime; /* 文件开始时间 */ QDateTime FileEndTime; /* 文件结束时间 */ int FileDuration = 0; /* 文件时长,单位秒 */ QString FilePath; /* 文件路径 */ eRecordState fileState; /* 录音文件状态 */ RecordFileInfo_t() = default; RecordFileInfo_t(const RecordFileInfo_t& obj) { *this = obj; } RecordFileInfo_t& operator=(const RecordFileInfo_t& obj); }; #endif // __GLOBAL_VARIABLE_H__