Convert P2PTransportChannel Candidate Pair Change to CallbackList

Earlier attempts have shown that this signal is multiply listened to.

Bug: webrtc:11943
Change-Id: If9130a7f4c70714b5afda5aca0469b66c8e2612f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/347981
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42124}
This commit is contained in:
Harald Alvestrand 2024-04-19 14:57:33 +00:00 committed by WebRTC LUCI CQ
parent a28350ab05
commit dc43cb24bd
4 changed files with 14 additions and 14 deletions

View File

@ -338,11 +338,15 @@ class RTC_EXPORT IceTransportInternal : public rtc::PacketTransportInternal {
// SignalNetworkRouteChanged.
sigslot::signal2<IceTransportInternal*, const Candidate&> SignalRouteChange;
void SetCandidatePairChangeCallback(
void AddCandidatePairChangeCallback(
const void* removal_tag,
absl::AnyInvocable<void(const cricket::CandidatePairChangeEvent&)>
callback) {
RTC_DCHECK(!candidate_pair_change_callback_);
candidate_pair_change_callback_ = std::move(callback);
candidate_pair_change_callback_list_.AddReceiver(removal_tag,
std::move(callback));
}
void RemoveCandidatePairChangeCallback(const void* removal_tag) {
candidate_pair_change_callback_list_.RemoveReceivers(removal_tag);
}
// Invoked when there is conflict in the ICE role between local and remote
@ -385,7 +389,8 @@ class RTC_EXPORT IceTransportInternal : public rtc::PacketTransportInternal {
protected:
void SendGatheringStateEvent() { SignalGatheringState(this); }
webrtc::CallbackList<const cricket::CandidatePairChangeEvent&>
candidate_pair_change_callback_list_;
webrtc::CallbackList<IceTransportInternal*,
const StunDictionaryView&,
rtc::ArrayView<uint16_t>>
@ -401,9 +406,6 @@ class RTC_EXPORT IceTransportInternal : public rtc::PacketTransportInternal {
absl::AnyInvocable<void(IceTransportInternal*, const Candidates&)>
candidates_removed_callback_;
absl::AnyInvocable<void(const cricket::CandidatePairChangeEvent&)>
candidate_pair_change_callback_;
private:
// TODO(bugs.webrtc.org/11943): remove when removing Signal
void SignalGatheringStateFired(IceTransportInternal* transport) {

View File

@ -1838,9 +1838,7 @@ void P2PTransportChannel::SwitchSelectedConnectionInternal(
} else {
pair_change.estimated_disconnected_time_ms = 0;
}
if (candidate_pair_change_callback_) {
candidate_pair_change_callback_(pair_change);
}
candidate_pair_change_callback_list_.Send(pair_change);
}
++selected_candidate_pair_changes_;

View File

@ -3326,8 +3326,8 @@ class P2PTransportChannelPingTest : public ::testing::Test,
&P2PTransportChannelPingTest::OnReadyToSend);
ch->SignalStateChanged.connect(
this, &P2PTransportChannelPingTest::OnChannelStateChanged);
ch->SetCandidatePairChangeCallback(
[this](const cricket::CandidatePairChangeEvent& event) {
ch->AddCandidatePairChangeCallback(
this, [this](const cricket::CandidatePairChangeEvent& event) {
OnCandidatePairChanged(event);
});
}

View File

@ -464,8 +464,8 @@ JsepTransportController::CreateDtlsTransport(
this, &JsepTransportController::OnTransportStateChanged_n);
dtls->ice_transport()->SignalIceTransportStateChanged.connect(
this, &JsepTransportController::OnTransportStateChanged_n);
dtls->ice_transport()->SetCandidatePairChangeCallback(
[this](const cricket::CandidatePairChangeEvent& event) {
dtls->ice_transport()->AddCandidatePairChangeCallback(
this, [this](const cricket::CandidatePairChangeEvent& event) {
RTC_DCHECK_RUN_ON(network_thread_);
OnTransportCandidatePairChanged_n(event);
});