Skip to content

Commit

Permalink
fix:whipinto and whepfrom mode sdp file path failed at windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Marsyew committed Oct 28, 2024
1 parent 5fab5bb commit fec3995
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
8 changes: 8 additions & 0 deletions libs/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,14 @@ pub fn get_codec_type(codec: &RTCRtpCodecCapability) -> RTPCodecType {

pub fn create_child(command: Option<String>) -> Result<Option<Mutex<Child>>> {
let child = if let Some(command) = command {
let command = if cfg!(windows) {
command.replace('\\', "/")
} else {
command
};

let mut args = shellwords::split(&command)?;

Some(Mutex::new(
Command::new(args.remove(0))
.args(args)
Expand All @@ -145,5 +152,6 @@ pub fn create_child(command: Option<String>) -> Result<Option<Mutex<Child>>> {
} else {
None
};

Ok(child)
}
31 changes: 22 additions & 9 deletions livetwo/src/whep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use sdp::{description::media::RangedPort, SessionDescription};
use std::{
fs::File,
io::{Cursor, Write},
path::Path,
sync::Arc,
time::Duration,
};
Expand Down Expand Up @@ -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(),

Check warning on line 64 in livetwo/src/whep.rs

View check run for this annotation

Codecov / codecov/patch

livetwo/src/whep.rs#L64

Added line #L64 was not covered by tests
None => {
eprintln!("Invalid host for {}, using default.", input);
Ipv4Addr::UNSPECIFIED.to_string()

Check warning on line 67 in livetwo/src/whep.rs

View check run for this annotation

Codecov / codecov/patch

livetwo/src/whep.rs#L66-L67

Added lines #L66 - L67 were not covered by tests
}
};

if let Some(ref h) = set_host {
Expand Down Expand Up @@ -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())

Check warning on line 143 in livetwo/src/whep.rs

View check run for this annotation

Codecov / codecov/patch

livetwo/src/whep.rs#L142-L143

Added lines #L142 - L143 were not covered by tests
.unwrap_or("127.0.0.1".to_string());
for media in &mut session.media_descriptions {
if media.media_name.media == "video" {
if let Some(port) = media_info.video_rtp_client {
Expand All @@ -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)?;

Check warning on line 170 in livetwo/src/whep.rs

View check run for this annotation

Codecov / codecov/patch

livetwo/src/whep.rs#L170

Added line #L170 was not covered by tests
file.write_all(sdp.as_bytes())?;
}
debug!("media info : {:?}", media_info);
Expand Down
20 changes: 13 additions & 7 deletions livetwo/src/whip.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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(),

Check warning on line 59 in livetwo/src/whip.rs

View check run for this annotation

Codecov / codecov/patch

livetwo/src/whip.rs#L59

Added line #L59 was not covered by tests
None => {
eprintln!("Invalid host for {}, using default.", input);
Ipv4Addr::UNSPECIFIED.to_string()

Check warning on line 62 in livetwo/src/whip.rs

View check run for this annotation

Codecov / codecov/patch

livetwo/src/whip.rs#L61-L62

Added lines #L61 - L62 were not covered by tests
}
};

if let Some(ref h) = set_host {
Expand Down Expand Up @@ -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");

Expand Down

0 comments on commit fec3995

Please sign in to comment.