|
@@ -10,6 +10,7 @@
|
|
|
#include "CreateRecordFileThread.h"
|
|
|
#include "RecordThread.h"
|
|
|
#include "AssignSrcDataThread.h"
|
|
|
+#include "SoundCards.h"
|
|
|
|
|
|
#include "ThreadPool.h"
|
|
|
#include <mutex>
|
|
@@ -43,12 +44,47 @@ void ThreadManager::thread_destroyeRecordThread()
|
|
|
{
|
|
|
while(true)
|
|
|
{
|
|
|
- std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
- destroyeRecordThread();
|
|
|
+ // SPDLOG_LOGGER_WARN(m_logger, "销毁录音线程函数开始运行");
|
|
|
+ /* 设置超时2秒 */
|
|
|
+ std::unique_lock<std::mutex> m_lock(m_mutexRecordThreadRefCount);
|
|
|
+ m_condVarDestroyRecord.wait_for(m_lock, std::chrono::seconds(2), [this]() {
|
|
|
+ return m_isDestroyeRecordThread.load();
|
|
|
+ });
|
|
|
+ // SPDLOG_LOGGER_WARN(m_logger, "销毁录音线程函数被唤醒, 销毁标志: {}", m_isDestroyeRecordThread.load());
|
|
|
+ if(m_isDestroyeRecordThread.load() == false)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ /* 销毁标志位置为false */
|
|
|
+ m_isDestroyeRecordThread.store(false);
|
|
|
+
|
|
|
+
|
|
|
+ /* 获取所有引用计数为0的录音线程 */
|
|
|
+ QList<std::string> removePCMList; // 需要移除的录音通道列表
|
|
|
+ for(auto it = m_mapRecordThreadRefCount.begin(); it != m_mapRecordThreadRefCount.end(); it++)
|
|
|
+ {
|
|
|
+ if(it->second.empty())
|
|
|
+ {
|
|
|
+ removePCMList.push_back(it->first);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /* 停止线程 */
|
|
|
+ for(const auto& pcmName : removePCMList)
|
|
|
+ {
|
|
|
+ OneSoundCardPCMInfo_t pcmInfo;
|
|
|
+ pcmInfo.pcmInfo.strPCMName = pcmName;
|
|
|
+ stopRecordAllThreads(pcmInfo);
|
|
|
+ }
|
|
|
+ /* 销毁线程 */
|
|
|
+ destroyRecordThread();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-/* 创建一个录音通道及其附属的线程 */
|
|
|
+/* 创建一个录音通道及其附属的线程
|
|
|
+ 注意:这个函数在对比项线程中运行
|
|
|
+*/
|
|
|
bool ThreadManager::createRecordThread(const OneSoundCardPCMInfo_t& pcmInfo, int compareItemID)
|
|
|
{
|
|
|
/* 先查找队列中有没有该录音通道 */
|
|
@@ -174,9 +210,11 @@ bool ThreadManager::createRecordThread(const OneSoundCardPCMInfo_t& pcmInfo, int
|
|
|
/**
|
|
|
销毁一个录音通道及其附属的线程,如果引用计数为0, 这里只停止该录音通道的所有线程,不会删除实例
|
|
|
线程实例会由其他管理线程定期去删除
|
|
|
+ 注意:这个函数其实是在对比项线程中运行的
|
|
|
*/
|
|
|
bool ThreadManager::removeRecordThread(const OneSoundCardPCMInfo_t& pcmInfo, int compareItemID)
|
|
|
{
|
|
|
+ // SPDLOG_LOGGER_WARN(m_logger, "{}:{} 准备减少录音线程计数...", pcmInfo.strSoundCardName, pcmInfo.pcmInfo.strPCMName);
|
|
|
std::unique_lock<std::mutex> lock(m_mutexRecordThreadRefCount);
|
|
|
// SPDLOG_LOGGER_WARN(m_logger, "{}:{} 准备销毁录音线程, map Size: {}", pcmInfo.strSoundCardName, pcmInfo.pcmInfo.strPCMName, m_mapRecordThreadRefCount.size());
|
|
|
/* 先查找这个引用计数是否存在 */
|
|
@@ -209,17 +247,197 @@ bool ThreadManager::removeRecordThread(const OneSoundCardPCMInfo_t& pcmInfo, int
|
|
|
SPDLOG_LOGGER_WARN(m_logger, "{} 录音线程未找到,可能已经释放", logBase);
|
|
|
return true;
|
|
|
}
|
|
|
- SPDLOG_LOGGER_WARN(m_logger, "{} 录音线程引用计数为0,即将停止该录音通道的所有线程", logBase);
|
|
|
+ SPDLOG_LOGGER_WARN(m_logger, "{} 录音线程引用计数为0,需要释放该录音通道的所有线程", logBase);
|
|
|
+
|
|
|
+ /* 设置销毁录音线程标志 */
|
|
|
+ m_isDestroyeRecordThread.store(true);
|
|
|
+ m_condVarDestroyRecord.notify_one();
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/* 查找录音线程 */
|
|
|
+BaseRecordThread* ThreadManager::findRecordThread(EThreadType type, std::string pcmName)
|
|
|
+{
|
|
|
+ switch(type)
|
|
|
+ {
|
|
|
+ case EThreadType::Type_RecordSrc: /* 录音线程 */
|
|
|
+ {
|
|
|
+ std::lock_guard<std::mutex> lock(m_mutexRecordThreads);
|
|
|
+ for (auto& pThread : m_recordThreads)
|
|
|
+ {
|
|
|
+ if (pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName == pcmName )
|
|
|
+ {
|
|
|
+ return pThread;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case EThreadType::Type_CreateWAV: /* 创建wav小文件和分离左右声道的线程 */
|
|
|
+ {
|
|
|
+ std::lock_guard<std::mutex> lock(m_mutexCreateWAVThreads);
|
|
|
+ for (auto& pThread : m_createWAVThreads)
|
|
|
+ {
|
|
|
+ if (pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName == pcmName )
|
|
|
+ {
|
|
|
+ return pThread;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case EThreadType::Type_CreateDB: /* 计算音量和反相的线程 */
|
|
|
+ {
|
|
|
+ std::lock_guard<std::mutex> lock(m_mutexCreateDBThreads);
|
|
|
+ for (auto& pThread : m_createDBThreads)
|
|
|
+ {
|
|
|
+ if (pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName == pcmName )
|
|
|
+ {
|
|
|
+ return pThread;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case EThreadType::Type_CreateLongWAV: /* 创建长文件的线程 */
|
|
|
+ {
|
|
|
+ std::lock_guard<std::mutex> lock(m_mutexCreateLongWAVThreads);
|
|
|
+ for (auto& pThread : m_createLongWAVThreads)
|
|
|
+ {
|
|
|
+ if (pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName == pcmName )
|
|
|
+ {
|
|
|
+ return pThread;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case EThreadType::Type_AssignSrcData: /* 分派数据线程 */
|
|
|
+ {
|
|
|
+ std::lock_guard<std::mutex> lock(m_mutexAssignSrcDataThreads);
|
|
|
+ for (auto& pThread : m_assignSrcDataThreads)
|
|
|
+ {
|
|
|
+ if (pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName == pcmName )
|
|
|
+ {
|
|
|
+ return pThread;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case EThreadType::Type_RtpSend: /* RTP发送线程 */
|
|
|
+ {
|
|
|
+ std::lock_guard<std::mutex> lock(m_mutexRtpSendThreads);
|
|
|
+ for (auto& pThread : m_rtpSendThreads)
|
|
|
+ {
|
|
|
+ if (pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName == pcmName )
|
|
|
+ {
|
|
|
+ return pThread;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ SPDLOG_LOGGER_ERROR(m_logger, "{} 查找录音线程失败,未知线程类型: {}", m_logBase, static_cast<int>(type));
|
|
|
+ return nullptr; // 未知线程类型
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return nullptr;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/* 获取创建WAV线程指针 */
|
|
|
+CreateWAVThread* ThreadManager::getCreateWAVThread(std::string pcmName)
|
|
|
+{
|
|
|
+ std::lock_guard<std::mutex> lock(m_mutexCreateWAVThreads);
|
|
|
+ for(auto& pThread : m_createWAVThreads)
|
|
|
+ {
|
|
|
+ if(pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName == pcmName)
|
|
|
+ {
|
|
|
+ return dynamic_cast<CreateWAVThread*>(pThread);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nullptr;
|
|
|
+}
|
|
|
+
|
|
|
+/* 获取创建音量值的线程 */
|
|
|
+CreateDBThread* ThreadManager::getCreateDBThread(std::string pcmName)
|
|
|
+{
|
|
|
+ std::lock_guard<std::mutex> lock(m_mutexCreateDBThreads);
|
|
|
+ for(auto& pThread : m_createDBThreads)
|
|
|
+ {
|
|
|
+ if(pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName == pcmName)
|
|
|
+ {
|
|
|
+ return dynamic_cast<CreateDBThread*>(pThread);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nullptr;
|
|
|
+}
|
|
|
+
|
|
|
+/* 获取发送Rtp数据的线程 */
|
|
|
+RTPOneRoadThread* ThreadManager::getRtpSendThread(std::string pcmName)
|
|
|
+{
|
|
|
+ std::lock_guard<std::mutex> lock(m_mutexRtpSendThreads);
|
|
|
+ for(auto& pThread : m_rtpSendThreads)
|
|
|
+ {
|
|
|
+ const auto& threadInfo = pThread->getThreadInfo();
|
|
|
+ if(threadInfo.cardRoadInfo.pcmInfo.strPCMName == pcmName)
|
|
|
+ {
|
|
|
+ return dynamic_cast<RTPOneRoadThread*>(pThread);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nullptr;
|
|
|
+}
|
|
|
+
|
|
|
+/* 获取录制报警文件的线程 */
|
|
|
+CreateRecordFileThread* ThreadManager::getCreateRecordFileThread(std::string pcmName)
|
|
|
+{
|
|
|
+ std::lock_guard<std::mutex> lock(m_mutexCreateLongWAVThreads);
|
|
|
+ for(auto& pThread : m_createLongWAVThreads)
|
|
|
+ {
|
|
|
+ if(pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName == pcmName)
|
|
|
+ {
|
|
|
+ return dynamic_cast<CreateRecordFileThread*>(pThread);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nullptr;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/* RTP线程函数,套一层壳 */
|
|
|
+void ThreadManager::thread_RTPSend(RecordThreadInfo_t& threadInfo)
|
|
|
+{
|
|
|
+ RTPOneRoadThread* pRtpSendThread = new RTPOneRoadThread(threadInfo);
|
|
|
+ if(pRtpSendThread == nullptr)
|
|
|
+ {
|
|
|
+ SPDLOG_ERROR("{}:{} 创建RTP发送线程失败", threadInfo.cardRoadInfo.strSoundCardName, threadInfo.cardRoadInfo.pcmInfo.strPCMName);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ /* 先加入队列,再开启线程 */
|
|
|
+ ThreadMan.m_mutexRtpSendThreads.lock();
|
|
|
+ ThreadMan.m_rtpSendThreads.push_back(pRtpSendThread);
|
|
|
+ ThreadMan.m_mutexRtpSendThreads.unlock();
|
|
|
+
|
|
|
+ pRtpSendThread->thread_task();
|
|
|
+}
|
|
|
+
|
|
|
+/* 停止某个录音通道的所有的线程 */
|
|
|
+void ThreadManager::stopRecordAllThreads(const OneSoundCardPCMInfo_t& pcmInfo)
|
|
|
+{
|
|
|
|
|
|
+ std::string logBase = fmt::format("{}:{}", pcmInfo.strSoundCardName, pcmInfo.pcmInfo.strPCMName);
|
|
|
/* 引用计数为0,停止该录音通道的所有线程 */
|
|
|
/* 停止录音线程 */
|
|
|
{
|
|
|
std::lock_guard<std::mutex> lock(m_mutexRecordThreads);
|
|
|
+ SPDLOG_LOGGER_WARN(m_logger, "{} 录音线程列表Size: {}", logBase, m_recordThreads.size());
|
|
|
for(auto it : m_recordThreads)
|
|
|
{
|
|
|
const auto& threadInfo = it->getThreadInfo();
|
|
|
if(threadInfo.cardRoadInfo.pcmInfo.strPCMName == pcmInfo.pcmInfo.strPCMName)
|
|
|
{
|
|
|
+ SPDLOG_LOGGER_TRACE(m_logger, "{} 准备停止录音线程: {}", logBase, threadInfo.cardRoadInfo.pcmInfo.strPCMName);
|
|
|
it->thread_stop_block();
|
|
|
SPDLOG_LOGGER_TRACE(m_logger, "{} 录音线程已停止", logBase);
|
|
|
break;
|
|
@@ -305,55 +523,46 @@ bool ThreadManager::removeRecordThread(const OneSoundCardPCMInfo_t& pcmInfo, int
|
|
|
if(it != m_mapRecordThreadRefCount.end())
|
|
|
{
|
|
|
m_mapRecordThreadRefCount.erase(it);
|
|
|
- SPDLOG_LOGGER_INFO(m_logger, "{} 录音线程已停止运行", logBase);
|
|
|
+ SPDLOG_LOGGER_WARN(m_logger, " ➢ 录音通道: {} 线程已全部停止运行", logBase);
|
|
|
} else
|
|
|
{
|
|
|
SPDLOG_LOGGER_WARN(m_logger, "{} 录音线程引用计数未找到", logBase);
|
|
|
}
|
|
|
|
|
|
- // 设置销毁录音线程标志
|
|
|
- m_isDestroyeRecordThread.store(true);
|
|
|
- m_condVarDestroyRecord.notify_one();
|
|
|
-
|
|
|
- return true;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/* 销毁录音线程 */
|
|
|
-void ThreadManager::destroyeRecordThread()
|
|
|
+void ThreadManager::destroyRecordThread()
|
|
|
{
|
|
|
- std::unique_lock<std::mutex> m_lock(m_mutexRecordThreadRefCount);
|
|
|
- m_condVarDestroyRecord.wait(m_lock, [this]() {
|
|
|
- return m_isDestroyeRecordThread.load();
|
|
|
- });
|
|
|
- if(!m_isDestroyeRecordThread.load())
|
|
|
- {
|
|
|
- /* 没有需要销毁的线程 */
|
|
|
- return;
|
|
|
- }
|
|
|
- SPDLOG_LOGGER_INFO(m_logger, "{} 准备销毁录音线程...", m_logBase);
|
|
|
+
|
|
|
+ SPDLOG_LOGGER_DEBUG(m_logger, "{} 准备销毁录音线程...", m_logBase);
|
|
|
/* 销毁录音线程 */
|
|
|
{
|
|
|
std::lock_guard<std::mutex> lock(m_mutexRecordThreads);
|
|
|
for(auto it = m_recordThreads.begin(); it != m_recordThreads.end(); )
|
|
|
{
|
|
|
BaseRecordThread* pThread = *it;
|
|
|
- if(pThread != nullptr)
|
|
|
+ if(pThread == nullptr)
|
|
|
{
|
|
|
- auto threadState = pThread->getThreadInfo().threadState.load();
|
|
|
- if(EThreadState::State_Stopped == threadState ||
|
|
|
- EThreadState::State_Error == threadState )
|
|
|
- {
|
|
|
- SPDLOG_LOGGER_DEBUG(m_logger, "{} 销毁录音线程: {}:{}", m_logBase, pThread->getThreadInfo().cardRoadInfo.strSoundCardName,
|
|
|
- pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName);
|
|
|
- auto pRecordThread = dynamic_cast<RecordThread*>(pThread);
|
|
|
- delete pRecordThread; // 删除线程
|
|
|
- pThread = nullptr;
|
|
|
- it = m_recordThreads.erase(it); // 从列表中移除
|
|
|
- }
|
|
|
- } else
|
|
|
+ /* 删除空指针元素 */
|
|
|
+ it = m_recordThreads.erase(it);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ auto threadState = pThread->getThreadInfo().threadState.load();
|
|
|
+ if(EThreadState::State_Stopped == threadState ||
|
|
|
+ EThreadState::State_Error == threadState )
|
|
|
{
|
|
|
- it++;
|
|
|
+ SPDLOG_LOGGER_DEBUG(m_logger, "{} 销毁录音线程: {}:{}", m_logBase, pThread->getThreadInfo().cardRoadInfo.strSoundCardName,
|
|
|
+ pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName);
|
|
|
+ auto pRecordThread = dynamic_cast<RecordThread*>(pThread);
|
|
|
+ delete pRecordThread; // 删除线程
|
|
|
+ pThread = nullptr;
|
|
|
+ it = m_recordThreads.erase(it);
|
|
|
+ continue;
|
|
|
}
|
|
|
+ ++it;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -363,23 +572,24 @@ void ThreadManager::destroyeRecordThread()
|
|
|
for(auto it = m_assignSrcDataThreads.begin(); it != m_assignSrcDataThreads.end(); )
|
|
|
{
|
|
|
BaseRecordThread* pThread = *it;
|
|
|
- if(pThread != nullptr)
|
|
|
+ if(pThread == nullptr)
|
|
|
{
|
|
|
- auto threadState = pThread->getThreadInfo().threadState.load();
|
|
|
- if(EThreadState::State_Stopped == threadState ||
|
|
|
- EThreadState::State_Error == threadState )
|
|
|
- {
|
|
|
- SPDLOG_LOGGER_DEBUG(m_logger, "{} 销毁分派数据线程: {}:{}", m_logBase, pThread->getThreadInfo().cardRoadInfo.strSoundCardName,
|
|
|
- pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName);
|
|
|
- auto pAssignSrcDataThread = dynamic_cast<AssignSrcDataThread*>(pThread);
|
|
|
- delete pAssignSrcDataThread; // 删除线程
|
|
|
- pThread = nullptr;
|
|
|
- it = m_assignSrcDataThreads.erase(it); // 从列表中移除
|
|
|
- }
|
|
|
- } else
|
|
|
+ it = m_assignSrcDataThreads.erase(it);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ auto threadState = pThread->getThreadInfo().threadState.load();
|
|
|
+ if(EThreadState::State_Stopped == threadState ||
|
|
|
+ EThreadState::State_Error == threadState )
|
|
|
{
|
|
|
- it++;
|
|
|
+ SPDLOG_LOGGER_DEBUG(m_logger, "{} 销毁分派数据线程: {}:{}", m_logBase, pThread->getThreadInfo().cardRoadInfo.strSoundCardName,
|
|
|
+ pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName);
|
|
|
+ auto pAssignSrcDataThread = dynamic_cast<AssignSrcDataThread*>(pThread);
|
|
|
+ delete pAssignSrcDataThread; // 删除线程
|
|
|
+ pThread = nullptr;
|
|
|
+ it = m_assignSrcDataThreads.erase(it); // 从列表中移除
|
|
|
+ continue;
|
|
|
}
|
|
|
+ ++it;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -389,23 +599,24 @@ void ThreadManager::destroyeRecordThread()
|
|
|
for(auto it = m_createWAVThreads.begin(); it != m_createWAVThreads.end(); )
|
|
|
{
|
|
|
BaseRecordThread* pThread = *it;
|
|
|
- if(pThread != nullptr)
|
|
|
+ if(pThread == nullptr)
|
|
|
{
|
|
|
- auto threadState = pThread->getThreadInfo().threadState.load();
|
|
|
- if(EThreadState::State_Stopped == threadState ||
|
|
|
- EThreadState::State_Error == threadState )
|
|
|
- {
|
|
|
- SPDLOG_LOGGER_DEBUG(m_logger, "{} 销毁 CreateWAV 线程: {}:{}", m_logBase, pThread->getThreadInfo().cardRoadInfo.strSoundCardName,
|
|
|
- pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName);
|
|
|
- auto pCreateWAVThread = dynamic_cast<CreateWAVThread*>(pThread);
|
|
|
- delete pCreateWAVThread; // 删除线程
|
|
|
- pThread = nullptr;
|
|
|
- it = m_createWAVThreads.erase(it); // 从列表中移除
|
|
|
- }
|
|
|
- } else
|
|
|
+ it = m_createWAVThreads.erase(it);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ auto threadState = pThread->getThreadInfo().threadState.load();
|
|
|
+ if(EThreadState::State_Stopped == threadState ||
|
|
|
+ EThreadState::State_Error == threadState )
|
|
|
{
|
|
|
- it++;
|
|
|
+ SPDLOG_LOGGER_DEBUG(m_logger, "{} 销毁 CreateWAV 线程: {}:{}", m_logBase, pThread->getThreadInfo().cardRoadInfo.strSoundCardName,
|
|
|
+ pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName);
|
|
|
+ auto pCreateWAVThread = dynamic_cast<CreateWAVThread*>(pThread);
|
|
|
+ delete pCreateWAVThread; // 删除线程
|
|
|
+ pThread = nullptr;
|
|
|
+ it = m_createWAVThreads.erase(it); // 从列表中移除
|
|
|
+ continue;
|
|
|
}
|
|
|
+ ++it;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -415,23 +626,24 @@ void ThreadManager::destroyeRecordThread()
|
|
|
for(auto it = m_createDBThreads.begin(); it != m_createDBThreads.end(); )
|
|
|
{
|
|
|
BaseRecordThread* pThread = *it;
|
|
|
- if(pThread != nullptr)
|
|
|
+ if(pThread == nullptr)
|
|
|
{
|
|
|
- auto threadState = pThread->getThreadInfo().threadState.load();
|
|
|
- if(EThreadState::State_Stopped == threadState ||
|
|
|
- EThreadState::State_Error == threadState )
|
|
|
- {
|
|
|
- SPDLOG_LOGGER_DEBUG(m_logger, "{} 销毁 CreateDB 线程: {}:{}", m_logBase, pThread->getThreadInfo().cardRoadInfo.strSoundCardName,
|
|
|
- pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName);
|
|
|
- auto pCreateDBThread = dynamic_cast<CreateDBThread*>(pThread);
|
|
|
- delete pCreateDBThread; // 删除线程
|
|
|
- pThread = nullptr;
|
|
|
- it = m_createDBThreads.erase(it); // 从列表中移除
|
|
|
- }
|
|
|
- } else
|
|
|
+ it = m_createDBThreads.erase(it);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ auto threadState = pThread->getThreadInfo().threadState.load();
|
|
|
+ if(EThreadState::State_Stopped == threadState ||
|
|
|
+ EThreadState::State_Error == threadState )
|
|
|
{
|
|
|
- it++;
|
|
|
+ SPDLOG_LOGGER_DEBUG(m_logger, "{} 销毁 CreateDB 线程: {}:{}", m_logBase, pThread->getThreadInfo().cardRoadInfo.strSoundCardName,
|
|
|
+ pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName);
|
|
|
+ auto pCreateDBThread = dynamic_cast<CreateDBThread*>(pThread);
|
|
|
+ delete pCreateDBThread; // 删除线程
|
|
|
+ pThread = nullptr;
|
|
|
+ it = m_createDBThreads.erase(it); // 从列表中移除
|
|
|
+ continue;
|
|
|
}
|
|
|
+ ++it;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -441,23 +653,24 @@ void ThreadManager::destroyeRecordThread()
|
|
|
for(auto it = m_createLongWAVThreads.begin(); it != m_createLongWAVThreads.end(); )
|
|
|
{
|
|
|
BaseRecordThread* pThread = *it;
|
|
|
- if(pThread != nullptr)
|
|
|
+ if(pThread == nullptr)
|
|
|
{
|
|
|
- auto threadState = pThread->getThreadInfo().threadState.load();
|
|
|
- if(EThreadState::State_Stopped == threadState ||
|
|
|
- EThreadState::State_Error == threadState )
|
|
|
- {
|
|
|
- SPDLOG_LOGGER_DEBUG(m_logger, "{} 销毁 RecordFile 线程: {}:{}", m_logBase, pThread->getThreadInfo().cardRoadInfo.strSoundCardName,
|
|
|
- pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName);
|
|
|
- auto pCreateLongWAVThread = dynamic_cast<CreateRecordFileThread*>(pThread);
|
|
|
- delete pCreateLongWAVThread; // 删除线程
|
|
|
- pThread = nullptr;
|
|
|
- it = m_createLongWAVThreads.erase(it); // 从列表中移除
|
|
|
- }
|
|
|
- } else
|
|
|
+ it = m_createLongWAVThreads.erase(it);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ auto threadState = pThread->getThreadInfo().threadState.load();
|
|
|
+ if(EThreadState::State_Stopped == threadState ||
|
|
|
+ EThreadState::State_Error == threadState )
|
|
|
{
|
|
|
- it++;
|
|
|
+ SPDLOG_LOGGER_DEBUG(m_logger, "{} 销毁 CreateRecordFileThread 线程: {}:{}", m_logBase, pThread->getThreadInfo().cardRoadInfo.strSoundCardName,
|
|
|
+ pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName);
|
|
|
+ auto pCreateLongWAVThread = dynamic_cast<CreateRecordFileThread*>(pThread);
|
|
|
+ delete pCreateLongWAVThread; // 删除线程
|
|
|
+ pThread = nullptr;
|
|
|
+ it = m_createLongWAVThreads.erase(it); // 从列表中移除
|
|
|
+ continue;
|
|
|
}
|
|
|
+ ++it;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -467,471 +680,27 @@ void ThreadManager::destroyeRecordThread()
|
|
|
for(auto it = m_rtpSendThreads.begin(); it != m_rtpSendThreads.end(); )
|
|
|
{
|
|
|
BaseRecordThread* pThread = *it;
|
|
|
- if(pThread != nullptr)
|
|
|
- {
|
|
|
- auto threadState = pThread->getThreadInfo().threadState.load();
|
|
|
- if(EThreadState::State_Stopped == threadState ||
|
|
|
- EThreadState::State_Error == threadState )
|
|
|
- {
|
|
|
- SPDLOG_LOGGER_DEBUG(m_logger, "{} 销毁 RTP Send 线程: {}:{}", m_logBase, pThread->getThreadInfo().cardRoadInfo.strSoundCardName,
|
|
|
- pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName);
|
|
|
- auto pRtpSendThread = dynamic_cast<RTPOneRoadThread*>(pThread);
|
|
|
- delete pRtpSendThread; // 删除线程
|
|
|
- pThread = nullptr;
|
|
|
- it = m_rtpSendThreads.erase(it); // 从列表中移除
|
|
|
- }
|
|
|
- } else
|
|
|
- {
|
|
|
- it++;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /* 销毁标志位置为false */
|
|
|
- m_isDestroyeRecordThread.store(false);
|
|
|
- SPDLOG_LOGGER_INFO(m_logger, "{} 录音线程销毁完成", m_logBase);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-/* 查找录音线程 */
|
|
|
-BaseRecordThread* ThreadManager::findRecordThread(EThreadType type, std::string pcmName)
|
|
|
-{
|
|
|
- switch(type)
|
|
|
- {
|
|
|
- case EThreadType::Type_RecordSrc: /* 录音线程 */
|
|
|
- {
|
|
|
- std::lock_guard<std::mutex> lock(m_mutexRecordThreads);
|
|
|
- for (auto& pThread : m_recordThreads)
|
|
|
- {
|
|
|
- if (pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName == pcmName )
|
|
|
- {
|
|
|
- return pThread;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- case EThreadType::Type_CreateWAV: /* 创建wav小文件和分离左右声道的线程 */
|
|
|
- {
|
|
|
- std::lock_guard<std::mutex> lock(m_mutexCreateWAVThreads);
|
|
|
- for (auto& pThread : m_createWAVThreads)
|
|
|
- {
|
|
|
- if (pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName == pcmName )
|
|
|
- {
|
|
|
- return pThread;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- case EThreadType::Type_CreateDB: /* 计算音量和反相的线程 */
|
|
|
- {
|
|
|
- std::lock_guard<std::mutex> lock(m_mutexCreateDBThreads);
|
|
|
- for (auto& pThread : m_createDBThreads)
|
|
|
- {
|
|
|
- if (pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName == pcmName )
|
|
|
- {
|
|
|
- return pThread;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- case EThreadType::Type_CreateLongWAV: /* 创建长文件的线程 */
|
|
|
+ if(pThread == nullptr)
|
|
|
{
|
|
|
- std::lock_guard<std::mutex> lock(m_mutexCreateLongWAVThreads);
|
|
|
- for (auto& pThread : m_createLongWAVThreads)
|
|
|
- {
|
|
|
- if (pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName == pcmName )
|
|
|
- {
|
|
|
- return pThread;
|
|
|
- }
|
|
|
- }
|
|
|
+ it = m_rtpSendThreads.erase(it);
|
|
|
+ continue;
|
|
|
}
|
|
|
- break;
|
|
|
- case EThreadType::Type_AssignSrcData: /* 分派数据线程 */
|
|
|
+ auto threadState = pThread->getThreadInfo().threadState.load();
|
|
|
+ if(EThreadState::State_Stopped == threadState ||
|
|
|
+ EThreadState::State_Error == threadState )
|
|
|
{
|
|
|
- std::lock_guard<std::mutex> lock(m_mutexAssignSrcDataThreads);
|
|
|
- for (auto& pThread : m_assignSrcDataThreads)
|
|
|
- {
|
|
|
- if (pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName == pcmName )
|
|
|
- {
|
|
|
- return pThread;
|
|
|
- }
|
|
|
- }
|
|
|
+ SPDLOG_LOGGER_DEBUG(m_logger, "{} 销毁 RTP Send 线程: {}:{}", m_logBase, pThread->getThreadInfo().cardRoadInfo.strSoundCardName,
|
|
|
+ pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName);
|
|
|
+ auto pRtpSendThread = dynamic_cast<RTPOneRoadThread*>(pThread);
|
|
|
+ delete pRtpSendThread; // 删除线程
|
|
|
+ pThread = nullptr;
|
|
|
+ it = m_rtpSendThreads.erase(it); // 从列表中移除
|
|
|
}
|
|
|
- break;
|
|
|
- case EThreadType::Type_RtpSend: /* RTP发送线程 */
|
|
|
- {
|
|
|
- std::lock_guard<std::mutex> lock(m_mutexRtpSendThreads);
|
|
|
- for (auto& pThread : m_rtpSendThreads)
|
|
|
- {
|
|
|
- if (pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName == pcmName )
|
|
|
- {
|
|
|
- return pThread;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- default:
|
|
|
- SPDLOG_LOGGER_ERROR(m_logger, "{} 查找录音线程失败,未知线程类型: {}", m_logBase, static_cast<int>(type));
|
|
|
- return nullptr; // 未知线程类型
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- return nullptr;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-/* 获取创建WAV线程指针 */
|
|
|
-CreateWAVThread* ThreadManager::getCreateWAVThread(std::string pcmName)
|
|
|
-{
|
|
|
- std::lock_guard<std::mutex> lock(m_mutexCreateWAVThreads);
|
|
|
- for(auto& pThread : m_createWAVThreads)
|
|
|
- {
|
|
|
- if(pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName == pcmName)
|
|
|
- {
|
|
|
- return dynamic_cast<CreateWAVThread*>(pThread);
|
|
|
+ ++it;
|
|
|
}
|
|
|
}
|
|
|
- return nullptr;
|
|
|
-}
|
|
|
|
|
|
-/* 获取创建音量值的线程 */
|
|
|
-CreateDBThread* ThreadManager::getCreateDBThread(std::string pcmName)
|
|
|
-{
|
|
|
- std::lock_guard<std::mutex> lock(m_mutexCreateDBThreads);
|
|
|
- for(auto& pThread : m_createDBThreads)
|
|
|
- {
|
|
|
- if(pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName == pcmName)
|
|
|
- {
|
|
|
- return dynamic_cast<CreateDBThread*>(pThread);
|
|
|
- }
|
|
|
- }
|
|
|
- return nullptr;
|
|
|
+ SPDLOG_LOGGER_DEBUG(m_logger, "{} 录音线程销毁完成", m_logBase);
|
|
|
}
|
|
|
|
|
|
-/* 获取发送Rtp数据的线程 */
|
|
|
-RTPOneRoadThread* ThreadManager::getRtpSendThread(std::string pcmName)
|
|
|
-{
|
|
|
- std::lock_guard<std::mutex> lock(m_mutexRtpSendThreads);
|
|
|
- for(auto& pThread : m_rtpSendThreads)
|
|
|
- {
|
|
|
- const auto& threadInfo = pThread->getThreadInfo();
|
|
|
- if(threadInfo.cardRoadInfo.pcmInfo.strPCMName == pcmName)
|
|
|
- {
|
|
|
- return dynamic_cast<RTPOneRoadThread*>(pThread);
|
|
|
- }
|
|
|
- }
|
|
|
- return nullptr;
|
|
|
-}
|
|
|
-
|
|
|
-/* 获取录制报警文件的线程 */
|
|
|
-CreateRecordFileThread* ThreadManager::getCreateRecordFileThread(std::string pcmName)
|
|
|
-{
|
|
|
- std::lock_guard<std::mutex> lock(m_mutexCreateLongWAVThreads);
|
|
|
- for(auto& pThread : m_createLongWAVThreads)
|
|
|
- {
|
|
|
- if(pThread->getThreadInfo().cardRoadInfo.pcmInfo.strPCMName == pcmName)
|
|
|
- {
|
|
|
- return dynamic_cast<CreateRecordFileThread*>(pThread);
|
|
|
- }
|
|
|
- }
|
|
|
- return nullptr;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-/* -------------------------------------------------------------------------------------------
|
|
|
- * 获取计算线程,如果该线程不存在则创建该线程
|
|
|
- * 当不需要此线程后,调用remove()函数去掉该线程
|
|
|
- * -------------------------------------------------------------------------------------------- */
|
|
|
-
|
|
|
-/* 获取一致性比对线程,线程不存在则创建 */
|
|
|
-// ConsistencyCompareThread* ThreadManager::getConsistencyCompareThread(const SoundCardRoadInfo_t& roadInfo1, const SoundCardRoadInfo_t& roadInfo2)
|
|
|
-// {
|
|
|
-// std::lock_guard<std::mutex> lock(m_mutexConsistencyCompareThreads);
|
|
|
-// for(const auto pThread : m_listConsistencyCompareThreads)
|
|
|
-// {
|
|
|
-// if(pThread->isRoadEqual(roadInfo1, roadInfo2))
|
|
|
-// {
|
|
|
-// return pThread; // 找到相同的线程,直接返回
|
|
|
-// }
|
|
|
-// }
|
|
|
-// /* 没找到该线程,创建新的线程 */
|
|
|
-// CompareItemRoadInfo_t item1;
|
|
|
-// item1.nCompareRoadNum = 1;
|
|
|
-// item1.scRoadInfo = roadInfo1;
|
|
|
-// CompareItemRoadInfo_t item2;
|
|
|
-// item2.nCompareRoadNum = 2;
|
|
|
-// item2.scRoadInfo = roadInfo2;
|
|
|
-
|
|
|
-// CalculateThreadInfo_t threadInfo;
|
|
|
-// threadInfo.compareItemInfo.mapRoad.insert(item1.nCompareRoadNum, item1);
|
|
|
-// threadInfo.compareItemInfo.mapRoad.insert(item2.nCompareRoadNum, item2);
|
|
|
-// ConsistencyCompareThread* newThread = new ConsistencyCompareThread(threadInfo);
|
|
|
-
|
|
|
-// if(newThread == nullptr)
|
|
|
-// {
|
|
|
-// SPDLOG_LOGGER_ERROR(m_logger, "创建一致性比对线程失败");
|
|
|
-// return nullptr; // 创建失败
|
|
|
-// }
|
|
|
-// CPPTP.add_task(&ConsistencyCompareThread::threadTask, newThread);
|
|
|
-
|
|
|
-// m_listConsistencyCompareThreads.push_back(newThread);
|
|
|
-// m_referCountConsistencyCompare++; // 引用计数加一
|
|
|
-
|
|
|
-// return newThread;
|
|
|
-// }
|
|
|
-
|
|
|
-/* 去掉线程,线程使用的计数减一,计数为0则销毁该线程 */
|
|
|
-// bool ThreadManager::removeConsistencyCompareThread(SoundCardRoadInfo_t& roadInfo1, SoundCardRoadInfo_t& roadInfo2)
|
|
|
-// {
|
|
|
-// std::lock_guard<std::mutex> lock(m_mutexConsistencyCompareThreads);
|
|
|
-// ConsistencyCompareThread* pThreadToRemove = nullptr;
|
|
|
-// for(const auto pThread : m_listConsistencyCompareThreads)
|
|
|
-// {
|
|
|
-// if(pThread->isRoadEqual(roadInfo1, roadInfo2))
|
|
|
-// {
|
|
|
-// pThreadToRemove = pThread; // 找到相同的线程,直接返回
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if(pThreadToRemove == nullptr)
|
|
|
-// {
|
|
|
-// SPDLOG_LOGGER_WARN(m_logger, "{}:{} - {}:{} 一致性比对线程未找到", roadInfo1.strSoundCardName.toStdString(), roadInfo1.roadInfo.nRoadNum,
|
|
|
-// roadInfo2.strSoundCardName.toStdString(), roadInfo2.roadInfo.nRoadNum);
|
|
|
-// return false; // 没找到该线程
|
|
|
-// }
|
|
|
-// m_referCountConsistencyCompare--; // 引用计数减一
|
|
|
-// if(m_referCountConsistencyCompare <= 0)
|
|
|
-// {
|
|
|
-// /* 停止线程,并一直等待其停止 */
|
|
|
-// pThreadToRemove->thread_stop_block();
|
|
|
-// m_listConsistencyCompareThreads.remove(pThreadToRemove); // 从列表中移除
|
|
|
-// delete pThreadToRemove; // 删除线程
|
|
|
-// pThreadToRemove = nullptr;
|
|
|
-// m_referCountConsistencyCompare = 0; // 重置引用计数
|
|
|
-// SPDLOG_LOGGER_WARN(m_logger, "{}:{} - {}:{} 一致性比对线程已销毁", roadInfo1.strSoundCardName.toStdString(), roadInfo1.roadInfo.nRoadNum,
|
|
|
-// roadInfo2.strSoundCardName.toStdString(), roadInfo2.roadInfo.nRoadNum);
|
|
|
-// }
|
|
|
-
|
|
|
-// return true;
|
|
|
-// }
|
|
|
-
|
|
|
-/* 获取噪音检测线程 */
|
|
|
-// NoiseDetectThread* ThreadManager::getNoiseDetectThread(const OneSoundCardPCMInfo_t& roadInfo, int compareItemID)
|
|
|
-// {
|
|
|
-// std::lock_guard<std::mutex> lock(m_mutexNoiseDetectThreads);
|
|
|
-// NoiseDetectThread* pNoiseDetectThread = nullptr;
|
|
|
-// for(const auto pThread : m_listNoiseDetectThreads)
|
|
|
-// {
|
|
|
-// const OneSoundCardPCMInfo_t & threadRoadInfo = pThread->getRoadInfo();
|
|
|
-// if(threadRoadInfo.pcmInfo.strPCMName == roadInfo.pcmInfo.strPCMName)
|
|
|
-// {
|
|
|
-// pNoiseDetectThread = pThread;
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// /* 判断引用计数是否需要增加 */
|
|
|
-// if(pNoiseDetectThread != nullptr)
|
|
|
-// {
|
|
|
-// /* 查找这个通道是否在列表中(实际上肯定在列表中) */
|
|
|
-// bool isExist = false;
|
|
|
-// for(auto it = m_mapNoiseDetectThreadRefCount.begin(); it != m_mapNoiseDetectThreadRefCount.end(); ++it)
|
|
|
-// {
|
|
|
-// if(it->first.roadInfo. == roadInfo.pcmInfo.strPCMName &&
|
|
|
-// it->first.roadInfo.nRoadNum == roadInfo.roadInfo.nRoadNum)
|
|
|
-// {
|
|
|
-// bool isFound = false;
|
|
|
-// for(auto& id : it->second)
|
|
|
-// {
|
|
|
-// if(id == compareItemID)
|
|
|
-// {
|
|
|
-// isFound = true;
|
|
|
-// break; // 找到相同的对比项ID,直接返回
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if(!isFound)
|
|
|
-// {
|
|
|
-// it->second.push_back(compareItemID); // 添加新的对比项ID
|
|
|
-// SPDLOG_LOGGER_TRACE(m_logger, "{}:{} 噪音检测线程引用计数增加,当前计数: {}",
|
|
|
-// roadInfo.strSoundCardName.toStdString(), roadInfo.roadInfo.nRoadNum, it->second.size());
|
|
|
-// }
|
|
|
-// isExist = true;
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if(!isExist)
|
|
|
-// {
|
|
|
-// /* 不在引用计数的列表中,添加进入 */
|
|
|
-// m_mapNoiseDetectThreadRefCount[roadInfo].push_back(compareItemID);
|
|
|
-// }
|
|
|
-// return pNoiseDetectThread;
|
|
|
-// }
|
|
|
-
|
|
|
-// /* 没找到该线程,创建新的线程 */
|
|
|
-// CalculateThreadInfo_t threadInfo;
|
|
|
-// CompareItemRoadInfo_t item;
|
|
|
-// item.nCompareRoadNum = 1; // 假设噪音检测线程
|
|
|
-// item.scRoadInfo = roadInfo;
|
|
|
-// threadInfo.compareItemInfo.mapRoad.insert(item.nCompareRoadNum, item);
|
|
|
-// NoiseDetectThread* newThread = new NoiseDetectThread(threadInfo);
|
|
|
-// if(newThread == nullptr)
|
|
|
-// {
|
|
|
-// SPDLOG_LOGGER_ERROR(m_logger, "创建噪音检测线程失败");
|
|
|
-// return nullptr; // 创建失败
|
|
|
-// }
|
|
|
-// CPPTP.add_task(&NoiseDetectThread::threadTask, newThread);
|
|
|
-// m_listNoiseDetectThreads.push_back(newThread);
|
|
|
-
|
|
|
-// /* 不在引用计数的列表中,添加进入 */
|
|
|
-// m_mapNoiseDetectThreadRefCount[roadInfo].push_back(compareItemID);
|
|
|
-
|
|
|
-// return newThread;
|
|
|
-// }
|
|
|
-
|
|
|
-/* 去掉噪音检测线程,线程使用的计数减一,计数为0则销毁该线程 */
|
|
|
-// bool ThreadManager::removeNoiseDetectThread(const SoundCardRoadInfo_t& roadInfo, int compareItemID)
|
|
|
-// {
|
|
|
-// std::lock_guard<std::mutex> lock(m_mutexNoiseDetectThreads);
|
|
|
-// NoiseDetectThread* pThreadToRemove = nullptr;
|
|
|
-// for(const auto pThread : m_listNoiseDetectThreads)
|
|
|
-// {
|
|
|
-// const SoundCardRoadInfo_t& threadRoadInfo = pThread->getRoadInfo();
|
|
|
-// if(threadRoadInfo.nSoundCardNum == roadInfo.nSoundCardNum &&
|
|
|
-// threadRoadInfo.roadInfo.nRoadNum == roadInfo.roadInfo.nRoadNum)
|
|
|
-// {
|
|
|
-// pThreadToRemove = pThread; // 找到相同的线程,直接返回
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if(pThreadToRemove == nullptr)
|
|
|
-// {
|
|
|
-// SPDLOG_LOGGER_WARN(m_logger, "{}:{} 噪音检测线程未找到", roadInfo.strSoundCardName.toStdString(), roadInfo.roadInfo.nRoadNum);
|
|
|
-// return false; // 没找到该线程
|
|
|
-// }
|
|
|
-
|
|
|
-// /* 引用计数减一 */
|
|
|
-// int useCount = 0;
|
|
|
-// for(auto it = m_mapNoiseDetectThreadRefCount.begin(); it != m_mapNoiseDetectThreadRefCount.end(); ++it)
|
|
|
-// {
|
|
|
-// if(it->first.nSoundCardNum == roadInfo.nSoundCardNum &&
|
|
|
-// it->first.roadInfo.nRoadNum == roadInfo.roadInfo.nRoadNum)
|
|
|
-// {
|
|
|
-// /* 将对比项ID从列表中删除 */
|
|
|
-// auto& compareItemList = it->second;
|
|
|
-// auto itemIt = std::find(compareItemList.begin(), compareItemList.end(), compareItemID);
|
|
|
-// if(itemIt != compareItemList.end())
|
|
|
-// {
|
|
|
-// compareItemList.erase(itemIt); // 移除该对比项ID
|
|
|
-// SPDLOG_LOGGER_TRACE(m_logger, "{}:{} 噪音检测线程引用计数减少,当前计数: {}",
|
|
|
-// roadInfo.strSoundCardName.toStdString(), roadInfo.roadInfo.nRoadNum, compareItemList.size());
|
|
|
-// }
|
|
|
-// useCount = compareItemList.size(); // 获取当前引用计数
|
|
|
-// if(useCount <= 0)
|
|
|
-// {
|
|
|
-// m_mapNoiseDetectThreadRefCount.erase(it); // 如果引用计数为0,则从列表中移除
|
|
|
-// }
|
|
|
-// break; // 找到后退出循环
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-// if(useCount <= 0)
|
|
|
-// {
|
|
|
-// SPDLOG_LOGGER_INFO(m_logger, "{}:{} 噪音检测线程引用计数为0,准备销毁该线程",
|
|
|
-// roadInfo.strSoundCardName.toStdString(), roadInfo.roadInfo.nRoadNum);
|
|
|
-// pThreadToRemove->thread_stop_block(); // 停止线程
|
|
|
-// m_listNoiseDetectThreads.remove(pThreadToRemove); // 从列表中移除
|
|
|
-// delete pThreadToRemove; // 删除线程
|
|
|
-// pThreadToRemove = nullptr;
|
|
|
-// SPDLOG_LOGGER_INFO(m_logger, "{}:{} 噪音检测线程已销毁", roadInfo.strSoundCardName.toStdString(), roadInfo.roadInfo.nRoadNum);
|
|
|
-// }
|
|
|
-
|
|
|
-// return true;
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-// /* 获取音量报警线程 */
|
|
|
-// CalculateDBPhaseThread* ThreadManager::getCalculateDBPhaseThread(const SoundCardRoadInfo_t& roadInfo)
|
|
|
-// {
|
|
|
-// std::lock_guard<std::mutex> lock(m_mutexCalculateDBPhaseThreads);
|
|
|
-// for(const auto pThread : m_listCalculateDBPhaseThreads)
|
|
|
-// {
|
|
|
-// const SoundCardRoadInfo_t& threadRoadInfo = pThread->getRoadInfo();
|
|
|
-// if(threadRoadInfo.nSoundCardNum == roadInfo.nSoundCardNum &&
|
|
|
-// threadRoadInfo.roadInfo.nRoadNum == roadInfo.roadInfo.nRoadNum)
|
|
|
-// {
|
|
|
-// return pThread; // 找到相同的线程,直接返回
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// /* 没找到该线程,创建新的线程 */
|
|
|
-// CompareItemRoadInfo_t item;
|
|
|
-// item.nCompareRoadNum = 1; // 假设音量报警线程
|
|
|
-// item.scRoadInfo = roadInfo;
|
|
|
-
|
|
|
-// threadInfo.compareItemInfo.mapRoad.insert(item.nCompareRoadNum, item);
|
|
|
-// CalculateDBPhaseThread* newThread = new CalculateDBPhaseThread(threadInfo);
|
|
|
-
|
|
|
-// if(newThread == nullptr)
|
|
|
-// {
|
|
|
-// SPDLOG_LOGGER_ERROR(m_logger, "创建音量报警线程失败");
|
|
|
-// return nullptr; // 创建失败
|
|
|
-// }
|
|
|
-// CPPTP.add_task(&CalculateDBPhaseThread::threadTask, newThread);
|
|
|
-
|
|
|
-// m_listCalculateDBPhaseThreads.push_back(newThread);
|
|
|
-// m_referCountCalculateDBPhase++; // 引用计数加一
|
|
|
-
|
|
|
-// return newThread;
|
|
|
-// }
|
|
|
-
|
|
|
-// /* 去掉音量报警线程,线程使用的计数减一,计数为0则销毁该线程 */
|
|
|
-// bool ThreadManager::removeCalculateDBPhaseThread(RoadNumberInfo_t& roadInfo)
|
|
|
-// {
|
|
|
-// std::lock_guard<std::mutex> lock(m_mutexCalculateDBPhaseThreads);
|
|
|
-// CalculateDBPhaseThread* pThreadToRemove = nullptr;
|
|
|
-// for(const auto pThread : m_listCalculateDBPhaseThreads)
|
|
|
-// {
|
|
|
-// if(pThread->getRoadInfo().roadID == roadInfo.roadID)
|
|
|
-// {
|
|
|
-// pThreadToRemove = pThread; // 找到相同的线程,直接返回
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if(pThreadToRemove == nullptr)
|
|
|
-// {
|
|
|
-// SPDLOG_LOGGER_WARN(m_logger, "{} 音量报警线程未找到", roadInfo.strRoadName);
|
|
|
-// return false; // 没找到该线程
|
|
|
-// }
|
|
|
-// m_referCountCalculateDBPhase--; // 引用计数减一
|
|
|
-// if(m_referCountCalculateDBPhase <= 0)
|
|
|
-// {
|
|
|
-// pThreadToRemove->thread_stop(); // 停止线程
|
|
|
-// m_listCalculateDBPhaseThreads.remove(pThreadToRemove); // 从列表中移除
|
|
|
-// delete pThreadToRemove; // 删除线程
|
|
|
-// pThreadToRemove = nullptr;
|
|
|
-// m_referCountCalculateDBPhase = 0; // 重置引用计数
|
|
|
-// SPDLOG_LOGGER_INFO(m_logger, "{} 音量报警线程已销毁", roadInfo.strRoadName);
|
|
|
-// }
|
|
|
-
|
|
|
-// return true;
|
|
|
-// }
|
|
|
-
|
|
|
-/* RTP线程函数,套一层壳 */
|
|
|
-void ThreadManager::thread_RTPSend(RecordThreadInfo_t& threadInfo)
|
|
|
-{
|
|
|
- RTPOneRoadThread* pRtpSendThread = new RTPOneRoadThread(threadInfo);
|
|
|
- if(pRtpSendThread == nullptr)
|
|
|
- {
|
|
|
- SPDLOG_ERROR("{}:{} 创建RTP发送线程失败", threadInfo.cardRoadInfo.strSoundCardName, threadInfo.cardRoadInfo.pcmInfo.strPCMName);
|
|
|
- return;
|
|
|
- }
|
|
|
- /* 先加入队列,再开启线程 */
|
|
|
- ThreadMan.m_mutexRtpSendThreads.lock();
|
|
|
- ThreadMan.m_rtpSendThreads.push_back(pRtpSendThread);
|
|
|
- ThreadMan.m_mutexRtpSendThreads.unlock();
|
|
|
-
|
|
|
- pRtpSendThread->thread_task();
|
|
|
-}
|
|
|
|