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

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

Issue 2801733002: Move rtp header extension length check from Packet::FindExtension to ExtensionT::Parse (Closed)
Patch Set: 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
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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 struct ExtensionInfo { 135 struct ExtensionInfo {
136 ExtensionType type; 136 ExtensionType type;
137 uint16_t offset; 137 uint16_t offset;
138 uint8_t length; 138 uint8_t length;
139 }; 139 };
140 140
141 // Helper function for Parse. Fill header fields using data in given buffer, 141 // Helper function for Parse. Fill header fields using data in given buffer,
142 // but does not touch packet own buffer, leaving packet in invalid state. 142 // but does not touch packet own buffer, leaving packet in invalid state.
143 bool ParseBuffer(const uint8_t* buffer, size_t size); 143 bool ParseBuffer(const uint8_t* buffer, size_t size);
144 144
145 // Find an extension based on the type field of the parameter. 145 // Find an extension |type|.
146 // If found, length field would be validated, the offset field will be set 146 // Returns view of the raw extension or empty view on failure.
147 // and true returned, 147 rtc::ArrayView<const uint8_t> FindExtension(ExtensionType type) const;
148 // otherwise the parameter will be unchanged and false is returned.
149 bool FindExtension(ExtensionType type,
150 uint8_t length,
151 uint16_t* offset) const;
152 148
153 // Find or allocate an extension |type|. Returns view of size |length| 149 // Find or allocate an extension |type|. Returns view of size |length|
154 // to write raw extension to or an empty view on failure. 150 // to write raw extension to or an empty view on failure.
155 rtc::ArrayView<uint8_t> AllocateExtension(ExtensionType type, size_t length); 151 rtc::ArrayView<uint8_t> AllocateExtension(ExtensionType type, size_t length);
156 152
157 uint8_t* WriteAt(size_t offset); 153 uint8_t* WriteAt(size_t offset);
158 void WriteAt(size_t offset, uint8_t byte); 154 void WriteAt(size_t offset, uint8_t byte);
159 155
160 // Header. 156 // Header.
161 bool marker_; 157 bool marker_;
162 uint8_t payload_type_; 158 uint8_t payload_type_;
163 uint8_t padding_size_; 159 uint8_t padding_size_;
164 uint16_t sequence_number_; 160 uint16_t sequence_number_;
165 uint32_t timestamp_; 161 uint32_t timestamp_;
166 uint32_t ssrc_; 162 uint32_t ssrc_;
167 size_t payload_offset_; // Match header size with csrcs and extensions. 163 size_t payload_offset_; // Match header size with csrcs and extensions.
168 size_t payload_size_; 164 size_t payload_size_;
169 165
170 ExtensionInfo extension_entries_[kMaxExtensionHeaders]; 166 ExtensionInfo extension_entries_[kMaxExtensionHeaders];
171 uint16_t extensions_size_ = 0; // Unaligned. 167 uint16_t extensions_size_ = 0; // Unaligned.
172 rtc::CopyOnWriteBuffer buffer_; 168 rtc::CopyOnWriteBuffer buffer_;
173 }; 169 };
174 170
175 template <typename Extension> 171 template <typename Extension>
176 bool Packet::HasExtension() const { 172 bool Packet::HasExtension() const {
177 uint16_t offset = 0; 173 return !FindExtension(Extension::kId).empty();
178 return FindExtension(Extension::kId, Extension::kValueSizeBytes, &offset);
179 } 174 }
180 175
181 template <typename Extension, typename... Values> 176 template <typename Extension, typename... Values>
182 bool Packet::GetExtension(Values... values) const { 177 bool Packet::GetExtension(Values... values) const {
183 uint16_t offset = 0; 178 auto raw = FindExtension(Extension::kId);
184 if (!FindExtension(Extension::kId, Extension::kValueSizeBytes, &offset)) 179 if (raw.empty())
185 return false; 180 return false;
186 return Extension::Parse(data() + offset, values...); 181 return Extension::Parse(raw, values...);
187 } 182 }
188 183
189 template <typename Extension, typename... Values> 184 template <typename Extension, typename... Values>
190 bool Packet::SetExtension(Values... values) { 185 bool Packet::SetExtension(Values... values) {
191 auto buffer = AllocateExtension(Extension::kId, Extension::kValueSizeBytes); 186 auto buffer = AllocateExtension(Extension::kId, Extension::kValueSizeBytes);
192 if (buffer.empty()) 187 if (buffer.empty())
193 return false; 188 return false;
194 return Extension::Write(buffer.data(), values...); 189 return Extension::Write(buffer.data(), values...);
195 } 190 }
196 191
197 template <typename Extension> 192 template <typename Extension>
198 bool Packet::ReserveExtension() { 193 bool Packet::ReserveExtension() {
199 auto buffer = AllocateExtension(Extension::kId, Extension::kValueSizeBytes); 194 auto buffer = AllocateExtension(Extension::kId, Extension::kValueSizeBytes);
200 if (buffer.empty()) 195 if (buffer.empty())
201 return false; 196 return false;
202 memset(buffer.data(), 0, Extension::kValueSizeBytes); 197 memset(buffer.data(), 0, Extension::kValueSizeBytes);
203 return true; 198 return true;
204 } 199 }
205 } // namespace rtp 200 } // namespace rtp
206 } // namespace webrtc 201 } // namespace webrtc
207 202
208 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_PACKET_H_ 203 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_PACKET_H_
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_header_extensions.cc ('k') | webrtc/modules/rtp_rtcp/source/rtp_packet.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698