diff options
| author | Nikita Kostovsky <nikita@kostovsky.me> | 2025-11-22 14:09:50 +0100 |
|---|---|---|
| committer | Nikita Kostovsky <nikita@kostovsky.me> | 2025-11-22 14:09:50 +0100 |
| commit | 6aecc111a48ccc316a923e92b4b41424847be297 (patch) | |
| tree | 18e6b96829d4f65aee0f51ceb803ed1a0f23bc04 /src/camera/veyeimx287m.h | |
| parent | 0d91425d3b10249aa3942d3151daf0a1e41e7b22 (diff) | |
get rid of video buffers; refactor; add garbage code
Diffstat (limited to 'src/camera/veyeimx287m.h')
| -rw-r--r-- | src/camera/veyeimx287m.h | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/src/camera/veyeimx287m.h b/src/camera/veyeimx287m.h index 7946d2f..ab7e3e5 100644 --- a/src/camera/veyeimx287m.h +++ b/src/camera/veyeimx287m.h @@ -6,6 +6,7 @@ #include <thread> #include <QReadWriteLock> +#include <QSemaphore> #include "constants.h" #include "image.h" @@ -40,6 +41,7 @@ public: bool dequeueImageBuffer(size_t &image); // bool getImage(Image &image); bool getImage(Image *image) override; + std::shared_ptr<Image> getImage() override; bool init(); @@ -71,7 +73,8 @@ private: bool initI2C(); // bool initHttpServer(); - void calcFrameLoop(std::stop_token stopToken); + void getFrameLoop(std::stop_token stopToken); + void rotateFrameLoop(std::stop_token stopToken); private: /*! @@ -79,42 +82,47 @@ private: */ int m_cam_fd{-1}; - static constexpr uint8_t BUFFER_COUNT{16}; + /*! + * \brief m_previousFrameCounter - used to detect dropped frames + */ + std::optional<int64_t> m_previousFrameCounter{}; - struct MA - { - QReadWriteLock rwLock; - Image image; - } bbbbb[BUFFER_COUNT]; + static constexpr uint8_t BUFFER_COUNT{16}; - std::array<Image, BUFFER_COUNT> m_images; + // std::array<Image, BUFFER_COUNT> m_images; /*! * \brief m_imageMutexes - lock while processing image from m_images */ std::array<std::mutex, BUFFER_COUNT> m_imageMutexes; - /*! - * \todo copy image right after dequeue to avoid situation with ioctl writing - * to m_videoBuffers[i] which is being copied to m_images[i]. In theory, it - * should not overlap if BUFFER_COUNT > theads count - */ - std::array<uint8_t *, BUFFER_COUNT> m_videoBuffers{0}; struct buffer { - unsigned int padding[VIDEO_MAX_PLANES]{std::numeric_limits<unsigned int>::max()}; - unsigned int size[VIDEO_MAX_PLANES]{std::numeric_limits<unsigned int>::max()}; - // void *mem[VIDEO_MAX_PLANES]{nullptr}; + unsigned int padding{0}; + unsigned int size{0}; void *mem{nullptr}; + std::shared_ptr<Image> image{std::make_shared<Image>()}; }; std::vector<buffer> m_buffers; + struct Semaphore + { + 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; std::mutex m_camMtx; - std::queue<size_t> m_buffersQueue; + /*! + * \brief m_buffersQueue - queue of buffers which require extracting pixels + */ + std::queue<std::remove_const<decltype(BUFFER_COUNT)>> m_buffersQueue; std::jthread m_streamThread; - // std::jthread m_calcThreads[1]; - std::jthread m_calcThreads[4]; + // std::jthread m_getThreads[1]; + std::jthread m_getThreads[4]; + std::jthread m_rotateThreads[1]; std::shared_ptr<veye::imx287m::i2c> m_i2c; std::shared_ptr<HttpServer> m_httpServer; |
