ndisrc: Remove unnecessary Arc around the timestamp observations and use AtomicRefCell instead of Mutex

This commit is contained in:
Sebastian Dröge 2022-06-06 14:17:40 +03:00
parent 718734ab18
commit b82acb9ca9
2 changed files with 6 additions and 4 deletions

View file

@ -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"

View file

@ -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) {