OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/protocol/session_config.h" | 5 #include "remoting/protocol/session_config.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> |
8 | 9 |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 | 11 |
11 namespace remoting { | 12 namespace remoting { |
12 namespace protocol { | 13 namespace protocol { |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 bool IsChannelConfigSupported(const std::list<ChannelConfig>& list, | 17 bool IsChannelConfigSupported(const std::list<ChannelConfig>& list, |
17 const ChannelConfig& value) { | 18 const ChannelConfig& value) { |
18 return std::find(list.begin(), list.end(), value) != list.end(); | 19 return std::find(list.begin(), list.end(), value) != list.end(); |
19 } | 20 } |
20 | 21 |
21 bool SelectCommonChannelConfig(const std::list<ChannelConfig>& host_configs, | 22 bool SelectCommonChannelConfig(const std::list<ChannelConfig>& host_configs, |
22 const std::list<ChannelConfig>& client_configs, | 23 const std::list<ChannelConfig>& client_configs, |
23 ChannelConfig* config) { | 24 ChannelConfig* config) { |
24 // Usually each of these lists will contain just a few elements, so iterating | 25 // Usually each of these lists will contain just a few elements, so iterating |
25 // over all of them is not a problem. | 26 // over all of them is not a problem. |
26 std::list<ChannelConfig>::const_iterator it; | 27 std::list<ChannelConfig>::const_iterator it; |
27 for (it = client_configs.begin(); it != client_configs.end(); ++it) { | 28 for (it = client_configs.begin(); it != client_configs.end(); ++it) { |
28 if (IsChannelConfigSupported(host_configs, *it)) { | 29 if (IsChannelConfigSupported(host_configs, *it)) { |
29 *config = *it; | 30 *config = *it; |
30 return true; | 31 return true; |
31 } | 32 } |
32 } | 33 } |
33 return false; | 34 return false; |
34 } | 35 } |
35 | 36 |
| 37 void UpdateConfigListToPreferTransport(std::list<ChannelConfig>* configs, |
| 38 ChannelConfig::TransportType transport) { |
| 39 std::vector<ChannelConfig> sorted(configs->begin(), configs->end()); |
| 40 std::stable_sort(sorted.begin(), sorted.end(), |
| 41 [transport](const ChannelConfig& a, const ChannelConfig& b) { |
| 42 // |a| must precede |b| if |a| uses preferred transport and |
| 43 // |b| doesn't. |
| 44 return a.transport == transport && |
| 45 b.transport != transport; |
| 46 }); |
| 47 configs->assign(sorted.begin(), sorted.end()); |
| 48 } |
| 49 |
36 } // namespace | 50 } // namespace |
37 | 51 |
38 const int kDefaultStreamVersion = 2; | 52 const int kDefaultStreamVersion = 2; |
39 const int kControlStreamVersion = 3; | 53 const int kControlStreamVersion = 3; |
40 | 54 |
41 ChannelConfig ChannelConfig::None() { | 55 ChannelConfig ChannelConfig::None() { |
42 return ChannelConfig(); | 56 return ChannelConfig(); |
43 } | 57 } |
44 | 58 |
45 ChannelConfig::ChannelConfig(TransportType transport, int version, Codec codec) | 59 ChannelConfig::ChannelConfig(TransportType transport, int version, Codec codec) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 result->event_config_ = candidate_config->event_configs().front(); | 129 result->event_config_ = candidate_config->event_configs().front(); |
116 result->video_config_ = candidate_config->video_configs().front(); | 130 result->video_config_ = candidate_config->video_configs().front(); |
117 result->audio_config_ = candidate_config->audio_configs().front(); | 131 result->audio_config_ = candidate_config->audio_configs().front(); |
118 | 132 |
119 return result.Pass(); | 133 return result.Pass(); |
120 } | 134 } |
121 | 135 |
122 // static | 136 // static |
123 scoped_ptr<SessionConfig> SessionConfig::ForTest() { | 137 scoped_ptr<SessionConfig> SessionConfig::ForTest() { |
124 scoped_ptr<SessionConfig> result(new SessionConfig()); | 138 scoped_ptr<SessionConfig> result(new SessionConfig()); |
125 result->control_config_ = ChannelConfig(ChannelConfig::TRANSPORT_MUX_STREAM, | 139 result->control_config_ = ChannelConfig(ChannelConfig::TRANSPORT_QUIC_STREAM, |
126 kControlStreamVersion, | 140 kControlStreamVersion, |
127 ChannelConfig::CODEC_UNDEFINED); | 141 ChannelConfig::CODEC_UNDEFINED); |
128 result->event_config_ = ChannelConfig(ChannelConfig::TRANSPORT_MUX_STREAM, | 142 result->event_config_ = ChannelConfig(ChannelConfig::TRANSPORT_QUIC_STREAM, |
129 kDefaultStreamVersion, | 143 kDefaultStreamVersion, |
130 ChannelConfig::CODEC_UNDEFINED); | 144 ChannelConfig::CODEC_UNDEFINED); |
131 result->video_config_ = ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | 145 result->video_config_ = ChannelConfig(ChannelConfig::TRANSPORT_QUIC_STREAM, |
132 kDefaultStreamVersion, | 146 kDefaultStreamVersion, |
133 ChannelConfig::CODEC_VP8); | 147 ChannelConfig::CODEC_VP8); |
134 result->audio_config_ = ChannelConfig(ChannelConfig::TRANSPORT_NONE, | 148 result->audio_config_ = ChannelConfig(ChannelConfig::TRANSPORT_NONE, |
135 kDefaultStreamVersion, | 149 kDefaultStreamVersion, |
136 ChannelConfig::CODEC_UNDEFINED); | 150 ChannelConfig::CODEC_UNDEFINED); |
137 return result.Pass(); | 151 return result.Pass(); |
138 } | 152 } |
139 | 153 |
140 SessionConfig::SessionConfig() {} | 154 SessionConfig::SessionConfig() {} |
141 | 155 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 189 |
176 // static | 190 // static |
177 scoped_ptr<CandidateSessionConfig> CandidateSessionConfig::CreateDefault() { | 191 scoped_ptr<CandidateSessionConfig> CandidateSessionConfig::CreateDefault() { |
178 scoped_ptr<CandidateSessionConfig> result = CreateEmpty(); | 192 scoped_ptr<CandidateSessionConfig> result = CreateEmpty(); |
179 | 193 |
180 // Control channel. | 194 // Control channel. |
181 result->mutable_control_configs()->push_back( | 195 result->mutable_control_configs()->push_back( |
182 ChannelConfig(ChannelConfig::TRANSPORT_MUX_STREAM, | 196 ChannelConfig(ChannelConfig::TRANSPORT_MUX_STREAM, |
183 kControlStreamVersion, | 197 kControlStreamVersion, |
184 ChannelConfig::CODEC_UNDEFINED)); | 198 ChannelConfig::CODEC_UNDEFINED)); |
| 199 result->mutable_control_configs()->push_back( |
| 200 ChannelConfig(ChannelConfig::TRANSPORT_QUIC_STREAM, |
| 201 kControlStreamVersion, |
| 202 ChannelConfig::CODEC_UNDEFINED)); |
185 | 203 |
186 // Event channel. | 204 // Event channel. |
187 result->mutable_event_configs()->push_back( | 205 result->mutable_event_configs()->push_back( |
188 ChannelConfig(ChannelConfig::TRANSPORT_MUX_STREAM, | 206 ChannelConfig(ChannelConfig::TRANSPORT_MUX_STREAM, |
189 kDefaultStreamVersion, | 207 kDefaultStreamVersion, |
190 ChannelConfig::CODEC_UNDEFINED)); | 208 ChannelConfig::CODEC_UNDEFINED)); |
| 209 result->mutable_event_configs()->push_back( |
| 210 ChannelConfig(ChannelConfig::TRANSPORT_QUIC_STREAM, |
| 211 kDefaultStreamVersion, |
| 212 ChannelConfig::CODEC_UNDEFINED)); |
191 | 213 |
192 // Video channel. | 214 // Video channel. |
193 result->mutable_video_configs()->push_back( | 215 result->mutable_video_configs()->push_back( |
194 ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | 216 ChannelConfig(ChannelConfig::TRANSPORT_STREAM, |
195 kDefaultStreamVersion, | 217 kDefaultStreamVersion, |
196 ChannelConfig::CODEC_VP9)); | 218 ChannelConfig::CODEC_VP9)); |
197 result->mutable_video_configs()->push_back( | 219 result->mutable_video_configs()->push_back( |
198 ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | 220 ChannelConfig(ChannelConfig::TRANSPORT_STREAM, |
199 kDefaultStreamVersion, | 221 kDefaultStreamVersion, |
200 ChannelConfig::CODEC_VP8)); | 222 ChannelConfig::CODEC_VP8)); |
| 223 result->mutable_video_configs()->push_back( |
| 224 ChannelConfig(ChannelConfig::TRANSPORT_QUIC_STREAM, |
| 225 kDefaultStreamVersion, |
| 226 ChannelConfig::CODEC_VP9)); |
| 227 result->mutable_video_configs()->push_back( |
| 228 ChannelConfig(ChannelConfig::TRANSPORT_QUIC_STREAM, |
| 229 kDefaultStreamVersion, |
| 230 ChannelConfig::CODEC_VP8)); |
201 | 231 |
202 // Audio channel. | 232 // Audio channel. |
203 result->mutable_audio_configs()->push_back( | 233 result->mutable_audio_configs()->push_back( |
204 ChannelConfig(ChannelConfig::TRANSPORT_MUX_STREAM, | 234 ChannelConfig(ChannelConfig::TRANSPORT_MUX_STREAM, |
205 kDefaultStreamVersion, | 235 kDefaultStreamVersion, |
206 ChannelConfig::CODEC_OPUS)); | 236 ChannelConfig::CODEC_OPUS)); |
| 237 result->mutable_audio_configs()->push_back( |
| 238 ChannelConfig(ChannelConfig::TRANSPORT_QUIC_STREAM, |
| 239 kDefaultStreamVersion, |
| 240 ChannelConfig::CODEC_OPUS)); |
207 result->mutable_audio_configs()->push_back(ChannelConfig::None()); | 241 result->mutable_audio_configs()->push_back(ChannelConfig::None()); |
208 | 242 |
209 return result.Pass(); | 243 return result.Pass(); |
210 } | 244 } |
211 | 245 |
212 void CandidateSessionConfig::DisableAudioChannel() { | 246 void CandidateSessionConfig::DisableAudioChannel() { |
213 mutable_audio_configs()->clear(); | 247 mutable_audio_configs()->clear(); |
214 mutable_audio_configs()->push_back(ChannelConfig()); | 248 mutable_audio_configs()->push_back(ChannelConfig()); |
215 } | 249 } |
216 | 250 |
| 251 void CandidateSessionConfig::PreferTransport( |
| 252 ChannelConfig::TransportType transport) { |
| 253 UpdateConfigListToPreferTransport(&control_configs_, transport); |
| 254 UpdateConfigListToPreferTransport(&event_configs_, transport); |
| 255 UpdateConfigListToPreferTransport(&video_configs_, transport); |
| 256 UpdateConfigListToPreferTransport(&audio_configs_, transport); |
| 257 } |
| 258 |
217 } // namespace protocol | 259 } // namespace protocol |
218 } // namespace remoting | 260 } // namespace remoting |
OLD | NEW |