summaryrefslogtreecommitdiff
path: root/src/camera/veyeimx287m.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/camera/veyeimx287m.h')
-rw-r--r--src/camera/veyeimx287m.h43
1 files changed, 31 insertions, 12 deletions
diff --git a/src/camera/veyeimx287m.h b/src/camera/veyeimx287m.h
index ab7e3e5..2b5c28c 100644
--- a/src/camera/veyeimx287m.h
+++ b/src/camera/veyeimx287m.h
@@ -1,17 +1,20 @@
#pragma once
+// c/cpp
#include <cstdint>
#include <linux/videodev2.h>
#include <queue>
#include <thread>
+// qt
+#include <QQueue>
#include <QReadWriteLock>
#include <QSemaphore>
+// orpheus
#include "constants.h"
-#include "image.h"
-
#include "icamera.h"
+#include "image.h"
namespace veye {
namespace imx287m {
@@ -75,6 +78,7 @@ private:
void getFrameLoop(std::stop_token stopToken);
void rotateFrameLoop(std::stop_token stopToken);
+ void calcPixelsLoop(std::stop_token stopToken);
private:
/*!
@@ -95,10 +99,10 @@ private:
*/
std::array<std::mutex, BUFFER_COUNT> m_imageMutexes;
+ // TODO: split this
+ // there should be no chance of changing image by ioctl during futher processing
struct buffer
{
- unsigned int padding{0};
- unsigned int size{0};
void *mem{nullptr};
std::shared_ptr<Image> image{std::make_shared<Image>()};
};
@@ -106,13 +110,26 @@ private:
struct Semaphore
{
+ Semaphore()
+ {
+ rawBufferIndices.reserve(BUFFER_COUNT);
+ rotatedBufferIndices.reserve(BUFFER_COUNT);
+ }
const uint8_t maxSize{BUFFER_COUNT};
- uint8_t bufferIdx{std::numeric_limits<decltype(bufferIdx)>::max()};
- std::binary_semaphore main2calc{0};
- std::binary_semaphore calc2main{0};
- } m_receiverCalculatorSem;
- // std::mutex m_queueMtx;
+ QQueue<size_t> rawBufferIndices;
+ QSemaphore freeRawBuffers{BUFFER_COUNT};
+ QSemaphore usedRawBuffers{};
+
+ QQueue<size_t> rotatedBufferIndices;
+ QSemaphore freeRotatedBuffers{BUFFER_COUNT};
+ QSemaphore usedRotatedBuffers{};
+
+ // uint8_t bufferIdx{std::numeric_limits<decltype(bufferIdx)>::max()};
+ // std::binary_semaphore main2calc{0};
+ // std::binary_semaphore calc2main{0};
+ } m_sync;
+
std::mutex m_camMtx;
/*!
* \brief m_buffersQueue - queue of buffers which require extracting pixels
@@ -120,9 +137,11 @@ private:
std::queue<std::remove_const<decltype(BUFFER_COUNT)>> m_buffersQueue;
std::jthread m_streamThread;
- // std::jthread m_getThreads[1];
- std::jthread m_getThreads[4];
- std::jthread m_rotateThreads[1];
+ std::jthread m_getThreads[1];
+ // std::jthread m_getThreads[4];
+ // TODO: sync all loops somehow to guarantee frames order
+ std::jthread m_rotateThreads[2];
+ std::jthread m_calcPixelsThreads[1];
std::shared_ptr<veye::imx287m::i2c> m_i2c;
std::shared_ptr<HttpServer> m_httpServer;