Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: webrtc/modules/video_coding/packet_buffer.cc

Issue 2868723003: Break backwards traversal loop if we have looped around all packet in the PacketBuffer for H264 fra… (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/modules/video_coding/video_packet_buffer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 if (sequence_buffer_[prev_index].continuous) 191 if (sequence_buffer_[prev_index].continuous)
192 return true; 192 return true;
193 193
194 return false; 194 return false;
195 } 195 }
196 196
197 std::vector<std::unique_ptr<RtpFrameObject>> PacketBuffer::FindFrames( 197 std::vector<std::unique_ptr<RtpFrameObject>> PacketBuffer::FindFrames(
198 uint16_t seq_num) { 198 uint16_t seq_num) {
199 std::vector<std::unique_ptr<RtpFrameObject>> found_frames; 199 std::vector<std::unique_ptr<RtpFrameObject>> found_frames;
200 size_t packets_tested = 0; 200 size_t packets_tested = 0;
201 while (packets_tested < size_ && PotentialNewFrame(seq_num)) { 201 while (packets_tested < size_ && PotentialNewFrame(seq_num)) {
stefan-webrtc 2017/05/08 11:47:27 Can this perhaps also be a for loop?
philipel 2017/05/08 12:56:23 Done.
202 size_t index = seq_num % size_; 202 size_t index = seq_num % size_;
203 sequence_buffer_[index].continuous = true; 203 sequence_buffer_[index].continuous = true;
204 204
205 // If all packets of the frame is continuous, find the first packet of the 205 // If all packets of the frame is continuous, find the first packet of the
206 // frame and create an RtpFrameObject. 206 // frame and create an RtpFrameObject.
207 if (sequence_buffer_[index].frame_end) { 207 if (sequence_buffer_[index].frame_end) {
208 size_t frame_size = 0; 208 size_t frame_size = 0;
209 int max_nack_count = -1; 209 int max_nack_count = -1;
210 uint16_t start_seq_num = seq_num; 210 uint16_t start_seq_num = seq_num;
211 211
212 // Find the start index by searching backward until the packet with 212 // Find the start index by searching backward until the packet with
213 // the |frame_begin| flag is set. 213 // the |frame_begin| flag is set.
214 int start_index = index; 214 int start_index = index;
215 215
216 bool is_h264 = data_buffer_[start_index].codec == kVideoCodecH264; 216 bool is_h264 = data_buffer_[start_index].codec == kVideoCodecH264;
217 int64_t frame_timestamp = data_buffer_[start_index].timestamp; 217 int64_t frame_timestamp = data_buffer_[start_index].timestamp;
218 while (true) { 218 while (true) {
stefan-webrtc 2017/05/08 11:47:27 Try to get rid of this while loop as it's hard to
philipel 2017/05/08 12:56:23 Agree that a loop is cleaner, fixed.
219 frame_size += data_buffer_[start_index].sizeBytes; 219 frame_size += data_buffer_[start_index].sizeBytes;
220 max_nack_count = 220 max_nack_count =
221 std::max(max_nack_count, data_buffer_[start_index].timesNacked); 221 std::max(max_nack_count, data_buffer_[start_index].timesNacked);
222 sequence_buffer_[start_index].frame_created = true; 222 sequence_buffer_[start_index].frame_created = true;
223 223
224 if (!is_h264 && sequence_buffer_[start_index].frame_begin) 224 if (!is_h264 && sequence_buffer_[start_index].frame_begin)
225 break; 225 break;
226 226
227 start_index = start_index > 0 ? start_index - 1 : size_ - 1; 227 start_index = start_index > 0 ? start_index - 1 : size_ - 1;
228 228
229 // In the case of H264 we don't have a frame_begin bit (yes, 229 // In the case of H264 we don't have a frame_begin bit (yes,
230 // |frame_begin| might be set to true but that is a lie). So instead 230 // |frame_begin| might be set to true but that is a lie). So instead
231 // we traverese backwards as long as we have a previous packet and 231 // we traverese backwards as long as we have a previous packet and
232 // the timestamp of that packet is the same as this one. This may cause 232 // the timestamp of that packet is the same as this one. This may cause
233 // the PacketBuffer to hand out incomplete frames. 233 // the PacketBuffer to hand out incomplete frames.
234 // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=7106 234 // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=7106
235 // 235 //
236 // Since we ignore the |frame_begin| flag of the inserted packets 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 237 // we check if |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 238 // that we don't get stuck in a loop if the packet buffer is filled
239 // with packets of the same timestamp. 239 // with packets of the same timestamp.
240 if (is_h264 && start_index != static_cast<int>(index) && 240 if ((is_h264 && start_index == static_cast<int>(index)) ||
241 (!sequence_buffer_[start_index].used || 241 (!sequence_buffer_[start_index].used ||
242 data_buffer_[start_index].timestamp != frame_timestamp)) { 242 data_buffer_[start_index].timestamp != frame_timestamp)) {
243 break; 243 break;
244 } 244 }
245 245
246 --start_seq_num; 246 --start_seq_num;
247 } 247 }
248 248
249 found_frames.emplace_back( 249 found_frames.emplace_back(
250 new RtpFrameObject(this, start_seq_num, seq_num, frame_size, 250 new RtpFrameObject(this, start_seq_num, seq_num, frame_size,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 int PacketBuffer::Release() const { 312 int PacketBuffer::Release() const {
313 int count = rtc::AtomicOps::Decrement(&ref_count_); 313 int count = rtc::AtomicOps::Decrement(&ref_count_);
314 if (!count) { 314 if (!count) {
315 delete this; 315 delete this;
316 } 316 }
317 return count; 317 return count;
318 } 318 }
319 319
320 } // namespace video_coding 320 } // namespace video_coding
321 } // namespace webrtc 321 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/video_coding/video_packet_buffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698