diff options
author | Sebastian Dröge <sebastian@centricular.com> | 2022-02-14 15:36:50 +0300 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2022-02-14 15:36:50 +0300 |
commit | 03787ef857809563584adff568cfdb23999e0b3b (patch) | |
tree | c282dfb5d53649bfe5cecd5df37a80deed9a0d58 /video/rav1e/src/rav1enc/imp.rs | |
parent | 001fdd4d03944986e5036002f261b016bb865fcb (diff) |
rav1eenc: Use `AtomicRefCell` instead of `Mutex` for the state
It's only accessed from the streaming thread.
Diffstat (limited to 'video/rav1e/src/rav1enc/imp.rs')
-rw-r--r-- | video/rav1e/src/rav1enc/imp.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/video/rav1e/src/rav1enc/imp.rs b/video/rav1e/src/rav1enc/imp.rs index 7c832ce1..3de1873c 100644 --- a/video/rav1e/src/rav1enc/imp.rs +++ b/video/rav1e/src/rav1enc/imp.rs @@ -8,6 +8,7 @@ // // SPDX-License-Identifier: MIT/Apache-2.0 +use atomic_refcell::AtomicRefCell; use gst::glib; use gst::gst_debug; use gst::subclass::prelude::*; @@ -220,7 +221,7 @@ struct State { #[derive(Default)] pub struct Rav1Enc { - state: Mutex<Option<State>>, + state: AtomicRefCell<Option<State>>, settings: Mutex<Settings>, } @@ -608,7 +609,7 @@ impl ElementImpl for Rav1Enc { impl VideoEncoderImpl for Rav1Enc { fn stop(&self, _element: &Self::Type) -> Result<(), gst::ErrorMessage> { - *self.state.lock().unwrap() = None; + *self.state.borrow_mut() = None; Ok(()) } @@ -860,7 +861,7 @@ impl VideoEncoderImpl for Rav1Enc { let container_sequence_header = gst::Buffer::from_mut_slice(context.container_sequence_header()); - *self.state.lock().unwrap() = Some(State { + *self.state.borrow_mut() = Some(State { context, video_info, }); @@ -885,7 +886,7 @@ impl VideoEncoderImpl for Rav1Enc { fn flush(&self, element: &Self::Type) -> bool { gst_debug!(CAT, obj: element, "Flushing"); - let mut state_guard = self.state.lock().unwrap(); + let mut state_guard = self.state.borrow_mut(); if let Some(ref mut state) = *state_guard { state.context.flush(); while let Ok(_) | Err(data::EncoderStatus::Encoded) = state.context.receive_packet() { @@ -899,7 +900,7 @@ impl VideoEncoderImpl for Rav1Enc { fn finish(&self, element: &Self::Type) -> Result<gst::FlowSuccess, gst::FlowError> { gst_debug!(CAT, obj: element, "Finishing"); - let mut state_guard = self.state.lock().unwrap(); + let mut state_guard = self.state.borrow_mut(); if let Some(ref mut state) = *state_guard { state.context.flush(); self.output_frames(element, state)?; @@ -913,7 +914,7 @@ impl VideoEncoderImpl for Rav1Enc { element: &Self::Type, frame: gst_video::VideoCodecFrame, ) -> Result<gst::FlowSuccess, gst::FlowError> { - let mut state_guard = self.state.lock().unwrap(); + let mut state_guard = self.state.borrow_mut(); let state = state_guard.as_mut().ok_or(gst::FlowError::NotNegotiated)?; self.output_frames(element, state)?; |