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>
This commit is contained in:
Niklas Söderlund 2019-02-26 01:37:53 +01:00
parent 132ce9c1cf
commit 77100a7578
2 changed files with 241 additions and 46 deletions

View file

@ -39,7 +39,7 @@ public:
Signal<Camera *> disconnected;
int acquire();
void release();
int release();
const std::set<Stream *> &streams() const;
std::map<Stream *, StreamConfiguration>
@ -47,7 +47,7 @@ public:
int configureStreams(std::map<Stream *, StreamConfiguration> &config);
int allocateBuffers();
void freeBuffers();
int freeBuffers();
Request *createRequest();
int queueRequest(Request *request);
@ -56,20 +56,30 @@ public:
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();
int exclusiveAccess();
std::shared_ptr<PipelineHandler> pipe_;
std::string name_;
std::set<Stream *> streams_;
std::set<Stream *> activeStreams_;
bool acquired_;
bool disconnected_;
State state_;
};
} /* namespace libcamera */