Commit 394c8003 authored by Yuwei Huang's avatar Yuwei Huang Committed by Commit Bot

[remoting host] Allow client to override min and max bitrate

We have had some reports from users that claim the session performance
is pretty bad and they can improve it by hardcoding a higher min
bitrate.

To help us debug this issue, this CL adds support to the host to apply
min/max bitrate from session options.

Bug: 1096197
Change-Id: Ifd76fb81b9d69581740110a34f547e92efb63c33
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2250662Reviewed-by: default avatarLambros Lambrou <lambroslambrou@chromium.org>
Commit-Queue: Yuwei Huang <yuweih@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779605}
parent b6f92595
...@@ -561,7 +561,9 @@ bool WebrtcTransport::ProcessTransportInfo(XmlElement* transport_info) { ...@@ -561,7 +561,9 @@ bool WebrtcTransport::ProcessTransportInfo(XmlElement* transport_info) {
// SetRemoteDescription() might overwrite any bitrate caps previously set, // SetRemoteDescription() might overwrite any bitrate caps previously set,
// so (re)apply them here. This might happen if ICE state were already // so (re)apply them here. This might happen if ICE state were already
// connected and OnStatsDelivered() had already set the caps. // connected and OnStatsDelivered() had already set the caps.
SetPeerConnectionBitrates(MaxBitrateForConnection()); int min_bitrate_bps, max_bitrate_bps;
std::tie(min_bitrate_bps, max_bitrate_bps) = BitratesForConnection();
SetPeerConnectionBitrates(min_bitrate_bps, max_bitrate_bps);
} }
XmlElement* candidate_element; XmlElement* candidate_element;
...@@ -693,7 +695,9 @@ void WebrtcTransport::OnAudioTransceiverCreated( ...@@ -693,7 +695,9 @@ void WebrtcTransport::OnAudioTransceiverCreated(
void WebrtcTransport::OnVideoTransceiverCreated( void WebrtcTransport::OnVideoTransceiverCreated(
rtc::scoped_refptr<webrtc::RtpTransceiverInterface> transceiver) { rtc::scoped_refptr<webrtc::RtpTransceiverInterface> transceiver) {
video_transceiver_ = transceiver; video_transceiver_ = transceiver;
SetSenderBitrates(MaxBitrateForConnection()); int min_bitrate_bps, max_bitrate_bps;
std::tie(min_bitrate_bps, max_bitrate_bps) = BitratesForConnection();
SetSenderBitrates(min_bitrate_bps, max_bitrate_bps);
} }
void WebrtcTransport::OnLocalSessionDescriptionCreated( void WebrtcTransport::OnLocalSessionDescriptionCreated(
...@@ -936,12 +940,13 @@ void WebrtcTransport::OnStatsDelivered( ...@@ -936,12 +940,13 @@ void WebrtcTransport::OnStatsDelivered(
// (~600kbps). // (~600kbps).
// Set the global bitrate caps in addition to the VideoSender bitrates. The // Set the global bitrate caps in addition to the VideoSender bitrates. The
// global caps affect the probing configuration used by b/w estimator. // global caps affect the probing configuration used by b/w estimator.
int max_bitrate_bps = MaxBitrateForConnection(); int min_bitrate_bps, max_bitrate_bps;
SetPeerConnectionBitrates(max_bitrate_bps); std::tie(min_bitrate_bps, max_bitrate_bps) = BitratesForConnection();
SetSenderBitrates(max_bitrate_bps); SetPeerConnectionBitrates(min_bitrate_bps, max_bitrate_bps);
SetSenderBitrates(min_bitrate_bps, max_bitrate_bps);
} }
int WebrtcTransport::MaxBitrateForConnection() { std::tuple<int, int> WebrtcTransport::BitratesForConnection() {
int max_bitrate_bps = kMaxBitrateBps; int max_bitrate_bps = kMaxBitrateBps;
if (connection_relayed_.value_or(false)) { if (connection_relayed_.value_or(false)) {
int turn_max_rate_kbps = transport_context_->GetTurnMaxRateKbps(); int turn_max_rate_kbps = transport_context_->GetTurnMaxRateKbps();
...@@ -955,16 +960,54 @@ int WebrtcTransport::MaxBitrateForConnection() { ...@@ -955,16 +960,54 @@ int WebrtcTransport::MaxBitrateForConnection() {
max_bitrate_bps = turn_max_rate_kbps * 1000; max_bitrate_bps = turn_max_rate_kbps * 1000;
} }
} }
return max_bitrate_bps;
base::Optional<int> max_bitrate_from_options =
session_options().GetInt("Max-Bitrate");
if (max_bitrate_from_options.has_value()) {
if (*max_bitrate_from_options >= 0 &&
*max_bitrate_from_options <= max_bitrate_bps) {
VLOG(0) << "Client sets max bitrate to " << *max_bitrate_from_options
<< " bps.";
max_bitrate_bps = *max_bitrate_from_options;
} else {
LOG(WARNING) << "Max bitrate setting " << *max_bitrate_from_options
<< " bps ignored since it's not in the range of "
<< "[0, " << max_bitrate_bps << "].";
}
}
int min_bitrate_bps = 0;
base::Optional<int> min_bitrate_from_options =
session_options().GetInt("Min-Bitrate");
if (min_bitrate_from_options.has_value()) {
if (min_bitrate_from_options >= 0 &&
min_bitrate_from_options <= max_bitrate_bps) {
VLOG(0) << "Client sets min bitrate to " << *min_bitrate_from_options
<< " bps.";
min_bitrate_bps = *min_bitrate_from_options;
} else {
LOG(WARNING) << "Min bitrate setting " << *min_bitrate_from_options
<< " bps ignored since it's not in the range of "
<< "[0, " << max_bitrate_bps << "].";
}
}
return {min_bitrate_bps, max_bitrate_bps};
} }
void WebrtcTransport::SetPeerConnectionBitrates(int max_bitrate_bps) { void WebrtcTransport::SetPeerConnectionBitrates(int min_bitrate_bps,
int max_bitrate_bps) {
DCHECK_LE(min_bitrate_bps, max_bitrate_bps);
webrtc::BitrateSettings bitrate; webrtc::BitrateSettings bitrate;
if (min_bitrate_bps > 0) {
bitrate.min_bitrate_bps = min_bitrate_bps;
}
bitrate.max_bitrate_bps = max_bitrate_bps; bitrate.max_bitrate_bps = max_bitrate_bps;
peer_connection()->SetBitrate(bitrate); peer_connection()->SetBitrate(bitrate);
} }
void WebrtcTransport::SetSenderBitrates(int max_bitrate_bps) { void WebrtcTransport::SetSenderBitrates(int min_bitrate_bps,
int max_bitrate_bps) {
DCHECK_LE(min_bitrate_bps, max_bitrate_bps);
// Only set the cap on the VideoSender, because the AudioSender (via the // Only set the cap on the VideoSender, because the AudioSender (via the
// Opus codec) is already configured with a lower bitrate. // Opus codec) is already configured with a lower bitrate.
rtc::scoped_refptr<webrtc::RtpSenderInterface> sender = GetVideoSender(); rtc::scoped_refptr<webrtc::RtpSenderInterface> sender = GetVideoSender();
...@@ -985,6 +1028,9 @@ void WebrtcTransport::SetSenderBitrates(int max_bitrate_bps) { ...@@ -985,6 +1028,9 @@ void WebrtcTransport::SetSenderBitrates(int max_bitrate_bps) {
<< sender->id(); << sender->id();
} }
if (min_bitrate_bps > 0) {
parameters.encodings[0].min_bitrate_bps = min_bitrate_bps;
}
parameters.encodings[0].max_bitrate_bps = max_bitrate_bps; parameters.encodings[0].max_bitrate_bps = max_bitrate_bps;
webrtc::RTCError result = sender->SetParameters(parameters); webrtc::RTCError result = sender->SetParameters(parameters);
DCHECK(result.ok()) << "SetParameters() failed: " << result.message(); DCHECK(result.ok()) << "SetParameters() failed: " << result.message();
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <tuple>
#include <vector> #include <vector>
#include "base/macros.h" #include "base/macros.h"
...@@ -152,19 +153,20 @@ class WebrtcTransport : public Transport, public SessionOptionsProvider { ...@@ -152,19 +153,20 @@ class WebrtcTransport : public Transport, public SessionOptionsProvider {
void OnStatsDelivered( void OnStatsDelivered(
const rtc::scoped_refptr<const webrtc::RTCStatsReport>& report); const rtc::scoped_refptr<const webrtc::RTCStatsReport>& report);
// Returns the max bitrate to set for this connection, taking into // Returns the min (first element) and max (second element) bitrate for this
// account any relay bitrate cap. If the relay status is unknown, this // connection, taking into account any relay bitrate cap and client overrides.
// returns the default maximum bitrate. // The default range is [0, default max bixrate]. Client overrides that go
int MaxBitrateForConnection(); // beyond this bound or exceed the relay server's max bitrate will be ignored.
std::tuple<int, int> BitratesForConnection();
// Sets bitrates on the PeerConnection. // Sets bitrates on the PeerConnection.
// Called after SetRemoteDescription(), but also called if the relay status // Called after SetRemoteDescription(), but also called if the relay status
// changes. // changes.
void SetPeerConnectionBitrates(int max_bitrate_bps); void SetPeerConnectionBitrates(int min_bitrate_bps, int max_bitrate_bps);
// Sets bitrates on the (video) sender. Called when the sender is created, but // Sets bitrates on the (video) sender. Called when the sender is created, but
// also called if the relay status changes. // also called if the relay status changes.
void SetSenderBitrates(int max_bitrate_bps); void SetSenderBitrates(int min_bitrate_bps, int max_bitrate_bps);
void RequestRtcStats(); void RequestRtcStats();
void RequestNegotiation(); void RequestNegotiation();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment