Skip to content
Open
Changes from 3 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
20 changes: 20 additions & 0 deletions src/capturer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,26 @@ impl Capturer {
}
}

/// Attempts to return the next captured frame without blocking.
///
/// Processes all currently available channel items until a usable frame is found.
/// Returns `Ok(None)` if no frames are available at this moment (not that items were filtered).
/// Returns `Err(mpsc::RecvError)` if the capture channel has been disconnected.
pub fn try_get_next_frame(&self) -> Result<Option<Frame>, mpsc::RecvError> {
loop {
match self.rx.try_recv() {
Ok(res) => {
if let Some(frame) = self.engine.process_channel_item(res) {
return Ok(Some(frame));
}
// Item filtered, try next without blocking
}
Err(mpsc::TryRecvError::Empty) => return Ok(None),
Err(mpsc::TryRecvError::Disconnected) => return Err(mpsc::RecvError),
}
}
}

/// Get the dimensions the frames will be captured in
pub fn get_output_frame_size(&mut self) -> [u32; 2] {
self.engine.get_output_frame_size()
Expand Down