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

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

Issue 2803623004: Allow rtp::Packet::*RawExtension to take 0 as an extension id (Closed)
Patch Set: +AllocateRawExtension 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_unittest.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 10
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 WriteAt(0, (data()[0] & 0xF0) | csrcs.size()); 272 WriteAt(0, (data()[0] & 0xF0) | csrcs.size());
273 size_t offset = kFixedHeaderSize; 273 size_t offset = kFixedHeaderSize;
274 for (uint32_t csrc : csrcs) { 274 for (uint32_t csrc : csrcs) {
275 ByteWriter<uint32_t>::WriteBigEndian(WriteAt(offset), csrc); 275 ByteWriter<uint32_t>::WriteBigEndian(WriteAt(offset), csrc);
276 offset += 4; 276 offset += 4;
277 } 277 }
278 buffer_.SetSize(payload_offset_); 278 buffer_.SetSize(payload_offset_);
279 } 279 }
280 280
281 bool Packet::HasRawExtension(int id) const { 281 bool Packet::HasRawExtension(int id) const {
282 if (id == ExtensionManager::kInvalidId)
283 return false;
282 RTC_DCHECK_GE(id, kMinExtensionId); 284 RTC_DCHECK_GE(id, kMinExtensionId);
283 RTC_DCHECK_LE(id, kMaxExtensionId); 285 RTC_DCHECK_LE(id, kMaxExtensionId);
284 return extension_entries_[id - 1].offset != 0; 286 return extension_entries_[id - 1].offset != 0;
285 } 287 }
286 288
287 rtc::ArrayView<const uint8_t> Packet::GetRawExtension(int id) const { 289 rtc::ArrayView<const uint8_t> Packet::GetRawExtension(int id) const {
290 if (id == ExtensionManager::kInvalidId)
291 return nullptr;
288 RTC_DCHECK_GE(id, kMinExtensionId); 292 RTC_DCHECK_GE(id, kMinExtensionId);
289 RTC_DCHECK_LE(id, kMaxExtensionId); 293 RTC_DCHECK_LE(id, kMaxExtensionId);
290 const ExtensionInfo& extension = extension_entries_[id - 1]; 294 const ExtensionInfo& extension = extension_entries_[id - 1];
291 if (extension.offset == 0) 295 if (extension.offset == 0)
292 return nullptr; 296 return nullptr;
293 return rtc::MakeArrayView(data() + extension.offset, extension.length); 297 return rtc::MakeArrayView(data() + extension.offset, extension.length);
294 } 298 }
295 299
296 bool Packet::SetRawExtension(int id, rtc::ArrayView<const uint8_t> data) { 300 bool Packet::SetRawExtension(int id, rtc::ArrayView<const uint8_t> data) {
297 auto buffer = AllocateRawExtension(id, data.size()); 301 auto buffer = AllocateRawExtension(id, data.size());
298 if (buffer.empty()) 302 if (buffer.empty())
299 return false; 303 return false;
300 RTC_DCHECK_EQ(buffer.size(), data.size()); 304 RTC_DCHECK_EQ(buffer.size(), data.size());
301 memcpy(buffer.data(), data.data(), data.size()); 305 memcpy(buffer.data(), data.data(), data.size());
302 return true; 306 return true;
303 } 307 }
304 308
305 rtc::ArrayView<uint8_t> Packet::AllocateRawExtension(int id, size_t length) { 309 rtc::ArrayView<uint8_t> Packet::AllocateRawExtension(int id, size_t length) {
310 if (id == ExtensionManager::kInvalidId)
311 return nullptr;
306 RTC_DCHECK_GE(id, kMinExtensionId); 312 RTC_DCHECK_GE(id, kMinExtensionId);
307 RTC_DCHECK_LE(id, kMaxExtensionId); 313 RTC_DCHECK_LE(id, kMaxExtensionId);
308 RTC_DCHECK_GE(length, 1); 314 RTC_DCHECK_GE(length, 1);
309 RTC_DCHECK_LE(length, 16); 315 RTC_DCHECK_LE(length, 16);
310 316
311 ExtensionInfo* extension_entry = &extension_entries_[id - 1]; 317 ExtensionInfo* extension_entry = &extension_entries_[id - 1];
312 if (extension_entry->offset != 0) { 318 if (extension_entry->offset != 0) {
313 // Extension already reserved. Check if same length is used. 319 // Extension already reserved. Check if same length is used.
314 if (extension_entry->length == length) 320 if (extension_entry->length == length)
315 return rtc::MakeArrayView(WriteAt(extension_entry->offset), length); 321 return rtc::MakeArrayView(WriteAt(extension_entry->offset), length);
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 uint8_t* Packet::WriteAt(size_t offset) { 567 uint8_t* Packet::WriteAt(size_t offset) {
562 return buffer_.data() + offset; 568 return buffer_.data() + offset;
563 } 569 }
564 570
565 void Packet::WriteAt(size_t offset, uint8_t byte) { 571 void Packet::WriteAt(size_t offset, uint8_t byte) {
566 buffer_.data()[offset] = byte; 572 buffer_.data()[offset] = byte;
567 } 573 }
568 574
569 } // namespace rtp 575 } // namespace rtp
570 } // namespace webrtc 576 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/rtp_rtcp/source/rtp_packet_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698