From patchwork Thu Apr 14 07:43:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kate Hsuan X-Patchwork-Id: 15672 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 8C37EC3260 for ; Thu, 14 Apr 2022 07:44:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 00D746564C; Thu, 14 Apr 2022 09:44:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1649922248; bh=PyW+bGU1SmxQjx/hYyZl+q7hgY6meSbOypmRASKhcy8=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Vwf9xFkj0LW8prHUfJyfW5I8KUN9T4Col5cJgTTGBfakuNvu3ACjkq2ArTv+p8hVl kzia3HYQVT5OlEplLlv2hW/9dCOQ1RYWY3Exf0QUwtUIYX/70MCwmainjuGIXP1Y+A YOuauJKy+pUzPFihS5lBCsFg2PSyGhtYLhs22t4LZ03bhhPcdJYAeEQq/qug+m3i2E wvwP8aojaXh7kjd8kq2v950lLYK7o/3NIZALom0RxdJcRNv1HIQeGCYT43yQ6UlZie GPur+lOmoVqhKRVk2dnTCJt42dN4vXk3WWPVYqGiunNQ0ohan50noXF74oXVAcjdD+ nUu3oBrt+aImQ== Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1E28965645 for ; Thu, 14 Apr 2022 09:44:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="OEMK4Plp"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649922245; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tC/C2lez66xZ9LADfw7zvXSambvgPNfB4konHKWScS8=; b=OEMK4Plp7dPmQUqcno9bfQoLriMWypO6qlkm4IQKpGRdKVy3QWfULhk8uI/7sBKO0ou4JY BVwr8yN2DcAd2NBk64WYPyFpuqfb+4c6womvdzDWiFya27s9lRU8fvXCPsAXVSq7HarFFC 6NImy/P4BXx0WVFAGl82DOTZNfeJaP8= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-453-CIYn7r2HO0eu6ru3OwQXbA-1; Thu, 14 Apr 2022 03:44:04 -0400 X-MC-Unique: CIYn7r2HO0eu6ru3OwQXbA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 87A983C02B60 for ; Thu, 14 Apr 2022 07:44:04 +0000 (UTC) Received: from fedora.rhtw.internal (unknown [10.39.193.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC0E9111E3EA; Thu, 14 Apr 2022 07:44:02 +0000 (UTC) To: libcamera devel Date: Thu, 14 Apr 2022 15:43:38 +0800 Message-Id: <20220414074342.7455-2-hpa@redhat.com> In-Reply-To: <20220414074342.7455-1-hpa@redhat.com> References: <20220414074342.7455-1-hpa@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=hpa@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [libcamera-devel] [RFC v1 1/5] libcamera: v4l2_device: VIDIOC_QUERYCTRL call to fetch device attributes 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-Patchwork-Original-From: Kate Hsuan via libcamera-devel From: Kate Hsuan Reply-To: Kate Hsuan Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" VIDIOC_QUERYCTRL can be used to get the device attributes. It can be used to get the attributes for a given control list and store them in it. Fianlly, the maximum capacity of the device can be found in the control list. Signed-off-by: Kate Hsuan --- include/libcamera/internal/v4l2_device.h | 2 ++ src/libcamera/v4l2_device.cpp | 37 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h index a52a5f2c..d93a72a0 100644 --- a/include/libcamera/internal/v4l2_device.h +++ b/include/libcamera/internal/v4l2_device.h @@ -37,6 +37,8 @@ public: ControlList getControls(const std::vector &ids); int setControls(ControlList *ctrls); + int getAttributes(ControlList *ctrls); + const struct v4l2_query_ext_ctrl *controlInfo(uint32_t id) const; const std::string &deviceNode() const { return deviceNode_; } diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 3fc8438f..eda429be 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -364,6 +364,43 @@ int V4L2Device::setControls(ControlList *ctrls) return ret; } +/** + * \brief Get capacity for a given control list + * + * This function will get device maximum capacity through VIDIOC_QUERYCTRL and + * store the maximum value to the \a ctrls. If a non-support control is found, + * it will return -EINVAL. + * + * \param ctrls The list of controls to get the capacity + * \return 0 or non-zero on success or a empty control list + * \retval -EINVAL One of the control is not supported or not accessible + */ +int V4L2Device::getAttributes(ControlList *ctrls) +{ + int ret = 0; + if (ctrls->empty()) + return 0; + + struct v4l2_queryctrl query_ctrl; + for (auto [ctrl, i] = std::pair(ctrls->begin(), 0u); i < ctrls->size(); ctrl++, i++) { + const unsigned int id = ctrl->first; + const auto iter = controls_.find(id); + if (iter == controls_.end()) { + LOG(V4L2, Error) + << "Control " << utils::hex(id) << " not found"; + return -EINVAL; + } + + memset(&query_ctrl, 0, sizeof(struct v4l2_queryctrl)); + query_ctrl.id = id; + query_ctrl.type = V4L2_CTRL_TYPE_INTEGER; + ret = ioctl(VIDIOC_QUERYCTRL, &query_ctrl); + ctrls->set(id, query_ctrl.maximum); + } + + return ret; +} + /** * \brief Retrieve the v4l2_query_ext_ctrl information for the given control * \param[in] id The V4L2 control id