From patchwork Sat Apr 4 00:44:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3380 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 29D64629B9 for ; Sat, 4 Apr 2020 02:44:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="pZr+jKT3"; dkim-atps=neutral Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 939E011C5; Sat, 4 Apr 2020 02:44:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1585961092; bh=c10gNrHAm+EO2q6JnAi1ds4eikzpT59BYjnc+NZNhs8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pZr+jKT3PoYkRsusCJg3iD7rVlOwRQvOqd+7Q6rDD+ueVaRbB/EEFrIQs6qLPVVel KXeAOkLBRIpgUsoq97POPLTmQ5mkntvogfyJps2E8HGGEa+p9W5AE4tTM/DjW+xagh 3eMTRsuM5YhiexvMRxN2X24Ag6U7bho6k1Bq/mso= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Martijn Braam , Benjamin GAIGNARD , Andrey Konovalov Date: Sat, 4 Apr 2020 03:44:30 +0300 Message-Id: <20200404004438.17992-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200404004438.17992-1-laurent.pinchart@ideasonboard.com> References: <20200404004438.17992-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 03/11] libcamera: v4l2_subdevice: Extend [gs]etFormat() to specify format type 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: Sat, 04 Apr 2020 00:44:54 -0000 The V4L2 subdevice API exposes ACTIVE and TRY formats, but the V4L2Subdevice getFormat() and setFormat() operations only apply on ACTIVE formats. Extend them to support TRY formats as well. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- Changes since v2: - Reference ActiveFormat and TryFormat correctly from documentation --- src/libcamera/include/v4l2_subdevice.h | 11 +++++++++-- src/libcamera/v4l2_subdevice.cpp | 25 +++++++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h index 9c077674f997..4a04eadfb1f9 100644 --- a/src/libcamera/include/v4l2_subdevice.h +++ b/src/libcamera/include/v4l2_subdevice.h @@ -32,6 +32,11 @@ struct V4L2SubdeviceFormat { class V4L2Subdevice : public V4L2Device { public: + enum Whence { + ActiveFormat, + TryFormat, + }; + explicit V4L2Subdevice(const MediaEntity *entity); V4L2Subdevice(const V4L2Subdevice &) = delete; V4L2Subdevice &operator=(const V4L2Subdevice &) = delete; @@ -46,8 +51,10 @@ public: ImageFormats formats(unsigned int pad); - int getFormat(unsigned int pad, V4L2SubdeviceFormat *format); - int setFormat(unsigned int pad, V4L2SubdeviceFormat *format); + int getFormat(unsigned int pad, V4L2SubdeviceFormat *format, + Whence whence = ActiveFormat); + int setFormat(unsigned int pad, V4L2SubdeviceFormat *format, + Whence whence = ActiveFormat); static V4L2Subdevice *fromEntityName(const MediaDevice *media, const std::string &entity); diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 8b9da81e8ab3..f554d2385fff 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -95,6 +95,15 @@ const std::string V4L2SubdeviceFormat::toString() const * any device left open will be closed, and any resources released. */ +/** + * \enum V4L2Subdevice::Whence + * \brief Specify the type of format for getFormat() and setFormat() operations + * \var V4L2Subdevice::ActiveFormat + * \brief The format operation applies to ACTIVE formats + * \var V4L2Subdevice::TryFormat + * \brief The format operation applies to TRY formats + */ + /** * \brief Create a V4L2 subdevice from a MediaEntity using its device node * path @@ -184,12 +193,16 @@ ImageFormats V4L2Subdevice::formats(unsigned int pad) * \brief Retrieve the image format set on one of the V4L2 subdevice pads * \param[in] pad The 0-indexed pad number the format is to be retrieved from * \param[out] format The image bus format + * \param[in] whence The format to get, \ref V4L2Subdevice::ActiveFormat + * "ActiveFormat" or \ref V4L2Subdevice::TryFormat "TryFormat" * \return 0 on success or a negative error code otherwise */ -int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format) +int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format, + Whence whence) { struct v4l2_subdev_format subdevFmt = {}; - subdevFmt.which = V4L2_SUBDEV_FORMAT_ACTIVE; + subdevFmt.which = whence == ActiveFormat ? V4L2_SUBDEV_FORMAT_ACTIVE + : V4L2_SUBDEV_FORMAT_TRY; subdevFmt.pad = pad; int ret = ioctl(VIDIOC_SUBDEV_G_FMT, &subdevFmt); @@ -211,6 +224,8 @@ int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format) * \brief Set an image format on one of the V4L2 subdevice pads * \param[in] pad The 0-indexed pad number the format is to be applied to * \param[inout] format The image bus format to apply to the subdevice's pad + * \param[in] whence The format to set, \ref V4L2Subdevice::ActiveFormat + * "ActiveFormat" or \ref V4L2Subdevice::TryFormat "TryFormat" * * Apply the requested image format to the desired media pad and return the * actually applied format parameters, as \ref V4L2Subdevice::getFormat would @@ -218,10 +233,12 @@ int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format) * * \return 0 on success or a negative error code otherwise */ -int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format) +int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format, + Whence whence) { struct v4l2_subdev_format subdevFmt = {}; - subdevFmt.which = V4L2_SUBDEV_FORMAT_ACTIVE; + subdevFmt.which = whence == ActiveFormat ? V4L2_SUBDEV_FORMAT_ACTIVE + : V4L2_SUBDEV_FORMAT_TRY; subdevFmt.pad = pad; subdevFmt.format.width = format->size.width; subdevFmt.format.height = format->size.height;