From fe1a89dbd83e10bfb480962a511fa0f43885eb77 Mon Sep 17 00:00:00 2001 From: Nikita Kostovsky Date: Sat, 22 Nov 2025 21:59:31 +0100 Subject: introduce calc pixels thread; rotation still requires 2 threads --- src/camera/veyeimx287m.h | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) (limited to 'src/camera/veyeimx287m.h') 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 #include #include #include +// qt +#include #include #include +// 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 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{std::make_shared()}; }; @@ -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::max()}; - std::binary_semaphore main2calc{0}; - std::binary_semaphore calc2main{0}; - } m_receiverCalculatorSem; - // std::mutex m_queueMtx; + QQueue rawBufferIndices; + QSemaphore freeRawBuffers{BUFFER_COUNT}; + QSemaphore usedRawBuffers{}; + + QQueue rotatedBufferIndices; + QSemaphore freeRotatedBuffers{BUFFER_COUNT}; + QSemaphore usedRotatedBuffers{}; + + // uint8_t bufferIdx{std::numeric_limits::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> 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 m_i2c; std::shared_ptr m_httpServer; -- cgit v1.2.3-70-g09d2