Patch Detail
Show a patch.
GET /api/1.1/patches/1308/?format=api
{ "id": 1308, "url": "https://patchwork.libcamera.org/api/1.1/patches/1308/?format=api", "web_url": "https://patchwork.libcamera.org/patch/1308/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20190527001543.13593-15-niklas.soderlund@ragnatech.se>", "date": "2019-05-27T00:15:40", "name": "[libcamera-devel,14/17] cam: Move camera configuration preparation to CamApp", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "9217bf598a7c726f31cd2be9c245144cb266f898", "submitter": { "id": 5, "url": "https://patchwork.libcamera.org/api/1.1/people/5/?format=api", "name": "Niklas Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/1308/mbox/", "series": [ { "id": 328, "url": "https://patchwork.libcamera.org/api/1.1/series/328/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=328", "date": "2019-05-27T00:15:28", "name": "libcamera: Add support for format information and validation", "version": 1, "mbox": "https://patchwork.libcamera.org/series/328/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/1308/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/1308/checks/", "tags": {}, "headers": { "Return-Path": "<niklas.soderlund@ragnatech.se>", "Received": [ "from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net\n\t[195.74.38.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 35B6D61909\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 May 2019 02:16:14 +0200 (CEST)", "from bismarck.berto.se (unknown [89.233.230.99])\n\tby bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA\n\tid a0b8a676-8014-11e9-8ab4-005056917a89;\n\tMon, 27 May 2019 02:16:09 +0200 (CEST)" ], "X-Halon-ID": "a0b8a676-8014-11e9-8ab4-005056917a89", "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": "Mon, 27 May 2019 02:15:40 +0200", "Message-Id": "<20190527001543.13593-15-niklas.soderlund@ragnatech.se>", "X-Mailer": "git-send-email 2.21.0", "In-Reply-To": "<20190527001543.13593-1-niklas.soderlund@ragnatech.se>", "References": "<20190527001543.13593-1-niklas.soderlund@ragnatech.se>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 14/17] cam: Move camera configuration\n\tpreparation to CamApp", "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": "Mon, 27 May 2019 00:16:15 -0000" }, "content": "Most of the camera configuration preparation which is done in the\nCapture module is not specific to capturing and could be useful for\nother modules. Extract the generic parts to CamApp and do basic\npreparation of the configuration before passing it to modules.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/cam/capture.cpp | 84 ++++-----------------------------------------\n src/cam/capture.h | 7 ++--\n src/cam/main.cpp | 75 ++++++++++++++++++++++++++++++++++++++--\n 3 files changed, 83 insertions(+), 83 deletions(-)", "diff": "diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp\nindex a4aa44af25828f23..e455612b36238157 100644\n--- a/src/cam/capture.cpp\n+++ b/src/cam/capture.cpp\n@@ -15,8 +15,8 @@\n \n using namespace libcamera;\n \n-Capture::Capture(Camera *camera)\n-\t: camera_(camera), writer_(nullptr), last_(0)\n+Capture::Capture(Camera *camera, CameraConfiguration *config)\n+\t: camera_(camera), config_(config), writer_(nullptr), last_(0)\n {\n }\n \n@@ -29,13 +29,13 @@ int Capture::run(EventLoop *loop, const OptionsParser::Options &options)\n \t\treturn -ENODEV;\n \t}\n \n-\tret = prepareConfig(options);\n-\tif (ret) {\n-\t\tstd::cout << \"Failed to prepare camera configuration\" << std::endl;\n-\t\treturn -EINVAL;\n+\tstreamName_.clear();\n+\tfor (unsigned int index = 0; index < config_->size(); ++index) {\n+\t\tStreamConfiguration &cfg = config_->at(index);\n+\t\tstreamName_[cfg.stream()] = \"stream\" + std::to_string(index);\n \t}\n \n-\tret = camera_->configure(config_.get());\n+\tret = camera_->configure(config_);\n \tif (ret < 0) {\n \t\tstd::cout << \"Failed to configure camera\" << std::endl;\n \t\treturn ret;\n@@ -64,80 +64,10 @@ int Capture::run(EventLoop *loop, const OptionsParser::Options &options)\n \t}\n \n \tcamera_->freeBuffers();\n-\tconfig_.reset();\n \n \treturn ret;\n }\n \n-int Capture::prepareConfig(const OptionsParser::Options &options)\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\tif (!opt.isSet(\"role\")) {\n-\t\t\t\troles.push_back(StreamRole::VideoRecording);\n-\t\t\t} else if (opt[\"role\"].toString() == \"viewfinder\") {\n-\t\t\t\troles.push_back(StreamRole::Viewfinder);\n-\t\t\t} else if (opt[\"role\"].toString() == \"video\") {\n-\t\t\t\troles.push_back(StreamRole::VideoRecording);\n-\t\t\t} else if (opt[\"role\"].toString() == \"still\") {\n-\t\t\t\troles.push_back(StreamRole::StillCapture);\n-\t\t\t} else {\n-\t\t\t\tstd::cerr << \"Unknown stream role \"\n-\t\t\t\t\t << opt[\"role\"].toString() << 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-\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 = opt[\"pixelformat\"];\n-\t\t}\n-\t}\n-\n-\tstreamName_.clear();\n-\tfor (unsigned int index = 0; index < config_->size(); ++index) {\n-\t\tStreamConfiguration &cfg = config_->at(index);\n-\t\tstreamName_[cfg.stream()] = \"stream\" + std::to_string(index);\n-\t}\n-\n-\treturn 0;\n-}\n-\n int Capture::capture(EventLoop *loop)\n {\n \tint ret;\ndiff --git a/src/cam/capture.h b/src/cam/capture.h\nindex a97d1f44d229c214..1d4a25a84a51403b 100644\n--- a/src/cam/capture.h\n+++ b/src/cam/capture.h\n@@ -20,19 +20,18 @@\n class Capture\n {\n public:\n-\tCapture(libcamera::Camera *camera);\n+\tCapture(libcamera::Camera *camera,\n+\t\tlibcamera::CameraConfiguration *config);\n \n \tint run(EventLoop *loop, const OptionsParser::Options &options);\n private:\n-\tint prepareConfig(const OptionsParser::Options &options);\n-\n \tint capture(EventLoop *loop);\n \n \tvoid requestComplete(libcamera::Request *request,\n \t\t\t const std::map<libcamera::Stream *, libcamera::Buffer *> &buffers);\n \n \tlibcamera::Camera *camera_;\n-\tstd::unique_ptr<libcamera::CameraConfiguration> config_;\n+\tlibcamera::CameraConfiguration *config_;\n \n \tstd::map<libcamera::Stream *, std::string> streamName_;\n \tBufferWriter *writer_;\ndiff --git a/src/cam/main.cpp b/src/cam/main.cpp\nindex dbf04917bcc5aa38..338740d1512c7189 100644\n--- a/src/cam/main.cpp\n+++ b/src/cam/main.cpp\n@@ -33,19 +33,21 @@ public:\n \n private:\n \tint parseOptions(int argc, char *argv[]);\n+\tint prepareConfig();\n \tint run();\n \n \tstatic CamApp *app_;\n \tOptionsParser::Options options_;\n \tCameraManager *cm_;\n \tstd::shared_ptr<Camera> camera_;\n+\tstd::unique_ptr<libcamera::CameraConfiguration> config_;\n \tEventLoop *loop_;\n };\n \n CamApp *CamApp::app_ = nullptr;\n \n CamApp::CamApp()\n-\t: cm_(nullptr), camera_(nullptr), loop_(nullptr)\n+\t: cm_(nullptr), camera_(nullptr), config_(nullptr), loop_(nullptr)\n {\n \tCamApp::app_ = this;\n }\n@@ -90,6 +92,10 @@ int CamApp::init(int argc, char **argv)\n \t\t}\n \n \t\tstd::cout << \"Using camera \" << camera_->name() << std::endl;\n+\n+\t\tret = prepareConfig();\n+\t\tif (ret)\n+\t\t\treturn ret;\n \t}\n \n \tloop_ = new EventLoop(cm_->eventDispatcher());\n@@ -107,6 +113,8 @@ void CamApp::cleanup()\n \t\tcamera_.reset();\n \t}\n \n+\tconfig_.reset();\n+\n \tcm_->stop();\n }\n \n@@ -168,6 +176,69 @@ int CamApp::parseOptions(int argc, char *argv[])\n \treturn 0;\n }\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\tif (!opt.isSet(\"role\")) {\n+\t\t\t\troles.push_back(StreamRole::VideoRecording);\n+\t\t\t} else if (opt[\"role\"].toString() == \"viewfinder\") {\n+\t\t\t\troles.push_back(StreamRole::Viewfinder);\n+\t\t\t} else if (opt[\"role\"].toString() == \"video\") {\n+\t\t\t\troles.push_back(StreamRole::VideoRecording);\n+\t\t\t} else if (opt[\"role\"].toString() == \"still\") {\n+\t\t\t\troles.push_back(StreamRole::StillCapture);\n+\t\t\t} else {\n+\t\t\t\tstd::cerr << \"Unknown stream role \"\n+\t\t\t\t\t << opt[\"role\"].toString() << 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+\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 = opt[\"pixelformat\"];\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n int CamApp::run()\n {\n \tif (options_.isSet(OptList)) {\n@@ -177,7 +248,7 @@ int CamApp::run()\n \t}\n \n \tif (options_.isSet(OptCapture)) {\n-\t\tCapture capture(camera_.get());\n+\t\tCapture capture(camera_.get(), config_.get());\n \t\treturn capture.run(loop_, options_);\n \t}\n \n", "prefixes": [ "libcamera-devel", "14/17" ] }