fix(native): give video admission one owner
The allocator admitted an optional trial with a positive grant below every representation of its source, and the video Input then deactivated it silently. The flow was neither waiting nor rejected, so the route owner saw an admitted trial that sent audio and never video. The same split disabled a selected flow on a relay that cannot re-encode once the estimate fell below its only representation. The supply now reports a deliverable floor: the cheapest full or temporal representation, unknown before a complete observation and zero while idle. An output that the producer's encoder can serve in an accepted format has a zero floor, because any positive grant is usable. The allocator owns admission: an optional trial whose known floor exceeds its budget waits or is rejected, including when no selected incumbent is present. Established selected video keeps its floor when the estimate falls below it, which is charged before optional work, so floors beyond the estimate admit no optional load. Startup without feedback and unknown floors keep the existing bootstrap. This follows the shape of libwebrtc's allocator, which gives an enforced-minimum stream its minimum when the total is too low and pauses the others explicitly: https://webrtc.googlesource.com/src/+/refs/heads/main/call/bitrate_allocator.cc The Input keeps layer selection and keyframe readiness only. A positive grant that no longer fits after planning carries the cheapest representation until the next plan; Paused and a zero grant still deactivate it. Allocator tests cover the observed 187,043/121,722/53,370 bps case, exact and below-floor trials, unknown and idle sources, startup, the branch without an incumbent and selected floors above the estimate. Fixture tests whose subject is RTP identity or source lifetime now hold their second flow as selected media or give it a fixed estimate instead of relying on optional admission against the loopback estimate.
This commit is contained in:
1 parent
9115a86a79
commit
151f660109
6 files changed
+305
-37
No files matched your search
@@ -2,7 +2,7 @@
|
||||
//! independently when its finite queue cannot keep up.
|
||||
use super::{clock::SourceTime, Rate, RtpCodec};
|
||||
use crate::EncodedFrame;
|
||||
use anyhow::{ensure, Result};
|
||||
use anyhow::{ensure, Context, Result};
|
||||
use std::{
|
||||
collections::VecDeque,
|
||||
sync::{Arc, Mutex, OnceLock, Weak},
|
||||
@@ -11,7 +11,7 @@ use std::{
|
||||
use tokio::sync::{watch, Notify};
|
||||
|
||||
mod temporal;
|
||||
use temporal::{Decision, Rates, Temporal};
|
||||
use temporal::{Decision, Rates, Selection, Temporal};
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum EncodingDemand {
|
||||
@@ -103,6 +103,18 @@ impl Layers {
|
||||
}
|
||||
(highest, present.then_some(aggregate).flatten())
|
||||
}
|
||||
/// Cost of the cheapest representation any measured feed can deliver.
|
||||
/// Idle feeds cost nothing only while no measured feed is flowing.
|
||||
pub fn floor(&self, now: Instant) -> Option<u64> {
|
||||
let layers = self.0.lock().unwrap();
|
||||
layers
|
||||
.iter()
|
||||
.filter_map(|(_, video)| video.as_ref()?.floor(now))
|
||||
.reduce(|a, b| match (a, b) {
|
||||
(0, bps) | (bps, 0) => bps,
|
||||
(a, b) => a.min(b),
|
||||
})
|
||||
}
|
||||
pub fn supply(
|
||||
&self,
|
||||
inputs: &[(String, Arc<Input>)],
|
||||
@@ -122,11 +134,12 @@ impl Layers {
|
||||
let active = rates
|
||||
.iter()
|
||||
.any(|rate| rate.full.is_some_and(|bps| bps > 0));
|
||||
let mut remaining = match demand {
|
||||
let budget = match demand {
|
||||
EncodingDemand::Original => u64::MAX,
|
||||
EncodingDemand::Limited(bps) => u64::from(bps),
|
||||
EncodingDemand::Paused => 0,
|
||||
};
|
||||
let mut remaining = budget;
|
||||
for ((rid, video), rate) in layers.iter().zip(rates) {
|
||||
let Some((_, input)) = inputs.iter().find(|(id, _)| id == rid) else {
|
||||
continue;
|
||||
@@ -135,7 +148,13 @@ impl Layers {
|
||||
input.set_active(false);
|
||||
continue;
|
||||
};
|
||||
let selection = rate.fit(remaining);
|
||||
// The allocator owns admission. A grant it no longer fits after
|
||||
// planning still carries the cheapest representation, not nothing.
|
||||
let selection = rate.fit(remaining).or_else(|| {
|
||||
(remaining > 0 && remaining == budget)
|
||||
.then(|| rate.fit(rate.floor()?))
|
||||
.flatten()
|
||||
});
|
||||
let temporal = if demand == EncodingDemand::Original {
|
||||
None
|
||||
} else if let Some(selection) = selection {
|
||||
@@ -170,7 +189,7 @@ impl Layers {
|
||||
}
|
||||
if let Some(selection) = selection {
|
||||
input.set_active(true);
|
||||
remaining -= selection.bps;
|
||||
remaining = remaining.saturating_sub(selection.bps);
|
||||
} else {
|
||||
input.set_active(false);
|
||||
remaining = 0;
|
||||
@@ -233,6 +252,10 @@ impl Video {
|
||||
pub fn bitrate(&self, now: Instant) -> Option<u64> {
|
||||
self.rates(now).full
|
||||
}
|
||||
/// Cost of the cheapest full or temporal representation of this feed.
|
||||
pub fn floor(&self, now: Instant) -> Option<u64> {
|
||||
self.rates(now).floor()
|
||||
}
|
||||
pub(super) fn observe_rate(&self, active: bool, now: Instant) {
|
||||
self.0.rate.lock().unwrap().observing(active, now);
|
||||
}
|
||||
@@ -404,6 +427,7 @@ impl Input {
|
||||
let mut incumbent = None;
|
||||
let mut pending_feed = None;
|
||||
let mut active = false;
|
||||
let mut cheapest: Option<(&Video, Selection)> = None;
|
||||
let selected = videos.find_map(|video| {
|
||||
first.get_or_insert(video);
|
||||
if current.as_ref().is_some_and(|current| current.same(video)) {
|
||||
@@ -414,6 +438,11 @@ impl Input {
|
||||
}
|
||||
let rates = video.rates(now);
|
||||
active |= rates.full.is_some_and(|bps| bps > 0);
|
||||
if let Some(floor) = rates.floor().and_then(|bps| rates.fit(bps)) {
|
||||
if cheapest.is_none_or(|(_, cheapest)| floor.bps < cheapest.bps) {
|
||||
cheapest = Some((video, floor));
|
||||
}
|
||||
}
|
||||
rates.fit(budget).map(|selection| (video, selection))
|
||||
});
|
||||
if !active {
|
||||
@@ -435,10 +464,11 @@ impl Input {
|
||||
self.set_active(true);
|
||||
return Ok(());
|
||||
}
|
||||
let Some((video, selection)) = selected else {
|
||||
self.set_active(false);
|
||||
return Ok(());
|
||||
};
|
||||
// The allocator owns admission. A grant it no longer fits after
|
||||
// planning keeps the cheapest flowing representation until the next plan.
|
||||
let (video, selection) = selected
|
||||
.or(cheapest)
|
||||
.context("a flowing feed has no selectable representation")?;
|
||||
let required = if matches!(demand, EncodingDemand::Limited(_)) {
|
||||
let mut state = self.state.lock().unwrap();
|
||||
let incumbent = state
|
||||
@@ -1067,8 +1097,20 @@ mod tests {
|
||||
Some(0)
|
||||
);
|
||||
assert!(qi.state.lock().unwrap().active && hi.state.lock().unwrap().active);
|
||||
// The allocator owns admission: a positive grant that fits nothing
|
||||
// still carries the cheapest representation instead of no video.
|
||||
layers.supply(&inputs, EncodingDemand::Limited(1), now)?;
|
||||
assert!(!qi.state.lock().unwrap().active && !hi.state.lock().unwrap().active);
|
||||
assert_eq!(
|
||||
qi.state.lock().unwrap().pending.as_ref().unwrap().temporal,
|
||||
Some(0)
|
||||
);
|
||||
assert!(qi.state.lock().unwrap().active && !hi.state.lock().unwrap().active);
|
||||
layers.select(&terminal, EncodingDemand::Limited(1), now)?;
|
||||
{
|
||||
let state = terminal.state.lock().unwrap();
|
||||
assert!(state.active && state.current.as_ref().unwrap().same(&q));
|
||||
assert_eq!(state.temporal.target, Some(0));
|
||||
}
|
||||
// Idle samples preserve selection; resumption reopens the shared window.
|
||||
let idle = now + Duration::from_secs(2);
|
||||
q.rates(idle);
|
||||
|
||||
@@ -34,6 +34,21 @@ impl Rates {
|
||||
}
|
||||
Self { full, temporal }
|
||||
}
|
||||
/// Cost of the cheapest representation `fit` can select: unknown before a
|
||||
/// complete observation, zero while the feed is idle.
|
||||
pub fn floor(&self) -> Option<u64> {
|
||||
let full = self.full?;
|
||||
Some(
|
||||
self.temporal
|
||||
.iter()
|
||||
.flatten()
|
||||
.chain([&full])
|
||||
.copied()
|
||||
.filter(|bps| *bps > 0)
|
||||
.min()
|
||||
.unwrap_or(0),
|
||||
)
|
||||
}
|
||||
pub fn fit(&self, budget: u64) -> Option<Selection> {
|
||||
let full = self.full?;
|
||||
if full > 0 && full <= budget {
|
||||
|
||||
@@ -13,6 +13,16 @@ pub(super) struct BandwidthPlan {
|
||||
pub rejected: HashSet<Uuid>,
|
||||
video: HashMap<Uuid, VideoAllocation>,
|
||||
}
|
||||
impl BandwidthPlan {
|
||||
/// An optional flow that does not fit ends its trial or waits to start one.
|
||||
fn decline(&mut self, request: &Request) {
|
||||
if request.started {
|
||||
self.rejected.insert(request.id);
|
||||
} else {
|
||||
self.waiting.insert(request.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn desired_bitrate(
|
||||
configured: Option<u32>,
|
||||
@@ -60,7 +70,11 @@ impl Driver {
|
||||
(rate, rate)
|
||||
}
|
||||
};
|
||||
(source.id, rates)
|
||||
let floor = match &source.layers {
|
||||
Some(layers) => layers.floor(now),
|
||||
None => source.video().and_then(|video| video.floor(now)),
|
||||
};
|
||||
(source.id, (rates, floor))
|
||||
})
|
||||
.collect();
|
||||
self.pairs
|
||||
@@ -98,7 +112,7 @@ impl Driver {
|
||||
let mut opaque_bps = 0;
|
||||
let mut video = None;
|
||||
for source in &sources {
|
||||
let (highest, aggregate) = rates[&source.id];
|
||||
let ((highest, aggregate), floor) = rates[&source.id];
|
||||
let rate = if pair.plan.can_receive_video_layers {
|
||||
aggregate
|
||||
} else {
|
||||
@@ -112,6 +126,21 @@ impl Driver {
|
||||
});
|
||||
#[cfg(not(feature = "capture"))]
|
||||
let requires_conversion = false;
|
||||
// The producer's encoder serves any positive grant in a
|
||||
// format this receiver accepts. Before negotiation, the
|
||||
// output offers the source format.
|
||||
#[cfg(feature = "capture")]
|
||||
let encodable = self.has_video_producer(source.id)
|
||||
&& crate::media::encoding_codec(source.codec()).is_some_and(
|
||||
|codec| {
|
||||
output.filter(|out| out.source == source.id).map_or_else(
|
||||
|| crate::media::compatible(&codec, source.codec()),
|
||||
|out| out.can_forward(&codec),
|
||||
)
|
||||
},
|
||||
);
|
||||
#[cfg(not(feature = "capture"))]
|
||||
let encodable = false;
|
||||
if flow.selected && !requires_conversion {
|
||||
// Original bytes are not this output's transmit demand
|
||||
// when negotiation requires another representation.
|
||||
@@ -129,6 +158,11 @@ impl Driver {
|
||||
measured &= full_bps.is_some();
|
||||
video = Some(VideoRequest {
|
||||
full_bps,
|
||||
floor_bps: if encodable {
|
||||
Some(0)
|
||||
} else {
|
||||
floor.map(|bps| bps.min(u64::from(u32::MAX)) as u32)
|
||||
},
|
||||
requires_conversion,
|
||||
ceiling_bps: configured.or_else(|| {
|
||||
self.publications[&flow.publication_id]
|
||||
@@ -381,11 +415,17 @@ struct Request {
|
||||
}
|
||||
struct VideoRequest {
|
||||
full_bps: Option<u32>,
|
||||
/// Cheapest representation this output can deliver: unknown before a
|
||||
/// complete observation, zero while idle or when an encoder serves any grant.
|
||||
floor_bps: Option<u32>,
|
||||
requires_conversion: bool,
|
||||
ceiling_bps: Option<u32>,
|
||||
stable: bool,
|
||||
}
|
||||
impl VideoRequest {
|
||||
fn below_floor(&self, grant: u64) -> bool {
|
||||
self.floor_bps.is_some_and(|floor| u64::from(floor) > grant)
|
||||
}
|
||||
fn capacity(&self) -> Option<u32> {
|
||||
if self.requires_conversion {
|
||||
self.ceiling_bps
|
||||
@@ -453,17 +493,41 @@ fn allocate(estimate: transport::Estimate, requests: &[Request]) -> BandwidthPla
|
||||
requests.iter().filter(|r| r.selected),
|
||||
&mut plan,
|
||||
);
|
||||
// Like libwebrtc's enforced minimum, established selected video keeps the
|
||||
// cheapest representation it can deliver; the SDK paces any excess.
|
||||
for request in requests.iter().filter(|r| r.selected) {
|
||||
let (Some(video), Some(allocation)) = (&request.video, plan.video.get_mut(&request.id))
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
if let Some(floor) = video.floor_bps.filter(|bps| *bps > allocation.encoder_bps) {
|
||||
*allocation = video.allocation(u64::from(floor), floor);
|
||||
}
|
||||
}
|
||||
if !protected {
|
||||
// With no selected incumbent to protect, optional flows may start
|
||||
// using the current feedback-derived budget.
|
||||
let opaque = requests.iter().map(|r| r.opaque_bps).sum::<u64>();
|
||||
share_video_budget(
|
||||
target.saturating_sub(opaque),
|
||||
requests.iter().filter(|r| !r.selected),
|
||||
&mut plan,
|
||||
);
|
||||
let budget = target.saturating_sub(opaque);
|
||||
share_video_budget(budget, requests.iter().filter(|r| !r.selected), &mut plan);
|
||||
for request in requests.iter().filter(|r| !r.selected) {
|
||||
let grant = plan
|
||||
.video
|
||||
.get(&request.id)
|
||||
.map_or(budget, |allocation| u64::from(allocation.encoder_bps));
|
||||
if request
|
||||
.video
|
||||
.as_ref()
|
||||
.is_some_and(|video| video.below_floor(grant))
|
||||
{
|
||||
plan.video.remove(&request.id);
|
||||
plan.decline(request);
|
||||
}
|
||||
}
|
||||
return plan;
|
||||
}
|
||||
// Original supply, or a conversion's grant, already covers each selected
|
||||
// floor. Floors beyond the estimate leave nothing for optional flows.
|
||||
let selected_cap = requests
|
||||
.iter()
|
||||
.filter(|r| r.selected)
|
||||
@@ -498,17 +562,12 @@ fn allocate(estimate: transport::Estimate, requests: &[Request]) -> BandwidthPla
|
||||
let opaque = request.opaque_bps;
|
||||
let budget = remaining.saturating_sub(opaque);
|
||||
if opaque > remaining
|
||||
|| request
|
||||
.video
|
||||
.as_ref()
|
||||
.is_some_and(|v| v.requires_conversion || v.full_bps.is_some_and(|bps| bps > 0))
|
||||
&& budget == 0
|
||||
|| request.video.as_ref().is_some_and(|v| {
|
||||
(v.requires_conversion || v.full_bps.is_some_and(|bps| bps > 0)) && budget == 0
|
||||
|| v.below_floor(budget)
|
||||
})
|
||||
{
|
||||
if request.started {
|
||||
plan.rejected.insert(request.id);
|
||||
} else {
|
||||
plan.waiting.insert(request.id);
|
||||
}
|
||||
plan.decline(request);
|
||||
continue;
|
||||
}
|
||||
remaining = budget;
|
||||
@@ -659,7 +718,8 @@ mod tests {
|
||||
use rtc_shared::time::SystemInstant;
|
||||
|
||||
#[tokio::test]
|
||||
async fn late_viewer_bootstraps_known_layers_before_feedback_then_obeys_budget() -> Result<()> {
|
||||
async fn late_viewer_bootstraps_known_layers_before_feedback_then_keeps_its_floor() -> Result<()>
|
||||
{
|
||||
let epoch = Instant::now();
|
||||
let time = SourceTime::local(epoch, SystemInstant::now(epoch));
|
||||
let low = Video::new(time.clone(), Arc::new(Notify::new()));
|
||||
@@ -673,19 +733,26 @@ mod tests {
|
||||
low.write(frame(128_000, 0));
|
||||
high.write(frame(512_000, 0));
|
||||
let now = epoch + Duration::from_secs(2);
|
||||
assert!(low.bitrate(now).unwrap() > 300_000);
|
||||
let floor = low.bitrate(now).unwrap() as u32;
|
||||
assert!(floor > 300_000);
|
||||
let full = high.bitrate(now).unwrap() as u32;
|
||||
let layers = Layers::new(vec!["q".into(), "h".into()]);
|
||||
layers.insert("q".into(), low.clone());
|
||||
layers.insert("h".into(), high.clone());
|
||||
let requests = [request(1, true, Some(0), Some((full, true)))];
|
||||
assert_eq!(layers.floor(now), Some(u64::from(floor)));
|
||||
let mut requests = [request(1, true, Some(0), Some((full, true)))];
|
||||
requests[0].video.as_mut().unwrap().floor_bps = Some(floor);
|
||||
let input = low.subscribe();
|
||||
let key = Uuid::from_u128(1);
|
||||
|
||||
// The old numeric startup path pauses a late viewer with these actual rates.
|
||||
// Feedback below every layer keeps the cheapest one rather than pausing.
|
||||
let startup_number = allocate(Some(300_000), &requests);
|
||||
assert_eq!(
|
||||
startup_number.video[&key].forwarding,
|
||||
EncodingDemand::Limited(floor)
|
||||
);
|
||||
layers.select(&input, startup_number.video[&key].forwarding, now)?;
|
||||
assert!(!low.needed() && !high.needed());
|
||||
assert!(low.needed() && !high.needed());
|
||||
|
||||
let startup = allocate(None, &requests);
|
||||
layers.select(&input, startup.video[&key].forwarding, now)?;
|
||||
@@ -696,10 +763,10 @@ mod tests {
|
||||
epoch + Duration::from_millis(2100)
|
||||
);
|
||||
|
||||
// Real feedback can constrain this same Output after bootstrap.
|
||||
// Real feedback constrains this same Output to its floor after bootstrap.
|
||||
let constrained = allocate(Some(100_000), &requests);
|
||||
layers.select(&input, constrained.video[&key].forwarding, now)?;
|
||||
assert!(!low.needed() && !high.needed());
|
||||
assert!(low.needed() && !high.needed());
|
||||
let restored = allocate(Some(u64::from(full)), &requests);
|
||||
layers.select(&input, restored.video[&key].forwarding, now)?;
|
||||
high.write(frame(64, 2200));
|
||||
@@ -715,8 +782,8 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn sdk_minimum_tracks_selected_original_supply_and_its_lifecycle() -> Result<()> {
|
||||
// The actual Driver advertises original supply, independently of the
|
||||
// Limited grant it gives this selected output. Unknown desired capacity
|
||||
// must not become a fabricated minimum.
|
||||
// grant it gives this selected output. Unknown desired capacity must
|
||||
// not become a fabricated minimum.
|
||||
let mut f =
|
||||
crate::peer::tests::support::Fixture::new(crate::peer::tests::support::vp8()).await?;
|
||||
f.driver
|
||||
@@ -782,9 +849,10 @@ mod tests {
|
||||
let original_bps = original.bitrate(measured).unwrap();
|
||||
assert!(original_bps > 100_000);
|
||||
let plan = f.driver.bandwidth_plans(measured);
|
||||
// Its only representation exceeds the estimate, so the grant keeps it.
|
||||
assert_eq!(
|
||||
plan[&f.sink].video[&flow_id].forwarding,
|
||||
EncodingDemand::Limited(100_000)
|
||||
EncodingDemand::Original
|
||||
);
|
||||
assert_eq!(
|
||||
*f.driver.pairs[&f.sink].demand.borrow(),
|
||||
@@ -1005,6 +1073,7 @@ mod tests {
|
||||
measured: opaque.is_some(),
|
||||
video: video.map(|(cap_bps, stable)| VideoRequest {
|
||||
full_bps: Some(cap_bps),
|
||||
floor_bps: None,
|
||||
requires_conversion: false,
|
||||
ceiling_bps: None,
|
||||
stable,
|
||||
@@ -1242,4 +1311,121 @@ mod tests {
|
||||
assert_eq!(startup.video[&requests[0].id].encoder_bps, 100_000);
|
||||
assert_eq!(startup.video[&requests[1].id].encoder_bps, 100_000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn optional_trials_start_only_when_their_floor_fits() {
|
||||
// Observed: a selected feed and a started trial of the same single
|
||||
// 121,722 bps representation, each with audio, on 187,043 bps feedback.
|
||||
let estimate = Some(187_043);
|
||||
let incumbent = Uuid::from_u128(1);
|
||||
let trial = Uuid::from_u128(2);
|
||||
let requests = |floor| {
|
||||
let mut requests = [
|
||||
request(1, true, Some(5_975), Some((121_722, true))),
|
||||
request(2, false, Some(5_976), Some((121_722, true))),
|
||||
];
|
||||
requests[0].video.as_mut().unwrap().floor_bps = Some(121_722);
|
||||
requests[1].video.as_mut().unwrap().floor_bps = floor;
|
||||
requests[1].started = true;
|
||||
requests
|
||||
};
|
||||
// An unknown floor keeps today's grant: the remainder after the incumbent.
|
||||
let plan = allocate(estimate, &requests(None));
|
||||
assert_eq!(plan.video[&incumbent].forwarding, EncodingDemand::Original);
|
||||
assert_eq!(
|
||||
plan.video[&trial].forwarding,
|
||||
EncodingDemand::Limited(53_370)
|
||||
);
|
||||
|
||||
let plan = allocate(estimate, &requests(Some(121_722)));
|
||||
assert_eq!(plan.video[&incumbent].forwarding, EncodingDemand::Original);
|
||||
assert!(plan.rejected.contains(&trial) && !plan.video.contains_key(&trial));
|
||||
|
||||
// A cheaper representation fits exactly; an encoder serves any grant.
|
||||
for floor in [53_370, 0] {
|
||||
let plan = allocate(estimate, &requests(Some(floor)));
|
||||
assert!(plan.rejected.is_empty() && plan.waiting.is_empty());
|
||||
assert_eq!(
|
||||
plan.video[&trial].forwarding,
|
||||
EncodingDemand::Limited(53_370)
|
||||
);
|
||||
}
|
||||
let mut below = requests(Some(53_371));
|
||||
assert!(allocate(estimate, &below).rejected.contains(&trial));
|
||||
below[1].started = false;
|
||||
below[1].video.as_mut().unwrap().stable = false;
|
||||
let plan = allocate(estimate, &below);
|
||||
assert!(plan.waiting.contains(&trial) && plan.rejected.is_empty());
|
||||
|
||||
// A static source costs nothing, so a positive remainder wakes it.
|
||||
let mut idle = requests(Some(0));
|
||||
idle[1].video.as_mut().unwrap().full_bps = Some(0);
|
||||
let plan = allocate(estimate, &idle);
|
||||
assert!(plan.rejected.is_empty() && plan.waiting.is_empty());
|
||||
assert_eq!(plan.video[&trial].forwarding, EncodingDemand::Original);
|
||||
|
||||
// An unmeasured trial and the no-feedback startup wait as before.
|
||||
let mut unknown = requests(None);
|
||||
unknown[1].measured = false;
|
||||
unknown[1].video.as_mut().unwrap().full_bps = None;
|
||||
let plan = allocate(estimate, &unknown);
|
||||
assert!(plan.waiting.contains(&trial) && plan.video[&trial] == PAUSED);
|
||||
let plan = allocate(None, &requests(Some(121_722)));
|
||||
assert_eq!(plan.video[&incumbent].forwarding, EncodingDemand::Original);
|
||||
assert!(plan.waiting.contains(&trial) && plan.video[&trial] == PAUSED);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trials_without_an_incumbent_start_only_when_their_floor_fits() {
|
||||
let trial = Uuid::from_u128(2);
|
||||
let mut requests = [request(2, false, Some(5_976), Some((121_722, true)))];
|
||||
requests[0].started = true;
|
||||
requests[0].video.as_mut().unwrap().floor_bps = Some(121_722);
|
||||
let plan = allocate(Some(59_346), &requests);
|
||||
assert!(plan.rejected.contains(&trial) && !plan.video.contains_key(&trial));
|
||||
let plan = allocate(Some(121_722 + 5_976), &requests);
|
||||
assert!(plan.rejected.is_empty());
|
||||
assert_eq!(plan.video[&trial].forwarding, EncodingDemand::Original);
|
||||
// The startup estimate still bootstraps the trial.
|
||||
let plan = allocate(None, &requests);
|
||||
assert!(plan.rejected.is_empty());
|
||||
assert_eq!(plan.video[&trial].forwarding, EncodingDemand::Original);
|
||||
requests[0].started = false;
|
||||
requests[0].video.as_mut().unwrap().stable = false;
|
||||
let plan = allocate(Some(59_346), &requests);
|
||||
assert!(plan.waiting.contains(&trial) && plan.rejected.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn selected_video_keeps_its_floor_before_optional_work() {
|
||||
let selected = Uuid::from_u128(1);
|
||||
let optional = Uuid::from_u128(2);
|
||||
let mut requests = [
|
||||
request(1, true, Some(0), Some((600_000, true))),
|
||||
request(2, false, Some(0), Some((50_000, true))),
|
||||
];
|
||||
requests[0].video.as_mut().unwrap().floor_bps = Some(200_000);
|
||||
requests[1].video.as_mut().unwrap().floor_bps = Some(10_000);
|
||||
requests[1].started = true;
|
||||
// Above its temporal base layer, the selected grant follows the estimate.
|
||||
let plan = allocate(Some(300_000), &requests);
|
||||
assert_eq!(
|
||||
plan.video[&selected].forwarding,
|
||||
EncodingDemand::Limited(300_000)
|
||||
);
|
||||
// Below it, the floor is kept and charged before any optional work.
|
||||
let plan = allocate(Some(150_000), &requests);
|
||||
assert_eq!(
|
||||
plan.video[&selected],
|
||||
VideoAllocation {
|
||||
forwarding: EncodingDemand::Limited(200_000),
|
||||
encoder_bps: 200_000,
|
||||
}
|
||||
);
|
||||
assert!(plan.rejected.contains(&optional) && !plan.video.contains_key(&optional));
|
||||
// A single representation stays whole rather than pausing.
|
||||
requests[0].video.as_mut().unwrap().floor_bps = Some(600_000);
|
||||
let plan = allocate(Some(150_000), &requests[..1]);
|
||||
assert_eq!(plan.video[&selected].forwarding, EncodingDemand::Original);
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,10 @@ async fn video_bootstrap_retries_a_missed_keyframe_request() -> Result<()> {
|
||||
async fn shadow_flows_preserve_source_clock_and_warm_outputs() -> Result<()> {
|
||||
let mut f = Fixture::new(vp8()).await?;
|
||||
let sink = f.sink;
|
||||
// Warm-output identity, not trial admission against the loopback
|
||||
// estimate, is under test here. Give both flows room to carry video.
|
||||
f.driver.pairs.get_mut(&sink).unwrap().bandwidth =
|
||||
watch::channel(transport::Estimate::Feedback(10_000_000.0)).1;
|
||||
let old_flow = f.plans.last().unwrap().outgoing[0].id;
|
||||
let warm_flow = f.plans.last().unwrap().outgoing[1].id;
|
||||
f.until(|f| {
|
||||
|
||||
@@ -666,6 +666,18 @@ async fn repeated_media_leases_keep_sibling_av_and_use_fresh_rtp() -> Result<()>
|
||||
let pc = fixture.driver.pairs[&sink].pc.clone();
|
||||
let sibling = fixture.plans.last().unwrap().outgoing[0].id;
|
||||
let mut binding = fixture.plans.last().unwrap().outgoing[1];
|
||||
// Both leases are required media. Optional-trial admission is covered
|
||||
// by the allocator's own tests.
|
||||
binding.selected = true;
|
||||
fixture.plans.last_mut().unwrap().outgoing[1] = binding;
|
||||
fixture
|
||||
.driver
|
||||
.update(
|
||||
fixture.plans.clone(),
|
||||
vec![fixture.publication.clone()],
|
||||
vec![],
|
||||
)
|
||||
.await;
|
||||
fixture
|
||||
.until(|f| {
|
||||
[sibling, binding.id].iter().all(|flow| {
|
||||
|
||||
@@ -94,6 +94,9 @@ async fn declared_source_withdrawal_remaps_the_same_flow_without_failing_its_pai
|
||||
let input = f.plans[0].incoming[0].id;
|
||||
let flow = f.plans.last().unwrap().outgoing[0].id;
|
||||
let sibling = f.plans.last().unwrap().outgoing[1].id;
|
||||
// The sibling is retained media, not an optional trial admitted
|
||||
// against the remapped flow's bandwidth.
|
||||
f.plans.last_mut().unwrap().outgoing[1].selected = true;
|
||||
f.plans[0].rooms.clear();
|
||||
f.driver
|
||||
.update(f.plans.clone(), vec![f.publication.clone()], vec![])
|
||||
@@ -372,6 +375,12 @@ async fn physical_failure_retires_only_that_source_and_keeps_other_flow_leases()
|
||||
let mut f = Fixture::new(vp8()).await?;
|
||||
let result = async {
|
||||
let sink = f.sink;
|
||||
// The survivor is retained media, not an optional trial admitted
|
||||
// against the failing flow's bandwidth.
|
||||
f.plans.last_mut().unwrap().outgoing[1].selected = true;
|
||||
f.driver
|
||||
.update(f.plans.clone(), vec![f.publication.clone()], vec![])
|
||||
.await;
|
||||
let flow = f.plans.iter().find(|p| p.id == sink).unwrap().outgoing[1].id;
|
||||
f.until(|f| {
|
||||
f.driver.pairs[&sink]
|
||||
|
||||
Reference in new issue
Block a user