mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-01-19 23:55:42 +00:00
ebur128level: Use an atomic bool for the resetting and check on every iteration
Instead of checking it only once per buffer.
This commit is contained in:
parent
81f9d334e8
commit
195f22c2e3
1 changed files with 18 additions and 10 deletions
|
@ -14,6 +14,7 @@ use gst_base::prelude::*;
|
||||||
use gst_base::subclass::prelude::*;
|
use gst_base::subclass::prelude::*;
|
||||||
|
|
||||||
use std::i32;
|
use std::i32;
|
||||||
|
use std::sync::atomic;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
@ -87,7 +88,6 @@ struct Settings {
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
post_messages: bool,
|
post_messages: bool,
|
||||||
interval: u64,
|
interval: u64,
|
||||||
reset: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Settings {
|
impl Default for Settings {
|
||||||
|
@ -96,7 +96,6 @@ impl Default for Settings {
|
||||||
mode: DEFAULT_MODE,
|
mode: DEFAULT_MODE,
|
||||||
post_messages: DEFAULT_POST_MESSAGES,
|
post_messages: DEFAULT_POST_MESSAGES,
|
||||||
interval: DEFAULT_INTERVAL,
|
interval: DEFAULT_INTERVAL,
|
||||||
reset: false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,6 +112,7 @@ struct State {
|
||||||
pub struct EbuR128Level {
|
pub struct EbuR128Level {
|
||||||
settings: Mutex<Settings>,
|
settings: Mutex<Settings>,
|
||||||
state: AtomicRefCell<Option<State>>,
|
state: AtomicRefCell<Option<State>>,
|
||||||
|
reset: atomic::AtomicBool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
|
@ -133,7 +133,7 @@ impl ObjectImpl for EbuR128Level {
|
||||||
let imp = EbuR128Level::from_instance(&this);
|
let imp = EbuR128Level::from_instance(&this);
|
||||||
|
|
||||||
gst_info!(CAT, obj: &this, "Resetting measurements",);
|
gst_info!(CAT, obj: &this, "Resetting measurements",);
|
||||||
imp.settings.lock().unwrap().reset = true;
|
imp.reset.store(true, atomic::Ordering::SeqCst);
|
||||||
|
|
||||||
None
|
None
|
||||||
})
|
})
|
||||||
|
@ -432,13 +432,6 @@ impl BaseTransformImpl for EbuR128Level {
|
||||||
gst::FlowError::NotNegotiated
|
gst::FlowError::NotNegotiated
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
if settings.reset {
|
|
||||||
self.settings.lock().unwrap().reset = false;
|
|
||||||
state.ebur128.reset();
|
|
||||||
state.interval_frames_remaining = state.interval_frames;
|
|
||||||
state.num_frames = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut timestamp = buf.get_pts();
|
let mut timestamp = buf.get_pts();
|
||||||
let segment = element.get_segment().downcast::<gst::ClockTime>().ok();
|
let segment = element.get_segment().downcast::<gst::ClockTime>().ok();
|
||||||
|
|
||||||
|
@ -451,6 +444,21 @@ impl BaseTransformImpl for EbuR128Level {
|
||||||
|
|
||||||
let mut frames = Frames::from_audio_buffer(element, &buf)?;
|
let mut frames = Frames::from_audio_buffer(element, &buf)?;
|
||||||
while frames.num_frames() > 0 {
|
while frames.num_frames() > 0 {
|
||||||
|
if self
|
||||||
|
.reset
|
||||||
|
.compare_exchange(
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
atomic::Ordering::SeqCst,
|
||||||
|
atomic::Ordering::SeqCst,
|
||||||
|
)
|
||||||
|
.is_ok()
|
||||||
|
{
|
||||||
|
state.ebur128.reset();
|
||||||
|
state.interval_frames_remaining = state.interval_frames;
|
||||||
|
state.num_frames = 0;
|
||||||
|
}
|
||||||
|
|
||||||
let to_process = u64::min(state.interval_frames_remaining, frames.num_frames() as u64);
|
let to_process = u64::min(state.interval_frames_remaining, frames.num_frames() as u64);
|
||||||
|
|
||||||
frames
|
frames
|
||||||
|
|
Loading…
Reference in a new issue