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

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

Issue 2527903002: Fixed bug in PacketBuffer to correctly detect new complete frames. (Closed)
Patch Set: Feedback fix Created 4 years 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 } 165 }
166 166
167 bool PacketBuffer::PotentialNewFrame(uint16_t seq_num) const { 167 bool PacketBuffer::PotentialNewFrame(uint16_t seq_num) const {
168 size_t index = seq_num % size_; 168 size_t index = seq_num % size_;
169 int prev_index = index > 0 ? index - 1 : size_ - 1; 169 int prev_index = index > 0 ? index - 1 : size_ - 1;
170 170
171 if (!sequence_buffer_[index].used) 171 if (!sequence_buffer_[index].used)
172 return false; 172 return false;
173 if (sequence_buffer_[index].frame_created) 173 if (sequence_buffer_[index].frame_created)
174 return false; 174 return false;
175 if (sequence_buffer_[index].frame_begin && 175 if (sequence_buffer_[index].frame_begin)
176 (!sequence_buffer_[prev_index].used ||
177 AheadOf(seq_num, sequence_buffer_[prev_index].seq_num))) {
178 // The reason we only return true if this packet is the first packet of the
179 // frame and the sequence number is newer than the packet with the previous
180 // index is because we want to avoid an inifite loop in the case where
181 // a single frame containing more packets than the current size of the
182 // packet buffer is inserted.
183 return true; 176 return true;
184 }
185 if (!sequence_buffer_[prev_index].used) 177 if (!sequence_buffer_[prev_index].used)
186 return false; 178 return false;
187 if (sequence_buffer_[prev_index].seq_num != 179 if (sequence_buffer_[prev_index].seq_num !=
188 sequence_buffer_[index].seq_num - 1) { 180 sequence_buffer_[index].seq_num - 1) {
189 return false; 181 return false;
190 } 182 }
191 if (sequence_buffer_[prev_index].continuous) 183 if (sequence_buffer_[prev_index].continuous)
192 return true; 184 return true;
193 185
194 return false; 186 return false;
195 } 187 }
196 188
197 std::vector<std::unique_ptr<RtpFrameObject>> PacketBuffer::FindFrames( 189 std::vector<std::unique_ptr<RtpFrameObject>> PacketBuffer::FindFrames(
198 uint16_t seq_num) { 190 uint16_t seq_num) {
199 std::vector<std::unique_ptr<RtpFrameObject>> found_frames; 191 std::vector<std::unique_ptr<RtpFrameObject>> found_frames;
200 while (PotentialNewFrame(seq_num)) { 192 size_t packets_tested = 0;
193 while (packets_tested < size_ && PotentialNewFrame(seq_num)) {
201 size_t index = seq_num % size_; 194 size_t index = seq_num % size_;
202 sequence_buffer_[index].continuous = true; 195 sequence_buffer_[index].continuous = true;
203 196
204 // If all packets of the frame is continuous, find the first packet of the 197 // If all packets of the frame is continuous, find the first packet of the
205 // frame and create an RtpFrameObject. 198 // frame and create an RtpFrameObject.
206 if (sequence_buffer_[index].frame_end) { 199 if (sequence_buffer_[index].frame_end) {
207 size_t frame_size = 0; 200 size_t frame_size = 0;
208 int max_nack_count = -1; 201 int max_nack_count = -1;
209 uint16_t start_seq_num = seq_num; 202 uint16_t start_seq_num = seq_num;
210 203
(...skipping 11 matching lines...) Expand all
222 215
223 start_index = start_index > 0 ? start_index - 1 : size_ - 1; 216 start_index = start_index > 0 ? start_index - 1 : size_ - 1;
224 start_seq_num--; 217 start_seq_num--;
225 } 218 }
226 219
227 found_frames.emplace_back( 220 found_frames.emplace_back(
228 new RtpFrameObject(this, start_seq_num, seq_num, frame_size, 221 new RtpFrameObject(this, start_seq_num, seq_num, frame_size,
229 max_nack_count, clock_->TimeInMilliseconds())); 222 max_nack_count, clock_->TimeInMilliseconds()));
230 } 223 }
231 ++seq_num; 224 ++seq_num;
225 ++packets_tested;
232 } 226 }
233 return found_frames; 227 return found_frames;
234 } 228 }
235 229
236 void PacketBuffer::ReturnFrame(RtpFrameObject* frame) { 230 void PacketBuffer::ReturnFrame(RtpFrameObject* frame) {
237 rtc::CritScope lock(&crit_); 231 rtc::CritScope lock(&crit_);
238 size_t index = frame->first_seq_num() % size_; 232 size_t index = frame->first_seq_num() % size_;
239 size_t end = (frame->last_seq_num() + 1) % size_; 233 size_t end = (frame->last_seq_num() + 1) % size_;
240 uint16_t seq_num = frame->first_seq_num(); 234 uint16_t seq_num = frame->first_seq_num();
241 while (index != end) { 235 while (index != end) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 int PacketBuffer::Release() const { 283 int PacketBuffer::Release() const {
290 int count = rtc::AtomicOps::Decrement(&ref_count_); 284 int count = rtc::AtomicOps::Decrement(&ref_count_);
291 if (!count) { 285 if (!count) {
292 delete this; 286 delete this;
293 } 287 }
294 return count; 288 return count;
295 } 289 }
296 290
297 } // namespace video_coding 291 } // namespace video_coding
298 } // namespace webrtc 292 } // 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