o_sfu_core/engine/director/planner/
mod.rs1mod audio;
13mod speakers;
14#[cfg(test)]
15#[path = "TESTS/mod.rs"]
16mod tests;
17mod video;
18
19use std::time::Instant;
20
21use o_sfu_model::{UserId, VideoLayoutIntent};
22
23pub(super) use self::video::{VideoAdmissionRank, layout_role};
24use super::allocation::{PendingUpgrade, ReceiverAllocation, RouteAllocation};
25use crate::{
26 Bitrate, RoomMediaLimits, VideoAdaptationTuning,
27 engine::source_model::{PolicyPauseReason, PublishedSourceDescriptor, PublishedSourceId},
28};
29
30#[derive(Debug)]
32pub(super) struct PolicyFacts<'facts> {
33 pub(super) receivers: Vec<ReceiverFacts<'facts>>,
35 pub(super) routes: Vec<RouteFacts<'facts>>,
39 pub(super) speakers: Vec<SpeakerFacts>,
41 pub(super) media_limits: RoomMediaLimits,
42 pub(super) tuning: VideoAdaptationTuning,
43}
44
45#[derive(Debug)]
46pub(super) struct ReceiverFacts<'facts> {
47 pub(super) user_id: &'facts UserId,
48 pub(super) deaf: bool,
49 pub(super) featured: Option<bool>,
50 pub(super) bandwidth: Option<Bitrate>,
52 pub(super) allocation: ReceiverAllocation,
53}
54
55#[derive(Debug)]
56pub(super) struct RouteFacts<'facts> {
57 pub(super) receiver: usize,
59 pub(super) source: &'facts PublishedSourceDescriptor,
60 pub(super) source_bitrate: Option<Bitrate>,
62 pub(super) layout: Option<VideoLayoutIntent>,
63 pub(super) allocation: RouteAllocation,
64 pub(super) pending_upgrade: Option<PendingUpgrade>,
65}
66
67#[derive(Debug)]
68pub(super) struct SpeakerFacts {
69 pub(super) source_id: PublishedSourceId,
70 pub(super) observed_at: Instant,
71 pub(super) audio_level_dbov: Option<i8>,
72 pub(super) owner_screensharing: bool,
73 pub(super) featured_owner: Option<UserId>,
76}
77
78#[derive(Debug)]
79pub(super) struct PolicyPlan {
80 pub(super) routes: Vec<RoutePlan>,
82 pub(super) receivers: Vec<ReceiverPlan>,
84}
85
86#[derive(Debug, Clone, Copy, PartialEq, Eq)]
87pub(super) struct RoutePlan {
88 pub(super) allocation: RouteAllocation,
89 pub(super) pending_upgrade: Option<PendingUpgrade>,
90 pub(super) interrupts_upgrade: bool,
92 pub(super) request_keyframe: bool,
95 pub(super) transition: Option<VideoRouteTransition>,
96 pub(super) selected_estimated_bitrate: Option<Bitrate>,
98 pub(super) budget_bitrate: Option<BudgetBitrate>,
100}
101
102#[derive(Debug, Clone, Copy, PartialEq, Eq)]
104pub(super) struct BudgetBitrate {
105 pub(super) captured: Bitrate,
106 pub(super) planned: Bitrate,
107}
108
109#[derive(Debug, Clone, Copy, PartialEq, Eq)]
110pub(super) struct ReceiverPlan {
111 pub(super) allocation: ReceiverAllocation,
112 pub(super) bwe_target: Bitrate,
114 pub(super) featured: Option<bool>,
115 pub(super) next_deadline: Option<Instant>,
117 pub(super) retained_deadline: Option<Instant>,
120}
121
122#[derive(Debug, Clone, Copy, PartialEq, Eq)]
123pub(super) enum VideoRouteTransition {
124 Degraded,
125 Paused { reason: PolicyPauseReason },
126 Resumed { cleared_reason: PolicyPauseReason },
127}
128
129impl RoutePlan {
130 const fn unchanged(route: &RouteFacts<'_>) -> Self {
131 Self {
132 allocation: route.allocation,
133 pending_upgrade: route.pending_upgrade,
134 interrupts_upgrade: false,
135 request_keyframe: false,
136 transition: None,
137 selected_estimated_bitrate: None,
138 budget_bitrate: None,
139 }
140 }
141}
142
143#[must_use]
144pub(super) fn plan(facts: &PolicyFacts<'_>, now: Instant) -> PolicyPlan {
145 let speakers = speakers::SpeakerPlan::new(facts);
146 let audio_reserves = audio::reserve_by_receiver(facts, &speakers);
147 let mut plan = PolicyPlan {
148 routes: facts.routes.iter().map(RoutePlan::unchanged).collect(),
149 receivers: facts
150 .receivers
151 .iter()
152 .zip(&audio_reserves)
153 .map(|(receiver, &audio_reserve)| ReceiverPlan {
154 allocation: ReceiverAllocation::default(),
155 bwe_target: audio_reserve,
156 featured: speakers.featured(receiver),
157 next_deadline: None,
158 retained_deadline: None,
159 })
160 .collect(),
161 };
162 audio::plan(facts, &speakers, &mut plan.routes);
163 video::plan(facts, &speakers, &audio_reserves, now, &mut plan);
164 plan
165}