{"id":776,"url":"https://patchwork.libcamera.org/api/1.1/patches/776/?format=json","web_url":"https://patchwork.libcamera.org/patch/776/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20190320163055.22056-31-jacopo@jmondi.org>","date":"2019-03-20T16:30:54","name":"[libcamera-devel,v4,30/31] HACK: src: cam: Play with streams combinations","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"72874302fdcfa3bd04fdc83831c2b141ce7244c2","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/1.1/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/776/mbox/","series":[{"id":214,"url":"https://patchwork.libcamera.org/api/1.1/series/214/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=214","date":"2019-03-20T16:30:24","name":"libcamera: ipu3: Add ImgU support + multiple streams","version":4,"mbox":"https://patchwork.libcamera.org/series/214/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/776/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/776/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay12.mail.gandi.net (relay12.mail.gandi.net\n\t[217.70.178.232])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 01C82611A2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 20 Mar 2019 17:30:47 +0100 (CET)","from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay12.mail.gandi.net (Postfix) with ESMTPSA id 8DEB6200011;\n\tWed, 20 Mar 2019 16:30:46 +0000 (UTC)"],"From":"Jacopo Mondi <jacopo@jmondi.org>","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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 30/31] HACK: src: cam: Play with\n\tstreams combinations","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Wed, 20 Mar 2019 16:30:47 -0000"},"content":"Make the 'configureStreams()' method of the camera application accept a\nmap of stream configuration to be used to create and fill requests.\n\nThis allow to easily change which streams to capture from.\nwhile at there, hardcode the viewfinder output size to 640x480 to\ndemostrate the two output can have different resolutions.\n\nThis commit is clearly an hack and shall be removed once it is possible\nto specify per-stream configuration from the command line.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/cam/main.cpp | 48 ++++++++++++++++++++++++++++++++++++------------\n 1 file changed, 36 insertions(+), 12 deletions(-)","diff":"diff --git a/src/cam/main.cpp b/src/cam/main.cpp\nindex a2364ef92bad..28ea0b7d76b2 100644\n--- a/src/cam/main.cpp\n+++ b/src/cam/main.cpp\n@@ -75,26 +75,40 @@ static int parseOptions(int argc, char *argv[])\n \treturn 0;\n }\n \n-static int configureStreams(Camera *camera, std::set<Stream *> &streams)\n+static int configureStreams(Camera *camera, std::set<Stream *> &streams,\n+\t\t\t    std::map<Stream *, StreamConfiguration> &config)\n {\n \tKeyValueParser::Options format = options[OptFormat];\n-\tStream *id = *streams.begin();\n+\tauto it = streams.begin();\n+\tStream *output = *it;\n+\tStream *viewfinder = *(++it);\n \n-\tstd::map<Stream *, StreamConfiguration> config =\n+\tstd::map<Stream *, StreamConfiguration> defaultConfig =\n \t\tcamera->streamConfiguration(streams);\n \n \tif (options.isSet(OptFormat)) {\n \t\tif (format.isSet(\"width\"))\n-\t\t\tconfig[id].width = format[\"width\"];\n+\t\t\tdefaultConfig[output].width = format[\"width\"];\n \n \t\tif (format.isSet(\"height\"))\n-\t\t\tconfig[id].height = format[\"height\"];\n+\t\t\tdefaultConfig[output].height = format[\"height\"];\n \n \t\t/* TODO: Translate 4CC string to ID. */\n \t\tif (format.isSet(\"pixelformat\"))\n-\t\t\tconfig[id].pixelFormat = format[\"pixelformat\"];\n+\t\t\tdefaultConfig[output].pixelFormat = format[\"pixelformat\"];\n \t}\n \n+\t/* Configure the secondary output stream. */\n+\tdefaultConfig[viewfinder].width = 640;\n+\tdefaultConfig[viewfinder].height = 480;\n+\n+\t/*\n+\t * HACK: add output/viewfinder to 'config'\n+\t * to play with stream combinations.\n+\t */\n+\tconfig[output] = defaultConfig[output];\n+\tconfig[viewfinder] = defaultConfig[viewfinder];\n+\n \treturn camera->configureStreams(config);\n }\n \n@@ -145,17 +159,21 @@ static void requestComplete(Request *request,\n \n static int capture()\n {\n+\tstd::set<Stream *> cameraStreams = camera->streams();\n+\tstd::map<Stream *, StreamConfiguration> config;\n \tint ret;\n \n-\tstd::set<Stream *> streams = camera->streams();\n-\tstd::vector<Request *> requests;\n-\n-\tret = configureStreams(camera.get(), streams);\n+\tret = configureStreams(camera.get(), cameraStreams, config);\n \tif (ret < 0) {\n \t\tstd::cout << \"Failed to configure camera\" << std::endl;\n \t\treturn ret;\n \t}\n \n+\tif (config.empty()) {\n+\t\tstd::cout << \"Stream configuration is empty\" << std::endl;\n+\t\treturn ret;\n+\t}\n+\n \tret = camera->allocateBuffers();\n \tif (ret) {\n \t\tstd::cerr << \"Failed to allocate buffers\"\n@@ -163,13 +181,19 @@ static int capture()\n \t\treturn ret;\n \t}\n \n+\t/* Store only the active streams. */\n+\tstd::set<Stream *> activeStreams;\n+\tfor (const auto &iter : config)\n+\t\tactiveStreams.insert(iter.first);\n+\n \t/*\n \t * Create the requests to be later enqueued.\n \t *\n \t * FIXME: Assume all streams have the same number of buffers: use\n \t * the first stream's buffer pool and create on request per buffer.\n \t */\n-\tunsigned int bufferCount = (*streams.begin())->bufferPool().count();\n+\tstd::vector<Request *> requests;\n+\tunsigned int bufferCount = (*activeStreams.begin())->bufferPool().count();\n \tfor (unsigned int i = 0; i < bufferCount; ++i) {\n \t\tRequest *request = camera->createRequest();\n \t\tif (!request) {\n@@ -180,7 +204,7 @@ static int capture()\n \n \t\t/* Provide to each request a stream to buffer association map. */\n \t\tstd::map<Stream *, Buffer *> requestMap;\n-\t\tfor (Stream *stream : streams) {\n+\t\tfor (Stream *stream : activeStreams) {\n \t\t\tBuffer *buffer = &stream->bufferPool().buffers()[i];\n \t\t\trequestMap[stream] = buffer;\n \t\t}\n","prefixes":["libcamera-devel","v4","30/31"]}