diff options
author | Wonchul Lee <wonchul.dev@gmail.com> | 2020-11-03 04:10:57 +0300 |
---|---|---|
committer | Wonchul Lee <wonchul.dev@gmail.com> | 2020-11-06 10:42:38 +0300 |
commit | 469ab5337780d4cdf38c935e43f48d7f37f6b303 (patch) | |
tree | cb20b245af64d1ea2e5b6c5ad1af3a42cef4c903 /generic/threadshare | |
parent | 49198f9c11a7795aeed34047ded7777baafdf8fa (diff) |
threadshare/udpsrc: Fix to update settings
It fixes to update settings along with prepared socket and port number
Diffstat (limited to 'generic/threadshare')
-rw-r--r-- | generic/threadshare/src/udpsrc.rs | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/generic/threadshare/src/udpsrc.rs b/generic/threadshare/src/udpsrc.rs index 0d080f7fd..f8dd26ad1 100644 --- a/generic/threadshare/src/udpsrc.rs +++ b/generic/threadshare/src/udpsrc.rs @@ -533,19 +533,19 @@ lazy_static! { impl UdpSrc { 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"); - let context = - Context::acquire(&settings.context, settings.context_wait).map_err(|err| { + let context = Context::acquire(&settings_guard.context, settings_guard.context_wait) + .map_err(|err| { gst_error_msg!( gst::ResourceError::OpenRead, ["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; 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 } else { - let addr: IpAddr = match settings.address { + let addr: IpAddr = match settings_guard.address { None => { return Err(gst_error_msg!( gst::ResourceError::Settings, @@ -589,7 +589,7 @@ impl UdpSrc { Ok(addr) => addr, }, }; - let port = settings.port; + let port = settings_guard.port; // TODO: TTL, multicast loopback, etc let saddr = if addr.is_multicast() { @@ -636,16 +636,18 @@ impl UdpSrc { ) })?; - socket.set_reuse_address(settings.reuse).map_err(|err| { - gst_error_msg!( - gst::ResourceError::OpenRead, - ["Failed to set reuse_address: {}", err] - ) - })?; + socket + .set_reuse_address(settings_guard.reuse) + .map_err(|err| { + gst_error_msg!( + gst::ResourceError::OpenRead, + ["Failed to set reuse_address: {}", err] + ) + })?; #[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::ResourceError::OpenRead, ["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 }; + 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 mut config = buffer_pool.get_config(); config.set_params(None, settings.mtu, 0, 0); |