Skip to contentSkip to conversation

v4l2_buffer with PBO mapped memory

DISCUSSION Thomas Scheuermann 3 participants 9 messages Apr 2, 2014 – Apr 15, 2014 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

Hello,

I've written a program which shows my webcam with the v4l2 interface. In the v4l2_buffer I use the type V4L2_BUF_TYPE_VIDEO_CAPTURE and the memory is V4L2_MEMORY_USERPTR.
Everything works if I use malloced memory for frame buffers. Now I want to get the frames directly in OpenGL. I've mapped a pixel buffer object with glMapBuffer and wanted to use this as a frame buffer. But if I use this memory, the ioctl VIDIOC_QBUF fails with 'invalid argument'.

What can I do to use the pixel buffer object together with the v4l2 interface?
I want to use as less copy steps as possible.

Regards,

Thomas
This message is subject to the following terms and conditions: MAIL DISCLAIMER<http://www.barco.com/en/maildisclaimer>

#1 lore raw

Hi Thomas,

Quoted 11 lines · On Wednesday 02 April 2014 17:10:42 Thomas Scheuermann wrote:

Hello,

I've written a program which shows my webcam with the v4l2 interface. In the v4l2_buffer I use the type V4L2_BUF_TYPE_VIDEO_CAPTURE and the memory is V4L2_MEMORY_USERPTR.
Everything works if I use malloced memory for frame buffers. Now I want to get the frames directly in OpenGL. I've mapped a pixel buffer object with glMapBuffer and wanted to use this as a frame buffer. But if I use this memory, the ioctl VIDIOC_QBUF fails with 'invalid argument'.

Quoted 3 lines

What can I do to use the pixel buffer object together with the v4l2 interface?
I want to use as less copy steps as possible.

The use case is reasonable (although V4L2_MEMORY_DMABUF would be better, but we're not there yet on the OpenGL side I believe), so let's try to debug this. First of all, what webcam driver do you use ?

Signature · 3 lines
Regards,

Laurent Pinchart
#2 lore raw

Hi Laurent,

the driver my device uses is the uvcvideo. I have the kernel 3.11.0-18 from Ubuntu 13.10 running. It is built in in a Thinkpad X240 notebook.

Regards,

Thomas

________________________________________
Von: Laurent Pinchart [[email protected]]
Gesendet: Mittwoch, 2. April 2014 21:23
An: Scheuermann, Mail
Cc: [email protected]
Betreff: Re: v4l2_buffer with PBO mapped memory

Hi Thomas,

Quoted 11 lines · On Wednesday 02 April 2014 17:10:42 Thomas Scheuermann wrote:

Hello,

I've written a program which shows my webcam with the v4l2 interface. In the v4l2_buffer I use the type V4L2_BUF_TYPE_VIDEO_CAPTURE and the memory is V4L2_MEMORY_USERPTR.
Everything works if I use malloced memory for frame buffers. Now I want to get the frames directly in OpenGL. I've mapped a pixel buffer object with glMapBuffer and wanted to use this as a frame buffer. But if I use this memory, the ioctl VIDIOC_QBUF fails with 'invalid argument'.

Quoted 3 lines

What can I do to use the pixel buffer object together with the v4l2 interface?
I want to use as less copy steps as possible.

The use case is reasonable (although V4L2_MEMORY_DMABUF would be better, but we're not there yet on the OpenGL side I believe), so let's try to debug this. First of all, what webcam driver do you use ?

--
Regards,

Laurent Pinchart

This message is subject to the following terms and conditions: MAIL DISCLAIMER<http://www.barco.com/en/maildisclaimer>

#3 lore raw

Hi Thomas,

Quoted 4 lines · Mail

Hi Laurent,

the driver my device uses is the uvcvideo. I have the kernel 3.11.0-18 from Ubuntu 13.10 running. It is built in in a Thinkpad X240 notebook.

OK. A bit of debugging will then be needed. Could you set the videobuf2-core debug parameter to 3, retry your test case and send us the kernel log ?

Signature · 3 lines
Regards,

Laurent Pinchart
#4 lore raw

Hi Laurent,

I've done the following:

echo 3 >/sys/module/videobuf2_core/parameters/debug

and found in /var/log/kern.log after starting my program:

Apr  4 21:53:48 x240 kernel: [239432.535077] vb2: Buffer 0, plane 0 offset 0x00000000
Apr  4 21:53:48 x240 kernel: [239432.535080] vb2: Buffer 1, plane 0 offset 0x001c2000
Apr  4 21:53:48 x240 kernel: [239432.535082] vb2: Buffer 2, plane 0 offset 0x00384000
Apr  4 21:53:48 x240 kernel: [239432.535083] vb2: Allocated 3 buffers, 1 plane(s) each
Apr  4 21:53:48 x240 kernel: [239432.535085] vb2: qbuf: userspace address for plane 0 changed, reacquiring memory
Apr  4 21:53:48 x240 kernel: [239432.535087] vb2: qbuf: failed acquiring userspace memory for plane 0
Apr  4 21:53:48 x240 kernel: [239432.535088] vb2: qbuf: buffer preparation failed: -22
Apr  4 21:53:48 x240 kernel: [239432.535128] vb2: streamoff: not streaming

Regards,

Thomas

________________________________________
Von: Laurent Pinchart [[email protected]]
Gesendet: Freitag, 4. April 2014 01:16
An: Scheuermann, Mail
Cc: [email protected]
Betreff: Re: AW: v4l2_buffer with PBO mapped memory

Hi Thomas,

Quoted 4 lines · Mail

Hi Laurent,

the driver my device uses is the uvcvideo. I have the kernel 3.11.0-18 from Ubuntu 13.10 running. It is built in in a Thinkpad X240 notebook.

OK. A bit of debugging will then be needed. Could you set the videobuf2-core debug parameter to 3, retry your test case and send us the kernel log ?

--
Regards,

Laurent Pinchart

This message is subject to the following terms and conditions: MAIL DISCLAIMER<http://www.barco.com/en/maildisclaimer>

#5 lore raw

Hi Thomas,

Quoted 8 lines · Mail

Hi Laurent,

I've done the following:

echo 3 >/sys/module/videobuf2_core/parameters/debug

and found in /var/log/kern.log after starting my program:

Quoted 7 lines
[239432.535077] vb2: Buffer 0, plane 0 offset 0x00000000
[239432.535080] vb2: Buffer 1, plane 0 offset 0x001c2000
[239432.535082] vb2: Buffer 2, plane 0 offset 0x00384000
[239432.535083] vb2: Allocated 3 buffers, 1 plane(s) each
[239432.535085] vb2: qbuf: userspace address for plane 0 changed,
reacquiring memory
[239432.535087] vb2: qbuf: failed acquiring userspace memory for plane 0

This confirms everything is working properly up to the point where videobuf2- vmalloc fails to acquire the user pointer memory. The problem comes from vb2_vmalloc_get_userptr() in drivers/media/v4l2-core/videobuf2-vmalloc.c. Unfortunately that function lacks debugging. Are you familiar enough with kernel programming to add printk statements there and see where it fails ?

Quoted 2 lines
[239432.535088] vb2: qbuf: buffer preparation failed: -22
[239432.535128] vb2: streamoff: not streaming
Signature · 3 lines
Regards,

Laurent Pinchart
#6 lore raw

Hi Laurent,

Quoted 18 lines · Laurent Pinchart

Hi Thomas,

Quoted 8 lines · Mail

Hi Laurent,

I've done the following:

echo 3 >/sys/module/videobuf2_core/parameters/debug

and found in /var/log/kern.log after starting my program:

Quoted 7 lines
[239432.535077] vb2: Buffer 0, plane 0 offset 0x00000000
[239432.535080] vb2: Buffer 1, plane 0 offset 0x001c2000
[239432.535082] vb2: Buffer 2, plane 0 offset 0x00384000
[239432.535083] vb2: Allocated 3 buffers, 1 plane(s) each
[239432.535085] vb2: qbuf: userspace address for plane 0 changed,
reacquiring memory
[239432.535087] vb2: qbuf: failed acquiring userspace memory for plane 0
Quoted 5 lines

This confirms everything is working properly up to the point where videobuf2- vmalloc fails to acquire the user pointer memory. The problem comes from vb2_vmalloc_get_userptr() in drivers/media/v4l2-core/videobuf2-vmalloc.c. Unfortunately that function lacks debugging. Are you familiar enough with kernel programming to add printk statements there and see where it fails ?

I was able to put some debug output in vb2_vmalloc_get_userptr. A call to 'vb2_get_contig_userptr' failed.
I will also put some debug code there to get more information.

Quoted 2 lines
Quoted 2 lines
[239432.535088] vb2: qbuf: buffer preparation failed: -22
[239432.535128] vb2: streamoff: not streaming

This message is subject to the following terms and conditions: MAIL DISCLAIMER<http://www.barco.com/en/maildisclaimer>

#7 lore raw

Hi Laurent,

Quoted 31 lines · Thomas Scheuermann

Hi Laurent,

Quoted 19 lines · Laurent Pinchart

Hi Thomas,

Quoted 8 lines · Mail

Hi Laurent,

I've done the following:

echo 3 >/sys/module/videobuf2_core/parameters/debug

and found in /var/log/kern.log after starting my program:

Quoted 8 lines
[239432.535077] vb2: Buffer 0, plane 0 offset 0x00000000
[239432.535080] vb2: Buffer 1, plane 0 offset 0x001c2000
[239432.535082] vb2: Buffer 2, plane 0 offset 0x00384000
[239432.535083] vb2: Allocated 3 buffers, 1 plane(s) each
[239432.535085] vb2: qbuf: userspace address for plane 0 changed,
reacquiring memory
[239432.535087] vb2: qbuf: failed acquiring userspace memory for

plane 0

Quoted 9 lines

This confirms everything is working properly up to the point where videobuf2-
vmalloc fails to acquire the user pointer memory. The problem comes from vb2_vmalloc_get_userptr() in drivers/media/v4l2-core/videobuf2-vmalloc.c.
Unfortunately that function lacks debugging. Are you familiar enough with
kernel programming to add printk statements there and see where it fails ?

Quoted 3 lines

I was able to put some debug output in vb2_vmalloc_get_userptr. A call to 'vb2_get_contig_userptr' failed.
I will also put some debug code there to get more information.

In vb2_get_contig_userptr I saw that the call to 'follow_pfn' failed and returned -22.
Do you know what the problem here is?

Quoted 9 lines
Quoted 2 lines
Quoted 2 lines
[239432.535088] vb2: qbuf: buffer preparation failed: -22
[239432.535128] vb2: streamoff: not streaming

This message is subject to the following terms and conditions: MAIL DISCLAIMER<http://www.barco.com/en/maildisclaimer>
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

This message is subject to the following terms and conditions: MAIL DISCLAIMER<http://www.barco.com/en/maildisclaimer>

#8 lore raw
Quoted 36 lines · Thomas Scheuermann

Hi Laurent,

Quoted 33 lines · Thomas Scheuermann

Hi Laurent,

Quoted 19 lines · Laurent Pinchart

Hi Thomas,

Quoted 8 lines · Mail

Hi Laurent,

I've done the following:

echo 3 >/sys/module/videobuf2_core/parameters/debug

and found in /var/log/kern.log after starting my program:

Quoted 8 lines
[239432.535077] vb2: Buffer 0, plane 0 offset 0x00000000
[239432.535080] vb2: Buffer 1, plane 0 offset 0x001c2000
[239432.535082] vb2: Buffer 2, plane 0 offset 0x00384000
[239432.535083] vb2: Allocated 3 buffers, 1 plane(s) each
[239432.535085] vb2: qbuf: userspace address for plane 0 changed,
reacquiring memory
[239432.535087] vb2: qbuf: failed acquiring userspace memory for

plane 0

Quoted 9 lines

This confirms everything is working properly up to the point where videobuf2-
vmalloc fails to acquire the user pointer memory. The problem comes from vb2_vmalloc_get_userptr() in drivers/media/v4l2-core/videobuf2-vmalloc.c.
Unfortunately that function lacks debugging. Are you familiar enough with
kernel programming to add printk statements there and see where it fails ?

I was able to put some debug output in vb2_vmalloc_get_userptr. A call to 'vb2_get_contig_userptr' failed.

Unless I am mistaken vb2_get_contig_userptr() requires that the userptr points to physically contiguous memory, but that should not be a requirement for videobuf2-vmalloc.

Pawel, any idea why vb2_get_contig_userptr() is used here?

Regards,

Hans

Quoted 21 lines
Quoted 1 line

I will also put some debug code there to get more information.

In vb2_get_contig_userptr I saw that the call to 'follow_pfn' failed and returned -22.
Do you know what the problem here is?

Quoted 9 lines
Quoted 2 lines
Quoted 2 lines
[239432.535088] vb2: qbuf: buffer preparation failed: -22
[239432.535128] vb2: streamoff: not streaming

This message is subject to the following terms and conditions: MAIL DISCLAIMER<http://www.barco.com/en/maildisclaimer>
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

This message is subject to the following terms and conditions: MAIL DISCLAIMER<http://www.barco.com/en/maildisclaimer> --
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html