mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-11-10 20:31:10 +00:00
ndisrc: Move from start/stop to change_state for slight code simplification
All state change related code is in a single place now. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1727>
This commit is contained in:
parent
0135c4251c
commit
f2658eb773
1 changed files with 58 additions and 49 deletions
|
@ -363,6 +363,7 @@ impl ElementImpl for NdiSrc {
|
||||||
PAD_TEMPLATES.as_ref()
|
PAD_TEMPLATES.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::single_match)]
|
||||||
fn change_state(
|
fn change_state(
|
||||||
&self,
|
&self,
|
||||||
transition: gst::StateChange,
|
transition: gst::StateChange,
|
||||||
|
@ -389,10 +390,66 @@ impl ElementImpl for NdiSrc {
|
||||||
controller.shutdown();
|
controller.shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
gst::StateChange::ReadyToPaused => {
|
||||||
|
*self.state.lock().unwrap() = Default::default();
|
||||||
|
let settings = self.settings.lock().unwrap().clone();
|
||||||
|
|
||||||
|
if settings.ndi_name.is_none() && settings.url_address.is_none() {
|
||||||
|
gst::element_imp_error!(
|
||||||
|
self,
|
||||||
|
gst::LibraryError::Settings,
|
||||||
|
["No NDI name or URL/address given"]
|
||||||
|
);
|
||||||
|
|
||||||
|
return Err(gst::StateChangeError);
|
||||||
|
}
|
||||||
|
|
||||||
|
let receiver = Receiver::connect(
|
||||||
|
self.obj().upcast_ref(),
|
||||||
|
settings.ndi_name.as_deref(),
|
||||||
|
settings.url_address.as_deref(),
|
||||||
|
&settings.receiver_ndi_name,
|
||||||
|
settings.connect_timeout,
|
||||||
|
settings.bandwidth,
|
||||||
|
settings.color_format.into(),
|
||||||
|
settings.timeout,
|
||||||
|
settings.max_queue_length as usize,
|
||||||
|
);
|
||||||
|
|
||||||
|
match receiver {
|
||||||
|
None => {
|
||||||
|
gst::element_imp_error!(
|
||||||
|
self,
|
||||||
|
gst::ResourceError::NotFound,
|
||||||
|
["Could not connect to this source"]
|
||||||
|
);
|
||||||
|
|
||||||
|
return Err(gst::StateChangeError);
|
||||||
|
}
|
||||||
|
Some(receiver) => {
|
||||||
|
*self.receiver_controller.lock().unwrap() =
|
||||||
|
Some(receiver.receiver_control_handle());
|
||||||
|
let mut state = self.state.lock().unwrap();
|
||||||
|
state.receiver = Some(receiver);
|
||||||
|
state.timestamp_mode = settings.timestamp_mode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
self.parent_change_state(transition)
|
let res = self.parent_change_state(transition)?;
|
||||||
|
|
||||||
|
match transition {
|
||||||
|
gst::StateChange::PausedToReady => {
|
||||||
|
*self.receiver_controller.lock().unwrap() = None;
|
||||||
|
*self.state.lock().unwrap() = State::default();
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,54 +476,6 @@ impl BaseSrcImpl for NdiSrc {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start(&self) -> Result<(), gst::ErrorMessage> {
|
|
||||||
*self.state.lock().unwrap() = Default::default();
|
|
||||||
let settings = self.settings.lock().unwrap().clone();
|
|
||||||
|
|
||||||
if settings.ndi_name.is_none() && settings.url_address.is_none() {
|
|
||||||
return Err(gst::error_msg!(
|
|
||||||
gst::LibraryError::Settings,
|
|
||||||
["No NDI name or URL/address given"]
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
let receiver = Receiver::connect(
|
|
||||||
self.obj().upcast_ref(),
|
|
||||||
settings.ndi_name.as_deref(),
|
|
||||||
settings.url_address.as_deref(),
|
|
||||||
&settings.receiver_ndi_name,
|
|
||||||
settings.connect_timeout,
|
|
||||||
settings.bandwidth,
|
|
||||||
settings.color_format.into(),
|
|
||||||
settings.timeout,
|
|
||||||
settings.max_queue_length as usize,
|
|
||||||
);
|
|
||||||
|
|
||||||
match receiver {
|
|
||||||
None => Err(gst::error_msg!(
|
|
||||||
gst::ResourceError::NotFound,
|
|
||||||
["Could not connect to this source"]
|
|
||||||
)),
|
|
||||||
Some(receiver) => {
|
|
||||||
*self.receiver_controller.lock().unwrap() =
|
|
||||||
Some(receiver.receiver_control_handle());
|
|
||||||
let mut state = self.state.lock().unwrap();
|
|
||||||
state.receiver = Some(receiver);
|
|
||||||
state.timestamp_mode = settings.timestamp_mode;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn stop(&self) -> Result<(), gst::ErrorMessage> {
|
|
||||||
if let Some(ref controller) = self.receiver_controller.lock().unwrap().take() {
|
|
||||||
controller.shutdown();
|
|
||||||
}
|
|
||||||
*self.state.lock().unwrap() = State::default();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn query(&self, query: &mut gst::QueryRef) -> bool {
|
fn query(&self, query: &mut gst::QueryRef) -> bool {
|
||||||
use gst::QueryViewMut;
|
use gst::QueryViewMut;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue