Skip to main content

rtflow_media/
connection.rs

1//! SDP connection-info value type (`c=` line).
2//!
3//! The multicast helpers sit behind the `multicast` feature; the `rtflow-multicast` crate.
4
5use std::net::IpAddr;
6
7#[derive(Clone, Debug, Eq, PartialEq)]
8pub struct SdpConnection {
9    pub addr_type: String,
10    pub address: IpAddr,
11    pub ttl: Option<u8>,
12    /// RTP port advertised by the SDP `m=` line (multicast).
13    pub port: Option<u16>,
14}
15
16impl SdpConnection {
17    pub fn is_multicast(&self) -> bool {
18        rtflow_multicast::MulticastConfig::is_multicast(&self.address)
19    }
20    pub fn to_multicast_config(&self, port: u16) -> Option<rtflow_multicast::MulticastConfig> {
21        if !self.is_multicast() {
22            return None;
23        }
24        let mut cfg = rtflow_multicast::MulticastConfig::new(self.address, port);
25        if let Some(ttl) = self.ttl {
26            cfg = cfg.with_ttl(ttl);
27        }
28        Some(cfg)
29    }
30}