Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose bytesused to users #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions examples/save-jpeg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ fn main() -> anyhow::Result<()> {
device.capabilities()?.device_capabilities()
);

let capture = device.video_capture(PixFormat::new(u32::MAX, u32::MAX, PixelFormat::JPEG))?;
let capture = device.video_capture(PixFormat::new(u32::MAX, u32::MAX, PixelFormat::MJPG))?;

println!("negotiated format: {:?}", capture.format());

let mut stream = capture.into_stream()?;

println!("stream started, waiting for data");
stream.dequeue(|buf| {
file.write_all(&*buf)?;
let bytesused = usize::try_from (buf.bytesused ()).unwrap ();
file.write_all(&buf [0..bytesused])?;
println!("wrote file");
Ok(())
})?;
Expand Down
6 changes: 6 additions & 0 deletions src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ impl ReadStream {
unsafe { slice::from_raw_parts(buffer.ptr as *const u8, buffer.length as usize) };
let view = ReadBufferView {
flags: buf.flags,
bytesused: buf.bytesused,
data,
};

Expand Down Expand Up @@ -282,10 +283,15 @@ impl AsRawFd for ReadStream {
/// Dereferences to a byte slice.
pub struct ReadBufferView<'a> {
flags: BufFlag,
bytesused: u32,
data: &'a [u8],
}

impl ReadBufferView<'_> {
pub fn bytesused(&self) -> u32 {
self.bytesused
}

/// Returns whether the error flag for this buffer is set.
///
/// If this returns `true`, the application should expect data corruption in the buffer data.
Expand Down