#pragma once #include #include #include #include #include "constants.h" #include "image.h" #include "icamera.h" 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 init(); bool setExposureTime(const std::chrono::microseconds us); bool setExposureTimeUs(int value) override; bool setGain(int value) override; bool setLaserLevel(int value) override; bool setSomething(int value) override; bool dequeueImageBuffer(size_t &image); bool getImage(Image &image); public: /*! * \brief processedCounter - count of images processed in current second. * Used for performance measurement and bottlenecks analysing */ uint32_t processedCounter{0}; private: bool setCamParam(unsigned int v4l2controlId, int value); bool openCam(); bool selectCam(int camIdx = 0); bool initCam(); bool initHttpServer(); void calcFrameLoop(std::stop_token stopToken); private: /*! * \brief m_cam_fd - camera file descriptor */ int m_cam_fd{-1}; 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; /*! * \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 m_videoBuffers; struct buffer { unsigned int idx; unsigned int padding[VIDEO_MAX_PLANES]; unsigned int size[VIDEO_MAX_PLANES]; void *mem[VIDEO_MAX_PLANES]; }; std::vector buffers; // std::mutex m_queueMtx; std::mutex m_camMtx; std::queue m_buffersQueue; std::jthread m_streamThread; // std::jthread m_calcThreads[1]; std::jthread m_calcThreads[4]; std::shared_ptr m_httpServer; };