Files
external_libcamera/include/libcamera/camera.h
Niklas Söderlund 77100a7578 libcamera: camera: add state machine to control access from applications
There is a need to better control the order of operations an application
performs on a camera for it to function correctly. Add a basic state
machine to ensure applications perform operations on the camera in good
order.

Internal to the Camera states are added; Available, Acquired,
Configured, Prepared and Running. Each state represents a higher state
of configuration of the camera ultimately leading to the highest state
where the camera is capturing frames. Each state supports a subset of
operations the application may perform.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-03-01 00:28:17 +01:00

88 lines
1.7 KiB
C++

/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2018, Google Inc.
*
* camera.h - Camera object interface
*/
#ifndef __LIBCAMERA_CAMERA_H__
#define __LIBCAMERA_CAMERA_H__
#include <map>
#include <memory>
#include <set>
#include <string>
#include <libcamera/request.h>
#include <libcamera/signal.h>
namespace libcamera {
class Buffer;
class PipelineHandler;
class Request;
class Stream;
class StreamConfiguration;
class Camera final
{
public:
static std::shared_ptr<Camera> create(PipelineHandler *pipe,
const std::string &name,
const std::set<Stream *> &streams);
Camera(const Camera &) = delete;
Camera &operator=(const Camera &) = delete;
const std::string &name() const;
Signal<Request *, const std::map<Stream *, Buffer *> &> requestCompleted;
Signal<Camera *> disconnected;
int acquire();
int release();
const std::set<Stream *> &streams() const;
std::map<Stream *, StreamConfiguration>
streamConfiguration(std::set<Stream *> &streams);
int configureStreams(std::map<Stream *, StreamConfiguration> &config);
int allocateBuffers();
int freeBuffers();
Request *createRequest();
int queueRequest(Request *request);
int start();
int stop();
private:
enum State {
CameraAvailable,
CameraAcquired,
CameraConfigured,
CameraPrepared,
CameraRunning,
};
Camera(PipelineHandler *pipe, const std::string &name);
~Camera();
bool stateBetween(State low, State high) const;
bool stateIs(State state) const;
friend class PipelineHandler;
void disconnect();
std::shared_ptr<PipelineHandler> pipe_;
std::string name_;
std::set<Stream *> streams_;
std::set<Stream *> activeStreams_;
bool disconnected_;
State state_;
};
} /* namespace libcamera */
#endif /* __LIBCAMERA_CAMERA_H__ */