From patchwork Wed Mar 20 16:30:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 776 Return-Path: Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 01C82611A2 for ; Wed, 20 Mar 2019 17:30:47 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id 8DEB6200011; Wed, 20 Mar 2019 16:30:46 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 20 Mar 2019 17:30:54 +0100 Message-Id: <20190320163055.22056-31-jacopo@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190320163055.22056-1-jacopo@jmondi.org> References: <20190320163055.22056-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 30/31] HACK: src: cam: Play with streams combinations 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: Wed, 20 Mar 2019 16:30:47 -0000 Make the 'configureStreams()' method of the camera application accept a map of stream configuration to be used to create and fill requests. This allow to easily change which streams to capture from. while at there, hardcode the viewfinder output size to 640x480 to demostrate the two output can have different resolutions. This commit is clearly an hack and shall be removed once it is possible to specify per-stream configuration from the command line. Signed-off-by: Jacopo Mondi --- src/cam/main.cpp | 48 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/src/cam/main.cpp b/src/cam/main.cpp index a2364ef92bad..28ea0b7d76b2 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -75,26 +75,40 @@ static int parseOptions(int argc, char *argv[]) return 0; } -static int configureStreams(Camera *camera, std::set &streams) +static int configureStreams(Camera *camera, std::set &streams, + std::map &config) { KeyValueParser::Options format = options[OptFormat]; - Stream *id = *streams.begin(); + auto it = streams.begin(); + Stream *output = *it; + Stream *viewfinder = *(++it); - std::map config = + std::map defaultConfig = camera->streamConfiguration(streams); if (options.isSet(OptFormat)) { if (format.isSet("width")) - config[id].width = format["width"]; + defaultConfig[output].width = format["width"]; if (format.isSet("height")) - config[id].height = format["height"]; + defaultConfig[output].height = format["height"]; /* TODO: Translate 4CC string to ID. */ if (format.isSet("pixelformat")) - config[id].pixelFormat = format["pixelformat"]; + defaultConfig[output].pixelFormat = format["pixelformat"]; } + /* Configure the secondary output stream. */ + defaultConfig[viewfinder].width = 640; + defaultConfig[viewfinder].height = 480; + + /* + * HACK: add output/viewfinder to 'config' + * to play with stream combinations. + */ + config[output] = defaultConfig[output]; + config[viewfinder] = defaultConfig[viewfinder]; + return camera->configureStreams(config); } @@ -145,17 +159,21 @@ static void requestComplete(Request *request, static int capture() { + std::set cameraStreams = camera->streams(); + std::map config; int ret; - std::set streams = camera->streams(); - std::vector requests; - - ret = configureStreams(camera.get(), streams); + ret = configureStreams(camera.get(), cameraStreams, config); if (ret < 0) { std::cout << "Failed to configure camera" << std::endl; return ret; } + if (config.empty()) { + std::cout << "Stream configuration is empty" << std::endl; + return ret; + } + ret = camera->allocateBuffers(); if (ret) { std::cerr << "Failed to allocate buffers" @@ -163,13 +181,19 @@ static int capture() return ret; } + /* Store only the active streams. */ + std::set activeStreams; + for (const auto &iter : config) + activeStreams.insert(iter.first); + /* * Create the requests to be later enqueued. * * FIXME: Assume all streams have the same number of buffers: use * the first stream's buffer pool and create on request per buffer. */ - unsigned int bufferCount = (*streams.begin())->bufferPool().count(); + std::vector requests; + unsigned int bufferCount = (*activeStreams.begin())->bufferPool().count(); for (unsigned int i = 0; i < bufferCount; ++i) { Request *request = camera->createRequest(); if (!request) { @@ -180,7 +204,7 @@ static int capture() /* Provide to each request a stream to buffer association map. */ std::map requestMap; - for (Stream *stream : streams) { + for (Stream *stream : activeStreams) { Buffer *buffer = &stream->bufferPool().buffers()[i]; requestMap[stream] = buffer; }