Chromium Code Reviews| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 last_seq_num_ = seq_num; | 83 last_seq_num_ = seq_num; |
| 84 | 84 |
| 85 sequence_buffer_[index].frame_begin = packet.isFirstPacket; | 85 sequence_buffer_[index].frame_begin = packet.isFirstPacket; |
| 86 sequence_buffer_[index].frame_end = packet.markerBit; | 86 sequence_buffer_[index].frame_end = packet.markerBit; |
| 87 sequence_buffer_[index].seq_num = packet.seqNum; | 87 sequence_buffer_[index].seq_num = packet.seqNum; |
| 88 sequence_buffer_[index].continuous = false; | 88 sequence_buffer_[index].continuous = false; |
| 89 sequence_buffer_[index].frame_created = false; | 89 sequence_buffer_[index].frame_created = false; |
| 90 sequence_buffer_[index].used = true; | 90 sequence_buffer_[index].used = true; |
| 91 data_buffer_[index] = packet; | 91 data_buffer_[index] = packet; |
| 92 | 92 |
| 93 // Since the data pointed to by |packet.dataPtr| is volatile the | |
| 94 // data has to be copied to its own buffer. | |
| 95 if (packet.sizeBytes) { | |
| 96 uint8_t* payload = new uint8_t[packet.sizeBytes]; | |
| 97 memcpy(payload, packet.dataPtr, packet.sizeBytes); | |
|
brandtr
2016/09/01 12:45:13
In this block, the copied VCMPacket essentially ta
philipel
2016/09/01 12:49:07
We don't need to lock the data at this points.
I
brandtr
2016/09/01 13:21:53
"Non-persistent" sounds good.
philipel
2016/09/01 13:28:00
Done.
| |
| 98 data_buffer_[index].dataPtr = payload; | |
| 99 } | |
| 100 | |
| 93 FindFrames(seq_num); | 101 FindFrames(seq_num); |
| 94 return true; | 102 return true; |
| 95 } | 103 } |
| 96 | 104 |
| 97 void PacketBuffer::ClearTo(uint16_t seq_num) { | 105 void PacketBuffer::ClearTo(uint16_t seq_num) { |
| 98 rtc::CritScope lock(&crit_); | 106 rtc::CritScope lock(&crit_); |
| 99 size_t index = first_seq_num_ % size_; | 107 size_t index = first_seq_num_ % size_; |
| 100 while (AheadOf<uint16_t>(seq_num, first_seq_num_ + 1)) { | 108 while (AheadOf<uint16_t>(seq_num, first_seq_num_ + 1)) { |
| 101 index = (index + 1) % size_; | 109 index = (index + 1) % size_; |
| 102 first_seq_num_ = Add<1 << 16>(first_seq_num_, 1); | 110 ++first_seq_num_; |
| 111 delete data_buffer_[index].dataPtr; | |
| 112 data_buffer_[index].dataPtr = nullptr; | |
| 103 sequence_buffer_[index].used = false; | 113 sequence_buffer_[index].used = false; |
| 104 } | 114 } |
| 105 } | 115 } |
| 106 | 116 |
| 107 bool PacketBuffer::ExpandBufferSize() { | 117 bool PacketBuffer::ExpandBufferSize() { |
| 108 if (size_ == max_size_) | 118 if (size_ == max_size_) |
| 109 return false; | 119 return false; |
| 110 | 120 |
| 111 size_t new_size = std::min(max_size_, 2 * size_); | 121 size_t new_size = std::min(max_size_, 2 * size_); |
| 112 std::vector<VCMPacket> new_data_buffer(new_size); | 122 std::vector<VCMPacket> new_data_buffer(new_size); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 ++seq_num; | 194 ++seq_num; |
| 185 } | 195 } |
| 186 } | 196 } |
| 187 | 197 |
| 188 void PacketBuffer::ReturnFrame(RtpFrameObject* frame) { | 198 void PacketBuffer::ReturnFrame(RtpFrameObject* frame) { |
| 189 rtc::CritScope lock(&crit_); | 199 rtc::CritScope lock(&crit_); |
| 190 size_t index = frame->first_seq_num() % size_; | 200 size_t index = frame->first_seq_num() % size_; |
| 191 size_t end = (frame->last_seq_num() + 1) % size_; | 201 size_t end = (frame->last_seq_num() + 1) % size_; |
| 192 uint16_t seq_num = frame->first_seq_num(); | 202 uint16_t seq_num = frame->first_seq_num(); |
| 193 while (index != end) { | 203 while (index != end) { |
| 194 if (sequence_buffer_[index].seq_num == seq_num) | 204 if (sequence_buffer_[index].seq_num == seq_num) { |
| 205 delete data_buffer_[index].dataPtr; | |
| 206 data_buffer_[index].dataPtr = nullptr; | |
| 195 sequence_buffer_[index].used = false; | 207 sequence_buffer_[index].used = false; |
| 208 } | |
| 196 | 209 |
| 197 index = (index + 1) % size_; | 210 index = (index + 1) % size_; |
| 198 ++seq_num; | 211 ++seq_num; |
| 199 } | 212 } |
| 200 | 213 |
| 201 index = first_seq_num_ % size_; | 214 index = first_seq_num_ % size_; |
| 202 while (AheadOf<uint16_t>(last_seq_num_, first_seq_num_) && | 215 while (AheadOf<uint16_t>(last_seq_num_, first_seq_num_) && |
| 203 !sequence_buffer_[index].used) { | 216 !sequence_buffer_[index].used) { |
| 204 ++first_seq_num_; | 217 ++first_seq_num_; |
| 205 index = (index + 1) % size_; | 218 index = (index + 1) % size_; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 int PacketBuffer::Release() const { | 267 int PacketBuffer::Release() const { |
| 255 int count = rtc::AtomicOps::Decrement(&ref_count_); | 268 int count = rtc::AtomicOps::Decrement(&ref_count_); |
| 256 if (!count) { | 269 if (!count) { |
| 257 delete this; | 270 delete this; |
| 258 } | 271 } |
| 259 return count; | 272 return count; |
| 260 } | 273 } |
| 261 | 274 |
| 262 } // namespace video_coding | 275 } // namespace video_coding |
| 263 } // namespace webrtc | 276 } // namespace webrtc |
| OLD | NEW |