diff options
author | Sebastian Dröge <sebastian@centricular.com> | 2022-06-06 14:17:40 +0300 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2022-10-12 21:29:07 +0300 |
commit | b82acb9ca95b3c2f075b695398759104f9790b41 (patch) | |
tree | 8c81551472c150db9bc30287db2cc29b7f8f16ff /net/ndi | |
parent | 718734ab181d92a3b0e899d72d0b6571bcbe5793 (diff) |
ndisrc: Remove unnecessary Arc around the timestamp observations and use AtomicRefCell instead of Mutex
Diffstat (limited to 'net/ndi')
-rw-r--r-- | net/ndi/Cargo.toml | 1 | ||||
-rw-r--r-- | net/ndi/src/receiver.rs | 9 |
2 files changed, 6 insertions, 4 deletions
diff --git a/net/ndi/Cargo.toml b/net/ndi/Cargo.toml index 95447083..b645d7e0 100644 --- a/net/ndi/Cargo.toml +++ b/net/ndi/Cargo.toml @@ -16,6 +16,7 @@ gst-video = { package = "gstreamer-video", version = "0.18", features = ["v1_12" byte-slice-cast = "1" once_cell = "1.0" byteorder = "1.0" +atomic_refcell = "0.1" [build-dependencies] gst-plugin-version-helper = "0.7" diff --git a/net/ndi/src/receiver.rs b/net/ndi/src/receiver.rs index 8801addb..b0d98776 100644 --- a/net/ndi/src/receiver.rs +++ b/net/ndi/src/receiver.rs @@ -10,6 +10,8 @@ use std::collections::VecDeque; use std::sync::{Arc, Condvar, Mutex, Weak}; use std::thread; +use atomic_refcell::AtomicRefCell; + use super::*; static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| { @@ -225,8 +227,7 @@ struct ReceiverQueueInner { const WINDOW_LENGTH: u64 = 512; const WINDOW_DURATION: u64 = 2_000_000_000; -#[derive(Clone)] -struct Observations(Arc<Mutex<ObservationsInner>>); +struct Observations(AtomicRefCell<ObservationsInner>); struct ObservationsInner { base_remote_time: Option<u64>, @@ -254,7 +255,7 @@ impl Default for ObservationsInner { impl Observations { fn new() -> Self { - Self(Arc::new(Mutex::new(ObservationsInner::default()))) + Self(AtomicRefCell::new(ObservationsInner::default())) } // Based on the algorithm used in GStreamer's rtpjitterbuffer, which comes from @@ -282,7 +283,7 @@ impl Observations { gst::ClockTime::from_nseconds(remote_time), ); - let mut inner = self.0.lock().unwrap(); + let mut inner = self.0.borrow_mut(); let (base_remote_time, base_local_time) = match (inner.base_remote_time, inner.base_local_time) { |