[{"id":1119,"web_url":"https://patchwork.libcamera.org/comment/1119/","msgid":"<20190323143620.GN4587@pendragon.ideasonboard.com>","date":"2019-03-23T14:36:20","subject":"Re: [libcamera-devel] [RFC 4/4] cam: Allow specifying configuration\n\tfor more then one stream","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 Fri, Mar 22, 2019 at 02:53:49AM +0100, Niklas Söderlund wrote:\n> As a step to allow multiple streams extend the cam tool to be able to\n> configure more then one stream. At this point libcamera do not allow an\n\ns/do not/does not/\n\n> application to associate a stream with a intended use-case so instead\n> add a 'id' field to the --format parser.\n> \n> The numerical id represent the order in the array of streams which are\n> handed to the application from the library. This should change once the\n> library learns stream use-case. This implementation is a small and\n> incomplete step in the direction of extending the cam utility to support\n> cameras with more then one stream.\n> \n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  src/cam/main.cpp | 39 ++++++++++++++++++++++++++++-----------\n>  1 file changed, 28 insertions(+), 11 deletions(-)\n> \n> diff --git a/src/cam/main.cpp b/src/cam/main.cpp\n> index 1ca7862bf237d85f..c9239ac62a83ce31 100644\n> --- a/src/cam/main.cpp\n> +++ b/src/cam/main.cpp\n> @@ -42,6 +42,8 @@ void signalHandler(int signal)\n>  static int parseOptions(int argc, char *argv[])\n>  {\n>  \tKeyValueParser formatKeyValue;\n> +\tformatKeyValue.addOption(\"id\", OptionInteger, \"ID of stream\",\n\n\"Stream ID\" ?\n\n> +\t\t\t\t ArgumentRequired);\n>  \tformatKeyValue.addOption(\"width\", OptionInteger, \"Width in pixels\",\n>  \t\t\t\t ArgumentRequired);\n>  \tformatKeyValue.addOption(\"height\", OptionInteger, \"Height in pixels\",\n> @@ -61,7 +63,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(OptFormat, &formatKeyValue,\n> -\t\t\t \"Set format of the camera's first stream\", \"format\");\n> +\t\t\t \"Set format of the camera's first stream\", \"format\", true);\n\nYou can break the line to avoid going over 80 columns.\n\n>  \tparser.addOption(OptHelp, OptionNone, \"Display this help message\",\n>  \t\t\t \"help\");\n>  \tparser.addOption(OptList, OptionNone, \"List all cameras\", \"list\");\n> @@ -77,22 +79,37 @@ static int parseOptions(int argc, char *argv[])\n>  \n>  static int configureStreams(Camera *camera, std::set<Stream *> &streams)\n>  {\n> -\tKeyValueParser::Options format = options[OptFormat];\n> -\tStream *id = *streams.begin();\n> -\n>  \tstd::map<Stream *, StreamConfiguration> config =\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\tint num = 0;\n> +\t\tfor (Stream *id : streams) {\n> +\t\t\tfor (auto const &value : options[OptFormat].toArray()) {\n> +\t\t\t\tKeyValueParser::Options format = value.toKeyValues();\n>  \n> -\t\tif (format.isSet(\"height\"))\n> -\t\t\tconfig[id].height = format[\"height\"];\n> +\t\t\t\tif (!format.isSet(\"id\") || format[\"id\"] != num)\n> +\t\t\t\t\tcontinue;\n\nShouldn't you accept streams with no ID ? You can pick the next\navailable stream in that case.\n\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\t\tif (format.isSet(\"width\"))\n> +\t\t\t\t\tconfig[id].width = format[\"width\"];\n> +\n> +\t\t\t\tif (format.isSet(\"height\"))\n> +\t\t\t\t\tconfig[id].height = format[\"height\"];\n> +\n> +\t\t\t\t/* TODO: Translate 4CC string to ID. */\n> +\t\t\t\tif (format.isSet(\"pixelformat\"))\n> +\t\t\t\t\tconfig[id].pixelFormat = format[\"pixelformat\"];\n> +\t\t\t}\n> +\t\t\tnum++;\n> +\t\t}\n> +\t}\n> +\n> +\tfor (auto const &it : config) {\n> +\t\tconst StreamConfiguration &conf = it.second;\n> +\n> +\t\tstd::cout << \"size: \" << conf.width << \"x\" << conf.height\n> +\t\t\t  << \"pixelformat: \" << conf.pixelFormat << std::endl;\n>  \t}\n>  \n>  \treturn camera->configureStreams(config);","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 2043C610B6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 23 Mar 2019 15:36:33 +0100 (CET)","from pendragon.ideasonboard.com\n\t(p5269001-ipngn11702marunouchi.tokyo.ocn.ne.jp [114.158.195.1])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8558D22;\n\tSat, 23 Mar 2019 15:36:31 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1553351792;\n\tbh=faFRcqdZPp8EzGznB9vhY+mey3jZRgCTQY/VM+NA19k=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=o+MaAZSG2X0huVcCcLM5SI7hchfBUOWaMldsDASHWKZmWciF98cVe5HaH5ox1To2b\n\tp1/sOM9HGct6XqcdYxh/3EmxO+S+88OYGVs3Ac6fJ5kqNMKwDI61v6ghPje1TXIUAv\n\t/xrKFLDOANL5aqgA4622Q3E/uPj9kOKwSMoghDnc=","Date":"Sat, 23 Mar 2019 16:36:20 +0200","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":"<20190323143620.GN4587@pendragon.ideasonboard.com>","References":"<20190322015349.14934-1-niklas.soderlund@ragnatech.se>\n\t<20190322015349.14934-5-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":"<20190322015349.14934-5-niklas.soderlund@ragnatech.se>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [RFC 4/4] cam: Allow specifying configuration\n\tfor more then one stream","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":"Sat, 23 Mar 2019 14:36:33 -0000"}}]