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/session_config.h" | 5 #include "remoting/protocol/session_config.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 namespace remoting { | 9 namespace remoting { |
| 10 namespace protocol { | 10 namespace protocol { |
| 11 | 11 |
| 12 const int kDefaultStreamVersion = 2; | 12 const int kDefaultStreamVersion = 2; |
| 13 | 13 |
| 14 ChannelConfig::ChannelConfig() { | 14 ChannelConfig::ChannelConfig() { |
| 15 Reset(); | 15 Reset(); |
| 16 } | 16 } |
| 17 | 17 |
| 18 ChannelConfig::ChannelConfig(TransportType transport, int version, Codec codec) | 18 ChannelConfig::ChannelConfig(TransportType transport, int version, Codec codec) |
| 19 : transport(transport), | 19 : transport(transport), |
| 20 version(version), | 20 version(version), |
| 21 codec(codec) { | 21 codec(codec) { |
| 22 } | 22 } |
| 23 | 23 |
| 24 bool ChannelConfig::operator==(const ChannelConfig& b) const { | 24 bool ChannelConfig::operator==(const ChannelConfig& b) const { |
| 25 return transport == b.transport && version == b.version && codec == b.codec; | 25 return transport == b.transport && |
| 26 version == b.version && | |
| 27 codec == b.codec; | |
| 26 } | 28 } |
| 27 | 29 |
| 28 void ChannelConfig::Reset() { | 30 void ChannelConfig::Reset() { |
| 29 transport = TRANSPORT_STREAM; | 31 transport = TRANSPORT_STREAM; |
| 30 version = kDefaultStreamVersion; | 32 version = kDefaultStreamVersion; |
| 31 codec = CODEC_UNDEFINED; | 33 codec = CODEC_UNDEFINED; |
| 32 } | 34 } |
| 33 | 35 |
| 34 // static | 36 // static |
| 35 SessionConfig SessionConfig::GetDefault() { | 37 SessionConfig SessionConfig::GetDefault() { |
| 36 SessionConfig result; | 38 SessionConfig result; |
| 37 result.set_control_config(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | 39 result.set_control_config(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, |
| 38 kDefaultStreamVersion, | 40 kDefaultStreamVersion, |
| 39 ChannelConfig::CODEC_UNDEFINED)); | 41 ChannelConfig::CODEC_UNDEFINED)); |
| 40 result.set_event_config(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | 42 result.set_event_config(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, |
| 41 kDefaultStreamVersion, | 43 kDefaultStreamVersion, |
| 42 ChannelConfig::CODEC_UNDEFINED)); | 44 ChannelConfig::CODEC_UNDEFINED)); |
| 43 result.set_video_config(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | 45 result.set_video_config(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, |
| 44 kDefaultStreamVersion, | 46 kDefaultStreamVersion, |
| 45 ChannelConfig::CODEC_VP8)); | 47 ChannelConfig::CODEC_VP8)); |
| 48 result.set_audio_config(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | |
| 49 kDefaultStreamVersion, | |
| 50 ChannelConfig::CODEC_UNDEFINED)); | |
| 46 return result; | 51 return result; |
| 47 } | 52 } |
| 48 | 53 |
| 49 CandidateSessionConfig::CandidateSessionConfig() { } | 54 CandidateSessionConfig::CandidateSessionConfig() { } |
| 50 | 55 |
| 51 CandidateSessionConfig::CandidateSessionConfig( | 56 CandidateSessionConfig::CandidateSessionConfig( |
| 52 const CandidateSessionConfig& config) | 57 const CandidateSessionConfig& config) |
| 53 : control_configs_(config.control_configs_), | 58 : control_configs_(config.control_configs_), |
| 54 event_configs_(config.event_configs_), | 59 event_configs_(config.event_configs_), |
| 55 video_configs_(config.video_configs_) { | 60 video_configs_(config.video_configs_), |
| 61 audio_configs_(config.audio_configs_) { | |
| 56 } | 62 } |
| 57 | 63 |
| 58 CandidateSessionConfig::~CandidateSessionConfig() { } | 64 CandidateSessionConfig::~CandidateSessionConfig() { } |
| 59 | 65 |
| 60 bool CandidateSessionConfig::Select( | 66 bool CandidateSessionConfig::Select( |
| 61 const CandidateSessionConfig* client_config, | 67 const CandidateSessionConfig* client_config, |
| 62 SessionConfig* result) { | 68 SessionConfig* result) { |
| 63 ChannelConfig control_config; | 69 ChannelConfig control_config; |
| 64 ChannelConfig event_config; | 70 ChannelConfig event_config; |
| 65 ChannelConfig video_config; | 71 ChannelConfig video_config; |
| 72 ChannelConfig audio_config; | |
| 66 | 73 |
| 67 if (!SelectCommonChannelConfig( | 74 if (!SelectCommonChannelConfig( |
| 68 control_configs_, client_config->control_configs_, &control_config) || | 75 control_configs_, client_config->control_configs_, &control_config) || |
| 69 !SelectCommonChannelConfig( | 76 !SelectCommonChannelConfig( |
| 70 event_configs_, client_config->event_configs_, &event_config) || | 77 event_configs_, client_config->event_configs_, &event_config) || |
| 71 !SelectCommonChannelConfig( | 78 !SelectCommonChannelConfig( |
| 72 video_configs_, client_config->video_configs_, &video_config)) { | 79 video_configs_, client_config->video_configs_, &video_config) || |
| 80 !SelectCommonChannelConfig( | |
| 81 audio_configs_, client_config->audio_configs_, &audio_config)) { | |
| 73 return false; | 82 return false; |
| 74 } | 83 } |
| 75 | 84 |
| 76 result->set_control_config(control_config); | 85 result->set_control_config(control_config); |
| 77 result->set_event_config(event_config); | 86 result->set_event_config(event_config); |
| 78 result->set_video_config(video_config); | 87 result->set_video_config(video_config); |
| 88 result->set_audio_config(audio_config); | |
| 79 | 89 |
| 80 return true; | 90 return true; |
| 81 } | 91 } |
| 82 | 92 |
| 83 bool CandidateSessionConfig::IsSupported( | 93 bool CandidateSessionConfig::IsSupported( |
| 84 const SessionConfig& config) const { | 94 const SessionConfig& config) const { |
| 85 return | 95 return |
| 86 IsChannelConfigSupported(control_configs_, config.control_config()) && | 96 IsChannelConfigSupported(control_configs_, config.control_config()) && |
| 87 IsChannelConfigSupported(event_configs_, config.event_config()) && | 97 IsChannelConfigSupported(event_configs_, config.event_config()) && |
| 88 IsChannelConfigSupported(video_configs_, config.video_config()); | 98 IsChannelConfigSupported(video_configs_, config.video_config()) && |
| 99 IsChannelConfigSupported(audio_configs_, config.audio_config()); | |
| 89 } | 100 } |
| 90 | 101 |
| 91 bool CandidateSessionConfig::GetFinalConfig(SessionConfig* result) const { | 102 bool CandidateSessionConfig::GetFinalConfig(SessionConfig* result) const { |
| 92 if (control_configs_.size() != 1 || | 103 if (control_configs_.size() != 1 || |
| 93 event_configs_.size() != 1 || | 104 event_configs_.size() != 1 || |
| 94 video_configs_.size() != 1) { | 105 video_configs_.size() != 1 || |
| 106 audio_configs_.size() != 1) { | |
| 95 return false; | 107 return false; |
| 96 } | 108 } |
| 97 | 109 |
| 98 result->set_control_config(control_configs_.front()); | 110 result->set_control_config(control_configs_.front()); |
| 99 result->set_event_config(event_configs_.front()); | 111 result->set_event_config(event_configs_.front()); |
| 100 result->set_video_config(video_configs_.front()); | 112 result->set_video_config(video_configs_.front()); |
| 113 result->set_audio_config(audio_configs_.front()); | |
| 101 | 114 |
| 102 return true; | 115 return true; |
| 103 } | 116 } |
| 104 | 117 |
| 105 // static | 118 // static |
| 106 bool CandidateSessionConfig::SelectCommonChannelConfig( | 119 bool CandidateSessionConfig::SelectCommonChannelConfig( |
| 107 const std::vector<ChannelConfig>& host_configs, | 120 const std::vector<ChannelConfig>& host_configs, |
| 108 const std::vector<ChannelConfig>& client_configs, | 121 const std::vector<ChannelConfig>& client_configs, |
| 109 ChannelConfig* config) { | 122 ChannelConfig* config) { |
| 110 // Usually each of these vectors will contain just several elements, | 123 // Usually each of these vectors will contain just several elements, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 135 return scoped_ptr<CandidateSessionConfig>(new CandidateSessionConfig()); | 148 return scoped_ptr<CandidateSessionConfig>(new CandidateSessionConfig()); |
| 136 } | 149 } |
| 137 | 150 |
| 138 // static | 151 // static |
| 139 scoped_ptr<CandidateSessionConfig> CandidateSessionConfig::CreateFrom( | 152 scoped_ptr<CandidateSessionConfig> CandidateSessionConfig::CreateFrom( |
| 140 const SessionConfig& config) { | 153 const SessionConfig& config) { |
| 141 scoped_ptr<CandidateSessionConfig> result = CreateEmpty(); | 154 scoped_ptr<CandidateSessionConfig> result = CreateEmpty(); |
| 142 result->mutable_control_configs()->push_back(config.control_config()); | 155 result->mutable_control_configs()->push_back(config.control_config()); |
| 143 result->mutable_event_configs()->push_back(config.event_config()); | 156 result->mutable_event_configs()->push_back(config.event_config()); |
| 144 result->mutable_video_configs()->push_back(config.video_config()); | 157 result->mutable_video_configs()->push_back(config.video_config()); |
| 158 result->mutable_audio_configs()->push_back(config.audio_config()); | |
| 145 return result.Pass(); | 159 return result.Pass(); |
| 146 } | 160 } |
| 147 | 161 |
| 148 // static | 162 // static |
| 149 scoped_ptr<CandidateSessionConfig> CandidateSessionConfig::CreateDefault() { | 163 scoped_ptr<CandidateSessionConfig> CandidateSessionConfig::CreateDefault() { |
| 150 scoped_ptr<CandidateSessionConfig> result = CreateEmpty(); | 164 scoped_ptr<CandidateSessionConfig> result = CreateEmpty(); |
| 151 result->mutable_control_configs()->push_back( | 165 result->mutable_control_configs()->push_back( |
| 152 ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | 166 ChannelConfig(ChannelConfig::TRANSPORT_STREAM, |
| 153 kDefaultStreamVersion, | 167 kDefaultStreamVersion, |
| 154 ChannelConfig::CODEC_UNDEFINED)); | 168 ChannelConfig::CODEC_UNDEFINED)); |
| 155 result->mutable_event_configs()->push_back( | 169 result->mutable_event_configs()->push_back( |
| 156 ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | 170 ChannelConfig(ChannelConfig::TRANSPORT_STREAM, |
| 157 kDefaultStreamVersion, | 171 kDefaultStreamVersion, |
| 158 ChannelConfig::CODEC_UNDEFINED)); | 172 ChannelConfig::CODEC_UNDEFINED)); |
| 159 result->mutable_video_configs()->push_back( | 173 result->mutable_video_configs()->push_back( |
| 160 ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | 174 ChannelConfig(ChannelConfig::TRANSPORT_STREAM, |
| 161 kDefaultStreamVersion, | 175 kDefaultStreamVersion, |
| 162 ChannelConfig::CODEC_VP8)); | 176 ChannelConfig::CODEC_VP8)); |
| 177 result->mutable_audio_configs()->push_back( | |
| 178 ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | |
| 179 kDefaultStreamVersion, | |
| 180 ChannelConfig::CODEC_UNDEFINED)); | |
| 181 result->mutable_audio_configs()->push_back( | |
|
Sergey Ulanov
2012/06/21 17:24:56
Please make TRANSPORT_NONE the first audio config
kxing
2012/06/21 18:09:22
Done.
| |
| 182 ChannelConfig(ChannelConfig::TRANSPORT_NONE, | |
| 183 kDefaultStreamVersion, | |
| 184 ChannelConfig::CODEC_UNDEFINED)); | |
| 163 return result.Pass(); | 185 return result.Pass(); |
| 164 } | 186 } |
| 165 | 187 |
| 166 } // namespace protocol | 188 } // namespace protocol |
| 167 } // namespace remoting | 189 } // namespace remoting |
| OLD | NEW |