From patchwork Tue Mar 16 15:52:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marian Cichy X-Patchwork-Id: 11593 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 050FCBD80C for ; Tue, 16 Mar 2021 15:52:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CC72068D50; Tue, 16 Mar 2021 16:52:30 +0100 (CET) Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9BED368D49 for ; Tue, 16 Mar 2021 16:52:27 +0100 (CET) Received: from dude02.hi.pengutronix.de ([2001:67c:670:100:1d::28]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lMBze-0000V3-SW; Tue, 16 Mar 2021 16:52:26 +0100 Received: from mci by dude02.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1lMBze-0003Dd-IZ; Tue, 16 Mar 2021 16:52:26 +0100 From: Marian Cichy To: libcamera-devel@lists.libcamera.org Date: Tue, 16 Mar 2021 16:52:08 +0100 Message-Id: <20210316155211.6679-4-m.cichy@pengutronix.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210316155211.6679-1-m.cichy@pengutronix.de> References: <20210316155211.6679-1-m.cichy@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::28 X-SA-Exim-Mail-From: mci@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: libcamera-devel@lists.libcamera.org Subject: [libcamera-devel] [RFC PATCH 3/6] libcamera: v4l2_subdevice: Add methods to get/set frame interval 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: , Cc: graphics@pengutronix.de, Marian Cichy Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add API-methods to get and set the frame interval on V4L2-subdevices. Signed-off-by: Marian Cichy --- include/libcamera/internal/v4l2_subdevice.h | 4 ++ src/libcamera/v4l2_subdevice.cpp | 43 +++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index d2b9ca55..310746d9 100644 --- a/include/libcamera/internal/v4l2_subdevice.h +++ b/include/libcamera/internal/v4l2_subdevice.h @@ -12,6 +12,7 @@ #include #include +#include #include #include "libcamera/internal/formats.h" @@ -60,6 +61,9 @@ public: int setFormat(unsigned int pad, V4L2SubdeviceFormat *format, Whence whence = ActiveFormat); + int getFrameInterval(unsigned int pad, Fraction *frameInterval); + int setFrameInterval(unsigned int pad, Fraction *frameInterval); + static std::unique_ptr fromEntityName(const MediaDevice *media, const std::string &entity); diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 721ff5a9..eac2d7d3 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include "libcamera/internal/log.h" @@ -440,6 +441,48 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format, return 0; } +int V4L2Subdevice::getFrameInterval(unsigned int pad, Fraction *frameInterval) +{ + struct v4l2_subdev_frame_interval subdevFrameInterval = {}; + subdevFrameInterval.pad = pad; + + int ret = ioctl(VIDIOC_SUBDEV_G_FRAME_INTERVAL, &subdevFrameInterval); + if (ret) { + LOG(V4L2, Debug) + << "Unable to get frame interval on pad " << pad + << ": " << strerror(-ret); + return ret; + } + + frameInterval->numerator = subdevFrameInterval.interval.numerator; + frameInterval->denominator = subdevFrameInterval.interval.denominator; + + return 0; +} + +int V4L2Subdevice::setFrameInterval(unsigned int pad, Fraction *frameInterval) +{ + struct v4l2_subdev_frame_interval subdevFrameInterval = {}; + struct v4l2_fract fract = { frameInterval->numerator, + frameInterval->denominator }; + + subdevFrameInterval.pad = pad; + subdevFrameInterval.interval = fract; + + int ret = ioctl(VIDIOC_SUBDEV_S_FRAME_INTERVAL, &subdevFrameInterval); + if (ret) { + LOG(V4L2, Debug) + << "Unable to set frame interval on pad " << pad + << ": " << strerror(-ret); + return ret; + } + + frameInterval->numerator = subdevFrameInterval.interval.numerator; + frameInterval->denominator = subdevFrameInterval.interval.denominator; + + return 0; +} + /** * \brief Create a new video subdevice instance from \a entity in media device * \a media