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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 timestamp_ = timestamp; | 246 timestamp_ = timestamp; |
247 ByteWriter<uint32_t>::WriteBigEndian(WriteAt(4), timestamp); | 247 ByteWriter<uint32_t>::WriteBigEndian(WriteAt(4), timestamp); |
248 } | 248 } |
249 | 249 |
250 void Packet::SetSsrc(uint32_t ssrc) { | 250 void Packet::SetSsrc(uint32_t ssrc) { |
251 ssrc_ = ssrc; | 251 ssrc_ = ssrc; |
252 ByteWriter<uint32_t>::WriteBigEndian(WriteAt(8), ssrc); | 252 ByteWriter<uint32_t>::WriteBigEndian(WriteAt(8), ssrc); |
253 } | 253 } |
254 | 254 |
255 void Packet::SetCsrcs(const std::vector<uint32_t>& csrcs) { | 255 void Packet::SetCsrcs(const std::vector<uint32_t>& csrcs) { |
256 RTC_DCHECK_EQ(num_extensions_, 0u); | 256 RTC_DCHECK_EQ(num_extensions_, 0); |
257 RTC_DCHECK_EQ(payload_size_, 0u); | 257 RTC_DCHECK_EQ(payload_size_, 0); |
258 RTC_DCHECK_EQ(padding_size_, 0u); | 258 RTC_DCHECK_EQ(padding_size_, 0); |
259 RTC_DCHECK_LE(csrcs.size(), 0x0fu); | 259 RTC_DCHECK_LE(csrcs.size(), 0x0fu); |
260 RTC_DCHECK_LE(kFixedHeaderSize + 4 * csrcs.size(), capacity()); | 260 RTC_DCHECK_LE(kFixedHeaderSize + 4 * csrcs.size(), capacity()); |
261 payload_offset_ = kFixedHeaderSize + 4 * csrcs.size(); | 261 payload_offset_ = kFixedHeaderSize + 4 * csrcs.size(); |
262 WriteAt(0, (data()[0] & 0xF0) | csrcs.size()); | 262 WriteAt(0, (data()[0] & 0xF0) | csrcs.size()); |
263 size_t offset = kFixedHeaderSize; | 263 size_t offset = kFixedHeaderSize; |
264 for (uint32_t csrc : csrcs) { | 264 for (uint32_t csrc : csrcs) { |
265 ByteWriter<uint32_t>::WriteBigEndian(WriteAt(offset), csrc); | 265 ByteWriter<uint32_t>::WriteBigEndian(WriteAt(offset), csrc); |
266 offset += 4; | 266 offset += 4; |
267 } | 267 } |
268 buffer_.SetSize(payload_offset_); | 268 buffer_.SetSize(payload_offset_); |
269 } | 269 } |
270 | 270 |
271 uint8_t* Packet::AllocatePayload(size_t size_bytes) { | 271 uint8_t* Packet::AllocatePayload(size_t size_bytes) { |
272 RTC_DCHECK_EQ(padding_size_, 0u); | 272 RTC_DCHECK_EQ(padding_size_, 0); |
273 if (payload_offset_ + size_bytes > capacity()) { | 273 if (payload_offset_ + size_bytes > capacity()) { |
274 LOG(LS_WARNING) << "Cannot set payload, not enough space in buffer."; | 274 LOG(LS_WARNING) << "Cannot set payload, not enough space in buffer."; |
275 return nullptr; | 275 return nullptr; |
276 } | 276 } |
277 // Reset payload size to 0. If CopyOnWrite buffer_ was shared, this will cause | 277 // Reset payload size to 0. If CopyOnWrite buffer_ was shared, this will cause |
278 // reallocation and memcpy. Setting size to just headers reduces memcpy size. | 278 // reallocation and memcpy. Setting size to just headers reduces memcpy size. |
279 buffer_.SetSize(payload_offset_); | 279 buffer_.SetSize(payload_offset_); |
280 payload_size_ = size_bytes; | 280 payload_size_ = size_bytes; |
281 buffer_.SetSize(payload_offset_ + payload_size_); | 281 buffer_.SetSize(payload_offset_ + payload_size_); |
282 return WriteAt(payload_offset_); | 282 return WriteAt(payload_offset_); |
283 } | 283 } |
284 | 284 |
285 void Packet::SetPayloadSize(size_t size_bytes) { | 285 void Packet::SetPayloadSize(size_t size_bytes) { |
286 RTC_DCHECK_EQ(padding_size_, 0u); | 286 RTC_DCHECK_EQ(padding_size_, 0); |
287 RTC_DCHECK_LE(size_bytes, payload_size_); | 287 RTC_DCHECK_LE(size_bytes, payload_size_); |
288 payload_size_ = size_bytes; | 288 payload_size_ = size_bytes; |
289 buffer_.SetSize(payload_offset_ + payload_size_); | 289 buffer_.SetSize(payload_offset_ + payload_size_); |
290 } | 290 } |
291 | 291 |
292 bool Packet::SetPadding(uint8_t size_bytes, Random* random) { | 292 bool Packet::SetPadding(uint8_t size_bytes, Random* random) { |
293 RTC_DCHECK(random); | 293 RTC_DCHECK(random); |
294 if (payload_offset_ + payload_size_ + size_bytes > capacity()) { | 294 if (payload_offset_ + payload_size_ + size_bytes > capacity()) { |
295 LOG(LS_WARNING) << "Cannot set padding size " << size_bytes << ", only " | 295 LOG(LS_WARNING) << "Cannot set padding size " << size_bytes << ", only " |
296 << (capacity() - payload_offset_ - payload_size_) | 296 << (capacity() - payload_offset_ - payload_size_) |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 return false; | 466 return false; |
467 } | 467 } |
468 if (padding_size_ > 0) { | 468 if (padding_size_ > 0) { |
469 return false; | 469 return false; |
470 } | 470 } |
471 | 471 |
472 uint8_t extension_id = extensions_->GetId(type); | 472 uint8_t extension_id = extensions_->GetId(type); |
473 if (extension_id == ExtensionManager::kInvalidId) { | 473 if (extension_id == ExtensionManager::kInvalidId) { |
474 return false; | 474 return false; |
475 } | 475 } |
476 RTC_DCHECK_GT(length, 0u); | 476 RTC_DCHECK_GT(length, 0); |
477 RTC_DCHECK_LE(length, 16u); | 477 RTC_DCHECK_LE(length, 16); |
478 | 478 |
479 size_t num_csrc = data()[0] & 0x0F; | 479 size_t num_csrc = data()[0] & 0x0F; |
480 size_t extensions_offset = kFixedHeaderSize + (num_csrc * 4) + 4; | 480 size_t extensions_offset = kFixedHeaderSize + (num_csrc * 4) + 4; |
481 if (extensions_offset + extensions_size_ + kOneByteHeaderSize + length > | 481 if (extensions_offset + extensions_size_ + kOneByteHeaderSize + length > |
482 capacity()) { | 482 capacity()) { |
483 LOG(LS_WARNING) << "Extension cannot be registered: " | 483 LOG(LS_WARNING) << "Extension cannot be registered: " |
484 "Not enough space left in buffer."; | 484 "Not enough space left in buffer."; |
485 return false; | 485 return false; |
486 } | 486 } |
487 | 487 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 uint8_t* Packet::WriteAt(size_t offset) { | 525 uint8_t* Packet::WriteAt(size_t offset) { |
526 return buffer_.data() + offset; | 526 return buffer_.data() + offset; |
527 } | 527 } |
528 | 528 |
529 void Packet::WriteAt(size_t offset, uint8_t byte) { | 529 void Packet::WriteAt(size_t offset, uint8_t byte) { |
530 buffer_.data()[offset] = byte; | 530 buffer_.data()[offset] = byte; |
531 } | 531 } |
532 | 532 |
533 } // namespace rtp | 533 } // namespace rtp |
534 } // namespace webrtc | 534 } // namespace webrtc |
OLD | NEW |