OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 return CreateWebRtcMediaEngine(adm, encoder_factory, decoder_factory); | 66 return CreateWebRtcMediaEngine(adm, encoder_factory, decoder_factory); |
67 } | 67 } |
68 | 68 |
69 namespace { | 69 namespace { |
70 // Remove mutually exclusive extensions with lower priority. | 70 // Remove mutually exclusive extensions with lower priority. |
71 void DiscardRedundantExtensions( | 71 void DiscardRedundantExtensions( |
72 std::vector<webrtc::RtpExtension>* extensions, | 72 std::vector<webrtc::RtpExtension>* extensions, |
73 rtc::ArrayView<const char*> extensions_decreasing_prio) { | 73 rtc::ArrayView<const char*> extensions_decreasing_prio) { |
74 RTC_DCHECK(extensions); | 74 RTC_DCHECK(extensions); |
75 bool found = false; | 75 bool found = false; |
76 for (const char* name : extensions_decreasing_prio) { | 76 for (const char* uri : extensions_decreasing_prio) { |
77 auto it = std::find_if(extensions->begin(), extensions->end(), | 77 auto it = std::find_if( |
78 [name](const webrtc::RtpExtension& rhs) { | 78 extensions->begin(), extensions->end(), |
79 return rhs.name == name; | 79 [uri](const webrtc::RtpExtension& rhs) { return rhs.uri == uri; }); |
80 }); | |
81 if (it != extensions->end()) { | 80 if (it != extensions->end()) { |
82 if (found) { | 81 if (found) { |
83 extensions->erase(it); | 82 extensions->erase(it); |
84 } | 83 } |
85 found = true; | 84 found = true; |
86 } | 85 } |
87 } | 86 } |
88 } | 87 } |
89 } // namespace | 88 } // namespace |
90 | 89 |
91 bool ValidateRtpExtensions(const std::vector<RtpHeaderExtension>& extensions) { | 90 bool ValidateRtpExtensions( |
| 91 const std::vector<webrtc::RtpExtension>& extensions) { |
92 bool id_used[14] = {false}; | 92 bool id_used[14] = {false}; |
93 for (const auto& extension : extensions) { | 93 for (const auto& extension : extensions) { |
94 if (extension.id <= 0 || extension.id >= 15) { | 94 if (extension.id <= 0 || extension.id >= 15) { |
95 LOG(LS_ERROR) << "Bad RTP extension ID: " << extension.ToString(); | 95 LOG(LS_ERROR) << "Bad RTP extension ID: " << extension.ToString(); |
96 return false; | 96 return false; |
97 } | 97 } |
98 if (id_used[extension.id - 1]) { | 98 if (id_used[extension.id - 1]) { |
99 LOG(LS_ERROR) << "Duplicate RTP extension ID: " << extension.ToString(); | 99 LOG(LS_ERROR) << "Duplicate RTP extension ID: " << extension.ToString(); |
100 return false; | 100 return false; |
101 } | 101 } |
102 id_used[extension.id - 1] = true; | 102 id_used[extension.id - 1] = true; |
103 } | 103 } |
104 return true; | 104 return true; |
105 } | 105 } |
106 | 106 |
107 std::vector<webrtc::RtpExtension> FilterRtpExtensions( | 107 std::vector<webrtc::RtpExtension> FilterRtpExtensions( |
108 const std::vector<RtpHeaderExtension>& extensions, | 108 const std::vector<webrtc::RtpExtension>& extensions, |
109 bool (*supported)(const std::string&), | 109 bool (*supported)(const std::string&), |
110 bool filter_redundant_extensions) { | 110 bool filter_redundant_extensions) { |
111 RTC_DCHECK(ValidateRtpExtensions(extensions)); | 111 RTC_DCHECK(ValidateRtpExtensions(extensions)); |
112 RTC_DCHECK(supported); | 112 RTC_DCHECK(supported); |
113 std::vector<webrtc::RtpExtension> result; | 113 std::vector<webrtc::RtpExtension> result; |
114 | 114 |
115 // Ignore any extensions that we don't recognize. | 115 // Ignore any extensions that we don't recognize. |
116 for (const auto& extension : extensions) { | 116 for (const auto& extension : extensions) { |
117 if (supported(extension.uri)) { | 117 if (supported(extension.uri)) { |
118 result.push_back({extension.uri, extension.id}); | 118 result.push_back(extension); |
119 } else { | 119 } else { |
120 LOG(LS_WARNING) << "Unsupported RTP extension: " << extension.ToString(); | 120 LOG(LS_WARNING) << "Unsupported RTP extension: " << extension.ToString(); |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 // Sort by name, ascending, so that we don't reset extensions if they were | 124 // Sort by name, ascending, so that we don't reset extensions if they were |
125 // specified in a different order (also allows us to use std::unique below). | 125 // specified in a different order (also allows us to use std::unique below). |
126 std::sort(result.begin(), result.end(), | 126 std::sort(result.begin(), result.end(), |
127 [](const webrtc::RtpExtension& rhs, const webrtc::RtpExtension& lhs) { | 127 [](const webrtc::RtpExtension& rhs, |
128 return rhs.name < lhs.name; | 128 const webrtc::RtpExtension& lhs) { return rhs.uri < lhs.uri; }); |
129 }); | |
130 | 129 |
131 // Remove unnecessary extensions (used on send side). | 130 // Remove unnecessary extensions (used on send side). |
132 if (filter_redundant_extensions) { | 131 if (filter_redundant_extensions) { |
133 auto it = std::unique(result.begin(), result.end(), | 132 auto it = std::unique( |
| 133 result.begin(), result.end(), |
134 [](const webrtc::RtpExtension& rhs, const webrtc::RtpExtension& lhs) { | 134 [](const webrtc::RtpExtension& rhs, const webrtc::RtpExtension& lhs) { |
135 return rhs.name == lhs.name; | 135 return rhs.uri == lhs.uri; |
136 }); | 136 }); |
137 result.erase(it, result.end()); | 137 result.erase(it, result.end()); |
138 | 138 |
139 // Keep just the highest priority extension of any in the following list. | 139 // Keep just the highest priority extension of any in the following list. |
140 static const char* kBweExtensionPriorities[] = { | 140 static const char* kBweExtensionPriorities[] = { |
141 kRtpTransportSequenceNumberHeaderExtension, | 141 webrtc::RtpExtension::kTransportSequenceNumberUri, |
142 kRtpAbsoluteSenderTimeHeaderExtension, | 142 webrtc::RtpExtension::kAbsSendTimeUri, |
143 kRtpTimestampOffsetHeaderExtension | 143 webrtc::RtpExtension::kTimestampOffsetUri}; |
144 }; | |
145 DiscardRedundantExtensions(&result, kBweExtensionPriorities); | 144 DiscardRedundantExtensions(&result, kBweExtensionPriorities); |
146 } | 145 } |
147 | 146 |
148 return result; | 147 return result; |
149 } | 148 } |
150 } // namespace cricket | 149 } // namespace cricket |
OLD | NEW |