<div dir="auto"><div>Hi Laurent,<br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 8 Jan, 2022, 19:22 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>
On Sat, Jan 08, 2022 at 03:10:15AM +0530, Vedant Paranjape wrote:<br>
> Hello Laurent,<br>
> I have been able to get v4l2-ctl working to stream using dmabuf, here<br>
> are the steps I followed:<br>
> <br>
> 1) Apply the patch in the trailing email (v4) on the latest branch of libcamera<br>
> 2) Clone master of v4l-utils and apply this patch<br>
> <a href="https://patchwork.kernel.org/project/linux-media/patch/20220104130708.166638-1-vedantparanjape160201@gmail.com/" rel="noreferrer noreferrer" target="_blank">https://patchwork.kernel.org/project/linux-media/patch/20220104130708.166638-1-vedantparanjape160201@gmail.com/</a><br>
> 3) Compile v4l-utils<br>
> 4) give alias v4l2-ctl-edge=<PATH OF COMPILED V4l2-ctl><br>
> 5) run the following command in libcamera root directory:<br>
> LD_PRELOAD=./build/src/v4l2/v4l2-compat.so v4l2-ctl-edge -d0<br>
> --set-fmt-video=pixelformat='YUYV' --stream-mmap --out-device<br>
> /dev/video3 --stream-out-dmabuf --get-fmt-video --get-fmt-video-out<br>
<br>
You can drop the last two arguments.<br>
<br>
While this show that the EXPBUF implementation works, in a real use case<br>
you would still potentially have different formats on the capture and<br>
output side, which would lead to garbled output. You should specify the<br>
format and resolution explicitly on both the capture and output side.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Makes sense, I'll keep this in mind.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'll merge the patch.<br>
<br>
> I have attached the output of lsv4l2 here as well:<br>
> <br>
> video0: HD WebCam: HD WebCam<br>
> video1: HD WebCam: HD WebCam<br>
> video2: vivid-000-vid-cap<br>
> video3: vivid-000-vid-out<br>
> <br>
> Here's the terminal output: <a href="https://paste.debian.net/1226342/" rel="noreferrer noreferrer" target="_blank">https://paste.debian.net/1226342/</a><br>
> <br>
> Regards,<br>
> Vedant Paranjape<br>
> <br>
> On Thu, Dec 30, 2021 at 4:06 AM Laurent Pinchart wrote:<br>
> > On Wed, Dec 29, 2021 at 12:20:14AM +0530, Vedant Paranjape wrote:<br>
> > > To support DMABUF as one of the memory buffer, we need to implement<br>
> > > EXPBUF in the v4l2 compat layer.<br>
> > ><br>
> > > This patch implements vidioc_expbuf as one of the supported ioctls.<br>
> > ><br>
> > > Bug: <a href="https://bugs.libcamera.org/show_bug.cgi?id=89" rel="noreferrer noreferrer" target="_blank">https://bugs.libcamera.org/show_bug.cgi?id=89</a><br>
> > ><br>
> > > Signed-off-by: Vedant Paranjape <<a href="mailto:vedantparanjape160201@gmail.com" target="_blank" rel="noreferrer">vedantparanjape160201@gmail.com</a>><br>
> ><br>
> > This looks fine. As soon as you can test it with v4l2-ctl and capture<br>
> > images, I think it can be merged.<br>
> ><br>
> > I've sent a patch for v4l2-ctl (which has been merged in the master<br>
> > branch already) that should help with testing.<br>
> ><br>
> > > ---<br>
> > > src/v4l2/v4l2_camera_proxy.cpp | 30 ++++++++++++++++++++++++++++++<br>
> > > src/v4l2/v4l2_camera_proxy.h | 1 +<br>
> > > 2 files changed, 31 insertions(+)<br>
> > ><br>
> > > diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp<br>
> > > index c1375777c185..4d529bc29a4d 100644<br>
> > > --- a/src/v4l2/v4l2_camera_proxy.cpp<br>
> > > +++ b/src/v4l2/v4l2_camera_proxy.cpp<br>
> > > @@ -624,6 +624,32 @@ int V4L2CameraProxy::vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg,<br>
> > > return 0;<br>
> > > }<br>
> > ><br>
> > > +int V4L2CameraProxy::vidioc_expbuf(V4L2CameraFile *file, struct v4l2_exportbuffer *arg)<br>
> > > +{<br>
> > > + LOG(V4L2Compat, Debug) << "Servicing vidioc_expbuf fd = " << file->efd();<br>
> > > +<br>
> > > + if (!hasOwnership(file))<br>
> > > + return -EBUSY;<br>
> > > +<br>
> > > + /* \todo Verify that the memory type is MMAP when adding DMABUF support */<br>
> > > + if (!validateBufferType(arg->type))<br>
> > > + return -EINVAL;<br>
> > > +<br>
> > > + if (arg->index >= bufferCount_)<br>
> > > + return -EINVAL;<br>
> > > +<br>
> > > + if (arg->flags & ~(O_CLOEXEC | O_ACCMODE))<br>
> > > + return -EINVAL;<br>
> > > +<br>
> > > + memset(arg->reserved, 0, sizeof(arg->reserved));<br>
> > > +<br>
> > > + /* \todo honor the O_ACCMODE flags passed to this function */<br>
> > > + arg->fd = fcntl(vcam_->getBufferFd(arg->index),<br>
> > > + arg->flags & O_CLOEXEC ? F_DUPFD_CLOEXEC : F_DUPFD, 0);<br>
> > > +<br>
> > > + return 0;<br>
> > > +}<br>
> > > +<br>
> > > int V4L2CameraProxy::vidioc_streamon(V4L2CameraFile *file, int *arg)<br>
> > > {<br>
> > > LOG(V4L2Compat, Debug) << "Servicing vidioc_streamon fd = " << file->efd();<br>
> > > @@ -685,6 +711,7 @@ const std::set<unsigned long> V4L2CameraProxy::supportedIoctls_ = {<br>
> > > VIDIOC_QUERYBUF,<br>
> > > VIDIOC_QBUF,<br>
> > > VIDIOC_DQBUF,<br>
> > > + VIDIOC_EXPBUF,<br>
> > > VIDIOC_STREAMON,<br>
> > > VIDIOC_STREAMOFF,<br>
> > > };<br>
> > > @@ -755,6 +782,9 @@ int V4L2CameraProxy::ioctl(V4L2CameraFile *file, unsigned long request, void *ar<br>
> > > case VIDIOC_DQBUF:<br>
> > > ret = vidioc_dqbuf(file, static_cast<struct v4l2_buffer *>(arg), &proxyMutex_);<br>
> > > break;<br>
> > > + case VIDIOC_EXPBUF:<br>
> > > + ret = vidioc_expbuf(file, static_cast<struct v4l2_exportbuffer *>(arg));<br>
> > > + break;<br>
> > > case VIDIOC_STREAMON:<br>
> > > ret = vidioc_streamon(file, static_cast<int *>(arg));<br>
> > > break;<br>
> > > diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h<br>
> > > index fa0a49e0439b..14e027c3e7d1 100644<br>
> > > --- a/src/v4l2/v4l2_camera_proxy.h<br>
> > > +++ b/src/v4l2/v4l2_camera_proxy.h<br>
> > > @@ -60,6 +60,7 @@ private:<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>
> > > + int vidioc_expbuf(V4L2CameraFile *file, struct v4l2_exportbuffer *arg);<br>
> > > int vidioc_streamon(V4L2CameraFile *file, int *arg);<br>
> > > int vidioc_streamoff(V4L2CameraFile *file, int *arg);<br>
> > ><br>
<br>
-- <br>
Regards,<br>
<br>
Laurent Pinchart</blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Regards,</div><div dir="auto">Vedant Paranjape</div><div dir="auto"></div></div>