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 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 payload_offset_ = extension_offset + extensions_capacity; | 526 payload_offset_ = extension_offset + extensions_capacity; |
527 } | 527 } |
528 | 528 |
529 if (payload_offset_ + padding_size_ > size) { | 529 if (payload_offset_ + padding_size_ > size) { |
530 return false; | 530 return false; |
531 } | 531 } |
532 payload_size_ = size - payload_offset_ - padding_size_; | 532 payload_size_ = size - payload_offset_ - padding_size_; |
533 return true; | 533 return true; |
534 } | 534 } |
535 | 535 |
536 bool Packet::FindExtension(ExtensionType type, | 536 rtc::ArrayView<const uint8_t> Packet::FindExtension(ExtensionType type) const { |
537 uint8_t length, | |
538 uint16_t* offset) const { | |
539 RTC_DCHECK(offset); | |
540 for (const ExtensionInfo& extension : extension_entries_) { | 537 for (const ExtensionInfo& extension : extension_entries_) { |
541 if (extension.type == type) { | 538 if (extension.type == type) { |
542 if (extension.length == 0) { | 539 if (extension.length == 0) { |
543 // Extension is registered but not set. | 540 // Extension is registered but not set. |
544 return false; | 541 return nullptr; |
545 } | 542 } |
546 if (length != extension.length) { | 543 return rtc::MakeArrayView(data() + extension.offset, extension.length); |
547 LOG(LS_WARNING) << "Length mismatch for extension '" << type | |
548 << "': expected " << static_cast<int>(length) | |
549 << ", received " << static_cast<int>(extension.length); | |
550 return false; | |
551 } | |
552 *offset = extension.offset; | |
553 return true; | |
554 } | 544 } |
555 } | 545 } |
556 return false; | 546 return nullptr; |
557 } | 547 } |
558 | 548 |
559 rtc::ArrayView<uint8_t> Packet::AllocateExtension(ExtensionType type, | 549 rtc::ArrayView<uint8_t> Packet::AllocateExtension(ExtensionType type, |
560 size_t length) { | 550 size_t length) { |
561 for (size_t i = 0; i < kMaxExtensionHeaders; ++i) { | 551 for (size_t i = 0; i < kMaxExtensionHeaders; ++i) { |
562 if (extension_entries_[i].type == type) { | 552 if (extension_entries_[i].type == type) { |
563 int extension_id = i + 1; | 553 int extension_id = i + 1; |
564 return AllocateRawExtension(extension_id, length); | 554 return AllocateRawExtension(extension_id, length); |
565 } | 555 } |
566 } | 556 } |
567 // Extension not registered. | 557 // Extension not registered. |
568 return nullptr; | 558 return nullptr; |
569 } | 559 } |
570 | 560 |
571 uint8_t* Packet::WriteAt(size_t offset) { | 561 uint8_t* Packet::WriteAt(size_t offset) { |
572 return buffer_.data() + offset; | 562 return buffer_.data() + offset; |
573 } | 563 } |
574 | 564 |
575 void Packet::WriteAt(size_t offset, uint8_t byte) { | 565 void Packet::WriteAt(size_t offset, uint8_t byte) { |
576 buffer_.data()[offset] = byte; | 566 buffer_.data()[offset] = byte; |
577 } | 567 } |
578 | 568 |
579 } // namespace rtp | 569 } // namespace rtp |
580 } // namespace webrtc | 570 } // namespace webrtc |
OLD | NEW |