PacketBuffer (位于webrtc\modules\video_coding)
新版的webrtc已经弃用了以前的VCMJitterBuffer类
主要函数:
virtual bool InsertPacket(VCMPacket* packet);
void ClearTo(uint16_t seq_num);
void Clear();
void PaddingReceived(uint16_t seq_num);
VCMPacket :应该是video coding model packet 的缩写,用于视频包。
InsertPacket函数:
bool PacketBuffer::InsertPacket(VCMPacket* packet);
//packet 里的数据是rtp数据
//源码实现
{
//完整的数据帧,例如:h264
std::vector<std::unique_ptr<CRtpFrameObject>> found_frames;
{
MiniBase::CGurd lock(&crit_);
uint16_t seq_num = packet->seqNum;
size_t index = seq_num % nTotalSize_;
//如果是第一个包
if (!first_packet_received_)
{
first_seq_num_ = seq_num;
first_packet_received_ = true;
}
////判断first_seq_num_是否在seq_num之前,如果是返回false;
else if (AheadOf(first_seq_num_, seq_num))
{
uint16_t old_seq_num = first_seq_num_ - kMaxPaddingAge;
// If we have explicitly cleared past this packet then it's old,
// don't insert it.
if (is_cleared_to_first_seq_num_)
{
delete[] packet->dataPtr;
packet->dataPtr = nullptr;
return false;
}
first_seq_num_ = seq_num;
}
if (sequence_buffer_[index].used)
{
// Duplicate packet, just delete the payload.
if (data_buffer_[index].seqNum == packet->seqNum)
{
delete[] packet->dataPtr;
packet->dataPtr = nullptr;
return true;
}
// The packet buffer is full, try to expand the buffer.
// 在队列中寻找缓冲,如果缓冲已经满了,则扩充
while (ExpandBufferSize() && sequence_buffer_[seq_num % nTotalSize_].used)
{
}
// 删除旧的数据
if (sequence_buffer_[index].used)
{
delete[] packet->dataPtr;
packet->dataPtr = nullptr;
return false;
}
}
sequence_buffer_[index].frame_begin = packet->is_first_packet_in_frame;
sequence_buffer_[index].frame_end = packet->markerBit;
sequence_buffer_[index].seq_num = packet->seqNum;
sequence_buffer_[index].continuous = false;
sequence_buffer_[index].frame_created = false;
sequence_buffer_[index].used = true;
data_buffer_[index] = *packet;
packet->dataPtr = nullptr;
//更新丢包列表,注意nack请求再NackModule里
UpdateMissingPackets(packet->seqNum);
int64_t now_ms = m_pClock_->TimeInMilliseconds();
last_received_packet_ms_ = MiniBase::Optional<int64_t>(now_ms);
//更新最后接收关键帧的时间
if (packet->frameType == kVFrameKey)
last_received_keyframe_packet_ms_ = MiniBase::Optional<int64_t>(now_ms);
//查找收到的帧
found_frames = FindFrames(seq_num);
}
//完整的数据,通知回调
for (std::unique_ptr<CRtpFrameObject>& frame : found_frames)
received_frame_callback_->OnReceivedFrame(std::move(frame));
return true;
}
网友评论