Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrançois Laignel <fengalin@free.fr>2021-12-14 21:40:27 +0300
committerSebastian Dröge <slomo@coaxion.net>2021-12-25 14:25:56 +0300
commit6163589ac7f9809903c9d52a3b0591de77e722c8 (patch)
treeba9aa19bbbb99b650745cd12244488d9ff17bff1 /generic/threadshare/src/udpsrc
parentdb9c38aa9386c825ac917e77b321b99b12d454e7 (diff)
ts/executor: replace tokio with smol-like implementation
The threadshare executor was based on a modified version of tokio which implemented the throttling strategy in the BasicScheduler. Upstream tokio codebase has significantly diverged from what it was when the throttling strategy was implemented making it hard to follow. This means that we can hardly get updates from the upstream project and when we cherry pick fixes, we can't reflect the state of the project on our fork's version. As a consequence, tools such as cargo-deny can't check for RUSTSEC fixes in our fork. The smol ecosystem makes it quite easy to implement and maintain a custom async executor. This MR imports the smol parts that need modifications to comply with the threadshare model and implements a throttling executor in place of the tokio fork. Networking tokio specific types are replaced with Async wrappers in the spirit of [smol-rs/async-io]. Note however that the Async wrappers needed modifications in order to use the per thread Reactor model. This means that higher level upstream networking crates such as [async-net] can not be used with our Async implementation. Based on the example benchmark with ts-udpsrc, performances seem on par with what we achieved using the tokio fork. Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/issues/118 Related to https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/604
Diffstat (limited to 'generic/threadshare/src/udpsrc')
-rw-r--r--generic/threadshare/src/udpsrc/imp.rs27
1 files changed, 13 insertions, 14 deletions
diff --git a/generic/threadshare/src/udpsrc/imp.rs b/generic/threadshare/src/udpsrc/imp.rs
index 5a423fa43..6a3158b84 100644
--- a/generic/threadshare/src/udpsrc/imp.rs
+++ b/generic/threadshare/src/udpsrc/imp.rs
@@ -29,14 +29,14 @@ use once_cell::sync::Lazy;
use std::i32;
use std::io;
-use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
+use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, UdpSocket};
use std::sync::Arc;
use std::sync::Mutex as StdMutex;
use std::time::Duration;
use std::u16;
use crate::runtime::prelude::*;
-use crate::runtime::{Context, PadSrc, PadSrcRef, PadSrcWeak, Task};
+use crate::runtime::{Async, Context, PadSrc, PadSrcRef, PadSrcWeak, Task};
use crate::socket::{wrap_socket, GioSocketWrapper, Socket, SocketError, SocketRead};
@@ -83,10 +83,10 @@ impl Default for Settings {
}
#[derive(Debug)]
-struct UdpReader(tokio::net::UdpSocket);
+struct UdpReader(Async<UdpSocket>);
impl UdpReader {
- fn new(socket: tokio::net::UdpSocket) -> Self {
+ fn new(socket: Async<UdpSocket>) -> Self {
UdpReader(socket)
}
}
@@ -438,8 +438,6 @@ impl UdpSrc {
})?;
let socket = if let Some(ref wrapped_socket) = settings_guard.socket {
- use std::net::UdpSocket;
-
let socket: UdpSocket;
#[cfg(unix)]
@@ -452,10 +450,10 @@ impl UdpSrc {
}
let socket = context.enter(|| {
- tokio::net::UdpSocket::from_std(socket).map_err(|err| {
+ Async::<UdpSocket>::try_from(socket).map_err(|err| {
gst::error_msg!(
gst::ResourceError::OpenRead,
- ["Failed to setup socket for tokio: {}", err]
+ ["Failed to setup Async socket: {}", err]
)
})
})?;
@@ -555,10 +553,10 @@ impl UdpSrc {
})?;
let socket = context.enter(|| {
- tokio::net::UdpSocket::from_std(socket.into()).map_err(|err| {
+ Async::<UdpSocket>::try_from(socket).map_err(|err| {
gst::error_msg!(
gst::ResourceError::OpenRead,
- ["Failed to setup socket for tokio: {}", err]
+ ["Failed to setup Async socket: {}", err]
)
})
})?;
@@ -568,7 +566,8 @@ impl UdpSrc {
match addr {
IpAddr::V4(addr) => {
socket
- .join_multicast_v4(addr, Ipv4Addr::new(0, 0, 0, 0))
+ .as_ref()
+ .join_multicast_v4(&addr, &Ipv4Addr::new(0, 0, 0, 0))
.map_err(|err| {
gst::error_msg!(
gst::ResourceError::OpenRead,
@@ -577,7 +576,7 @@ impl UdpSrc {
})?;
}
IpAddr::V6(addr) => {
- socket.join_multicast_v6(&addr, 0).map_err(|err| {
+ socket.as_ref().join_multicast_v6(&addr, 0).map_err(|err| {
gst::error_msg!(
gst::ResourceError::OpenRead,
["Failed to join multicast group: {}", err]
@@ -592,7 +591,7 @@ impl UdpSrc {
socket
};
- let port: i32 = socket.local_addr().unwrap().port().into();
+ let port: i32 = socket.as_ref().local_addr().unwrap().port().into();
let settings = if settings_guard.port != port {
settings_guard.port = port;
let settings = settings_guard.clone();
@@ -834,7 +833,7 @@ impl ObjectImpl for UdpSrc {
settings.context = value
.get::<Option<String>>()
.expect("type checked upstream")
- .unwrap_or_else(|| "".into());
+ .unwrap_or_else(|| DEFAULT_CONTEXT.into());
}
"context-wait" => {
settings.context_wait = Duration::from_millis(