| 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 non-persistent the |
| 94 // data has to be copied to its own buffer. |
| 95 // TODO(philipel): Take ownership instead of copying payload when |
| 96 // bitstream-fixing has been implemented. |
| 97 if (packet.sizeBytes) { |
| 98 uint8_t* payload = new uint8_t[packet.sizeBytes]; |
| 99 memcpy(payload, packet.dataPtr, packet.sizeBytes); |
| 100 data_buffer_[index].dataPtr = payload; |
| 101 } |
| 102 |
| 93 FindFrames(seq_num); | 103 FindFrames(seq_num); |
| 94 return true; | 104 return true; |
| 95 } | 105 } |
| 96 | 106 |
| 97 void PacketBuffer::ClearTo(uint16_t seq_num) { | 107 void PacketBuffer::ClearTo(uint16_t seq_num) { |
| 98 rtc::CritScope lock(&crit_); | 108 rtc::CritScope lock(&crit_); |
| 99 size_t index = first_seq_num_ % size_; | 109 size_t index = first_seq_num_ % size_; |
| 100 while (AheadOf<uint16_t>(seq_num, first_seq_num_ + 1)) { | 110 while (AheadOf<uint16_t>(seq_num, first_seq_num_ + 1)) { |
| 101 index = (index + 1) % size_; | 111 index = (index + 1) % size_; |
| 102 first_seq_num_ = Add<1 << 16>(first_seq_num_, 1); | 112 ++first_seq_num_; |
| 113 delete[] data_buffer_[index].dataPtr; |
| 114 data_buffer_[index].dataPtr = nullptr; |
| 103 sequence_buffer_[index].used = false; | 115 sequence_buffer_[index].used = false; |
| 104 } | 116 } |
| 105 } | 117 } |
| 106 | 118 |
| 107 bool PacketBuffer::ExpandBufferSize() { | 119 bool PacketBuffer::ExpandBufferSize() { |
| 108 if (size_ == max_size_) | 120 if (size_ == max_size_) |
| 109 return false; | 121 return false; |
| 110 | 122 |
| 111 size_t new_size = std::min(max_size_, 2 * size_); | 123 size_t new_size = std::min(max_size_, 2 * size_); |
| 112 std::vector<VCMPacket> new_data_buffer(new_size); | 124 std::vector<VCMPacket> new_data_buffer(new_size); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 ++seq_num; | 196 ++seq_num; |
| 185 } | 197 } |
| 186 } | 198 } |
| 187 | 199 |
| 188 void PacketBuffer::ReturnFrame(RtpFrameObject* frame) { | 200 void PacketBuffer::ReturnFrame(RtpFrameObject* frame) { |
| 189 rtc::CritScope lock(&crit_); | 201 rtc::CritScope lock(&crit_); |
| 190 size_t index = frame->first_seq_num() % size_; | 202 size_t index = frame->first_seq_num() % size_; |
| 191 size_t end = (frame->last_seq_num() + 1) % size_; | 203 size_t end = (frame->last_seq_num() + 1) % size_; |
| 192 uint16_t seq_num = frame->first_seq_num(); | 204 uint16_t seq_num = frame->first_seq_num(); |
| 193 while (index != end) { | 205 while (index != end) { |
| 194 if (sequence_buffer_[index].seq_num == seq_num) | 206 if (sequence_buffer_[index].seq_num == seq_num) { |
| 207 delete[] data_buffer_[index].dataPtr; |
| 208 data_buffer_[index].dataPtr = nullptr; |
| 195 sequence_buffer_[index].used = false; | 209 sequence_buffer_[index].used = false; |
| 210 } |
| 196 | 211 |
| 197 index = (index + 1) % size_; | 212 index = (index + 1) % size_; |
| 198 ++seq_num; | 213 ++seq_num; |
| 199 } | 214 } |
| 200 | 215 |
| 201 index = first_seq_num_ % size_; | 216 index = first_seq_num_ % size_; |
| 202 while (AheadOf<uint16_t>(last_seq_num_, first_seq_num_) && | 217 while (AheadOf<uint16_t>(last_seq_num_, first_seq_num_) && |
| 203 !sequence_buffer_[index].used) { | 218 !sequence_buffer_[index].used) { |
| 204 ++first_seq_num_; | 219 ++first_seq_num_; |
| 205 index = (index + 1) % size_; | 220 index = (index + 1) % size_; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 int PacketBuffer::Release() const { | 269 int PacketBuffer::Release() const { |
| 255 int count = rtc::AtomicOps::Decrement(&ref_count_); | 270 int count = rtc::AtomicOps::Decrement(&ref_count_); |
| 256 if (!count) { | 271 if (!count) { |
| 257 delete this; | 272 delete this; |
| 258 } | 273 } |
| 259 return count; | 274 return count; |
| 260 } | 275 } |
| 261 | 276 |
| 262 } // namespace video_coding | 277 } // namespace video_coding |
| 263 } // namespace webrtc | 278 } // namespace webrtc |
| OLD | NEW |