// +-------------------------------- DISCLAIMER ---------------------------------+
// |                                                                             |
// | This program is provided to you free of charge "as such".                   |
// | You should not assume that this program is error-free or suitable for any   |
// | purpose whatsoever.                                                         |
// |                                                                             |
// | EURESYS does not give any representation, warranty or undertaking that this |
// | program is free of any defect or error or suitable for any purpose. EURESYS |
// | shall not be liable, in contract, in torts or otherwise, for any damages,   |
// | loss, costs, expenses or other claims for compensation, including those     |
// | asserted by third parties, arising out of or in connection with the use of  |
// | this program.                                                               |
// +-----------------------------------------------------------------------------+

#ifndef CAMERAHANDLER_H
#define CAMERAHANDLER_H

#include <condition_variable>
#include <thread>
#include <vector>
#include <memory>
#include <string>

namespace libcamera
{
  class Request;
  class Camera;
  class Stream;
  class CameraManager;
  class FrameBufferAllocator;
}

class CameraHandler
{
public:
  CameraHandler(const std::string& params = "");
  ~CameraHandler();
  void launchCamera();

  static std::vector<uint8_t> buffer_;
  static std::mutex processImageMutex_;
  static std::condition_variable canProcessImage_;

  uint8_t* data_;
  uint32_t width_;
  uint32_t height_;
  uint32_t pitch_;
  bool abort_;

private:
  static void requestComplete(libcamera::Request *request);

  libcamera::Stream* stream_;
  std::unique_ptr<libcamera::CameraManager> cameraManager_;
  libcamera::FrameBufferAllocator* allocator_;
  std::vector<std::unique_ptr<libcamera::Request>> requests_;
  static std::shared_ptr<libcamera::Camera> camera_;

  // make non-copyable
  CameraHandler( const CameraHandler& );
  CameraHandler& operator=( const CameraHandler& );
};

#endif // CAMERAHANDLER_H


