Patch Detail
Show a patch.
GET /api/patches/2645/?format=api
{ "id": 2645, "url": "https://patchwork.libcamera.org/api/patches/2645/?format=api", "web_url": "https://patchwork.libcamera.org/patch/2645/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/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": "<20200114163153.39167-1-jacopo@jmondi.org>", "date": "2020-01-14T16:31:53", "name": "[libcamera-devel,v1.1,22/23] libcamera: control_serializer: Add support for compound controls", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "97d06e2e0a2d883b262bd41c0e2a3c90fc17638b", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": { "id": 15, "url": "https://patchwork.libcamera.org/api/users/15/?format=api", "username": "jmondi", "first_name": "Jacopo", "last_name": "Mondi", "email": "jacopo@jmondi.org" }, "mbox": "https://patchwork.libcamera.org/patch/2645/mbox/", "series": [ { "id": 624, "url": "https://patchwork.libcamera.org/api/series/624/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=624", "date": "2020-01-14T16:31:53", "name": null, "version": 1, "mbox": "https://patchwork.libcamera.org/series/624/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/2645/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/2645/checks/", "tags": {}, "headers": { "Return-Path": "<jacopo@jmondi.org>", "Received": [ "from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net\n\t[217.70.183.196])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3CF106017C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 14 Jan 2020 17:29:50 +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 relay4-d.mail.gandi.net (Postfix) with ESMTPSA id A4EB1E0006;\n\tTue, 14 Jan 2020 16:29:49 +0000 (UTC)" ], "X-Originating-IP": "2.224.242.101", "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 14 Jan 2020 17:31:53 +0100", "Message-Id": "<20200114163153.39167-1-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.24.1", "In-Reply-To": "<20200113164245.52535-23-jacopo@jmondi.org>", "References": "<20200113164245.52535-23-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v1.1 22/23] libcamera: control_serializer:\n\tAdd support 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": "Tue, 14 Jan 2020 16:29:50 -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\nsa rightfully noticed by Laurent in offline discussion, there was quite a big\nleak in the code as the Span<> class does not enforce memory ownership, so the\nmemory location that is provided to it during data loading should be manually\nreleased.\n\nFix this by wrapping it in an unique_ptr<>\n\n void ControlSerializer::loadData(ByteStreamBuffer &buffer, unsigned int count,\n ControlValue *value)\n {\n- Span<T> data(new T[count], count);\n+ std::unique_ptr<T> mem(new T[count]);\n+ Span<T> data(mem.get(), count);\n buffer.read(&data);\n\n /*\n\n\nValgrind does not report leaks anymore by complains about unique_ptr<>\ndestructor getting confused.\n==38940== Mismatched free() / delete / delete []\n==38940== at 0x4839EAB: operator delete(void*) (vg_replace_malloc.c:586)\n==38940== by 0x4A02E6D: std::default_delete<int>::operator()(int*) const (unique_ptr.h:81)\n==38940== by 0x4A02BBC: std::unique_ptr<int, std::default_delete<int> >::~unique_ptr() (unique_ptr.h:284)\n==38940== by 0x49FEF84: void libcamera::ControlSerializer::loadData<int>(libcamera::ByteStreamBuffer&, unsigned int, libcamera::ControlValue*) (control_serializer.cpp:377)\n\nMight be a false positive as the heap is clean\n\n==38940== HEAP SUMMARY:\n==38940== in use at exit: 0 bytes in 0 blocks\n==38940== total heap usage: 4,497 allocs, 4,497 frees, 1,350,869 bytes allocated\n\n---\n src/libcamera/control_serializer.cpp | 124 ++++++++++++++++++---\n src/libcamera/include/control_serializer.h | 10 +-\n 2 files changed, 118 insertions(+), 16 deletions(-)\n\n--\n2.24.1", "diff": "diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp\nindex fd91baf15156..c24cb7a57195 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,75 @@ 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+\tstd::unique_ptr<T> mem(new T[count]);\n+\tSpan<T> data(mem.get(), 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 +439,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 +612,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", "v1.1", "22/23" ] }