{"id":3510,"url":"https://patchwork.libcamera.org/api/1.1/patches/3510/?format=json","web_url":"https://patchwork.libcamera.org/patch/3510/","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":"<20200424011656.2889720-3-niklas.soderlund@ragnatech.se>","date":"2020-04-24T01:16:55","name":"[libcamera-devel,2/3] cam: Make use of StreamOptionsParser","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"885fe74680e38a1bf217989dc3468db203619df2","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/1.1/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/3510/mbox/","series":[{"id":820,"url":"https://patchwork.libcamera.org/api/1.1/series/820/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=820","date":"2020-04-24T01:16:53","name":"{cam, qcam}: Unify stream option parsing","version":1,"mbox":"https://patchwork.libcamera.org/series/820/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3510/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3510/checks/","tags":{},"headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net\n\t[195.74.38.229])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AE5CB603F9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Apr 2020 03:17:06 +0200 (CEST)","from bismarck.berto.se (p4fca2392.dip0.t-ipconnect.de\n\t[79.202.35.146]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA\n\tid 495e2c41-85c9-11ea-aeed-005056917f90;\n\tFri, 24 Apr 2020 03:16:55 +0200 (CEST)"],"X-Halon-ID":"495e2c41-85c9-11ea-aeed-005056917f90","Authorized-sender":"niklas@soderlund.pp.se","From":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 24 Apr 2020 03:16:55 +0200","Message-Id":"<20200424011656.2889720-3-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.26.0","In-Reply-To":"<20200424011656.2889720-1-niklas.soderlund@ragnatech.se>","References":"<20200424011656.2889720-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 2/3] cam: Make use of StreamOptionsParser","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":"Fri, 24 Apr 2020 01:17:06 -0000"},"content":"Use the StreamOptionsParser helper to parse stream configuration from\nthe command line.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/cam/main.cpp | 77 +++++-------------------------------------------\n 1 file changed, 7 insertions(+), 70 deletions(-)","diff":"diff --git a/src/cam/main.cpp b/src/cam/main.cpp\nindex 718740f49762ec7b..b7cc206e6d5176db 100644\n--- a/src/cam/main.cpp\n+++ b/src/cam/main.cpp\n@@ -17,6 +17,7 @@\n #include \"event_loop.h\"\n #include \"main.h\"\n #include \"options.h\"\n+#include \"stream_options.h\"\n \n using namespace libcamera;\n \n@@ -42,7 +43,7 @@ private:\n \tint run();\n \n \tstatic CamApp *app_;\n-\tOptionsParser::Options options_;\n+\tStreamOptionsParser::Options options_;\n \tCameraManager *cm_;\n \tstd::shared_ptr<Camera> camera_;\n \tstd::unique_ptr<libcamera::CameraConfiguration> config_;\n@@ -153,18 +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-\n-\tOptionsParser parser;\n+\tStreamOptionsParser parser;\n \tparser.addOption(OptCamera, OptionString,\n \t\t\t \"Specify which camera to operate on, by name or by index\", \"camera\",\n \t\t\t ArgumentRequired, \"camera\");\n@@ -175,8 +165,7 @@ int CamApp::parseOptions(int argc, char *argv[])\n \t\t\t \"The first '#' character in the file name is expanded to the stream name and frame sequence number.\\n\"\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\", true);\n+\tparser.addStreamOptions(OptStream, \"stream\");\n \tparser.addOption(OptHelp, OptionNone, \"Display this help message\",\n \t\t\t \"help\");\n \tparser.addOption(OptInfo, OptionNone,\n@@ -199,67 +188,15 @@ 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-\t}\n-\n-\tconfig_ = camera_->generateConfiguration(roles);\n-\tif (!config_ || config_->size() != roles.size()) {\n+\tconfig_ = camera_->generateConfiguration(options_.roles());\n+\tif (!config_ || config_->size() != options_.roles().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 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+\toptions_.applyCameraParameters(config_.get());\n \n \tswitch (config_->validate()) {\n \tcase CameraConfiguration::Valid:\n","prefixes":["libcamera-devel","2/3"]}