Waits for a sample to become available and returns it. Uses a semaphore to track available frames. The semaphore's permits accumulate when frames arrive, ensuring no notifications are missed.
(&self)
| 524 | /// Uses a semaphore to track available frames. The semaphore's permits |
| 525 | /// accumulate when frames arrive, ensuring no notifications are missed. |
| 526 | async fn wait_for_sample(&self) -> Result<SendableSample> { |
| 527 | let permit = self.shared.frame_ready.acquire().await.map_err(|e| { |
| 528 | CameraError::Io(std::io::Error::other(format!("Semaphore error: {}", e))) |
| 529 | })?; |
| 530 | permit.forget(); |
| 531 | |
| 532 | let mut slot = self.shared.sample_slot.lock().unwrap(); |
| 533 | slot.take() |
| 534 | .ok_or_else(|| CameraError::Io(std::io::Error::other("Frame slot was empty"))) |
| 535 | } |
| 536 | } |