From 4e2c16a2afc3674fcd445b8dafef168f5929f82c Mon Sep 17 00:00:00 2001 From: Taruntej Kanakamalla Date: Fri, 15 Nov 2024 10:43:52 +0530 Subject: [PATCH] Revert "threadshare: udp: avoid getifaddrs in android" This reverts commit 75a0baa6fa67f80fb391f0255877d21ea8d9eb7c. Part-of: --- Cargo.lock | 1 - generic/threadshare/Cargo.toml | 5 +-- generic/threadshare/src/net.rs | 54 ---------------------- generic/threadshare/src/udpsink/imp.rs | 62 +++++++++++--------------- generic/threadshare/src/udpsrc/imp.rs | 60 +++++++++++-------------- 5 files changed, 54 insertions(+), 128 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 89bcd516d..382ca8d8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3409,7 +3409,6 @@ version = "0.15.0-alpha.1" dependencies = [ "async-lock", "async-task", - "bitflags 2.9.1", "byte-slice-cast", "cc", "cfg-if", diff --git a/generic/threadshare/Cargo.toml b/generic/threadshare/Cargo.toml index 6b61693d3..5ade894a9 100644 --- a/generic/threadshare/Cargo.toml +++ b/generic/threadshare/Cargo.toml @@ -29,15 +29,12 @@ slab = "0.4.7" socket2 = {features = ["all"], version = "0.6"} thiserror = "2" waker-fn = "1.1" -bitflags = "2.6.0" +getifaddrs = "0.2" libc = "0.2" [target.'cfg(target_os = "windows")'.dependencies] windows-sys = { version = ">=0.52, <=0.60", features = ["Win32_Foundation"] } -[target.'cfg(not(target_os = "android"))'.dependencies] -getifaddrs = "0.2" - [dev-dependencies] gst-check.workspace = true gst-app = { workspace = true, features = [ "v1_20" ] } diff --git a/generic/threadshare/src/net.rs b/generic/threadshare/src/net.rs index 12274cfcb..510281229 100644 --- a/generic/threadshare/src/net.rs +++ b/generic/threadshare/src/net.rs @@ -8,60 +8,6 @@ // // 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, - /// The netmask of the interface, if available. - pub netmask: Option, - /// The flags indicating the interface's properties and state. - pub flags: InterfaceFlags, - /// The index of the interface, if available. - pub index: Option, - } -} - use getifaddrs::Interface; #[cfg(unix)] diff --git a/generic/threadshare/src/udpsink/imp.rs b/generic/threadshare/src/udpsink/imp.rs index 31748647f..94f8bd351 100644 --- a/generic/threadshare/src/udpsink/imp.rs +++ b/generic/threadshare/src/udpsink/imp.rs @@ -36,10 +36,6 @@ use std::net::{IpAddr, SocketAddr, UdpSocket}; use std::sync::{Arc, Mutex}; 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_PORT: i32 = 5004; const DEFAULT_SYNC: bool = true; @@ -160,46 +156,42 @@ impl UdpSinkPadHandler { // So we first get all the interfaces and then apply filter // 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| { - gst::error_msg!( - gst::ResourceError::OpenRead, - ["Failed to find interface {}: {}", multicast_iface, err] - ) - })?; + let ifaces = getifaddrs::getifaddrs().map_err(|err| { + gst::error_msg!( + gst::ResourceError::OpenRead, + ["Failed to find interface {}: {}", multicast_iface, err] + ) + })?; - let iface_filter = ifaces.filter(|i| { - let ip_ver = if i.address.is_ipv4() { "IPv4" } else { "IPv6" }; + let iface_filter = ifaces.filter(|i| { + let ip_ver = if i.address.is_ipv4() { "IPv4" } else { "IPv6" }; - if &i.name == multicast_iface { + if &i.name == multicast_iface { + gst::debug!( + CAT, + imp = imp, + "Found interface: {}, version: {ip_ver}", + i.name, + ); + true + } else { + #[cfg(windows)] + if &i.description == multicast_iface { gst::debug!( CAT, imp = imp, "Found interface: {}, version: {ip_ver}", - i.name, + i.description, ); - true - } else { - #[cfg(windows)] - if &i.description == multicast_iface { - gst::debug!( - CAT, - imp = imp, - "Found interface: {}, version: {ip_ver}", - i.description, - ); - return true; - } - - gst::trace!(CAT, imp = imp, "skipping interface {}", i.name); - false + return true; } - }); - inner.multicast_ifaces = iface_filter.collect(); - } + gst::trace!(CAT, imp = imp, "skipping interface {}", i.name); + false + } + }); + + inner.multicast_ifaces = iface_filter.collect(); } for addr in inner.clients.iter() { diff --git a/generic/threadshare/src/udpsrc/imp.rs b/generic/threadshare/src/udpsrc/imp.rs index fec350877..0cb3e5918 100644 --- a/generic/threadshare/src/udpsrc/imp.rs +++ b/generic/threadshare/src/udpsrc/imp.rs @@ -39,10 +39,6 @@ use crate::socket::{wrap_socket, GioSocketWrapper, Socket, SocketError, SocketRe use futures::channel::mpsc::{channel, Receiver, Sender}; 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_PORT: i32 = 5004; const DEFAULT_REUSE: bool = true; @@ -378,46 +374,42 @@ impl TaskImpl for UdpSrcTask { let multi_ifaces: Vec = 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| { - gst::error_msg!( - gst::ResourceError::OpenRead, - ["Failed to get interfaces: {}", err] - ) - })?; + let iter = getifaddrs::getifaddrs().map_err(|err| { + gst::error_msg!( + gst::ResourceError::OpenRead, + ["Failed to get interfaces: {}", err] + ) + })?; - iter.for_each(|iface| { - let ip_ver = if iface.address.is_ipv4() { - "IPv4" + iter.for_each(|iface| { + let ip_ver = if iface.address.is_ipv4() { + "IPv4" + } else { + "IPv6" + }; + + for m in &multi_ifaces { + if &iface.name == m { + self.multicast_ifaces.push(iface.clone()); + gst::debug!( + CAT, + obj = self.element, + "Interface {m} available, version: {ip_ver}" + ); } else { - "IPv6" - }; - - for m in &multi_ifaces { - if &iface.name == m { + // check if name matches the interface description (Friendly name) on Windows + #[cfg(windows)] + if &iface.description == m { self.multicast_ifaces.push(iface.clone()); gst::debug!( CAT, obj = self.element, "Interface {m} available, version: {ip_ver}" ); - } else { - // check if name matches the interface description (Friendly name) on Windows - #[cfg(windows)] - if &iface.description == m { - self.multicast_ifaces.push(iface.clone()); - gst::debug!( - CAT, - obj = self.element, - "Interface {m} available, version: {ip_ver}" - ); - } } } - }); - } + } + }); } if self.multicast_ifaces.is_empty() {