o_sfu_core/engine/director/
allocation.rs1use std::time::Instant;
11
12use o_sfu_router::MediaKind;
13
14use crate::{
15 Bitrate,
16 engine::source_model::{PolicyPauseReason, SourceSelector, SourceSubscriptionIntent},
17};
18
19#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
25pub(in crate::engine) struct RouteAllocation {
26 pub(super) selector: SourceSelector,
27 pub(super) pause_reason: Option<PolicyPauseReason>,
28}
29
30impl RouteAllocation {
31 pub(in crate::engine) const fn selector(self) -> SourceSelector {
32 self.selector
33 }
34
35 pub(in crate::engine) const fn pause_reason(self) -> Option<PolicyPauseReason> {
36 self.pause_reason
37 }
38
39 pub(in crate::engine) const fn allows_delivery(self) -> bool {
40 self.pause_reason.is_none()
41 }
42
43 pub(in crate::engine) const fn delivers(self, intent: SourceSubscriptionIntent) -> bool {
46 intent.is_active() && self.allows_delivery()
47 }
48
49 #[must_use]
53 pub(in crate::engine) fn admit_setup(
54 mut self,
55 kind: MediaKind,
56 receiver_deaf: bool,
57 video_download_limit_reached: bool,
58 ) -> Self {
59 if !self.allows_delivery() {
60 return self;
61 }
62 match kind {
63 MediaKind::Audio if receiver_deaf => self.pause_for_deaf_receiver(),
64 MediaKind::Video if video_download_limit_reached => {
65 self.pause_reason = Some(PolicyPauseReason::VideoDownloadLimit);
66 }
67 MediaKind::Audio | MediaKind::Video => {}
68 }
69 self
70 }
71
72 pub(in crate::engine) const fn pause_for_deaf_receiver(&mut self) {
74 self.pause_reason = Some(PolicyPauseReason::ReceiverDeafened);
75 }
76}
77
78#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
80pub(in crate::engine) struct ReceiverAllocation {
81 pub(super) budget: ReceiverVideoBudgetDiagnostics,
82 pub(super) soft_pause_deadline: Option<Instant>,
84}
85
86impl ReceiverAllocation {
87 pub(in crate::engine) const fn budget(self) -> ReceiverVideoBudgetDiagnostics {
88 self.budget
89 }
90
91 pub(in crate::engine) const fn soft_pause_deadline(self) -> Option<Instant> {
92 self.soft_pause_deadline
93 }
94}
95
96#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
98pub(in crate::engine) struct ReceiverVideoBudgetDiagnostics {
99 pub(super) latest_receiver_bandwidth: Option<Bitrate>,
100 pub(super) selected_video_budget: Option<Bitrate>,
101 pub(super) active_video_route_count: usize,
102 pub(super) selected_video_bitrate: Bitrate,
103}
104
105impl ReceiverVideoBudgetDiagnostics {
106 pub(in crate::engine) const fn latest_receiver_bandwidth(self) -> Option<Bitrate> {
107 self.latest_receiver_bandwidth
108 }
109
110 pub(in crate::engine) const fn selected_video_budget(self) -> Option<Bitrate> {
111 self.selected_video_budget
112 }
113
114 pub(in crate::engine) const fn active_video_route_count(self) -> usize {
115 self.active_video_route_count
116 }
117
118 pub(in crate::engine) const fn selected_video_bitrate(self) -> Bitrate {
119 self.selected_video_bitrate
120 }
121}
122
123#[derive(Debug, Clone, Copy, PartialEq, Eq)]
127pub(in crate::engine) struct PendingUpgrade {
128 pub(super) selector: SourceSelector,
129 pub(super) deadline: Instant,
130}
131
132impl PendingUpgrade {
133 pub(in crate::engine) const fn selector(self) -> SourceSelector {
134 self.selector
135 }
136
137 pub(in crate::engine) const fn deadline(self) -> Instant {
138 self.deadline
139 }
140}