From 75de3bff9e165e512be5f53e19f31c7388dc08b1 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 29 Apr 2019 20:58:34 +0300 Subject: libcamera: camera: Return a pointer from generateConfiguration() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To prepare for specialising the CameraConfiguration class in pipeline handlers, return a pointer to a camera configuration instead of a reference from Camera::generateConfiguration(). The camera configuration always needs to be allocated from the pipeline handler, and its ownership is passed to the application. For symmetry, change Camera::configure() to take a CameraConfiguration pointer instead of a reference. This aligns with our coding practice of passing parameters that are modified by the callee by pointer. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- src/cam/main.cpp | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) (limited to 'src/cam') diff --git a/src/cam/main.cpp b/src/cam/main.cpp index cd165bea..535c2420 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -85,15 +85,13 @@ static int parseOptions(int argc, char *argv[]) return 0; } -static int prepareCameraConfig(CameraConfiguration *config) +static std::unique_ptr prepareCameraConfig() { StreamRoles roles; /* If no configuration is provided assume a single video stream. */ - if (!options.isSet(OptStream)) { - *config = camera->generateConfiguration({ StreamRole::VideoRecording }); - return 0; - } + if (!options.isSet(OptStream)) + return camera->generateConfiguration({ StreamRole::VideoRecording }); const std::vector &streamOptions = options[OptStream].toArray(); @@ -113,23 +111,22 @@ static int prepareCameraConfig(CameraConfiguration *config) } else { std::cerr << "Unknown stream role " << conf["role"].toString() << std::endl; - return -EINVAL; + return nullptr; } } - *config = camera->generateConfiguration(roles); - - if (!config->isValid()) { + std::unique_ptr config = camera->generateConfiguration(roles); + if (!config || !config->isValid()) { std::cerr << "Failed to get default stream configuration" << std::endl; - return -EINVAL; + return nullptr; } /* Apply configuration explicitly requested. */ unsigned int i = 0; for (auto const &value : streamOptions) { KeyValueParser::Options conf = value.toKeyValues(); - StreamConfiguration &cfg = (*config)[i++]; + StreamConfiguration &cfg = config->at(i++); if (conf.isSet("width")) cfg.size.width = conf["width"]; @@ -142,7 +139,7 @@ static int prepareCameraConfig(CameraConfiguration *config) cfg.pixelFormat = conf["pixelformat"]; } - return 0; + return config; } static void requestComplete(Request *request, const std::map &buffers) @@ -191,16 +188,15 @@ static void requestComplete(Request *request, const std::map static int capture() { - CameraConfiguration config; int ret; - ret = prepareCameraConfig(&config); - if (ret) { + std::unique_ptr config = prepareCameraConfig(); + if (!config) { std::cout << "Failed to prepare camera configuration" << std::endl; - return ret; + return -EINVAL; } - ret = camera->configure(config); + ret = camera->configure(config.get()); if (ret < 0) { std::cout << "Failed to configure camera" << std::endl; return ret; @@ -208,8 +204,8 @@ static int capture() streamInfo.clear(); - for (unsigned int index = 0; index < config.size(); ++index) { - StreamConfiguration &cfg = config[index]; + for (unsigned int index = 0; index < config->size(); ++index) { + StreamConfiguration &cfg = config->at(index); streamInfo[cfg.stream()] = "stream" + std::to_string(index); } @@ -224,7 +220,7 @@ static int capture() /* Identify the stream with the least number of buffers. */ unsigned int nbuffers = UINT_MAX; - for (StreamConfiguration &cfg : config) { + for (StreamConfiguration &cfg : *config) { Stream *stream = cfg.stream(); nbuffers = std::min(nbuffers, stream->bufferPool().count()); } @@ -244,7 +240,7 @@ static int capture() } std::map map; - for (StreamConfiguration &cfg : config) { + for (StreamConfiguration &cfg : *config) { Stream *stream = cfg.stream(); map[stream] = &stream->bufferPool().buffers()[i]; } -- cgit v1.2.1