{"id":3646,"url":"https://patchwork.libcamera.org/api/1.1/patches/3646/?format=json","web_url":"https://patchwork.libcamera.org/patch/3646/","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":"<20200501023432.90032-5-niklas.soderlund@ragnatech.se>","date":"2020-05-01T02:34:30","name":"[libcamera-devel,v3,4/6] cam: Make use of StreamKeyValueParser","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"a87820ef5756cc3f2cab298d779dd71870fa6e74","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/3646/mbox/","series":[{"id":864,"url":"https://patchwork.libcamera.org/api/1.1/series/864/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=864","date":"2020-05-01T02:34:27","name":"{cam, qcam}: Unify stream option parsing","version":3,"mbox":"https://patchwork.libcamera.org/series/864/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3646/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3646/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 AA816614C9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  1 May 2020 04:34:44 +0200 (CEST)","from bismarck.berto.se (p4fca2392.dip0.t-ipconnect.de\n\t[79.202.35.146]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA\n\tid 50003b78-8b54-11ea-89d0-0050569116f7;\n\tFri, 01 May 2020 04:34:42 +0200 (CEST)"],"X-Halon-ID":"50003b78-8b54-11ea-89d0-0050569116f7","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,  1 May 2020 04:34:30 +0200","Message-Id":"<20200501023432.90032-5-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.26.2","In-Reply-To":"<20200501023432.90032-1-niklas.soderlund@ragnatech.se>","References":"<20200501023432.90032-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 4/6] 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":"Fri, 01 May 2020 02:34:46 -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>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n* Changes since v2\n- Add log message\n---\n src/cam/main.cpp | 68 +++++-------------------------------------------\n 1 file changed, 7 insertions(+), 61 deletions(-)","diff":"diff --git a/src/cam/main.cpp b/src/cam/main.cpp\nindex ced4f567b8f38e00..2512fe9da782165b 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@@ -154,16 +155,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 +194,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-\t}\n+\tStreamRoles roles = StreamKeyValueParser::roles(options_[OptStream]);\n \n \tconfig_ = camera_->generateConfiguration(roles);\n \tif (!config_ || config_->size() != roles.size()) {\n@@ -243,25 +204,10 @@ 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+\tif (StreamKeyValueParser::updateConfiguration(config_.get(),\n+\t\t\t\t\t\t      options_[OptStream])) {\n+\t\tstd::cerr << \"Failed to update configuration\" << std::endl;\n+\t\treturn -EINVAL;\n \t}\n \n \tswitch (config_->validate()) {\n","prefixes":["libcamera-devel","v3","4/6"]}