WebRTC Probe 探测码率、transport-cc作用
为什么需要探测带宽?
答:拥塞控制的AIMD算法,加法增加太慢了,网络很好的时候,需要很快探测到最大带宽。
一 ProbeBitrateEstimator
我看其它文章说,是根据RTCP Feedback transport-cc的ACK应答,来计算码率。
具体说明下是怎么计算的,因为应答是不带长度的。
1 发送时,记录RTP包信息,比如发送时间,长度等,插入历史队列中。
2 收到应答,在历史队列中查找序列号,统计出相关的长度。
//根据RTCP Feedback transport中的ACK应答的序列号来计算的
absl::optional<DataRate> ProbeBitrateEstimator::HandleProbeAndEstimateBitrate(
const PacketResult& packet_feedback) {
...
//packet_feedback.sent_packet.size怎么计算的
cluster->size_total += packet_feedback.sent_packet.size;
...
DataSize send_size = cluster->size_total - cluster->size_last_send;
DataRate send_rate = send_size / send_interval;
...
}
TransportFeedbackAdapter::AddPacket(...){
...
packet.sent.size = DataSize::Bytes(packet_info.length + overhead_bytes);
...
history_.insert(std::make_pair(packet.sent.sequence_number, packet));
}
std::vector<PacketResult>
TransportFeedbackAdapter::ProcessTransportFeedbackInner(
const rtcp::TransportFeedback& feedback,
Timestamp feedback_receive_time) {
for (const auto& packet : feedback.GetAllPackets()) {
int64_t seq_num = seq_num_unwrapper_.Unwrap(packet.sequence_number());
auto it = history_.find(seq_num);
PacketFeedback packet_feedback = it->second;
PacketResult result;
result.sent_packet = packet_feedback.sent;
result.receive_time = packet_feedback.receive_time;
packet_result_vector.push_back(result);
}
return packet_result_vector;
}
absl::optional<DataRate> probe_bitrate =
probe_bitrate_estimator_->FetchAndResetLastEstimatedBitrate();
二 ProbeController:探测控制
probe探测发送的数据:音视频rtp包数据,如果数据量不够,padding的数据。
GoogCcNetworkController::OnProcessInterval(
--| probe_controller_->Process(msg.at_time.ms());
probe_controller_->SetBitrates(
min_data_rate_.bps(), GetBpsOrDefault(starting_rate_, -1),
max_data_rate_.bps_or(-1), new_constraints.at_time.ms());
GoogCcNetworkController::MaybeTriggerOnNetworkChanged(
--| probe_controller_->SetEstimatedBitrate(
loss_based_target_rate.bps(), at_time.ms());
ProbeController::InitiateExponentialProbing(...): 第一次是3倍, 第二次6倍。
三 AcknowledgedBitrateEstimator:根据根据RTCP Feedback transport-cc的ACK应答,算吞吐量,即实际带宽。
class AcknowledgedBitrateEstimator
{
std::unique_ptr<BitrateEstimator> bitrate_estimator_;
}
// Computes a bayesian estimate of the throughput given acks containing
// the arrival time and payload size.
//基于贝叶斯估计,通过ack的到达时间和包体大小
class BitrateEstimator {
}
acknowledged_bitrate_estimator_->IncomingPacketFeedbackVector(
report.SortedByReceiveTime());
auto acknowledged_bitrate = acknowledged_bitrate_estimator_->bitrate();