srt-runtime 0.13.1

SRT (Secure Reliable Transport, draft-sharabayko-srt-01) packet codecs, sans-IO HSv5 handshakes, a one-connection link engine, ARQ, TSBPD, LiveCC/FileCC congestion control, optional payload crypto and an optional tokio UDP adapter; no_std core.
Documentation
use core::time::Duration;

use broadcast_net::timeouts::Timeouts;

use crate::link::LinkCadence;

pub(crate) const DEFAULT_CADENCE: LinkCadence = LinkCadence {
    handshake_retransmit: Duration::from_millis(250),
    keepalive: Duration::from_secs(1),
    km_resend: Duration::from_millis(500),
    kmreq_min_interval: Duration::from_millis(100),
};

pub(crate) const SRT_TIMEOUTS: Timeouts = Timeouts::new(
    Duration::from_secs(10),
    Duration::from_secs(5),
    Duration::from_secs(5),
    Duration::from_secs(5),
);

pub(crate) const TEST_DRIFT_SAMPLE_COUNT: u32 = 1000;
pub(crate) const TEST_DRIFT_WINDOW: core::num::NonZeroU32 =
    core::num::NonZeroU32::MIN.saturating_add(TEST_DRIFT_SAMPLE_COUNT - 1);

#[cfg(feature = "tokio")]
pub(crate) const DEFAULT_MAX_PENDING: usize = 1024;
#[cfg(feature = "tokio")]
pub(crate) const DEFAULT_PENDING_TICK_INTERVAL: Duration = Duration::from_millis(100);
#[cfg(feature = "tokio")]
pub(crate) const DEFAULT_COOKIE_KEY_ROTATION: Duration = Duration::from_secs(60);
#[cfg(feature = "tokio")]
pub(crate) const DEFAULT_RECENT_ACCEPT_TTL: Duration = Duration::from_secs(10);

#[cfg(feature = "tokio")]
pub(crate) const DEFAULT_LISTENER_LIMITS: crate::io::ListenerLimits = crate::io::ListenerLimits {
    max_pending: DEFAULT_MAX_PENDING,
    pending_tick: DEFAULT_PENDING_TICK_INTERVAL,
    cookie_key_rotation: DEFAULT_COOKIE_KEY_ROTATION,
    recent_accept_ttl: DEFAULT_RECENT_ACCEPT_TTL,
};

#[cfg(feature = "tokio")]
pub(crate) fn io_config() -> crate::io::IoConfig {
    crate::io::IoConfig {
        max_datagram: 1500,
        timeouts: SRT_TIMEOUTS,
        km_refresh_thresholds: crate::km_refresh::KmRefreshThresholds::RECOMMENDED,
        cadence: DEFAULT_CADENCE,
        listener: DEFAULT_LISTENER_LIMITS,
        arq: ARQ_BOUNDS,
        drift_sample_count: TEST_DRIFT_SAMPLE_COUNT,
        channels: CHANNELS,
        max_bw: crate::livecc::MaxBwConfig::Set(125_000_000),
        close: crate::io::CloseTimings::for_profile(broadcast_core::Profile::Server),
    }
}

#[cfg(feature = "tokio")]
pub(crate) const CHANNELS: crate::io::ChannelCapacities = crate::io::ChannelCapacities {
    rx: RX_CHANNEL_CAPACITY,
    unrouted: UNROUTED_CHANNEL_CAPACITY,
    send: SEND_CHANNEL_CAPACITY,
    deliver: DELIVER_CHANNEL_CAPACITY,
    accept: ACCEPT_CAPACITY,
};

pub(crate) const RX_CHANNEL_CAPACITY: std::num::NonZeroUsize =
    match std::num::NonZeroUsize::new(4096) {
        Some(n) => n,
        None => std::num::NonZeroUsize::MIN,
    };
pub(crate) const UNROUTED_CHANNEL_CAPACITY: std::num::NonZeroUsize =
    match std::num::NonZeroUsize::new(1024) {
        Some(n) => n,
        None => std::num::NonZeroUsize::MIN,
    };
pub(crate) const SEND_CHANNEL_CAPACITY: std::num::NonZeroUsize =
    match std::num::NonZeroUsize::new(1024) {
        Some(n) => n,
        None => std::num::NonZeroUsize::MIN,
    };
pub(crate) const DELIVER_CHANNEL_CAPACITY: std::num::NonZeroUsize =
    match std::num::NonZeroUsize::new(4096) {
        Some(n) => n,
        None => std::num::NonZeroUsize::MIN,
    };
pub(crate) const ACCEPT_CAPACITY: std::num::NonZeroUsize = match std::num::NonZeroUsize::new(64) {
    Some(n) => n,
    None => std::num::NonZeroUsize::MIN,
};
pub(crate) const ARQ_BOUNDS: crate::arq::ArqBounds = crate::arq::ArqBounds {
    receiver: crate::arq::ReceiverBounds {
        max_tracked_window: 1 << 18,
        max_pending_skips: 1024,
        max_outstanding_acks: 1024,
    },
    sender: crate::arq::SenderBounds {
        max_nak_seqs_per_packet: 1 << 16,
        min_retransmit_interval: Duration::from_millis(20),
        pacing_burst_packets: 16,
    },
};

pub(crate) fn at(micros: u64) -> broadcast_core::stage::Instant {
    broadcast_core::stage::Instant::from_micros(micros)
}