webrtc-DelayBasedBwe

DelayBasedBwe
基于接收端网络延迟,估算出的码率

主要用的的成员:

  //计算帧间间隔
  std::unique_ptr inter_arrival_;
  //估算延迟的3中方法,卡尔曼滤波,基于斜率最小二乘,基于斜率的中值
  std::unique_ptr kalman_estimator_;
  std::unique_ptr trendline_estimator_;
  std::unique_ptr median_slope_estimator_;
  //过载探测器
  OveruseDetector detector_;
  //用于统计真实接收码率
  BitrateEstimator receiver_incoming_bitrate_;	  
  //控制带宽增加,减少,基于过载探测器
  AimdRateControl rate_control_;

主要处理逻辑:

//输入PacketInfo数组,循环调用IncomingPacketInfo
DelayBasedBwe::Result IncomingPacketFeedbackVector(
    const std::vector& packet_feedback_vector) {
     for(:packet_feedback_vector){
       IncomingPacketInfo();
     }
}

//主要的处理函数
DelayBasedBwe::Result IncomingPacketInfo(const PacketInfo& info) {
  int64_t now_ms = clock_->TimeInMilliseconds();
  //计算真实的接收码率
  receiver_incoming_bitrate_.Update(info.arrival_time_ms, info.payload_size);
  ...	
 
  //把64位发送时间转化为32位的时间戳,截取了发送时间的低位部分
  // 发送时间戳用于计算相对时间戳,只要相对值正确就ok,差不多就是去个余的意思
  //  timestamp = info.send_time_ms % xxxxx
  uint32_t send_time_24bits =
      static_cast(
          ((static_cast(info.send_time_ms) << kAbsSendTimeFraction) +
           500) /
          1000) &
      0x00FFFFFF;
  uint32_t timestamp = send_time_24bits << kAbsSendTimeInterArrivalUpshift;
     
  
  // 计算最近2组数据的一些差值,根据发送就收时间进行分组的
  uint32_t ts_delta = 0;
  int64_t t_delta = 0;
  int size_delta = 0;
  if (inter_arrival_->ComputeDeltas(timestamp, info.arrival_time_ms, now_ms,
                                    info.payload_size, &ts_delta, &t_delta,
                                    &size_delta)) {
    double ts_delta_ms = (1000.0 * ts_delta) / (1 << kInterArrivalShift);
    //
    //  3中方式,选用一种进行估算,结果detector_中获取
    //  
    if (in_trendline_experiment_) {
      trendline_estimator_->Update(t_delta, ts_delta_ms, info.arrival_time_ms);
      detector_.Detect(trendline_estimator_->trendline_slope(), ts_delta_ms,
                       trendline_estimator_->num_of_deltas(),
                       info.arrival_time_ms);
    } else if (in_median_slope_experiment_) {
      median_slope_estimator_->Update(t_delta, ts_delta_ms,
                                      info.arrival_time_ms);
      detector_.Detect(median_slope_estimator_->trendline_slope(), ts_delta_ms,
                       median_slope_estimator_->num_of_deltas(),
                       info.arrival_time_ms);
    } else {
      kalman_estimator_->Update(t_delta, ts_delta_ms, size_delta,
                                detector_.State(), info.arrival_time_ms);
      detector_.Detect(kalman_estimator_->offset(), ts_delta_ms,
                       kalman_estimator_->num_of_deltas(),
                       info.arrival_time_ms);
    }
  }

  //这个没找到设置pacing_info的地方,字面意思就是有探测码率请求了
  int probing_bps = 0;
  if (info.pacing_info.probe_cluster_id != PacedPacketInfo::kNotAProbe) {
    probing_bps = probe_bitrate_estimator_.HandleProbeAndEstimateBitrate(info);
  }

  //根据实质接收码率,网络过载情况等,由rate_control_获取估算码率
  rtc::Optional acked_bitrate_bps = receiver_incoming_bitrate_.bitrate_bps();
  // Currently overusing the bandwidth.
  if (detector_.State() == kBwOverusing) {
    if (acked_bitrate_bps &&
        rate_control_.TimeToReduceFurther(now_ms, *acked_bitrate_bps)) {
      result.updated =
          UpdateEstimate(info.arrival_time_ms, now_ms, acked_bitrate_bps,
                         &result.target_bitrate_bps);
    }
  } else if (probing_bps > 0) {
    // No overuse, but probing measured a bitrate.
    rate_control_.SetEstimate(probing_bps, info.arrival_time_ms);
    result.probe = true;
    result.updated =
        UpdateEstimate(info.arrival_time_ms, now_ms, acked_bitrate_bps,
                       &result.target_bitrate_bps);
  }
  if (!result.updated &&
      (last_update_ms_ == -1 ||
       now_ms - last_update_ms_ > rate_control_.GetFeedbackInterval())) {
     //如果大于一个fb间隔,则强制更新一下
    result.updated =
        UpdateEstimate(info.arrival_time_ms, now_ms, acked_bitrate_bps,
                       &result.target_bitrate_bps);
  }

  return result;
}

你可能感兴趣的:(webrtc笔记)