[{"id":4685,"web_url":"https://patchwork.libcamera.org/comment/4685/","msgid":"<20200430164503.GR5856@pendragon.ideasonboard.com>","date":"2020-04-30T16:45:03","subject":"Re: [libcamera-devel] [PATCH v2 4/5] cam: Make use of\n\tStreamKeyValueParser","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nOn Tue, Apr 28, 2020 at 12:05:28AM +0200, Niklas Söderlund wrote:\n> Use the StreamOptionsParser helper to parse stream configuration from\n> the command line.\n> \n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  src/cam/main.cpp | 69 +++++-------------------------------------------\n>  1 file changed, 6 insertions(+), 63 deletions(-)\n> \n> diff --git a/src/cam/main.cpp b/src/cam/main.cpp\n> index ced4f567b8f38e00..c6814f21aa51cf41 100644\n> --- a/src/cam/main.cpp\n> +++ b/src/cam/main.cpp\n> @@ -16,7 +16,7 @@\n>  #include \"capture.h\"\n>  #include \"event_loop.h\"\n>  #include \"main.h\"\n> -#include \"options.h\"\n> +#include \"stream_options.h\"\n\nI'd keep the two files, up to you.\n\n>  using namespace libcamera;\n>  \n> @@ -154,16 +154,7 @@ void CamApp::quit()\n>  \n>  int CamApp::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, stillraw)\",\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> -\t\t\t\t ArgumentRequired);\n> -\tstreamKeyValue.addOption(\"pixelformat\", OptionInteger, \"Pixel format\",\n> -\t\t\t\t ArgumentRequired);\n> +\tStreamKeyValueParser streamKeyValue;\n>  \n>  \tOptionsParser parser;\n>  \tparser.addOption(OptCamera, OptionString,\n> @@ -202,38 +193,7 @@ int CamApp::parseOptions(int argc, char *argv[])\n>  \n>  int CamApp::prepareConfig()\n>  {\n> -\tStreamRoles roles;\n> -\n> -\tif (options_.isSet(OptStream)) {\n> -\t\tconst std::vector<OptionValue> &streamOptions =\n> -\t\t\toptions_[OptStream].toArray();\n> -\n> -\t\t/* Use roles and get a default configuration. */\n> -\t\tfor (auto const &value : streamOptions) {\n> -\t\t\tKeyValueParser::Options opt = value.toKeyValues();\n> -\n> -\t\t\tstd::string role = opt.isSet(\"role\")\n> -\t\t\t\t\t ? opt[\"role\"].toString()\n> -\t\t\t\t\t : \"viewfinder\";\n> -\n> -\t\t\tif (role == \"viewfinder\") {\n> -\t\t\t\troles.push_back(StreamRole::Viewfinder);\n> -\t\t\t} else if (role == \"video\") {\n> -\t\t\t\troles.push_back(StreamRole::VideoRecording);\n> -\t\t\t} else if (role == \"still\") {\n> -\t\t\t\troles.push_back(StreamRole::StillCapture);\n> -\t\t\t} else if (role == \"stillraw\") {\n> -\t\t\t\troles.push_back(StreamRole::StillCaptureRaw);\n> -\t\t\t} else {\n> -\t\t\t\tstd::cerr << \"Unknown stream role \"\n> -\t\t\t\t\t  << role << std::endl;\n> -\t\t\t\treturn -EINVAL;\n> -\t\t\t}\n> -\t\t}\n> -\t} else {\n> -\t\t/* If no configuration is provided assume a single video stream. */\n> -\t\troles.push_back(StreamRole::VideoRecording);\n\nThis differs from the default in the parser. Not a big deal for now, but\nI think it shows the default should likely be application-specific.\n\n> -\t}\n> +\tStreamRoles roles = StreamKeyValueParser::roles(options_[OptStream]);\n>  \n>  \tconfig_ = camera_->generateConfiguration(roles);\n>  \tif (!config_ || config_->size() != roles.size()) {\n> @@ -243,26 +203,9 @@ int CamApp::prepareConfig()\n>  \t}\n>  \n>  \t/* Apply configuration if explicitly requested. */\n> -\tif (options_.isSet(OptStream)) {\n> -\t\tconst std::vector<OptionValue> &streamOptions =\n> -\t\t\toptions_[OptStream].toArray();\n> -\n> -\t\tunsigned int i = 0;\n> -\t\tfor (auto const &value : streamOptions) {\n> -\t\t\tKeyValueParser::Options opt = value.toKeyValues();\n> -\t\t\tStreamConfiguration &cfg = config_->at(i++);\n> -\n> -\t\t\tif (opt.isSet(\"width\"))\n> -\t\t\t\tcfg.size.width = opt[\"width\"];\n> -\n> -\t\t\tif (opt.isSet(\"height\"))\n> -\t\t\t\tcfg.size.height = opt[\"height\"];\n> -\n> -\t\t\t/* TODO: Translate 4CC string to ID. */\n> -\t\t\tif (opt.isSet(\"pixelformat\"))\n> -\t\t\t\tcfg.pixelFormat = PixelFormat(opt[\"pixelformat\"]);\n> -\t\t}\n> -\t}\n> +\tif (StreamKeyValueParser::updateConfiguration(config_.get(),\n> +\t\t\t\t\t\t      options_[OptStream]))\n> +\t\treturn -EINVAL;\n\nMaybe logging a message here ?\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>  \n>  \tswitch (config_->validate()) {\n>  \tcase CameraConfiguration::Valid:","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 34072613A8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Apr 2020 18:45:05 +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 A606A321;\n\tThu, 30 Apr 2020 18:45:04 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"h4UxbyXI\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1588265104;\n\tbh=w+a133xHkTMtueEQCsdAwh9di/lPzb2CW8xvk79OJTM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=h4UxbyXIia3GJCqTS6MsUrIqEHcRB73/8gQv19r84HEqHa5xTJ3cvF/eJex3vREN0\n\tP/iElnbj4G+4tGLGopy7JKqz2RTWSWnsPiG3iHMXDordysDDUaE29DvSDljLonlpcg\n\to2g1AiZsUxdetUDoIjAWy+Ia/SL1x4KxaAXkKbA8=","Date":"Thu, 30 Apr 2020 19:45:03 +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":"<20200430164503.GR5856@pendragon.ideasonboard.com>","References":"<20200427220529.1085074-1-niklas.soderlund@ragnatech.se>\n\t<20200427220529.1085074-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":"<20200427220529.1085074-5-niklas.soderlund@ragnatech.se>","Subject":"Re: [libcamera-devel] [PATCH v2 4/5] cam: Make use of\n\tStreamKeyValueParser","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","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, 30 Apr 2020 16:45:05 -0000"}}]