Skip to content

Commit

Permalink
Merge pull request #650 from dilr/crossbeamify
Browse files Browse the repository at this point in the history
Change webcam channel implementation to mpmc.
  • Loading branch information
kaikalii authored Jan 24, 2025
2 parents f3c1d5e + 1d6cfcf commit 82236c4
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/sys/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use std::{
};

use colored::Colorize;
#[cfg(feature = "webcam")]
use crossbeam_channel as channel;
use dashmap::DashMap;
use once_cell::sync::Lazy;

Expand Down Expand Up @@ -77,15 +79,10 @@ impl<T> Drop for ChildStream<T> {

#[cfg(feature = "webcam")]
struct WebcamChannel {
send: std::sync::mpsc::Sender<()>,
recv: std::sync::mpsc::Receiver<Result<image::RgbImage, String>>,
send: channel::Sender<()>,
recv: channel::Receiver<Result<image::RgbImage, String>>,
}

#[cfg(feature = "webcam")]
unsafe impl Send for WebcamChannel {}
#[cfg(feature = "webcam")]
unsafe impl Sync for WebcamChannel {}

#[cfg(feature = "webcam")]
impl WebcamChannel {
fn new(index: usize) -> Result<Self, String> {
Expand All @@ -94,8 +91,8 @@ impl WebcamChannel {
utils::{CameraIndex, RequestedFormat, RequestedFormatType},
Camera,
};
let (req_send, req_recv) = std::sync::mpsc::channel();
let (image_send, image_recv) = std::sync::mpsc::channel();
let (req_send, req_recv) = channel::unbounded();
let (image_send, image_recv) = channel::unbounded();
std::thread::spawn(move || {
let mut camera = match Camera::new(
CameraIndex::Index(index as u32),
Expand Down

0 comments on commit 82236c4

Please sign in to comment.