webrtc 代码学习(三十二) video RTT 作用笔记

video RTT 作用笔记
作者:LanPZzzz

文章目录

          • 1. RTT 下发 video\call_stats.cc 120,通过线程
          • 2. RTT 下发,作用,发送给各个ObServer 用于各自的计算
          • 3. CallStats 中的 report 是从 CallStats::OnRttUpdate
          • 4. rtt 是 SR 和 RR 计算出来的,LSR,DLSR,看 三十章

1. RTT 下发 video\call_stats.cc 120,通过线程
void CallStats::Process() {
  RTC_DCHECK_RUN_ON(&process_thread_checker_);
  int64_t now = clock_->TimeInMilliseconds();
  last_process_time_ = now;

  int64_t avg_rtt_ms = avg_rtt_ms_;
  RemoveOldReports(now, &reports_);
  获取
  max_rtt_ms_ = GetMaxRttMs(reports_);
  avg_rtt_ms = GetNewAvgRttMs(reports_, avg_rtt_ms);
  {
    rtc::CritScope lock(&avg_rtt_ms_lock_);
    avg_rtt_ms_ = avg_rtt_ms;
  }

  // If there is a valid rtt, update all observers with the max rtt.
  if (max_rtt_ms_ >= 0) {
    RTC_DCHECK_GE(avg_rtt_ms, 0);
    下发
    for (CallStatsObserver* observer : observers_)
      observer->OnRttUpdate(avg_rtt_ms, max_rtt_ms_);
    // Sum for Histogram of average RTT reported over the entire call.
    sum_avg_rtt_ms_ += avg_rtt_ms;
    ++num_avg_rtt_;
  }
}
2. RTT 下发,作用,发送给各个ObServer 用于各自的计算

for (CallStatsObserver* observer : observers_)
observer->OnRttUpdate(avg_rtt_ms, max_rtt_ms_);

-> OnRttUpdate 下的3个observer
-> VideoReceiveStream::OnRttUpdate (\video\video_receive_stream.cc 360)
-> FrameBuffer::UpdateRtt (modules\video_coding\frame_buffer2.cc 265)
-> VCMJitterEstimator::UpdateRtt (\modules\video_coding\jitter_estimator.cc 375)
-> VCMRttFilter::Update (modules\video_coding\rtt_filter.cc 56) 设置 jitter buffer rtt
->RtpVideoStreamReceiver::UpdateRtt (\video\rtp_video_stream_receiver.cc 350) === 因为 ModuleRtpRtcpImpl::Process 中 rtt_stats_ 在 audio 和 video 是同一个,所以在update时候,是不区分audio 和 video 的,都是同一个rtt
-> NackModule::UpdateRtt (\modules\video_coding\nack_module.cc 124) video 的nack 使用,重传时候
-> VideoStreamDecoder::UpdateRtt (video\video_stream_decoder.cc 127)
-> VideoReceiver::SetReceiveChannelParameters (modules\video_coding\video_receiver.cc 137)
-> VCMReceiver::UpdateRtt (\modules\video_coding\receiver.cc 100)
-> VCMJitterBuffer::UpdateRtt (modules\video_coding\jitter_buffer.cc 895)
-> VCMJitterEstimator::UpdateRtt (modules\video_coding\jitter_estimator.cc 375)
-> VCMRttFilter::Update (modules\video_coding\rtt_filter.cc 56)

-> SendSideCongestionController::OnRttUpdate (modules\congestion_controller\send_side_congestion_controller.cc 348)
    -> DelayBasedBwe::OnRttUpdate (\modules\congestion_controller\goog_cc\delay_based_bwe.cc 293)
        -> AimdRateControl::SetRtt (modules\remote_bitrate_estimator\aimd_rate_control.cc 128) 设置到 send 的 aimd 上的
        
->ReceiveSideCongestionController::OnRttUpdate (modules\congestion_controller\receive_side_congestion_controller.cc 158)
    -> ReceiveSideCongestionController::WrappingBitrateEstimator::OnRttUpdate (\modules\congestion_controller\receive_side_congestion_controller.cc 54)
        -> RemoteBitrateEstimatorSingleStream::OnRttUpdate (\modules\remote_bitrate_estimator\remote_bitrate_estimator_single_stream.cc 197)
            -> AimdRateControl::SetRtt (modules\remote_bitrate_estimator\aimd_rate_control.cc 128) 设置到 receive 的 aimd
3. CallStats 中的 report 是从 CallStats::OnRttUpdate

-> ModuleRtpRtcpImpl::Process (modules\rtp_rtcp\source\rtp_rtcp_impl.cc 153) 通过线程
-> rtp_sender_->ProcessBitrate => RTPSender::ProcessBitrate (\modules\rtp_rtcp\source\rtp_sender.cc 1121)
-> CallStats::OnRttUpdate =========== ModuleRtpRtcpImpl audio 和 video 各有一个,但是 rtt_stats_ 是同一个
-> int64_t last_rtt = rtt_stats_->LastProcessedRtt() ; set_rtt_ms(last_rtt) (modules\rtp_rtcp\source\rtp_rtcp_impl.cc 293) => ModuleRtpRtcpImpl::set_rtt_ms (modules\rtp_rtcp\source\rtp_rtcp_impl.cc 893)
-> RTPSender::SetRtt (\modules\rtp_rtcp\source\rtp_sender.cc 1474)
-> rtcp_sender_.SendRTCP => RTCPSender::SendRTCP (\modules\rtp_rtcp\source\rtcp_sender.cc 685) 发送report 的 rtcp 包
->
->

    这里至少是1000ms 跑一次
    // Process RTT if we have received a report block and we haven't
    // processed RTT for at least |kRtpRtcpRttProcessTimeMs| milliseconds.
    if (rtcp_receiver_.LastReceivedReportBlockMs() > last_rtt_process_time_ &&
        process_rtt) {
      std::vector receive_blocks;
      获取有block,主要是ssrc
      rtcp_receiver_.StatisticsReceived(&receive_blocks);
      int64_t max_rtt = 0;
      for (std::vector::iterator it = receive_blocks.begin();
           it != receive_blocks.end(); ++it) {
        int64_t rtt = 0;
        这里获取rtt (*last_rtt_ms = report_block->last_rtt_ms),选择最大的rtt
        rtcp_receiver_.RTT(it->sender_ssrc, &rtt, NULL, NULL, NULL);
        max_rtt = (rtt > max_rtt) ? rtt : max_rtt;
      }
      // Report the rtt.
      if (rtt_stats_ && max_rtt != 0)
        rtt_stats_->OnRttUpdate(max_rtt);   ===== CallStats::OnRttUpdate 
    }
void CallStats::OnRttUpdate(int64_t rtt) {
  int64_t now_ms = clock_->TimeInMilliseconds();
  process_thread_->PostTask(rtc::NewClosure([rtt, now_ms, this]() {
    RTC_DCHECK_RUN_ON(&process_thread_checker_);
    把上一次的rtt 就push 到reports,用于上面使用
    reports_.push_back(RttTime(rtt, now_ms));
    if (time_of_first_rtt_ms_ == -1)
      time_of_first_rtt_ms_ = now_ms;

    process_thread_->WakeUp(this);
  }));
}
4. rtt 是 SR 和 RR 计算出来的,LSR,DLSR,看 三十章

你可能感兴趣的:(webrtc学习)