threadshare: udpsrc: add buffer-size property

Use buffer-size to set the receive buffer size
on the socket
This commit is contained in:
Taruntej Kanakamalla 2024-01-03 17:35:21 +05:30
parent 7733a45e2b
commit 9751fee093
2 changed files with 38 additions and 0 deletions

View file

@ -9981,6 +9981,20 @@
"type": "gchararray",
"writable": true
},
"buffer-size": {
"blurb": "Size of the kernel receive buffer in bytes, 0=default",
"conditionally-available": false,
"construct": false,
"construct-only": false,
"controllable": false,
"default": "0",
"max": "-1",
"min": "0",
"mutable": "null",
"readable": true,
"type": "guint",
"writable": true
},
"caps": {
"blurb": "Caps to use",
"conditionally-available": false,

View file

@ -50,6 +50,7 @@ const DEFAULT_CONTEXT: &str = "";
const DEFAULT_CONTEXT_WAIT: Duration = Duration::ZERO;
const DEFAULT_RETRIEVE_SENDER_ADDRESS: bool = true;
const DEFAULT_MULTICAST_IFACE: Option<&str> = None;
const DEFAULT_BUFFER_SIZE: u32 = 0;
#[derive(Debug, Clone)]
struct Settings {
@ -64,6 +65,7 @@ struct Settings {
context_wait: Duration,
retrieve_sender_address: bool,
multicast_iface: Option<String>,
buffer_size: u32,
}
impl Default for Settings {
@ -80,6 +82,7 @@ impl Default for Settings {
context_wait: DEFAULT_CONTEXT_WAIT,
retrieve_sender_address: DEFAULT_RETRIEVE_SENDER_ADDRESS,
multicast_iface: DEFAULT_MULTICAST_IFACE.map(Into::into),
buffer_size: DEFAULT_BUFFER_SIZE,
}
}
}
@ -305,6 +308,17 @@ impl TaskImpl for UdpSrcTask {
)
})?;
gst::debug!(CAT, obj: self.element, "socket recv buffer size is {:?}", socket.recv_buffer_size());
if settings.buffer_size != 0 {
gst::debug!(CAT, obj: self.element, "changing the socket recv buffer size to {}", settings.buffer_size);
socket.set_recv_buffer_size(settings.buffer_size as usize).map_err(|err| {
gst::error_msg!(
gst::ResourceError::OpenRead,
["Failed to set buffer_size: {}", err]
)
})?;
}
#[cfg(unix)]
{
socket.set_reuse_port(settings.reuse).map_err(|err| {
@ -744,6 +758,12 @@ impl ObjectImpl for UdpSrc {
.blurb("The network interface on which to join the multicast group. This allows multiple interfaces separated by comma. ( e.g. eth0,eth1,wlan0)")
.default_value(DEFAULT_MULTICAST_IFACE)
.build(),
glib::ParamSpecUInt::builder("buffer-size")
.nick("Buffer Size")
.blurb("Size of the kernel receive buffer in bytes, 0=default")
.maximum(u32::MAX)
.default_value(DEFAULT_BUFFER_SIZE)
.build(),
];
#[cfg(not(windows))]
@ -813,6 +833,9 @@ impl ObjectImpl for UdpSrc {
"multicast-iface" => {
settings.multicast_iface = value.get().expect("type checked upstream");
}
"buffer-size" => {
settings.buffer_size = value.get().expect("type checked upstream");
}
_ => unimplemented!(),
}
}
@ -839,6 +862,7 @@ impl ObjectImpl for UdpSrc {
"context-wait" => (settings.context_wait.as_millis() as u32).to_value(),
"retrieve-sender-address" => settings.retrieve_sender_address.to_value(),
"multicast-iface" => settings.multicast_iface.to_value(),
"buffer-size" => settings.buffer_size.to_value(),
_ => unimplemented!(),
}
}