Check if packet in PacketBuffer was cleared before the frame was fully received.

Bug: none
Change-Id: Iaa5702a8da93462ba80f72821f075a6673eeb0e1
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/260324
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Philip Eliasson <philipel@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36694}
This commit is contained in:
philipel
2022-04-28 14:31:55 +02:00
committed by WebRTC LUCI CQ
parent 9432768024
commit 90623e1a91
2 changed files with 32 additions and 17 deletions

View File

@ -242,11 +242,17 @@ std::vector<std::unique_ptr<PacketBuffer::Packet>> PacketBuffer::FindFrames(
bool is_h264_keyframe = false;
int idr_width = -1;
int idr_height = -1;
bool full_frame_found = false;
while (true) {
++tested_packets;
if (!is_h264 && buffer_[start_index]->is_first_packet_in_frame())
break;
if (!is_h264) {
if (buffer_[start_index] == nullptr ||
buffer_[start_index]->is_first_packet_in_frame()) {
full_frame_found = buffer_[start_index] != nullptr;
break;
}
}
if (is_h264) {
const auto* h264_header = absl::get_if<RTPVideoHeaderH264>(
@ -336,22 +342,24 @@ std::vector<std::unique_ptr<PacketBuffer::Packet>> PacketBuffer::FindFrames(
}
}
const uint16_t end_seq_num = seq_num + 1;
// Use uint16_t type to handle sequence number wrap around case.
uint16_t num_packets = end_seq_num - start_seq_num;
found_frames.reserve(found_frames.size() + num_packets);
for (uint16_t i = start_seq_num; i != end_seq_num; ++i) {
std::unique_ptr<Packet>& packet = buffer_[i % buffer_.size()];
RTC_DCHECK(packet);
RTC_DCHECK_EQ(i, packet->seq_num);
// Ensure frame boundary flags are properly set.
packet->video_header.is_first_packet_in_frame = (i == start_seq_num);
packet->video_header.is_last_packet_in_frame = (i == seq_num);
found_frames.push_back(std::move(packet));
}
if (is_h264 || full_frame_found) {
const uint16_t end_seq_num = seq_num + 1;
// Use uint16_t type to handle sequence number wrap around case.
uint16_t num_packets = end_seq_num - start_seq_num;
found_frames.reserve(found_frames.size() + num_packets);
for (uint16_t i = start_seq_num; i != end_seq_num; ++i) {
std::unique_ptr<Packet>& packet = buffer_[i % buffer_.size()];
RTC_DCHECK(packet);
RTC_DCHECK_EQ(i, packet->seq_num);
// Ensure frame boundary flags are properly set.
packet->video_header.is_first_packet_in_frame = (i == start_seq_num);
packet->video_header.is_last_packet_in_frame = (i == seq_num);
found_frames.push_back(std::move(packet));
}
missing_packets_.erase(missing_packets_.begin(),
missing_packets_.upper_bound(seq_num));
missing_packets_.erase(missing_packets_.begin(),
missing_packets_.upper_bound(seq_num));
}
}
++seq_num;
}