OLD | NEW |
---|---|
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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 } | 120 } |
121 | 121 |
122 for (std::unique_ptr<RtpFrameObject>& frame : found_frames) | 122 for (std::unique_ptr<RtpFrameObject>& frame : found_frames) |
123 received_frame_callback_->OnReceivedFrame(std::move(frame)); | 123 received_frame_callback_->OnReceivedFrame(std::move(frame)); |
124 | 124 |
125 return true; | 125 return true; |
126 } | 126 } |
127 | 127 |
128 void PacketBuffer::ClearTo(uint16_t seq_num) { | 128 void PacketBuffer::ClearTo(uint16_t seq_num) { |
129 rtc::CritScope lock(&crit_); | 129 rtc::CritScope lock(&crit_); |
130 // We have already cleared past this sequence number, no need to do anything. | |
131 if (is_cleared_to_first_seq_num_ && | |
132 AheadOf<uint16_t>(first_seq_num_, seq_num)) { | |
133 return; | |
134 } | |
sprang_webrtc
2017/07/28 15:36:50
Is this case covered by the new test?
philipel
2017/08/01 11:22:03
It is covered by already existing tests.
| |
130 | 135 |
131 // If the packet buffer was cleared between a frame was created and returned. | 136 // If the packet buffer was cleared between a frame was created and returned. |
132 if (!first_packet_received_) | 137 if (!first_packet_received_) |
133 return; | 138 return; |
134 | 139 |
135 is_cleared_to_first_seq_num_ = true; | 140 // Avoid iterating over the buffer more than once by capping the number of |
136 while (AheadOrAt<uint16_t>(seq_num, first_seq_num_)) { | 141 // iterations to the |size_| of the buffer. |
142 ++seq_num; | |
143 size_t diff = ForwardDiff<uint16_t>(first_seq_num_, seq_num); | |
144 size_t iterations = std::min(diff, size_); | |
145 for (size_t i = 0; i < iterations; ++i) { | |
137 size_t index = first_seq_num_ % size_; | 146 size_t index = first_seq_num_ % size_; |
138 delete[] data_buffer_[index].dataPtr; | 147 RTC_DCHECK_EQ(data_buffer_[index].seqNum, sequence_buffer_[index].seq_num); |
139 data_buffer_[index].dataPtr = nullptr; | 148 if (AheadOf<uint16_t>(seq_num, sequence_buffer_[index].seq_num)) { |
140 sequence_buffer_[index].used = false; | 149 delete[] data_buffer_[index].dataPtr; |
150 data_buffer_[index].dataPtr = nullptr; | |
151 sequence_buffer_[index].used = false; | |
152 } | |
141 ++first_seq_num_; | 153 ++first_seq_num_; |
142 } | 154 } |
143 | 155 |
156 // If |diff| is larger than |iterations| it means that we don't increment | |
157 // |first_seq_num_| until we reach |seq_num|, so we set it here. | |
158 first_seq_num_ = seq_num; | |
159 | |
160 is_cleared_to_first_seq_num_ = true; | |
144 missing_packets_.erase(missing_packets_.begin(), | 161 missing_packets_.erase(missing_packets_.begin(), |
145 missing_packets_.upper_bound(seq_num)); | 162 missing_packets_.upper_bound(seq_num)); |
146 } | 163 } |
147 | 164 |
148 void PacketBuffer::Clear() { | 165 void PacketBuffer::Clear() { |
149 rtc::CritScope lock(&crit_); | 166 rtc::CritScope lock(&crit_); |
150 for (size_t i = 0; i < size_; ++i) { | 167 for (size_t i = 0; i < size_; ++i) { |
151 delete[] data_buffer_[i].dataPtr; | 168 delete[] data_buffer_[i].dataPtr; |
152 data_buffer_[i].dataPtr = nullptr; | 169 data_buffer_[i].dataPtr = nullptr; |
153 sequence_buffer_[i].used = false; | 170 sequence_buffer_[i].used = false; |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
402 missing_packets_.insert(*newest_inserted_seq_num_); | 419 missing_packets_.insert(*newest_inserted_seq_num_); |
403 ++*newest_inserted_seq_num_; | 420 ++*newest_inserted_seq_num_; |
404 } | 421 } |
405 } else { | 422 } else { |
406 missing_packets_.erase(seq_num); | 423 missing_packets_.erase(seq_num); |
407 } | 424 } |
408 } | 425 } |
409 | 426 |
410 } // namespace video_coding | 427 } // namespace video_coding |
411 } // namespace webrtc | 428 } // namespace webrtc |
OLD | NEW |