Skip to content

Commit aab28db

Browse files
authored
feat: more aggresive quality upgrade (#46)
* more aggressive initial bwe * fix: incorrect keyframe request on transition * fix: miss switching opportunity * init depacketizer * update keyframe filter * save things * add keyframe request retry * increase keyframe debounce to 500ms * remove unused * rename push to forward * ref: make it consistent with poll_slow and poll_fast * fix: warnings
1 parent c57e167 commit aab28db

File tree

12 files changed

+311
-161
lines changed

12 files changed

+311
-161
lines changed

pulsebeam/src/controller.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl ControllerActor {
123123
.set_rtp_mode(true)
124124
// .set_stats_interval(Some(Duration::from_millis(200)))
125125
// TODO: enable bwe
126-
.enable_bwe(Some(str0m::bwe::Bitrate::kbps(300)))
126+
.enable_bwe(Some(str0m::bwe::Bitrate::mbps(1)))
127127
// Uncomment this to see statistics
128128
// .set_stats_interval(Some(Duration::from_secs(1)))
129129
// enable for compatibility, some clients don't support remote ice-lite

pulsebeam/src/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::shard::ShardMessageSet;
2-
use crate::{api, controller, gateway, shard};
2+
use crate::{api, controller, gateway};
33
use pulsebeam_runtime::actor::RunnerConfig;
44
use pulsebeam_runtime::prelude::*;
55
use pulsebeam_runtime::{actor, net, rand};

pulsebeam/src/participant/actor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl actor::Actor<ParticipantMessageSet> for ParticipantActor {
142142

143143
// Priority 4: Background tasks
144144
now = stats_interval.tick() => {
145-
self.core.poll_stats(now);
145+
self.core.poll_slow(now);
146146
}
147147
_ = &mut rtc_timer => {
148148
new_deadline = self.core.handle_timeout();

pulsebeam/src/participant/core.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,10 @@ impl ParticipantCore {
126126
self.update_desired_bitrate();
127127
}
128128

129-
pub fn poll_stats(&mut self, now: Instant) {
129+
pub fn poll_slow(&mut self, now: Instant) {
130130
self.update_desired_bitrate();
131-
self.upstream.poll_stats(now);
131+
self.downstream.poll_slow(now);
132+
self.upstream.poll_slow(now);
132133
}
133134

134135
pub fn poll_rtc(&mut self) -> Option<Instant> {

pulsebeam/src/participant/downstream/audio.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
use futures_lite::StreamExt;
22
use pulsebeam_runtime::sync::spmc;
33

4-
use std::pin::Pin;
4+
use crate::entity::TrackId;
5+
use crate::rtp;
6+
use crate::rtp::RtpPacket;
7+
use crate::rtp::timeline::Timeline;
8+
use crate::track::TrackReceiver;
59
use std::sync::Arc;
610
use std::task::Waker;
711
use std::task::ready;
812
use std::task::{Context, Poll};
913
use std::time::Duration;
1014
use str0m::media::Mid;
1115
use tokio::time::Instant;
12-
use tokio_stream::{Stream, StreamMap};
13-
14-
use crate::entity::TrackId;
15-
use crate::rtp;
16-
use crate::rtp::RtpPacket;
17-
use crate::rtp::timeline::Timeline;
18-
use crate::track::SimulcastReceiver;
19-
use crate::track::TrackReceiver;
20-
use pulsebeam_runtime::sync::spmc::RecvError;
16+
use tokio_stream::StreamMap;
2117

2218
pub struct AudioAllocator {
2319
inputs: StreamMap<Arc<TrackId>, spmc::Receiver<RtpPacket>>,

pulsebeam/src/participant/downstream/mod.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
mod audio;
22
mod video;
33

4-
use crate::participant::bitrate::BitrateController;
54
use crate::participant::downstream::audio::AudioAllocator;
65
use crate::participant::downstream::video::VideoAllocator;
76
use crate::rtp::RtpPacket;
@@ -14,7 +13,7 @@ use str0m::media::{KeyframeRequest, MediaKind, Mid};
1413
use tokio::time::Instant;
1514

1615
pub struct DownstreamAllocator {
17-
available_bandwidth: BitrateController,
16+
available_bandwidth: Bitrate,
1817

1918
audio: AudioAllocator,
2019
video: VideoAllocator,
@@ -23,7 +22,7 @@ pub struct DownstreamAllocator {
2322
impl DownstreamAllocator {
2423
pub fn new() -> Self {
2524
Self {
26-
available_bandwidth: BitrateController::default(),
25+
available_bandwidth: Bitrate::mbps(1),
2726
audio: AudioAllocator::new(),
2827
video: VideoAllocator::default(),
2928
}
@@ -52,33 +51,35 @@ impl DownstreamAllocator {
5251

5352
/// Handle BWE and compute both current and desired bitrate in one pass.
5453
pub fn update_bitrate(&mut self, available_bandwidth: Bitrate) -> (Bitrate, Bitrate) {
55-
self.available_bandwidth
56-
.update(available_bandwidth, Instant::now());
54+
self.available_bandwidth = available_bandwidth;
5755
self.update_allocations()
5856
}
5957

6058
pub fn update_allocations(&mut self) -> (Bitrate, Bitrate) {
61-
self.video
62-
.update_allocations(self.available_bandwidth.current())
59+
self.video.update_allocations(self.available_bandwidth)
6360
}
6461

6562
pub fn handle_keyframe_request(&mut self, req: KeyframeRequest) {
6663
self.video.handle_keyframe_request(req);
6764
}
6865

69-
pub fn poll_next_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Option<(Mid, RtpPacket)>> {
66+
pub fn poll_slow(&mut self, now: Instant) {
67+
self.video.poll_slow(now);
68+
}
69+
70+
pub fn poll_fast(&mut self, cx: &mut Context<'_>) -> Poll<Option<(Mid, RtpPacket)>> {
7071
if let Poll::Ready(item) = self.audio.poll_next(cx) {
7172
return Poll::Ready(item);
7273
}
7374

74-
self.video.poll_next(cx)
75+
self.video.poll_fast(cx)
7576
}
7677
}
7778

7879
impl Stream for DownstreamAllocator {
7980
type Item = (Mid, RtpPacket);
8081

8182
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
82-
self.get_mut().poll_next_unpin(cx)
83+
self.get_mut().poll_fast(cx)
8384
}
8485
}

0 commit comments

Comments
 (0)