add: h265 & AV1 support (with a lot of fixes)
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
use std::{env, error::Error, net::SocketAddr, sync::Arc};
|
||||
use std::{
|
||||
env,
|
||||
error::Error,
|
||||
net::{IpAddr, SocketAddr},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use bytes::Bytes;
|
||||
use dashmap::DashMap;
|
||||
@@ -13,6 +18,7 @@ pub struct WebRtcProxyConfig {
|
||||
pub proxy_port: i32,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct WebrtcProxy {
|
||||
clients_ufrag: Arc<DashMap<String, tokio::sync::mpsc::Sender<(Bytes, SocketAddr)>>>,
|
||||
clients_addr: Arc<DashMap<SocketAddr, tokio::sync::mpsc::Sender<(Bytes, SocketAddr)>>>,
|
||||
@@ -34,9 +40,17 @@ impl WebrtcProxy {
|
||||
ip
|
||||
}
|
||||
Err(_) => {
|
||||
let ip = stun_public_ip().await?;
|
||||
info!(%ip, "discovered public IP via STUN for WebRTC candidates");
|
||||
ip
|
||||
if cfg!(debug_assertions) {
|
||||
// For testing
|
||||
info!(
|
||||
"using ip 0.0.0.0 for WebRTC candidates (because we are in a debug build)"
|
||||
);
|
||||
IpAddr::from([127, 0, 0, 1])
|
||||
} else {
|
||||
let ip = stun_public_ip().await?;
|
||||
info!(%ip, "discovered public IP via STUN for WebRTC candidates");
|
||||
ip
|
||||
}
|
||||
}
|
||||
};
|
||||
let public_addr = SocketAddr::new(public_ip, port);
|
||||
@@ -49,13 +63,11 @@ impl WebrtcProxy {
|
||||
public_addr,
|
||||
})
|
||||
}
|
||||
pub fn start(&self) -> Result<(), Box<dyn Error>> {
|
||||
// let self_arc = Arc::new(self);
|
||||
let by_ufrag = self.clients_ufrag.clone();
|
||||
let by_addr = self.clients_addr.clone();
|
||||
let socket = self.socket.clone();
|
||||
|
||||
tokio::spawn(async move {
|
||||
pub async fn run(self) {
|
||||
let by_ufrag = self.clients_ufrag;
|
||||
let by_addr = self.clients_addr;
|
||||
let socket = self.socket;
|
||||
{
|
||||
let mut buf = vec![0u8; 65535];
|
||||
loop {
|
||||
let (b, from) = match socket.recv_from(&mut buf).await {
|
||||
@@ -91,7 +103,7 @@ impl WebrtcProxy {
|
||||
};
|
||||
|
||||
let Some((_, tx)) = by_ufrag.remove(&ufrag) else {
|
||||
warn!("STUN packet ({}), isnt registored", ufrag);
|
||||
// warn!("STUN packet ({}), isnt registored", ufrag);
|
||||
continue;
|
||||
};
|
||||
|
||||
@@ -109,8 +121,7 @@ impl WebrtcProxy {
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub fn add_client(&self, ufrag: String) -> (Arc<UdpSocket>, Receiver<(Bytes, SocketAddr)>) {
|
||||
debug!("Added client {}", ufrag);
|
||||
|
||||
Reference in New Issue
Block a user