From patchwork Mon Apr 27 21:32:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 3570 Return-Path: Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DEC3860AFA for ; Mon, 27 Apr 2020 23:29:32 +0200 (CEST) X-Originating-IP: 212.216.150.148 Received: from uno.homenet.telecomitalia.it (a-ur1-85.tin.it [212.216.150.148]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 2DA5140009; Mon, 27 Apr 2020 21:29:31 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 27 Apr 2020 23:32:30 +0200 Message-Id: <20200427213236.333777-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200427213236.333777-1-jacopo@jmondi.org> References: <20200427213236.333777-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 1/7] libcamera: v4l2_subdevice: Expose setSelection() 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, 27 Apr 2020 21:29:33 -0000 Expose V4L2Subdevice::setSelection() method and drop V4L2Subdevice::setCrop() and V4L2Subdevice::setComopse() as wrapping each target with a single function does not provide any benefit. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/libcamera/include/v4l2_subdevice.h | 7 +-- src/libcamera/pipeline/ipu3/ipu3.cpp | 4 +- src/libcamera/v4l2_subdevice.cpp | 76 ++++++++++---------------- 3 files changed, 34 insertions(+), 53 deletions(-) diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h index 4a04eadfb1f9..9a5c812db9b6 100644 --- a/src/libcamera/include/v4l2_subdevice.h +++ b/src/libcamera/include/v4l2_subdevice.h @@ -46,8 +46,8 @@ public: const MediaEntity *entity() const { return entity_; } - int setCrop(unsigned int pad, Rectangle *rect); - int setCompose(unsigned int pad, Rectangle *rect); + int setSelection(unsigned int pad, unsigned int target, + Rectangle *rect); ImageFormats formats(unsigned int pad); @@ -67,9 +67,6 @@ private: std::vector enumPadSizes(unsigned int pad, unsigned int code); - int setSelection(unsigned int pad, unsigned int target, - Rectangle *rect); - const MediaEntity *entity_; }; diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index b45900159d06..ff33f15f9eac 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -1135,11 +1135,11 @@ int ImgUDevice::configureInput(const Size &size, .width = inputFormat->size.width, .height = inputFormat->size.height, }; - ret = imgu_->setCrop(PAD_INPUT, &rect); + ret = imgu_->setSelection(PAD_INPUT, V4L2_SEL_TGT_CROP, &rect); if (ret) return ret; - ret = imgu_->setCompose(PAD_INPUT, &rect); + ret = imgu_->setSelection(PAD_INPUT, V4L2_SEL_TGT_COMPOSE, &rect); if (ret) return ret; diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 5a479a96b795..432e89eacbd3 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -134,27 +134,42 @@ int V4L2Subdevice::open() */ /** - * \brief Set a crop rectangle on one of the V4L2 subdevice pads + * \brief Set selection rectangle \a rect for \a target * \param[in] pad The 0-indexed pad number the rectangle is to be applied to - * \param[inout] rect The rectangle describing crop target area + * \param[in] target The selection target defined by the V4L2_SEL_TGT_* flags + * \param[inout] rect The selection rectangle to be applied * \return 0 on success or a negative error code otherwise */ -int V4L2Subdevice::setCrop(unsigned int pad, Rectangle *rect) +int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target, + Rectangle *rect) { - return setSelection(pad, V4L2_SEL_TGT_CROP, rect); -} + struct v4l2_subdev_selection sel = {}; -/** - * \brief Set a compose rectangle on one of the V4L2 subdevice pads - * \param[in] pad The 0-indexed pad number the rectangle is to be applied to - * \param[inout] rect The rectangle describing the compose target area - * \return 0 on success or a negative error code otherwise - */ -int V4L2Subdevice::setCompose(unsigned int pad, Rectangle *rect) -{ - return setSelection(pad, V4L2_SEL_TGT_COMPOSE, rect); -} + sel.which = V4L2_SUBDEV_FORMAT_ACTIVE; + sel.pad = pad; + sel.target = target; + sel.flags = 0; + sel.r.left = rect->x; + sel.r.top = rect->y; + sel.r.width = rect->width; + sel.r.height = rect->height; + + int ret = ioctl(VIDIOC_SUBDEV_S_SELECTION, &sel); + if (ret < 0) { + LOG(V4L2, Error) + << "Unable to set rectangle " << target << " on pad " + << pad << ": " << strerror(-ret); + return ret; + } + + rect->x = sel.r.left; + rect->y = sel.r.top; + rect->width = sel.r.width; + rect->height = sel.r.height; + + return 0; +} /** * \brief Enumerate all media bus codes and frame sizes on a \a pad * \param[in] pad The 0-indexed pad number to enumerate formats on @@ -343,35 +358,4 @@ std::vector V4L2Subdevice::enumPadSizes(unsigned int pad, return sizes; } -int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target, - Rectangle *rect) -{ - struct v4l2_subdev_selection sel = {}; - - sel.which = V4L2_SUBDEV_FORMAT_ACTIVE; - sel.pad = pad; - sel.target = target; - sel.flags = 0; - - sel.r.left = rect->x; - sel.r.top = rect->y; - sel.r.width = rect->width; - sel.r.height = rect->height; - - int ret = ioctl(VIDIOC_SUBDEV_S_SELECTION, &sel); - if (ret < 0) { - LOG(V4L2, Error) - << "Unable to set rectangle " << target << " on pad " - << pad << ": " << strerror(-ret); - return ret; - } - - rect->x = sel.r.left; - rect->y = sel.r.top; - rect->width = sel.r.width; - rect->height = sel.r.height; - - return 0; -} - } /* namespace libcamera */ From patchwork Mon Apr 27 21:32:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 3571 Return-Path: Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A761A60AF4 for ; Mon, 27 Apr 2020 23:29:33 +0200 (CEST) X-Originating-IP: 212.216.150.148 Received: from uno.homenet.telecomitalia.it (a-ur1-85.tin.it [212.216.150.148]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 1D9EE4000A; Mon, 27 Apr 2020 21:29:32 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 27 Apr 2020 23:32:31 +0200 Message-Id: <20200427213236.333777-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200427213236.333777-1-jacopo@jmondi.org> References: <20200427213236.333777-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 2/7] libcamera: v4l2_videodevice: Expose setSelection() 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, 27 Apr 2020 21:29:33 -0000 Expose V4L2Videodevice::setSelection() method and drop V4L2Videodevice::setCrop() and V4L2Videodevice::setComopse() as wrapping each target with a single function does not provide any benefit. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/libcamera/include/v4l2_videodevice.h | 5 +---- src/libcamera/v4l2_videodevice.cpp | 20 +++----------------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h index a0409e59c08f..976ef9b6dc50 100644 --- a/src/libcamera/include/v4l2_videodevice.h +++ b/src/libcamera/include/v4l2_videodevice.h @@ -211,8 +211,7 @@ public: int setFormat(V4L2DeviceFormat *format); std::map> formats(); - int setCrop(Rectangle *rect); - int setCompose(Rectangle *rect); + int setSelection(unsigned int target, Rectangle *rect); int allocateBuffers(unsigned int count, std::vector> *buffers); @@ -254,8 +253,6 @@ private: std::vector enumPixelformats(); std::vector enumSizes(V4L2PixelFormat pixelFormat); - int setSelection(unsigned int target, Rectangle *rect); - int requestBuffers(unsigned int count, enum v4l2_memory memoryType); int createBuffers(unsigned int count, std::vector> *buffers); diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 8d642be0d05c..b16ab82c2807 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -1108,25 +1108,11 @@ std::vector V4L2VideoDevice::enumSizes(V4L2PixelFormat pixelFormat) } /** - * \brief Set a crop rectangle on the V4L2 video device node - * \param[inout] rect The rectangle describing the crop target area + * \brief Set a selection rectangle \a rect for \a target + * \param[in] target The selection target defined by the V4L2_SEL_TGT_* flags + * \param[inout] rect The selection rectangle to be applied * \return 0 on success or a negative error code otherwise */ -int V4L2VideoDevice::setCrop(Rectangle *rect) -{ - return setSelection(V4L2_SEL_TGT_CROP, rect); -} - -/** - * \brief Set a compose rectangle on the V4L2 video device node - * \param[inout] rect The rectangle describing the compose target area - * \return 0 on success or a negative error code otherwise - */ -int V4L2VideoDevice::setCompose(Rectangle *rect) -{ - return setSelection(V4L2_SEL_TGT_COMPOSE, rect); -} - int V4L2VideoDevice::setSelection(unsigned int target, Rectangle *rect) { struct v4l2_selection sel = {}; From patchwork Mon Apr 27 21:32:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 3572 Return-Path: Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AC59F6121D for ; Mon, 27 Apr 2020 23:29:34 +0200 (CEST) X-Originating-IP: 212.216.150.148 Received: from uno.homenet.telecomitalia.it (a-ur1-85.tin.it [212.216.150.148]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id D732740007; Mon, 27 Apr 2020 21:29:33 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 27 Apr 2020 23:32:32 +0200 Message-Id: <20200427213236.333777-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200427213236.333777-1-jacopo@jmondi.org> References: <20200427213236.333777-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 3/7] libcamera: v4l2_subdevice: Implement getSelection() 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, 27 Apr 2020 21:29:35 -0000 Implement V4L2Subdevice::getSelection() to support retrieving selection rectangles from the v4l2 subdevice. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/libcamera/include/v4l2_subdevice.h | 2 ++ src/libcamera/v4l2_subdevice.cpp | 33 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h index 9a5c812db9b6..27ba5b17f61e 100644 --- a/src/libcamera/include/v4l2_subdevice.h +++ b/src/libcamera/include/v4l2_subdevice.h @@ -46,6 +46,8 @@ public: const MediaEntity *entity() const { return entity_; } + int getSelection(unsigned int pad, unsigned int target, + Rectangle *rect); int setSelection(unsigned int pad, unsigned int target, Rectangle *rect); diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 432e89eacbd3..74788ce7cf4f 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -133,6 +133,39 @@ int V4L2Subdevice::open() * \return The subdevice's associated media entity. */ +/** + * \brief Get selection rectangle \a rect for \a target + * \param[in] pad The 0-indexed pad number the rectangle is retrieved from + * \param[in] target The selection target defined by the V4L2_SEL_TGT_* flags + * \param[out] rect The retrieved selection rectangle + * \return 0 on success or a negative error code otherwise + */ +int V4L2Subdevice::getSelection(unsigned int pad, unsigned int target, + Rectangle *rect) +{ + struct v4l2_subdev_selection sel = {}; + + sel.which = V4L2_SUBDEV_FORMAT_ACTIVE; + sel.pad = pad; + sel.target = target; + sel.flags = 0; + + int ret = ioctl(VIDIOC_SUBDEV_G_SELECTION, &sel); + if (ret < 0) { + LOG(V4L2, Error) + << "Unable to get rectangle " << target << " on pad " + << pad << ": " << strerror(-ret); + return ret; + } + + rect->x = sel.r.left; + rect->y = sel.r.top; + rect->width = sel.r.width; + rect->height = sel.r.height; + + return 0; +} + /** * \brief Set selection rectangle \a rect for \a target * \param[in] pad The 0-indexed pad number the rectangle is to be applied to From patchwork Mon Apr 27 21:32:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 3573 Return-Path: Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 68850603F9 for ; Mon, 27 Apr 2020 23:29:35 +0200 (CEST) X-Originating-IP: 212.216.150.148 Received: from uno.homenet.telecomitalia.it (a-ur1-85.tin.it [212.216.150.148]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id B9EEF40002; Mon, 27 Apr 2020 21:29:34 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 27 Apr 2020 23:32:33 +0200 Message-Id: <20200427213236.333777-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200427213236.333777-1-jacopo@jmondi.org> References: <20200427213236.333777-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 4/7] libcamera: camera_sensor: Define CameraSensorInfo 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, 27 Apr 2020 21:29:35 -0000 Define the CameraSensorInfo structure that reports the current image sensor configuration. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/camera_sensor.cpp | 84 +++++++++++++++++++++++++++ src/libcamera/include/camera_sensor.h | 13 +++++ 2 files changed, 97 insertions(+) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index ce585cab1a4f..4fd1ee84eb47 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -28,6 +28,90 @@ namespace libcamera { LOG_DEFINE_CATEGORY(CameraSensor); +/** + * \struct CameraSensorInfo + * \brief Report the image sensor characteristics + * + * The structure reports image sensor characteristics used by IPA modules to + * tune their algorithms based on the image sensor model currently in use and + * its configuration. + * + * The here reported information describe the sensor's intrinsics + * characteristics, such as its pixel array size and the sensor model name, + * as well as information relative to the currently configured mode, such as + * the produced image size and the bit depth of the requested image format. + * + * Instances of this structure are meant to be assembled by the CameraSensor + * class by inspecting the sensor static properties as well as the currently + * configured sensor mode. + */ + +/** + * \var CameraSensorInfo::model + * \brief The image sensor model name + * + * The sensor model name is a free-formed string that uniquely identifies the + * sensor model. + */ + +/** + * \var CameraSensorInfo::bitsPerPixel + * \brief The number of bits per pixel of the image format produced by the + * image sensor + */ + +/** + * \var CameraSensorInfo::activeAreaSize + * \brief The size of the pixel array active area of the sensor + */ + +/** + * \var CameraSensorInfo::analogCrop + * \brief The portion of the pixel array active area which is read-out and + * processed + * + * The analog crop rectangle top-left corner is defined as the displacement + * from the top-left corner of the pixel array active area. The rectangle + * horizontal and vertical sizes define the portion of the pixel array which + * is read-out and provided to the sensor's internal processing pipeline, before + * any pixel sub-sampling method, such as pixel binning, skipping and averaging + * take place. + */ + +/** + * \var CameraSensorInfo::outputSize + * \brief The size of the images produced by the camera sensor + * + * The output image size defines the horizontal and vertical sizes of the images + * produced by the image sensor. The output image size is defined as the end + * result of the sensor's internal image processing pipeline stages, applied on + * the pixel array portion defined by the analog crop rectangle. Each image + * processing stage that performs pixel sub-sampling techniques, such as pixel + * binning or skipping, or perform any additional digital scaling concur in the + * definition of the output image size. + */ + +/** + * \var CameraSensorInfo::pixelRate + * \brief The number of pixel produced in a second + * + * The pixel read out frequency in Hz. The property describes how many pixels + * per second are produced by the camera sensor, including blanking. + * + * To obtain the read-out time in second of a full line: + * + * \verbatim + lineDuration(s) = lineLength(pixel) / pixelRate(Hz) + \endverbatim + */ + +/** + * \var CameraSensorInfo::lineLength + * \brief Total line length in pixels + * + * The total line length in pixel clock periods, including blanking. + */ + /** * \class CameraSensor * \brief A camera sensor based on V4L2 subdevices diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h index 5277f7f7fe87..28ebfaa30c22 100644 --- a/src/libcamera/include/camera_sensor.h +++ b/src/libcamera/include/camera_sensor.h @@ -22,6 +22,19 @@ class V4L2Subdevice; struct V4L2SubdeviceFormat; +struct CameraSensorInfo { + std::string model; + + uint32_t bitsPerPixel; + + Size activeAreaSize; + Rectangle analogCrop; + Size outputSize; + + uint32_t pixelRate; + uint32_t lineLength; +}; + class CameraSensor : protected Loggable { public: From patchwork Mon Apr 27 21:32:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 3574 Return-Path: Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4823860B0A for ; Mon, 27 Apr 2020 23:29:36 +0200 (CEST) X-Originating-IP: 212.216.150.148 Received: from uno.homenet.telecomitalia.it (a-ur1-85.tin.it [212.216.150.148]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 9955440002; Mon, 27 Apr 2020 21:29:35 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 27 Apr 2020 23:32:34 +0200 Message-Id: <20200427213236.333777-6-jacopo@jmondi.org> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200427213236.333777-1-jacopo@jmondi.org> References: <20200427213236.333777-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 5/7] libcamera: v4l2_subdevice: Add format information 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, 27 Apr 2020 21:29:36 -0000 Define a map of static information associated with a media bus code. Start by reporting the bits-per-pixel for each media bus code defined by the V4L2 kernel API, to later expand it when necessary. Add to the V4L2SubdeviceFormat class a method to return the bits per pixel, retrieved by inspecting the static map of format information. While at there, remove a rouge map inclusion from header file. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/include/v4l2_subdevice.h | 2 +- src/libcamera/v4l2_subdevice.cpp | 104 +++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) -- 2.26.1 diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h index 27ba5b17f61e..d0e565dbdaab 100644 --- a/src/libcamera/include/v4l2_subdevice.h +++ b/src/libcamera/include/v4l2_subdevice.h @@ -7,7 +7,6 @@ #ifndef __LIBCAMERA_V4L2_SUBDEVICE_H__ #define __LIBCAMERA_V4L2_SUBDEVICE_H__ -#include #include #include @@ -27,6 +26,7 @@ struct V4L2SubdeviceFormat { Size size; const std::string toString() const; + uint8_t bitsPerPixel() const; }; class V4L2Subdevice : public V4L2Device diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 74788ce7cf4f..93fe4b8c3d32 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -32,6 +33,92 @@ namespace libcamera { LOG_DECLARE_CATEGORY(V4L2) +namespace { + +/* + * \var formatInfoMap + * \brief A map that associates bits per pixel to V4L2 media bus codes + */ +const std::map formatInfoMap = { + { V4L2_MBUS_FMT_RGB444_2X8_PADHI_BE, 16 }, + { V4L2_MBUS_FMT_RGB444_2X8_PADHI_LE, 16 }, + { V4L2_MBUS_FMT_RGB555_2X8_PADHI_BE, 16 }, + { V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE, 16 }, + { V4L2_MBUS_FMT_BGR565_2X8_BE, 16 }, + { V4L2_MBUS_FMT_BGR565_2X8_LE, 16 }, + { V4L2_MBUS_FMT_RGB565_2X8_BE, 16 }, + { V4L2_MBUS_FMT_RGB565_2X8_LE, 16 }, + { V4L2_MBUS_FMT_RGB666_1X18, 18 }, + { V4L2_MBUS_FMT_RGB888_1X24, 24 }, + { V4L2_MBUS_FMT_RGB888_2X12_BE, 24 }, + { V4L2_MBUS_FMT_RGB888_2X12_LE, 24 }, + { V4L2_MBUS_FMT_ARGB8888_1X32, 32 }, + { V4L2_MBUS_FMT_Y8_1X8, 8 }, + { V4L2_MBUS_FMT_UV8_1X8, 8 }, + { V4L2_MBUS_FMT_UYVY8_1_5X8, 40 }, + { V4L2_MBUS_FMT_VYUY8_1_5X8, 40 }, + { V4L2_MBUS_FMT_YUYV8_1_5X8, 40 }, + { V4L2_MBUS_FMT_YVYU8_1_5X8, 40 }, + { V4L2_MBUS_FMT_UYVY8_2X8, 16 }, + { V4L2_MBUS_FMT_VYUY8_2X8, 16 }, + { V4L2_MBUS_FMT_YUYV8_2X8, 16 }, + { V4L2_MBUS_FMT_YVYU8_2X8, 16 }, + { V4L2_MBUS_FMT_Y10_1X10, 10 }, + { V4L2_MBUS_FMT_UYVY10_2X10, 20 }, + { V4L2_MBUS_FMT_VYUY10_2X10, 20 }, + { V4L2_MBUS_FMT_YUYV10_2X10, 20 }, + { V4L2_MBUS_FMT_YVYU10_2X10, 20 }, + { V4L2_MBUS_FMT_Y12_1X12, 12 }, + { V4L2_MBUS_FMT_UYVY8_1X16, 16 }, + { V4L2_MBUS_FMT_VYUY8_1X16, 16 }, + { V4L2_MBUS_FMT_YUYV8_1X16, 16 }, + { V4L2_MBUS_FMT_YVYU8_1X16, 16 }, + { V4L2_MBUS_FMT_YDYUYDYV8_1X16, 16 }, + { V4L2_MBUS_FMT_UYVY10_1X20, 20 }, + { V4L2_MBUS_FMT_VYUY10_1X20, 20 }, + { V4L2_MBUS_FMT_YUYV10_1X20, 20 }, + { V4L2_MBUS_FMT_YVYU10_1X20, 20 }, + { V4L2_MBUS_FMT_YUV10_1X30, 30 }, + { V4L2_MBUS_FMT_AYUV8_1X32, 32 }, + { V4L2_MBUS_FMT_UYVY12_2X12, 24 }, + { V4L2_MBUS_FMT_VYUY12_2X12, 24 }, + { V4L2_MBUS_FMT_YUYV12_2X12, 24 }, + { V4L2_MBUS_FMT_YVYU12_2X12, 24 }, + { V4L2_MBUS_FMT_UYVY12_1X24, 24 }, + { V4L2_MBUS_FMT_VYUY12_1X24, 24 }, + { V4L2_MBUS_FMT_YUYV12_1X24, 24 }, + { V4L2_MBUS_FMT_YVYU12_1X24, 24 }, + { V4L2_MBUS_FMT_SBGGR8_1X8, 8 }, + { V4L2_MBUS_FMT_SGBRG8_1X8, 8 }, + { V4L2_MBUS_FMT_SGRBG8_1X8, 8 }, + { V4L2_MBUS_FMT_SRGGB8_1X8, 8 }, + { V4L2_MBUS_FMT_SBGGR10_ALAW8_1X8, 8 }, + { V4L2_MBUS_FMT_SGBRG10_ALAW8_1X8, 8 }, + { V4L2_MBUS_FMT_SGRBG10_ALAW8_1X8, 8 }, + { V4L2_MBUS_FMT_SRGGB10_ALAW8_1X8, 8 }, + { V4L2_MBUS_FMT_SBGGR10_DPCM8_1X8, 8 }, + { V4L2_MBUS_FMT_SGBRG10_DPCM8_1X8, 8 }, + { V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8, 8 }, + { V4L2_MBUS_FMT_SRGGB10_DPCM8_1X8, 8 }, + { V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_BE, 16 }, + { V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE, 16 }, + { V4L2_MBUS_FMT_SBGGR10_2X8_PADLO_BE, 16 }, + { V4L2_MBUS_FMT_SBGGR10_2X8_PADLO_LE, 16 }, + { V4L2_MBUS_FMT_SBGGR10_1X10, 10 }, + { V4L2_MBUS_FMT_SGBRG10_1X10, 10 }, + { V4L2_MBUS_FMT_SGRBG10_1X10, 10 }, + { V4L2_MBUS_FMT_SRGGB10_1X10, 10 }, + { V4L2_MBUS_FMT_SBGGR12_1X12, 24 }, + { V4L2_MBUS_FMT_SGBRG12_1X12, 24 }, + { V4L2_MBUS_FMT_SGRBG12_1X12, 24 }, + { V4L2_MBUS_FMT_SRGGB12_1X12, 24 }, + { V4L2_MBUS_FMT_JPEG_1X8, 8 }, + { V4L2_MBUS_FMT_S5C_UYVY_JPEG_1X8, 8 }, + { V4L2_MBUS_FMT_AHSV8888_1X32, 32 }, +}; + +}; /* namespace */ + /** * \struct V4L2SubdeviceFormat * \brief The V4L2 sub-device image format and sizes @@ -81,6 +168,23 @@ const std::string V4L2SubdeviceFormat::toString() const return ss.str(); } +/** + * \brief Retrieve the number of bits per pixel for the V4L2 subdevice format + * \return The number of bits per pixel for the format, or default it to 8 if + * the format's media bus code is not supported + */ +uint8_t V4L2SubdeviceFormat::bitsPerPixel() const +{ + const auto it = formatInfoMap.find(mbus_code); + if (it == formatInfoMap.end()) { + LOG(V4L2, Error) << "No information available for format '" + << toString() << "'"; + return 0; + } + + return it->second; +} + /** * \class V4L2Subdevice * \brief A V4L2 subdevice as exposed by the Linux kernel From patchwork Mon Apr 27 21:32:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 3575 Return-Path: Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 29453603F9 for ; Mon, 27 Apr 2020 23:29:37 +0200 (CEST) X-Originating-IP: 212.216.150.148 Received: from uno.homenet.telecomitalia.it (a-ur1-85.tin.it [212.216.150.148]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 80E6140007; Mon, 27 Apr 2020 21:29:36 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 27 Apr 2020 23:32:35 +0200 Message-Id: <20200427213236.333777-7-jacopo@jmondi.org> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200427213236.333777-1-jacopo@jmondi.org> References: <20200427213236.333777-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 6/7] libcamera: camera_sensor: Add method to get sensor info 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, 27 Apr 2020 21:29:38 -0000 Add method to retrieve the CameraSensorInfo to the CameraSensor class. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/camera_sensor.cpp | 83 +++++++++++++++++++++++++++ src/libcamera/include/camera_sensor.h | 1 + 2 files changed, 84 insertions(+) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 4fd1ee84eb47..8b37f63dc04e 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -440,6 +440,89 @@ int CameraSensor::setControls(ControlList *ctrls) return subdev_->setControls(ctrls); } +/** + * \brief Assemble and return the camera sensor info + * \param[out] info The camera sensor info that reports the sensor information + * + * The CameraSensorInfo content is assembled by inspecting the currently + * applied sensor configuration and the sensor static properties. + * + * \return 0 on success, a negative error code otherwise + */ +int CameraSensor::sensorInfo(CameraSensorInfo *info) const +{ + /* + * Construct the camera sensor name using the media entity name. + * + * \todo There is no standardized naming scheme for sensor entities + * in the Linux kernel at the moment. The most common naming scheme + * is the one obtained by associating the sensor name and its I2C + * device and bus addresses in the form of: "devname i2c-adapt:i2c-addr" + * Assume this is the standard naming scheme and parse the first part + * of the entity name to obtain "devname". + */ + std::string entityName = subdev_->entity()->name(); + info->model = entityName.substr(0, entityName.find(' ')); + + /* + * Get the active area size from the ActiveAreas property. Do + * not use the content of properties::ActiveAreas but fetch it from the + * subdevice as the property registration is optional, but it's + * mandatory to construct the CameraSensorInfo. + * + * \todo The ActiveAreas property aims to describe multiple + * active area rectangles. At the moment only a single active + * area rectangle is exposed by the subdevice API. Use that single + * rectangle width and height to construct the ActiveAreaSize. + */ + Rectangle rect = {}; + int ret = subdev_->getSelection(0, V4L2_SEL_TGT_CROP_DEFAULT, &rect); + if (ret) { + LOG(CameraSensor, Error) + << "Failed to construct camera sensor info: " + << "the camera sensor does not report the active area"; + + return ret; + } + info->activeAreaSize = { rect.width, rect.height }; + + /* It's mandatory for the subdevice to report its crop rectangle. */ + ret = subdev_->getSelection(0, V4L2_SEL_TGT_CROP, &info->analogCrop); + if (ret) { + LOG(CameraSensor, Error) + << "Failed to construct camera sensor info: " + << "the camera sensor does not report the crop rectangle"; + return ret; + } + + /* The bit-depth and image size depend on the currently applied format. */ + V4L2SubdeviceFormat format{}; + ret = subdev_->getFormat(0, &format); + if (ret) + return ret; + info->bitsPerPixel = format.bitsPerPixel(); + info->outputSize = format.size; + + /* + * Retrieve the pixel rate and the line length through V4L2 controls. + * Support for the V4L2_CID_PIXEL_RATE and V4L2_CID_HBLANK controls is + * mandatory. + */ + ControlList ctrls = subdev_->getControls({ V4L2_CID_PIXEL_RATE, + V4L2_CID_HBLANK }); + if (ctrls.empty()) { + LOG(CameraSensor, Error) + << "Failed to retrieve camera info controls"; + return -EINVAL; + } + + int32_t hblank = ctrls.get(V4L2_CID_HBLANK).get(); + info->lineLength = info->outputSize.width + hblank; + info->pixelRate = ctrls.get(V4L2_CID_PIXEL_RATE).get(); + + return 0; +} + std::string CameraSensor::logPrefix() const { return "'" + subdev_->entity()->name() + "'"; diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h index 28ebfaa30c22..91d270552d3f 100644 --- a/src/libcamera/include/camera_sensor.h +++ b/src/libcamera/include/camera_sensor.h @@ -60,6 +60,7 @@ public: int setControls(ControlList *ctrls); const ControlList &properties() const { return properties_; } + int sensorInfo(CameraSensorInfo *info) const; protected: std::string logPrefix() const; From patchwork Mon Apr 27 21:32:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 3576 Return-Path: Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B931F6120E for ; Mon, 27 Apr 2020 23:29:38 +0200 (CEST) X-Originating-IP: 212.216.150.148 Received: from uno.homenet.telecomitalia.it (a-ur1-85.tin.it [212.216.150.148]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 5BEA440002; Mon, 27 Apr 2020 21:29:37 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 27 Apr 2020 23:32:36 +0200 Message-Id: <20200427213236.333777-8-jacopo@jmondi.org> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200427213236.333777-1-jacopo@jmondi.org> References: <20200427213236.333777-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 7/7] libcamera: ipa: Add support for CameraSensorInfo 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, 27 Apr 2020 21:29:38 -0000 Add support for camera sensor information in the libcamera IPA protocol. Define a new 'struct ipa_sensor_info' structure in the IPA context and use it to perform translation between the C and the C++ API. Update the IPAInterface::configure() operation to accept a new CameraSensorInfo parameter and port all users of that function to the new interface. Signed-off-by: Jacopo Mondi --- include/ipa/ipa_interface.h | 26 +++++++- src/ipa/libipa/ipa_interface_wrapper.cpp | 19 +++++- src/ipa/libipa/ipa_interface_wrapper.h | 1 + src/ipa/rkisp1/rkisp1.cpp | 13 +++- src/ipa/vimc/vimc.cpp | 4 +- src/libcamera/include/ipa_context_wrapper.h | 4 +- src/libcamera/ipa_context_wrapper.cpp | 23 ++++++- src/libcamera/ipa_interface.cpp | 73 +++++++++++++++++++++ src/libcamera/pipeline/rkisp1/rkisp1.cpp | 14 +++- src/libcamera/proxy/ipa_proxy_linux.cpp | 4 +- src/libcamera/proxy/ipa_proxy_thread.cpp | 9 ++- test/ipa/ipa_wrappers_test.cpp | 22 ++++++- 12 files changed, 195 insertions(+), 17 deletions(-) diff --git a/include/ipa/ipa_interface.h b/include/ipa/ipa_interface.h index e65844bc7b34..0a6d849d8f89 100644 --- a/include/ipa/ipa_interface.h +++ b/include/ipa/ipa_interface.h @@ -18,6 +18,27 @@ struct ipa_context { const struct ipa_context_ops *ops; }; +struct ipa_sensor_info { + const char *model; + uint8_t bits_per_pixel; + struct { + uint32_t width; + uint32_t height; + } active_area; + struct { + int32_t left; + int32_t top; + uint32_t width; + uint32_t height; + } analog_crop; + struct { + uint32_t width; + uint32_t height; + } output_size; + uint32_t pixel_rate; + uint32_t line_length; +}; + struct ipa_stream { unsigned int id; unsigned int pixel_format; @@ -70,6 +91,7 @@ struct ipa_context_ops { const struct ipa_callback_ops *callbacks, void *cb_ctx); void (*configure)(struct ipa_context *ctx, + const struct ipa_sensor_info *sensor_info, const struct ipa_stream *streams, unsigned int num_streams, const struct ipa_control_info_map *maps, @@ -116,6 +138,7 @@ struct IPAOperationData { std::vector controls; }; +struct CameraSensorInfo; class IPAInterface { public: @@ -125,7 +148,8 @@ public: virtual int start() = 0; virtual void stop() = 0; - virtual void configure(const std::map &streamConfig, + virtual void configure(const CameraSensorInfo &sensorInfo, + const std::map &streamConfig, const std::map &entityControls) = 0; virtual void mapBuffers(const std::vector &buffers) = 0; diff --git a/src/ipa/libipa/ipa_interface_wrapper.cpp b/src/ipa/libipa/ipa_interface_wrapper.cpp index f50f93a0185a..e65822c62315 100644 --- a/src/ipa/libipa/ipa_interface_wrapper.cpp +++ b/src/ipa/libipa/ipa_interface_wrapper.cpp @@ -15,6 +15,7 @@ #include #include "byte_stream_buffer.h" +#include "camera_sensor.h" /** * \file ipa_interface_wrapper.h @@ -111,6 +112,7 @@ void IPAInterfaceWrapper::register_callbacks(struct ipa_context *_ctx, } void IPAInterfaceWrapper::configure(struct ipa_context *_ctx, + const struct ipa_sensor_info *sensor_info, const struct ipa_stream *streams, unsigned int num_streams, const struct ipa_control_info_map *maps, @@ -120,6 +122,21 @@ void IPAInterfaceWrapper::configure(struct ipa_context *_ctx, ctx->serializer_.reset(); + /* Translate the IPA sensor info. */ + CameraSensorInfo sensorInfo{}; + sensorInfo.model = sensor_info->model; + sensorInfo.bitsPerPixel = sensor_info->bits_per_pixel; + sensorInfo.activeAreaSize = { sensor_info->active_area.width, + sensor_info->active_area.height }; + sensorInfo.analogCrop = { sensor_info->analog_crop.left, + sensor_info->analog_crop.top, + sensor_info->analog_crop.width, + sensor_info->analog_crop.height }; + sensorInfo.outputSize = { sensor_info->output_size.width, + sensor_info->output_size.height }; + sensorInfo.pixelRate = sensor_info->pixel_rate; + sensorInfo.lineLength = sensor_info->line_length; + /* Translate the IPA stream configurations map. */ std::map ipaStreams; @@ -145,7 +162,7 @@ void IPAInterfaceWrapper::configure(struct ipa_context *_ctx, entityControls.emplace(id, infoMaps[id]); } - ctx->ipa_->configure(ipaStreams, entityControls); + ctx->ipa_->configure(sensorInfo, ipaStreams, entityControls); } void IPAInterfaceWrapper::map_buffers(struct ipa_context *_ctx, diff --git a/src/ipa/libipa/ipa_interface_wrapper.h b/src/ipa/libipa/ipa_interface_wrapper.h index e4bc6dd4535d..febd6e66d0c4 100644 --- a/src/ipa/libipa/ipa_interface_wrapper.h +++ b/src/ipa/libipa/ipa_interface_wrapper.h @@ -30,6 +30,7 @@ private: const struct ipa_callback_ops *callbacks, void *cb_ctx); static void configure(struct ipa_context *ctx, + const struct ipa_sensor_info *sensor_info, const struct ipa_stream *streams, unsigned int num_streams, const struct ipa_control_info_map *maps, diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index acbbe58c7a2e..b6da672c1384 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -22,6 +22,7 @@ #include #include +#include "camera_sensor.h" #include "log.h" #include "utils.h" @@ -36,7 +37,8 @@ public: int start() override { return 0; } void stop() override {} - void configure(const std::map &streamConfig, + void configure(const CameraSensorInfo &info, + const std::map &streamConfig, const std::map &entityControls) override; void mapBuffers(const std::vector &buffers) override; void unmapBuffers(const std::vector &ids) override; @@ -66,7 +68,14 @@ private: uint32_t maxGain_; }; -void IPARkISP1::configure(const std::map &streamConfig, +/** + * \todo The RkISP1 pipeline currently provides an empty CameraSensorInfo + * if the connected sensor does not provide enough information to properly + * assemble one. Make sure the reported sensor information are relevant + * before accessing them. + */ +void IPARkISP1::configure(const CameraSensorInfo &info, + const std::map &streamConfig, const std::map &entityControls) { if (entityControls.empty()) diff --git a/src/ipa/vimc/vimc.cpp b/src/ipa/vimc/vimc.cpp index d2267e11737f..b8aadd8588cb 100644 --- a/src/ipa/vimc/vimc.cpp +++ b/src/ipa/vimc/vimc.cpp @@ -19,6 +19,7 @@ #include +#include "camera_sensor.h" #include "log.h" namespace libcamera { @@ -36,7 +37,8 @@ public: int start() override; void stop() override; - void configure(const std::map &streamConfig, + void configure(const CameraSensorInfo &sensorInfo, + const std::map &streamConfig, const std::map &entityControls) override {} void mapBuffers(const std::vector &buffers) override {} void unmapBuffers(const std::vector &ids) override {} diff --git a/src/libcamera/include/ipa_context_wrapper.h b/src/libcamera/include/ipa_context_wrapper.h index 0a48bfe732c8..cfb435ee1b91 100644 --- a/src/libcamera/include/ipa_context_wrapper.h +++ b/src/libcamera/include/ipa_context_wrapper.h @@ -13,6 +13,7 @@ namespace libcamera { +struct CameraSensorInfo; class IPAContextWrapper final : public IPAInterface { public: @@ -22,7 +23,8 @@ public: int init() override; int start() override; void stop() override; - void configure(const std::map &streamConfig, + void configure(const CameraSensorInfo &sensorInfo, + const std::map &streamConfig, const std::map &entityControls) override; void mapBuffers(const std::vector &buffers) override; diff --git a/src/libcamera/ipa_context_wrapper.cpp b/src/libcamera/ipa_context_wrapper.cpp index ab6ce396b88a..d591c67f8791 100644 --- a/src/libcamera/ipa_context_wrapper.cpp +++ b/src/libcamera/ipa_context_wrapper.cpp @@ -12,6 +12,7 @@ #include #include "byte_stream_buffer.h" +#include "camera_sensor.h" #include "utils.h" /** @@ -104,17 +105,33 @@ void IPAContextWrapper::stop() ctx_->ops->stop(ctx_); } -void IPAContextWrapper::configure(const std::map &streamConfig, +void IPAContextWrapper::configure(const CameraSensorInfo &sensorInfo, + const std::map &streamConfig, const std::map &entityControls) { if (intf_) - return intf_->configure(streamConfig, entityControls); + return intf_->configure(sensorInfo, streamConfig, entityControls); if (!ctx_) return; serializer_.reset(); + /* Translate the camera sensor info. */ + struct ipa_sensor_info sensor_info = {}; + sensor_info.model = sensorInfo.model.c_str(); + sensor_info.bits_per_pixel = sensorInfo.bitsPerPixel; + sensor_info.active_area.width = sensorInfo.activeAreaSize.width; + sensor_info.active_area.height = sensorInfo.activeAreaSize.height; + sensor_info.analog_crop.left = sensorInfo.analogCrop.x; + sensor_info.analog_crop.top = sensorInfo.analogCrop.y; + sensor_info.analog_crop.width = sensorInfo.analogCrop.width; + sensor_info.analog_crop.height = sensorInfo.analogCrop.height; + sensor_info.output_size.width = sensorInfo.outputSize.width; + sensor_info.output_size.height = sensorInfo.outputSize.height; + sensor_info.pixel_rate = sensorInfo.pixelRate; + sensor_info.line_length = sensorInfo.lineLength; + /* Translate the IPA stream configurations map. */ struct ipa_stream c_streams[streamConfig.size()]; @@ -154,7 +171,7 @@ void IPAContextWrapper::configure(const std::map &strea ++i; } - ctx_->ops->configure(ctx_, c_streams, streamConfig.size(), + ctx_->ops->configure(ctx_, &sensor_info, c_streams, streamConfig.size(), c_info_maps, entityControls.size()); } diff --git a/src/libcamera/ipa_interface.cpp b/src/libcamera/ipa_interface.cpp index 890d4340e4f3..13df090f3374 100644 --- a/src/libcamera/ipa_interface.cpp +++ b/src/libcamera/ipa_interface.cpp @@ -92,6 +92,74 @@ * \brief The IPA context operations */ +/** + * \struct ipa_sensor_info + * \brief Camera sensor information for the IPA context operations + * \sa libcamera::CameraSensorInfo + * + * \var ipa_sensor_info::model + * \brief The camera sensor model name + * \todo Remove this field as soon as no IPA depends on it anymore + * + * \var ipa_sensor_info::bits_per_pixel + * \brief The camera sensor image format bit depth + * \sa libcamera::CameraSensorInfo::bitsPerPixel + * + * \var ipa_sensor_info::active_area.width + * \brief The camera sensor pixel array active area width + * \sa libcamera::CameraSensorInfo::activeAreaSize + * + * \var ipa_sensor_info::active_area.height + * \brief The camera sensor pixel array active area height + * \sa libcamera::CameraSensorInfo::activeAreaSize + * + * \var ipa_sensor_info::active_area + * \brief The camera sensor pixel array active size + * \sa libcamera::CameraSensorInfo::activeAreaSize + * + * \var ipa_sensor_info::analog_crop.left + * \brief The left coordinate of the analog crop rectangle, relative to the + * pixel array active area + * \sa libcamera::CameraSensorInfo::analogCrop + * + * \var ipa_sensor_info::analog_crop.top + * \brief The top coordinate of the analog crop rectangle, relative to the pixel + * array active area + * \sa libcamera::CameraSensorInfo::analogCrop + * + * \var ipa_sensor_info::analog_crop.width + * \brief The horizontal size of the analog crop rectangle + * \sa libcamera::CameraSensorInfo::analogCrop + * + * \var ipa_sensor_info::analog_crop.height + * \brief The vertical size of the analog crop rectangle + * \sa libcamera::CameraSensorInfo::analogCrop + * + * \var ipa_sensor_info::analog_crop + * \brief The analog crop rectangle + * \sa libcamera::CameraSensorInfo::analogCrop + * + * \var ipa_sensor_info::output_size.width + * \brief The horizontal size of the output image + * \sa libcamera::CameraSensorInfo::outputSize + * + * \var ipa_sensor_info::output_size.height + * \brief The vertical size of the output image + * \sa libcamera::CameraSensorInfo::outputSize + * + * \var ipa_sensor_info::output_size + * \brief The size of the output image + * \sa libcamera::CameraSensorInfo::outputSize + * + * \var ipa_sensor_info::pixel_rate + * \brief The number of pixel produced in a second + * \sa libcamera::CameraSensorInfo::pixelClock + * + * \var ipa_sensor_info::line_length + * \brief The full line length, including blanking, in pixel units + * \sa libcamera::CameraSensorInfo::lineLength + */ + /** * \struct ipa_stream * \brief Stream information for the IPA context operations @@ -447,6 +515,7 @@ namespace libcamera { /** * \fn IPAInterface::configure() * \brief Configure the IPA stream and sensor settings + * \param[in] sensorInfo Camera sensor information * \param[in] streamConfig Configuration of all active streams * \param[in] entityControls Controls provided by the pipeline entities * @@ -454,6 +523,10 @@ namespace libcamera { * the camera's streams and the sensor settings. The meaning of the numerical * keys in the \a streamConfig and \a entityControls maps is defined by the IPA * protocol. + * + * The \a sensorInfo conveys information about the camera sensor settings that + * the pipeline handler has selected for the configuration. The IPA may use + * that information to tune its algorithms. */ /** diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index f42264361785..4058b9014fb9 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -821,7 +821,17 @@ int PipelineHandlerRkISP1::start(Camera *camera) activeCamera_ = camera; - /* Inform IPA of stream configuration and sensor controls. */ + /* + * Inform IPA of stream configuration and sensor controls. + */ + CameraSensorInfo sensorInfo = {}; + ret = data->sensor_->sensorInfo(&sensorInfo); + if (ret) { + /* \todo Turn this in an hard failure. */ + LOG(RkISP1, Info) << "Camera sensor information not available"; + sensorInfo = {}; + } + std::map streamConfig; streamConfig[0] = { .pixelFormat = data->stream_.configuration().pixelFormat, @@ -831,7 +841,7 @@ int PipelineHandlerRkISP1::start(Camera *camera) std::map entityControls; entityControls.emplace(0, data->sensor_->controls()); - data->ipa_->configure(streamConfig, entityControls); + data->ipa_->configure(sensorInfo, streamConfig, entityControls); return ret; } diff --git a/src/libcamera/proxy/ipa_proxy_linux.cpp b/src/libcamera/proxy/ipa_proxy_linux.cpp index 2aa80b946704..54b1abc4727b 100644 --- a/src/libcamera/proxy/ipa_proxy_linux.cpp +++ b/src/libcamera/proxy/ipa_proxy_linux.cpp @@ -10,6 +10,7 @@ #include #include +#include "camera_sensor.h" #include "ipa_module.h" #include "ipa_proxy.h" #include "ipc_unixsocket.h" @@ -29,7 +30,8 @@ public: int init() override { return 0; } int start() override { return 0; } void stop() override {} - void configure(const std::map &streamConfig, + void configure(const CameraSensorInfo &sensorInfo, + const std::map &streamConfig, const std::map &entityControls) override {} void mapBuffers(const std::vector &buffers) override {} void unmapBuffers(const std::vector &ids) override {} diff --git a/src/libcamera/proxy/ipa_proxy_thread.cpp b/src/libcamera/proxy/ipa_proxy_thread.cpp index 368ccca1cf60..b06734371b39 100644 --- a/src/libcamera/proxy/ipa_proxy_thread.cpp +++ b/src/libcamera/proxy/ipa_proxy_thread.cpp @@ -10,6 +10,7 @@ #include #include +#include "camera_sensor.h" #include "ipa_context_wrapper.h" #include "ipa_module.h" #include "ipa_proxy.h" @@ -29,7 +30,8 @@ public: int start() override; void stop() override; - void configure(const std::map &streamConfig, + void configure(const CameraSensorInfo &sensorInfo, + const std::map &streamConfig, const std::map &entityControls) override; void mapBuffers(const std::vector &buffers) override; void unmapBuffers(const std::vector &ids) override; @@ -126,10 +128,11 @@ void IPAProxyThread::stop() thread_.wait(); } -void IPAProxyThread::configure(const std::map &streamConfig, +void IPAProxyThread::configure(const CameraSensorInfo &sensorInfo, + const std::map &streamConfig, const std::map &entityControls) { - ipa_->configure(streamConfig, entityControls); + ipa_->configure(sensorInfo, streamConfig, entityControls); } void IPAProxyThread::mapBuffers(const std::vector &buffers) diff --git a/test/ipa/ipa_wrappers_test.cpp b/test/ipa/ipa_wrappers_test.cpp index fae1d56b67c7..a6bf0836ac4e 100644 --- a/test/ipa/ipa_wrappers_test.cpp +++ b/test/ipa/ipa_wrappers_test.cpp @@ -15,6 +15,7 @@ #include #include +#include "camera_sensor.h" #include "device_enumerator.h" #include "ipa_context_wrapper.h" #include "media_device.h" @@ -60,9 +61,17 @@ public: report(Op_stop, TestPass); } - void configure(const std::map &streamConfig, + void configure(const CameraSensorInfo &sensorInfo, + const std::map &streamConfig, const std::map &entityControls) override { + /* Verify sensorInfo. */ + if (sensorInfo.outputSize.width != 2560 || + sensorInfo.outputSize.height != 1940) { + cerr << "configure(): Invalid sensor info sizes: (" + << sensorInfo.outputSize.toString(); + } + /* Verify streamConfig. */ if (streamConfig.size() != 2) { cerr << "configure(): Invalid number of streams " @@ -287,13 +296,22 @@ protected: int ret; /* Test configure(). */ + CameraSensorInfo sensorInfo{ + .model = "sensor", + .bitsPerPixel = 8, + .activeAreaSize = { 2576, 1956 }, + .analogCrop = { 8, 8, 2560, 1940 }, + .outputSize = { 2560, 1940 }, + .pixelRate = 96000000, + .lineLength = 2918, + }; std::map config{ { 1, { V4L2_PIX_FMT_YUYV, { 1024, 768 } } }, { 2, { V4L2_PIX_FMT_NV12, { 800, 600 } } }, }; std::map controlInfo; controlInfo.emplace(42, subdev_->controls()); - ret = INVOKE(configure, config, controlInfo); + ret = INVOKE(configure, sensorInfo, config, controlInfo); if (ret == TestFail) return TestFail;