From b5aa0a85f31b415d9e5965814907ebd714a729e0 Mon Sep 17 00:00:00 2001 From: Jonas Oreland Date: Tue, 3 Dec 2019 09:59:11 +0100 Subject: [PATCH] Add IceControllerEvent::ICE_CONTROLLER_RECHECK This patch adds a new enum value in IceControllerEvent::Type, that allows an IceController to request a recheck without any of the predefined event occuring. This patch is a NOP for BasicIceController. BUG=webrtc:10647 Change-Id: Idf1d0946480437109ff272946679fef559ca7beb Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/161047 Reviewed-by: Harald Alvestrand Commit-Queue: Jonas Oreland Cr-Commit-Position: refs/heads/master@{#29976} --- p2p/base/basic_ice_controller.cc | 14 +++++++++----- p2p/base/ice_controller_interface.cc | 8 +++++--- p2p/base/ice_controller_interface.h | 12 ++++++++---- p2p/base/p2p_transport_channel.cc | 7 +++---- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/p2p/base/basic_ice_controller.cc b/p2p/base/basic_ice_controller.cc index 9877388cd8..09bc4f1f5f 100644 --- a/p2p/base/basic_ice_controller.cc +++ b/p2p/base/basic_ice_controller.cc @@ -462,7 +462,9 @@ BasicIceController::HandleInitialSelectDampening( } RTC_LOG(LS_INFO) << "delay initial selection up to " << min_delay << "ms"; - return {absl::nullopt, min_delay}; + reason.type = IceControllerEvent::ICE_CONTROLLER_RECHECK; + reason.recheck_delay_ms = min_delay; + return {absl::nullopt, reason}; } IceControllerInterface::SwitchResult BasicIceController::ShouldSwitchConnection( @@ -492,20 +494,22 @@ IceControllerInterface::SwitchResult BasicIceController::ShouldSwitchConnection( receiving_unchanged_threshold, &missed_receiving_unchanged_threshold); - absl::optional recheck_delay; + absl::optional recheck_event; if (missed_receiving_unchanged_threshold && config_.receiving_switching_delay_or_default()) { // If we do not switch to the connection because it missed the receiving // threshold, the new connection is in a better receiving state than the // currently selected connection. So we need to re-check whether it needs // to be switched at a later time. - recheck_delay = config_.receiving_switching_delay_or_default(); + recheck_event = reason; + recheck_event->recheck_delay_ms = + config_.receiving_switching_delay_or_default(); } if (cmp < 0) { return {new_connection, absl::nullopt}; } else if (cmp > 0) { - return {absl::nullopt, recheck_delay}; + return {absl::nullopt, recheck_event}; } // If everything else is the same, switch only if rtt has improved by @@ -514,7 +518,7 @@ IceControllerInterface::SwitchResult BasicIceController::ShouldSwitchConnection( return {new_connection, absl::nullopt}; } - return {absl::nullopt, recheck_delay}; + return {absl::nullopt, recheck_event}; } IceControllerInterface::SwitchResult diff --git a/p2p/base/ice_controller_interface.cc b/p2p/base/ice_controller_interface.cc index 6c930124aa..6d9bb85343 100644 --- a/p2p/base/ice_controller_interface.cc +++ b/p2p/base/ice_controller_interface.cc @@ -44,10 +44,12 @@ std::string IceControllerEvent::ToString() const { case SELECTED_CONNECTION_DESTROYED: reason = "selected candidate pair destroyed"; break; + case ICE_CONTROLLER_RECHECK: + reason = "ice-controller-request-recheck"; + break; } - if (dampening_delay) { - reason += " (after switching dampening interval: " + - std::to_string(dampening_delay) + ")"; + if (recheck_delay_ms) { + reason += " (after delay: " + std::to_string(recheck_delay_ms) + ")"; } return reason; } diff --git a/p2p/base/ice_controller_interface.h b/p2p/base/ice_controller_interface.h index 4f8dc7253a..43bb88471b 100644 --- a/p2p/base/ice_controller_interface.h +++ b/p2p/base/ice_controller_interface.h @@ -32,7 +32,11 @@ struct IceControllerEvent { NOMINATION_ON_CONTROLLED_SIDE, DATA_RECEIVED, CONNECT_STATE_CHANGE, - SELECTED_CONNECTION_DESTROYED + SELECTED_CONNECTION_DESTROYED, + // The ICE_CONTROLLER_RECHECK enum value lets an IceController request + // P2PTransportChannel to recheck a switch periodically without an event + // taking place. + ICE_CONTROLLER_RECHECK, }; IceControllerEvent(const Type& _type) // NOLINT: runtime/explicit @@ -40,7 +44,7 @@ struct IceControllerEvent { std::string ToString() const; Type type; - int dampening_delay = 0; + int recheck_delay_ms = 0; }; // Defines the interface for a module that control @@ -65,8 +69,8 @@ class IceControllerInterface { // Connection that we should (optionally) switch to. absl::optional connection; - // Delay in milliseconds when we should resort and try switching again. - absl::optional recheck_delay_ms; + // An optional recheck event for when a Switch() should be attempted again. + absl::optional recheck_event; }; virtual ~IceControllerInterface() = default; diff --git a/p2p/base/p2p_transport_channel.cc b/p2p/base/p2p_transport_channel.cc index 8d67690f80..c11a6b4efb 100644 --- a/p2p/base/p2p_transport_channel.cc +++ b/p2p/base/p2p_transport_channel.cc @@ -234,17 +234,16 @@ bool P2PTransportChannel::MaybeSwitchSelectedConnection( reason); } - if (result.recheck_delay_ms.has_value()) { + if (result.recheck_event.has_value()) { // If we do not switch to the connection because it missed the receiving // threshold, the new connection is in a better receiving state than the // currently selected connection. So we need to re-check whether it needs // to be switched at a later time. - reason.dampening_delay = *result.recheck_delay_ms; invoker_.AsyncInvokeDelayed( RTC_FROM_HERE, thread(), rtc::Bind(&P2PTransportChannel::SortConnectionsAndUpdateState, this, - reason), - reason.dampening_delay); + *result.recheck_event), + result.recheck_event->recheck_delay_ms); } return result.connection.has_value();