From patchwork Tue Apr 2 00:53:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 833 Return-Path: Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E66D76110A for ; Tue, 2 Apr 2019 02:54:00 +0200 (CEST) X-Halon-ID: cc5ff4f2-54e1-11e9-846a-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id cc5ff4f2-54e1-11e9-846a-005056917a89; Tue, 02 Apr 2019 02:53:58 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 2 Apr 2019 02:53:28 +0200 Message-Id: <20190402005332.25018-2-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190402005332.25018-1-niklas.soderlund@ragnatech.se> References: <20190402005332.25018-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 1/5] cam: Rework how streams configuration is prepared X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Apr 2019 00:54:01 -0000 In preparation of reworking how a default configuration is retrieved from a camera separate preparation of stream configuration and applying of it into to different functions. Reason for this is that preparation of camera configuration will become more complex. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/cam/main.cpp | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/cam/main.cpp b/src/cam/main.cpp index e7490c32f99a01ad..cc5302ca4e72ea6f 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -78,27 +78,27 @@ static int parseOptions(int argc, char *argv[]) return 0; } -static int configureStreams(Camera *camera, std::set &streams) +static int prepare_camera_config(std::map *config) { - KeyValueParser::Options format = options[OptFormat]; - Stream *id = *streams.begin(); - - std::map config = - camera->streamConfiguration(streams); + std::set streams = camera->streams(); + *config = camera->streamConfiguration(streams); + Stream *stream = config->begin()->first; if (options.isSet(OptFormat)) { + KeyValueParser::Options format = options[OptFormat]; + if (format.isSet("width")) - config[id].width = format["width"]; + (*config)[stream].width = format["width"]; if (format.isSet("height")) - config[id].height = format["height"]; + (*config)[stream].height = format["height"]; /* TODO: Translate 4CC string to ID. */ if (format.isSet("pixelformat")) - config[id].pixelFormat = format["pixelformat"]; + (*config)[stream].pixelFormat = format["pixelformat"]; } - return camera->configureStreams(config); + return 0; } static void requestComplete(Request *request, const std::map &buffers) @@ -136,18 +136,23 @@ static void requestComplete(Request *request, const std::map static int capture() { - int ret; - - std::set streams = camera->streams(); + std::map config; std::vector requests; + int ret; - ret = configureStreams(camera.get(), streams); + ret = prepare_camera_config(&config); + if (ret) { + std::cout << "Failed to prepare camera configuration" << std::endl; + return ret; + } + + ret = camera->configureStreams(config); if (ret < 0) { std::cout << "Failed to configure camera" << std::endl; return ret; } - Stream *stream = *streams.begin(); + Stream *stream = config.begin()->first; ret = camera->allocateBuffers(); if (ret) {