Index: webrtc/call/call.cc |
diff --git a/webrtc/call/call.cc b/webrtc/call/call.cc |
index e9838d9baad0acdadde8f33ddc12bb863068cc92..d82f0c16601dd4fa305418a203865c789089c5d8 100644 |
--- a/webrtc/call/call.cc |
+++ b/webrtc/call/call.cc |
@@ -180,6 +180,9 @@ class Call : public webrtc::Call, |
void SetBitrateConfig( |
const webrtc::Call::Config::BitrateConfig& bitrate_config) override; |
+ RTCError SetBitrateConfigMask( |
+ const webrtc::Call::Config::BitrateConfigMask& bitrate_config) override; |
+ |
void SignalChannelNetworkState(MediaType media, NetworkState state) override; |
void OnTransportOverheadChanged(MediaType media, |
@@ -225,6 +228,15 @@ class Call : public webrtc::Call, |
void UpdateHistograms(); |
void UpdateAggregateNetworkState(); |
+ // Updates the BitrateConfig cached in |config_| by combining |
+ // |base_bitrate_config_| and |bitrate_config_mask_| and updates the |
+ // congestion controller if the combined config changed or if |
+ // |force_update| is true. |
+ RTCError UpdateCurrentBitrateConfig(bool force_update); |
+ |
+ // UpdateCurrentBitrateConfig, but doesn't verify BitrateConfig invariants. |
+ void UpdateCurrentBitrateConfigUnchecked(); |
+ |
Clock* const clock_; |
const int num_cpu_cores_; |
@@ -321,6 +333,14 @@ class Call : public webrtc::Call, |
// and deleted before any other members. |
rtc::TaskQueue worker_queue_; |
+ // The config mask set by SetBitrateConfigMask. |
+ // 0 <= min <= start <= max |
+ Config::BitrateConfigMask bitrate_config_mask_; |
+ |
+ // The config set by SetBitrateConfig. |
+ // min >= 0, start != 0, max == -1 || max > 0 |
+ Config::BitrateConfig base_bitrate_config_; |
+ |
RTC_DISALLOW_COPY_AND_ASSIGN(Call); |
}; |
} // namespace internal |
@@ -374,7 +394,8 @@ Call::Call(const Call::Config& config, |
receive_side_cc_(clock_, &remb_, transport_send_->packet_router()), |
video_send_delay_stats_(new SendDelayStats(clock_)), |
start_ms_(clock_->TimeInMilliseconds()), |
- worker_queue_("call_worker_queue") { |
+ worker_queue_("call_worker_queue"), |
+ base_bitrate_config_(config.bitrate_config) { |
RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
RTC_DCHECK(config.event_log != nullptr); |
RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); |
@@ -897,29 +918,120 @@ void Call::SetBitrateConfig( |
const webrtc::Call::Config::BitrateConfig& bitrate_config) { |
TRACE_EVENT0("webrtc", "Call::SetBitrateConfig"); |
RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
+ |
RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0); |
- if (bitrate_config.max_bitrate_bps != -1) |
+ RTC_DCHECK_NE(bitrate_config.start_bitrate_bps, 0); |
+ if (bitrate_config.max_bitrate_bps != -1) { |
RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0); |
- if (config_.bitrate_config.min_bitrate_bps == |
- bitrate_config.min_bitrate_bps && |
- (bitrate_config.start_bitrate_bps <= 0 || |
- config_.bitrate_config.start_bitrate_bps == |
- bitrate_config.start_bitrate_bps) && |
- config_.bitrate_config.max_bitrate_bps == |
- bitrate_config.max_bitrate_bps) { |
+ } |
+ |
+ const bool same_min = |
+ base_bitrate_config_.min_bitrate_bps == bitrate_config.min_bitrate_bps; |
+ const bool same_start = base_bitrate_config_.start_bitrate_bps == |
+ bitrate_config.start_bitrate_bps; |
+ const bool same_max = |
+ base_bitrate_config_.max_bitrate_bps == bitrate_config.max_bitrate_bps; |
+ if (same_min && (bitrate_config.start_bitrate_bps <= 0 || same_start) && |
+ same_max) { |
Zach Stein
2017/04/20 20:48:01
(bitrate_config.max_bitrate_bps == -1 || same_max)
|
// Nothing new to set, early abort to avoid encoder reconfigurations. |
return; |
} |
- config_.bitrate_config.min_bitrate_bps = bitrate_config.min_bitrate_bps; |
+ |
+ base_bitrate_config_.min_bitrate_bps = bitrate_config.min_bitrate_bps; |
// Start bitrate of -1 means we should keep the old bitrate, which there is |
// no point in remembering for the future. |
- if (bitrate_config.start_bitrate_bps > 0) |
- config_.bitrate_config.start_bitrate_bps = bitrate_config.start_bitrate_bps; |
- config_.bitrate_config.max_bitrate_bps = bitrate_config.max_bitrate_bps; |
- RTC_DCHECK_NE(bitrate_config.start_bitrate_bps, 0); |
+ if (bitrate_config.start_bitrate_bps > 0) { |
+ base_bitrate_config_.start_bitrate_bps = bitrate_config.start_bitrate_bps; |
+ } |
+ base_bitrate_config_.max_bitrate_bps = bitrate_config.max_bitrate_bps; |
+ |
+ UpdateCurrentBitrateConfigUnchecked(); |
+} |
+ |
+RTCError Call::SetBitrateConfigMask( |
+ const webrtc::Call::Config::BitrateConfigMask& mask) { |
+ TRACE_EVENT0("webrtc", "Call::SetBitrateConfigMask"); |
+ RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
+ |
+ bitrate_config_mask_ = mask; |
+ |
+ const bool force_update = static_cast<bool>(mask.start_bitrate_bps); |
+ |
+ return UpdateCurrentBitrateConfig(force_update); |
+} |
+ |
+Call::Config::BitrateConfig ComputeMasked( |
+ const Call::Config::BitrateConfig& base, |
+ const Call::Config::BitrateConfigMask& mask) { |
+ Call::Config::BitrateConfig masked; |
+ masked.min_bitrate_bps = mask.min_bitrate_bps.value_or(base.min_bitrate_bps); |
+ masked.start_bitrate_bps = |
+ mask.start_bitrate_bps.value_or(base.start_bitrate_bps); |
+ |
+ const rtc::Optional<int>& mask_max = mask.max_bitrate_bps; |
+ const int base_max = base.max_bitrate_bps; |
+ const bool mask_has_max = static_cast<bool>(mask_max); |
+ const bool base_has_max = base_max != -1; |
+ if (mask_has_max && base_has_max) { |
+ masked.max_bitrate_bps = std::min(*mask_max, base_max); |
+ } else if (mask_has_max) { |
+ masked.max_bitrate_bps = *mask_max; |
+ } else if (base_has_max) { |
+ masked.max_bitrate_bps = base_max; |
+ } else { |
+ masked.max_bitrate_bps = -1; |
+ } |
+ |
+ return masked; |
+} |
+ |
+void Call::UpdateCurrentBitrateConfigUnchecked() { |
+ Config::BitrateConfig masked = |
+ ComputeMasked(base_bitrate_config_, bitrate_config_mask_); |
+ |
+ // We only get here if SetBitrateConfig changed something. |
+ |
+ config_.bitrate_config = masked; |
transport_send_->send_side_cc()->SetBweBitrates( |
- bitrate_config.min_bitrate_bps, bitrate_config.start_bitrate_bps, |
- bitrate_config.max_bitrate_bps); |
+ masked.min_bitrate_bps, masked.start_bitrate_bps, masked.max_bitrate_bps); |
+} |
+ |
+RTCError Call::UpdateCurrentBitrateConfig(bool force_update) { |
Zach Stein
2017/04/20 20:48:00
Looking in to adding Call tests next.
|
+ Config::BitrateConfig masked = |
+ ComputeMasked(base_bitrate_config_, bitrate_config_mask_); |
+ |
+ Config::BitrateConfig& current = config_.bitrate_config; |
+ if (!force_update && masked.min_bitrate_bps == current.min_bitrate_bps && |
+ masked.start_bitrate_bps == current.start_bitrate_bps && |
+ masked.max_bitrate_bps == current.max_bitrate_bps) { |
+ return RTCError::OK(); |
+ } |
+ |
+ RTC_DCHECK_GE(masked.min_bitrate_bps, 0); |
+ if (masked.start_bitrate_bps > 0 && |
+ masked.start_bitrate_bps < masked.min_bitrate_bps) { |
+ LOG_AND_RETURN_ERROR( |
+ RTCErrorType::INVALID_STATE, |
+ "effective start_bitrate_bps < effective min_bitrate_bps"); |
+ } |
+ if (masked.max_bitrate_bps != -1 && masked.start_bitrate_bps > 0 && |
+ masked.max_bitrate_bps < masked.start_bitrate_bps) { |
+ LOG_AND_RETURN_ERROR( |
+ RTCErrorType::INVALID_STATE, |
+ "effective max_bitrate_bps < effective start_bitrate_bps"); |
+ } |
+ if (masked.max_bitrate_bps != -1 && |
+ masked.max_bitrate_bps < masked.min_bitrate_bps) { |
+ LOG_AND_RETURN_ERROR( |
+ RTCErrorType::INVALID_STATE, |
+ "effective max_bitrate_bps < effective min_bitrate_bps"); |
+ } |
+ |
+ current = masked; |
+ transport_send_->send_side_cc()->SetBweBitrates(current.min_bitrate_bps, |
+ current.start_bitrate_bps, |
+ current.max_bitrate_bps); |
+ return RTCError::OK(); |
} |
void Call::SignalChannelNetworkState(MediaType media, NetworkState state) { |