|
@@ -42,7 +42,7 @@ void ThreadManager::stopAllThreads()
|
|
|
bool ThreadManager::createRecordThread(const OneSoundCardPCMInfo_t& pcmInfo, int compareItemID)
|
|
|
{
|
|
|
/* 先查找队列中有没有该录音通道 */
|
|
|
- std::lock_guard<std::mutex> lock(m_mutexRecordThreadRefCount);
|
|
|
+ std::unique_lock<std::mutex> lock(m_mutexRecordThreadRefCount);
|
|
|
for(const auto& pair : m_mapRecordThreadRefCount)
|
|
|
{
|
|
|
if( pair.first == pcmInfo.pcmInfo.strPCMName)
|
|
@@ -85,7 +85,7 @@ bool ThreadManager::createRecordThread(const OneSoundCardPCMInfo_t& pcmInfo, int
|
|
|
// return false; // 创建失败
|
|
|
}else
|
|
|
{
|
|
|
- CPPTP.add_task(&CreateWAVThread::threadTask, pCreateWAVThread);
|
|
|
+ CPPTP.add_task(&CreateWAVThread::thread_task, pCreateWAVThread);
|
|
|
std::lock_guard<std::mutex> lock(m_mutexCreateWAVThreads);
|
|
|
m_createWAVThreads.push_back(pCreateWAVThread);
|
|
|
}
|
|
@@ -100,7 +100,7 @@ bool ThreadManager::createRecordThread(const OneSoundCardPCMInfo_t& pcmInfo, int
|
|
|
// return false; // 创建失败
|
|
|
}else
|
|
|
{
|
|
|
- CPPTP.add_task(&CreateDBThread::threadTask, pCreateDBThread);
|
|
|
+ CPPTP.add_task(&CreateDBThread::thread_task, pCreateDBThread);
|
|
|
std::lock_guard<std::mutex> lock(m_mutexCreateDBThreads);
|
|
|
m_createDBThreads.push_back(pCreateDBThread);
|
|
|
}
|
|
@@ -114,7 +114,7 @@ bool ThreadManager::createRecordThread(const OneSoundCardPCMInfo_t& pcmInfo, int
|
|
|
// return false; // 创建失败
|
|
|
}else
|
|
|
{
|
|
|
- CPPTP.add_task(&CreateRecordFileThread::threadTask, pCreateLongWAVThread);
|
|
|
+ CPPTP.add_task(&CreateRecordFileThread::thread_task, pCreateLongWAVThread);
|
|
|
std::lock_guard<std::mutex> lock(m_mutexCreateLongWAVThreads);
|
|
|
m_createLongWAVThreads.push_back(pCreateLongWAVThread);
|
|
|
}
|
|
@@ -143,7 +143,7 @@ bool ThreadManager::createRecordThread(const OneSoundCardPCMInfo_t& pcmInfo, int
|
|
|
// return false; // 创建失败
|
|
|
}else
|
|
|
{
|
|
|
- CPPTP.add_task(&RecordThread::threadTask, pRecordThread);
|
|
|
+ CPPTP.add_task(&RecordThread::thread_task, pRecordThread);
|
|
|
std::lock_guard<std::mutex> lock(m_mutexRecordThreads);
|
|
|
m_recordThreads.push_back(pRecordThread);
|
|
|
}
|
|
@@ -157,7 +157,7 @@ bool ThreadManager::createRecordThread(const OneSoundCardPCMInfo_t& pcmInfo, int
|
|
|
// return false; // 创建失败
|
|
|
}else
|
|
|
{
|
|
|
- CPPTP.add_task(&AssignSrcDataThread::threadTask, pAssignSrcDataThread);
|
|
|
+ CPPTP.add_task(&AssignSrcDataThread::thread_task, pAssignSrcDataThread);
|
|
|
std::lock_guard<std::mutex> lock(m_mutexAssignSrcDataThreads);
|
|
|
m_assignSrcDataThreads.push_back(pAssignSrcDataThread);
|
|
|
}
|
|
@@ -174,7 +174,7 @@ bool ThreadManager::createRecordThread(const OneSoundCardPCMInfo_t& pcmInfo, int
|
|
|
*/
|
|
|
bool ThreadManager::removeRecordThread(const OneSoundCardPCMInfo_t& pcmInfo, int compareItemID)
|
|
|
{
|
|
|
- std::lock_guard<std::mutex> lock(m_mutexRecordThreadRefCount);
|
|
|
+ std::unique_lock<std::mutex> lock(m_mutexRecordThreadRefCount);
|
|
|
/* 先查找这个引用计数是否存在 */
|
|
|
int refCount = 0;
|
|
|
for(auto& pair : m_mapRecordThreadRefCount)
|
|
@@ -211,7 +211,7 @@ bool ThreadManager::removeRecordThread(const OneSoundCardPCMInfo_t& pcmInfo, int
|
|
|
const auto& threadInfo = it->getThreadInfo();
|
|
|
if(threadInfo.cardRoadInfo.pcmInfo.strPCMName == pcmInfo.pcmInfo.strPCMName)
|
|
|
{
|
|
|
- it->stopThread();
|
|
|
+ it->thread_stop_block();
|
|
|
SPDLOG_LOGGER_TRACE(m_logger, "{} 录音线程已停止", logBase);
|
|
|
break;
|
|
|
}
|
|
@@ -225,7 +225,7 @@ bool ThreadManager::removeRecordThread(const OneSoundCardPCMInfo_t& pcmInfo, int
|
|
|
const auto& threadInfo = it->getThreadInfo();
|
|
|
if(threadInfo.cardRoadInfo.pcmInfo.strPCMName == pcmInfo.pcmInfo.strPCMName)
|
|
|
{
|
|
|
- it->stopThread();
|
|
|
+ it->thread_stop_block();
|
|
|
SPDLOG_LOGGER_TRACE(m_logger, "{} 分派数据线程已停止", logBase);
|
|
|
break;
|
|
|
}
|
|
@@ -239,7 +239,7 @@ bool ThreadManager::removeRecordThread(const OneSoundCardPCMInfo_t& pcmInfo, int
|
|
|
const auto& threadInfo = it->getThreadInfo();
|
|
|
if(threadInfo.cardRoadInfo.pcmInfo.strPCMName == pcmInfo.pcmInfo.strPCMName)
|
|
|
{
|
|
|
- it->stopThread();
|
|
|
+ it->thread_stop_block();
|
|
|
SPDLOG_LOGGER_TRACE(m_logger, "{} 生成wav小文件线程已停止", logBase);
|
|
|
break;
|
|
|
}
|
|
@@ -254,7 +254,7 @@ bool ThreadManager::removeRecordThread(const OneSoundCardPCMInfo_t& pcmInfo, int
|
|
|
const auto& threadInfo = it->getThreadInfo();
|
|
|
if(threadInfo.cardRoadInfo.pcmInfo.strPCMName == pcmInfo.pcmInfo.strPCMName)
|
|
|
{
|
|
|
- it->stopThread();
|
|
|
+ it->thread_stop_block();
|
|
|
SPDLOG_LOGGER_TRACE(m_logger, "{} 计算音量线程已停止", logBase);
|
|
|
break;
|
|
|
}
|
|
@@ -269,7 +269,7 @@ bool ThreadManager::removeRecordThread(const OneSoundCardPCMInfo_t& pcmInfo, int
|
|
|
const auto& threadInfo = it->getThreadInfo();
|
|
|
if(threadInfo.cardRoadInfo.pcmInfo.strPCMName == pcmInfo.pcmInfo.strPCMName)
|
|
|
{
|
|
|
- it->stopThread();
|
|
|
+ it->thread_stop_block();
|
|
|
SPDLOG_LOGGER_TRACE(m_logger, "{} 生成长文件线程已停止", logBase);
|
|
|
break;
|
|
|
}
|
|
@@ -284,7 +284,7 @@ bool ThreadManager::removeRecordThread(const OneSoundCardPCMInfo_t& pcmInfo, int
|
|
|
const auto& threadInfo = it->getThreadInfo();
|
|
|
if(threadInfo.cardRoadInfo.pcmInfo.strPCMName == pcmInfo.pcmInfo.strPCMName)
|
|
|
{
|
|
|
- it->stopThread();
|
|
|
+ it->thread_stop_block();
|
|
|
SPDLOG_LOGGER_TRACE(m_logger, "{} 发送RTP数据线程已停止", logBase);
|
|
|
break;
|
|
|
}
|
|
@@ -304,13 +304,18 @@ bool ThreadManager::removeRecordThread(const OneSoundCardPCMInfo_t& pcmInfo, int
|
|
|
|
|
|
// 设置销毁录音线程标志
|
|
|
m_isDestroyeRecordThread.store(true);
|
|
|
+ m_condVarDestroyRecord.notify_one();
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/* 销毁录音线程 */
|
|
|
-void ThreadManager::destroyeRecordThread()
|
|
|
+void ThreadManager::thread_destroyeRecordThread()
|
|
|
{
|
|
|
+ std::unique_lock<std::mutex> m_lock(m_mutexRecordThreadRefCount);
|
|
|
+ m_condVarDestroyRecord.wait(m_lock, [this]() {
|
|
|
+ return m_isDestroyeRecordThread.load();
|
|
|
+ });
|
|
|
if(!m_isDestroyeRecordThread.load())
|
|
|
{
|
|
|
/* 没有需要销毁的线程 */
|
|
@@ -324,7 +329,9 @@ void ThreadManager::destroyeRecordThread()
|
|
|
BaseRecordThread* pThread = *it;
|
|
|
if(pThread != nullptr)
|
|
|
{
|
|
|
- if(pThread->getThreadInfo().threadState == EThreadState::State_Running)
|
|
|
+ auto threadState = pThread->getThreadInfo().threadState;
|
|
|
+ if(EThreadState::State_Stopped == threadState ||
|
|
|
+ EThreadState::State_Error == threadState )
|
|
|
{
|
|
|
auto pRecordThread = dynamic_cast<RecordThread*>(pThread);
|
|
|
delete pRecordThread; // 删除线程
|
|
@@ -346,7 +353,9 @@ void ThreadManager::destroyeRecordThread()
|
|
|
BaseRecordThread* pThread = *it;
|
|
|
if(pThread != nullptr)
|
|
|
{
|
|
|
- if(pThread->getThreadInfo().threadState == EThreadState::State_Running)
|
|
|
+ auto threadState = pThread->getThreadInfo().threadState;
|
|
|
+ if(EThreadState::State_Stopped == threadState ||
|
|
|
+ EThreadState::State_Error == threadState )
|
|
|
{
|
|
|
auto pAssignSrcDataThread = dynamic_cast<AssignSrcDataThread*>(pThread);
|
|
|
delete pAssignSrcDataThread; // 删除线程
|
|
@@ -368,7 +377,9 @@ void ThreadManager::destroyeRecordThread()
|
|
|
BaseRecordThread* pThread = *it;
|
|
|
if(pThread != nullptr)
|
|
|
{
|
|
|
- if(pThread->getThreadInfo().threadState == EThreadState::State_Running)
|
|
|
+ auto threadState = pThread->getThreadInfo().threadState;
|
|
|
+ if(EThreadState::State_Stopped == threadState ||
|
|
|
+ EThreadState::State_Error == threadState )
|
|
|
{
|
|
|
auto pCreateWAVThread = dynamic_cast<CreateWAVThread*>(pThread);
|
|
|
delete pCreateWAVThread; // 删除线程
|
|
@@ -390,7 +401,9 @@ void ThreadManager::destroyeRecordThread()
|
|
|
BaseRecordThread* pThread = *it;
|
|
|
if(pThread != nullptr)
|
|
|
{
|
|
|
- if(pThread->getThreadInfo().threadState == EThreadState::State_Running)
|
|
|
+ auto threadState = pThread->getThreadInfo().threadState;
|
|
|
+ if(EThreadState::State_Stopped == threadState ||
|
|
|
+ EThreadState::State_Error == threadState )
|
|
|
{
|
|
|
auto pCreateDBThread = dynamic_cast<CreateDBThread*>(pThread);
|
|
|
delete pCreateDBThread; // 删除线程
|
|
@@ -412,7 +425,9 @@ void ThreadManager::destroyeRecordThread()
|
|
|
BaseRecordThread* pThread = *it;
|
|
|
if(pThread != nullptr)
|
|
|
{
|
|
|
- if(pThread->getThreadInfo().threadState == EThreadState::State_Running)
|
|
|
+ auto threadState = pThread->getThreadInfo().threadState;
|
|
|
+ if(EThreadState::State_Stopped == threadState ||
|
|
|
+ EThreadState::State_Error == threadState )
|
|
|
{
|
|
|
auto pCreateLongWAVThread = dynamic_cast<CreateRecordFileThread*>(pThread);
|
|
|
delete pCreateLongWAVThread; // 删除线程
|
|
@@ -434,7 +449,9 @@ void ThreadManager::destroyeRecordThread()
|
|
|
BaseRecordThread* pThread = *it;
|
|
|
if(pThread != nullptr)
|
|
|
{
|
|
|
- if(pThread->getThreadInfo().threadState == EThreadState::State_Running)
|
|
|
+ auto threadState = pThread->getThreadInfo().threadState;
|
|
|
+ if(EThreadState::State_Stopped == threadState ||
|
|
|
+ EThreadState::State_Error == threadState )
|
|
|
{
|
|
|
auto pRtpSendThread = dynamic_cast<RTPOneRoadThread*>(pThread);
|
|
|
delete pRtpSendThread; // 删除线程
|
|
@@ -664,7 +681,7 @@ CreateRecordFileThread* ThreadManager::getCreateRecordFileThread(std::string pcm
|
|
|
// if(m_referCountConsistencyCompare <= 0)
|
|
|
// {
|
|
|
// /* 停止线程,并一直等待其停止 */
|
|
|
-// pThreadToRemove->stopThreadBlock();
|
|
|
+// pThreadToRemove->thread_stopBlock();
|
|
|
// m_listConsistencyCompareThreads.remove(pThreadToRemove); // 从列表中移除
|
|
|
// delete pThreadToRemove; // 删除线程
|
|
|
// pThreadToRemove = nullptr;
|
|
@@ -799,7 +816,7 @@ CreateRecordFileThread* ThreadManager::getCreateRecordFileThread(std::string pcm
|
|
|
// {
|
|
|
// SPDLOG_LOGGER_INFO(m_logger, "{}:{} 噪音检测线程引用计数为0,准备销毁该线程",
|
|
|
// roadInfo.strSoundCardName.toStdString(), roadInfo.roadInfo.nRoadNum);
|
|
|
-// pThreadToRemove->stopThreadBlock(); // 停止线程
|
|
|
+// pThreadToRemove->thread_stopBlock(); // 停止线程
|
|
|
// m_listNoiseDetectThreads.remove(pThreadToRemove); // 从列表中移除
|
|
|
// delete pThreadToRemove; // 删除线程
|
|
|
// pThreadToRemove = nullptr;
|
|
@@ -867,7 +884,7 @@ CreateRecordFileThread* ThreadManager::getCreateRecordFileThread(std::string pcm
|
|
|
// m_referCountCalculateDBPhase--; // 引用计数减一
|
|
|
// if(m_referCountCalculateDBPhase <= 0)
|
|
|
// {
|
|
|
-// pThreadToRemove->stopThread(); // 停止线程
|
|
|
+// pThreadToRemove->thread_stop(); // 停止线程
|
|
|
// m_listCalculateDBPhaseThreads.remove(pThreadToRemove); // 从列表中移除
|
|
|
// delete pThreadToRemove; // 删除线程
|
|
|
// pThreadToRemove = nullptr;
|
|
@@ -892,6 +909,6 @@ void ThreadManager::thread_RTPSend(RecordThreadInfo_t& threadInfo)
|
|
|
ThreadMan.m_rtpSendThreads.push_back(pRtpSendThread);
|
|
|
ThreadMan.m_mutexRtpSendThreads.unlock();
|
|
|
|
|
|
- pRtpSendThread->threadTask();
|
|
|
+ pRtpSendThread->thread_task();
|
|
|
}
|
|
|
|