mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-02-17 13:25:15 +00:00
threadshare: udp: avoid getifaddrs in android
until the issue https://github.com/mmastrac/getifaddrs/issues/5 is fixed Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1917>
This commit is contained in:
parent
1963dad67e
commit
75a0baa6fa
5 changed files with 128 additions and 54 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -3071,6 +3071,7 @@ name = "gst-plugin-threadshare"
|
||||||
version = "0.14.0-alpha.1"
|
version = "0.14.0-alpha.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-task",
|
"async-task",
|
||||||
|
"bitflags 2.6.0",
|
||||||
"cc",
|
"cc",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"clap",
|
"clap",
|
||||||
|
|
|
@ -26,9 +26,12 @@ rustix = { version = "0.38.2", default-features = false, features = ["std", "fs"
|
||||||
slab = "0.4.7"
|
slab = "0.4.7"
|
||||||
socket2 = {features = ["all"], version = "0.5"}
|
socket2 = {features = ["all"], version = "0.5"}
|
||||||
waker-fn = "1.1"
|
waker-fn = "1.1"
|
||||||
getifaddrs = "0.1"
|
bitflags = "2.6.0"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
windows-sys = "0.59.0"
|
windows-sys = "0.59.0"
|
||||||
|
[target.'cfg(not(target_os = "android"))'.dependencies]
|
||||||
|
getifaddrs = "0.1"
|
||||||
|
|
||||||
|
|
||||||
# Used by examples
|
# Used by examples
|
||||||
clap = { version = "4", features = ["derive"], optional = true }
|
clap = { version = "4", features = ["derive"], optional = true }
|
||||||
|
|
|
@ -8,6 +8,60 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: MPL-2.0
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
|
//FIXME: Remove this when https://github.com/mmastrac/getifaddrs/issues/5 is fixed in the `getifaddrs` crate
|
||||||
|
#[cfg(target_os = "android")]
|
||||||
|
pub mod getifaddrs {
|
||||||
|
use bitflags::bitflags;
|
||||||
|
|
||||||
|
bitflags! {
|
||||||
|
/// Flags representing the status and capabilities of a network interface.
|
||||||
|
///
|
||||||
|
/// These flags provide information about the current state and features of a network interface.
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
pub struct InterfaceFlags: u32 {
|
||||||
|
/// The interface is up and running.
|
||||||
|
const UP = 0x1;
|
||||||
|
/// The interface is in a running state.
|
||||||
|
const RUNNING = 0x2;
|
||||||
|
/// The interface supports broadcast.
|
||||||
|
const BROADCAST = 0x4;
|
||||||
|
/// The interface is a loopback interface.
|
||||||
|
const LOOPBACK = 0x8;
|
||||||
|
/// The interface is a point-to-point link.
|
||||||
|
const POINTTOPOINT = 0x10;
|
||||||
|
/// The interface supports multicast.
|
||||||
|
const MULTICAST = 0x20;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Represents a network interface.
|
||||||
|
///
|
||||||
|
/// This struct contains information about a network interface, including its name,
|
||||||
|
/// IP address, netmask, flags, and index.
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
pub struct Interface {
|
||||||
|
/// The name of the interface.
|
||||||
|
pub name: String,
|
||||||
|
/// The description of the interface (Windows-specific).
|
||||||
|
#[cfg(windows)]
|
||||||
|
pub description: String,
|
||||||
|
/// The IP address associated with the interface.
|
||||||
|
pub address: std::net::IpAddr,
|
||||||
|
// TODO: This may be implementable for Windows.
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
/// The associated address of the interface. For broadcast interfaces, this
|
||||||
|
/// is the broadcast address. For point-to-point interfaces, this is the
|
||||||
|
/// peer address.
|
||||||
|
pub associated_address: Option<std::net::IpAddr>,
|
||||||
|
/// The netmask of the interface, if available.
|
||||||
|
pub netmask: Option<std::net::IpAddr>,
|
||||||
|
/// The flags indicating the interface's properties and state.
|
||||||
|
pub flags: InterfaceFlags,
|
||||||
|
/// The index of the interface, if available.
|
||||||
|
pub index: Option<u32>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
use getifaddrs::Interface;
|
use getifaddrs::Interface;
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
|
|
@ -39,6 +39,10 @@ use std::net::{IpAddr, SocketAddr, UdpSocket};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
//FIXME: Remove this when https://github.com/mmastrac/getifaddrs/issues/5 is fixed in the `getifaddrs` crate
|
||||||
|
#[cfg(target_os = "android")]
|
||||||
|
use net::getifaddrs;
|
||||||
|
|
||||||
const DEFAULT_HOST: Option<&str> = Some("127.0.0.1");
|
const DEFAULT_HOST: Option<&str> = Some("127.0.0.1");
|
||||||
const DEFAULT_PORT: i32 = 5004;
|
const DEFAULT_PORT: i32 = 5004;
|
||||||
const DEFAULT_SYNC: bool = true;
|
const DEFAULT_SYNC: bool = true;
|
||||||
|
@ -159,6 +163,9 @@ impl UdpSinkPadHandler {
|
||||||
// So we first get all the interfaces and then apply filter
|
// So we first get all the interfaces and then apply filter
|
||||||
// for name and description (Friendly Name) of each interface.
|
// for name and description (Friendly Name) of each interface.
|
||||||
|
|
||||||
|
//FIXME: Remove this when https://github.com/mmastrac/getifaddrs/issues/5 is fixed in the `getifaddrs` crate
|
||||||
|
#[cfg(not(target_os = "android"))]
|
||||||
|
{
|
||||||
let ifaces = getifaddrs::getifaddrs().map_err(|err| {
|
let ifaces = getifaddrs::getifaddrs().map_err(|err| {
|
||||||
gst::error_msg!(
|
gst::error_msg!(
|
||||||
gst::ResourceError::OpenRead,
|
gst::ResourceError::OpenRead,
|
||||||
|
@ -196,6 +203,7 @@ impl UdpSinkPadHandler {
|
||||||
|
|
||||||
inner.multicast_ifaces = iface_filter.collect();
|
inner.multicast_ifaces = iface_filter.collect();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for addr in inner.clients.iter() {
|
for addr in inner.clients.iter() {
|
||||||
inner.configure_client(addr)?;
|
inner.configure_client(addr)?;
|
||||||
|
|
|
@ -40,6 +40,10 @@ use crate::socket::{wrap_socket, GioSocketWrapper, Socket, SocketError, SocketRe
|
||||||
use futures::channel::mpsc::{channel, Receiver, Sender};
|
use futures::channel::mpsc::{channel, Receiver, Sender};
|
||||||
use futures::pin_mut;
|
use futures::pin_mut;
|
||||||
|
|
||||||
|
//FIXME: Remove this when https://github.com/mmastrac/getifaddrs/issues/5 is fixed in the `getifaddrs` crate
|
||||||
|
#[cfg(target_os = "android")]
|
||||||
|
use net::getifaddrs;
|
||||||
|
|
||||||
const DEFAULT_ADDRESS: Option<&str> = Some("0.0.0.0");
|
const DEFAULT_ADDRESS: Option<&str> = Some("0.0.0.0");
|
||||||
const DEFAULT_PORT: i32 = 5004;
|
const DEFAULT_PORT: i32 = 5004;
|
||||||
const DEFAULT_REUSE: bool = true;
|
const DEFAULT_REUSE: bool = true;
|
||||||
|
@ -378,6 +382,9 @@ impl TaskImpl for UdpSrcTask {
|
||||||
let multi_ifaces: Vec<String> =
|
let multi_ifaces: Vec<String> =
|
||||||
multicast_iface.split(',').map(|s| s.to_string()).collect();
|
multicast_iface.split(',').map(|s| s.to_string()).collect();
|
||||||
|
|
||||||
|
//FIXME: Remove this when https://github.com/mmastrac/getifaddrs/issues/5 is fixed in the `getifaddrs` crate
|
||||||
|
#[cfg(not(target_os = "android"))]
|
||||||
|
{
|
||||||
let iter = getifaddrs::getifaddrs().map_err(|err| {
|
let iter = getifaddrs::getifaddrs().map_err(|err| {
|
||||||
gst::error_msg!(
|
gst::error_msg!(
|
||||||
gst::ResourceError::OpenRead,
|
gst::ResourceError::OpenRead,
|
||||||
|
@ -415,6 +422,7 @@ impl TaskImpl for UdpSrcTask {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if self.multicast_ifaces.is_empty() {
|
if self.multicast_ifaces.is_empty() {
|
||||||
gst::warning!(
|
gst::warning!(
|
||||||
|
|
Loading…
Reference in a new issue