[{"id":31154,"web_url":"https://patchwork.libcamera.org/comment/31154/","msgid":"<172598952684.412786.7508001487178509411@ping.linuxembedded.co.uk>","date":"2024-09-10T17:32:06","subject":"Re: [PATCH v3] v4l2: Support setting frame rate in the V4L2\n\tAdaptation layer","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi All? (me included as I see my SoB here)\n\nQuoting Nejc Galof (2022-02-25 14:45:07)\n> The V4L2 adaptation layer can already support streaming with components\n> such as OpenCV, however it is not accepting, or handling any requests to\n> configure the frame rate.\n> \n> In V4L2 the frame rate is set by configuring the timeperframe component\n> of the v4l2_streamparm structure through the VIDIOC_S_PARM ioctl.\n> \n> Extend the V4L2 compatibility layer to accept the VIDIOC_S_PARM ioctls\n> and provide an interface for setting controls on the V4L2Camera class to\n> set the requested rate when starting the camera.\n> \n\nThis patch looks sane, but seems to have slipped through the net.\n\nIt needs to be rebased due to a merge conflict on headers being moved\nthough, which I've just done so I'll send that as v4 with my RB tag from\nhere:\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> Signed-off-by: Nejc Galof <galof.nejc@gmail.com>\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/v4l2/v4l2_camera.cpp       | 12 +++++++++---\n>  src/v4l2/v4l2_camera.h         |  5 +++++\n>  src/v4l2/v4l2_camera_proxy.cpp | 24 ++++++++++++++++++++++++\n>  src/v4l2/v4l2_camera_proxy.h   |  1 +\n>  4 files changed, 39 insertions(+), 3 deletions(-)\n> \n> diff --git a/src/v4l2/v4l2_camera.cpp b/src/v4l2/v4l2_camera.cpp\n> index e922b9e6..e4eb3a2b 100644\n> --- a/src/v4l2/v4l2_camera.cpp\n> +++ b/src/v4l2/v4l2_camera.cpp\n> @@ -12,13 +12,15 @@\n>  \n>  #include <libcamera/base/log.h>\n>  \n> +#include <libcamera/control_ids.h>\n> +\n>  using namespace libcamera;\n>  \n>  LOG_DECLARE_CATEGORY(V4L2Compat)\n>  \n>  V4L2Camera::V4L2Camera(std::shared_ptr<Camera> camera)\n> -       : camera_(camera), isRunning_(false), bufferAllocator_(nullptr),\n> -         efd_(-1), bufferAvailableCount_(0)\n> +       : camera_(camera), controls_(controls::controls), isRunning_(false),\n> +         bufferAllocator_(nullptr), efd_(-1), bufferAvailableCount_(0)\n>  {\n>         camera_->requestCompleted.connect(this, &V4L2Camera::requestComplete);\n>  }\n> @@ -203,10 +205,12 @@ int V4L2Camera::streamOn()\n>         if (isRunning_)\n>                 return 0;\n>  \n> -       int ret = camera_->start();\n> +       int ret = camera_->start(&controls_);\n>         if (ret < 0)\n>                 return ret == -EACCES ? -EBUSY : ret;\n>  \n> +       controls_.clear();\n> +\n>         isRunning_ = true;\n>  \n>         for (Request *req : pendingRequests_) {\n> @@ -266,6 +270,8 @@ int V4L2Camera::qbuf(unsigned int index)\n>                 return 0;\n>         }\n>  \n> +       request->controls().merge(std::move(controls_));\n> +\n>         ret = camera_->queueRequest(request);\n>         if (ret < 0) {\n>                 LOG(V4L2Compat, Error) << \"Can't queue request\";\n> diff --git a/src/v4l2/v4l2_camera.h b/src/v4l2/v4l2_camera.h\n> index 03e74118..4c203e31 100644\n> --- a/src/v4l2/v4l2_camera.h\n> +++ b/src/v4l2/v4l2_camera.h\n> @@ -15,6 +15,7 @@\n>  #include <libcamera/base/shared_fd.h>\n>  \n>  #include <libcamera/camera.h>\n> +#include <libcamera/controls.h>\n>  #include <libcamera/framebuffer.h>\n>  #include <libcamera/framebuffer_allocator.h>\n>  \n> @@ -49,6 +50,8 @@ public:\n>                                   const libcamera::Size &size,\n>                                   libcamera::StreamConfiguration *streamConfigOut);\n>  \n> +       libcamera::ControlList &controls() { return controls_; }\n> +\n>         int allocBuffers(unsigned int count);\n>         void freeBuffers();\n>         int getBufferFd(unsigned int index);\n> @@ -69,6 +72,8 @@ private:\n>         std::shared_ptr<libcamera::Camera> camera_;\n>         std::unique_ptr<libcamera::CameraConfiguration> config_;\n>  \n> +       libcamera::ControlList controls_;\n> +\n>         bool isRunning_;\n>  \n>         libcamera::Mutex bufferLock_;\n> diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp\n> index 74bd54ce..493c41c0 100644\n> --- a/src/v4l2/v4l2_camera_proxy.cpp\n> +++ b/src/v4l2/v4l2_camera_proxy.cpp\n> @@ -18,6 +18,8 @@\n>  #include <unistd.h>\n>  \n>  #include <libcamera/camera.h>\n> +#include <libcamera/controls.h>\n> +#include <libcamera/control_ids.h>\n>  #include <libcamera/formats.h>\n>  \n>  #include <libcamera/base/log.h>\n> @@ -33,6 +35,7 @@\n>  #define KERNEL_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c))\n>  \n>  using namespace libcamera;\n> +using namespace std::literals::chrono_literals;\n>  \n>  LOG_DECLARE_CATEGORY(V4L2Compat)\n>  \n> @@ -755,6 +758,23 @@ int V4L2CameraProxy::vidioc_streamoff(V4L2CameraFile *file, int *arg)\n>         return ret;\n>  }\n>  \n> +int V4L2CameraProxy::vidioc_s_parm(V4L2CameraFile *file, struct v4l2_streamparm *arg)\n> +{\n> +       LOG(V4L2Compat, Debug)\n> +               << \"[\" << file->description() << \"] \" << __func__ << \"()\";\n> +\n> +       if (!validateBufferType(arg->type))\n> +               return -EINVAL;\n> +\n> +       struct v4l2_fract *timeperframe = &arg->parm.capture.timeperframe;\n> +       utils::Duration frameDuration = 1.0s * timeperframe->numerator / timeperframe->denominator;\n> +\n> +       int64_t uDuration = frameDuration.get<std::micro>();\n> +       vcam_->controls().set(controls::FrameDurationLimits, { uDuration, uDuration });\n> +\n> +       return 0;\n> +}\n> +\n>  const std::set<unsigned long> V4L2CameraProxy::supportedIoctls_ = {\n>         VIDIOC_QUERYCAP,\n>         VIDIOC_ENUM_FRAMESIZES,\n> @@ -775,6 +795,7 @@ const std::set<unsigned long> V4L2CameraProxy::supportedIoctls_ = {\n>         VIDIOC_EXPBUF,\n>         VIDIOC_STREAMON,\n>         VIDIOC_STREAMOFF,\n> +       VIDIOC_S_PARM,\n>  };\n>  \n>  int V4L2CameraProxy::ioctl(V4L2CameraFile *file, unsigned long request, void *arg)\n> @@ -852,6 +873,9 @@ int V4L2CameraProxy::ioctl(V4L2CameraFile *file, unsigned long request, void *ar\n>         case VIDIOC_STREAMOFF:\n>                 ret = vidioc_streamoff(file, static_cast<int *>(arg));\n>                 break;\n> +       case VIDIOC_S_PARM:\n> +               ret = vidioc_s_parm(file, static_cast<struct v4l2_streamparm *>(arg));\n> +               break;\n>         default:\n>                 ret = -ENOTTY;\n>                 break;\n> diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h\n> index 76ca2d8a..c1aeaff9 100644\n> --- a/src/v4l2/v4l2_camera_proxy.h\n> +++ b/src/v4l2/v4l2_camera_proxy.h\n> @@ -65,6 +65,7 @@ private:\n>         int vidioc_expbuf(V4L2CameraFile *file, struct v4l2_exportbuffer *arg);\n>         int vidioc_streamon(V4L2CameraFile *file, int *arg);\n>         int vidioc_streamoff(V4L2CameraFile *file, int *arg);\n> +       int vidioc_s_parm(V4L2CameraFile *file, struct v4l2_streamparm *arg);\n>  \n>         bool hasOwnership(V4L2CameraFile *file);\n>         int acquire(V4L2CameraFile *file);\n> -- \n> 2.17.1\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 4D937BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 10 Sep 2024 17:32:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 314B9634FC;\n\tTue, 10 Sep 2024 19:32:12 +0200 (CEST)","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 0CE47634E4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 10 Sep 2024 19:32:10 +0200 (CEST)","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 EFE2EFF1;\n\tTue, 10 Sep 2024 19:30:52 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Kn4e2261\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1725989453;\n\tbh=PYkwYK19QqXg2Px/YFT2JrW9uAjIo8aSEMuMWcQ9aRI=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=Kn4e2261ptAgUTmHLDuTQcwFXbIYLa7U/AobEQOt3WUvM4K7BEZhRtGM1crXhC9Tz\n\tX5BUUI2+jTnEK7Y3MpNa3km+ETjb3P9ZLXTnJAmkzBux3tM3lAurVvdpRlGnEoe7g6\n\tosY4/3Io5r5Y/f8r7xjjysNBeselaO0RGH6oIyWk=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20220225144507.69550-1-galof.nejc@gmail.com>","References":"<20220225144507.69550-1-galof.nejc@gmail.com>","Subject":"Re: [PATCH v3] v4l2: Support setting frame rate in the V4L2\n\tAdaptation layer","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"","To":"Nejc Galof <galof.nejc@gmail.com>, libcamera-devel@lists.libcamera.org","Date":"Tue, 10 Sep 2024 18:32:06 +0100","Message-ID":"<172598952684.412786.7508001487178509411@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>"}}]