From d25828a0bfc30e4b6f8677437ccc392693977a72 Mon Sep 17 00:00:00 2001 From: Steve Anton Date: Fri, 31 Aug 2018 13:06:05 -0700 Subject: [PATCH] Use AsyncInvoker in JsepTransportController instead of MessageHandler Bug: webrtc:9702 Change-Id: I9171d6e7f16fe50be1c2b139bf7dd1d097000791 Reviewed-on: https://webrtc-review.googlesource.com/97181 Reviewed-by: Seth Hampson Commit-Queue: Steve Anton Cr-Commit-Position: refs/heads/master@{#24516} --- pc/jseptransportcontroller.cc | 81 ++++++----------------------------- pc/jseptransportcontroller.h | 6 +-- 2 files changed, 15 insertions(+), 72 deletions(-) diff --git a/pc/jseptransportcontroller.cc b/pc/jseptransportcontroller.cc index 1375ab0e59..4c69a6a07e 100644 --- a/pc/jseptransportcontroller.cc +++ b/pc/jseptransportcontroller.cc @@ -24,21 +24,6 @@ using webrtc::SdpType; namespace { -enum { - MSG_ICECONNECTIONSTATE, - MSG_ICEGATHERINGSTATE, - MSG_ICECANDIDATESGATHERED, -}; - -struct CandidatesData : public rtc::MessageData { - CandidatesData(const std::string& transport_name, - const cricket::Candidates& candidates) - : transport_name(transport_name), candidates(candidates) {} - - std::string transport_name; - cricket::Candidates candidates; -}; - webrtc::RTCError VerifyCandidate(const cricket::Candidate& cand) { // No address zero. if (cand.address().IsNil() || cand.address().IsAnyIP()) { @@ -507,37 +492,6 @@ JsepTransportController::GetDtlsTransports() { return dtls_transports; } -void JsepTransportController::OnMessage(rtc::Message* pmsg) { - RTC_DCHECK(signaling_thread_->IsCurrent()); - - switch (pmsg->message_id) { - case MSG_ICECONNECTIONSTATE: { - rtc::TypedMessageData* data = - static_cast*>( - pmsg->pdata); - SignalIceConnectionState(data->data()); - delete data; - break; - } - case MSG_ICEGATHERINGSTATE: { - rtc::TypedMessageData* data = - static_cast*>( - pmsg->pdata); - SignalIceGatheringState(data->data()); - delete data; - break; - } - case MSG_ICECANDIDATESGATHERED: { - CandidatesData* data = static_cast(pmsg->pdata); - SignalIceCandidatesGathered(data->transport_name, data->candidates); - delete data; - break; - } - default: - RTC_NOTREACHED(); - } -} - RTCError JsepTransportController::ApplyDescription_n( bool local, SdpType type, @@ -1121,11 +1075,11 @@ void JsepTransportController::OnTransportCandidateGathered_n( RTC_NOTREACHED(); return; } - std::vector candidates; - candidates.push_back(candidate); - CandidatesData* data = - new CandidatesData(transport->transport_name(), candidates); - signaling_thread_->Post(RTC_FROM_HERE, this, MSG_ICECANDIDATESGATHERED, data); + std::string transport_name = transport->transport_name(); + invoker_.AsyncInvoke( + RTC_FROM_HERE, signaling_thread_, [this, transport_name, candidate] { + SignalIceCandidatesGathered(transport_name, {candidate}); + }); } void JsepTransportController::OnTransportCandidatesRemoved_n( @@ -1133,14 +1087,7 @@ void JsepTransportController::OnTransportCandidatesRemoved_n( const cricket::Candidates& candidates) { invoker_.AsyncInvoke( RTC_FROM_HERE, signaling_thread_, - rtc::Bind(&JsepTransportController::OnTransportCandidatesRemoved, this, - candidates)); -} - -void JsepTransportController::OnTransportCandidatesRemoved( - const cricket::Candidates& candidates) { - RTC_DCHECK(signaling_thread_->IsCurrent()); - SignalIceCandidatesRemoved(candidates); + [this, candidates] { SignalIceCandidatesRemoved(candidates); }); } void JsepTransportController::OnTransportRoleConflict_n( @@ -1207,10 +1154,10 @@ void JsepTransportController::UpdateAggregateStates_n() { } if (ice_connection_state_ != new_connection_state) { ice_connection_state_ = new_connection_state; - signaling_thread_->Post( - RTC_FROM_HERE, this, MSG_ICECONNECTIONSTATE, - new rtc::TypedMessageData( - new_connection_state)); + invoker_.AsyncInvoke(RTC_FROM_HERE, signaling_thread_, + [this, new_connection_state] { + SignalIceConnectionState(new_connection_state); + }); } if (all_done_gathering) { @@ -1220,10 +1167,10 @@ void JsepTransportController::UpdateAggregateStates_n() { } if (ice_gathering_state_ != new_gathering_state) { ice_gathering_state_ = new_gathering_state; - signaling_thread_->Post( - RTC_FROM_HERE, this, MSG_ICEGATHERINGSTATE, - new rtc::TypedMessageData( - new_gathering_state)); + invoker_.AsyncInvoke(RTC_FROM_HERE, signaling_thread_, + [this, new_gathering_state] { + SignalIceGatheringState(new_gathering_state); + }); } } diff --git a/pc/jseptransportcontroller.h b/pc/jseptransportcontroller.h index c8effd746b..d9340cf357 100644 --- a/pc/jseptransportcontroller.h +++ b/pc/jseptransportcontroller.h @@ -42,8 +42,7 @@ class PacketTransportInternal; namespace webrtc { -class JsepTransportController : public sigslot::has_slots<>, - public rtc::MessageHandler { +class JsepTransportController : public sigslot::has_slots<> { public: // Used when the RtpTransport/DtlsTransport of the m= section is changed // because the section is rejected or BUNDLE is enabled. @@ -181,8 +180,6 @@ class JsepTransportController : public sigslot::has_slots<>, sigslot::signal1 SignalDtlsHandshakeError; private: - void OnMessage(rtc::Message* pmsg) override; - RTCError ApplyDescription_n(bool local, SdpType type, const cricket::SessionDescription* description); @@ -284,7 +281,6 @@ class JsepTransportController : public sigslot::has_slots<>, void OnTransportGatheringState_n(cricket::IceTransportInternal* transport); void OnTransportCandidateGathered_n(cricket::IceTransportInternal* transport, const cricket::Candidate& candidate); - void OnTransportCandidatesRemoved(const cricket::Candidates& candidates); void OnTransportCandidatesRemoved_n(cricket::IceTransportInternal* transport, const cricket::Candidates& candidates); void OnTransportRoleConflict_n(cricket::IceTransportInternal* transport);