polygonaltree
Posts: 2
Joined: Tue Feb 10, 2015 4:41 pm

pi 2 and picamera, v4l2 not working

Tue Feb 10, 2015 4:51 pm

Hi all,
We have some python code that uses openCV and the v4l2 driver for the picamera. It works ok with all raspberry pi's based on bcm2835 but does not work in the pi 2 with the bcm2836 chip.
So, it seems that the module bcm2835-v4l2 is not working properly with the bcm2836, something that make sense. It starts but we only see green and black flickering.
Is there any solution, workaround or a future release of a module bcm2836-v4l2 to solve that?

The camera works well with raspistill and raspisvid but we really need the v4l2 driver.

Thank you.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7273
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: pi 2 and picamera, v4l2 not working

Tue Feb 10, 2015 5:31 pm

I now have a Pi2 to play with, but haven't fired it up as yet to check things out. I would have anticipated Pi Towers would have done so though. The V4L2 uses exactly the same API to access the camera on the GPU as raspistill/vid, so I wouldn't have anticipated any real issues.

What image format are you requesting from the V4L2 driver? "v4l2-ctl -v" should tell you once you've run your app. I suspect BGR3 from previous experience of OpenCV, but no guarantees.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

polygonaltree
Posts: 2
Joined: Tue Feb 10, 2015 4:41 pm

Re: pi 2 and picamera, v4l2 not working

Tue Feb 10, 2015 6:43 pm

Thank you for notice that the bcm2835-v4l2 works in the pi2. It does indeed.

We discover a bug in our code. Never use target_fps = 1 in opencv, because it crashes the pi camera badly and you have to restart the pi to get it working again.
This is SOLVED

towolf
Posts: 421
Joined: Fri Jan 18, 2013 2:11 pm

Re: pi 2 and picamera, v4l2 not working

Tue Feb 10, 2015 11:14 pm

Dunno if I should post this here or in a new thread. I get some kind of oops in dmesg using the V4l2 driver.

Code: Select all

[  118.606138] bcm2835-v4l2: Work-around for gstreamer issue is active.
[  118.613075] bcm2835-v4l2: V4L2 device registered as video0 - stills mode > 1280x720
[  118.626129] bcm2835-v4l2: Broadcom 2835 MMAL video capture ver 0.0.2 loaded.
[  141.960452] ------------[ cut here ]------------
[  141.965232] WARNING: CPU: 2 PID: 389 at drivers/media/v4l2-core/videobuf2-core.c:2135 __vb2_queue_cancel+0xec/0x150 [videobuf2_core]()
[  141.977588] Modules linked in: bcm2835_v4l2 videobuf2_vmalloc videobuf2_memops videobuf2_core v4l2_common videodev media w1_therm w1_gpio sch_fq_codel wire cn leds_gpio led_class uio_pdrv_genirq uio snd_bcm2835 snd_pcm snd_timer snd bcm2708_rng rng_core ipv6
[  142.001389] CPU: 2 PID: 389 Comm: gst-launch-1.0 Not tainted 3.18.6-2-ARCH #1
[  142.008676] [<c0015630>] (unwind_backtrace) from [<c0011f2c>] (show_stack+0x10/0x14)
[  142.016617] [<c0011f2c>] (show_stack) from [<c0734b80>] (dump_stack+0x84/0xc4)
[  142.024043] [<c0734b80>] (dump_stack) from [<c002cac4>] (warn_slowpath_common+0x74/0x90)
[  142.047887] [<c002cac4>] (warn_slowpath_common) from [<c002cb7c>] (warn_slowpath_null+0x1c/0x24)
[  142.089380] [<c002cb7c>] (warn_slowpath_null) from [<bf14c634>] (__vb2_queue_cancel+0xec/0x150 [videobuf2_core])
[  142.133246] [<bf14c634>] (__vb2_queue_cancel [videobuf2_core]) from [<bf14e088>] (vb2_internal_streamoff+0x34/0xc4 [videobuf2_core])
[  142.174630] [<bf14e088>] (vb2_internal_streamoff [videobuf2_core]) from [<bf1149c8>] (__video_do_ioctl+0x264/0x2d8 [videodev])
[  142.209799] [<bf1149c8>] (__video_do_ioctl [videodev]) from [<bf1142e0>] (video_usercopy+0x17c/0x5f4 [videodev])
[  142.244312] [<bf1142e0>] (video_usercopy [videodev]) from [<bf110638>] (v4l2_ioctl+0x140/0x160 [videodev])
[  142.278534] [<bf110638>] (v4l2_ioctl [videodev]) from [<c0152de0>] (do_vfs_ioctl+0x3dc/0x59c)
[  142.311810] [<c0152de0>] (do_vfs_ioctl) from [<c0152fd4>] (SyS_ioctl+0x34/0x5c)
[  142.331536] [<c0152fd4>] (SyS_ioctl) from [<c000e5c0>] (ret_fast_syscall+0x0/0x30)
[  142.363617] ---[ end trace 63c89990629b0051 ]---
[  143.930024] bcm2835-v4l2: error 0 waiting for frame completion

This oops happens when I run this GStreamer pipeline (which does not do anything) and then cancel with Ctrl-C. Then it emits one frame and quits. Very strange.

Code: Select all

gst-launch-1.0 -e v4l2src ! video/x-h264,width=640,height=480,fps=30 ! h264parse ! rtph264pay config-interval=10 pt=96 ! udpsink host=10.0.0.9 port=9000 sync=false async=true

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7273
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: pi 2 and picamera, v4l2 not working

Wed Feb 11, 2015 7:05 am

Warning, not Oops (which would normally be fatal). Already logged as https://github.com/raspberrypi/linux/issues/817 and is due to more sanity checking in the v4l2-core after updating to 3.18 kernel
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

towolf
Posts: 421
Joined: Fri Jan 18, 2013 2:11 pm

Re: pi 2 and picamera, v4l2 not working

Wed Feb 11, 2015 2:19 pm

Thanks. Sounds like the warning is not the cause of the issue, but just happens when stopping the non-working stream.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7273
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: pi 2 and picamera, v4l2 not working

Wed Feb 11, 2015 2:51 pm

towolf wrote:Thanks. Sounds like the warning is not the cause of the issue, but just happens when stopping the non-working stream.
AIUI It happens when stopping any stream!

As for non-working streams, there has been a change made to V4L2-core that as soon as a buffer is returned by the app to the framework, the framework memsets the header to 0. There's already been a bug fix for guvcviewer, mjpeg-streamer. motion, and a couple of others which were treating the header as their own even though they had returned it, so objected when they then found bytesused as 0. See links off https://github.com/raspberrypi/firmware/issues/347
It may be that gstreamer has a similar bug (should have been fixed upstream by now as the V4L2 changes came in with kernel 3.16).
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

towolf
Posts: 421
Joined: Fri Jan 18, 2013 2:11 pm

Re: pi 2 and picamera, v4l2 not working

Wed Feb 11, 2015 3:53 pm

Ah, thank you.

I think this is relevant: https://bugzilla.gnome.org/show_bug.cgi?id=733864#c13

Return to “Camera board”