Files
fault-finder/StreamReader.cpp
2020-01-12 15:22:11 -08:00

61 lines
1.8 KiB
C++

#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 = Pipeline->RetrieveNextBuffer(&lBuffer, 1000, &lOperationResult);
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();
// May need to push copy of data, not pointer to buffer in case it deallocs
emit 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";
}
}
}