image.png

收集Candidate的时机

image.png

收集Candidate的代码调用过程

image.png

JsepTransportController::MaybeStartGathering

h:\webrtc-20210315\webrtc-20210315\webrtc\webrtc-checkout\src\pc\jsep_transport_controller.cc
image.png

JsepTransportController::GetDtlsTransport

image.png
jseptransport_by_name一般只有一项,因为rtp和rtcp都是复用同一个端口。

jseptransport_by_name

image.png

启动AllocationSequence

image.png

AllocationSequence::Start

image.png
在AllocationSequence::OnMessage中判断收到MSG_ALLOCATION_PHASE消息。

AllocationSequence::OnMessage

image.png

  1. void AllocationSequence::OnMessage(rtc::Message* msg) {
  2. RTC_DCHECK(rtc::Thread::Current() == session_->network_thread());
  3. RTC_DCHECK(msg->message_id == MSG_ALLOCATION_PHASE);
  4. const char* const PHASE_NAMES[kNumPhases] = {"Udp", "Relay", "Tcp"};
  5. // Perform all of the phases in the current step.
  6. RTC_LOG(LS_INFO) << network_->ToString()
  7. << ": Allocation Phase=" << PHASE_NAMES[phase_];
  8. switch (phase_) {
  9. case PHASE_UDP:
  10. CreateUDPPorts();
  11. CreateStunPorts();
  12. break;
  13. case PHASE_RELAY:
  14. CreateRelayPorts();
  15. break;
  16. case PHASE_TCP:
  17. CreateTCPPorts();
  18. state_ = kCompleted;
  19. break;
  20. default:
  21. RTC_NOTREACHED();
  22. }
  23. if (state() == kRunning) {
  24. ++phase_;
  25. session_->network_thread()->PostDelayed(RTC_FROM_HERE,
  26. session_->allocator()->step_delay(),
  27. this, MSG_ALLOCATION_PHASE);
  28. } else {
  29. // If all phases in AllocationSequence are completed, no allocation
  30. // steps needed further. Canceling pending signal.
  31. session_->network_thread()->Clear(this, MSG_ALLOCATION_PHASE);
  32. SignalPortAllocationComplete(this);
  33. }
  34. }

刚开始会收到PHASE_UDP,后面会收到PHASE_RELAY消息。

小结

image.png