收集Candidate的时机
收集Candidate的代码调用过程
JsepTransportController::MaybeStartGathering
h:\webrtc-20210315\webrtc-20210315\webrtc\webrtc-checkout\src\pc\jsep_transport_controller.cc
JsepTransportController::GetDtlsTransport
jseptransport_by_name一般只有一项,因为rtp和rtcp都是复用同一个端口。
jseptransport_by_name
启动AllocationSequence
AllocationSequence::Start
在AllocationSequence::OnMessage中判断收到MSG_ALLOCATION_PHASE消息。
AllocationSequence::OnMessage
void AllocationSequence::OnMessage(rtc::Message* msg) {
RTC_DCHECK(rtc::Thread::Current() == session_->network_thread());
RTC_DCHECK(msg->message_id == MSG_ALLOCATION_PHASE);
const char* const PHASE_NAMES[kNumPhases] = {"Udp", "Relay", "Tcp"};
// Perform all of the phases in the current step.
RTC_LOG(LS_INFO) << network_->ToString()
<< ": Allocation Phase=" << PHASE_NAMES[phase_];
switch (phase_) {
case PHASE_UDP:
CreateUDPPorts();
CreateStunPorts();
break;
case PHASE_RELAY:
CreateRelayPorts();
break;
case PHASE_TCP:
CreateTCPPorts();
state_ = kCompleted;
break;
default:
RTC_NOTREACHED();
}
if (state() == kRunning) {
++phase_;
session_->network_thread()->PostDelayed(RTC_FROM_HERE,
session_->allocator()->step_delay(),
this, MSG_ALLOCATION_PHASE);
} else {
// 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);
}
}
刚开始会收到PHASE_UDP,后面会收到PHASE_RELAY消息。