Add Stream Reader Thread

This commit is contained in:
2019-11-10 14:25:35 -08:00
parent f567fb31c9
commit 49f1e3b19d
5 changed files with 329 additions and 15 deletions

60
StreamReader.cpp Normal file
View File

@@ -0,0 +1,60 @@
#include "StreamReader.hpp"
StreamReader::StreamReader(PvDevice *Device, PvStream *Stream, PvPipeline *Pipeline)
{
this->Device = Device;
this->Stream = Stream;
this->Pipeline = Pipeline;
}
void StreamReader::run()
{
while (!isInterruptionRequested())
{
PvBuffer *lBuffer = NULL;
PvResult lOperationResult;
// wait for this to unblock before called in event loop
// Retrieve next buffer
PvResult lResult = Stream->RetrieveBuffer(&lBuffer, &lOperationResult, 1000);
if (lResult.IsOK())
{
if (lOperationResult.IsOK())
{
PvPayloadType lType;
// If the buffer contains an image, display width and height.
uint32_t lWidth = 0, lHeight = 0;
lType = lBuffer->GetPayloadType();
if (lType == PvPayloadTypeImage)
{
// Get image specific buffer interface.
PvImage *lImage = lBuffer->GetImage();
// Read width, height.
lWidth = lImage->GetWidth();
lHeight = lImage->GetHeight();
NewImage(lWidth, lHeight, lImage->GetDataPointer());
}
else
{
qWarning() << " (buffer does not contain image)";
}
}
else
{
qInfo() << lOperationResult.GetCodeString().GetAscii() << "\r";
}
// Re-queue the buffer in the stream object
Stream->QueueBuffer(lBuffer);
}
else
{
// Retrieve buffer failure
qCritical() << lResult.GetCodeString().GetAscii() << "\r";
}
}
}