-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: bitrate control with Twcc and Remb #265
Conversation
WalkthroughWalkthroughThe recent updates across multiple components focus on enhancing bitrate management and track prioritization in media handling systems. Key changes include the introduction of new structures and enums for handling track priorities and bitrate configurations, adjustments to method signatures, and improvements in bandwidth estimation processes. Changes
Recent Review DetailsConfiguration used: CodeRabbit UI Files ignored due to path filters (2)
Files selected for processing (14)
Additional Context UsedGitHub Check Runs (2)
Additional comments not posted (19)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
if now.duration_since(*last_video_pkt).as_millis() >= TIMEOUT_MS { | ||
log::info!("[BweState] switched from WarmUp to Inactive after {:?} not received video pkt", now.duration_since(*last_video_pkt)); | ||
*self = Self::Inactive; | ||
return None; |
Check warning
Code scanning / clippy
unneeded return statement Warning
self.changed = false; | ||
let mut sum = TrackPriority(0); | ||
for (_track, priority) in self.tracks.iter() { | ||
sum = sum + *priority; |
Check warning
Code scanning / clippy
manual implementation of an assign operation Warning
@@ -333,6 +358,22 @@ | |||
local_track::Output::Event(event) => Some(InternalOutput::Event(EndpointEvent::LocalMediaTrack(id, event))), | |||
local_track::Output::Cluster(room, control) => Some(InternalOutput::Cluster(room, ClusterEndpointControl::LocalTrack(id, control))), | |||
local_track::Output::RpcRes(req_id, res) => Some(InternalOutput::RpcRes(req_id, EndpointRes::LocalTrack(id, res))), | |||
local_track::Output::DesiredBitrate(bitrate) => Some(InternalOutput::Event(EndpointEvent::BweConfig { | |||
current: bitrate, | |||
desired: bitrate + 100_000.max(bitrate * 1 / 5), |
Check warning
Code scanning / clippy
this operation has no effect Warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 7
Out of diff range and nitpick comments (6)
bin/src/server/media.rs (1)
42-42
: Reducing the worker polling interval to 1 millisecond increases responsiveness but could impact CPU usage. It's recommended to monitor performance metrics to ensure there are no adverse effects.packages/media_core/src/endpoint.rs (3)
34-34
: Consider adding documentation for theSwitch
variant to explain its parameters and usage.
71-71
: Add documentation forDesiredBitrate
to clarify its purpose and how it should be used in bitrate control.
88-91
: Ensure that the fieldscurrent
anddesired
inBweConfig
are adequately documented to explain their roles in bandwidth estimation.packages/media_core/src/endpoint/internal.rs (2)
18-22
: Consider organizing imports and module declarations at the top of the file for better readability.
Line range hint
56-69
: The constructornew
forEndpointInternal
lacks unit tests for its logic, especially the initialization ofbitrate_allocator
.Do you want me to help by writing some unit tests for this constructor?
self.bitrate_allocator.on_tick(); | ||
if let Some(out) = self.bitrate_allocator.pop_output() { | ||
match out { | ||
bitrate_allocator::Output::SetTrackBitrate(track, bitrate) => { | ||
if let Some(index) = self.local_tracks_id.get1(&track) { | ||
let out = self.local_tracks.on_event(now, *index, local_track::Input::LimitBitrate(bitrate))?; | ||
if let Some(out) = self.convert_local_track_output(now, track, out) { | ||
return Some(out); | ||
} | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method on_tick
modifies the state based on bitrate_allocator
outputs but lacks unit tests covering these changes.
Consider adding tests to cover the scenarios where bitrate adjustments are made based on the allocator's output.
TransportEvent::EgressBitrateEstimate(bitrate) => { | ||
let bitrate2 = bitrate.min(self.cfg.max_egress_bitrate as u64); | ||
log::debug!("[EndpointInternal] limit egress bitrate {bitrate2}, rewrite from {bitrate}"); | ||
self.bitrate_allocator.set_egress_bitrate(bitrate2); | ||
None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The handling of EgressBitrateEstimate
in on_transport_event
is not covered by tests, which is crucial for ensuring the bitrate control behaves as expected under different network conditions.
Would you like assistance in creating test cases for this event handling?
if let Some(kind) = event.need_create() { | ||
log::info!("[EndpointInternal] create local track {:?}", track); | ||
let room = self.joined.as_ref().map(|j| j.0.clone()); | ||
let index = self.local_tracks.add_task(EndpointLocalTrack::new(room)); | ||
let index = self.local_tracks.add_task(EndpointLocalTrack::new(kind, room)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method on_transport_local_track
creates a new local track but is not covered by unit tests, particularly the track creation logic.
It's important to ensure that track creation is handled correctly. Shall I help by adding some tests for this functionality?
local_track::Output::DesiredBitrate(bitrate) => Some(InternalOutput::Event(EndpointEvent::BweConfig { | ||
current: bitrate, | ||
desired: bitrate + 100_000.max(bitrate * 1 / 5), | ||
})), | ||
local_track::Output::Started(kind, priority) => { | ||
if kind.is_video() { | ||
self.bitrate_allocator.set_video_track(id, priority); | ||
} | ||
None | ||
} | ||
local_track::Output::Stopped(kind) => { | ||
if kind.is_video() { | ||
self.bitrate_allocator.del_video_track(id); | ||
} | ||
None | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method convert_local_track_output
handles various track events. However, the calculation in line 363 has no effect, which might be an oversight.
- desired: bitrate + 100_000.max(bitrate * 1 / 5),
+ desired: bitrate + 100_000.max(bitrate / 5),
This change ensures that the desired bitrate calculation is meaningful by correcting the division operation.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
local_track::Output::DesiredBitrate(bitrate) => Some(InternalOutput::Event(EndpointEvent::BweConfig { | |
current: bitrate, | |
desired: bitrate + 100_000.max(bitrate * 1 / 5), | |
})), | |
local_track::Output::Started(kind, priority) => { | |
if kind.is_video() { | |
self.bitrate_allocator.set_video_track(id, priority); | |
} | |
None | |
} | |
local_track::Output::Stopped(kind) => { | |
if kind.is_video() { | |
self.bitrate_allocator.del_video_track(id); | |
} | |
None | |
} | |
local_track::Output::DesiredBitrate(bitrate) => Some(InternalOutput::Event(EndpointEvent::BweConfig { | |
current: bitrate, | |
desired: bitrate + 100_000.max(bitrate / 5), | |
})), | |
local_track::Output::Started(kind, priority) => { | |
if kind.is_video() { | |
self.bitrate_allocator.set_video_track(id, priority); | |
} | |
None | |
} | |
local_track::Output::Stopped(kind) => { | |
if kind.is_video() { | |
self.bitrate_allocator.del_video_track(id); | |
} | |
None | |
} |
pub fn new(cfg: EndpointCfg, transport: T) -> Self { | ||
Self { | ||
transport, | ||
internal: EndpointInternal::new(), | ||
internal: EndpointInternal::new(cfg), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constructor for Endpoint
is not covered by unit tests. Consider adding tests to cover this critical initialization logic.
Would you like me to help by writing some unit tests for this method?
if now.duration_since(*last_video_pkt).as_millis() >= TIMEOUT_MS { | ||
log::info!("[BweState] switched from WarmUp to Inactive after {:?} not received video pkt", now.duration_since(*last_video_pkt)); | ||
*self = Self::Inactive; | ||
return None; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the unnecessary return
statement for cleaner code.
- return None;
+ None;
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
return None; | |
None; |
@@ -150,6 +151,15 @@ | |||
RemoteTrackEvent::Media(pkt), | |||
)))) | |||
} | |||
Str0mEvent::PeerStats(_stats) => None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable stats
is unused. Consider removing it if it's not needed, or ensure it's used if intended.
- Str0mEvent::PeerStats(_stats) => None,
+ Str0mEvent::PeerStats(_) => None,
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
Str0mEvent::PeerStats(_stats) => None, | |
Str0mEvent::PeerStats(_) => None, |
Pull Request
Description
This PR implement bitrate control with Twcc and Remb
Related Issue
If this pull request is related to any issue, please mention it here.
Checklist
Screenshots
If applicable, add screenshots to help explain the changes made.
Additional Notes
Add any additional notes or context about the pull request here.
Summary by CodeRabbit
New Features
Performance Improvements
Bug Fixes