|
@@ -38,6 +38,16 @@ void ThreadManager::stopAllThreads()
|
|
|
|
|
|
}
|
|
|
|
|
|
+/* 线程函数,销毁录音线程 */
|
|
|
+void ThreadManager::thread_destroyeRecordThread()
|
|
|
+{
|
|
|
+ while(true)
|
|
|
+ {
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
+ destroyeRecordThread();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/* 创建一个录音通道及其附属的线程 */
|
|
|
bool ThreadManager::createRecordThread(const OneSoundCardPCMInfo_t& pcmInfo, int compareItemID)
|
|
|
{
|
|
@@ -76,52 +86,52 @@ bool ThreadManager::createRecordThread(const OneSoundCardPCMInfo_t& pcmInfo, int
|
|
|
/* 先创建生成wav小文件数据的线程 */
|
|
|
RecordThreadInfo_t threadInfo;
|
|
|
threadInfo.cardRoadInfo = pcmInfo;
|
|
|
- threadInfo.threadState = EThreadState::State_Inited;
|
|
|
+ threadInfo.threadState.store(EThreadState::State_Inited);
|
|
|
threadInfo.threadType = EThreadType::Type_CreateWAV;
|
|
|
- // CreateWAVThread* pCreateWAVThread = new CreateWAVThread(threadInfo);
|
|
|
- // if(pCreateWAVThread == nullptr)
|
|
|
- // {
|
|
|
- // SPDLOG_LOGGER_ERROR(m_logger, "{}:{} 创建生成wav小文件线程失败", pcmInfo.strSoundCardName, pcmInfo.pcmInfo.strPCMName);
|
|
|
- // // return false; // 创建失败
|
|
|
- // }else
|
|
|
- // {
|
|
|
- // CPPTP.add_task(&CreateWAVThread::thread_task, pCreateWAVThread);
|
|
|
- // std::lock_guard<std::mutex> lock(m_mutexCreateWAVThreads);
|
|
|
- // m_createWAVThreads.push_back(pCreateWAVThread);
|
|
|
- // }
|
|
|
+ CreateWAVThread* pCreateWAVThread = new CreateWAVThread(threadInfo);
|
|
|
+ if(pCreateWAVThread == nullptr)
|
|
|
+ {
|
|
|
+ SPDLOG_LOGGER_ERROR(m_logger, "{}:{} 创建生成wav小文件线程失败", pcmInfo.strSoundCardName, pcmInfo.pcmInfo.strPCMName);
|
|
|
+ // return false; // 创建失败
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ CPPTP.add_task(&CreateWAVThread::thread_task, pCreateWAVThread);
|
|
|
+ std::lock_guard<std::mutex> lock(m_mutexCreateWAVThreads);
|
|
|
+ m_createWAVThreads.push_back(pCreateWAVThread);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/* 创建计算音量的线程 */
|
|
|
threadInfo.threadType = EThreadType::Type_CreateDB;
|
|
|
- // CreateDBThread* pCreateDBThread = new CreateDBThread(threadInfo);
|
|
|
- // if(pCreateDBThread == nullptr)
|
|
|
- // {
|
|
|
- // SPDLOG_LOGGER_ERROR(m_logger, "{}:{} 创建计算音量线程失败", pcmInfo.strSoundCardName, pcmInfo.pcmInfo.strPCMName);
|
|
|
- // // return false; // 创建失败
|
|
|
- // }else
|
|
|
- // {
|
|
|
- // CPPTP.add_task(&CreateDBThread::thread_task, pCreateDBThread);
|
|
|
- // std::lock_guard<std::mutex> lock(m_mutexCreateDBThreads);
|
|
|
- // m_createDBThreads.push_back(pCreateDBThread);
|
|
|
- // }
|
|
|
+ CreateDBThread* pCreateDBThread = new CreateDBThread(threadInfo);
|
|
|
+ if(pCreateDBThread == nullptr)
|
|
|
+ {
|
|
|
+ SPDLOG_LOGGER_ERROR(m_logger, "{}:{} 创建计算音量线程失败", pcmInfo.strSoundCardName, pcmInfo.pcmInfo.strPCMName);
|
|
|
+ // return false; // 创建失败
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ CPPTP.add_task(&CreateDBThread::thread_task, pCreateDBThread);
|
|
|
+ std::lock_guard<std::mutex> lock(m_mutexCreateDBThreads);
|
|
|
+ m_createDBThreads.push_back(pCreateDBThread);
|
|
|
+ }
|
|
|
|
|
|
/* 创建生成长文件的线程 */
|
|
|
threadInfo.threadType = EThreadType::Type_CreateLongWAV;
|
|
|
- // CreateRecordFileThread* pCreateLongWAVThread = new CreateRecordFileThread(threadInfo);
|
|
|
- // if(pCreateLongWAVThread == nullptr)
|
|
|
- // {
|
|
|
- // SPDLOG_LOGGER_ERROR(m_logger, "{}:{} 创建生成长文件线程失败", pcmInfo.strSoundCardName, pcmInfo.pcmInfo.strPCMName);
|
|
|
- // // return false; // 创建失败
|
|
|
- // }else
|
|
|
- // {
|
|
|
- // CPPTP.add_task(&CreateRecordFileThread::thread_task, pCreateLongWAVThread);
|
|
|
- // std::lock_guard<std::mutex> lock(m_mutexCreateLongWAVThreads);
|
|
|
- // m_createLongWAVThreads.push_back(pCreateLongWAVThread);
|
|
|
- // }
|
|
|
+ CreateRecordFileThread* pCreateLongWAVThread = new CreateRecordFileThread(threadInfo);
|
|
|
+ if(pCreateLongWAVThread == nullptr)
|
|
|
+ {
|
|
|
+ SPDLOG_LOGGER_ERROR(m_logger, "{}:{} 创建生成长文件线程失败", pcmInfo.strSoundCardName, pcmInfo.pcmInfo.strPCMName);
|
|
|
+ // return false; // 创建失败
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ CPPTP.add_task(&CreateRecordFileThread::thread_task, pCreateLongWAVThread);
|
|
|
+ std::lock_guard<std::mutex> lock(m_mutexCreateLongWAVThreads);
|
|
|
+ m_createLongWAVThreads.push_back(pCreateLongWAVThread);
|
|
|
+ }
|
|
|
|
|
|
/* 创建发送RTP数据的线程 */
|
|
|
threadInfo.threadType = EThreadType::Type_RtpSend;
|
|
|
- // CPPTP.add_task(&ThreadManager::thread_RTPSend, threadInfo);
|
|
|
+ CPPTP.add_task(&ThreadManager::thread_RTPSend, threadInfo);
|
|
|
|
|
|
/* 创建分派数据线程 */
|
|
|
threadInfo.threadType = EThreadType::Type_AssignSrcData;
|
|
@@ -309,7 +319,7 @@ bool ThreadManager::removeRecordThread(const OneSoundCardPCMInfo_t& pcmInfo, int
|
|
|
}
|
|
|
|
|
|
/* 销毁录音线程 */
|
|
|
-void ThreadManager::thread_destroyeRecordThread()
|
|
|
+void ThreadManager::destroyeRecordThread()
|
|
|
{
|
|
|
std::unique_lock<std::mutex> m_lock(m_mutexRecordThreadRefCount);
|
|
|
m_condVarDestroyRecord.wait(m_lock, [this]() {
|
|
@@ -329,7 +339,7 @@ void ThreadManager::thread_destroyeRecordThread()
|
|
|
BaseRecordThread* pThread = *it;
|
|
|
if(pThread != nullptr)
|
|
|
{
|
|
|
- auto threadState = pThread->getThreadInfo().threadState;
|
|
|
+ auto threadState = pThread->getThreadInfo().threadState.load();
|
|
|
if(EThreadState::State_Stopped == threadState ||
|
|
|
EThreadState::State_Error == threadState )
|
|
|
{
|
|
@@ -355,7 +365,7 @@ void ThreadManager::thread_destroyeRecordThread()
|
|
|
BaseRecordThread* pThread = *it;
|
|
|
if(pThread != nullptr)
|
|
|
{
|
|
|
- auto threadState = pThread->getThreadInfo().threadState;
|
|
|
+ auto threadState = pThread->getThreadInfo().threadState.load();
|
|
|
if(EThreadState::State_Stopped == threadState ||
|
|
|
EThreadState::State_Error == threadState )
|
|
|
{
|
|
@@ -381,7 +391,7 @@ void ThreadManager::thread_destroyeRecordThread()
|
|
|
BaseRecordThread* pThread = *it;
|
|
|
if(pThread != nullptr)
|
|
|
{
|
|
|
- auto threadState = pThread->getThreadInfo().threadState;
|
|
|
+ auto threadState = pThread->getThreadInfo().threadState.load();
|
|
|
if(EThreadState::State_Stopped == threadState ||
|
|
|
EThreadState::State_Error == threadState )
|
|
|
{
|
|
@@ -407,7 +417,7 @@ void ThreadManager::thread_destroyeRecordThread()
|
|
|
BaseRecordThread* pThread = *it;
|
|
|
if(pThread != nullptr)
|
|
|
{
|
|
|
- auto threadState = pThread->getThreadInfo().threadState;
|
|
|
+ auto threadState = pThread->getThreadInfo().threadState.load();
|
|
|
if(EThreadState::State_Stopped == threadState ||
|
|
|
EThreadState::State_Error == threadState )
|
|
|
{
|
|
@@ -433,7 +443,7 @@ void ThreadManager::thread_destroyeRecordThread()
|
|
|
BaseRecordThread* pThread = *it;
|
|
|
if(pThread != nullptr)
|
|
|
{
|
|
|
- auto threadState = pThread->getThreadInfo().threadState;
|
|
|
+ auto threadState = pThread->getThreadInfo().threadState.load();
|
|
|
if(EThreadState::State_Stopped == threadState ||
|
|
|
EThreadState::State_Error == threadState )
|
|
|
{
|
|
@@ -459,7 +469,7 @@ void ThreadManager::thread_destroyeRecordThread()
|
|
|
BaseRecordThread* pThread = *it;
|
|
|
if(pThread != nullptr)
|
|
|
{
|
|
|
- auto threadState = pThread->getThreadInfo().threadState;
|
|
|
+ auto threadState = pThread->getThreadInfo().threadState.load();
|
|
|
if(EThreadState::State_Stopped == threadState ||
|
|
|
EThreadState::State_Error == threadState )
|
|
|
{
|