From 69b234457a1881630d66ef8811ed91d8b7204965 Mon Sep 17 00:00:00 2001 From: cijiugechu Date: Mon, 13 Oct 2025 00:30:21 +0800 Subject: [PATCH 1/5] add non-blocking `try_get_next_frame` --- src/capturer/mod.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/capturer/mod.rs b/src/capturer/mod.rs index 04a189b..45fedeb 100644 --- a/src/capturer/mod.rs +++ b/src/capturer/mod.rs @@ -140,6 +140,20 @@ impl Capturer { } } + /// Attempts to return the next captured frame without blocking. + pub fn try_get_next_frame(&self) -> Result, mpsc::RecvError> { + match self.rx.try_recv() { + Ok(res) => { + if let Some(frame) = self.engine.process_channel_item(res) { + return Ok(Some(frame)); + } + return Ok(None); + } + Err(mpsc::TryRecvError::Empty) => Ok(None), + Err(mpsc::TryRecvError::Disconnected) => 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() From f454d78ac7f9694170d7910480848a28fafe82cb Mon Sep 17 00:00:00 2001 From: cijiugechu Date: Mon, 13 Oct 2025 01:56:11 +0800 Subject: [PATCH 2/5] align with blocking version --- src/capturer/mod.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/capturer/mod.rs b/src/capturer/mod.rs index 45fedeb..7ca8b64 100644 --- a/src/capturer/mod.rs +++ b/src/capturer/mod.rs @@ -142,15 +142,17 @@ impl Capturer { /// Attempts to return the next captured frame without blocking. pub fn try_get_next_frame(&self) -> Result, mpsc::RecvError> { - match self.rx.try_recv() { - Ok(res) => { - if let Some(frame) = self.engine.process_channel_item(res) { - return Ok(Some(frame)); + 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 } - return Ok(None); + Err(mpsc::TryRecvError::Empty) => return Ok(None), + Err(mpsc::TryRecvError::Disconnected) => return Err(mpsc::RecvError), } - Err(mpsc::TryRecvError::Empty) => Ok(None), - Err(mpsc::TryRecvError::Disconnected) => Err(mpsc::RecvError), } } From e82713065c55c129e50ec2e577485ac8a19a44c4 Mon Sep 17 00:00:00 2001 From: cijiugechu Date: Mon, 13 Oct 2025 02:05:05 +0800 Subject: [PATCH 3/5] update comment --- src/capturer/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/capturer/mod.rs b/src/capturer/mod.rs index 7ca8b64..3f27219 100644 --- a/src/capturer/mod.rs +++ b/src/capturer/mod.rs @@ -141,6 +141,10 @@ 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, mpsc::RecvError> { loop { match self.rx.try_recv() { From c0cc23446acb8b1adfe89e1438dca29248e04ab6 Mon Sep 17 00:00:00 2001 From: cijiugechu Date: Mon, 13 Oct 2025 02:08:05 +0800 Subject: [PATCH 4/5] fix typo --- src/capturer/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/capturer/mod.rs b/src/capturer/mod.rs index 3f27219..aa0b1c8 100644 --- a/src/capturer/mod.rs +++ b/src/capturer/mod.rs @@ -143,7 +143,7 @@ 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 `Ok(None)` if no frames are available at this moment (note that items were filtered). /// Returns `Err(mpsc::RecvError)` if the capture channel has been disconnected. pub fn try_get_next_frame(&self) -> Result, mpsc::RecvError> { loop { From bd8e9a46d1aaec65af4cc5a2d005800aeb2f2dc7 Mon Sep 17 00:00:00 2001 From: cijiugechu Date: Mon, 13 Oct 2025 02:12:42 +0800 Subject: [PATCH 5/5] udpate comment --- src/capturer/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/capturer/mod.rs b/src/capturer/mod.rs index aa0b1c8..9ee311d 100644 --- a/src/capturer/mod.rs +++ b/src/capturer/mod.rs @@ -143,7 +143,7 @@ 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 (note that items were filtered). + /// Returns `Ok(None)` if the channel is empty; filtered items are processed transparently. /// Returns `Err(mpsc::RecvError)` if the capture channel has been disconnected. pub fn try_get_next_frame(&self) -> Result, mpsc::RecvError> { loop {