Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_packet.h

Issue 2789773004: Add functions to get/set rtp header extension by id. (Closed)
Patch Set: nits Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/modules/rtp_rtcp/source/rtp_packet.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10 matching lines...) Expand all
21 struct RTPHeader; 21 struct RTPHeader;
22 class RtpHeaderExtensionMap; 22 class RtpHeaderExtensionMap;
23 class Random; 23 class Random;
24 24
25 namespace rtp { 25 namespace rtp {
26 class Packet { 26 class Packet {
27 public: 27 public:
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 static constexpr int kMinExtensionId = 1;
32 static constexpr int kMaxExtensionId = 14;
31 33
32 // Parse and copy given buffer into Packet. 34 // Parse and copy given buffer into Packet.
33 bool Parse(const uint8_t* buffer, size_t size); 35 bool Parse(const uint8_t* buffer, size_t size);
34 bool Parse(rtc::ArrayView<const uint8_t> packet); 36 bool Parse(rtc::ArrayView<const uint8_t> packet);
35 37
36 // Parse and move given buffer into Packet. 38 // Parse and move given buffer into Packet.
37 bool Parse(rtc::CopyOnWriteBuffer packet); 39 bool Parse(rtc::CopyOnWriteBuffer packet);
38 40
39 // Maps extensions id to their types. 41 // Maps extensions id to their types.
40 void IdentifyExtensions(const ExtensionManager& extensions); 42 void IdentifyExtensions(const ExtensionManager& extensions);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 90
89 template <typename Extension, typename... Values> 91 template <typename Extension, typename... Values>
90 bool GetExtension(Values...) const; 92 bool GetExtension(Values...) const;
91 93
92 template <typename Extension, typename... Values> 94 template <typename Extension, typename... Values>
93 bool SetExtension(Values...); 95 bool SetExtension(Values...);
94 96
95 template <typename Extension> 97 template <typename Extension>
96 bool ReserveExtension(); 98 bool ReserveExtension();
97 99
100 // Following 4 helpers identify rtp header extension by |id| negotiated with
101 // remote peer and written in an rtp packet.
102 bool HasRawExtension(int id) const;
103
104 // Returns place where extension with |id| is stored.
105 // Returns empty arrayview if extension is not present.
106 rtc::ArrayView<const uint8_t> GetRawExtension(int id) const;
107
108 // Allocates and store header extension. Returns true on success.
109 bool SetRawExtension(int id, rtc::ArrayView<const uint8_t> data);
110
111 // Allocates and returns place to store rtp header extension.
112 // Returns empty arrayview on failure.
113 rtc::ArrayView<uint8_t> AllocateRawExtension(int id, size_t length);
114
98 // Reserve size_bytes for payload. Returns nullptr on failure. 115 // Reserve size_bytes for payload. Returns nullptr on failure.
99 uint8_t* SetPayloadSize(size_t size_bytes); 116 uint8_t* SetPayloadSize(size_t size_bytes);
100 // Same as SetPayloadSize but doesn't guarantee to keep current payload. 117 // Same as SetPayloadSize but doesn't guarantee to keep current payload.
101 uint8_t* AllocatePayload(size_t size_bytes); 118 uint8_t* AllocatePayload(size_t size_bytes);
102 bool SetPadding(uint8_t size_bytes, Random* random); 119 bool SetPadding(uint8_t size_bytes, Random* random);
103 120
104 protected: 121 protected:
105 // |extensions| required for SetExtension/ReserveExtension functions during 122 // |extensions| required for SetExtension/ReserveExtension functions during
106 // packet creating and used if available in Parse function. 123 // packet creating and used if available in Parse function.
107 // Adding and getting extensions will fail until |extensions| is 124 // Adding and getting extensions will fail until |extensions| is
(...skipping 18 matching lines...) Expand all
126 bool ParseBuffer(const uint8_t* buffer, size_t size); 143 bool ParseBuffer(const uint8_t* buffer, size_t size);
127 144
128 // Find an extension based on the type field of the parameter. 145 // Find an extension based on the type field of the parameter.
129 // If found, length field would be validated, the offset field will be set 146 // If found, length field would be validated, the offset field will be set
130 // and true returned, 147 // and true returned,
131 // otherwise the parameter will be unchanged and false is returned. 148 // otherwise the parameter will be unchanged and false is returned.
132 bool FindExtension(ExtensionType type, 149 bool FindExtension(ExtensionType type,
133 uint8_t length, 150 uint8_t length,
134 uint16_t* offset) const; 151 uint16_t* offset) const;
135 152
136 // Find or allocate an extension, based on the type field of the parameter. 153 // Find or allocate an extension |type|. Returns view of size |length|
137 // If found, the length field be checked against what is already registered 154 // to write raw extension to or an empty view on failure.
138 // and the offset field will be set, then true is returned. If allocated, the 155 rtc::ArrayView<uint8_t> AllocateExtension(ExtensionType type, size_t length);
139 // length field will be used for allocation and the offset update to indicate
140 // position, the true is returned.
141 // If not found and allocations fails, false is returned and parameter remains
142 // unchanged.
143 bool AllocateExtension(ExtensionType type, uint8_t length, uint16_t* offset);
144 156
145 uint8_t* WriteAt(size_t offset); 157 uint8_t* WriteAt(size_t offset);
146 void WriteAt(size_t offset, uint8_t byte); 158 void WriteAt(size_t offset, uint8_t byte);
147 159
148 // Header. 160 // Header.
149 bool marker_; 161 bool marker_;
150 uint8_t payload_type_; 162 uint8_t payload_type_;
151 uint8_t padding_size_; 163 uint8_t padding_size_;
152 uint16_t sequence_number_; 164 uint16_t sequence_number_;
153 uint32_t timestamp_; 165 uint32_t timestamp_;
(...skipping 15 matching lines...) Expand all
169 template <typename Extension, typename... Values> 181 template <typename Extension, typename... Values>
170 bool Packet::GetExtension(Values... values) const { 182 bool Packet::GetExtension(Values... values) const {
171 uint16_t offset = 0; 183 uint16_t offset = 0;
172 if (!FindExtension(Extension::kId, Extension::kValueSizeBytes, &offset)) 184 if (!FindExtension(Extension::kId, Extension::kValueSizeBytes, &offset))
173 return false; 185 return false;
174 return Extension::Parse(data() + offset, values...); 186 return Extension::Parse(data() + offset, values...);
175 } 187 }
176 188
177 template <typename Extension, typename... Values> 189 template <typename Extension, typename... Values>
178 bool Packet::SetExtension(Values... values) { 190 bool Packet::SetExtension(Values... values) {
179 uint16_t offset = 0; 191 auto buffer = AllocateExtension(Extension::kId, Extension::kValueSizeBytes);
180 if (!AllocateExtension(Extension::kId, Extension::kValueSizeBytes, &offset)) 192 if (buffer.empty())
181 return false; 193 return false;
182 return Extension::Write(WriteAt(offset), values...); 194 return Extension::Write(buffer.data(), values...);
183 } 195 }
184 196
185 template <typename Extension> 197 template <typename Extension>
186 bool Packet::ReserveExtension() { 198 bool Packet::ReserveExtension() {
187 uint16_t offset = 0; 199 auto buffer = AllocateExtension(Extension::kId, Extension::kValueSizeBytes);
188 if (!AllocateExtension(Extension::kId, Extension::kValueSizeBytes, &offset)) 200 if (buffer.empty())
189 return false; 201 return false;
190 memset(WriteAt(offset), 0, Extension::kValueSizeBytes); 202 memset(buffer.data(), 0, Extension::kValueSizeBytes);
191 return true; 203 return true;
192 } 204 }
193 } // namespace rtp 205 } // namespace rtp
194 } // namespace webrtc 206 } // namespace webrtc
195 207
196 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_PACKET_H_ 208 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_PACKET_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/rtp_rtcp/source/rtp_packet.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698