Show a patch.

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

{
    "id": 824,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/824/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/824/",
    "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": "<20190401101410.4984-2-jacopo@jmondi.org>",
    "date": "2019-04-01T10:14:09",
    "name": "[libcamera-devel,RFC,1/2] libcamera: stream: Implement StreamProperties",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "28bc9a152c9b3bc3322924a0ee4ecb572d1e30de",
    "submitter": {
        "id": 3,
        "url": "https://patchwork.libcamera.org/api/1.1/people/3/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo@jmondi.org"
    },
    "delegate": {
        "id": 15,
        "url": "https://patchwork.libcamera.org/api/1.1/users/15/?format=api",
        "username": "jmondi",
        "first_name": "Jacopo",
        "last_name": "Mondi",
        "email": "jacopo@jmondi.org"
    },
    "mbox": "https://patchwork.libcamera.org/patch/824/mbox/",
    "series": [
        {
            "id": 225,
            "url": "https://patchwork.libcamera.org/api/1.1/series/225/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=225",
            "date": "2019-04-01T10:14:08",
            "name": "libcamera: Implement stream properties",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/225/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/824/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/824/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<jacopo@jmondi.org>",
        "Received": [
            "from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net\n\t[217.70.183.201])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 20904600F9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  1 Apr 2019 12:13:38 +0200 (CEST)",
            "from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 9FF391BF207;\n\tMon,  1 Apr 2019 10:13:37 +0000 (UTC)"
        ],
        "X-Originating-IP": "2.224.242.101",
        "From": "Jacopo Mondi <jacopo@jmondi.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon,  1 Apr 2019 12:14:09 +0200",
        "Message-Id": "<20190401101410.4984-2-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.21.0",
        "In-Reply-To": "<20190401101410.4984-1-jacopo@jmondi.org>",
        "References": "<20190401101410.4984-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [RFC 1/2] libcamera: stream: Implement\n\tStreamProperties",
        "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, 01 Apr 2019 10:13:38 -0000"
    },
    "content": "Add definition for the StreamProperties and StreamUsage classes.\n\nUse them in the IPU3 pipeline handler to store stream-specific properties,\nand extend the StreamProperties base class with IPU3 specific\nparameters, such as the desired ImgU pipeline mode.\n\nAlso add an 'hints' field to StreamConfiguration to implement matching\nbetween the stream properties and a requested configuration.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/meson.build             |   1 +\n include/libcamera/stream.h                |   7 ++\n include/libcamera/stream_usages.h         |  20 ++++\n src/libcamera/include/stream_properties.h |  41 ++++++++\n src/libcamera/meson.build                 |   1 +\n src/libcamera/pipeline/ipu3/ipu3.cpp      |  45 ++++++++\n src/libcamera/stream.cpp                  |  25 +++++\n src/libcamera/stream_properties.cpp       | 121 ++++++++++++++++++++++\n 8 files changed, 261 insertions(+)\n create mode 100644 include/libcamera/stream_usages.h\n create mode 100644 src/libcamera/include/stream_properties.h\n create mode 100644 src/libcamera/stream_properties.cpp",
    "diff": "diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build\nindex 3f4d1e28208b..25901303b97d 100644\n--- a/include/libcamera/meson.build\n+++ b/include/libcamera/meson.build\n@@ -9,6 +9,7 @@ libcamera_api = files([\n     'request.h',\n     'signal.h',\n     'stream.h',\n+    'stream_usages.h',\n     'timer.h',\n ])\n \ndiff --git a/include/libcamera/stream.h b/include/libcamera/stream.h\nindex 970c479627fa..afcc4ff08923 100644\n--- a/include/libcamera/stream.h\n+++ b/include/libcamera/stream.h\n@@ -7,7 +7,10 @@\n #ifndef __LIBCAMERA_STREAM_H__\n #define __LIBCAMERA_STREAM_H__\n \n+#include <forward_list>\n+\n #include <libcamera/buffer.h>\n+#include <libcamera/stream_usages.h>\n \n namespace libcamera {\n \n@@ -19,6 +22,10 @@ struct StreamConfiguration {\n \tunsigned int pixelFormat;\n \n \tunsigned int bufferCount;\n+\n+\tstd::forward_list<enum StreamUsage> hints;\n+\n+\tbool supports(const enum StreamUsage &usage) const;\n };\n \n class Stream final\ndiff --git a/include/libcamera/stream_usages.h b/include/libcamera/stream_usages.h\nnew file mode 100644\nindex 000000000000..9f7358954181\n--- /dev/null\n+++ b/include/libcamera/stream_usages.h\n@@ -0,0 +1,20 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * stream_usages.h - Definition of stream usage hints\n+ */\n+#ifndef __LIBCAMERA_STREAM_USAGES_H__\n+#define __LIBCAMERA_STREAM_USAGES_H__\n+\n+namespace libcamera {\n+\n+enum StreamUsage {\n+\tVIEWFINDER,\n+\tVIDEO_RECORDING,\n+\tSTILL_CAPTURE,\n+};\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_STREAM_USAGES_H__ */\ndiff --git a/src/libcamera/include/stream_properties.h b/src/libcamera/include/stream_properties.h\nnew file mode 100644\nindex 000000000000..ced8bb931bf6\n--- /dev/null\n+++ b/src/libcamera/include/stream_properties.h\n@@ -0,0 +1,41 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * stream_properties.h - Properties associated with a camera stream\n+ */\n+\n+#ifndef __LIBCAMERA_STREAM_PROPERTIES_H__\n+#define __LIBCAMERA_STREAM_PROPERTIES_H__\n+\n+#include <forward_list>\n+#include <string>\n+\n+#include <libcamera/stream.h>\n+#include <libcamera/stream_usages.h>\n+\n+#include \"formats.h\"\n+\n+namespace libcamera {\n+\n+class StreamProperties {\n+public:\n+\tvirtual ~StreamProperties() { }\n+\n+\tvoid addUsage(const enum StreamUsage &usage);\n+\tvoid addFormat(unsigned int pixfmt, std::vector<SizeRange> sizes);\n+\n+\tconst std::string &name() const { return name_; }\n+\tvoid setName(const std::string &name);\n+\n+\tvirtual bool match(const StreamConfiguration &config) const;\n+\n+private:\n+\tstd::forward_list<enum StreamUsage> usages_;\n+\tFormatEnum formats_;\n+\tstd::string name_;\n+};\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_STREAM_USAGES_H__ */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 4433abfceca3..b00a34919c2c 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -16,6 +16,7 @@ libcamera_sources = files([\n     'request.cpp',\n     'signal.cpp',\n     'stream.cpp',\n+    'stream_properties.cpp',\n     'timer.cpp',\n     'v4l2_device.cpp',\n     'v4l2_subdevice.cpp',\ndiff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex 69b40aa0026b..46479944a4da 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -14,12 +14,14 @@\n #include <libcamera/camera.h>\n #include <libcamera/request.h>\n #include <libcamera/stream.h>\n+#include <libcamera/stream_usages.h>\n \n #include \"device_enumerator.h\"\n #include \"geometry.h\"\n #include \"log.h\"\n #include \"media_device.h\"\n #include \"pipeline_handler.h\"\n+#include \"stream_properties.h\"\n #include \"utils.h\"\n #include \"v4l2_device.h\"\n #include \"v4l2_subdevice.h\"\n@@ -28,6 +30,17 @@ namespace libcamera {\n \n LOG_DEFINE_CATEGORY(IPU3)\n \n+class IPU3StreamProperties : public StreamProperties\n+{\n+public:\n+\tstatic constexpr unsigned int IMGU_VIDEO_MODE = 0;\n+\tstatic constexpr unsigned int IMGU_STILL_MODE = 1;\n+\n+\t~IPU3StreamProperties() { }\n+\n+\tunsigned int pipelineMode;\n+};\n+\n static int mediaBusToCIO2Format(unsigned int code)\n {\n \tswitch (code) {\n@@ -222,6 +235,7 @@ private:\n \n \t\tStream outStream_;\n \t\tStream vfStream_;\n+\t\tstd::map<Stream *, IPU3StreamProperties> streamProps_;\n \n \t\t/* Absolute miniumum and maximum sizes. */\n \t\tSizeRange sizes_;\n@@ -811,6 +825,37 @@ int PipelineHandlerIPU3::registerCameras()\n \t\tdata->imgu_->viewfinder_->bufferReady.connect(data.get(),\n \t\t\t\t\t&IPU3CameraData::imguCaptureBufferReady);\n \n+\n+\t\t/*\n+\t\t * Prepare the enumerations of formats supported by the\n+\t\t * streams.\n+\t\t *\n+\t\t * \\todo: As of now, only support continous size ranges.\n+\t\t */\n+\t\tSizeRange &cio2MaxSize = cio2->maxSizes_.second;\n+\t\tSizeRange ipu3StreamSizes(1, 1, cio2MaxSize.maxWidth,\n+\t\t\t\t\t  cio2MaxSize.maxHeight);\n+\n+\t\t/* Fill in the properties for each supported stream. */\n+\t\tIPU3StreamProperties outputStreamProps;\n+\t\toutputStreamProps.setName(\"output\");\n+\t\toutputStreamProps.addUsage(STILL_CAPTURE);\n+\t\toutputStreamProps.addFormat(V4L2_PIX_FMT_NV12,\n+\t\t\t\t\t    { ipu3StreamSizes } );\n+\t\toutputStreamProps.pipelineMode =\n+\t\t\tIPU3StreamProperties::IMGU_STILL_MODE;\n+\t\tdata->streamProps_[&data->outStream_] = outputStreamProps;\n+\n+\t\tIPU3StreamProperties viewfinderStreamProps;\n+\t\tviewfinderStreamProps.setName(\"viewfinder\");\n+\t\tviewfinderStreamProps.addUsage(VIEWFINDER);\n+\t\tviewfinderStreamProps.addUsage(VIDEO_RECORDING);\n+\t\tviewfinderStreamProps.addFormat(V4L2_PIX_FMT_NV12,\n+\t\t\t\t\t\t{ ipu3StreamSizes } );\n+\t\toutputStreamProps.pipelineMode =\n+\t\t\tIPU3StreamProperties::IMGU_VIDEO_MODE;\n+\t\tdata->streamProps_[&data->vfStream_] = viewfinderStreamProps;\n+\n \t\t/* Create and register the Camera instance. */\n \t\tstd::string cameraName = cio2->name() + \" \"\n \t\t\t\t       + std::to_string(id);\ndiff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp\nindex c4943c91b2e6..7b8d6ac4f895 100644\n--- a/src/libcamera/stream.cpp\n+++ b/src/libcamera/stream.cpp\n@@ -60,6 +60,31 @@ namespace libcamera {\n  * \\brief Requested number of buffers to allocate for the stream\n  */\n \n+/**\n+ * \\var StreamConfiguration::hints\n+ * \\brief List of intended stream usages\n+ *\n+ * This field represents a list of intended stream usage hints. It is set\n+ * by applications when requesting the stream's default configurations with\n+ * Camera::streamConfiguration() method.\n+ */\n+\n+/**\n+ * \\brief Verify if a stream configuration supports a \\a usage\n+ * \\param[in] usage The stream usage to verify\n+ *\n+ * \\return True if the usage is supported, false otherwise\n+ */\n+bool StreamConfiguration::supports(const enum StreamUsage &usage) const\n+{\n+\tfor (const enum StreamUsage &hint : hints) {\n+\t\tif (hint == usage)\n+\t\t\treturn true;\n+\t}\n+\n+\treturn false;\n+}\n+\n /**\n  * \\class Stream\n  * \\brief Video stream for a camera\ndiff --git a/src/libcamera/stream_properties.cpp b/src/libcamera/stream_properties.cpp\nnew file mode 100644\nindex 000000000000..582b314b7bb6\n--- /dev/null\n+++ b/src/libcamera/stream_properties.cpp\n@@ -0,0 +1,121 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * stream_properties.cpp - Properties associated with a camera stream\n+ */\n+\n+#include <libcamera/stream.h>\n+\n+#include \"log.h\"\n+#include \"stream_properties.h\"\n+\n+namespace libcamera {\n+\n+LOG_DEFINE_CATEGORY(PROPS)\n+\n+/**\n+ * \\class StreamProperties\n+ * \\brief Collect a stream characteristics and matches them against a\n+ * requested stream configuration\n+ *\n+ * The StreamProperties class collects all the informations related to a\n+ * Stream capabilities, including its name, the list of supported formats and\n+ * sizes and the list of intended usages of the streams.\n+ *\n+ * Streams are created by pipeline handlers, and their static properties are\n+ * represented by instances of this class, which pipeline handlers should\n+ * internally associate with each of its streams.\n+ *\n+ * The stream properties can be matched against a requested stream\n+ * configuration, and this operations is usually performed by pipeline\n+ * handlers trying to satisfy an application request at\n+ * PipelineHander::streamConfiguration() time, where a list of\n+ * StreamConfiguration instances gets associated with a list of Streams.\n+ *\n+ * Pipeline handlers are free to sub-class StreamProperties to extend them\n+ * and add platform-specific informations, as StreamProperties are not exposed\n+ * to applications nor in the public library interface (for this reason, there\n+ * is not direct dependencies between this class and the Stream one, which is\n+ * publicly exposed and directly used by applications). The additional\n+ * platform specific informations shall be used in the stream matching procedure\n+ * or to store pipeline specific configuration parameters associated with a\n+ * stream.\n+ */\n+\n+/**\n+ * \\brief Add a usage hint to the stream property\n+ * \\param[in] usage The usage hint\n+ */\n+void StreamProperties::addUsage(const enum StreamUsage &usage)\n+{\n+\tusages_.push_front(usage);\n+}\n+\n+/**\n+ * \\brief Add a list of supported sizes associated with a pixel format\n+ * \\param[in] pixfmt The pixel format\n+ * \\param[in] sizes The list of size ranges\n+ */\n+void StreamProperties::addFormat(unsigned int pixfmt,\n+\t\t\t\t std::vector<SizeRange> sizes)\n+{\n+\tif (formats_.find(pixfmt) != formats_.end())\n+\t\tLOG(PROPS, Error) << \"Overwriting sizes associated with format \"\n+\t\t\t\t  << pixfmt;\n+\n+\tformats_[pixfmt] = sizes;\n+}\n+\n+/**\n+ * \\fn StreamProperties::name()\n+ * \\brief Retrieve the stream name\n+ *\n+ * \\return The stream name\n+ */\n+\n+/**\n+ * \\brief Set the stream name\n+ * \\param[in] name The stream name\n+ */\n+void StreamProperties::setName(const std::string &name)\n+{\n+\tname_ = name;\n+}\n+\n+/**\n+ * \\brief Compare the properties of a stream with a stream configuration request\n+ * \\param[in] config The requested stream configuration\n+ *\n+ * This helper method compares the properties of a stream with a stream\n+ * requested configuration. Its intended users are pipeline handlers that\n+ * receive stream configurations and try to match them with a stream that\n+ * satisfies the request parameters.\n+ *\n+ * A StreamProperties satisfies the requested \\a config when:\n+ * 1) The requested pixel format is listed in the property's formats map;\n+ * 2) The requested sizes are included in the supported size intervals list in\n+ * the property's formats map;\n+ * 3) At least one of the requested usage hints is reported in the property's\n+ * list of intended usages;\n+ *\n+ * If all the above criteria as satisfied, the helper return true and the\n+ * stream associated with the property matches the requested configuration.\n+ *\n+ * \\return True if the stream's properties satisfy the requested configuration,\n+ * false otherwise\n+ */\n+bool StreamProperties::match(const StreamConfiguration &config) const\n+{\n+\t/* \\todo: as a proof of concept, right now only match on 'hints'. */\n+\tfor (const enum StreamUsage &usage : usages_) {\n+\t\tfor (const enum StreamUsage &hint : config.hints) {\n+\t\t\tif (usage == hint)\n+\t\t\t\treturn true;\n+\t\t}\n+\t}\n+\n+\treturn false;\n+}\n+\n+} /* namespace libcamera */\n",
    "prefixes": [
        "libcamera-devel",
        "RFC",
        "1/2"
    ]
}