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" |
| 11 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 11 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| 12 | 12 |
| 13 using buzz::QName; | 13 using buzz::QName; |
| 14 using buzz::XmlElement; | 14 using buzz::XmlElement; |
| 15 | 15 |
| 16 namespace remoting { | 16 namespace remoting { |
| 17 namespace protocol { | 17 namespace protocol { |
| 18 | 18 |
| 19 const char ContentDescription::kChromotingContentName[] = "chromoting"; | 19 const char ContentDescription::kChromotingContentName[] = "chromoting"; |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 const char kDefaultNs[] = ""; | 23 const char kDefaultNs[] = ""; |
| 24 | 24 |
| 25 // Following constants are used to format session description in XML. | 25 // Following constants are used to format session description in XML. |
| 26 const char kDescriptionTag[] = "description"; | 26 const char kDescriptionTag[] = "description"; |
| 27 const char kControlTag[] = "control"; | 27 const char kControlTag[] = "control"; |
| 28 const char kEventTag[] = "event"; | 28 const char kEventTag[] = "event"; |
| 29 const char kVideoTag[] = "video"; | 29 const char kVideoTag[] = "video"; |
| 30 const char kAudioTag[] = "audio"; | |
| 30 const char kDeprecatedResolutionTag[] = "initial-resolution"; | 31 const char kDeprecatedResolutionTag[] = "initial-resolution"; |
| 31 | 32 |
| 32 const char kTransportAttr[] = "transport"; | 33 const char kTransportAttr[] = "transport"; |
| 33 const char kVersionAttr[] = "version"; | 34 const char kVersionAttr[] = "version"; |
| 34 const char kCodecAttr[] = "codec"; | 35 const char kCodecAttr[] = "codec"; |
| 35 const char kDeprecatedWidthAttr[] = "width"; | 36 const char kDeprecatedWidthAttr[] = "width"; |
| 36 const char kDeprecatedHeightAttr[] = "height"; | 37 const char kDeprecatedHeightAttr[] = "height"; |
| 37 | 38 |
| 38 const char kStreamTransport[] = "stream"; | 39 const char kStreamTransport[] = "stream"; |
| 39 const char kDatagramTransport[] = "datagram"; | 40 const char kDatagramTransport[] = "datagram"; |
| 41 const char kNoneTransport[] = "none"; | |
| 40 | 42 |
| 41 const char kVerbatimCodec[] = "verbatim"; | 43 const char kVerbatimCodec[] = "verbatim"; |
| 42 const char kVp8Codec[] = "vp8"; | 44 const char kVp8Codec[] = "vp8"; |
| 43 const char kZipCodec[] = "zip"; | 45 const char kZipCodec[] = "zip"; |
| 46 const char kVorbisCodec[] = "vorbis"; | |
|
Wez
2012/06/22 18:29:53
Have you checked that all calling codesites cope g
kxing
2012/06/22 19:12:31
I think so:
remoting/client/rectangle_update_deco
| |
| 44 | 47 |
| 45 const char* GetTransportName(ChannelConfig::TransportType type) { | 48 const char* GetTransportName(ChannelConfig::TransportType type) { |
| 46 switch (type) { | 49 switch (type) { |
| 47 case ChannelConfig::TRANSPORT_STREAM: | 50 case ChannelConfig::TRANSPORT_STREAM: |
| 48 return kStreamTransport; | 51 return kStreamTransport; |
| 49 case ChannelConfig::TRANSPORT_DATAGRAM: | 52 case ChannelConfig::TRANSPORT_DATAGRAM: |
| 50 return kDatagramTransport; | 53 return kDatagramTransport; |
| 54 case ChannelConfig::TRANSPORT_NONE: | |
| 55 return kNoneTransport; | |
| 51 } | 56 } |
| 52 NOTREACHED(); | 57 NOTREACHED(); |
| 53 return NULL; | 58 return NULL; |
| 54 } | 59 } |
| 55 | 60 |
| 56 const char* GetCodecName(ChannelConfig::Codec type) { | 61 const char* GetCodecName(ChannelConfig::Codec type) { |
| 57 switch (type) { | 62 switch (type) { |
| 58 case ChannelConfig::CODEC_VERBATIM: | 63 case ChannelConfig::CODEC_VERBATIM: |
| 59 return kVerbatimCodec; | 64 return kVerbatimCodec; |
| 60 case ChannelConfig::CODEC_VP8: | 65 case ChannelConfig::CODEC_VP8: |
| 61 return kVp8Codec; | 66 return kVp8Codec; |
| 62 case ChannelConfig::CODEC_ZIP: | 67 case ChannelConfig::CODEC_ZIP: |
| 63 return kZipCodec; | 68 return kZipCodec; |
| 69 case ChannelConfig::CODEC_VORBIS: | |
| 70 return kVorbisCodec; | |
| 64 default: | 71 default: |
| 65 break; | 72 break; |
| 66 } | 73 } |
| 67 NOTREACHED(); | 74 NOTREACHED(); |
| 68 return NULL; | 75 return NULL; |
| 69 } | 76 } |
| 70 | 77 |
| 71 | 78 |
| 72 // Format a channel configuration tag for chromotocol session description, | 79 // Format a channel configuration tag for chromotocol session description, |
| 73 // e.g. for video channel: | 80 // e.g. for video channel: |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 90 | 97 |
| 91 return result; | 98 return result; |
| 92 } | 99 } |
| 93 | 100 |
| 94 bool ParseTransportName(const std::string& value, | 101 bool ParseTransportName(const std::string& value, |
| 95 ChannelConfig::TransportType* transport) { | 102 ChannelConfig::TransportType* transport) { |
| 96 if (value == kStreamTransport) { | 103 if (value == kStreamTransport) { |
| 97 *transport = ChannelConfig::TRANSPORT_STREAM; | 104 *transport = ChannelConfig::TRANSPORT_STREAM; |
| 98 } else if (value == kDatagramTransport) { | 105 } else if (value == kDatagramTransport) { |
| 99 *transport = ChannelConfig::TRANSPORT_DATAGRAM; | 106 *transport = ChannelConfig::TRANSPORT_DATAGRAM; |
| 107 } else if (value == kNoneTransport) { | |
| 108 *transport = ChannelConfig::TRANSPORT_NONE; | |
| 100 } else { | 109 } else { |
| 101 return false; | 110 return false; |
| 102 } | 111 } |
| 103 return true; | 112 return true; |
| 104 } | 113 } |
| 105 | 114 |
| 106 bool ParseCodecName(const std::string& value, ChannelConfig::Codec* codec) { | 115 bool ParseCodecName(const std::string& value, ChannelConfig::Codec* codec) { |
| 107 if (value == kVerbatimCodec) { | 116 if (value == kVerbatimCodec) { |
| 108 *codec = ChannelConfig::CODEC_VERBATIM; | 117 *codec = ChannelConfig::CODEC_VERBATIM; |
| 109 } else if (value == kVp8Codec) { | 118 } else if (value == kVp8Codec) { |
| 110 *codec = ChannelConfig::CODEC_VP8; | 119 *codec = ChannelConfig::CODEC_VP8; |
| 111 } else if (value == kZipCodec) { | 120 } else if (value == kZipCodec) { |
| 112 *codec = ChannelConfig::CODEC_ZIP; | 121 *codec = ChannelConfig::CODEC_ZIP; |
| 122 } else if (value == kVorbisCodec) { | |
| 123 *codec = ChannelConfig::CODEC_VORBIS; | |
| 113 } else { | 124 } else { |
| 114 return false; | 125 return false; |
| 115 } | 126 } |
| 116 return true; | 127 return true; |
| 117 } | 128 } |
| 118 | 129 |
| 119 // Returns false if the element is invalid. | 130 // Returns false if the element is invalid. |
| 120 bool ParseChannelConfig(const XmlElement* element, bool codec_required, | 131 bool ParseChannelConfig(const XmlElement* element, bool codec_required, |
| 121 ChannelConfig* config) { | 132 ChannelConfig* config) { |
| 122 if (!ParseTransportName(element->Attr(QName(kDefaultNs, kTransportAttr)), | 133 if (!ParseTransportName(element->Attr(QName(kDefaultNs, kTransportAttr)), |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 scoped_ptr<XmlElement> message(new XmlElement(*authenticator_message_)); | 167 scoped_ptr<XmlElement> message(new XmlElement(*authenticator_message_)); |
| 157 return new ContentDescription(candidate_config_->Clone(), message.Pass()); | 168 return new ContentDescription(candidate_config_->Clone(), message.Pass()); |
| 158 } | 169 } |
| 159 | 170 |
| 160 // ToXml() creates content description for chromoting session. The | 171 // ToXml() creates content description for chromoting session. The |
| 161 // description looks as follows: | 172 // description looks as follows: |
| 162 // <description xmlns="google:remoting"> | 173 // <description xmlns="google:remoting"> |
| 163 // <control transport="stream" version="1" /> | 174 // <control transport="stream" version="1" /> |
| 164 // <event transport="datagram" version="1" /> | 175 // <event transport="datagram" version="1" /> |
| 165 // <video transport="stream" codec="vp8" version="1" /> | 176 // <video transport="stream" codec="vp8" version="1" /> |
| 177 // <audio transport="stream" codec="vorbis" version="1" /> | |
| 166 // <authentication> | 178 // <authentication> |
| 167 // Message created by Authenticator implementation. | 179 // Message created by Authenticator implementation. |
| 168 // </authentication> | 180 // </authentication> |
| 169 // </description> | 181 // </description> |
| 170 // | 182 // |
| 171 XmlElement* ContentDescription::ToXml() const { | 183 XmlElement* ContentDescription::ToXml() const { |
| 172 XmlElement* root = new XmlElement( | 184 XmlElement* root = new XmlElement( |
| 173 QName(kChromotingXmlNamespace, kDescriptionTag), true); | 185 QName(kChromotingXmlNamespace, kDescriptionTag), true); |
| 174 | 186 |
| 175 std::vector<ChannelConfig>::const_iterator it; | 187 std::vector<ChannelConfig>::const_iterator it; |
| 176 | 188 |
| 177 for (it = config()->control_configs().begin(); | 189 for (it = config()->control_configs().begin(); |
| 178 it != config()->control_configs().end(); ++it) { | 190 it != config()->control_configs().end(); ++it) { |
| 179 root->AddElement(FormatChannelConfig(*it, kControlTag)); | 191 root->AddElement(FormatChannelConfig(*it, kControlTag)); |
| 180 } | 192 } |
| 181 | 193 |
| 182 for (it = config()->event_configs().begin(); | 194 for (it = config()->event_configs().begin(); |
| 183 it != config()->event_configs().end(); ++it) { | 195 it != config()->event_configs().end(); ++it) { |
| 184 root->AddElement(FormatChannelConfig(*it, kEventTag)); | 196 root->AddElement(FormatChannelConfig(*it, kEventTag)); |
| 185 } | 197 } |
| 186 | 198 |
| 187 for (it = config()->video_configs().begin(); | 199 for (it = config()->video_configs().begin(); |
| 188 it != config()->video_configs().end(); ++it) { | 200 it != config()->video_configs().end(); ++it) { |
| 189 root->AddElement(FormatChannelConfig(*it, kVideoTag)); | 201 root->AddElement(FormatChannelConfig(*it, kVideoTag)); |
| 190 } | 202 } |
| 191 | 203 |
| 204 for (it = config()->audio_configs().begin(); | |
| 205 it != config()->audio_configs().end(); ++it) { | |
| 206 root->AddElement(FormatChannelConfig(*it, kAudioTag)); | |
| 207 } | |
| 208 | |
| 192 // Older endpoints require an initial-resolution tag, but otherwise ignore it. | 209 // Older endpoints require an initial-resolution tag, but otherwise ignore it. |
| 193 XmlElement* resolution_tag = new XmlElement( | 210 XmlElement* resolution_tag = new XmlElement( |
| 194 QName(kChromotingXmlNamespace, kDeprecatedResolutionTag)); | 211 QName(kChromotingXmlNamespace, kDeprecatedResolutionTag)); |
| 195 resolution_tag->AddAttr(QName(kDefaultNs, kDeprecatedWidthAttr), "640"); | 212 resolution_tag->AddAttr(QName(kDefaultNs, kDeprecatedWidthAttr), "640"); |
| 196 resolution_tag->AddAttr(QName(kDefaultNs, kDeprecatedHeightAttr), "480"); | 213 resolution_tag->AddAttr(QName(kDefaultNs, kDeprecatedHeightAttr), "480"); |
| 197 root->AddElement(resolution_tag); | 214 root->AddElement(resolution_tag); |
| 198 | 215 |
| 199 if (authenticator_message_.get()) { | 216 if (authenticator_message_.get()) { |
| 200 DCHECK(Authenticator::IsAuthenticatorMessage(authenticator_message_.get())); | 217 DCHECK(Authenticator::IsAuthenticatorMessage(authenticator_message_.get())); |
| 201 root->AddElement(new XmlElement(*authenticator_message_)); | 218 root->AddElement(new XmlElement(*authenticator_message_)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 QName video_tag(kChromotingXmlNamespace, kVideoTag); | 255 QName video_tag(kChromotingXmlNamespace, kVideoTag); |
| 239 child = element->FirstNamed(video_tag); | 256 child = element->FirstNamed(video_tag); |
| 240 while (child) { | 257 while (child) { |
| 241 ChannelConfig channel_config; | 258 ChannelConfig channel_config; |
| 242 if (!ParseChannelConfig(child, true, &channel_config)) | 259 if (!ParseChannelConfig(child, true, &channel_config)) |
| 243 return NULL; | 260 return NULL; |
| 244 config->mutable_video_configs()->push_back(channel_config); | 261 config->mutable_video_configs()->push_back(channel_config); |
| 245 child = child->NextNamed(video_tag); | 262 child = child->NextNamed(video_tag); |
| 246 } | 263 } |
| 247 | 264 |
| 265 // <audio> tags. | |
| 266 QName audio_tag(kChromotingXmlNamespace, kAudioTag); | |
| 267 child = element->FirstNamed(audio_tag); | |
| 268 if (!child) { | |
| 269 // If there's no mention of audio, implicitly assume | |
| 270 // TRANSPORT_NONE for the audio_channel. | |
| 271 ChannelConfig no_audio(ChannelConfig::TRANSPORT_NONE, | |
| 272 kDefaultStreamVersion, | |
| 273 ChannelConfig::CODEC_UNDEFINED); | |
| 274 config->mutable_audio_configs()->push_back(no_audio); | |
| 275 } | |
| 276 while (child) { | |
| 277 ChannelConfig channel_config; | |
| 278 if (!ParseChannelConfig(child, false, &channel_config)) | |
| 279 return NULL; | |
| 280 config->mutable_audio_configs()->push_back(channel_config); | |
| 281 child = child->NextNamed(audio_tag); | |
| 282 } | |
|
Wez
2012/06/22 18:29:53
nit: We've got four all-but-identical blocks of co
kxing
2012/06/22 19:12:31
This might be a bit tricky, since video tags requi
Wez
2012/06/22 21:14:06
Good point. You also want audio tags to have a co
kxing
2012/06/22 21:21:37
Sure. I'll do that in https://code.google.com/p/ch
| |
| 283 | |
| 248 scoped_ptr<XmlElement> authenticator_message; | 284 scoped_ptr<XmlElement> authenticator_message; |
| 249 child = Authenticator::FindAuthenticatorMessage(element); | 285 child = Authenticator::FindAuthenticatorMessage(element); |
| 250 if (child) | 286 if (child) |
| 251 authenticator_message.reset(new XmlElement(*child)); | 287 authenticator_message.reset(new XmlElement(*child)); |
| 252 | 288 |
| 253 return new ContentDescription(config.Pass(), authenticator_message.Pass()); | 289 return new ContentDescription(config.Pass(), authenticator_message.Pass()); |
| 254 } | 290 } |
| 255 LOG(ERROR) << "Invalid description: " << element->Str(); | 291 LOG(ERROR) << "Invalid description: " << element->Str(); |
| 256 return NULL; | 292 return NULL; |
| 257 } | 293 } |
| 258 | 294 |
| 259 } // namespace protocol | 295 } // namespace protocol |
| 260 } // namespace remoting | 296 } // namespace remoting |
| OLD | NEW |