[{"id":4686,"web_url":"https://patchwork.libcamera.org/comment/4686/","msgid":"<20200430164924.GS5856@pendragon.ideasonboard.com>","date":"2020-04-30T16:49:24","subject":"Re: [libcamera-devel] [PATCH v2 5/5] qcam: 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\nOn Tue, Apr 28, 2020 at 12:05:29AM +0200, Niklas Söderlund wrote:\n> Use the StreamKeyValueParser helper to parse stream configuration from\n> the command line. This extends qcam to accept role hints and pixel\n> format in addition to a size.\n> \n> Currently only one viewfinder stream is supported, add a check to keep\n> this behavior. Going forward this restriction will be lifted to support\n> more then one stream.\n> \n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  src/qcam/main.cpp        | 12 ++++--------\n>  src/qcam/main_window.cpp | 35 ++++++++++++++++++-----------------\n>  src/qcam/main_window.h   |  4 ++--\n>  src/qcam/meson.build     |  1 +\n>  4 files changed, 25 insertions(+), 27 deletions(-)\n> \n> diff --git a/src/qcam/main.cpp b/src/qcam/main.cpp\n> index 862d714f467c04f9..cd73fa764614e7e7 100644\n> --- a/src/qcam/main.cpp\n> +++ b/src/qcam/main.cpp\n> @@ -13,8 +13,8 @@\n>  \n>  #include <libcamera/camera_manager.h>\n>  \n> +#include \"../cam/stream_options.h\"\n>  #include \"main_window.h\"\n> -#include \"../cam/options.h\"\n\nAs with the previous patch, I'd keep both.\n\n>  \n>  void signalHandler(int signal)\n>  {\n> @@ -24,11 +24,7 @@ void signalHandler(int signal)\n>  \n>  OptionsParser::Options parseOptions(int argc, char *argv[])\n>  {\n> -\tKeyValueParser sizeParser;\n> -\tsizeParser.addOption(\"width\", OptionInteger, \"Width in pixels\",\n> -\t\t\t     ArgumentRequired);\n> -\tsizeParser.addOption(\"height\", OptionInteger, \"Height in pixels\",\n> -\t\t\t     ArgumentRequired);\n> +\tStreamKeyValueParser streamKeyValue;\n>  \n>  \tOptionsParser parser;\n>  \tparser.addOption(OptCamera, OptionString,\n> @@ -36,8 +32,8 @@ OptionsParser::Options parseOptions(int argc, char *argv[])\n>  \t\t\t ArgumentRequired, \"camera\");\n>  \tparser.addOption(OptHelp, OptionNone, \"Display this help message\",\n>  \t\t\t \"help\");\n> -\tparser.addOption(OptSize, &sizeParser, \"Set the stream size\",\n> -\t\t\t \"size\", true);\n> +\tparser.addOption(OptStream, &streamKeyValue,\n> +\t\t\t \"Set configuration of a camera stream\", \"stream\", true);\n>  \n>  \tOptionsParser::Options options = parser.parse(argc, argv);\n>  \tif (options.isSet(OptHelp))\n> diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\n> index ed0cad417d62abea..ee779728fc630da8 100644\n> --- a/src/qcam/main_window.cpp\n> +++ b/src/qcam/main_window.cpp\n> @@ -277,29 +277,25 @@ void MainWindow::toggleCapture(bool start)\n>   */\n>  int MainWindow::startCapture()\n>  {\n> +\tStreamRoles roles = StreamKeyValueParser::roles(options_[OptStream]);\n>  \tint ret;\n>  \n> +\t/* Verify roles are supported. */\n> +\tif (roles.size() != 1) {\n> +\t\tqWarning() << \"Only one stream supported\";\n\ns/qWarning()/qCritical()/ as we can't continue ? Same below.\n\n> +\t\treturn -EINVAL;\n> +\t}\n> +\n> +\tif (roles[0] != StreamRole::Viewfinder) {\n> +\t\tqWarning() << \"Only viewfinder supported\";\n> +\t\treturn -EINVAL;\n> +\t}\n> +\n>  \t/* Configure the camera. */\n> -\tconfig_ = camera_->generateConfiguration({ StreamRole::Viewfinder });\n> +\tconfig_ = camera_->generateConfiguration(roles);\n>  \n>  \tStreamConfiguration &cfg = config_->at(0);\n>  \n> -\tif (options_.isSet(OptSize)) {\n> -\t\tconst std::vector<OptionValue> &sizeOptions =\n> -\t\t\toptions_[OptSize].toArray();\n> -\n> -\t\t/* Set desired stream size if requested. */\n> -\t\tfor (const auto &value : sizeOptions) {\n> -\t\t\tKeyValueParser::Options opt = value.toKeyValues();\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> -\t\t}\n> -\t}\n> -\n>  \t/* Use a format supported by the viewfinder if available. */\n>  \tstd::vector<PixelFormat> formats = cfg.formats().pixelformats();\n>  \tfor (const PixelFormat &format : viewfinder_->nativeFormats()) {\n> @@ -313,6 +309,11 @@ int MainWindow::startCapture()\n>  \t\t}\n>  \t}\n>  \n> +\t/* Allow user to override configuration. */\n> +\tif (StreamKeyValueParser::updateConfiguration(config_.get(),\n> +\t\t\t\t\t\t      options_[OptStream]))\n\nError here too ?\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\t\treturn -EINVAL;\n> +\n>  \tCameraConfiguration::Status validation = config_->validate();\n>  \tif (validation == CameraConfiguration::Invalid) {\n>  \t\tqWarning() << \"Failed to create valid camera configuration\";\n> diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h\n> index 5d6251c830707a79..5e9d9b8d9c6b2d6d 100644\n> --- a/src/qcam/main_window.h\n> +++ b/src/qcam/main_window.h\n> @@ -23,7 +23,7 @@\n>  #include <libcamera/framebuffer_allocator.h>\n>  #include <libcamera/stream.h>\n>  \n> -#include \"../cam/options.h\"\n> +#include \"../cam/stream_options.h\"\n>  #include \"viewfinder.h\"\n>  \n>  using namespace libcamera;\n> @@ -33,7 +33,7 @@ class QAction;\n>  enum {\n>  \tOptCamera = 'c',\n>  \tOptHelp = 'h',\n> -\tOptSize = 's',\n> +\tOptStream = 's',\n>  };\n>  \n>  class MainWindow : public QMainWindow\n> diff --git a/src/qcam/meson.build b/src/qcam/meson.build\n> index c256d06f8ccfc0ae..895264be4a3388f4 100644\n> --- a/src/qcam/meson.build\n> +++ b/src/qcam/meson.build\n> @@ -3,6 +3,7 @@ qcam_sources = files([\n>      'main.cpp',\n>      'main_window.cpp',\n>      '../cam/options.cpp',\n> +    '../cam/stream_options.cpp',\n>      'viewfinder.cpp',\n>  ])\n>","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 1904A613A8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Apr 2020 18:49:26 +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 76697321;\n\tThu, 30 Apr 2020 18:49:25 +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=\"IbsCtPkI\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1588265365;\n\tbh=XFh3sLG8b71nWH0JuV2xU1QWQ03Zv6O6GbNOPHSXdE0=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=IbsCtPkIaNt5VBi+25WpvQAldgtQv7rANKQbEPViYaw55ANggfLgjy3nTObn63eEf\n\tECE+fxuFpMKl7BNMgA/T7V6i80lL4feGwavz6aROSZ5CR2da+KIn5wnjEryGmwwKW5\n\tExlCLsZ7Q3AeTWcMmYay/6g7IaZl2W7zuRBTZVRE=","Date":"Thu, 30 Apr 2020 19:49:24 +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":"<20200430164924.GS5856@pendragon.ideasonboard.com>","References":"<20200427220529.1085074-1-niklas.soderlund@ragnatech.se>\n\t<20200427220529.1085074-6-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-6-niklas.soderlund@ragnatech.se>","Subject":"Re: [libcamera-devel] [PATCH v2 5/5] qcam: 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:49:26 -0000"}}]