WebRTC的Pacing

一  类图

WebRTC的Pacing_第1张图片

二 主要函数

作用:匀速发送数据,主要是视频。I帧和P帧的大小不一样,I帧拆分的RTP包多些,匀速发送。

void PacingController::EnqueuePacket(std::unique_ptr packet) {
  //优先级: audio最高, 重发的包, video, padding.
  const int priority = GetPriorityForType(*packet->packet_type());
  EnqueuePacketInternal(std::move(packet), priority);
}


void PacedSender::Process() {
  MutexLock lock(&mutex_);
  pacing_controller_.ProcessPackets();
}

//有周期和动态两种方式, 默认周期kPeriodic.
//constexpr TimeDelta kDefaultMinPacketLimit = TimeDelta::Millis(5);
void PacingController::ProcessPackets() {

...

// Fetch the next packet, so long as queue is not empty or budget is not
// exhausted.
1   std::unique_ptr rtp_packet =
    GetPendingPacket(pacing_info, target_send_time, now);
    if (rtp_packet == nullptr) {
      // No packet available to send, check if we should send padding.
      ...
    }

2 packet_sender_->SendPacket(std::move(rtp_packet), pacing_info);

}

void PacketRouter::SendPacket(std::unique_ptr packet,
                              const PacedPacketInfo& cluster_info) {

 ...
 if (packet->HasExtension()) {
    packet->SetExtension((++transport_seq_) & 0xFFFF);
  }

  ...
  ModuleRtpRtcpImpl2::TrySendPacket(...)
}

IntervalBudget media_budget_; //限制发送的带宽
IntervalBudget padding_budget_;

你可能感兴趣的:(webrtc,webrtc)