#pragma once #include #include #include #include #include #include #include "constants.h" #include "image.h" #include "icamera.h" namespace veye { namespace imx287m { class i2c; } // namespace imx287m } // namespace veye class HttpServer; class VeyeIMX287m : public ICamera { constexpr static char videoDevice[] = "/dev/video0"; public: using buffer_t = std::array; public: VeyeIMX287m(); ~VeyeIMX287m() override; public: static std::vector> search(); public: bool startStream() override; bool dequeueImageBuffer(size_t &image); // bool getImage(Image &image); bool getImage(Image *image) override; std::shared_ptr getImage() override; bool init(); // parameters public: bool set_autoExposure(const bool enable) override; std::optional get_autoExposure() override; bool set_autoGain(const bool enable) override; std::optional get_autoGain() override; bool set_exposureTime(const std::chrono::microseconds us) override; std::optional get_exposureTime() override; bool set_gain(const float value) override; std::optional get_gain() override; public: /*! * \brief processedCounter - count of images processed in current second. * Used for performance measurement and bottlenecks analysing */ uint32_t processedCounter{0}; private: bool openCam(); bool initCam(); bool initI2C(); // bool initHttpServer(); void getFrameLoop(std::stop_token stopToken); void rotateFrameLoop(std::stop_token stopToken); private: /*! * \brief m_cam_fd - camera file descriptor */ int m_cam_fd{-1}; /*! * \brief m_previousFrameCounter - used to detect dropped frames */ std::optional m_previousFrameCounter{}; static constexpr uint8_t BUFFER_COUNT{16}; // std::array m_images; /*! * \brief m_imageMutexes - lock while processing image from m_images */ std::array m_imageMutexes; struct buffer { unsigned int padding{0}; unsigned int size{0}; void *mem{nullptr}; std::shared_ptr image{std::make_shared()}; }; std::vector m_buffers; struct Semaphore { 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; std::mutex m_camMtx; /*! * \brief m_buffersQueue - queue of buffers which require extracting pixels */ std::queue> m_buffersQueue; std::jthread m_streamThread; // std::jthread m_getThreads[1]; std::jthread m_getThreads[4]; std::jthread m_rotateThreads[1]; std::shared_ptr m_i2c; std::shared_ptr m_httpServer; };