Replace sigslot usages with callback list library.

- Replace few sigslot usages in jsep_transport_controller.
- There is still one sigslot usages in this file so keeping the inheritance
and that is the reason for not having a binary size gain in this CL.
- Remaining sigslot will be removed in a separate CL.

Bug: webrtc:11943
Change-Id: Idb8fa1090b037c48eeb62f54cffd3c485cebfcda
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/190146
Reviewed-by: Andrey Logvin <landrey@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Lahiru Ginnaliya Gamathige <glahiru@webrtc.org>
Commit-Queue: Lahiru Ginnaliya Gamathige <glahiru@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33034}
This commit is contained in:
Lahiru Ginnaliya Gamathige 2021-01-18 23:32:22 -08:00 committed by Commit Bot
parent a722d2ac1e
commit 5eb527cf7f
5 changed files with 157 additions and 64 deletions

View File

@ -1154,7 +1154,8 @@ void JsepTransportController::OnTransportCandidateGathered_n(
std::string transport_name = transport->transport_name(); std::string transport_name = transport->transport_name();
invoker_.AsyncInvoke<void>( invoker_.AsyncInvoke<void>(
RTC_FROM_HERE, signaling_thread_, [this, transport_name, candidate] { RTC_FROM_HERE, signaling_thread_, [this, transport_name, candidate] {
SignalIceCandidatesGathered(transport_name, {candidate}); signal_ice_candidates_gathered_.Send(
transport_name, std::vector<cricket::Candidate>{candidate});
}); });
} }
@ -1163,20 +1164,21 @@ void JsepTransportController::OnTransportCandidateError_n(
const cricket::IceCandidateErrorEvent& event) { const cricket::IceCandidateErrorEvent& event) {
RTC_DCHECK(network_thread_->IsCurrent()); RTC_DCHECK(network_thread_->IsCurrent());
invoker_.AsyncInvoke<void>(RTC_FROM_HERE, signaling_thread_, invoker_.AsyncInvoke<void>(RTC_FROM_HERE, signaling_thread_, [this, event] {
[this, event] { SignalIceCandidateError(event); }); signal_ice_candidate_error_.Send(event);
});
} }
void JsepTransportController::OnTransportCandidatesRemoved_n( void JsepTransportController::OnTransportCandidatesRemoved_n(
cricket::IceTransportInternal* transport, cricket::IceTransportInternal* transport,
const cricket::Candidates& candidates) { const cricket::Candidates& candidates) {
invoker_.AsyncInvoke<void>( invoker_.AsyncInvoke<void>(
RTC_FROM_HERE, signaling_thread_, RTC_FROM_HERE, signaling_thread_,
[this, candidates] { SignalIceCandidatesRemoved(candidates); }); [this, candidates] { signal_ice_candidates_removed_.Send(candidates); });
} }
void JsepTransportController::OnTransportCandidatePairChanged_n( void JsepTransportController::OnTransportCandidatePairChanged_n(
const cricket::CandidatePairChangeEvent& event) { const cricket::CandidatePairChangeEvent& event) {
invoker_.AsyncInvoke<void>(RTC_FROM_HERE, signaling_thread_, [this, event] { invoker_.AsyncInvoke<void>(RTC_FROM_HERE, signaling_thread_, [this, event] {
SignalIceCandidatePairChanged(event); signal_ice_candidate_pair_changed_.Send(event);
}); });
} }
@ -1259,7 +1261,7 @@ void JsepTransportController::UpdateAggregateStates_n() {
invoker_.AsyncInvoke<void>( invoker_.AsyncInvoke<void>(
RTC_FROM_HERE, signaling_thread_, [this, new_connection_state] { RTC_FROM_HERE, signaling_thread_, [this, new_connection_state] {
SignalIceConnectionState.Send(new_connection_state); signal_ice_connection_state_.Send(new_connection_state);
}); });
} }
@ -1317,15 +1319,16 @@ void JsepTransportController::UpdateAggregateStates_n() {
PeerConnectionInterface::kIceConnectionCompleted) { PeerConnectionInterface::kIceConnectionCompleted) {
// Ensure that we never skip over the "connected" state. // Ensure that we never skip over the "connected" state.
invoker_.AsyncInvoke<void>(RTC_FROM_HERE, signaling_thread_, [this] { invoker_.AsyncInvoke<void>(RTC_FROM_HERE, signaling_thread_, [this] {
SignalStandardizedIceConnectionState( signal_standardized_ice_connection_state_.Send(
PeerConnectionInterface::kIceConnectionConnected); PeerConnectionInterface::kIceConnectionConnected);
}); });
} }
standardized_ice_connection_state_ = new_ice_connection_state; standardized_ice_connection_state_ = new_ice_connection_state;
invoker_.AsyncInvoke<void>( invoker_.AsyncInvoke<void>(RTC_FROM_HERE, signaling_thread_,
RTC_FROM_HERE, signaling_thread_, [this, new_ice_connection_state] { [this, new_ice_connection_state] {
SignalStandardizedIceConnectionState(new_ice_connection_state); signal_standardized_ice_connection_state_.Send(
}); new_ice_connection_state);
});
} }
// Compute the current RTCPeerConnectionState as described in // Compute the current RTCPeerConnectionState as described in
@ -1376,10 +1379,10 @@ void JsepTransportController::UpdateAggregateStates_n() {
if (combined_connection_state_ != new_combined_state) { if (combined_connection_state_ != new_combined_state) {
combined_connection_state_ = new_combined_state; combined_connection_state_ = new_combined_state;
invoker_.AsyncInvoke<void>(RTC_FROM_HERE, signaling_thread_, invoker_.AsyncInvoke<void>(
[this, new_combined_state] { RTC_FROM_HERE, signaling_thread_, [this, new_combined_state] {
SignalConnectionState(new_combined_state); signal_connection_state_.Send(new_combined_state);
}); });
} }
// Compute the gathering state. // Compute the gathering state.
@ -1392,10 +1395,10 @@ void JsepTransportController::UpdateAggregateStates_n() {
} }
if (ice_gathering_state_ != new_gathering_state) { if (ice_gathering_state_ != new_gathering_state) {
ice_gathering_state_ = new_gathering_state; ice_gathering_state_ = new_gathering_state;
invoker_.AsyncInvoke<void>(RTC_FROM_HERE, signaling_thread_, invoker_.AsyncInvoke<void>(
[this, new_gathering_state] { RTC_FROM_HERE, signaling_thread_, [this, new_gathering_state] {
SignalIceGatheringState(new_gathering_state); signal_ice_gathering_state_.Send(new_gathering_state);
}); });
} }
} }

View File

@ -192,41 +192,90 @@ class JsepTransportController : public sigslot::has_slots<> {
// and deletes unused transports, but doesn't consider anything more complex. // and deletes unused transports, but doesn't consider anything more complex.
void RollbackTransports(); void RollbackTransports();
// All of these signals are fired on the signaling thread. sigslot::signal1<rtc::SSLHandshakeError> SignalDtlsHandshakeError;
// F: void(const std::string&, const std::vector<cricket::Candidate>&)
template <typename F>
void SubscribeIceCandidateGathered(F&& callback) {
signal_ice_candidates_gathered_.AddReceiver(std::forward<F>(callback));
}
// F: void(cricket::IceConnectionState)
template <typename F>
void SubscribeIceConnectionState(F&& callback) {
signal_ice_connection_state_.AddReceiver(std::forward<F>(callback));
}
// F: void(PeerConnectionInterface::PeerConnectionState)
template <typename F>
void SubscribeConnectionState(F&& callback) {
signal_connection_state_.AddReceiver(std::forward<F>(callback));
}
// F: void(PeerConnectionInterface::IceConnectionState)
template <typename F>
void SubscribeStandardizedIceConnectionState(F&& callback) {
signal_standardized_ice_connection_state_.AddReceiver(
std::forward<F>(callback));
}
// F: void(cricket::IceGatheringState)
template <typename F>
void SubscribeIceGatheringState(F&& callback) {
signal_ice_gathering_state_.AddReceiver(std::forward<F>(callback));
}
// F: void(const cricket::IceCandidateErrorEvent&)
template <typename F>
void SubscribeIceCandidateError(F&& callback) {
signal_ice_candidate_error_.AddReceiver(std::forward<F>(callback));
}
// F: void(const std::vector<cricket::Candidate>&)
template <typename F>
void SubscribeIceCandidatesRemoved(F&& callback) {
signal_ice_candidates_removed_.AddReceiver(std::forward<F>(callback));
}
// F: void(const cricket::CandidatePairChangeEvent&)
template <typename F>
void SubscribeIceCandidatePairChanged(F&& callback) {
signal_ice_candidate_pair_changed_.AddReceiver(std::forward<F>(callback));
}
private:
// All of these callbacks are fired on the signaling thread.
// If any transport failed => failed, // If any transport failed => failed,
// Else if all completed => completed, // Else if all completed => completed,
// Else if all connected => connected, // Else if all connected => connected,
// Else => connecting // Else => connecting
CallbackList<cricket::IceConnectionState> SignalIceConnectionState; CallbackList<cricket::IceConnectionState> signal_ice_connection_state_;
sigslot::signal1<PeerConnectionInterface::PeerConnectionState> CallbackList<PeerConnectionInterface::PeerConnectionState>
SignalConnectionState; signal_connection_state_;
sigslot::signal1<PeerConnectionInterface::IceConnectionState> CallbackList<PeerConnectionInterface::IceConnectionState>
SignalStandardizedIceConnectionState; signal_standardized_ice_connection_state_;
// If all transports done gathering => complete, // If all transports done gathering => complete,
// Else if any are gathering => gathering, // Else if any are gathering => gathering,
// Else => new // Else => new
sigslot::signal1<cricket::IceGatheringState> SignalIceGatheringState; CallbackList<cricket::IceGatheringState> signal_ice_gathering_state_;
// (mid, candidates) // [mid, candidates]
sigslot::signal2<const std::string&, const std::vector<cricket::Candidate>&> CallbackList<const std::string&, const std::vector<cricket::Candidate>&>
SignalIceCandidatesGathered; signal_ice_candidates_gathered_;
sigslot::signal1<const cricket::IceCandidateErrorEvent&> CallbackList<const cricket::IceCandidateErrorEvent&>
SignalIceCandidateError; signal_ice_candidate_error_;
sigslot::signal1<const std::vector<cricket::Candidate>&> CallbackList<const std::vector<cricket::Candidate>&>
SignalIceCandidatesRemoved; signal_ice_candidates_removed_;
sigslot::signal1<const cricket::CandidatePairChangeEvent&> CallbackList<const cricket::CandidatePairChangeEvent&>
SignalIceCandidatePairChanged; signal_ice_candidate_pair_changed_;
sigslot::signal1<rtc::SSLHandshakeError> SignalDtlsHandshakeError;
private:
RTCError ApplyDescription_n(bool local, RTCError ApplyDescription_n(bool local,
SdpType type, SdpType type,
const cricket::SessionDescription* description) const cricket::SessionDescription* description)

View File

@ -89,18 +89,28 @@ class JsepTransportControllerTest : public JsepTransportController::Observer,
} }
void ConnectTransportControllerSignals() { void ConnectTransportControllerSignals() {
transport_controller_->SignalIceConnectionState.AddReceiver( transport_controller_->SubscribeIceConnectionState(
[this](cricket::IceConnectionState s) { [this](cricket::IceConnectionState s) {
JsepTransportControllerTest::OnConnectionState(s); JsepTransportControllerTest::OnConnectionState(s);
}); });
transport_controller_->SignalStandardizedIceConnectionState.connect( transport_controller_->SubscribeConnectionState(
this, &JsepTransportControllerTest::OnStandardizedIceConnectionState); [this](PeerConnectionInterface::PeerConnectionState s) {
transport_controller_->SignalConnectionState.connect( JsepTransportControllerTest::OnCombinedConnectionState(s);
this, &JsepTransportControllerTest::OnCombinedConnectionState); });
transport_controller_->SignalIceGatheringState.connect( transport_controller_->SubscribeStandardizedIceConnectionState(
this, &JsepTransportControllerTest::OnGatheringState); [this](PeerConnectionInterface::IceConnectionState s) {
transport_controller_->SignalIceCandidatesGathered.connect( JsepTransportControllerTest::OnStandardizedIceConnectionState(s);
this, &JsepTransportControllerTest::OnCandidatesGathered); });
transport_controller_->SubscribeIceGatheringState(
[this](cricket::IceGatheringState s) {
JsepTransportControllerTest::OnGatheringState(s);
});
transport_controller_->SubscribeIceCandidateGathered(
[this](const std::string& transport,
const std::vector<cricket::Candidate>& candidates) {
JsepTransportControllerTest::OnCandidatesGathered(transport,
candidates);
});
} }
std::unique_ptr<cricket::SessionDescription> std::unique_ptr<cricket::SessionDescription>

View File

@ -606,28 +606,55 @@ RTCError PeerConnection::Initialize(
transport_controller_.reset(new JsepTransportController( transport_controller_.reset(new JsepTransportController(
signaling_thread(), network_thread(), port_allocator_.get(), signaling_thread(), network_thread(), port_allocator_.get(),
async_resolver_factory_.get(), config)); async_resolver_factory_.get(), config));
transport_controller_->SignalStandardizedIceConnectionState.connect(
this, &PeerConnection::SetStandardizedIceConnectionState);
transport_controller_->SignalConnectionState.connect(
this, &PeerConnection::SetConnectionState);
transport_controller_->SignalIceGatheringState.connect(
this, &PeerConnection::OnTransportControllerGatheringState);
transport_controller_->SignalIceCandidatesGathered.connect(
this, &PeerConnection::OnTransportControllerCandidatesGathered);
transport_controller_->SignalIceCandidateError.connect(
this, &PeerConnection::OnTransportControllerCandidateError);
transport_controller_->SignalIceCandidatesRemoved.connect(
this, &PeerConnection::OnTransportControllerCandidatesRemoved);
transport_controller_->SignalDtlsHandshakeError.connect( transport_controller_->SignalDtlsHandshakeError.connect(
this, &PeerConnection::OnTransportControllerDtlsHandshakeError); this, &PeerConnection::OnTransportControllerDtlsHandshakeError);
transport_controller_->SignalIceCandidatePairChanged.connect(
this, &PeerConnection::OnTransportControllerCandidateChanged);
transport_controller_->SignalIceConnectionState.AddReceiver( // Following RTC_DCHECKs are added by looking at the caller thread.
// If this is incorrect there might not be test failures
// due to lack of unit tests which trigger these scenarios.
// TODO(bugs.webrtc.org/12160): Remove above comments.
transport_controller_->SubscribeIceConnectionState(
[this](cricket::IceConnectionState s) { [this](cricket::IceConnectionState s) {
RTC_DCHECK_RUN_ON(signaling_thread()); RTC_DCHECK_RUN_ON(signaling_thread());
OnTransportControllerConnectionState(s); OnTransportControllerConnectionState(s);
}); });
transport_controller_->SubscribeConnectionState(
[this](PeerConnectionInterface::PeerConnectionState s) {
RTC_DCHECK_RUN_ON(signaling_thread());
SetConnectionState(s);
});
transport_controller_->SubscribeStandardizedIceConnectionState(
[this](PeerConnectionInterface::IceConnectionState s) {
RTC_DCHECK_RUN_ON(signaling_thread());
SetStandardizedIceConnectionState(s);
});
transport_controller_->SubscribeIceGatheringState(
[this](cricket::IceGatheringState s) {
RTC_DCHECK_RUN_ON(signaling_thread());
OnTransportControllerGatheringState(s);
});
transport_controller_->SubscribeIceCandidateGathered(
[this](const std::string& transport,
const std::vector<cricket::Candidate>& candidates) {
RTC_DCHECK_RUN_ON(signaling_thread());
OnTransportControllerCandidatesGathered(transport, candidates);
});
transport_controller_->SubscribeIceCandidateError(
[this](const cricket::IceCandidateErrorEvent& event) {
RTC_DCHECK_RUN_ON(signaling_thread());
OnTransportControllerCandidateError(event);
});
transport_controller_->SubscribeIceCandidatesRemoved(
[this](const std::vector<cricket::Candidate>& c) {
RTC_DCHECK_RUN_ON(signaling_thread());
OnTransportControllerCandidatesRemoved(c);
});
transport_controller_->SubscribeIceCandidatePairChanged(
[this](const cricket::CandidatePairChangeEvent& event) {
RTC_DCHECK_RUN_ON(signaling_thread());
OnTransportControllerCandidateChanged(event);
});
configuration_ = configuration; configuration_ = configuration;

View File

@ -165,8 +165,12 @@ void ScenarioIceConnectionImpl::SetRemoteSdp(SdpType type,
const std::string& remote_sdp) { const std::string& remote_sdp) {
RTC_DCHECK_RUN_ON(signaling_thread_); RTC_DCHECK_RUN_ON(signaling_thread_);
remote_description_ = webrtc::CreateSessionDescription(type, remote_sdp); remote_description_ = webrtc::CreateSessionDescription(type, remote_sdp);
jsep_controller_->SignalIceCandidatesGathered.connect( jsep_controller_->SubscribeIceCandidateGathered(
this, &ScenarioIceConnectionImpl::OnCandidates); [this](const std::string& transport,
const std::vector<cricket::Candidate>& candidate) {
ScenarioIceConnectionImpl::OnCandidates(transport, candidate);
});
auto res = jsep_controller_->SetRemoteDescription( auto res = jsep_controller_->SetRemoteDescription(
remote_description_->GetType(), remote_description_->description()); remote_description_->GetType(), remote_description_->description());
RTC_CHECK(res.ok()) << res.message(); RTC_CHECK(res.ok()) << res.message();