Show a patch.

GET /api/1.1/patches/1444/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 1444,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/1444/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/1444/",
    "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": "<20190616133402.21934-14-niklas.soderlund@ragnatech.se>",
    "date": "2019-06-16T13:33:59",
    "name": "[libcamera-devel,v3,13/16] 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/1444/mbox/",
    "series": [
        {
            "id": 358,
            "url": "https://patchwork.libcamera.org/api/1.1/series/358/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=358",
            "date": "2019-06-16T13:33:46",
            "name": "libcamera: Add support for format information and validation",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/358/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/1444/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/1444/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 71E3964789\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 16 Jun 2019 15:35:41 +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 9ae935d7-903b-11e9-8ab4-005056917a89;\n\tSun, 16 Jun 2019 15:35:29 +0200 (CEST)"
        ],
        "X-Halon-ID": "9ae935d7-903b-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": "Sun, 16 Jun 2019 15:33:59 +0200",
        "Message-Id": "<20190616133402.21934-14-niklas.soderlund@ragnatech.se>",
        "X-Mailer": "git-send-email 2.21.0",
        "In-Reply-To": "<20190616133402.21934-1-niklas.soderlund@ragnatech.se>",
        "References": "<20190616133402.21934-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 13/16] 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": "Sun, 16 Jun 2019 13:35:41 -0000"
    },
    "content": "Most of the camera configuration preparation that 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>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\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 f03a9faf87fac865..c9ae22df5f9f123b 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",
        "v3",
        "13/16"
    ]
}