[{"id":32953,"web_url":"https://patchwork.libcamera.org/comment/32953/","msgid":"<173629349210.2120558.3475219845195083015@ping.linuxembedded.co.uk>","date":"2025-01-07T23:44:52","subject":"Re: [PATCH v2 6/6] libcamera: camera_sensor: Add support for\n\tembedded data","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Jacopo Mondi (2024-11-08 10:51:16)\n> From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n> Some sensors support producing and transmitting embedded data over a\n> stream separate from the image stream. Add support for this feature in\n> the CameraSensor interface, and implement it for the CameraSensorRaw\n> class. The CameraSensorLegacy uses the default stub implementation, as\n> the corresponding kernel drivers don't support embedded data.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\nNothing I can particularly comment on in this one so just a :\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  include/libcamera/internal/camera_sensor.h |  5 ++\n>  src/libcamera/sensor/camera_sensor.cpp     | 67 ++++++++++++++++++++\n>  src/libcamera/sensor/camera_sensor_raw.cpp | 72 ++++++++++++++++++++++\n>  3 files changed, 144 insertions(+)\n> \n> diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h\n> index 8aafd82e6547..61bf1d7ca6de 100644\n> --- a/include/libcamera/internal/camera_sensor.h\n> +++ b/include/libcamera/internal/camera_sensor.h\n> @@ -61,6 +61,11 @@ public:\n>                                        Transform transform = Transform::Identity,\n>                                        V4L2SubdeviceFormat *sensorFormat = nullptr) = 0;\n>  \n> +       virtual V4L2Subdevice::Stream imageStream() const;\n> +       virtual std::optional<V4L2Subdevice::Stream> embeddedDataStream() const;\n> +       virtual V4L2SubdeviceFormat embeddedDataFormat() const;\n> +       virtual int setEmbeddedDataEnabled(bool enable);\n> +\n>         virtual const ControlList &properties() const = 0;\n>         virtual int sensorInfo(IPACameraSensorInfo *info) const = 0;\n>         virtual Transform computeTransform(Orientation *orientation) const = 0;\n> diff --git a/src/libcamera/sensor/camera_sensor.cpp b/src/libcamera/sensor/camera_sensor.cpp\n> index 54cf98b203fd..1217365b2a55 100644\n> --- a/src/libcamera/sensor/camera_sensor.cpp\n> +++ b/src/libcamera/sensor/camera_sensor.cpp\n> @@ -196,6 +196,73 @@ CameraSensor::~CameraSensor() = default;\n>   * error code otherwise\n>   */\n>  \n> +/**\n> + * \\brief Retrieve the image source stream\n> + *\n> + * Sensors that produce multiple streams do not guarantee that the image stream\n> + * is always assigned number 0. This function allows callers to retrieve the\n> + * image stream on the sensor's source pad, in order to configure the receiving\n> + * side accordingly.\n> + *\n> + * \\return The image source stream\n> + */\n> +V4L2Subdevice::Stream CameraSensor::imageStream() const\n> +{\n> +       return { 0, 0 };\n> +}\n> +\n> +/**\n> + * \\brief Retrieve the embedded data source stream\n> + *\n> + * Some sensors produce embedded data in a stream separate from the image\n> + * stream. This function indicates if the sensor supports this feature by\n> + * returning the embedded data stream on the sensor's source pad if available,\n> + * or an std::optional<> without a value otheriwse.\n> + *\n> + * \\return The embedded data source stream\n> + */\n> +std::optional<V4L2Subdevice::Stream> CameraSensor::embeddedDataStream() const\n> +{\n> +       return {};\n> +}\n> +\n> +/**\n> + * \\brief Retrieve the format on the embedded data stream\n> + *\n> + * When an embedded data stream is available, this function returns the\n> + * corresponding format on the sensor's source pad. The format may vary with\n> + * the image stream format, and should therefore be retrieved after configuring\n> + * the image stream.\n> + *\n> + * If the sensor doesn't support embedded data, this function returns a\n> + * default-constructed format.\n> + *\n> + * \\return The format on the embedded data stream\n> + */\n> +V4L2SubdeviceFormat CameraSensor::embeddedDataFormat() const\n> +{\n> +       return {};\n> +}\n> +\n> +/**\n> + * \\brief Enable or disable the embedded data stream\n> + * \\param[in] enable True to enable the embedded data stream, false to disable it\n> + *\n> + * For sensors that support embedded data, this function enables or disables\n> + * generation of embedded data. Some of such sensors always produce embedded\n> + * data, in which case this function return -EISCONN if the caller attempts to\n> + * disable embedded data.\n> + *\n> + * If the sensor doesn't support embedded data, this function returns 0 when \\a\n> + * enable is false, and -ENOSTR otherwise.\n> + *\n> + * \\return 0 on success, or a negative error code otherwise\n> + */\n> +int CameraSensor::setEmbeddedDataEnabled(bool enable)\n> +{\n> +       return enable ? -ENOSTR : 0;\n> +}\n> +\n>  /**\n>   * \\fn CameraSensor::properties()\n>   * \\brief Retrieve the camera sensor properties\n> diff --git a/src/libcamera/sensor/camera_sensor_raw.cpp b/src/libcamera/sensor/camera_sensor_raw.cpp\n> index 4c653121d547..9380ec7129f6 100644\n> --- a/src/libcamera/sensor/camera_sensor_raw.cpp\n> +++ b/src/libcamera/sensor/camera_sensor_raw.cpp\n> @@ -84,6 +84,11 @@ public:\n>                                Transform transform = Transform::Identity,\n>                                V4L2SubdeviceFormat *sensorFormat = nullptr) override;\n>  \n> +       V4L2Subdevice::Stream imageStream() const override;\n> +       std::optional<V4L2Subdevice::Stream> embeddedDataStream() const override;\n> +       V4L2SubdeviceFormat embeddedDataFormat() const override;\n> +       int setEmbeddedDataEnabled(bool enable) override;\n> +\n>         const ControlList &properties() const override { return properties_; }\n>         int sensorInfo(IPACameraSensorInfo *info) const override;\n>         Transform computeTransform(Orientation *orientation) const override;\n> @@ -878,6 +883,73 @@ int CameraSensorRaw::applyConfiguration(const SensorConfiguration &config,\n>         return 0;\n>  }\n>  \n> +V4L2Subdevice::Stream CameraSensorRaw::imageStream() const\n> +{\n> +       return streams_.image.source;\n> +}\n> +\n> +std::optional<V4L2Subdevice::Stream> CameraSensorRaw::embeddedDataStream() const\n> +{\n> +       if (!streams_.edata)\n> +               return {};\n> +\n> +       return { streams_.edata->source };\n> +}\n> +\n> +V4L2SubdeviceFormat CameraSensorRaw::embeddedDataFormat() const\n> +{\n> +       if (!streams_.edata)\n> +               return {};\n> +\n> +       V4L2SubdeviceFormat format;\n> +       int ret = subdev_->getFormat(streams_.edata->source, &format);\n> +       if (ret)\n> +               return {};\n> +\n> +       return format;\n> +}\n> +\n> +int CameraSensorRaw::setEmbeddedDataEnabled(bool enable)\n> +{\n> +       if (!streams_.edata)\n> +               return enable ? -ENOSTR : 0;\n> +\n> +       V4L2Subdevice::Routing routing{ 2 };\n> +\n> +       routing[0].sink = streams_.image.sink;\n> +       routing[0].source = streams_.image.source;\n> +       routing[0].flags = V4L2_SUBDEV_ROUTE_FL_ACTIVE;\n> +\n> +       routing[1].sink = streams_.edata->sink;\n> +       routing[1].source = streams_.edata->source;\n> +       routing[1].flags = enable ? V4L2_SUBDEV_ROUTE_FL_ACTIVE : 0;\n> +\n> +       int ret = subdev_->setRouting(&routing);\n> +       if (ret)\n> +               return ret;\n> +\n> +       /*\n> +        * Check if the embedded data stream has been enabled or disabled\n> +        * correctly. Assume at least one route will match the embedded data\n> +        * source stream, as there would be something seriously wrong\n> +        * otherwise.\n> +        */\n> +       bool enabled = false;\n> +\n> +       for (const V4L2Subdevice::Route &route : routing) {\n> +               if (route.source != streams_.edata->source)\n> +                       continue;\n> +\n> +               enabled = route.flags & V4L2_SUBDEV_ROUTE_FL_ACTIVE;\n> +               break;\n> +       }\n> +\n> +       if (enabled != enable)\n> +               return enabled ? -EISCONN : -ENOSTR;\n> +\n> +       return 0;\n> +}\n> +\n>  int CameraSensorRaw::sensorInfo(IPACameraSensorInfo *info) const\n>  {\n>         info->model = model();\n> -- \n> 2.47.0\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 5E21ABD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  7 Jan 2025 23:44:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 48275684DF;\n\tWed,  8 Jan 2025 00:44:57 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B345D684D6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  8 Jan 2025 00:44:55 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 00D56664;\n\tWed,  8 Jan 2025 00:44:02 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"lZfDmBst\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1736293443;\n\tbh=3GFqlEdEBwIovGG0Hju5/7Y26OswxTaIalVZC3rBJcM=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=lZfDmBstLah2cdk3B9Jcdw8rTUIXYWqz1Hqp3XdAIBHQOYrIwfXFikES6v4GGAlut\n\tg6B+NNAfnUPtVvQ0+XH/PZWhv44NxarUCUlvAnEeLQGDcWbQcA8UzUf2vzg3eceJp+\n\tTpB+J1IlyanhEz9mN1tsMAJul0oR3vUfdhGnvfiY=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20241108105117.137121-7-jacopo.mondi@ideasonboard.com>","References":"<20241108105117.137121-1-jacopo.mondi@ideasonboard.com>\n\t<20241108105117.137121-7-jacopo.mondi@ideasonboard.com>","Subject":"Re: [PATCH v2 6/6] libcamera: camera_sensor: Add support for\n\tembedded data","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>, naush@raspberrypi.com,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Tue, 07 Jan 2025 23:44:52 +0000","Message-ID":"<173629349210.2120558.3475219845195083015@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]