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/content_description.h" | 5 #include "remoting/protocol/content_description.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "remoting/base/constants.h" | 10 #include "remoting/base/constants.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 const char kDefaultNs[] = ""; | 25 const char kDefaultNs[] = ""; |
26 | 26 |
27 // Following constants are used to format session description in XML. | 27 // Following constants are used to format session description in XML. |
28 const char kDescriptionTag[] = "description"; | 28 const char kDescriptionTag[] = "description"; |
29 const char kStandardIceTag[] = "standard-ice"; | 29 const char kStandardIceTag[] = "standard-ice"; |
30 const char kControlTag[] = "control"; | 30 const char kControlTag[] = "control"; |
31 const char kEventTag[] = "event"; | 31 const char kEventTag[] = "event"; |
32 const char kVideoTag[] = "video"; | 32 const char kVideoTag[] = "video"; |
33 const char kAudioTag[] = "audio"; | 33 const char kAudioTag[] = "audio"; |
34 const char kVp9ExperimentTag[] = "vp9-experiment"; | 34 const char kVp9ExperimentTag[] = "vp9-experiment"; |
35 const char kQuicConfigTag[] = "quic-config"; | |
36 | 35 |
37 const char kTransportAttr[] = "transport"; | 36 const char kTransportAttr[] = "transport"; |
38 const char kVersionAttr[] = "version"; | 37 const char kVersionAttr[] = "version"; |
39 const char kCodecAttr[] = "codec"; | 38 const char kCodecAttr[] = "codec"; |
40 | 39 |
41 const NameMapElement<ChannelConfig::TransportType> kTransports[] = { | 40 const NameMapElement<ChannelConfig::TransportType> kTransports[] = { |
42 { ChannelConfig::TRANSPORT_STREAM, "stream" }, | 41 { ChannelConfig::TRANSPORT_STREAM, "stream" }, |
43 { ChannelConfig::TRANSPORT_MUX_STREAM, "mux-stream" }, | 42 { ChannelConfig::TRANSPORT_MUX_STREAM, "mux-stream" }, |
44 { ChannelConfig::TRANSPORT_QUIC_STREAM, "quic-stream" }, | |
45 { ChannelConfig::TRANSPORT_DATAGRAM, "datagram" }, | 43 { ChannelConfig::TRANSPORT_DATAGRAM, "datagram" }, |
46 { ChannelConfig::TRANSPORT_NONE, "none" }, | 44 { ChannelConfig::TRANSPORT_NONE, "none" }, |
47 }; | 45 }; |
48 | 46 |
49 const NameMapElement<ChannelConfig::Codec> kCodecs[] = { | 47 const NameMapElement<ChannelConfig::Codec> kCodecs[] = { |
50 { ChannelConfig::CODEC_VERBATIM, "verbatim" }, | 48 { ChannelConfig::CODEC_VERBATIM, "verbatim" }, |
51 { ChannelConfig::CODEC_VP8, "vp8" }, | 49 { ChannelConfig::CODEC_VP8, "vp8" }, |
52 { ChannelConfig::CODEC_VP9, "vp9" }, | 50 { ChannelConfig::CODEC_VP9, "vp9" }, |
53 { ChannelConfig::CODEC_ZIP, "zip" }, | 51 { ChannelConfig::CODEC_ZIP, "zip" }, |
54 { ChannelConfig::CODEC_OPUS, "opus" }, | 52 { ChannelConfig::CODEC_OPUS, "opus" }, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 config->codec = ChannelConfig::CODEC_UNDEFINED; | 107 config->codec = ChannelConfig::CODEC_UNDEFINED; |
110 } | 108 } |
111 | 109 |
112 return true; | 110 return true; |
113 } | 111 } |
114 | 112 |
115 } // namespace | 113 } // namespace |
116 | 114 |
117 ContentDescription::ContentDescription( | 115 ContentDescription::ContentDescription( |
118 scoped_ptr<CandidateSessionConfig> config, | 116 scoped_ptr<CandidateSessionConfig> config, |
119 scoped_ptr<buzz::XmlElement> authenticator_message, | 117 scoped_ptr<buzz::XmlElement> authenticator_message) |
120 const std::string& quic_config_message) | |
121 : candidate_config_(config.Pass()), | 118 : candidate_config_(config.Pass()), |
122 authenticator_message_(authenticator_message.Pass()), | 119 authenticator_message_(authenticator_message.Pass()) { |
123 quic_config_message_(quic_config_message) { | |
124 } | 120 } |
125 | 121 |
126 ContentDescription::~ContentDescription() { } | 122 ContentDescription::~ContentDescription() { } |
127 | 123 |
128 // ToXml() creates content description for chromoting session. The | 124 // ToXml() creates content description for chromoting session. The |
129 // description looks as follows: | 125 // description looks as follows: |
130 // <description xmlns="google:remoting"> | 126 // <description xmlns="google:remoting"> |
131 // <standard-ice/> | 127 // <standard-ice/> |
132 // <control transport="stream" version="1" /> | 128 // <control transport="stream" version="1" /> |
133 // <event transport="datagram" version="1" /> | 129 // <event transport="datagram" version="1" /> |
(...skipping 27 matching lines...) Expand all Loading... |
161 for (const auto& channel_config : config()->audio_configs()) { | 157 for (const auto& channel_config : config()->audio_configs()) { |
162 root->AddElement(FormatChannelConfig(channel_config, kAudioTag)); | 158 root->AddElement(FormatChannelConfig(channel_config, kAudioTag)); |
163 } | 159 } |
164 } | 160 } |
165 | 161 |
166 if (authenticator_message_) { | 162 if (authenticator_message_) { |
167 DCHECK(Authenticator::IsAuthenticatorMessage(authenticator_message_.get())); | 163 DCHECK(Authenticator::IsAuthenticatorMessage(authenticator_message_.get())); |
168 root->AddElement(new XmlElement(*authenticator_message_)); | 164 root->AddElement(new XmlElement(*authenticator_message_)); |
169 } | 165 } |
170 | 166 |
171 if (!quic_config_message_.empty()) { | |
172 XmlElement* quic_config_tag = | |
173 new XmlElement(QName(kChromotingXmlNamespace, kQuicConfigTag)); | |
174 root->AddElement(quic_config_tag); | |
175 std::string config_base64; | |
176 base::Base64Encode(quic_config_message_, &config_base64); | |
177 quic_config_tag->SetBodyText(config_base64); | |
178 } | |
179 | |
180 if (config()->vp9_experiment_enabled()) { | 167 if (config()->vp9_experiment_enabled()) { |
181 root->AddElement( | 168 root->AddElement( |
182 new XmlElement(QName(kChromotingXmlNamespace, kVp9ExperimentTag))); | 169 new XmlElement(QName(kChromotingXmlNamespace, kVp9ExperimentTag))); |
183 } | 170 } |
184 | 171 |
185 return root; | 172 return root; |
186 } | 173 } |
187 | 174 |
188 // static | 175 // static |
189 // Adds the channel configs corresponding to |tag_name|, | 176 // Adds the channel configs corresponding to |tag_name|, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 // Check if VP9 experiment is enabled. | 228 // Check if VP9 experiment is enabled. |
242 if (element->FirstNamed(QName(kChromotingXmlNamespace, kVp9ExperimentTag))) { | 229 if (element->FirstNamed(QName(kChromotingXmlNamespace, kVp9ExperimentTag))) { |
243 config->set_vp9_experiment_enabled(true); | 230 config->set_vp9_experiment_enabled(true); |
244 } | 231 } |
245 | 232 |
246 scoped_ptr<XmlElement> authenticator_message; | 233 scoped_ptr<XmlElement> authenticator_message; |
247 const XmlElement* child = Authenticator::FindAuthenticatorMessage(element); | 234 const XmlElement* child = Authenticator::FindAuthenticatorMessage(element); |
248 if (child) | 235 if (child) |
249 authenticator_message.reset(new XmlElement(*child)); | 236 authenticator_message.reset(new XmlElement(*child)); |
250 | 237 |
251 std::string quic_config_message; | 238 return make_scoped_ptr( |
252 const XmlElement* quic_config_tag = | 239 new ContentDescription(config.Pass(), authenticator_message.Pass())); |
253 element->FirstNamed(QName(kChromotingXmlNamespace, kQuicConfigTag)); | |
254 if (quic_config_tag) { | |
255 if (!base::Base64Decode(quic_config_tag->BodyText(), | |
256 &quic_config_message)) { | |
257 LOG(ERROR) << "Failed to parse QUIC config."; | |
258 return nullptr; | |
259 } | |
260 } | |
261 | |
262 return make_scoped_ptr(new ContentDescription( | |
263 config.Pass(), authenticator_message.Pass(), quic_config_message)); | |
264 } | 240 } |
265 | 241 |
266 } // namespace protocol | 242 } // namespace protocol |
267 } // namespace remoting | 243 } // namespace remoting |
OLD | NEW |