raymanfx / libv4l-rs

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

Allow setting of bytesused through Meta struct. #33

Closed rytec-nl closed 3 years ago

rytec-nl commented 3 years ago

Fixes #30

raymanfx commented 3 years ago

I think we need some kind of safeguard here. If self.buf_meta[index].bytesused is not set, I would like to retain the old behavior.

rytec-nl commented 3 years ago

Indeed, would it make sense to make the meta.bytesused an Option?

raymanfx commented 3 years ago

The Default::default() impl for the Metadata struct (https://github.com/raymanfx/libv4l-rs/blob/master/src/buffer.rs#L102) will zero that field. So it's fine to check for a value of 0 and then just fallback to the existing logic.

rytec-nl commented 3 years ago

If I read the v4l2 documentation, if bytesused is set to 0, for an output stream, the value is set to the size of the plane. So would it then not mean that the current implementation would work?

raymanfx commented 3 years ago

Ah, good find. Yes, I think you're right. However, that behavior seems counter-intuitive to me. Would you mind adding a comment to that portion of the code referencing the v4l2 docs and hinting at this specific fallback behavior?