AllocationSequence: switch signal to callback.
Bug: webrtc:12840 Change-Id: Ic25ceb9a487b28575ab7530c54b13781ed404f7a Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/221367 Commit-Queue: Markus Handell <handellm@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/master@{#34240}
This commit is contained in:
parent
fd89fc75cc
commit
dedcdfeba3
@ -809,9 +809,11 @@ void BasicPortAllocatorSession::DoAllocate(bool disable_equivalent) {
|
||||
}
|
||||
|
||||
AllocationSequence* sequence =
|
||||
new AllocationSequence(this, networks[i], config, sequence_flags);
|
||||
sequence->SignalPortAllocationComplete.connect(
|
||||
this, &BasicPortAllocatorSession::OnPortAllocationComplete);
|
||||
new AllocationSequence(this, networks[i], config, sequence_flags,
|
||||
[this, safety_flag = network_safety_.flag()] {
|
||||
if (safety_flag->alive())
|
||||
OnPortAllocationComplete();
|
||||
});
|
||||
sequence->Init();
|
||||
sequence->Start();
|
||||
sequences_.push_back(sequence);
|
||||
@ -1124,8 +1126,7 @@ bool BasicPortAllocatorSession::CandidatePairable(const Candidate& c,
|
||||
!host_candidates_disabled);
|
||||
}
|
||||
|
||||
void BasicPortAllocatorSession::OnPortAllocationComplete(
|
||||
AllocationSequence* seq) {
|
||||
void BasicPortAllocatorSession::OnPortAllocationComplete() {
|
||||
RTC_DCHECK_RUN_ON(network_thread_);
|
||||
// Send candidate allocation complete signal if all ports are done.
|
||||
MaybeSignalCandidatesAllocationDone();
|
||||
@ -1216,10 +1217,12 @@ void BasicPortAllocatorSession::PrunePortsAndRemoveCandidates(
|
||||
|
||||
// AllocationSequence
|
||||
|
||||
AllocationSequence::AllocationSequence(BasicPortAllocatorSession* session,
|
||||
rtc::Network* network,
|
||||
PortConfiguration* config,
|
||||
uint32_t flags)
|
||||
AllocationSequence::AllocationSequence(
|
||||
BasicPortAllocatorSession* session,
|
||||
rtc::Network* network,
|
||||
PortConfiguration* config,
|
||||
uint32_t flags,
|
||||
std::function<void()> port_allocation_complete_callback)
|
||||
: session_(session),
|
||||
network_(network),
|
||||
config_(config),
|
||||
@ -1227,7 +1230,9 @@ AllocationSequence::AllocationSequence(BasicPortAllocatorSession* session,
|
||||
flags_(flags),
|
||||
udp_socket_(),
|
||||
udp_port_(NULL),
|
||||
phase_(0) {}
|
||||
phase_(0),
|
||||
port_allocation_complete_callback_(
|
||||
std::move(port_allocation_complete_callback)) {}
|
||||
|
||||
void AllocationSequence::Init() {
|
||||
if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET)) {
|
||||
@ -1386,7 +1391,7 @@ void AllocationSequence::OnMessage(rtc::Message* msg) {
|
||||
// If all phases in AllocationSequence are completed, no allocation
|
||||
// steps needed further. Canceling pending signal.
|
||||
session_->network_thread()->Clear(this, MSG_ALLOCATION_PHASE);
|
||||
SignalPortAllocationComplete(this);
|
||||
port_allocation_complete_callback_();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -237,7 +237,7 @@ class RTC_EXPORT BasicPortAllocatorSession : public PortAllocatorSession {
|
||||
void OnProtocolEnabled(AllocationSequence* seq, ProtocolType proto);
|
||||
void OnPortDestroyed(PortInterface* port);
|
||||
void MaybeSignalCandidatesAllocationDone();
|
||||
void OnPortAllocationComplete(AllocationSequence* seq);
|
||||
void OnPortAllocationComplete();
|
||||
PortData* FindPort(Port* port);
|
||||
std::vector<rtc::Network*> GetNetworks();
|
||||
std::vector<rtc::Network*> GetFailedNetworks();
|
||||
@ -338,10 +338,18 @@ class AllocationSequence : public rtc::MessageHandler,
|
||||
|
||||
// kInit --> kRunning --> {kCompleted|kStopped}
|
||||
};
|
||||
// |port_allocation_complete_callback| is called when AllocationSequence is
|
||||
// done with allocating ports. This signal is useful when port allocation
|
||||
// fails which doesn't result in any candidates. Using this signal
|
||||
// BasicPortAllocatorSession can send its candidate discovery conclusion
|
||||
// signal. Without this signal, BasicPortAllocatorSession doesn't have any
|
||||
// event to trigger signal. This can also be achieved by starting a timer in
|
||||
// BPAS, but this is less deterministic.
|
||||
AllocationSequence(BasicPortAllocatorSession* session,
|
||||
rtc::Network* network,
|
||||
PortConfiguration* config,
|
||||
uint32_t flags);
|
||||
uint32_t flags,
|
||||
std::function<void()> port_allocation_complete_callback);
|
||||
~AllocationSequence() override;
|
||||
void Init();
|
||||
void Clear();
|
||||
@ -367,14 +375,6 @@ class AllocationSequence : public rtc::MessageHandler,
|
||||
// MessageHandler
|
||||
void OnMessage(rtc::Message* msg) override;
|
||||
|
||||
// Signal from AllocationSequence, when it's done with allocating ports.
|
||||
// This signal is useful, when port allocation fails which doesn't result
|
||||
// in any candidates. Using this signal BasicPortAllocatorSession can send
|
||||
// its candidate discovery conclusion signal. Without this signal,
|
||||
// BasicPortAllocatorSession doesn't have any event to trigger signal. This
|
||||
// can also be achieved by starting timer in BPAS.
|
||||
sigslot::signal1<AllocationSequence*> SignalPortAllocationComplete;
|
||||
|
||||
protected:
|
||||
// For testing.
|
||||
void CreateTurnPort(const RelayServerConfig& config);
|
||||
@ -410,6 +410,7 @@ class AllocationSequence : public rtc::MessageHandler,
|
||||
UDPPort* udp_port_;
|
||||
std::vector<Port*> relay_ports_;
|
||||
int phase_;
|
||||
std::function<void()> port_allocation_complete_callback_;
|
||||
};
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user