loyd / rscam

Rust wrapper for v4l2
Other
116 stars 22 forks source link

InvalidInput for Camera::start with a valid config, only in release mode #18

Open joelgallant opened 6 years ago

joelgallant commented 6 years ago

When running a --release build (no non-standard options), Camera::start, which functions correctly with debug mode, throws the error: Io(Os { code: 22, kind: InvalidInput, message: "Invalid argument" }). I cannot adjust the options correctly to get it to not do this, and the options I select do show up when doing camera.resolution, etc.

As far as I can tell, it derives from here: https://github.com/loyd/rscam/blob/5e7a429fe1faed82925832c5ea5d3c9dadb6b239/src/v4l2.rs#L87-90

This led me down the path of enabling the no_wrapper feature, which did work in release mode, but changed the available formats, frame rates, etc. that it would allow me to use. I assume that differences between release and debug are not intentional, so I'd rather avoid that road.

It's worth mentioning that I am cross compiling for armv7-unknown-linux-gnueabihf.

I'm going to look in to this issue since it does matter to me for my project, but if you have any ideas I'd love any tips you might have?

joelgallant commented 6 years ago

On second look, I'm wrong about where the error is coming from - I believe it's alloc_buffers and mmap.

Specifically, v4l2_mmap returns usize::MAX and triggers the check_io!. The error is last_os_error, which is incorrect in this case as far as I can tell - it reports as InvalidArgument (which probably does make sense, since this is linking to v4l2_mmap, that doesn't report it's error using last_os_error).

loyd commented 6 years ago

this is linking to v4l2_mmap, that doesn't report it's error using last_os_error

v4l2_mmap uses errno, according to the documentation

It's worth mentioning that I am cross compiling for armv7-unknown-linux-gnueabihf.

I'll try to reproduce your problem as soon as I get my raspberry back.

joelgallant commented 6 years ago

I noticed that it does say it sets errno, when printing last_os_error before/after v4l2_mmap, it doesn't change - which doesn't mean it's not working.

skligys commented 6 years ago

I am seeing a similar error in Camera::start (also cross-compiling to Pi), also only in --release build:

I/O error: Value too large for defined data type (os error 75)

Strangely enough, if I clone rscam's source locally and build it:

[dependencies] rscam = { path = "vendor/rscam" }

everything works just fine. Was the failure fixed since 0.5.4 release?

jbolila commented 5 years ago

Compiling locally on a raspberry pi, also gives an error when compiled with --release.

Comparing both strace output the issue happens on the following call:

ioctl(3, VIDIOC_REQBUFS, {count=2, type=V4L2_BUF_TYPE_VIDEO_CAPTURE, memory=V4L2_MEMORY_MMAP}) = 0 ({count=2})
ioctl(3, VIDIOC_QUERYBUF, {type=V4L2_BUF_TYPE_VIDEO_CAPTURE, index=0, memory=V4L2_MEMORY_MMAP, m.offset=0, length=307200, bytesused=0, flags=0x2000 /* V4L2_BUF_FLAG_??? */, ...}) = 0
write(2, "thread '", 8thread ')                 = 8
write(2, "main", 4main)                     = 4
write(2, "' panicked at '", 15' panicked at ')         = 15
write(2, "called `Result::unwrap()` on an "..., 113called `Result::unwrap()` on an `Err` value: Io(Os { code: 22, kind: InvalidInput, message: "Invalid argument" })) = 113
write(2, "', ", 3', )                      = 3

compared with the debug version:

ioctl(3, VIDIOC_REQBUFS, {count=2, type=V4L2_BUF_TYPE_VIDEO_CAPTURE, memory=V4L2_MEMORY_MMAP}) = 0 ({count=2})
ioctl(3, VIDIOC_QUERYBUF, {type=V4L2_BUF_TYPE_VIDEO_CAPTURE, index=0, memory=V4L2_MEMORY_MMAP, m.offset=0, length=307200, bytesused=0, flags=0x2000 /* V4L2_BUF_FLAG_??? */, ...}) = 0
mmap2(NULL, 307200, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0) = 0x76c02000
ioctl(3, VIDIOC_QUERYBUF, {type=V4L2_BUF_TYPE_VIDEO_CAPTURE, index=1, memory=V4L2_MEMORY_MMAP, m.offset=0x4b000, length=307200, bytesused=0, flags=0x2000 /* V4L2_BUF_FLAG_??? */, ...}) = 0
mmap2(NULL, 307200, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0) = 0x767b5000
ioctl(3, VIDIOC_QBUF, {type=V4L2_BUF_TYPE_VIDEO_CAPTURE, index=0, memory=V4L2_MEMORY_MMAP, m.offset=0, length=307200, bytesused=0, flags=V4L2_BUF_FLAG_MAPPED|V4L2_BUF_FLAG_QUEUED|0x2000, ...}) = 0
ioctl(3, VIDIOC_QBUF, {type=V4L2_BUF_TYPE_VIDEO_CAPTURE, index=1, memory=V4L2_MEMORY_MMAP, m.offset=0x4b000, length=307200, bytesused=0, flags=V4L2_BUF_FLAG_QUEUED|0x2000, ...}) = 0
ioctl(3, VIDIOC_STREAMON, [V4L2_BUF_TYPE_VIDEO_CAPTURE]) = 0

I'm using the latest version (v0.5.4)

chris-ricketts commented 4 years ago

I've just encountered this cross-compiling to armv7-unknown-linux-gnueabihf as well. However, in this case the error occurs when built in debug, with --release it works.

This is version 0.5.5