Chromium Code Reviews| 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "remoting/base/constants.h" | 9 #include "remoting/base/constants.h" |
| 10 #include "remoting/protocol/authenticator.h" | 10 #include "remoting/protocol/authenticator.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 // e.g. for video channel: | 55 // e.g. for video channel: |
| 56 // <video transport="stream" version="1" codec="vp8" /> | 56 // <video transport="stream" version="1" codec="vp8" /> |
| 57 XmlElement* FormatChannelConfig(const ChannelConfig& config, | 57 XmlElement* FormatChannelConfig(const ChannelConfig& config, |
| 58 const std::string& tag_name) { | 58 const std::string& tag_name) { |
| 59 XmlElement* result = new XmlElement( | 59 XmlElement* result = new XmlElement( |
| 60 QName(kChromotingXmlNamespace, tag_name)); | 60 QName(kChromotingXmlNamespace, tag_name)); |
| 61 | 61 |
| 62 result->AddAttr(QName(kDefaultNs, kTransportAttr), | 62 result->AddAttr(QName(kDefaultNs, kTransportAttr), |
| 63 ValueToName(kTransports, config.transport)); | 63 ValueToName(kTransports, config.transport)); |
| 64 | 64 |
| 65 // TODO(sergeyu): Here we add version and codec attributes even when transport | |
| 66 // is set to NONE. This is needed for backward compatibility only. Fix this | |
| 67 // code once the current stable version is able to cope with missing version | |
| 68 // and codec attributes. | |
| 69 // crbug.com/144053 | |
|
Wez
2012/08/22 00:08:30
The codec case explicitly checks for CODEC_UNDEFIN
Sergey Ulanov
2012/08/22 00:18:27
Yes. Anyway I removed this comment and changed the
| |
| 70 | |
| 65 result->AddAttr(QName(kDefaultNs, kVersionAttr), | 71 result->AddAttr(QName(kDefaultNs, kVersionAttr), |
| 66 base::IntToString(config.version)); | 72 base::IntToString(config.version)); |
| 67 | 73 |
| 68 if (config.codec != ChannelConfig::CODEC_UNDEFINED) { | 74 if (config.codec != ChannelConfig::CODEC_UNDEFINED) { |
| 69 result->AddAttr(QName(kDefaultNs, kCodecAttr), | 75 result->AddAttr(QName(kDefaultNs, kCodecAttr), |
| 70 ValueToName(kCodecs, config.codec)); | 76 ValueToName(kCodecs, config.codec)); |
| 71 } | 77 } |
| 72 | 78 |
| 73 return result; | 79 return result; |
| 74 } | 80 } |
| 75 | 81 |
| 76 // Returns false if the element is invalid. | 82 // Returns false if the element is invalid. |
| 77 bool ParseChannelConfig(const XmlElement* element, bool codec_required, | 83 bool ParseChannelConfig(const XmlElement* element, bool codec_required, |
| 78 ChannelConfig* config) { | 84 ChannelConfig* config) { |
| 79 if (!NameToValue( | 85 if (!NameToValue( |
| 80 kTransports, element->Attr(QName(kDefaultNs, kTransportAttr)), | 86 kTransports, element->Attr(QName(kDefaultNs, kTransportAttr)), |
| 81 &config->transport) || | 87 &config->transport)) { |
| 82 !base::StringToInt(element->Attr(QName(kDefaultNs, kVersionAttr)), | |
| 83 &config->version)) { | |
| 84 return false; | 88 return false; |
| 85 } | 89 } |
| 86 | 90 |
| 87 if (codec_required) { | 91 // Version is not required when transport="none". |
| 92 if (config->transport != ChannelConfig::TRANSPORT_NONE) { | |
| 93 if (!base::StringToInt(element->Attr(QName(kDefaultNs, kVersionAttr)), | |
| 94 &config->version)) { | |
| 95 return false; | |
| 96 } | |
| 97 } else { | |
| 98 config->version = 0; | |
| 99 } | |
| 100 | |
| 101 // Codec is not required when transport="none". | |
| 102 if (codec_required && config->transport != ChannelConfig::TRANSPORT_NONE) { | |
|
Wez
2012/08/22 00:08:30
nit: Cleaner to have a single config->transport !=
Sergey Ulanov
2012/08/22 00:18:27
Done.
Wez
2012/08/22 00:26:54
What I meant was actually to put the version & cod
Sergey Ulanov
2012/08/22 00:37:42
Done.
| |
| 88 if (!NameToValue(kCodecs, element->Attr(QName(kDefaultNs, kCodecAttr)), | 103 if (!NameToValue(kCodecs, element->Attr(QName(kDefaultNs, kCodecAttr)), |
| 89 &config->codec)) { | 104 &config->codec)) { |
| 90 return false; | 105 return false; |
| 91 } | 106 } |
| 92 } else { | 107 } else { |
| 93 config->codec = ChannelConfig::CODEC_UNDEFINED; | 108 config->codec = ChannelConfig::CODEC_UNDEFINED; |
| 94 } | 109 } |
| 95 | 110 |
| 96 return true; | 111 return true; |
| 97 } | 112 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 root->AddElement(FormatChannelConfig(*it, kEventTag)); | 158 root->AddElement(FormatChannelConfig(*it, kEventTag)); |
| 144 } | 159 } |
| 145 | 160 |
| 146 for (it = config()->video_configs().begin(); | 161 for (it = config()->video_configs().begin(); |
| 147 it != config()->video_configs().end(); ++it) { | 162 it != config()->video_configs().end(); ++it) { |
| 148 root->AddElement(FormatChannelConfig(*it, kVideoTag)); | 163 root->AddElement(FormatChannelConfig(*it, kVideoTag)); |
| 149 } | 164 } |
| 150 | 165 |
| 151 for (it = config()->audio_configs().begin(); | 166 for (it = config()->audio_configs().begin(); |
| 152 it != config()->audio_configs().end(); ++it) { | 167 it != config()->audio_configs().end(); ++it) { |
| 153 root->AddElement(FormatChannelConfig(*it, kAudioTag)); | 168 ChannelConfig config = *it; |
| 169 if (config.transport == ChannelConfig::TRANSPORT_NONE) { | |
| 170 // Older client and host may expect the following values for for the | |
| 171 // version and codec for the NONE audio config. | |
| 172 // TODO(sergeyu): Remove this code once the current version supports. | |
| 173 // crbug.com/144053 | |
|
Wez
2012/08/22 00:08:30
This only affects clients which support optional c
Sergey Ulanov
2012/08/22 00:18:27
Yeah, Actually I think that M22 should be able to
Wez
2012/08/22 00:26:54
And if no configurations match then it'll fall bac
Sergey Ulanov
2012/08/22 00:37:42
Yes
| |
| 174 config.version = 2; | |
|
Wez
2012/08/22 00:08:30
nit: kDefaultVersion?
Sergey Ulanov
2012/08/22 00:18:27
Removed this code.
| |
| 175 config.codec = ChannelConfig::CODEC_VERBATIM; | |
| 176 } | |
| 177 root->AddElement(FormatChannelConfig(config, kAudioTag)); | |
| 154 } | 178 } |
| 155 | 179 |
| 156 // Older endpoints require an initial-resolution tag, but otherwise ignore it. | 180 // Older endpoints require an initial-resolution tag, but otherwise ignore it. |
| 157 XmlElement* resolution_tag = new XmlElement( | 181 XmlElement* resolution_tag = new XmlElement( |
| 158 QName(kChromotingXmlNamespace, kDeprecatedResolutionTag)); | 182 QName(kChromotingXmlNamespace, kDeprecatedResolutionTag)); |
| 159 resolution_tag->AddAttr(QName(kDefaultNs, kDeprecatedWidthAttr), "640"); | 183 resolution_tag->AddAttr(QName(kDefaultNs, kDeprecatedWidthAttr), "640"); |
| 160 resolution_tag->AddAttr(QName(kDefaultNs, kDeprecatedHeightAttr), "480"); | 184 resolution_tag->AddAttr(QName(kDefaultNs, kDeprecatedHeightAttr), "480"); |
| 161 root->AddElement(resolution_tag); | 185 root->AddElement(resolution_tag); |
| 162 | 186 |
| 163 if (authenticator_message_.get()) { | 187 if (authenticator_message_.get()) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 183 while (child) { | 207 while (child) { |
| 184 ChannelConfig channel_config; | 208 ChannelConfig channel_config; |
| 185 if (ParseChannelConfig(child, codec_required, &channel_config)) { | 209 if (ParseChannelConfig(child, codec_required, &channel_config)) { |
| 186 configs->push_back(channel_config); | 210 configs->push_back(channel_config); |
| 187 } | 211 } |
| 188 child = child->NextNamed(tag); | 212 child = child->NextNamed(tag); |
| 189 } | 213 } |
| 190 if (optional && configs->empty()) { | 214 if (optional && configs->empty()) { |
| 191 // If there's no mention of the tag, implicitly assume | 215 // If there's no mention of the tag, implicitly assume |
| 192 // TRANSPORT_NONE for the channel. | 216 // TRANSPORT_NONE for the channel. |
| 193 configs->push_back(ChannelConfig(ChannelConfig::TRANSPORT_NONE, | 217 configs->push_back(ChannelConfig()); |
| 194 kDefaultStreamVersion, | |
| 195 ChannelConfig::CODEC_VERBATIM)); | |
| 196 } | 218 } |
| 197 return true; | 219 return true; |
| 198 } | 220 } |
| 199 | 221 |
| 200 // static | 222 // static |
| 201 scoped_ptr<ContentDescription> ContentDescription::ParseXml( | 223 scoped_ptr<ContentDescription> ContentDescription::ParseXml( |
| 202 const XmlElement* element) { | 224 const XmlElement* element) { |
| 203 if (element->Name() != QName(kChromotingXmlNamespace, kDescriptionTag)) { | 225 if (element->Name() != QName(kChromotingXmlNamespace, kDescriptionTag)) { |
| 204 LOG(ERROR) << "Invalid description: " << element->Str(); | 226 LOG(ERROR) << "Invalid description: " << element->Str(); |
| 205 return scoped_ptr<ContentDescription>(); | 227 return scoped_ptr<ContentDescription>(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 221 const XmlElement* child = Authenticator::FindAuthenticatorMessage(element); | 243 const XmlElement* child = Authenticator::FindAuthenticatorMessage(element); |
| 222 if (child) | 244 if (child) |
| 223 authenticator_message.reset(new XmlElement(*child)); | 245 authenticator_message.reset(new XmlElement(*child)); |
| 224 | 246 |
| 225 return scoped_ptr<ContentDescription>( | 247 return scoped_ptr<ContentDescription>( |
| 226 new ContentDescription(config.Pass(), authenticator_message.Pass())); | 248 new ContentDescription(config.Pass(), authenticator_message.Pass())); |
| 227 } | 249 } |
| 228 | 250 |
| 229 } // namespace protocol | 251 } // namespace protocol |
| 230 } // namespace remoting | 252 } // namespace remoting |
| OLD | NEW |