From patchwork Mon Mar 9 16:24:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 3072 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2338362928 for ; Mon, 9 Mar 2020 17:21:31 +0100 (CET) X-Originating-IP: 93.34.114.233 Received: from uno.lan (93-34-114-233.ip49.fastwebnet.it [93.34.114.233]) (Authenticated sender: jacopo@jmondi.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id E4C7D60016 for ; Mon, 9 Mar 2020 16:21:30 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 9 Mar 2020 17:24:11 +0100 Message-Id: <20200309162414.720306-9-jacopo@jmondi.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200309162414.720306-1-jacopo@jmondi.org> References: <20200309162414.720306-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 08/11] licamera: v4l2_device: Support reading U8 array controls X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Mar 2020 16:21:32 -0000 Add support to retrieve the value of array controls of type V4L2_CTRL_TYPE_U8. Signed-off-by: Jacopo Mondi --- src/libcamera/v4l2_device.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 950e6286b84d..464df6a1fe18 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -185,6 +185,22 @@ int V4L2Device::getControls(ControlList *ctrls) return -EINVAL; } + const struct v4l2_query_ext_ctrl &info = ctrlsInfo_[id]; + if (info.flags & V4L2_CTRL_FLAG_HAS_PAYLOAD) { + if (info.type != V4L2_CTRL_TYPE_U8) { + /* + * \todo Fail loudly to notify support for + * other array control types is not implemented. + */ + LOG(V4L2, Error) << "Unsupported type"; + return -EINVAL; + } + + size_t sizeBytes = info.elems * info.elem_size; + v4l2Ctrls[i].p_u8 = new uint8_t[sizeBytes]; + v4l2Ctrls[i].size = sizeBytes; + } + v4l2Ctrls[i].id = id; i++; } @@ -214,6 +230,16 @@ int V4L2Device::getControls(ControlList *ctrls) updateControls(ctrls, v4l2Ctrls, count); + /* Release memory reserved for array controls. */ + for (unsigned int i = 0; i < count; i++) { + unsigned int id = v4l2Ctrls[i].id; + const struct v4l2_query_ext_ctrl &info = ctrlsInfo_[id]; + + /* \todo Adjust to support more array control types. */ + if (info.flags & V4L2_CTRL_FLAG_HAS_PAYLOAD) + delete[] v4l2Ctrls[i].p_u8; + } + return ret; }