From 053237b9c91f1b5892782c1c4b2eb50cc8aeadfd Mon Sep 17 00:00:00 2001 From: Nikita Kostovsky Date: Sat, 9 Nov 2024 17:26:11 +0100 Subject: Initial commit --- LibCamera.h | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 LibCamera.h (limited to 'LibCamera.h') diff --git a/LibCamera.h b/LibCamera.h new file mode 100644 index 0000000..2262ab2 --- /dev/null +++ b/LibCamera.h @@ -0,0 +1,86 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace libcamera; + +typedef struct { + uint8_t *imageData; + uint32_t size; + uint64_t request; +} LibcameraOutData; + +class LibCamera { + public: + LibCamera(){}; + ~LibCamera(){}; + + int initCamera(); + void configureStill(int width, int height, PixelFormat format, int buffercount, int rotation); + int startCamera(); + int resetCamera(int width, int height, PixelFormat format, int buffercount, int rotation); + bool readFrame(LibcameraOutData *frameData); + void returnFrameBuffer(LibcameraOutData frameData); + + void set(ControlList controls); + void stopCamera(); + void closeCamera(); + + Stream *VideoStream(uint32_t *w, uint32_t *h, uint32_t *stride) const; + char * getCameraId(); + + private: + int startCapture(); + int queueRequest(Request *request); + void requestComplete(Request *request); + void processRequest(Request *request); + + void StreamDimensions(Stream const *stream, uint32_t *w, uint32_t *h, uint32_t *stride) const; + + unsigned int cameraIndex_; + uint64_t last_; + std::unique_ptr cm; + std::shared_ptr camera_; + bool camera_acquired_ = false; + bool camera_started_ = false; + std::unique_ptr config_; + std::unique_ptr allocator_; + std::vector> requests_; + // std::map stream_; + std::map> mappedBuffers_; + + std::queue requestQueue; + + ControlList controls_; + std::mutex control_mutex_; + std::mutex camera_stop_mutex_; + std::mutex free_requests_mutex_; + + Stream *viewfinder_stream_ = nullptr; + std::string cameraId; +}; \ No newline at end of file -- cgit v1.2.3-70-g09d2