android: camera_device: Maintain a vector of CameraStream

Introduce a vector storing a CameraStream to track and maintain
state between an Android stream (camera3_stream_t) and a libcamera
Stream.

Only the index of the libcamera stream is stored, to facilitate identifying
the correct index for both the StreamConfiguration and Stream vectors.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
Kieran Bingham 2020-07-01 16:42:13 +01:00
parent eac0542c5e
commit 2f34f5ef06
2 changed files with 29 additions and 2 deletions

View file

@ -952,6 +952,20 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
return -EINVAL; return -EINVAL;
} }
/*
* Clear and remove any existing configuration from previous calls, and
* ensure the required entries are available without further
* re-allcoation.
*/
streams_.clear();
streams_.reserve(stream_list->num_streams);
/*
* Track actually created streams, as there may not be a 1:1 mapping of
* camera3 streams to libcamera streams.
*/
unsigned int streamIndex = 0;
for (unsigned int i = 0; i < stream_list->num_streams; ++i) { for (unsigned int i = 0; i < stream_list->num_streams; ++i) {
camera3_stream_t *stream = stream_list->streams[i]; camera3_stream_t *stream = stream_list->streams[i];
@ -974,6 +988,8 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
streamConfiguration.pixelFormat = format; streamConfiguration.pixelFormat = format;
config_->addConfiguration(streamConfiguration); config_->addConfiguration(streamConfiguration);
streams_[i].index = streamIndex++;
} }
switch (config_->validate()) { switch (config_->validate()) {
@ -991,10 +1007,11 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
for (unsigned int i = 0; i < stream_list->num_streams; ++i) { for (unsigned int i = 0; i < stream_list->num_streams; ++i) {
camera3_stream_t *stream = stream_list->streams[i]; camera3_stream_t *stream = stream_list->streams[i];
StreamConfiguration &streamConfiguration = config_->at(i); CameraStream *cameraStream = &streams_[i];
StreamConfiguration &cfg = config_->at(cameraStream->index);
/* Use the bufferCount confirmed by the validation process. */ /* Use the bufferCount confirmed by the validation process. */
stream->max_buffers = streamConfiguration.bufferCount; stream->max_buffers = cfg.bufferCount;
} }
/* /*

View file

@ -25,6 +25,15 @@
class CameraMetadata; class CameraMetadata;
struct CameraStream {
/*
* The index of the libcamera StreamConfiguration as added during
* configureStreams(). A single libcamera Stream may be used to deliver
* one or more streams to the Android framework.
*/
unsigned int index;
};
class CameraDevice : protected libcamera::Loggable class CameraDevice : protected libcamera::Loggable
{ {
public: public:
@ -90,6 +99,7 @@ private:
std::vector<Camera3StreamConfiguration> streamConfigurations_; std::vector<Camera3StreamConfiguration> streamConfigurations_;
std::map<int, libcamera::PixelFormat> formatsMap_; std::map<int, libcamera::PixelFormat> formatsMap_;
std::vector<CameraStream> streams_;
int facing_; int facing_;
int orientation_; int orientation_;