<div dir="auto">Sure, will do that. </div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 15 Jan, 2022, 21:57 Laurent Pinchart, <<a href="mailto:laurent.pinchart@ideasonboard.com">laurent.pinchart@ideasonboard.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Vedant,<br>
<br>
Thank you for the patch.<br>
<br>
On Wed, Jan 12, 2022 at 01:41:02AM +0530, Vedant Paranjape wrote:<br>
> Add support for PREPARE_BUF as one of the ioctl. Since this is a compat<br>
> layer, there doesn't seem to be an equivalent to the "transfer ownership<br>
> of the buffer to kernel driver" in V4L2Camera class.<br>
> <br>
> To match the error checks done by kernel implementation, we'd have to<br>
> check if dmabuf fd is valid and that the buffer size is large enough.<br>
> Doing so will not add any particular value to the program as<br>
> applications most likely don't depend on these conditions being<br>
> handled correctly.<br>
> <br>
> Signed-off-by: Vedant Paranjape <<a href="mailto:vedantparanjape160201@gmail.com" target="_blank" rel="noreferrer">vedantparanjape160201@gmail.com</a>><br>
> Reviewed-by: Laurent Pinchart <<a href="mailto:laurent.pinchart@ideasonboard.com" target="_blank" rel="noreferrer">laurent.pinchart@ideasonboard.com</a>><br>
> ---<br>
>  src/v4l2/v4l2_camera_proxy.cpp | 32 ++++++++++++++++++++++++++++++++<br>
>  src/v4l2/v4l2_camera_proxy.h   |  1 +<br>
>  2 files changed, 33 insertions(+)<br>
> <br>
> diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp<br>
> index 4d529bc29a4d..695af5be5c69 100644<br>
> --- a/src/v4l2/v4l2_camera_proxy.cpp<br>
> +++ b/src/v4l2/v4l2_camera_proxy.cpp<br>
> @@ -544,6 +544,37 @@ int V4L2CameraProxy::vidioc_querybuf(V4L2CameraFile *file, struct v4l2_buffer *a<br>
>       return 0;<br>
>  }<br>
>  <br>
> +int V4L2CameraProxy::vidioc_prepare_buf(V4L2CameraFile *file, struct v4l2_buffer *arg)<br>
> +{<br>
> +     LOG(V4L2Compat, Debug) << "Servicing vidioc_prepare_buf, index = "<br>
> +                            << arg->index << " fd = " << file->efd();<br>
<br>
We can replace this with<br>
<br>
        LOG(V4L2Compat, Debug)<br>
                << "[" << file->description() << "] " << __func__<br>
                << "(index=" << arg->index << ")";<br>
<br>
now that the V4L2 compat debugging improvements have been merged.<br>
<br>
> +<br>
> +     if (!hasOwnership(file))<br>
> +             return -EBUSY;<br>
> +<br>
> +     if (arg->index >= bufferCount_)<br>
> +             return -EINVAL;<br>
> +<br>
> +     if (arg->flags & V4L2_BUF_FLAG_REQUEST_FD)<br>
> +             return -EINVAL;<br>
> +<br>
> +     if (!validateBufferType(arg->type) ||<br>
> +         !validateMemoryType(arg->memory))<br>
> +             return -EINVAL;<br>
> +<br>
> +     struct v4l2_buffer &buffer = buffers_[arg->index];<br>
> +<br>
> +     if (buffer.flags & V4L2_BUF_FLAG_QUEUED ||<br>
> +         buffer.flags & V4L2_BUF_FLAG_PREPARED)<br>
> +             return -EINVAL;<br>
> +<br>
> +     buffer.flags |= V4L2_BUF_FLAG_PREPARED;<br>
<br>
This looks good, but there's one missing thing:<br>
V4L2CameraProxy::vidioc_dqbuf() should now clear the<br>
V4L2_BUF_FLAG_PREPARED flag. Can you send a v3 that addresses those two<br>
small issues ?<br>
<br>
> +<br>
> +     arg->flags = buffer.flags;<br>
> +<br>
> +     return 0;<br>
> +}<br>
> +<br>
>  int V4L2CameraProxy::vidioc_qbuf(V4L2CameraFile *file, struct v4l2_buffer *arg)<br>
>  {<br>
>       LOG(V4L2Compat, Debug) << "Servicing vidioc_qbuf, index = "<br>
> @@ -709,6 +740,7 @@ const std::set<unsigned long> V4L2CameraProxy::supportedIoctls_ = {<br>
>       VIDIOC_S_INPUT,<br>
>       VIDIOC_REQBUFS,<br>
>       VIDIOC_QUERYBUF,<br>
> +     VIDIOC_PREPARE_BUF,<br>
>       VIDIOC_QBUF,<br>
>       VIDIOC_DQBUF,<br>
>       VIDIOC_EXPBUF,<br>
> diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h<br>
> index 14e027c3e7d1..6baba94262a9 100644<br>
> --- a/src/v4l2/v4l2_camera_proxy.h<br>
> +++ b/src/v4l2/v4l2_camera_proxy.h<br>
> @@ -57,6 +57,7 @@ private:<br>
>       int vidioc_s_input(V4L2CameraFile *file, int *arg);<br>
>       int vidioc_reqbufs(V4L2CameraFile *file, struct v4l2_requestbuffers *arg);<br>
>       int vidioc_querybuf(V4L2CameraFile *file, struct v4l2_buffer *arg);<br>
> +     int vidioc_prepare_buf(V4L2CameraFile *file, struct v4l2_buffer *arg);<br>
>       int vidioc_qbuf(V4L2CameraFile *file, struct v4l2_buffer *arg);<br>
>       int vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg,<br>
>                        libcamera::Mutex *lock) LIBCAMERA_TSA_REQUIRES(*lock);<br>
<br>
-- <br>
Regards,<br>
<br>
Laurent Pinchart<br>
</blockquote></div>