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

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

Issue 2480293002: New jitter buffer experiment. (Closed)
Patch Set: Feedback Fixes. Created 4 years, 1 month 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
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 last_seq_num_ = seq_num; 93 last_seq_num_ = seq_num;
94 94
95 sequence_buffer_[index].frame_begin = packet.isFirstPacket; 95 sequence_buffer_[index].frame_begin = packet.isFirstPacket;
96 sequence_buffer_[index].frame_end = packet.markerBit; 96 sequence_buffer_[index].frame_end = packet.markerBit;
97 sequence_buffer_[index].seq_num = packet.seqNum; 97 sequence_buffer_[index].seq_num = packet.seqNum;
98 sequence_buffer_[index].continuous = false; 98 sequence_buffer_[index].continuous = false;
99 sequence_buffer_[index].frame_created = false; 99 sequence_buffer_[index].frame_created = false;
100 sequence_buffer_[index].used = true; 100 sequence_buffer_[index].used = true;
101 data_buffer_[index] = packet; 101 data_buffer_[index] = packet;
102 102
103 FindFrames(seq_num); 103 FindFrames(seq_num);
stefan-webrtc 2016/11/08 14:49:27 This shouldn't be called from within crit_ now as
philipel 2016/11/10 16:13:53 FindFrames now return a vector of found frames.
104 return true; 104 return true;
105 } 105 }
106 106
107 void PacketBuffer::ClearTo(uint16_t seq_num) { 107 void PacketBuffer::ClearTo(uint16_t seq_num) {
108 rtc::CritScope lock(&crit_); 108 rtc::CritScope lock(&crit_);
109 109
110 // If the packet buffer was cleared between a frame was created and returned. 110 // If the packet buffer was cleared between a frame was created and returned.
111 if (!first_packet_received_) 111 if (!first_packet_received_)
112 return; 112 return;
113 113
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 sequence_buffer_[index].seq_num - 1) { 181 sequence_buffer_[index].seq_num - 1) {
182 return false; 182 return false;
183 } 183 }
184 if (sequence_buffer_[prev_index].continuous) 184 if (sequence_buffer_[prev_index].continuous)
185 return true; 185 return true;
186 186
187 return false; 187 return false;
188 } 188 }
189 189
190 void PacketBuffer::FindFrames(uint16_t seq_num) { 190 void PacketBuffer::FindFrames(uint16_t seq_num) {
191 while (PotentialNewFrame(seq_num)) { 191 std::vector<std::unique_ptr<RtpFrameObject>> found_frames;
192 size_t index = seq_num % size_; 192 {
193 sequence_buffer_[index].continuous = true; 193 rtc::CritScope lock(&crit_);
194 while (PotentialNewFrame(seq_num)) {
195 size_t index = seq_num % size_;
196 sequence_buffer_[index].continuous = true;
194 197
195 // If all packets of the frame is continuous, find the first packet of the 198 // If all packets of the frame is continuous, find the first packet of the
196 // frame and create an RtpFrameObject. 199 // frame and create an RtpFrameObject.
197 if (sequence_buffer_[index].frame_end) { 200 if (sequence_buffer_[index].frame_end) {
198 size_t frame_size = 0; 201 size_t frame_size = 0;
199 int max_nack_count = -1; 202 int max_nack_count = -1;
200 uint16_t start_seq_num = seq_num; 203 uint16_t start_seq_num = seq_num;
201 204
202 // Find the start index by searching backward until the packet with 205 // Find the start index by searching backward until the packet with
203 // the |frame_begin| flag is set. 206 // the |frame_begin| flag is set.
204 int start_index = index; 207 int start_index = index;
205 while (true) { 208 while (true) {
206 frame_size += data_buffer_[start_index].sizeBytes; 209 frame_size += data_buffer_[start_index].sizeBytes;
207 max_nack_count = std::max( 210 max_nack_count =
208 max_nack_count, data_buffer_[start_index].timesNacked); 211 std::max(max_nack_count, data_buffer_[start_index].timesNacked);
209 sequence_buffer_[start_index].frame_created = true; 212 sequence_buffer_[start_index].frame_created = true;
210 213
211 if (sequence_buffer_[start_index].frame_begin) 214 if (sequence_buffer_[start_index].frame_begin)
212 break; 215 break;
213 216
214 start_index = start_index > 0 ? start_index - 1 : size_ - 1; 217 start_index = start_index > 0 ? start_index - 1 : size_ - 1;
215 start_seq_num--; 218 start_seq_num--;
219 }
220
221 found_frames.emplace_back(
222 new RtpFrameObject(this, start_seq_num, seq_num, frame_size,
223 max_nack_count, clock_->TimeInMilliseconds()));
216 } 224 }
217 225 ++seq_num;
218 std::unique_ptr<RtpFrameObject> frame(
219 new RtpFrameObject(this, start_seq_num, seq_num, frame_size,
220 max_nack_count, clock_->TimeInMilliseconds()));
221
222 received_frame_callback_->OnReceivedFrame(std::move(frame));
223 } 226 }
224
225 ++seq_num;
226 } 227 }
228 for (auto& frame : found_frames)
229 received_frame_callback_->OnReceivedFrame(std::move(frame));
227 } 230 }
228 231
229 void PacketBuffer::ReturnFrame(RtpFrameObject* frame) { 232 void PacketBuffer::ReturnFrame(RtpFrameObject* frame) {
230 rtc::CritScope lock(&crit_); 233 rtc::CritScope lock(&crit_);
231 size_t index = frame->first_seq_num() % size_; 234 size_t index = frame->first_seq_num() % size_;
232 size_t end = (frame->last_seq_num() + 1) % size_; 235 size_t end = (frame->last_seq_num() + 1) % size_;
233 uint16_t seq_num = frame->first_seq_num(); 236 uint16_t seq_num = frame->first_seq_num();
234 while (index != end) { 237 while (index != end) {
235 if (sequence_buffer_[index].seq_num == seq_num) { 238 if (sequence_buffer_[index].seq_num == seq_num) {
236 delete[] data_buffer_[index].dataPtr; 239 delete[] data_buffer_[index].dataPtr;
(...skipping 23 matching lines...) Expand all
260 size_t length = data_buffer_[index].sizeBytes; 263 size_t length = data_buffer_[index].sizeBytes;
261 memcpy(destination, source, length); 264 memcpy(destination, source, length);
262 destination += length; 265 destination += length;
263 index = (index + 1) % size_; 266 index = (index + 1) % size_;
264 ++seq_num; 267 ++seq_num;
265 } 268 }
266 return true; 269 return true;
267 } 270 }
268 271
269 VCMPacket* PacketBuffer::GetPacket(uint16_t seq_num) { 272 VCMPacket* PacketBuffer::GetPacket(uint16_t seq_num) {
270 rtc::CritScope lock(&crit_);
271 size_t index = seq_num % size_; 273 size_t index = seq_num % size_;
272 if (!sequence_buffer_[index].used || 274 if (!sequence_buffer_[index].used ||
273 seq_num != sequence_buffer_[index].seq_num) { 275 seq_num != sequence_buffer_[index].seq_num) {
274 return nullptr; 276 return nullptr;
275 } 277 }
276 return &data_buffer_[index]; 278 return &data_buffer_[index];
277 } 279 }
278 280
279 int PacketBuffer::AddRef() const { 281 int PacketBuffer::AddRef() const {
280 return rtc::AtomicOps::Increment(&ref_count_); 282 return rtc::AtomicOps::Increment(&ref_count_);
281 } 283 }
282 284
283 int PacketBuffer::Release() const { 285 int PacketBuffer::Release() const {
284 int count = rtc::AtomicOps::Decrement(&ref_count_); 286 int count = rtc::AtomicOps::Decrement(&ref_count_);
285 if (!count) { 287 if (!count) {
286 delete this; 288 delete this;
287 } 289 }
288 return count; 290 return count;
289 } 291 }
290 292
291 } // namespace video_coding 293 } // namespace video_coding
292 } // namespace webrtc 294 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/packet_buffer.h ('k') | webrtc/modules/video_coding/rtp_frame_reference_finder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698