使用RemoteBitrateEstimatorAbsSendTime的时候发现刚刚开始会出现大量的Probe failed, sent at
这样的打印,然后打印等级是Info(这个等级的打印说明问题不大),但是还是看了一下代码了解一下是什么原因导致的。这个是因为收到的包过于密集导致的,出现大量的接收或者发送的包间隔不到1毫秒(ComputeClusters函数)。
- 当且仅当发送间隔和接收间隔都大于等于1毫秒的时候,这个变量
num_above_min_delta
才会自加。正确的包都会使变量count
自加。 - 当
num_above_min_delta
的个数小于一半count
的个数的时候就会打印一下我们看到的这种log - 为什么会出现这样的情况呢,具体阅读平滑发送模块代码
PacedSender
就知道了,这个是因为一开始堆积的数据量大和起始发送码率大pacing_bitrate_kbps_
,然后单个包较小,单次发送的包个数就多(音频包的优先级高,会一次性发送所有的音频包,视频包会平滑发送PacedSender::SendPacket
)
void RemoteBitrateEstimatorAbsSendTime::ComputeClusters(
std::list<Cluster>* clusters) const {
Cluster current;
int64_t prev_send_time = -1;
int64_t prev_recv_time = -1;
for (std::list<Probe>::const_iterator it = probes_.begin();
it != probes_.end();
++it) {
if (prev_send_time >= 0) {
int send_delta_ms = it->send_time_ms - prev_send_time;
int recv_delta_ms = it->recv_time_ms - prev_recv_time;
if (send_delta_ms >= 1 && recv_delta_ms >= 1) {
++current.num_above_min_delta;
}
if (!IsWithinClusterBounds(send_delta_ms, current)) {
if (current.count >= kMinClusterSize)
AddCluster(clusters, ¤t);
current = Cluster();
}
current.send_mean_ms += send_delta_ms;
current.recv_mean_ms += recv_delta_ms;
current.mean_size += it->payload_size;
++current.count;
}
prev_send_time = it->send_time_ms;
prev_recv_time = it->recv_time_ms;
}
if (current.count >= kMinClusterSize)
AddCluster(clusters, ¤t);
}
std::list<Cluster>::const_iterator
RemoteBitrateEstimatorAbsSendTime::FindBestProbe(
const std::list<Cluster>& clusters) const {
int highest_probe_bitrate_bps = 0;
std::list<Cluster>::const_iterator best_it = clusters.end();
for (std::list<Cluster>::const_iterator it = clusters.begin();
it != clusters.end();
++it) {
if (it->send_mean_ms == 0 || it->recv_mean_ms == 0)
continue;
if (it->num_above_min_delta > it->count / 2 &&
(it->recv_mean_ms - it->send_mean_ms <= 2.0f &&
it->send_mean_ms - it->recv_mean_ms <= 5.0f)) {
int probe_bitrate_bps =
std::min(it->GetSendBitrateBps(), it->GetRecvBitrateBps());
if (probe_bitrate_bps > highest_probe_bitrate_bps) {
highest_probe_bitrate_bps = probe_bitrate_bps;
best_it = it;
}
} else {
int send_bitrate_bps = it->mean_size * 8 * 1000 / it->send_mean_ms;
int recv_bitrate_bps = it->mean_size * 8 * 1000 / it->recv_mean_ms;
LOG(LS_INFO) << "Probe failed, sent at " << send_bitrate_bps
<< " bps, received at " << recv_bitrate_bps
<< " bps. Mean send delta: " << it->send_mean_ms
<< " ms, mean recv delta: " << it->recv_mean_ms
<< " ms, num probes: " << it->count;
break;
}
}
return best_it;
}