#pragma once // c/cpp #include #include #include #include // qt #include #include #include // orpheus #include "constants.h" #include "icamera.h" #include "image.h" #include "utils/sem_queue.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: [[nodiscard]] static std::vector> search(); public: [[nodiscard]] bool startStream() override; [[nodiscard]] bool dequeueImageBuffer(size_t &image); // bool getImage(Image &image); // [[nodiscard]] bool getImage(Image *image) override; [[nodiscard]] Image *getImage() override; // [[nodiscard]] std::shared_ptr getImage() override; bool init(); // parameters public: [[nodiscard]] bool set_autoExposure(const bool enable) override; [[nodiscard]] std::optional get_autoExposure() override; [[nodiscard]] bool set_autoGain(const bool enable) override; [[nodiscard]] std::optional get_autoGain() override; [[nodiscard]] bool set_exposureTime(const std::chrono::microseconds us) override; [[nodiscard]] std::optional get_exposureTime() override; [[nodiscard]] bool set_gain(const float value) override; [[nodiscard]] std::optional get_gain() override; public: /*! * \brief processedCounter - count of images processed in current second. * Used for performance measurement and bottlenecks analysis */ uint32_t processedCounter{0}; private: [[nodiscard]] bool openCam(); [[nodiscard]] bool initCam(); [[nodiscard]] bool initI2C(); /*! * \brief getFramesLoop - get frames from camera and manage futher processing * \note to be started in a soparate thread * \param stopToken - asks to break the loop */ void getFramesLoop(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}; /*! * \brief m_imageMutexes - lock while processing image from m_images */ std::array m_imageMutexes; struct buffer { void *mem{nullptr}; }; std::vector m_rawBuffers; std::array m_images; // std::optional> m_lastImageIdx; std::optional m_lastImageIdx; std::mutex m_camMtx; std::jthread m_streamThread; std::jthread m_getThreads[1]; std::shared_ptr m_lastProcessedImage{}; std::shared_ptr m_i2c; std::shared_ptr m_httpServer; };