@@ -197,8 +197,7 @@ bool PacketBuffer::PotentialNewFrame(uint16_t seq_num) const {
197
197
std::vector<std::unique_ptr<RtpFrameObject>> PacketBuffer::FindFrames (
198
198
uint16_t seq_num) {
199
199
std::vector<std::unique_ptr<RtpFrameObject>> found_frames;
200
- size_t packets_tested = 0 ;
201
- while (packets_tested < size_ && PotentialNewFrame (seq_num)) {
200
+ for (size_t i = 0 ; i < size_ && PotentialNewFrame (seq_num); ++i) {
202
201
size_t index = seq_num % size_;
203
202
sequence_buffer_[index].continuous = true ;
204
203
@@ -215,7 +214,10 @@ std::vector<std::unique_ptr<RtpFrameObject>> PacketBuffer::FindFrames(
215
214
216
215
bool is_h264 = data_buffer_[start_index].codec == kVideoCodecH264 ;
217
216
int64_t frame_timestamp = data_buffer_[start_index].timestamp ;
218
- while (true ) {
217
+
218
+ // Since packet at |data_buffer_[index]| is already part of the frame
219
+ // we will have at most |size_ - 1| packets left to check.
220
+ for (size_t j = 0 ; j < size_ - 1 ; ++j) {
219
221
frame_size += data_buffer_[start_index].sizeBytes ;
220
222
max_nack_count =
221
223
std::max (max_nack_count, data_buffer_[start_index].timesNacked );
@@ -232,12 +234,7 @@ std::vector<std::unique_ptr<RtpFrameObject>> PacketBuffer::FindFrames(
232
234
// the timestamp of that packet is the same as this one. This may cause
233
235
// the PacketBuffer to hand out incomplete frames.
234
236
// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=7106
235
- //
236
- // Since we ignore the |frame_begin| flag of the inserted packets
237
- // we check that |start_index != static_cast<int>(index)| to make sure
238
- // that we don't get stuck in a loop if the packet buffer is filled
239
- // with packets of the same timestamp.
240
- if (is_h264 && start_index != static_cast <int >(index) &&
237
+ if (is_h264 &&
241
238
(!sequence_buffer_[start_index].used ||
242
239
data_buffer_[start_index].timestamp != frame_timestamp)) {
243
240
break ;
@@ -251,7 +248,6 @@ std::vector<std::unique_ptr<RtpFrameObject>> PacketBuffer::FindFrames(
251
248
max_nack_count, clock_->TimeInMilliseconds ()));
252
249
}
253
250
++seq_num;
254
- ++packets_tested;
255
251
}
256
252
return found_frames;
257
253
}
0 commit comments