87 lines
3.2 KiB
Python
87 lines
3.2 KiB
Python
"""Replay the observed grant ramp without hardware or altered packet admission."""
|
|
|
|
import unittest
|
|
|
|
from missioncore_plugin_sdk.media_budget import MediaBudget
|
|
|
|
|
|
class PreviewRecoveryTests(unittest.TestCase):
|
|
def setUp(self):
|
|
now = [100.]
|
|
budget = MediaBudget("video", clock=lambda: now[0])
|
|
|
|
def grant(at, rate, mode="observing"):
|
|
now[0] = 100 + at
|
|
budget.update({"schema": "missioncore.media-budget/v1", "allocation_bps": rate,
|
|
"ttl_ms": 3000, "mode": mode})
|
|
return budget.video()
|
|
|
|
self.preview = budget, now, grant
|
|
|
|
def tearDown(self):
|
|
self.preview[0].connection.close()
|
|
|
|
def test_brief_pause_and_single_low_grant_do_not_resize_video(self):
|
|
budget, _, grant = self.preview
|
|
assert grant(0, 5_000_000) == (1280, 15)
|
|
assert grant(1, 0) == (0, 0)
|
|
assert budget.bps == 0
|
|
assert grant(1.3, 184320) == (1280, 15)
|
|
assert budget.bps == 119808 # The smaller bitrate applies immediately.
|
|
assert grant(1.8, 5_000_000) == (1280, 15)
|
|
assert budget.profile == (1280, 15)
|
|
|
|
|
|
def test_recorded_recovery_ramp_does_not_pin_stream_at_two_fps(self):
|
|
budget, _, grant = self.preview
|
|
grant(0, 5_000_000)
|
|
assert grant(1, 0) == (0, 0)
|
|
# Node159 stationary recording: grant recovered every 0.5 s, but video
|
|
# remained 480x240 / 2 FPS for five seconds as its upgrade timer restarted.
|
|
rates = [184320, 672160, 1206080, 1720160, 1903120,
|
|
2494480, 3077520, 3634400, 4271520, 4841440]
|
|
profiles = []
|
|
for tick, rate in enumerate(rates):
|
|
profiles.append(grant(1.5 + tick * .5, rate))
|
|
assert budget.bps == int(rate * .65)
|
|
assert min(fps for _, fps in profiles) >= 6
|
|
assert profiles[7] == (1280, 15)
|
|
|
|
|
|
def test_sustained_low_capacity_still_reduces_profile(self):
|
|
budget, _, grant = self.preview
|
|
grant(0, 5_000_000)
|
|
grant(1, 100_000)
|
|
assert grant(1.5, 100_000) == (1280, 15)
|
|
assert grant(2, 100_000) == (320, 1)
|
|
assert budget.bps == 65000
|
|
assert grant(2.1, 0) == (0, 0)
|
|
assert grant(20, 100_000) == (320, 1)
|
|
|
|
|
|
def test_quality_recovery_needs_continuous_improvement_not_equal_numbers(self):
|
|
_, _, grant = self.preview
|
|
assert grant(0, 800000) == (960, 6)
|
|
assert grant(1, 1500000) == (960, 6)
|
|
assert grant(2, 5000000) == (960, 6)
|
|
assert grant(3, 5000000) == (1280, 15)
|
|
|
|
|
|
def test_pause_and_relapse_do_not_count_as_healthy_upgrade_time(self):
|
|
_, _, grant = self.preview
|
|
assert grant(0, 800000) == (960, 6)
|
|
grant(1, 5000000)
|
|
assert grant(2, 0) == (0, 0)
|
|
assert grant(10, 5000000) == (960, 6)
|
|
assert grant(11, 800000) == (960, 6)
|
|
assert grant(12, 5000000) == (960, 6)
|
|
assert grant(14, 5000000) == (1280, 15)
|
|
|
|
|
|
def test_expired_grant_pauses_and_mode_change_uses_current_policy(self):
|
|
budget, now, grant = self.preview
|
|
assert grant(0, 800000) == (960, 6)
|
|
now[0] = 104
|
|
assert budget.bps == 0 and budget.video() == (0, 0)
|
|
assert grant(5, 800000, "control_reserved") == (640, 10)
|