[{"id":1238,"web_url":"https://patchwork.libcamera.org/comment/1238/","msgid":"<453c51bc-6162-d889-8bdc-87c101fabcac@ideasonboard.com>","date":"2019-04-03T05:28:32","subject":"Re: [libcamera-devel] [PATCH v2 2/4] cam: Add support to specify\n\tmultiple stream configurations with roles","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Niklas,\n\nOn 03/04/2019 02:12, Niklas Söderlund wrote:\n> Extend the cam tool to allow configuring more than one stream. Add an\n> optional parameter to the --stream option to specify a usage role for\n> the stream. The stream role is passed to libcamera to give it control\n> over which streams to use.\n> \n> To support multiple streams, creation of requests needs to be reworked\n> to limit the number of requests to match the stream with the least\n> number of buffers. This should be improved in the future as the tool and\n> the library evolve.\n> \n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  src/cam/main.cpp | 78 ++++++++++++++++++++++++++++++++++++++++--------\n>  1 file changed, 66 insertions(+), 12 deletions(-)\n> \n> diff --git a/src/cam/main.cpp b/src/cam/main.cpp\n> index 6bf5e5926704d6e9..b47bda21cbb7f220 100644\n> --- a/src/cam/main.cpp\n> +++ b/src/cam/main.cpp\n> @@ -5,8 +5,10 @@\n>   * main.cpp - cam - The libcamera swiss army knife\n>   */\n>  \n> +#include <algorithm>\n>  #include <iomanip>\n>  #include <iostream>\n> +#include <limits.h>\n>  #include <map>\n>  #include <signal.h>\n>  #include <string.h>\n> @@ -42,6 +44,9 @@ void signalHandler(int signal)\n>  static int parseOptions(int argc, char *argv[])\n>  {\n>  \tKeyValueParser streamKeyValue;\n> +\tstreamKeyValue.addOption(\"role\", OptionString,\n> +\t\t\t\t \"Role for the stream (viewfinder, video, still)\",\n> +\t\t\t\t ArgumentRequired);\n>  \tstreamKeyValue.addOption(\"width\", OptionInteger, \"Width in pixels\",\n>  \t\t\t\t ArgumentRequired);\n>  \tstreamKeyValue.addOption(\"height\", OptionInteger, \"Height in pixels\",\n> @@ -61,7 +66,7 @@ static int parseOptions(int argc, char *argv[])\n>  \t\t\t \"The default file name is 'frame-#.bin'.\",\n>  \t\t\t \"file\", ArgumentOptional, \"filename\");\n>  \tparser.addOption(OptStream, &streamKeyValue,\n> -\t\t\t \"Set configuration of a camera stream\", \"stream\");\n> +\t\t\t \"Set configuration of a camera stream\", \"stream\", true);\n>  \tparser.addOption(OptHelp, OptionNone, \"Display this help message\",\n>  \t\t\t \"help\");\n>  \tparser.addOption(OptList, OptionNone, \"List all cameras\", \"list\");\n> @@ -80,12 +85,51 @@ static int parseOptions(int argc, char *argv[])\n>  \n>  static int prepareCameraConfig(std::map<Stream *, StreamConfiguration> *config)\n>  {\n> -\tstd::set<Stream *> streams = camera->streams();\n> -\t*config = camera->streamConfiguration({ Stream::VideoRecording() });\n> -\tStream *stream = config->begin()->first;\n> +\tstd::vector<StreamRole> roles;\n>  \n> -\tif (options.isSet(OptStream)) {\n> -\t\tKeyValueParser::Options conf = options[OptStream];\n> +\t/* If no configuration is provided assume a single video stream. */\n> +\tif (!options.isSet(OptStream)) {\n> +\t\t*config = camera->streamConfiguration({ Stream::VideoRecording() });\n> +\t\treturn 0;\n> +\t}\n> +\n> +\tconst std::vector<OptionValue> &streamopts =\n> +\t\toptions[OptStream].toArray();\n> +\n> +\t/* Use roles and get a default configuration. */\n> +\tfor (auto const &value : streamopts) {\n> +\t\tKeyValueParser::Options conf = value.toKeyValues();\n> +\n> +\t\tif (!conf.isSet(\"role\")) {\n> +\t\t\troles.push_back(Stream::VideoRecording());\n> +\t\t} else if (conf[\"role\"].toString() == \"viewfinder\") {\n> +\t\t\troles.push_back(Stream::Viewfinder(conf[\"width\"],\n> +\t\t\t\t\t\t\t   conf[\"height\"]));\n> +\t\t} else if (conf[\"role\"].toString() == \"video\") {\n> +\t\t\troles.push_back(Stream::VideoRecording());\n> +\t\t} else if (conf[\"role\"].toString() == \"still\") {\n> +\t\t\troles.push_back(Stream::StillCapture());\n> +\t\t} else {\n> +\t\t\tstd::cerr << \"Unknown stream role \"\n> +\t\t\t\t  << conf[\"role\"].toString() << std::endl;\n> +\t\t\treturn -EINVAL;\n> +\t\t}\n> +\t}\n> +\n> +\t*config = camera->streamConfiguration(roles);\n> +\n> +\tif (config->size() != streamopts.size()) {\n> +\t\tstd::cerr << \"Failed to get default stream configuration\"\n> +\t\t\t  << std::endl;\n> +\t\treturn -EINVAL;\n> +\t}\n> +\n> +\t/* Apply configuration explicitly requested. */\n> +\tstd::map<Stream *, StreamConfiguration>::iterator it = config->begin();\n> +\tfor (auto const &value : streamopts) {\n> +\t\tKeyValueParser::Options conf = value.toKeyValues();\n> +\t\tStream *stream = it->first;\n> +\t\tit++;\n>  \n>  \t\tif (conf.isSet(\"width\"))\n>  \t\t\t(*config)[stream].width = conf[\"width\"];\n> @@ -137,7 +181,6 @@ static void requestComplete(Request *request, const std::map<Stream *, Buffer *>\n>  static int capture()\n>  {\n>  \tstd::map<Stream *, StreamConfiguration> config;\n> -\tstd::vector<Request *> requests;\n>  \tint ret;\n>  \n>  \tret = prepareCameraConfig(&config);\n> @@ -152,8 +195,6 @@ static int capture()\n>  \t\treturn ret;\n>  \t}\n>  \n> -\tStream *stream = config.begin()->first;\n> -\n>  \tret = camera->allocateBuffers();\n>  \tif (ret) {\n>  \t\tstd::cerr << \"Failed to allocate buffers\"\n> @@ -163,9 +204,18 @@ static int capture()\n>  \n>  \tcamera->requestCompleted.connect(requestComplete);\n>  \n> -\tBufferPool &pool = stream->bufferPool();\n> +\t/* Figure out which stream s the lower number of buffers. */\n\n/s/has/ ?\n\nPerhaps:\n /* Identify the stream with the least number of buffers. */\n\n\n> +\tunsigned int nbuffers = UINT_MAX;\n> +\tfor (auto const &it : config)\n> +\t\tnbuffers = std::min(nbuffers, it.first->bufferPool().count());\n>  \n> -\tfor (Buffer &buffer : pool.buffers()) {\n> +\t/*\n> +\t * TODO: make cam tool smarter to support still capture by for\n> +\t * example pushing a button. For now run all streams all the time.\n> +\t */\n> +\n> +\tstd::vector<Request *> requests;\n> +\tfor (unsigned int i = 0; i < nbuffers; i++) {\n>  \t\tRequest *request = camera->createRequest();\n>  \t\tif (!request) {\n>  \t\t\tstd::cerr << \"Can't create request\" << std::endl;\n> @@ -174,7 +224,11 @@ static int capture()\n>  \t\t}\n>  \n>  \t\tstd::map<Stream *, Buffer *> map;\n> -\t\tmap[stream] = &buffer;\n> +\t\tfor (auto const &it : config) {\n> +\t\t\tStream *stream = it.first;\n> +\t\t\tmap[stream] = &stream->bufferPool().buffers()[i];\n> +\t\t}\n> +\n>  \t\tret = request->setBuffers(map);\n>  \t\tif (ret < 0) {\n>  \t\t\tstd::cerr << \"Can't set buffers for request\" << std::endl;\n>","headers":{"Return-Path":"<kieran.bingham@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2D7BD610B3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Apr 2019 07:28:39 +0200 (CEST)","from [10.71.11.124] (unknown [147.50.13.10])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8CAD52F9;\n\tWed,  3 Apr 2019 07:28:37 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1554269318;\n\tbh=A1eapDNRkn3ZVvRIInUEbxLNzGCaOfOqW2o4YQzVy1o=;\n\th=Reply-To:Subject:To:References:From:Date:In-Reply-To:From;\n\tb=rSXEndx+G1dUorqfIk5C8nmmOk7cpmiQRN+VZmdgd4+JvoMzWmI74ArTbvDJZze5X\n\tN1JKXnnRtWJfwm4NygK00MFdUhQ8ccTqb2OpMgDhzWL8xKoB4Id1BFEkxQ2dAZjFWP\n\tc653iUwb+EmeU+5rrUse7wpGuR4KoLtU7lG7Nrvo=","Reply-To":"kieran.bingham@ideasonboard.com","To":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20190403011235.12782-1-niklas.soderlund@ragnatech.se>\n\t<20190403011235.12782-3-niklas.soderlund@ragnatech.se>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Openpgp":"preference=signencrypt","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\t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\n\tsbsRB8KNNvVXBOVNwko86rQqF9drZuw=","Organization":"Ideas on Board","Message-ID":"<453c51bc-6162-d889-8bdc-87c101fabcac@ideasonboard.com>","Date":"Wed, 3 Apr 2019 12:28:32 +0700","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101\n\tThunderbird/60.5.1","MIME-Version":"1.0","In-Reply-To":"<20190403011235.12782-3-niklas.soderlund@ragnatech.se>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"8bit","Subject":"Re: [libcamera-devel] [PATCH v2 2/4] cam: Add support to specify\n\tmultiple stream configurations with roles","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, 03 Apr 2019 05:28:39 -0000"}},{"id":1244,"web_url":"https://patchwork.libcamera.org/comment/1244/","msgid":"<20190403071522.GG4813@pendragon.ideasonboard.com>","date":"2019-04-03T07:15:22","subject":"Re: [libcamera-devel] [PATCH v2 2/4] cam: Add support to specify\n\tmultiple stream configurations with roles","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nThank you for the patch.\n\nOn Wed, Apr 03, 2019 at 03:12:33AM +0200, Niklas Söderlund wrote:\n> Extend the cam tool to allow configuring more than one stream. Add an\n> optional parameter to the --stream option to specify a usage role for\n> the stream. The stream role is passed to libcamera to give it control\n> over which streams to use.\n> \n> To support multiple streams, creation of requests needs to be reworked\n> to limit the number of requests to match the stream with the least\n> number of buffers. This should be improved in the future as the tool and\n> the library evolve.\n> \n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  src/cam/main.cpp | 78 ++++++++++++++++++++++++++++++++++++++++--------\n>  1 file changed, 66 insertions(+), 12 deletions(-)\n> \n> diff --git a/src/cam/main.cpp b/src/cam/main.cpp\n> index 6bf5e5926704d6e9..b47bda21cbb7f220 100644\n> --- a/src/cam/main.cpp\n> +++ b/src/cam/main.cpp\n> @@ -5,8 +5,10 @@\n>   * main.cpp - cam - The libcamera swiss army knife\n>   */\n>  \n> +#include <algorithm>\n>  #include <iomanip>\n>  #include <iostream>\n> +#include <limits.h>\n>  #include <map>\n>  #include <signal.h>\n>  #include <string.h>\n> @@ -42,6 +44,9 @@ void signalHandler(int signal)\n>  static int parseOptions(int argc, char *argv[])\n>  {\n>  \tKeyValueParser streamKeyValue;\n> +\tstreamKeyValue.addOption(\"role\", OptionString,\n> +\t\t\t\t \"Role for the stream (viewfinder, video, still)\",\n> +\t\t\t\t ArgumentRequired);\n>  \tstreamKeyValue.addOption(\"width\", OptionInteger, \"Width in pixels\",\n>  \t\t\t\t ArgumentRequired);\n>  \tstreamKeyValue.addOption(\"height\", OptionInteger, \"Height in pixels\",\n> @@ -61,7 +66,7 @@ static int parseOptions(int argc, char *argv[])\n>  \t\t\t \"The default file name is 'frame-#.bin'.\",\n>  \t\t\t \"file\", ArgumentOptional, \"filename\");\n>  \tparser.addOption(OptStream, &streamKeyValue,\n> -\t\t\t \"Set configuration of a camera stream\", \"stream\");\n> +\t\t\t \"Set configuration of a camera stream\", \"stream\", true);\n>  \tparser.addOption(OptHelp, OptionNone, \"Display this help message\",\n>  \t\t\t \"help\");\n>  \tparser.addOption(OptList, OptionNone, \"List all cameras\", \"list\");\n> @@ -80,12 +85,51 @@ static int parseOptions(int argc, char *argv[])\n>  \n>  static int prepareCameraConfig(std::map<Stream *, StreamConfiguration> *config)\n>  {\n> -\tstd::set<Stream *> streams = camera->streams();\n> -\t*config = camera->streamConfiguration({ Stream::VideoRecording() });\n> -\tStream *stream = config->begin()->first;\n> +\tstd::vector<StreamRole> roles;\n>  \n> -\tif (options.isSet(OptStream)) {\n> -\t\tKeyValueParser::Options conf = options[OptStream];\n> +\t/* If no configuration is provided assume a single video stream. */\n> +\tif (!options.isSet(OptStream)) {\n> +\t\t*config = camera->streamConfiguration({ Stream::VideoRecording() });\n> +\t\treturn 0;\n> +\t}\n> +\n> +\tconst std::vector<OptionValue> &streamopts =\n\ns/streamopts/streamOpts/ (or even streamOptions) ?\n\n> +\t\toptions[OptStream].toArray();\n> +\n> +\t/* Use roles and get a default configuration. */\n> +\tfor (auto const &value : streamopts) {\n> +\t\tKeyValueParser::Options conf = value.toKeyValues();\n> +\n> +\t\tif (!conf.isSet(\"role\")) {\n> +\t\t\troles.push_back(Stream::VideoRecording());\n> +\t\t} else if (conf[\"role\"].toString() == \"viewfinder\") {\n> +\t\t\troles.push_back(Stream::Viewfinder(conf[\"width\"],\n> +\t\t\t\t\t\t\t   conf[\"height\"]));\n> +\t\t} else if (conf[\"role\"].toString() == \"video\") {\n> +\t\t\troles.push_back(Stream::VideoRecording());\n> +\t\t} else if (conf[\"role\"].toString() == \"still\") {\n> +\t\t\troles.push_back(Stream::StillCapture());\n> +\t\t} else {\n> +\t\t\tstd::cerr << \"Unknown stream role \"\n> +\t\t\t\t  << conf[\"role\"].toString() << std::endl;\n> +\t\t\treturn -EINVAL;\n> +\t\t}\n> +\t}\n> +\n> +\t*config = camera->streamConfiguration(roles);\n> +\n> +\tif (config->size() != streamopts.size()) {\n> +\t\tstd::cerr << \"Failed to get default stream configuration\"\n> +\t\t\t  << std::endl;\n> +\t\treturn -EINVAL;\n> +\t}\n> +\n> +\t/* Apply configuration explicitly requested. */\n> +\tstd::map<Stream *, StreamConfiguration>::iterator it = config->begin();\n> +\tfor (auto const &value : streamopts) {\n> +\t\tKeyValueParser::Options conf = value.toKeyValues();\n> +\t\tStream *stream = it->first;\n> +\t\tit++;\n>  \n>  \t\tif (conf.isSet(\"width\"))\n>  \t\t\t(*config)[stream].width = conf[\"width\"];\n> @@ -137,7 +181,6 @@ static void requestComplete(Request *request, const std::map<Stream *, Buffer *>\n>  static int capture()\n>  {\n>  \tstd::map<Stream *, StreamConfiguration> config;\n> -\tstd::vector<Request *> requests;\n>  \tint ret;\n>  \n>  \tret = prepareCameraConfig(&config);\n> @@ -152,8 +195,6 @@ static int capture()\n>  \t\treturn ret;\n>  \t}\n>  \n> -\tStream *stream = config.begin()->first;\n> -\n>  \tret = camera->allocateBuffers();\n>  \tif (ret) {\n>  \t\tstd::cerr << \"Failed to allocate buffers\"\n> @@ -163,9 +204,18 @@ static int capture()\n>  \n>  \tcamera->requestCompleted.connect(requestComplete);\n>  \n> -\tBufferPool &pool = stream->bufferPool();\n> +\t/* Figure out which stream s the lower number of buffers. */\n\ns/stream s/stream has/\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\tunsigned int nbuffers = UINT_MAX;\n> +\tfor (auto const &it : config)\n> +\t\tnbuffers = std::min(nbuffers, it.first->bufferPool().count());\n>  \n> -\tfor (Buffer &buffer : pool.buffers()) {\n> +\t/*\n> +\t * TODO: make cam tool smarter to support still capture by for\n> +\t * example pushing a button. For now run all streams all the time.\n> +\t */\n> +\n> +\tstd::vector<Request *> requests;\n> +\tfor (unsigned int i = 0; i < nbuffers; i++) {\n>  \t\tRequest *request = camera->createRequest();\n>  \t\tif (!request) {\n>  \t\t\tstd::cerr << \"Can't create request\" << std::endl;\n> @@ -174,7 +224,11 @@ static int capture()\n>  \t\t}\n>  \n>  \t\tstd::map<Stream *, Buffer *> map;\n> -\t\tmap[stream] = &buffer;\n> +\t\tfor (auto const &it : config) {\n> +\t\t\tStream *stream = it.first;\n> +\t\t\tmap[stream] = &stream->bufferPool().buffers()[i];\n> +\t\t}\n> +\n>  \t\tret = request->setBuffers(map);\n>  \t\tif (ret < 0) {\n>  \t\t\tstd::cerr << \"Can't set buffers for request\" << std::endl;","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7A97160DB2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Apr 2019 09:15:33 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DFD142F9;\n\tWed,  3 Apr 2019 09:15:32 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1554275733;\n\tbh=HbMkO3Cy8SEmvzi9Hab421LTKkeo6i3F4ujCI0IdNJw=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=tpbYE/D87MzDHUi1rsx1pjAKaoCiQL7ZtCZrhke4e8WYf1BEx7XrGZ2ZNZVVfLIZx\n\twLvWnIw5YF8Ur+r/4Ld1uBw2ofqB6rI1/+9O41+wVsL8G+E+JGlzebGxu96tybxxYE\n\t9csHWpp/kvDZfWeW8TPoNtOUZkLwur+IXMb1c88s=","Date":"Wed, 3 Apr 2019 10:15:22 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190403071522.GG4813@pendragon.ideasonboard.com>","References":"<20190403011235.12782-1-niklas.soderlund@ragnatech.se>\n\t<20190403011235.12782-3-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190403011235.12782-3-niklas.soderlund@ragnatech.se>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v2 2/4] cam: Add support to specify\n\tmultiple stream configurations with roles","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, 03 Apr 2019 07:15:33 -0000"}},{"id":1256,"web_url":"https://patchwork.libcamera.org/comment/1256/","msgid":"<20190403133947.e6tt267zlmnlz4sp@uno.localdomain>","date":"2019-04-03T13:39:47","subject":"Re: [libcamera-devel] [PATCH v2 2/4] cam: Add support to specify\n\tmultiple stream configurations with roles","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Niklas,\n  one general question below\n\nOn Wed, Apr 03, 2019 at 03:12:33AM +0200, Niklas Söderlund wrote:\n> Extend the cam tool to allow configuring more than one stream. Add an\n> optional parameter to the --stream option to specify a usage role for\n> the stream. The stream role is passed to libcamera to give it control\n> over which streams to use.\n>\n> To support multiple streams, creation of requests needs to be reworked\n> to limit the number of requests to match the stream with the least\n> number of buffers. This should be improved in the future as the tool and\n> the library evolve.\n>\n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  src/cam/main.cpp | 78 ++++++++++++++++++++++++++++++++++++++++--------\n>  1 file changed, 66 insertions(+), 12 deletions(-)\n>\n> diff --git a/src/cam/main.cpp b/src/cam/main.cpp\n> index 6bf5e5926704d6e9..b47bda21cbb7f220 100644\n> --- a/src/cam/main.cpp\n> +++ b/src/cam/main.cpp\n> @@ -5,8 +5,10 @@\n>   * main.cpp - cam - The libcamera swiss army knife\n>   */\n>\n> +#include <algorithm>\n>  #include <iomanip>\n>  #include <iostream>\n> +#include <limits.h>\n>  #include <map>\n>  #include <signal.h>\n>  #include <string.h>\n> @@ -42,6 +44,9 @@ void signalHandler(int signal)\n>  static int parseOptions(int argc, char *argv[])\n>  {\n>  \tKeyValueParser streamKeyValue;\n> +\tstreamKeyValue.addOption(\"role\", OptionString,\n> +\t\t\t\t \"Role for the stream (viewfinder, video, still)\",\n> +\t\t\t\t ArgumentRequired);\n>  \tstreamKeyValue.addOption(\"width\", OptionInteger, \"Width in pixels\",\n>  \t\t\t\t ArgumentRequired);\n>  \tstreamKeyValue.addOption(\"height\", OptionInteger, \"Height in pixels\",\n> @@ -61,7 +66,7 @@ static int parseOptions(int argc, char *argv[])\n>  \t\t\t \"The default file name is 'frame-#.bin'.\",\n>  \t\t\t \"file\", ArgumentOptional, \"filename\");\n>  \tparser.addOption(OptStream, &streamKeyValue,\n> -\t\t\t \"Set configuration of a camera stream\", \"stream\");\n> +\t\t\t \"Set configuration of a camera stream\", \"stream\", true);\n>  \tparser.addOption(OptHelp, OptionNone, \"Display this help message\",\n>  \t\t\t \"help\");\n>  \tparser.addOption(OptList, OptionNone, \"List all cameras\", \"list\");\n> @@ -80,12 +85,51 @@ static int parseOptions(int argc, char *argv[])\n>\n>  static int prepareCameraConfig(std::map<Stream *, StreamConfiguration> *config)\n>  {\n> -\tstd::set<Stream *> streams = camera->streams();\n> -\t*config = camera->streamConfiguration({ Stream::VideoRecording() });\n> -\tStream *stream = config->begin()->first;\n> +\tstd::vector<StreamRole> roles;\n>\n> -\tif (options.isSet(OptStream)) {\n> -\t\tKeyValueParser::Options conf = options[OptStream];\n> +\t/* If no configuration is provided assume a single video stream. */\n> +\tif (!options.isSet(OptStream)) {\n> +\t\t*config = camera->streamConfiguration({ Stream::VideoRecording() });\n> +\t\treturn 0;\n> +\t}\n> +\n> +\tconst std::vector<OptionValue> &streamopts =\n> +\t\toptions[OptStream].toArray();\n> +\n> +\t/* Use roles and get a default configuration. */\n> +\tfor (auto const &value : streamopts) {\n> +\t\tKeyValueParser::Options conf = value.toKeyValues();\n> +\n> +\t\tif (!conf.isSet(\"role\")) {\n> +\t\t\troles.push_back(Stream::VideoRecording());\n> +\t\t} else if (conf[\"role\"].toString() == \"viewfinder\") {\n> +\t\t\troles.push_back(Stream::Viewfinder(conf[\"width\"],\n> +\t\t\t\t\t\t\t   conf[\"height\"]));\n> +\t\t} else if (conf[\"role\"].toString() == \"video\") {\n> +\t\t\troles.push_back(Stream::VideoRecording());\n> +\t\t} else if (conf[\"role\"].toString() == \"still\") {\n> +\t\t\troles.push_back(Stream::StillCapture());\n> +\t\t} else {\n> +\t\t\tstd::cerr << \"Unknown stream role \"\n> +\t\t\t\t  << conf[\"role\"].toString() << std::endl;\n> +\t\t\treturn -EINVAL;\n> +\t\t}\n> +\t}\n\nOpen question and not specifically on this patch, but on this and the\nother series you have in flight: this implementation does not allow to\nspecify multiple roles for a stream, as you could have done using a\nbitmaks. For applications to stay as generic as possible, is it very\nunlikely to have them as for something like (VIEWFINDER | VIDEOCAPTURE) ?\nIf I'm not wrong this implementation makes roles mutually exclusive,\ndoesn't it?\n\nThis would call for pipeline handler to match at least one of the intended\nusages, to assign a stream to a stream usage.\n\n> +\n> +\t*config = camera->streamConfiguration(roles);\n> +\n> +\tif (config->size() != streamopts.size()) {\n> +\t\tstd::cerr << \"Failed to get default stream configuration\"\n> +\t\t\t  << std::endl;\n> +\t\treturn -EINVAL;\n> +\t}\n> +\n> +\t/* Apply configuration explicitly requested. */\n> +\tstd::map<Stream *, StreamConfiguration>::iterator it = config->begin();\n> +\tfor (auto const &value : streamopts) {\n> +\t\tKeyValueParser::Options conf = value.toKeyValues();\n> +\t\tStream *stream = it->first;\n> +\t\tit++;\n>\n>  \t\tif (conf.isSet(\"width\"))\n>  \t\t\t(*config)[stream].width = conf[\"width\"];\n> @@ -137,7 +181,6 @@ static void requestComplete(Request *request, const std::map<Stream *, Buffer *>\n>  static int capture()\n>  {\n>  \tstd::map<Stream *, StreamConfiguration> config;\n> -\tstd::vector<Request *> requests;\n>  \tint ret;\n>\n>  \tret = prepareCameraConfig(&config);\n> @@ -152,8 +195,6 @@ static int capture()\n>  \t\treturn ret;\n>  \t}\n>\n> -\tStream *stream = config.begin()->first;\n> -\n>  \tret = camera->allocateBuffers();\n>  \tif (ret) {\n>  \t\tstd::cerr << \"Failed to allocate buffers\"\n> @@ -163,9 +204,18 @@ static int capture()\n>\n>  \tcamera->requestCompleted.connect(requestComplete);\n>\n> -\tBufferPool &pool = stream->bufferPool();\n> +\t/* Figure out which stream s the lower number of buffers. */\n\ns/ s/has/ ?\n\n> +\tunsigned int nbuffers = UINT_MAX;\n> +\tfor (auto const &it : config)\n> +\t\tnbuffers = std::min(nbuffers, it.first->bufferPool().count());\n>\n> -\tfor (Buffer &buffer : pool.buffers()) {\n> +\t/*\n> +\t * TODO: make cam tool smarter to support still capture by for\n> +\t * example pushing a button. For now run all streams all the time.\n> +\t */\n> +\n> +\tstd::vector<Request *> requests;\n> +\tfor (unsigned int i = 0; i < nbuffers; i++) {\n>  \t\tRequest *request = camera->createRequest();\n>  \t\tif (!request) {\n>  \t\t\tstd::cerr << \"Can't create request\" << std::endl;\n> @@ -174,7 +224,11 @@ static int capture()\n>  \t\t}\n>\n>  \t\tstd::map<Stream *, Buffer *> map;\n> -\t\tmap[stream] = &buffer;\n> +\t\tfor (auto const &it : config) {\n> +\t\t\tStream *stream = it.first;\n> +\t\t\tmap[stream] = &stream->bufferPool().buffers()[i];\n> +\t\t}\n> +\n>  \t\tret = request->setBuffers(map);\n>  \t\tif (ret < 0) {\n>  \t\t\tstd::cerr << \"Can't set buffers for request\" << std::endl;\n> --\n> 2.21.0\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net\n\t[217.70.183.196])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2C743600FB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Apr 2019 15:39:02 +0200 (CEST)","from uno.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay4-d.mail.gandi.net (Postfix) with ESMTPSA id A77C0E0002;\n\tWed,  3 Apr 2019 13:39:01 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","Date":"Wed, 3 Apr 2019 15:39:47 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190403133947.e6tt267zlmnlz4sp@uno.localdomain>","References":"<20190403011235.12782-1-niklas.soderlund@ragnatech.se>\n\t<20190403011235.12782-3-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"aaqkmdfxvmwpdhda\"","Content-Disposition":"inline","In-Reply-To":"<20190403011235.12782-3-niklas.soderlund@ragnatech.se>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH v2 2/4] cam: Add support to specify\n\tmultiple stream configurations with roles","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, 03 Apr 2019 13:39:02 -0000"}},{"id":1261,"web_url":"https://patchwork.libcamera.org/comment/1261/","msgid":"<20190404000032.GL23466@bigcity.dyn.berto.se>","date":"2019-04-04T00:00:32","subject":"Re: [libcamera-devel] [PATCH v2 2/4] cam: Add support to specify\n\tmultiple stream configurations with roles","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Jacopo,\n\nThanks for your feedback.\n\nOn 2019-04-03 15:39:47 +0200, Jacopo Mondi wrote:\n> Hi Niklas,\n>   one general question below\n> \n> On Wed, Apr 03, 2019 at 03:12:33AM +0200, Niklas Söderlund wrote:\n> > Extend the cam tool to allow configuring more than one stream. Add an\n> > optional parameter to the --stream option to specify a usage role for\n> > the stream. The stream role is passed to libcamera to give it control\n> > over which streams to use.\n> >\n> > To support multiple streams, creation of requests needs to be reworked\n> > to limit the number of requests to match the stream with the least\n> > number of buffers. This should be improved in the future as the tool and\n> > the library evolve.\n> >\n> > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> > ---\n> >  src/cam/main.cpp | 78 ++++++++++++++++++++++++++++++++++++++++--------\n> >  1 file changed, 66 insertions(+), 12 deletions(-)\n> >\n> > diff --git a/src/cam/main.cpp b/src/cam/main.cpp\n> > index 6bf5e5926704d6e9..b47bda21cbb7f220 100644\n> > --- a/src/cam/main.cpp\n> > +++ b/src/cam/main.cpp\n> > @@ -5,8 +5,10 @@\n> >   * main.cpp - cam - The libcamera swiss army knife\n> >   */\n> >\n> > +#include <algorithm>\n> >  #include <iomanip>\n> >  #include <iostream>\n> > +#include <limits.h>\n> >  #include <map>\n> >  #include <signal.h>\n> >  #include <string.h>\n> > @@ -42,6 +44,9 @@ void signalHandler(int signal)\n> >  static int parseOptions(int argc, char *argv[])\n> >  {\n> >  \tKeyValueParser streamKeyValue;\n> > +\tstreamKeyValue.addOption(\"role\", OptionString,\n> > +\t\t\t\t \"Role for the stream (viewfinder, video, still)\",\n> > +\t\t\t\t ArgumentRequired);\n> >  \tstreamKeyValue.addOption(\"width\", OptionInteger, \"Width in pixels\",\n> >  \t\t\t\t ArgumentRequired);\n> >  \tstreamKeyValue.addOption(\"height\", OptionInteger, \"Height in pixels\",\n> > @@ -61,7 +66,7 @@ static int parseOptions(int argc, char *argv[])\n> >  \t\t\t \"The default file name is 'frame-#.bin'.\",\n> >  \t\t\t \"file\", ArgumentOptional, \"filename\");\n> >  \tparser.addOption(OptStream, &streamKeyValue,\n> > -\t\t\t \"Set configuration of a camera stream\", \"stream\");\n> > +\t\t\t \"Set configuration of a camera stream\", \"stream\", true);\n> >  \tparser.addOption(OptHelp, OptionNone, \"Display this help message\",\n> >  \t\t\t \"help\");\n> >  \tparser.addOption(OptList, OptionNone, \"List all cameras\", \"list\");\n> > @@ -80,12 +85,51 @@ static int parseOptions(int argc, char *argv[])\n> >\n> >  static int prepareCameraConfig(std::map<Stream *, StreamConfiguration> *config)\n> >  {\n> > -\tstd::set<Stream *> streams = camera->streams();\n> > -\t*config = camera->streamConfiguration({ Stream::VideoRecording() });\n> > -\tStream *stream = config->begin()->first;\n> > +\tstd::vector<StreamRole> roles;\n> >\n> > -\tif (options.isSet(OptStream)) {\n> > -\t\tKeyValueParser::Options conf = options[OptStream];\n> > +\t/* If no configuration is provided assume a single video stream. */\n> > +\tif (!options.isSet(OptStream)) {\n> > +\t\t*config = camera->streamConfiguration({ Stream::VideoRecording() });\n> > +\t\treturn 0;\n> > +\t}\n> > +\n> > +\tconst std::vector<OptionValue> &streamopts =\n> > +\t\toptions[OptStream].toArray();\n> > +\n> > +\t/* Use roles and get a default configuration. */\n> > +\tfor (auto const &value : streamopts) {\n> > +\t\tKeyValueParser::Options conf = value.toKeyValues();\n> > +\n> > +\t\tif (!conf.isSet(\"role\")) {\n> > +\t\t\troles.push_back(Stream::VideoRecording());\n> > +\t\t} else if (conf[\"role\"].toString() == \"viewfinder\") {\n> > +\t\t\troles.push_back(Stream::Viewfinder(conf[\"width\"],\n> > +\t\t\t\t\t\t\t   conf[\"height\"]));\n> > +\t\t} else if (conf[\"role\"].toString() == \"video\") {\n> > +\t\t\troles.push_back(Stream::VideoRecording());\n> > +\t\t} else if (conf[\"role\"].toString() == \"still\") {\n> > +\t\t\troles.push_back(Stream::StillCapture());\n> > +\t\t} else {\n> > +\t\t\tstd::cerr << \"Unknown stream role \"\n> > +\t\t\t\t  << conf[\"role\"].toString() << std::endl;\n> > +\t\t\treturn -EINVAL;\n> > +\t\t}\n> > +\t}\n> \n> Open question and not specifically on this patch, but on this and the\n> other series you have in flight: this implementation does not allow to\n> specify multiple roles for a stream, as you could have done using a\n> bitmaks. For applications to stay as generic as possible, is it very\n> unlikely to have them as for something like (VIEWFINDER | VIDEOCAPTURE) ?\n> If I'm not wrong this implementation makes roles mutually exclusive,\n> doesn't it?\n\nYes it makes roles mutually exclusive on a stream level. It is not \npossible to use the same stream simultaneously for both still image \ncapture and as a view finder. You can however use the same stream for \nboth purposes in two different capture sessions.\n\nDid I understand your question correctly?\n\n> \n> This would call for pipeline handler to match at least one of the intended\n> usages, to assign a stream to a stream usage.\n> \n> > +\n> > +\t*config = camera->streamConfiguration(roles);\n> > +\n> > +\tif (config->size() != streamopts.size()) {\n> > +\t\tstd::cerr << \"Failed to get default stream configuration\"\n> > +\t\t\t  << std::endl;\n> > +\t\treturn -EINVAL;\n> > +\t}\n> > +\n> > +\t/* Apply configuration explicitly requested. */\n> > +\tstd::map<Stream *, StreamConfiguration>::iterator it = config->begin();\n> > +\tfor (auto const &value : streamopts) {\n> > +\t\tKeyValueParser::Options conf = value.toKeyValues();\n> > +\t\tStream *stream = it->first;\n> > +\t\tit++;\n> >\n> >  \t\tif (conf.isSet(\"width\"))\n> >  \t\t\t(*config)[stream].width = conf[\"width\"];\n> > @@ -137,7 +181,6 @@ static void requestComplete(Request *request, const std::map<Stream *, Buffer *>\n> >  static int capture()\n> >  {\n> >  \tstd::map<Stream *, StreamConfiguration> config;\n> > -\tstd::vector<Request *> requests;\n> >  \tint ret;\n> >\n> >  \tret = prepareCameraConfig(&config);\n> > @@ -152,8 +195,6 @@ static int capture()\n> >  \t\treturn ret;\n> >  \t}\n> >\n> > -\tStream *stream = config.begin()->first;\n> > -\n> >  \tret = camera->allocateBuffers();\n> >  \tif (ret) {\n> >  \t\tstd::cerr << \"Failed to allocate buffers\"\n> > @@ -163,9 +204,18 @@ static int capture()\n> >\n> >  \tcamera->requestCompleted.connect(requestComplete);\n> >\n> > -\tBufferPool &pool = stream->bufferPool();\n> > +\t/* Figure out which stream s the lower number of buffers. */\n> \n> s/ s/has/ ?\n> \n> > +\tunsigned int nbuffers = UINT_MAX;\n> > +\tfor (auto const &it : config)\n> > +\t\tnbuffers = std::min(nbuffers, it.first->bufferPool().count());\n> >\n> > -\tfor (Buffer &buffer : pool.buffers()) {\n> > +\t/*\n> > +\t * TODO: make cam tool smarter to support still capture by for\n> > +\t * example pushing a button. For now run all streams all the time.\n> > +\t */\n> > +\n> > +\tstd::vector<Request *> requests;\n> > +\tfor (unsigned int i = 0; i < nbuffers; i++) {\n> >  \t\tRequest *request = camera->createRequest();\n> >  \t\tif (!request) {\n> >  \t\t\tstd::cerr << \"Can't create request\" << std::endl;\n> > @@ -174,7 +224,11 @@ static int capture()\n> >  \t\t}\n> >\n> >  \t\tstd::map<Stream *, Buffer *> map;\n> > -\t\tmap[stream] = &buffer;\n> > +\t\tfor (auto const &it : config) {\n> > +\t\t\tStream *stream = it.first;\n> > +\t\t\tmap[stream] = &stream->bufferPool().buffers()[i];\n> > +\t\t}\n> > +\n> >  \t\tret = request->setBuffers(map);\n> >  \t\tif (ret < 0) {\n> >  \t\t\tstd::cerr << \"Can't set buffers for request\" << std::endl;\n> > --\n> > 2.21.0\n> >\n> > _______________________________________________\n> > libcamera-devel mailing list\n> > libcamera-devel@lists.libcamera.org\n> > https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lj1-x242.google.com (mail-lj1-x242.google.com\n\t[IPv6:2a00:1450:4864:20::242])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CC298610D5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Apr 2019 02:00:34 +0200 (CEST)","by mail-lj1-x242.google.com with SMTP id y6so392789ljd.12\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 03 Apr 2019 17:00:34 -0700 (PDT)","from localhost (89-233-230-99.cust.bredband2.com. [89.233.230.99])\n\tby smtp.gmail.com with ESMTPSA id\n\tj8sm3603300ljh.58.2019.04.03.17.00.32\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tWed, 03 Apr 2019 17:00:33 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=WvVAM9ct0IyHsMscauo7N/fb9rMQ5Lo+V6SOZCOBFGM=;\n\tb=zNhN8ULF+9NCaZoUPmmCWLHOQTGSZpRXHKKqKHqyA62LKoxSAuyp6k16E/M9doyxWr\n\tu8XipPehhs9A9Mj/hMNF7QHtVyF3Fyw7R0kSttR5vdWfdpHGvsSHMDMY+V5Gz08pkkuD\n\th7c0QKlzy13hK6P6plOyckahKl2Zz132waoiFCfx2zOG014495h2fgEHwrlw4foURIy0\n\t2zlzuby/gGGHbsx/hdLtPM5pumj1ATYgTYRoaHqKtPROpKubyIJTCRTsr6KjSqf/y0LU\n\tMawoLChLrUaU1OOJRr3gIyFA6OWAz2GL5Jb/BRz31THdHflyr5R/mJBQEQgJ/8TofJYM\n\t+pfQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=WvVAM9ct0IyHsMscauo7N/fb9rMQ5Lo+V6SOZCOBFGM=;\n\tb=k5KZkaNJT3MraqgRyLCVRXnRQc/jeqTyT8QWClYBNTkPirNNud09VDIN+PuWB/ALa7\n\t3CJekP3OC3f+vyuScG1wlO+LlWAVQtaORncsuPAo227+6L8MIpTzbCPzvG+CZ0mWIqnC\n\tkNPOloAS+ssu0g+mHAweoTw5Bp+GmcJQ6DnVGHEWsVjxwoF8jHsrCvjE7OTkTqzczyeo\n\tBgGod7xqTGo8lQ4AegHvvmoc+DLBHRq6nYyD38DOJ5mP+/l+HN68Ck/aVJPy16RNPs/a\n\t9X0RDA8dEeGU/77mPT8ohYsqbmCHAjuZxxN/liJBUf6uSHUa4yBvSsci8MqUTePE/Yy3\n\ts+RA==","X-Gm-Message-State":"APjAAAW4kQ1o9bHke3L/++QrEmL+A5R7W+Q13cSc4lP+itUCwCSiajUH\n\tZlXU8kv4XOzEPj6u/2eEzD5bb5TCT6I=","X-Google-Smtp-Source":"APXvYqzMHiMb4Cs+dVrFOjiqUUc0rcFqWmQkxCRkP2xz1w5le1DLFU4bAojLKzPcLNcimWyyk/syhQ==","X-Received":"by 2002:a2e:8198:: with SMTP id e24mr1417292ljg.45.1554336034015;\n\tWed, 03 Apr 2019 17:00:34 -0700 (PDT)","Date":"Thu, 4 Apr 2019 02:00:32 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190404000032.GL23466@bigcity.dyn.berto.se>","References":"<20190403011235.12782-1-niklas.soderlund@ragnatech.se>\n\t<20190403011235.12782-3-niklas.soderlund@ragnatech.se>\n\t<20190403133947.e6tt267zlmnlz4sp@uno.localdomain>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190403133947.e6tt267zlmnlz4sp@uno.localdomain>","User-Agent":"Mutt/1.11.3 (2019-02-01)","Subject":"Re: [libcamera-devel] [PATCH v2 2/4] cam: Add support to specify\n\tmultiple stream configurations with roles","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":"Thu, 04 Apr 2019 00:00:35 -0000"}}]