Show a patch.

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

{
    "id": 2636,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/2636/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/2636/",
    "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": "<20200113164245.52535-23-jacopo@jmondi.org>",
    "date": "2020-01-13T16:42:44",
    "name": "[libcamera-devel,22/23] libcamera: control_serializer: Add support for compound controls",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "5bcf3d13cb6597aca12e1cdb1bff1ed76e572806",
    "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/2636/mbox/",
    "series": [
        {
            "id": 618,
            "url": "https://patchwork.libcamera.org/api/1.1/series/618/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=618",
            "date": "2020-01-13T16:42:22",
            "name": "Properties and compound controls",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/618/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/2636/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/2636/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<jacopo@jmondi.org>",
        "Received": [
            "from relay11.mail.gandi.net (relay11.mail.gandi.net\n\t[217.70.178.231])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9662D60700\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 13 Jan 2020 17:40:40 +0100 (CET)",
            "from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay11.mail.gandi.net (Postfix) with ESMTPSA id 30D90100003;\n\tMon, 13 Jan 2020 16:40:40 +0000 (UTC)"
        ],
        "From": "Jacopo Mondi <jacopo@jmondi.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 13 Jan 2020 17:42:44 +0100",
        "Message-Id": "<20200113164245.52535-23-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.24.0",
        "In-Reply-To": "<20200113164245.52535-1-jacopo@jmondi.org>",
        "References": "<20200113164245.52535-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 22/23] libcamera: control_serializer: Add\n\tsupport for compound controls",
        "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": "Mon, 13 Jan 2020 16:40:42 -0000"
    },
    "content": "Add support for serializing and deserializing control values which\ntransport compound values.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/control_serializer.cpp       | 123 ++++++++++++++++++---\n src/libcamera/include/control_serializer.h |  10 +-\n 2 files changed, 117 insertions(+), 16 deletions(-)",
    "diff": "diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp\nindex fd91baf15156..75e8ebc3d9d3 100644\n--- a/src/libcamera/control_serializer.cpp\n+++ b/src/libcamera/control_serializer.cpp\n@@ -14,6 +14,7 @@\n #include <ipa/ipa_controls.h>\n #include <libcamera/control_ids.h>\n #include <libcamera/controls.h>\n+#include <libcamera/span.h>\n \n #include \"byte_stream_buffer.h\"\n #include \"log.h\"\n@@ -30,11 +31,15 @@ LOG_DEFINE_CATEGORY(Serializer)\n namespace {\n \n static constexpr size_t ControlValueSize[] = {\n-\t[ControlTypeNone]\t= 1,\n-\t[ControlTypeBool]\t= sizeof(bool),\n-\t[ControlTypeInteger32]\t= sizeof(int32_t),\n-\t[ControlTypeInteger64]\t= sizeof(int64_t),\n-\t[ControlTypeFloat]\t= sizeof(float),\n+\t[ControlTypeNone]\t\t= 1,\n+\t[ControlTypeBool]\t\t= sizeof(bool),\n+\t[ControlTypeInteger32]\t\t= sizeof(int32_t),\n+\t[ControlTypeInteger64]\t\t= sizeof(int64_t),\n+\t[ControlTypeFloat]\t\t= sizeof(float),\n+\t[ControlTypeCompoundBool]\t= sizeof(bool),\n+\t[ControlTypeCompoundInt32]\t= sizeof(int32_t),\n+\t[ControlTypeCompoundInt64]\t= sizeof(int64_t),\n+\t[ControlTypeCompoundFloat]\t= sizeof(float),\n };\n \n } /* namespace */\n@@ -107,7 +112,7 @@ void ControlSerializer::reset()\n \n size_t ControlSerializer::binarySize(const ControlValue &value)\n {\n-\treturn ControlValueSize[value.type()];\n+\treturn ControlValueSize[value.type()] * value.numElements();\n }\n \n size_t ControlSerializer::binarySize(const ControlRange &range)\n@@ -183,6 +188,30 @@ void ControlSerializer::store(const ControlValue &value,\n \t\tbreak;\n \t}\n \n+\tcase ControlTypeCompoundBool: {\n+\t\tSpan<bool> data = value.get<Span<bool>>();\n+\t\tbuffer.write(&data);\n+\t\tbreak;\n+\t}\n+\n+\tcase ControlTypeCompoundInt32: {\n+\t\tSpan<int32_t> data = value.get<Span<int32_t>>();\n+\t\tbuffer.write(data);\n+\t\tbreak;\n+\t}\n+\n+\tcase ControlTypeCompoundInt64: {\n+\t\tSpan<int64_t> data = value.get<Span<int64_t>>();\n+\t\tbuffer.write(data);\n+\t\tbreak;\n+\t}\n+\n+\tcase ControlTypeCompoundFloat: {\n+\t\tSpan<float> data = value.get<Span<float>>();\n+\t\tbuffer.write(data);\n+\t\tbreak;\n+\t}\n+\n \tdefault:\n \t\tbreak;\n \t}\n@@ -318,7 +347,7 @@ int ControlSerializer::serialize(const ControlList &list,\n \n \t\tstruct ipa_control_value_entry entry;\n \t\tentry.id = id;\n-\t\tentry.count = 1;\n+\t\tentry.count = value.numElements();\n \t\tentry.type = value.type();\n \t\tentry.offset = values.offset();\n \t\tentries.write(&entry);\n@@ -332,35 +361,74 @@ int ControlSerializer::serialize(const ControlList &list,\n \treturn 0;\n }\n \n+template<typename T>\n+void ControlSerializer::loadData(ByteStreamBuffer &buffer, unsigned int count,\n+\t\t\t\t ControlValue *value)\n+{\n+\tSpan<T> data(new T[count], count);\n+\tbuffer.read(&data);\n+\n+\t/*\n+\t * Use of ControlValue::set() guarantees the memory content\n+\t * is copied into the ControlValue.\n+\t */\n+\tvalue->set(data);\n+}\n+\n template<>\n ControlValue ControlSerializer::load<ControlValue>(ControlType type,\n-\t\t\t\t\t\t   ByteStreamBuffer &b)\n+\t\t\t\t\t\t   ByteStreamBuffer &buffer,\n+\t\t\t\t\t\t   unsigned int count)\n {\n \tswitch (type) {\n \tcase ControlTypeBool: {\n \t\tbool value;\n-\t\tb.read(&value);\n+\t\tbuffer.read(&value);\n \t\treturn ControlValue(value);\n \t}\n \n \tcase ControlTypeInteger32: {\n \t\tint32_t value;\n-\t\tb.read(&value);\n+\t\tbuffer.read(&value);\n \t\treturn ControlValue(value);\n \t}\n \n \tcase ControlTypeInteger64: {\n \t\tint64_t value;\n-\t\tb.read(&value);\n+\t\tbuffer.read(&value);\n \t\treturn ControlValue(value);\n \t}\n \n \tcase ControlTypeFloat: {\n \t\tfloat value;\n-\t\tb.read(&value);\n+\t\tbuffer.read(&value);\n \t\treturn ControlValue(value);\n \t}\n \n+\tcase ControlTypeCompoundBool: {\n+\t\tControlValue value;\n+\t\tloadData<bool>(buffer, count, &value);\n+\t\treturn value;\n+\t}\n+\n+\tcase ControlTypeCompoundInt32: {\n+\t\tControlValue value;\n+\t\tloadData<int32_t>(buffer, count, &value);\n+\t\treturn value;\n+\t}\n+\n+\tcase ControlTypeCompoundInt64: {\n+\t\tControlValue value;\n+\t\tloadData<int64_t>(buffer, count, &value);\n+\t\treturn value;\n+\t}\n+\n+\tcase ControlTypeCompoundFloat: {\n+\t\tControlValue value;\n+\t\tloadData<float>(buffer, count, &value);\n+\t\treturn value;\n+\t}\n+\n \tdefault:\n \t\treturn ControlValue();\n \t}\n@@ -370,8 +438,32 @@ template<>\n ControlRange ControlSerializer::load<ControlRange>(ControlType type,\n \t\t\t\t\t\t   ByteStreamBuffer &b)\n {\n-\tControlValue min = load<ControlValue>(type, b);\n-\tControlValue max = load<ControlValue>(type, b);\n+\t/*\n+\t * The 'type' parameter represents the type of the Control\n+\t * the ControlRange refers to. Even if the Control is a compound,\n+\t * its range elements are not: adjust the type opportunely.\n+\t */\n+\tControlType rangeType;\n+\tswitch (type) {\n+\tcase ControlTypeCompoundBool:\n+\t\trangeType = ControlTypeBool;\n+\t\tbreak;\n+\tcase ControlTypeCompoundInt32:\n+\t\trangeType = ControlTypeInteger32;\n+\t\tbreak;\n+\tcase ControlTypeCompoundInt64:\n+\t\trangeType = ControlTypeInteger64;\n+\t\tbreak;\n+\tcase ControlTypeCompoundFloat:\n+\t\trangeType = ControlTypeFloat;\n+\t\tbreak;\n+\tdefault:\n+\t\trangeType = type;\n+\t\tbreak;\n+\t}\n+\n+\tControlValue min = load<ControlValue>(rangeType, b);\n+\tControlValue max = load<ControlValue>(rangeType, b);\n \n \treturn ControlRange(min, max);\n }\n@@ -519,7 +611,8 @@ ControlList ControlSerializer::deserialize<ControlList>(ByteStreamBuffer &buffer\n \t\t}\n \n \t\tControlType type = static_cast<ControlType>(entry.type);\n-\t\tctrls.set(entry.id, load<ControlValue>(type, values));\n+\t\tctrls.set(entry.id,\n+\t\t\t  load<ControlValue>(type, values, entry.count));\n \t}\n \n \treturn ctrls;\ndiff --git a/src/libcamera/include/control_serializer.h b/src/libcamera/include/control_serializer.h\nindex 55259913a2ca..2d76ffe7ed84 100644\n--- a/src/libcamera/include/control_serializer.h\n+++ b/src/libcamera/include/control_serializer.h\n@@ -10,6 +10,7 @@\n #include <map>\n #include <memory>\n #include <vector>\n+#include <type_traits>\n \n #include <libcamera/controls.h>\n \n@@ -40,8 +41,15 @@ private:\n \tstatic void store(const ControlValue &value, ByteStreamBuffer &buffer);\n \tstatic void store(const ControlRange &range, ByteStreamBuffer &buffer);\n \n+\ttemplate<typename T,\n+\t\t typename std::enable_if<std::is_same<ControlValue, T>::value>::type * = nullptr>\n+\tT load(ControlType type, ByteStreamBuffer &buffer, unsigned int count = 1);\n+\ttemplate<typename T,\n+\t\t typename std::enable_if<std::is_same<ControlRange, T>::value>::type * = nullptr>\n+\tT load(ControlType type, ByteStreamBuffer &buffer);\n \ttemplate<typename T>\n-\tT load(ControlType type, ByteStreamBuffer &b);\n+\tvoid loadData(ByteStreamBuffer &buffer, unsigned int count,\n+\t\t      ControlValue *value);\n \n \tunsigned int serial_;\n \tstd::vector<std::unique_ptr<ControlId>> controlIds_;\n",
    "prefixes": [
        "libcamera-devel",
        "22/23"
    ]
}