Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 |
| 11 #include "webrtc/modules/rtp_rtcp/include/rtp_header_extension_map.h" | 11 #include "webrtc/modules/rtp_rtcp/include/rtp_header_extension_map.h" |
| 12 | 12 |
| 13 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" | 13 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" |
| 14 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | |
| 15 #include "webrtc/rtc_base/arraysize.h" | 14 #include "webrtc/rtc_base/arraysize.h" |
| 16 #include "webrtc/rtc_base/checks.h" | 15 #include "webrtc/rtc_base/checks.h" |
| 17 #include "webrtc/rtc_base/logging.h" | 16 #include "webrtc/rtc_base/logging.h" |
| 18 | 17 |
| 19 namespace webrtc { | 18 namespace webrtc { |
| 20 namespace { | 19 namespace { |
| 21 | 20 |
| 22 using RtpUtility::Word32Align; | |
| 23 | |
| 24 struct ExtensionInfo { | 21 struct ExtensionInfo { |
| 25 RTPExtensionType type; | 22 RTPExtensionType type; |
| 26 const char* uri; | 23 const char* uri; |
| 27 }; | 24 }; |
| 28 | 25 |
| 29 template <typename Extension> | 26 template <typename Extension> |
| 30 constexpr ExtensionInfo CreateExtensionInfo() { | 27 constexpr ExtensionInfo CreateExtensionInfo() { |
| 31 return {Extension::kId, Extension::kUri}; | 28 return {Extension::kId, Extension::kUri}; |
| 32 } | 29 } |
| 33 | 30 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 static constexpr size_t kRtpOneByteHeaderLength = 4; | 92 static constexpr size_t kRtpOneByteHeaderLength = 4; |
| 96 // Header size of each individual extension, see RFC5285 Section 4.2 | 93 // Header size of each individual extension, see RFC5285 Section 4.2 |
| 97 static constexpr size_t kExtensionHeaderLength = 1; | 94 static constexpr size_t kExtensionHeaderLength = 1; |
| 98 size_t values_size = 0; | 95 size_t values_size = 0; |
| 99 for (const RtpExtensionSize& extension : extensions) { | 96 for (const RtpExtensionSize& extension : extensions) { |
| 100 if (IsRegistered(extension.type)) | 97 if (IsRegistered(extension.type)) |
| 101 values_size += extension.value_size + kExtensionHeaderLength; | 98 values_size += extension.value_size + kExtensionHeaderLength; |
| 102 } | 99 } |
| 103 if (values_size == 0) | 100 if (values_size == 0) |
| 104 return 0; | 101 return 0; |
| 105 return Word32Align(kRtpOneByteHeaderLength + values_size); | 102 size_t size = kRtpOneByteHeaderLength + values_size; |
| 103 // Round up to the nearest size that is a multiple of 4. | |
| 104 // Which is same as round down (size + 3). | |
| 105 return size + 3 - (size + 3) % 4; | |
|
eladalon
2017/09/12 15:25:24
I still think this would be safer, clearer and mor
danilchap
2017/09/12 15:40:31
For any reasonable use (there are up to 16 types o
| |
| 106 } | 106 } |
| 107 | 107 |
| 108 int32_t RtpHeaderExtensionMap::Deregister(RTPExtensionType type) { | 108 int32_t RtpHeaderExtensionMap::Deregister(RTPExtensionType type) { |
| 109 if (IsRegistered(type)) { | 109 if (IsRegistered(type)) { |
| 110 uint8_t id = GetId(type); | 110 uint8_t id = GetId(type); |
| 111 types_[id] = kInvalidType; | 111 types_[id] = kInvalidType; |
| 112 ids_[type] = kInvalidId; | 112 ids_[type] = kInvalidId; |
| 113 } | 113 } |
| 114 return 0; | 114 return 0; |
| 115 } | 115 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 140 return false; | 140 return false; |
| 141 } | 141 } |
| 142 RTC_DCHECK(!IsRegistered(type)); | 142 RTC_DCHECK(!IsRegistered(type)); |
| 143 | 143 |
| 144 types_[id] = type; | 144 types_[id] = type; |
| 145 ids_[type] = id; | 145 ids_[type] = id; |
| 146 return true; | 146 return true; |
| 147 } | 147 } |
| 148 | 148 |
| 149 } // namespace webrtc | 149 } // namespace webrtc |
| OLD | NEW |