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 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 // Because of kRtpExtensionNone, NumberOfExtension is 1 bigger than the actual | 45 // Because of kRtpExtensionNone, NumberOfExtension is 1 bigger than the actual |
46 // number of known extensions. | 46 // number of known extensions. |
47 static_assert(arraysize(kExtensions) == | 47 static_assert(arraysize(kExtensions) == |
48 static_cast<int>(kRtpExtensionNumberOfExtensions) - 1, | 48 static_cast<int>(kRtpExtensionNumberOfExtensions) - 1, |
49 "kExtensions expect to list all known extensions"); | 49 "kExtensions expect to list all known extensions"); |
50 | 50 |
51 } // namespace | 51 } // namespace |
52 | 52 |
53 constexpr RTPExtensionType RtpHeaderExtensionMap::kInvalidType; | 53 constexpr RTPExtensionType RtpHeaderExtensionMap::kInvalidType; |
54 constexpr uint8_t RtpHeaderExtensionMap::kInvalidId; | 54 constexpr int RtpHeaderExtensionMap::kInvalidId; |
55 constexpr uint8_t RtpHeaderExtensionMap::kMinId; | 55 constexpr int RtpHeaderExtensionMap::kMinId; |
56 constexpr uint8_t RtpHeaderExtensionMap::kMaxId; | 56 constexpr int RtpHeaderExtensionMap::kMaxId; |
57 | 57 |
58 RtpHeaderExtensionMap::RtpHeaderExtensionMap() { | 58 RtpHeaderExtensionMap::RtpHeaderExtensionMap() { |
59 for (auto& type : types_) | 59 for (auto& type : types_) |
60 type = kInvalidType; | 60 type = kInvalidType; |
61 for (auto& id : ids_) | 61 for (auto& id : ids_) |
62 id = kInvalidId; | 62 id = kInvalidId; |
63 } | 63 } |
64 | 64 |
65 RtpHeaderExtensionMap::RtpHeaderExtensionMap( | 65 RtpHeaderExtensionMap::RtpHeaderExtensionMap( |
66 rtc::ArrayView<const RtpExtension> extensions) | 66 rtc::ArrayView<const RtpExtension> extensions) |
67 : RtpHeaderExtensionMap() { | 67 : RtpHeaderExtensionMap() { |
68 for (const RtpExtension& extension : extensions) | 68 for (const RtpExtension& extension : extensions) |
69 RegisterByUri(extension.id, extension.uri); | 69 RegisterByUri(extension.id, extension.uri); |
70 } | 70 } |
71 | 71 |
72 bool RtpHeaderExtensionMap::RegisterByType(uint8_t id, RTPExtensionType type) { | 72 bool RtpHeaderExtensionMap::RegisterByType(int id, RTPExtensionType type) { |
73 for (const ExtensionInfo& extension : kExtensions) | 73 for (const ExtensionInfo& extension : kExtensions) |
74 if (type == extension.type) | 74 if (type == extension.type) |
75 return Register(id, extension.type, extension.uri); | 75 return Register(id, extension.type, extension.uri); |
76 RTC_NOTREACHED(); | 76 RTC_NOTREACHED(); |
77 return false; | 77 return false; |
78 } | 78 } |
79 | 79 |
80 bool RtpHeaderExtensionMap::RegisterByUri(uint8_t id, const std::string& uri) { | 80 bool RtpHeaderExtensionMap::RegisterByUri(int id, const std::string& uri) { |
81 for (const ExtensionInfo& extension : kExtensions) | 81 for (const ExtensionInfo& extension : kExtensions) |
82 if (uri == extension.uri) | 82 if (uri == extension.uri) |
83 return Register(id, extension.type, extension.uri); | 83 return Register(id, extension.type, extension.uri); |
84 LOG(LS_WARNING) << "Unknown extension uri:'" << uri | 84 LOG(LS_WARNING) << "Unknown extension uri:'" << uri |
85 << "', id: " << static_cast<int>(id) << '.'; | 85 << "', id: " << id << '.'; |
86 return false; | 86 return false; |
87 } | 87 } |
88 | 88 |
89 size_t RtpHeaderExtensionMap::GetTotalLengthInBytes( | 89 size_t RtpHeaderExtensionMap::GetTotalLengthInBytes( |
90 rtc::ArrayView<const RtpExtensionSize> extensions) const { | 90 rtc::ArrayView<const RtpExtensionSize> extensions) const { |
91 // Header size of the extension block, see RFC3550 Section 5.3.1 | 91 // Header size of the extension block, see RFC3550 Section 5.3.1 |
92 static constexpr size_t kRtpOneByteHeaderLength = 4; | 92 static constexpr size_t kRtpOneByteHeaderLength = 4; |
93 // Header size of each individual extension, see RFC5285 Section 4.2 | 93 // Header size of each individual extension, see RFC5285 Section 4.2 |
94 static constexpr size_t kExtensionHeaderLength = 1; | 94 static constexpr size_t kExtensionHeaderLength = 1; |
95 size_t values_size = 0; | 95 size_t values_size = 0; |
(...skipping 11 matching lines...) Expand all Loading... |
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 } |
116 | 116 |
117 bool RtpHeaderExtensionMap::Register(uint8_t id, | 117 bool RtpHeaderExtensionMap::Register(int id, |
118 RTPExtensionType type, | 118 RTPExtensionType type, |
119 const char* uri) { | 119 const char* uri) { |
120 RTC_DCHECK_GT(type, kRtpExtensionNone); | 120 RTC_DCHECK_GT(type, kRtpExtensionNone); |
121 RTC_DCHECK_LT(type, kRtpExtensionNumberOfExtensions); | 121 RTC_DCHECK_LT(type, kRtpExtensionNumberOfExtensions); |
122 | 122 |
123 if (id < kMinId || id > kMaxId) { | 123 if (id < kMinId || id > kMaxId) { |
124 LOG(LS_WARNING) << "Failed to register extension uri:'" << uri | 124 LOG(LS_WARNING) << "Failed to register extension uri:'" << uri |
125 << "' with invalid id:" << static_cast<int>(id) << "."; | 125 << "' with invalid id:" << id << "."; |
126 return false; | 126 return false; |
127 } | 127 } |
128 | 128 |
129 if (GetType(id) == type) { // Same type/id pair already registered. | 129 if (GetType(id) == type) { // Same type/id pair already registered. |
130 LOG(LS_VERBOSE) << "Reregistering extension uri:'" << uri | 130 LOG(LS_VERBOSE) << "Reregistering extension uri:'" << uri |
131 << "', id:" << static_cast<int>(id); | 131 << "', id:" << id; |
132 return true; | 132 return true; |
133 } | 133 } |
134 | 134 |
135 if (GetType(id) != kInvalidType) { // |id| used by another extension type. | 135 if (GetType(id) != kInvalidType) { // |id| used by another extension type. |
136 LOG(LS_WARNING) << "Failed to register extension uri:'" << uri | 136 LOG(LS_WARNING) << "Failed to register extension uri:'" << uri |
137 << "', id:" << static_cast<int>(id) | 137 << "', id:" << id |
138 << ". Id already in use by extension type " | 138 << ". Id already in use by extension type " |
139 << static_cast<int>(GetType(id)); | 139 << static_cast<int>(GetType(id)); |
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 // There is a run-time check above id fits into uint8_t. |
| 146 ids_[type] = static_cast<uint8_t>(id); |
146 return true; | 147 return true; |
147 } | 148 } |
148 | 149 |
149 } // namespace webrtc | 150 } // namespace webrtc |
OLD | NEW |