use std::ops::Deref;
use std::sync::Weak;
use std::time::Instant;
use crate::bandwidth::BandwidthEstimate;
use crate::client::TrackIn;
use crate::ids::{SfuMid, SfuRid};
use crate::keyframe::SfuKeyframeRequest;
use crate::media::SfuMediaPayload;
use crate::rtcp_stats::PeerRtcpStats;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ClientId(pub u64);
impl Deref for ClientId {
type Target = u64;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[allow(clippy::large_enum_variant)]
#[derive(Debug)]
pub enum Propagated {
Noop,
Timeout(Instant),
TrackOpen(ClientId, Weak<TrackIn>),
MediaData(ClientId, SfuMediaPayload),
KeyframeRequest(ClientId, SfuKeyframeRequest, ClientId, SfuMid),
UpstreamKeyframeRequest {
source_relay_id: ClientId,
req: SfuKeyframeRequest,
source_mid: SfuMid,
},
#[cfg(feature = "active-speaker")]
#[cfg_attr(docsrs, doc(cfg(feature = "active-speaker")))]
ActiveSpeakerChanged {
peer_id: u64,
confidence: f64,
},
BandwidthEstimate {
peer_id: ClientId,
estimate: BandwidthEstimate,
},
RtcpStats {
peer_id: ClientId,
stats: PeerRtcpStats,
},
#[cfg(feature = "pacer")]
#[cfg_attr(docsrs, doc(cfg(feature = "pacer")))]
AudioOnlyMode {
peer_id: ClientId,
audio_only: bool,
},
PublisherLayerHint {
publisher_id: ClientId,
max_rid: SfuRid,
},
PublisherLayerHintForUpstream {
publisher_relay_id: ClientId,
max_rid: SfuRid,
},
AudioCodecHint {
peer_id: ClientId,
opus_red: bool,
opus_dred: bool,
},
}
impl Propagated {
pub fn client_id(&self) -> Option<ClientId> {
match self {
Propagated::TrackOpen(c, _)
| Propagated::MediaData(c, _)
| Propagated::KeyframeRequest(c, _, _, _) => Some(*c),
Propagated::Noop | Propagated::Timeout(_) => None,
#[cfg(feature = "active-speaker")]
Propagated::ActiveSpeakerChanged { .. } => None,
Propagated::BandwidthEstimate { peer_id, .. }
| Propagated::RtcpStats { peer_id, .. } => Some(*peer_id),
#[cfg(feature = "pacer")]
Propagated::AudioOnlyMode { peer_id, .. } => Some(*peer_id),
Propagated::PublisherLayerHint { publisher_id, .. } => Some(*publisher_id),
Propagated::PublisherLayerHintForUpstream {
publisher_relay_id, ..
} => Some(*publisher_relay_id),
Propagated::AudioCodecHint { peer_id, .. } => Some(*peer_id),
Propagated::UpstreamKeyframeRequest {
source_relay_id, ..
} => Some(*source_relay_id),
}
}
}