mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-12-23 10:30:40 +00:00
threadshare/udpsrc: Fix to update settings
It fixes to update settings along with prepared socket and port number
This commit is contained in:
parent
49198f9c11
commit
469ab53377
1 changed files with 32 additions and 15 deletions
|
@ -533,19 +533,19 @@ lazy_static! {
|
||||||
|
|
||||||
impl UdpSrc {
|
impl UdpSrc {
|
||||||
fn prepare(&self, element: &gst::Element) -> Result<(), gst::ErrorMessage> {
|
fn prepare(&self, element: &gst::Element) -> Result<(), gst::ErrorMessage> {
|
||||||
let mut settings = self.settings.lock().unwrap().clone();
|
let mut settings_guard = self.settings.lock().unwrap();
|
||||||
|
|
||||||
gst_debug!(CAT, obj: element, "Preparing");
|
gst_debug!(CAT, obj: element, "Preparing");
|
||||||
|
|
||||||
let context =
|
let context = Context::acquire(&settings_guard.context, settings_guard.context_wait)
|
||||||
Context::acquire(&settings.context, settings.context_wait).map_err(|err| {
|
.map_err(|err| {
|
||||||
gst_error_msg!(
|
gst_error_msg!(
|
||||||
gst::ResourceError::OpenRead,
|
gst::ResourceError::OpenRead,
|
||||||
["Failed to acquire Context: {}", err]
|
["Failed to acquire Context: {}", err]
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let socket = if let Some(ref wrapped_socket) = settings.socket {
|
let socket = if let Some(ref wrapped_socket) = settings_guard.socket {
|
||||||
use std::net::UdpSocket;
|
use std::net::UdpSocket;
|
||||||
|
|
||||||
let socket: UdpSocket;
|
let socket: UdpSocket;
|
||||||
|
@ -568,11 +568,11 @@ impl UdpSrc {
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
settings.used_socket = Some(wrapped_socket.clone());
|
settings_guard.used_socket = Some(wrapped_socket.clone());
|
||||||
|
|
||||||
socket
|
socket
|
||||||
} else {
|
} else {
|
||||||
let addr: IpAddr = match settings.address {
|
let addr: IpAddr = match settings_guard.address {
|
||||||
None => {
|
None => {
|
||||||
return Err(gst_error_msg!(
|
return Err(gst_error_msg!(
|
||||||
gst::ResourceError::Settings,
|
gst::ResourceError::Settings,
|
||||||
|
@ -589,7 +589,7 @@ impl UdpSrc {
|
||||||
Ok(addr) => addr,
|
Ok(addr) => addr,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let port = settings.port;
|
let port = settings_guard.port;
|
||||||
|
|
||||||
// TODO: TTL, multicast loopback, etc
|
// TODO: TTL, multicast loopback, etc
|
||||||
let saddr = if addr.is_multicast() {
|
let saddr = if addr.is_multicast() {
|
||||||
|
@ -636,16 +636,18 @@ impl UdpSrc {
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
socket.set_reuse_address(settings.reuse).map_err(|err| {
|
socket
|
||||||
gst_error_msg!(
|
.set_reuse_address(settings_guard.reuse)
|
||||||
gst::ResourceError::OpenRead,
|
.map_err(|err| {
|
||||||
["Failed to set reuse_address: {}", err]
|
gst_error_msg!(
|
||||||
)
|
gst::ResourceError::OpenRead,
|
||||||
})?;
|
["Failed to set reuse_address: {}", err]
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
socket.set_reuse_port(settings.reuse).map_err(|err| {
|
socket.set_reuse_port(settings_guard.reuse).map_err(|err| {
|
||||||
gst_error_msg!(
|
gst_error_msg!(
|
||||||
gst::ResourceError::OpenRead,
|
gst::ResourceError::OpenRead,
|
||||||
["Failed to set reuse_port: {}", err]
|
["Failed to set reuse_port: {}", err]
|
||||||
|
@ -693,11 +695,26 @@ impl UdpSrc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.used_socket = Some(wrap_socket(&socket)?);
|
settings_guard.used_socket = Some(wrap_socket(&socket)?);
|
||||||
|
|
||||||
socket
|
socket
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let port: i32 = socket.local_addr().unwrap().port().into();
|
||||||
|
let settings = if settings_guard.port != port {
|
||||||
|
settings_guard.port = port;
|
||||||
|
let settings = settings_guard.clone();
|
||||||
|
drop(settings_guard);
|
||||||
|
element.notify("port");
|
||||||
|
|
||||||
|
settings
|
||||||
|
} else {
|
||||||
|
let settings = settings_guard.clone();
|
||||||
|
drop(settings_guard);
|
||||||
|
|
||||||
|
settings
|
||||||
|
};
|
||||||
|
|
||||||
let buffer_pool = gst::BufferPool::new();
|
let buffer_pool = gst::BufferPool::new();
|
||||||
let mut config = buffer_pool.get_config();
|
let mut config = buffer_pool.get_config();
|
||||||
config.set_params(None, settings.mtu, 0, 0);
|
config.set_params(None, settings.mtu, 0, 0);
|
||||||
|
|
Loading…
Reference in a new issue