| 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 "remoting/protocol/name_value_map.h" |
| 11 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 12 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| 12 | 13 |
| 13 using buzz::QName; | 14 using buzz::QName; |
| 14 using buzz::XmlElement; | 15 using buzz::XmlElement; |
| 15 | 16 |
| 16 namespace remoting { | 17 namespace remoting { |
| 17 namespace protocol { | 18 namespace protocol { |
| 18 | 19 |
| 19 const char ContentDescription::kChromotingContentName[] = "chromoting"; | 20 const char ContentDescription::kChromotingContentName[] = "chromoting"; |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 const char kDefaultNs[] = ""; | 24 const char kDefaultNs[] = ""; |
| 24 | 25 |
| 25 // Following constants are used to format session description in XML. | 26 // Following constants are used to format session description in XML. |
| 26 const char kDescriptionTag[] = "description"; | 27 const char kDescriptionTag[] = "description"; |
| 27 const char kControlTag[] = "control"; | 28 const char kControlTag[] = "control"; |
| 28 const char kEventTag[] = "event"; | 29 const char kEventTag[] = "event"; |
| 29 const char kVideoTag[] = "video"; | 30 const char kVideoTag[] = "video"; |
| 30 const char kAudioTag[] = "audio"; | 31 const char kAudioTag[] = "audio"; |
| 31 const char kDeprecatedResolutionTag[] = "initial-resolution"; | 32 const char kDeprecatedResolutionTag[] = "initial-resolution"; |
| 32 | 33 |
| 33 const char kTransportAttr[] = "transport"; | 34 const char kTransportAttr[] = "transport"; |
| 34 const char kVersionAttr[] = "version"; | 35 const char kVersionAttr[] = "version"; |
| 35 const char kCodecAttr[] = "codec"; | 36 const char kCodecAttr[] = "codec"; |
| 36 const char kDeprecatedWidthAttr[] = "width"; | 37 const char kDeprecatedWidthAttr[] = "width"; |
| 37 const char kDeprecatedHeightAttr[] = "height"; | 38 const char kDeprecatedHeightAttr[] = "height"; |
| 38 | 39 |
| 39 const char kStreamTransport[] = "stream"; | 40 const NameMapElement<ChannelConfig::TransportType> kTransports[] = { |
| 40 const char kDatagramTransport[] = "datagram"; | 41 { ChannelConfig::TRANSPORT_STREAM, "stream" }, |
| 41 const char kNoneTransport[] = "none"; | 42 { ChannelConfig::TRANSPORT_STREAM, "mux-stream" }, |
| 43 { ChannelConfig::TRANSPORT_DATAGRAM, "datagram" }, |
| 44 { ChannelConfig::TRANSPORT_NONE, "none" }, |
| 45 }; |
| 42 | 46 |
| 43 const char kVerbatimCodec[] = "verbatim"; | 47 const NameMapElement<ChannelConfig::Codec> kCodecs[] = { |
| 44 const char kVp8Codec[] = "vp8"; | 48 { ChannelConfig::CODEC_VERBATIM, "verbatim" }, |
| 45 const char kZipCodec[] = "zip"; | 49 { ChannelConfig::CODEC_VP8, "vp8" }, |
| 46 const char kVorbisCodec[] = "vorbis"; | 50 { ChannelConfig::CODEC_ZIP, "zip" }, |
| 47 | 51 { ChannelConfig::CODEC_VORBIS, "vorbis" }, |
| 48 const char* GetTransportName(ChannelConfig::TransportType type) { | 52 }; |
| 49 switch (type) { | |
| 50 case ChannelConfig::TRANSPORT_STREAM: | |
| 51 return kStreamTransport; | |
| 52 case ChannelConfig::TRANSPORT_DATAGRAM: | |
| 53 return kDatagramTransport; | |
| 54 case ChannelConfig::TRANSPORT_NONE: | |
| 55 return kNoneTransport; | |
| 56 } | |
| 57 NOTREACHED(); | |
| 58 return NULL; | |
| 59 } | |
| 60 | |
| 61 const char* GetCodecName(ChannelConfig::Codec type) { | |
| 62 switch (type) { | |
| 63 case ChannelConfig::CODEC_VERBATIM: | |
| 64 return kVerbatimCodec; | |
| 65 case ChannelConfig::CODEC_VP8: | |
| 66 return kVp8Codec; | |
| 67 case ChannelConfig::CODEC_ZIP: | |
| 68 return kZipCodec; | |
| 69 case ChannelConfig::CODEC_VORBIS: | |
| 70 return kVorbisCodec; | |
| 71 default: | |
| 72 break; | |
| 73 } | |
| 74 NOTREACHED(); | |
| 75 return NULL; | |
| 76 } | |
| 77 | |
| 78 | 53 |
| 79 // Format a channel configuration tag for chromotocol session description, | 54 // Format a channel configuration tag for chromotocol session description, |
| 80 // e.g. for video channel: | 55 // e.g. for video channel: |
| 81 // <video transport="stream" version="1" codec="vp8" /> | 56 // <video transport="stream" version="1" codec="vp8" /> |
| 82 XmlElement* FormatChannelConfig(const ChannelConfig& config, | 57 XmlElement* FormatChannelConfig(const ChannelConfig& config, |
| 83 const std::string& tag_name) { | 58 const std::string& tag_name) { |
| 84 XmlElement* result = new XmlElement( | 59 XmlElement* result = new XmlElement( |
| 85 QName(kChromotingXmlNamespace, tag_name)); | 60 QName(kChromotingXmlNamespace, tag_name)); |
| 86 | 61 |
| 87 result->AddAttr(QName(kDefaultNs, kTransportAttr), | 62 result->AddAttr(QName(kDefaultNs, kTransportAttr), |
| 88 GetTransportName(config.transport)); | 63 ValueToName(kTransports, config.transport)); |
| 89 | 64 |
| 90 result->AddAttr(QName(kDefaultNs, kVersionAttr), | 65 result->AddAttr(QName(kDefaultNs, kVersionAttr), |
| 91 base::IntToString(config.version)); | 66 base::IntToString(config.version)); |
| 92 | 67 |
| 93 if (config.codec != ChannelConfig::CODEC_UNDEFINED) { | 68 if (config.codec != ChannelConfig::CODEC_UNDEFINED) { |
| 94 result->AddAttr(QName(kDefaultNs, kCodecAttr), | 69 result->AddAttr(QName(kDefaultNs, kCodecAttr), |
| 95 GetCodecName(config.codec)); | 70 ValueToName(kCodecs, config.codec)); |
| 96 } | 71 } |
| 97 | 72 |
| 98 return result; | 73 return result; |
| 99 } | 74 } |
| 100 | 75 |
| 101 bool ParseTransportName(const std::string& value, | |
| 102 ChannelConfig::TransportType* transport) { | |
| 103 if (value == kStreamTransport) { | |
| 104 *transport = ChannelConfig::TRANSPORT_STREAM; | |
| 105 } else if (value == kDatagramTransport) { | |
| 106 *transport = ChannelConfig::TRANSPORT_DATAGRAM; | |
| 107 } else if (value == kNoneTransport) { | |
| 108 *transport = ChannelConfig::TRANSPORT_NONE; | |
| 109 } else { | |
| 110 return false; | |
| 111 } | |
| 112 return true; | |
| 113 } | |
| 114 | |
| 115 bool ParseCodecName(const std::string& value, ChannelConfig::Codec* codec) { | |
| 116 if (value == kVerbatimCodec) { | |
| 117 *codec = ChannelConfig::CODEC_VERBATIM; | |
| 118 } else if (value == kVp8Codec) { | |
| 119 *codec = ChannelConfig::CODEC_VP8; | |
| 120 } else if (value == kZipCodec) { | |
| 121 *codec = ChannelConfig::CODEC_ZIP; | |
| 122 } else if (value == kVorbisCodec) { | |
| 123 *codec = ChannelConfig::CODEC_VORBIS; | |
| 124 } else { | |
| 125 return false; | |
| 126 } | |
| 127 return true; | |
| 128 } | |
| 129 | |
| 130 // Returns false if the element is invalid. | 76 // Returns false if the element is invalid. |
| 131 bool ParseChannelConfig(const XmlElement* element, bool codec_required, | 77 bool ParseChannelConfig(const XmlElement* element, bool codec_required, |
| 132 ChannelConfig* config) { | 78 ChannelConfig* config) { |
| 133 if (!ParseTransportName(element->Attr(QName(kDefaultNs, kTransportAttr)), | 79 if (!NameToValue( |
| 134 &config->transport) || | 80 kTransports, element->Attr(QName(kDefaultNs, kTransportAttr)), |
| 81 &config->transport) || |
| 135 !base::StringToInt(element->Attr(QName(kDefaultNs, kVersionAttr)), | 82 !base::StringToInt(element->Attr(QName(kDefaultNs, kVersionAttr)), |
| 136 &config->version)) { | 83 &config->version)) { |
| 137 return false; | 84 return false; |
| 138 } | 85 } |
| 139 | 86 |
| 140 if (codec_required) { | 87 if (codec_required) { |
| 141 if (!ParseCodecName(element->Attr(QName(kDefaultNs, kCodecAttr)), | 88 if (!NameToValue(kCodecs, element->Attr(QName(kDefaultNs, kCodecAttr)), |
| 142 &config->codec)) { | 89 &config->codec)) { |
| 143 return false; | 90 return false; |
| 144 } | 91 } |
| 145 } else { | 92 } else { |
| 146 config->codec = ChannelConfig::CODEC_UNDEFINED; | 93 config->codec = ChannelConfig::CODEC_UNDEFINED; |
| 147 } | 94 } |
| 148 | 95 |
| 149 return true; | 96 return true; |
| 150 } | 97 } |
| 151 | 98 |
| 152 } // namespace | 99 } // namespace |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 const XmlElement* child = Authenticator::FindAuthenticatorMessage(element); | 221 const XmlElement* child = Authenticator::FindAuthenticatorMessage(element); |
| 275 if (child) | 222 if (child) |
| 276 authenticator_message.reset(new XmlElement(*child)); | 223 authenticator_message.reset(new XmlElement(*child)); |
| 277 | 224 |
| 278 return scoped_ptr<ContentDescription>( | 225 return scoped_ptr<ContentDescription>( |
| 279 new ContentDescription(config.Pass(), authenticator_message.Pass())); | 226 new ContentDescription(config.Pass(), authenticator_message.Pass())); |
| 280 } | 227 } |
| 281 | 228 |
| 282 } // namespace protocol | 229 } // namespace protocol |
| 283 } // namespace remoting | 230 } // namespace remoting |
| OLD | NEW |