raymanfx / libv4l-rs

Video4Linux2 bindings for Rust
MIT License
155 stars 65 forks source link

Cannot set bytesused using meta struct when queueing data. #30

Closed rytec-nl closed 3 years ago

rytec-nl commented 3 years ago

Hi,

I'm not sure if this is me misunderstanding something but when I fill the mmap output buffer with data I do not see a way to set the bytesUsed. Im streaming mjpeg and depending of the encoding the data size changes. As far as I can see now always the max buffer size is set. I tried using the meta struct to set meta.bytesused but that does not seem to be used in the library. As a workaround i did this in src/io/mmap/stream.rs:

diff --git a/src/io/mmap/stream.rs b/src/io/mmap/stream.rs
index 8a30846..13b21fc 100644
--- a/src/io/mmap/stream.rs
+++ b/src/io/mmap/stream.rs
@@ -190,9 +190,7 @@ impl<'a, 'b> OutputStream<'b> for Stream<'a> {
             v4l2_buf.type_ = self.buf_type as u32;
             v4l2_buf.memory = Memory::Mmap as u32;
             v4l2_buf.index = index as u32;
-            // output settings
-            let bytes = self.arena.get_unchecked_mut(index);
-            v4l2_buf.bytesused = bytes.len() as u32;
+            v4l2_buf.bytesused = self.buf_meta[index].bytesused;
             v4l2_buf.field = self.buf_meta[index].field;

             v4l2::ioctl(

However I do not know if this breaks other usage of the OutputStream. Am I missing something? Or am I on the right track and should my change be expanded to cover all situations.

Thanks in advance!

raymanfx commented 3 years ago

I recall people recently reported issues about the same thing. I attempted to fix those (runtime) crashes with https://github.com/raymanfx/libv4l-rs/commit/4d003b69f1dfa8580ff3127cfca03fc6888da509, but that only prevents copying a larger range of input data to a smaller output buffer.

I assume your patch is still needed for semantical correctness. Honestly I did not test output streaming for some weeks now, perhaps I should do that again soon. Could you send a PR for this one as well? Then we'll review it and I'll run some tests with MJPG frame encoding.

rytec-nl commented 3 years ago

Done: https://github.com/raymanfx/libv4l-rs/pull/33

One issue that I can see is when bytesused is not set on the meta struct. So there should be some check there and then perhaps default to the max size?