|
@@ -1,47 +1,82 @@
|
|
#include "MppManager.h"
|
|
#include "MppManager.h"
|
|
#include "../DataManager/DataManager.h"
|
|
#include "../DataManager/DataManager.h"
|
|
#include "../DataManager/DataPackage.h"
|
|
#include "../DataManager/DataPackage.h"
|
|
|
|
+#include "../ThreadGuardian/ThreadGuardian.h"
|
|
#include "../RGAColorTransfer/RgaColorTransfer.h"
|
|
#include "../RGAColorTransfer/RgaColorTransfer.h"
|
|
#include <thread>
|
|
#include <thread>
|
|
#include "../ImageTest/ImageTest.h"
|
|
#include "../ImageTest/ImageTest.h"
|
|
// ...existing code...
|
|
// ...existing code...
|
|
|
|
|
|
|
|
+void MppManager::updateThreadStatus(int threadIndex)
|
|
|
|
+{
|
|
|
|
+ std::string threadName = "mppThread_" + std::to_string(threadIndex);
|
|
|
|
+ ThreadGuardian::getInstance().updateThreadHeartbeat(threadName);
|
|
|
|
+}
|
|
|
|
+
|
|
MppManager::~MppManager()
|
|
MppManager::~MppManager()
|
|
{
|
|
{
|
|
- for (auto &thread : m_threads)
|
|
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < m_threads.size(); i++)
|
|
{
|
|
{
|
|
- m_threadSwitch = false;
|
|
|
|
- if (thread.joinable())
|
|
|
|
|
|
+ m_bThreadSwitch = false;
|
|
|
|
+ if (m_threads[i].joinable())
|
|
{
|
|
{
|
|
- thread.join();
|
|
|
|
|
|
+ m_threads[i].join();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void MppManager::addMppDecode()
|
|
void MppManager::addMppDecode()
|
|
{
|
|
{
|
|
- m_threads.emplace_back(&MppManager::decodeThread, this);
|
|
|
|
- m_threads.emplace_back(&MppManager::decodeThread, this);
|
|
|
|
- m_threads.emplace_back(&MppManager::decodeThread, this);
|
|
|
|
|
|
+ m_vThreadSwitch.resize(3);
|
|
|
|
+ m_bThreadSwitch = true;
|
|
|
|
+ m_threads.emplace_back(&MppManager::decodeThread, this, 0);
|
|
|
|
+ int index = m_threads.size() - 1;
|
|
|
|
+ ThreadGuardian::getInstance().registerMppThread(index, std::bind(&MppManager::restartDecodeThread, this, index));
|
|
|
|
+
|
|
|
|
+ m_threads.emplace_back(&MppManager::decodeThread, this, 1);
|
|
|
|
+ index = m_threads.size() - 1;
|
|
|
|
+ ThreadGuardian::getInstance().registerMppThread(index, std::bind(&MppManager::restartDecodeThread, this, index));
|
|
|
|
+
|
|
|
|
+ m_threads.emplace_back(&MppManager::decodeThread, this, 2);
|
|
|
|
+ index = m_threads.size() - 1;
|
|
|
|
+ ThreadGuardian::getInstance().registerMppThread(index, std::bind(&MppManager::restartDecodeThread, this, index));
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void MppManager::restartDecodeThread(int threadIndex)
|
|
|
|
+{
|
|
|
|
+ // 先停止当前线程
|
|
|
|
+ // if (m_threads[threadIndex].joinable())
|
|
|
|
+ // {
|
|
|
|
+ // m_vThreadSwitch[threadIndex] = false;
|
|
|
|
+ // m_threads[threadIndex].join();
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // 重新启动线程
|
|
|
|
+ if (threadIndex >= 0 && threadIndex < m_threads.size())
|
|
|
|
+ {
|
|
|
|
+ m_threads[threadIndex] = std::thread(&MppManager::decodeThread, this, threadIndex);
|
|
|
|
+ std::cout << "MPP线程 " << threadIndex << " 已重新启动" << std::endl;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
-void MppManager::decodeThread()
|
|
|
|
|
|
+void MppManager::decodeThread(int index)
|
|
{
|
|
{
|
|
MppDecoder decoder;
|
|
MppDecoder decoder;
|
|
decoder.init();
|
|
decoder.init();
|
|
RgaColorTransfer colorTransfer;
|
|
RgaColorTransfer colorTransfer;
|
|
unsigned char *rgbData = nullptr;
|
|
unsigned char *rgbData = nullptr;
|
|
int width = 0, height = 0;
|
|
int width = 0, height = 0;
|
|
- m_threadSwitch = true;
|
|
|
|
- int index = decoder.getDecodeIndex();
|
|
|
|
DataManager::getInstance().addDataPipe<DataPackagePtr>("resized" + std::to_string(index));
|
|
DataManager::getInstance().addDataPipe<DataPackagePtr>("resized" + std::to_string(index));
|
|
|
|
|
|
// test
|
|
// test
|
|
UsbTest::HighResolutionTimer timer;
|
|
UsbTest::HighResolutionTimer timer;
|
|
|
|
|
|
- while (m_threadSwitch)
|
|
|
|
|
|
+ while (m_bThreadSwitch)
|
|
{
|
|
{
|
|
DataPackagePtr dataPackage = nullptr;
|
|
DataPackagePtr dataPackage = nullptr;
|
|
|
|
+ // update thread status
|
|
|
|
+ updateThreadStatus(index);
|
|
if (DataManager::getInstance().popData("uvc" + std::to_string(index), dataPackage))
|
|
if (DataManager::getInstance().popData("uvc" + std::to_string(index), dataPackage))
|
|
{
|
|
{
|
|
decoder.decodeJpegToRgb((const char *)dataPackage->pJpegData, dataPackage->nJpegSize, (unsigned char **)&dataPackage->pRGBData, &width, &height);
|
|
decoder.decodeJpegToRgb((const char *)dataPackage->pJpegData, dataPackage->nJpegSize, (unsigned char **)&dataPackage->pRGBData, &width, &height);
|
|
@@ -50,7 +85,7 @@ void MppManager::decodeThread()
|
|
std::cerr << "the decode result is different from defined !!" << std::endl;
|
|
std::cerr << "the decode result is different from defined !!" << std::endl;
|
|
}
|
|
}
|
|
|
|
|
|
- // ImageTest::saveImageFromData((unsigned char *)dataPackage->pRGBData, dataPackage->nResizeWidth, dataPackage->nResizeHeight);
|
|
|
|
|
|
+ std::cout << "Decoded frame " << index << std::endl;
|
|
|
|
|
|
// color transfer
|
|
// color transfer
|
|
resize_image(dataPackage->pRGBData, width, height, dataPackage->pResizeData, dataPackage->nResizeWidth, dataPackage->nResizeHeight);
|
|
resize_image(dataPackage->pRGBData, width, height, dataPackage->pResizeData, dataPackage->nResizeWidth, dataPackage->nResizeHeight);
|
|
@@ -58,7 +93,7 @@ void MppManager::decodeThread()
|
|
// ImageTest::saveImageFromData((unsigned char *)dataPackage->pResizeData, dataPackage->nResizeWidth, dataPackage->nResizeHeight);
|
|
// ImageTest::saveImageFromData((unsigned char *)dataPackage->pResizeData, dataPackage->nResizeWidth, dataPackage->nResizeHeight);
|
|
|
|
|
|
std::string logMessage = "Decoded frame " + std::to_string(index) + " degree : " + std::to_string(dataPackage->dDegree) + " " + UsbTest::GlobalResolutionTimer::getInstance().pressStopWatchString();
|
|
std::string logMessage = "Decoded frame " + std::to_string(index) + " degree : " + std::to_string(dataPackage->dDegree) + " " + UsbTest::GlobalResolutionTimer::getInstance().pressStopWatchString();
|
|
- //UsbTest::TimeRecorder::getInstance().recordTime(logMessage);
|
|
|
|
|
|
+ // UsbTest::TimeRecorder::getInstance().recordTime(logMessage);
|
|
|
|
|
|
// push data to the next pipe
|
|
// push data to the next pipe
|
|
DataManager::getInstance().pushData("resized" + std::to_string(index), dataPackage);
|
|
DataManager::getInstance().pushData("resized" + std::to_string(index), dataPackage);
|