| 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 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_PACKET_H_ | 10 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_PACKET_H_ |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 using ExtensionType = RTPExtensionType; | 28 using ExtensionType = RTPExtensionType; |
| 29 using ExtensionManager = RtpHeaderExtensionMap; | 29 using ExtensionManager = RtpHeaderExtensionMap; |
| 30 static constexpr size_t kMaxExtensionHeaders = 14; | 30 static constexpr size_t kMaxExtensionHeaders = 14; |
| 31 | 31 |
| 32 // Parse and copy given buffer into Packet. | 32 // Parse and copy given buffer into Packet. |
| 33 bool Parse(const uint8_t* buffer, size_t size); | 33 bool Parse(const uint8_t* buffer, size_t size); |
| 34 | 34 |
| 35 // Parse and move given buffer into Packet. | 35 // Parse and move given buffer into Packet. |
| 36 bool Parse(rtc::CopyOnWriteBuffer packet); | 36 bool Parse(rtc::CopyOnWriteBuffer packet); |
| 37 | 37 |
| 38 // Maps parsed extensions to their types to allow use of GetExtension. | 38 // Maps extensions id to their types. |
| 39 // Used after parsing when |extensions| can't be provided until base rtp | 39 void IdentifyExtensions(const ExtensionManager& extensions); |
| 40 // header is parsed. | |
| 41 void IdentifyExtensions(const ExtensionManager* extensions); | |
| 42 | 40 |
| 43 // Header. | 41 // Header. |
| 44 bool Marker() const; | 42 bool Marker() const; |
| 45 uint8_t PayloadType() const; | 43 uint8_t PayloadType() const; |
| 46 uint16_t SequenceNumber() const; | 44 uint16_t SequenceNumber() const; |
| 47 uint32_t Timestamp() const; | 45 uint32_t Timestamp() const; |
| 48 uint32_t Ssrc() const; | 46 uint32_t Ssrc() const; |
| 49 std::vector<uint32_t> Csrcs() const; | 47 std::vector<uint32_t> Csrcs() const; |
| 50 | 48 |
| 51 // TODO(danilchap): Remove this function when all code update to use RtpPacket | 49 // TODO(danilchap): Remove this function when all code update to use RtpPacket |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 // Reserve size_bytes for payload. Returns nullptr on failure. | 97 // Reserve size_bytes for payload. Returns nullptr on failure. |
| 100 uint8_t* AllocatePayload(size_t size_bytes); | 98 uint8_t* AllocatePayload(size_t size_bytes); |
| 101 void SetPayloadSize(size_t size_bytes); | 99 void SetPayloadSize(size_t size_bytes); |
| 102 bool SetPadding(uint8_t size_bytes, Random* random); | 100 bool SetPadding(uint8_t size_bytes, Random* random); |
| 103 | 101 |
| 104 protected: | 102 protected: |
| 105 // |extensions| required for SetExtension/ReserveExtension functions during | 103 // |extensions| required for SetExtension/ReserveExtension functions during |
| 106 // packet creating and used if available in Parse function. | 104 // packet creating and used if available in Parse function. |
| 107 // Adding and getting extensions will fail until |extensions| is | 105 // Adding and getting extensions will fail until |extensions| is |
| 108 // provided via constructor or IdentifyExtensions function. | 106 // provided via constructor or IdentifyExtensions function. |
| 107 Packet(); |
| 109 explicit Packet(const ExtensionManager* extensions); | 108 explicit Packet(const ExtensionManager* extensions); |
| 110 Packet(const Packet&) = default; | 109 Packet(const Packet&) = default; |
| 111 Packet(const ExtensionManager* extensions, size_t capacity); | 110 Packet(const ExtensionManager* extensions, size_t capacity); |
| 112 virtual ~Packet(); | 111 virtual ~Packet(); |
| 113 | 112 |
| 114 Packet& operator=(const Packet&) = default; | 113 Packet& operator=(const Packet&) = default; |
| 115 | 114 |
| 116 private: | 115 private: |
| 117 struct ExtensionInfo { | 116 struct ExtensionInfo { |
| 118 ExtensionType type; | 117 ExtensionType type; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 137 // and the offset field will be set, then true is returned. If allocated, the | 136 // and the offset field will be set, then true is returned. If allocated, the |
| 138 // length field will be used for allocation and the offset update to indicate | 137 // length field will be used for allocation and the offset update to indicate |
| 139 // position, the true is returned. | 138 // position, the true is returned. |
| 140 // If not found and allocations fails, false is returned and parameter remains | 139 // If not found and allocations fails, false is returned and parameter remains |
| 141 // unchanged. | 140 // unchanged. |
| 142 bool AllocateExtension(ExtensionType type, uint8_t length, uint16_t* offset); | 141 bool AllocateExtension(ExtensionType type, uint8_t length, uint16_t* offset); |
| 143 | 142 |
| 144 uint8_t* WriteAt(size_t offset); | 143 uint8_t* WriteAt(size_t offset); |
| 145 void WriteAt(size_t offset, uint8_t byte); | 144 void WriteAt(size_t offset, uint8_t byte); |
| 146 | 145 |
| 147 const ExtensionManager* extensions_; | |
| 148 | |
| 149 // Header. | 146 // Header. |
| 150 bool marker_; | 147 bool marker_; |
| 151 uint8_t payload_type_; | 148 uint8_t payload_type_; |
| 152 uint8_t padding_size_; | 149 uint8_t padding_size_; |
| 153 uint16_t sequence_number_; | 150 uint16_t sequence_number_; |
| 154 uint32_t timestamp_; | 151 uint32_t timestamp_; |
| 155 uint32_t ssrc_; | 152 uint32_t ssrc_; |
| 156 size_t payload_offset_; // Match header size with csrcs and extensions. | 153 size_t payload_offset_; // Match header size with csrcs and extensions. |
| 157 size_t payload_size_; | 154 size_t payload_size_; |
| 158 | 155 |
| 159 uint8_t num_extensions_ = 0; | |
| 160 ExtensionInfo extension_entries_[kMaxExtensionHeaders]; | 156 ExtensionInfo extension_entries_[kMaxExtensionHeaders]; |
| 161 uint16_t extensions_size_ = 0; // Unaligned. | 157 uint16_t extensions_size_ = 0; // Unaligned. |
| 162 rtc::CopyOnWriteBuffer buffer_; | 158 rtc::CopyOnWriteBuffer buffer_; |
| 163 | |
| 164 Packet() = delete; | |
| 165 }; | 159 }; |
| 166 | 160 |
| 167 template <typename Extension> | 161 template <typename Extension> |
| 168 bool Packet::HasExtension() const { | 162 bool Packet::HasExtension() const { |
| 169 uint16_t offset = 0; | 163 uint16_t offset = 0; |
| 170 return FindExtension(Extension::kId, Extension::kValueSizeBytes, &offset); | 164 return FindExtension(Extension::kId, Extension::kValueSizeBytes, &offset); |
| 171 } | 165 } |
| 172 | 166 |
| 173 template <typename Extension, typename... Values> | 167 template <typename Extension, typename... Values> |
| 174 bool Packet::GetExtension(Values... values) const { | 168 bool Packet::GetExtension(Values... values) const { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 191 uint16_t offset = 0; | 185 uint16_t offset = 0; |
| 192 if (!AllocateExtension(Extension::kId, Extension::kValueSizeBytes, &offset)) | 186 if (!AllocateExtension(Extension::kId, Extension::kValueSizeBytes, &offset)) |
| 193 return false; | 187 return false; |
| 194 memset(WriteAt(offset), 0, Extension::kValueSizeBytes); | 188 memset(WriteAt(offset), 0, Extension::kValueSizeBytes); |
| 195 return true; | 189 return true; |
| 196 } | 190 } |
| 197 } // namespace rtp | 191 } // namespace rtp |
| 198 } // namespace webrtc | 192 } // namespace webrtc |
| 199 | 193 |
| 200 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_PACKET_H_ | 194 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_PACKET_H_ |
| OLD | NEW |