use async_trait::async_trait;
use std::net::SocketAddr;
use tokio::sync::broadcast;
use crate::packet::rtcp::RtcpPacket;
use crate::packet::RtpPacket;
use crate::traits::RtpEvent;
use crate::Result;
#[async_trait]
pub trait RtpTransport: Send + Sync {
fn local_rtp_addr(&self) -> Result<SocketAddr>;
fn local_rtcp_addr(&self) -> Result<Option<SocketAddr>>;
async fn send_rtp(&self, packet: &RtpPacket, dest: SocketAddr) -> Result<()>;
async fn send_rtp_bytes(&self, bytes: &[u8], dest: SocketAddr) -> Result<()>;
async fn send_rtcp(&self, packet: &RtcpPacket, dest: SocketAddr) -> Result<()>;
async fn send_rtcp_bytes(&self, bytes: &[u8], dest: SocketAddr) -> Result<()>;
async fn receive_packet(&self, buffer: &mut [u8]) -> Result<(usize, SocketAddr)>;
fn subscribe(&self) -> broadcast::Receiver<RtpEvent>;
fn as_any(&self) -> &dyn std::any::Any;
async fn close(&self) -> Result<()>;
}
#[derive(Debug, Clone)]
pub struct RtpTransportConfig {
pub local_rtp_addr: SocketAddr,
pub local_rtcp_addr: Option<SocketAddr>,
pub symmetric_rtp: bool,
pub rtcp_mux: bool,
pub session_id: Option<String>,
pub use_port_allocator: bool,
}
impl Default for RtpTransportConfig {
fn default() -> Self {
Self {
local_rtp_addr: "0.0.0.0:0".parse().unwrap(),
local_rtcp_addr: None,
symmetric_rtp: true,
rtcp_mux: true, session_id: None,
use_port_allocator: false,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PortPairingStrategy {
Adjacent,
Muxed,
}
mod allocator;
pub mod recv_pool;
pub mod security_transport;
mod tcp;
mod udp;
mod validation;
pub use allocator::{
AllocationStrategy, GlobalPortAllocator, PairingStrategy, PortAllocator, PortAllocatorConfig,
DEFAULT_RTP_PORT_RANGE_END, DEFAULT_RTP_PORT_RANGE_START, MIN_PORT,
};
pub use security_transport::SecurityRtpTransport;
pub use tcp::TcpRtpTransport;
pub use udp::{set_diagnostics as set_udp_diagnostics, UdpRtpTransport};
pub use validation::{PlatformSocketStrategy, PlatformType, RtpSocketValidator};