From 77ae64eb24bf6c2fe241b6f7b841315b1ee15707 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 29 Apr 2019 15:15:23 +0300 Subject: libcamera: Refactor the camera configuration storage and API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactor the CameraConfiguration structure to not rely on Stream instances. This is a step towards making the camera configuration object more powerful with configuration validation using "try" semantics. The CameraConfiguration now exposes a simple vector-like API to access the contained stream configurations. Both operator[]() and at() are provided to access elements. The isEmpty() method is renamed to empty() and the methods reordered to match the std::vector class. As applications need access to the Stream instances associated with the configuration entries in order to associate buffers with streams when creating requests, expose the stream selected by the pipeline handler through a new StreamConfiguration::stream(). Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- src/cam/main.cpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'src/cam') diff --git a/src/cam/main.cpp b/src/cam/main.cpp index d603228c..cd165bea 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -89,12 +89,9 @@ static int prepareCameraConfig(CameraConfiguration *config) { StreamRoles roles; - streamInfo.clear(); - /* If no configuration is provided assume a single video stream. */ if (!options.isSet(OptStream)) { *config = camera->generateConfiguration({ StreamRole::VideoRecording }); - streamInfo[config->front()] = "stream0"; return 0; } @@ -129,27 +126,20 @@ static int prepareCameraConfig(CameraConfiguration *config) } /* Apply configuration explicitly requested. */ - CameraConfiguration::iterator it = config->begin(); + unsigned int i = 0; for (auto const &value : streamOptions) { KeyValueParser::Options conf = value.toKeyValues(); - Stream *stream = *it; - it++; + StreamConfiguration &cfg = (*config)[i++]; if (conf.isSet("width")) - (*config)[stream].size.width = conf["width"]; + cfg.size.width = conf["width"]; if (conf.isSet("height")) - (*config)[stream].size.height = conf["height"]; + cfg.size.height = conf["height"]; /* TODO: Translate 4CC string to ID. */ if (conf.isSet("pixelformat")) - (*config)[stream].pixelFormat = conf["pixelformat"]; - } - - unsigned int index = 0; - for (Stream *stream : *config) { - streamInfo[stream] = "stream" + std::to_string(index); - index++; + cfg.pixelFormat = conf["pixelformat"]; } return 0; @@ -216,6 +206,13 @@ static int capture() return ret; } + streamInfo.clear(); + + for (unsigned int index = 0; index < config.size(); ++index) { + StreamConfiguration &cfg = config[index]; + streamInfo[cfg.stream()] = "stream" + std::to_string(index); + } + ret = camera->allocateBuffers(); if (ret) { std::cerr << "Failed to allocate buffers" @@ -227,8 +224,10 @@ static int capture() /* Identify the stream with the least number of buffers. */ unsigned int nbuffers = UINT_MAX; - for (Stream *stream : config) + for (StreamConfiguration &cfg : config) { + Stream *stream = cfg.stream(); nbuffers = std::min(nbuffers, stream->bufferPool().count()); + } /* * TODO: make cam tool smarter to support still capture by for @@ -245,8 +244,10 @@ static int capture() } std::map map; - for (Stream *stream : config) + for (StreamConfiguration &cfg : config) { + Stream *stream = cfg.stream(); map[stream] = &stream->bufferPool().buffers()[i]; + } ret = request->setBuffers(map); if (ret < 0) { -- cgit v1.2.1