WebRTC研究:丢包判断
程序员文章站
2022-07-01 17:39:44
...
/*
sequence_number:当前收到的包***
*/
bool VCMJitterBuffer::UpdateNackList(uint16_t sequence_number) {
if (nack_mode_ == kNoNack) {
return true;
}
// Make sure we don't add packets which are already too old to be decoded.
if (!last_decoded_state_.in_initial_state()) {
/* latest_received_sequence_number_:上一次收到的最新RTP包*** */
latest_received_sequence_number_ = LatestSequenceNumber(
latest_received_sequence_number_, last_decoded_state_.sequence_num());
}
/* 判断当前RTP包是否是新的数据包,而不是重传或者乱序包 */
if (IsNewerSequenceNumber(sequence_number, latest_received_sequence_number_))
{
/*
从 latest_received_sequence_number_ + 1 开始判断是否满足 IsNewerSequenceNumber,
即:判断当前包的*** sequence_number 是不是比排在 i 的后面,
是的话,说明 [latest_received_sequence_number_ + 1, latest_received_sequence_number_] 区间的包丢了
*/
for (uint16_t i = latest_received_sequence_number_ + 1; IsNewerSequenceNumber(sequence_number, i); ++i) {
/* 将*** i 添加到 missing_sequence_numbers_(std::set类型),被认为包已经丢失 */
missing_sequence_numbers_.insert(missing_sequence_numbers_.end(), i);
TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "AddNack", "seqnum", i);
}
/*
判断集合 missing_sequence_numbers_ 的容量是否超过最大限制
是的话,通过调用 RecycleFramesUntilKeyFrame 不断丢包来减少集合中的***
*/
if (TooLargeNackList() && !HandleTooLargeNackList())
{
LOG(LS_WARNING) << "Requesting key frame due to too large NACK list.";
return false;
}
/*
判断集合 missing_sequence_numbers_ 里的是否太久了
判断依据:当前包的*** sequence_number 与 集合 missing_sequence_numbers_ 中第一个包的***之间的差值是否超过限制
是的话,通过调用 RecycleFramesUntilKeyFrame 不断丢包来减少集合中的***
*/
if (MissingTooOldPacket(sequence_number) && !HandleTooOldPackets(sequence_number)) {
LOG(LS_WARNING) << "Requesting key frame due to missing too old packets";
return false;
}
}
else
{
/* 当前包是重传或者乱序包,直接从丢包集合中剔除 */
missing_sequence_numbers_.erase(sequence_number);
TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RemoveNack",
"seqnum", sequence_number);
}
return true;
}
上一篇: FFmpeg 从零开始开发简单的音视频播放器(四)
下一篇: Edge