diff --git a/libs/cli/src/lib.rs b/libs/cli/src/lib.rs index 60887296..296c0032 100644 --- a/libs/cli/src/lib.rs +++ b/libs/cli/src/lib.rs @@ -132,18 +132,21 @@ pub fn get_codec_type(codec: &RTCRtpCodecCapability) -> RTPCodecType { } pub fn create_child(command: Option) -> Result>> { - let child = if let Some(command) = command { - let mut args = shellwords::split(&command)?; - Some(Mutex::new( - Command::new(args.remove(0)) - .args(args) - .stdin(Stdio::inherit()) - .stdout(Stdio::inherit()) - .stderr(Stdio::inherit()) - .spawn()?, - )) - } else { - None - }; - Ok(child) + Ok(match command { + Some(command) => { + #[cfg(windows)] + let command = command.replace('\\', "/"); + + let mut args = shellwords::split(&command)?; + Some(Mutex::new( + Command::new(args.remove(0)) + .args(args) + .stdin(Stdio::inherit()) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .spawn()?, + )) + } + None => None, + }) } diff --git a/livetwo/src/whep.rs b/livetwo/src/whep.rs index b1c28b76..90af382e 100644 --- a/livetwo/src/whep.rs +++ b/livetwo/src/whep.rs @@ -8,6 +8,7 @@ use sdp::{description::media::RangedPort, SessionDescription}; use std::{ fs::File, io::{Cursor, Write}, + path::Path, sync::Arc, time::Duration, }; @@ -58,12 +59,13 @@ pub async fn from( ); info!("=== Received Output: {} ===", target_url); - let mut host = match input - .host() - .unwrap_or_else(|| panic!("Invalid host for {}", input)) - { - Host::Domain(_) | Host::Ipv4(_) => Ipv4Addr::UNSPECIFIED.to_string(), - Host::Ipv6(_) => Ipv6Addr::UNSPECIFIED.to_string(), + let mut host = match input.host() { + Some(Host::Domain(_)) | Some(Host::Ipv4(_)) => Ipv4Addr::UNSPECIFIED.to_string(), + Some(Host::Ipv6(_)) => Ipv6Addr::UNSPECIFIED.to_string(), + None => { + error!("Invalid host for {}, using default.", input); + Ipv4Addr::UNSPECIFIED.to_string() + } }; if let Some(ref h) = set_host { @@ -134,6 +136,12 @@ pub async fn from( let mut reader = Cursor::new(filtered_sdp.as_bytes()); let mut session = SessionDescription::unmarshal(&mut reader).unwrap(); + host = session + .clone() + .connection_information + .and_then(|conn_info| conn_info.address) + .map(|address| address.to_string()) + .unwrap_or(Ipv4Addr::LOCALHOST.to_string()); for media in &mut session.media_descriptions { if media.media_name.media == "video" { if let Some(port) = media_info.video_rtp_client { @@ -152,9 +160,14 @@ pub async fn from( } } let sdp = session.marshal(); - let file_path = input.path().strip_prefix('/').unwrap(); - info!("SDP written to {}", file_path); - let mut file = File::create(file_path)?; + + let file_path = Path::new(&target_url); + info!("SDP written to {:?}", file_path); + let mut file = File::options() + .write(true) + .create(true) + .truncate(true) + .open(file_path)?; file.write_all(sdp.as_bytes())?; } debug!("media info : {:?}", media_info); diff --git a/livetwo/src/whip.rs b/livetwo/src/whip.rs index 1b216971..e2a84c2e 100644 --- a/livetwo/src/whip.rs +++ b/livetwo/src/whip.rs @@ -1,5 +1,6 @@ use std::fs; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; +use std::path::Path; use std::{sync::Arc, time::Duration, vec}; use anyhow::{anyhow, Result}; @@ -53,12 +54,13 @@ pub async fn into( ); info!("=== Received Input: {} ===", input); - let mut host = match input - .host() - .unwrap_or_else(|| panic!("Invalid host for {}", input)) - { - Host::Domain(_) | Host::Ipv4(_) => Ipv4Addr::UNSPECIFIED.to_string(), - Host::Ipv6(_) => Ipv6Addr::UNSPECIFIED.to_string(), + let mut host = match input.host() { + Some(Host::Domain(_)) | Some(Host::Ipv4(_)) => Ipv4Addr::UNSPECIFIED.to_string(), + Some(Host::Ipv6(_)) => Ipv6Addr::UNSPECIFIED.to_string(), + None => { + eprintln!("Invalid host for {}, using default.", input); + Ipv4Addr::UNSPECIFIED.to_string() + } }; if let Some(ref h) = set_host { @@ -124,7 +126,11 @@ pub async fn into( }; } else { tokio::time::sleep(Duration::from_secs(1)).await; - let sdp = sdp_types::Session::parse(&fs::read(&target_url).unwrap()).unwrap(); + let path = Path::new(&target_url); + let sdp = sdp_types::Session::parse(&fs::read(path).unwrap()).unwrap(); + if let Some(connection_info) = &sdp.connection { + host.clone_from(&connection_info.connection_address); + } let video_track = sdp.medias.iter().find(|md| md.media == "video"); let audio_track = sdp.medias.iter().find(|md| md.media == "audio"); diff --git a/tests/tests.rs b/tests/tests.rs index 880760b1..4c5ba800 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -81,7 +81,6 @@ async fn test_liveion_stream_create() { assert_eq!(1, body.len()); } -#[cfg(not(windows))] #[tokio::test] async fn test_liveion_stream_connect() { let cfg = liveion::config::Config::default(); @@ -208,7 +207,6 @@ a=rtpmap:96 VP8/90000 assert!(result.is_some()); } -#[cfg(not(windows))] #[tokio::test] async fn test_liveion_stream_ffmpeg() { let cfg = liveion::config::Config::default();