| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/chromotocol_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 | 11 |
| 11 const int kDefaultStreamVersion = 1; | 12 const int kDefaultStreamVersion = 1; |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 const int kDefaultWidth = 800; | 15 const int kDefaultWidth = 800; |
| 15 const int kDefaultHeight = 600; | 16 const int kDefaultHeight = 600; |
| 16 } // namespace | 17 } // namespace |
| 17 | 18 |
| 18 ChannelConfig::ChannelConfig() { | 19 ChannelConfig::ChannelConfig() { |
| 19 Reset(); | 20 Reset(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 42 | 43 |
| 43 ScreenResolution::ScreenResolution(int width, int height) | 44 ScreenResolution::ScreenResolution(int width, int height) |
| 44 : width(width), | 45 : width(width), |
| 45 height(height) { | 46 height(height) { |
| 46 } | 47 } |
| 47 | 48 |
| 48 bool ScreenResolution::IsValid() const { | 49 bool ScreenResolution::IsValid() const { |
| 49 return width > 0 && height > 0; | 50 return width > 0 && height > 0; |
| 50 } | 51 } |
| 51 | 52 |
| 52 ChromotocolConfig::ChromotocolConfig() { } | 53 SessionConfig::SessionConfig() { } |
| 53 | 54 |
| 54 ChromotocolConfig::ChromotocolConfig(const ChromotocolConfig& config) | 55 SessionConfig::SessionConfig(const SessionConfig& config) |
| 55 : control_config_(config.control_config_), | 56 : control_config_(config.control_config_), |
| 56 event_config_(config.event_config_), | 57 event_config_(config.event_config_), |
| 57 video_config_(config.video_config_), | 58 video_config_(config.video_config_), |
| 58 initial_resolution_(config.initial_resolution_) { | 59 initial_resolution_(config.initial_resolution_) { |
| 59 } | 60 } |
| 60 | 61 |
| 61 ChromotocolConfig::~ChromotocolConfig() { } | 62 SessionConfig::~SessionConfig() { } |
| 62 | 63 |
| 63 void ChromotocolConfig::SetControlConfig(const ChannelConfig& control_config) { | 64 void SessionConfig::SetControlConfig(const ChannelConfig& control_config) { |
| 64 control_config_ = control_config; | 65 control_config_ = control_config; |
| 65 } | 66 } |
| 66 void ChromotocolConfig::SetEventConfig(const ChannelConfig& event_config) { | 67 void SessionConfig::SetEventConfig(const ChannelConfig& event_config) { |
| 67 event_config_ = event_config; | 68 event_config_ = event_config; |
| 68 } | 69 } |
| 69 void ChromotocolConfig::SetVideoConfig(const ChannelConfig& video_config) { | 70 void SessionConfig::SetVideoConfig(const ChannelConfig& video_config) { |
| 70 video_config_ = video_config; | 71 video_config_ = video_config; |
| 71 } | 72 } |
| 72 void ChromotocolConfig::SetInitialResolution(const ScreenResolution& resolution)
{ | 73 void SessionConfig::SetInitialResolution(const ScreenResolution& resolution) { |
| 73 initial_resolution_ = resolution; | 74 initial_resolution_ = resolution; |
| 74 } | 75 } |
| 75 | 76 |
| 76 ChromotocolConfig* ChromotocolConfig::Clone() const { | 77 SessionConfig* SessionConfig::Clone() const { |
| 77 return new ChromotocolConfig(*this); | 78 return new SessionConfig(*this); |
| 78 } | 79 } |
| 79 | 80 |
| 80 // static | 81 // static |
| 81 ChromotocolConfig* ChromotocolConfig::CreateDefault() { | 82 SessionConfig* SessionConfig::CreateDefault() { |
| 82 ChromotocolConfig* result = new ChromotocolConfig(); | 83 SessionConfig* result = new SessionConfig(); |
| 83 result->SetControlConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | 84 result->SetControlConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, |
| 84 kDefaultStreamVersion, | 85 kDefaultStreamVersion, |
| 85 ChannelConfig::CODEC_UNDEFINED)); | 86 ChannelConfig::CODEC_UNDEFINED)); |
| 86 result->SetEventConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | 87 result->SetEventConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, |
| 87 kDefaultStreamVersion, | 88 kDefaultStreamVersion, |
| 88 ChannelConfig::CODEC_UNDEFINED)); | 89 ChannelConfig::CODEC_UNDEFINED)); |
| 89 result->SetVideoConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | 90 result->SetVideoConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, |
| 90 kDefaultStreamVersion, | 91 kDefaultStreamVersion, |
| 91 ChannelConfig::CODEC_ZIP)); | 92 ChannelConfig::CODEC_ZIP)); |
| 92 return result; | 93 return result; |
| 93 } | 94 } |
| 94 | 95 |
| 95 CandidateChromotocolConfig::CandidateChromotocolConfig() { } | 96 CandidateSessionConfig::CandidateSessionConfig() { } |
| 96 | 97 |
| 97 CandidateChromotocolConfig::CandidateChromotocolConfig( | 98 CandidateSessionConfig::CandidateSessionConfig( |
| 98 const CandidateChromotocolConfig& config) | 99 const CandidateSessionConfig& config) |
| 99 : control_configs_(config.control_configs_), | 100 : control_configs_(config.control_configs_), |
| 100 event_configs_(config.event_configs_), | 101 event_configs_(config.event_configs_), |
| 101 video_configs_(config.video_configs_), | 102 video_configs_(config.video_configs_), |
| 102 initial_resolution_(config.initial_resolution_) { | 103 initial_resolution_(config.initial_resolution_) { |
| 103 } | 104 } |
| 104 | 105 |
| 105 CandidateChromotocolConfig::~CandidateChromotocolConfig() { } | 106 CandidateSessionConfig::~CandidateSessionConfig() { } |
| 106 | 107 |
| 107 void CandidateChromotocolConfig::AddControlConfig( | 108 void CandidateSessionConfig::AddControlConfig( |
| 108 const ChannelConfig& control_config) { | 109 const ChannelConfig& control_config) { |
| 109 control_configs_.push_back(control_config); | 110 control_configs_.push_back(control_config); |
| 110 } | 111 } |
| 111 | 112 |
| 112 void CandidateChromotocolConfig::AddEventConfig( | 113 void CandidateSessionConfig::AddEventConfig( |
| 113 const ChannelConfig& event_config) { | 114 const ChannelConfig& event_config) { |
| 114 event_configs_.push_back(event_config); | 115 event_configs_.push_back(event_config); |
| 115 } | 116 } |
| 116 | 117 |
| 117 void CandidateChromotocolConfig::AddVideoConfig( | 118 void CandidateSessionConfig::AddVideoConfig( |
| 118 const ChannelConfig& video_config) { | 119 const ChannelConfig& video_config) { |
| 119 video_configs_.push_back(video_config); | 120 video_configs_.push_back(video_config); |
| 120 } | 121 } |
| 121 | 122 |
| 122 void CandidateChromotocolConfig::SetInitialResolution( | 123 void CandidateSessionConfig::SetInitialResolution( |
| 123 const ScreenResolution& resolution) { | 124 const ScreenResolution& resolution) { |
| 124 initial_resolution_ = resolution; | 125 initial_resolution_ = resolution; |
| 125 } | 126 } |
| 126 | 127 |
| 127 ChromotocolConfig* CandidateChromotocolConfig::Select( | 128 SessionConfig* CandidateSessionConfig::Select( |
| 128 const CandidateChromotocolConfig* client_config, | 129 const CandidateSessionConfig* client_config, |
| 129 bool force_host_resolution) { | 130 bool force_host_resolution) { |
| 130 ChannelConfig control_config; | 131 ChannelConfig control_config; |
| 131 ChannelConfig event_config; | 132 ChannelConfig event_config; |
| 132 ChannelConfig video_config; | 133 ChannelConfig video_config; |
| 133 if (!SelectCommonChannelConfig( | 134 if (!SelectCommonChannelConfig( |
| 134 control_configs_, client_config->control_configs_, &control_config) || | 135 control_configs_, client_config->control_configs_, &control_config) || |
| 135 !SelectCommonChannelConfig( | 136 !SelectCommonChannelConfig( |
| 136 event_configs_, client_config->event_configs_, &event_config) || | 137 event_configs_, client_config->event_configs_, &event_config) || |
| 137 !SelectCommonChannelConfig( | 138 !SelectCommonChannelConfig( |
| 138 video_configs_, client_config->video_configs_, &video_config)) { | 139 video_configs_, client_config->video_configs_, &video_config)) { |
| 139 return NULL; | 140 return NULL; |
| 140 } | 141 } |
| 141 | 142 |
| 142 ChromotocolConfig* result = ChromotocolConfig::CreateDefault(); | 143 SessionConfig* result = SessionConfig::CreateDefault(); |
| 143 result->SetControlConfig(control_config); | 144 result->SetControlConfig(control_config); |
| 144 result->SetEventConfig(event_config); | 145 result->SetEventConfig(event_config); |
| 145 result->SetVideoConfig(video_config); | 146 result->SetVideoConfig(video_config); |
| 146 | 147 |
| 147 if (force_host_resolution) { | 148 if (force_host_resolution) { |
| 148 result->SetInitialResolution(initial_resolution()); | 149 result->SetInitialResolution(initial_resolution()); |
| 149 } else { | 150 } else { |
| 150 result->SetInitialResolution(client_config->initial_resolution()); | 151 result->SetInitialResolution(client_config->initial_resolution()); |
| 151 } | 152 } |
| 152 | 153 |
| 153 return result; | 154 return result; |
| 154 } | 155 } |
| 155 | 156 |
| 156 bool CandidateChromotocolConfig::IsSupported( | 157 bool CandidateSessionConfig::IsSupported( |
| 157 const ChromotocolConfig* config) const { | 158 const SessionConfig* config) const { |
| 158 return | 159 return |
| 159 IsChannelConfigSupported(control_configs_, config->control_config()) && | 160 IsChannelConfigSupported(control_configs_, config->control_config()) && |
| 160 IsChannelConfigSupported(event_configs_, config->event_config()) && | 161 IsChannelConfigSupported(event_configs_, config->event_config()) && |
| 161 IsChannelConfigSupported(video_configs_, config->video_config()) && | 162 IsChannelConfigSupported(video_configs_, config->video_config()) && |
| 162 config->initial_resolution().IsValid(); | 163 config->initial_resolution().IsValid(); |
| 163 } | 164 } |
| 164 | 165 |
| 165 ChromotocolConfig* CandidateChromotocolConfig::GetFinalConfig() const { | 166 SessionConfig* CandidateSessionConfig::GetFinalConfig() const { |
| 166 if (control_configs_.size() != 1 || | 167 if (control_configs_.size() != 1 || |
| 167 event_configs_.size() != 1 || | 168 event_configs_.size() != 1 || |
| 168 video_configs_.size() != 1) { | 169 video_configs_.size() != 1) { |
| 169 return NULL; | 170 return NULL; |
| 170 } | 171 } |
| 171 | 172 |
| 172 ChromotocolConfig* result = ChromotocolConfig::CreateDefault(); | 173 SessionConfig* result = SessionConfig::CreateDefault(); |
| 173 result->SetControlConfig(control_configs_.front()); | 174 result->SetControlConfig(control_configs_.front()); |
| 174 result->SetEventConfig(event_configs_.front()); | 175 result->SetEventConfig(event_configs_.front()); |
| 175 result->SetVideoConfig(video_configs_.front()); | 176 result->SetVideoConfig(video_configs_.front()); |
| 176 result->SetInitialResolution(initial_resolution_); | 177 result->SetInitialResolution(initial_resolution_); |
| 177 return result; | 178 return result; |
| 178 } | 179 } |
| 179 | 180 |
| 180 // static | 181 // static |
| 181 bool CandidateChromotocolConfig::SelectCommonChannelConfig( | 182 bool CandidateSessionConfig::SelectCommonChannelConfig( |
| 182 const std::vector<ChannelConfig>& host_configs, | 183 const std::vector<ChannelConfig>& host_configs, |
| 183 const std::vector<ChannelConfig>& client_configs, | 184 const std::vector<ChannelConfig>& client_configs, |
| 184 ChannelConfig* config) { | 185 ChannelConfig* config) { |
| 185 // Usually each of these vectors will contain just several elements, | 186 // Usually each of these vectors will contain just several elements, |
| 186 // so iterating over all of them is not a problem. | 187 // so iterating over all of them is not a problem. |
| 187 std::vector<ChannelConfig>::const_iterator it; | 188 std::vector<ChannelConfig>::const_iterator it; |
| 188 for (it = client_configs.begin(); it != client_configs.end(); ++it) { | 189 for (it = client_configs.begin(); it != client_configs.end(); ++it) { |
| 189 if (IsChannelConfigSupported(host_configs, *it)) { | 190 if (IsChannelConfigSupported(host_configs, *it)) { |
| 190 *config = *it; | 191 *config = *it; |
| 191 return true; | 192 return true; |
| 192 } | 193 } |
| 193 } | 194 } |
| 194 return false; | 195 return false; |
| 195 } | 196 } |
| 196 | 197 |
| 197 // static | 198 // static |
| 198 bool CandidateChromotocolConfig::IsChannelConfigSupported( | 199 bool CandidateSessionConfig::IsChannelConfigSupported( |
| 199 const std::vector<ChannelConfig>& vector, | 200 const std::vector<ChannelConfig>& vector, |
| 200 const ChannelConfig& value) { | 201 const ChannelConfig& value) { |
| 201 return std::find(vector.begin(), vector.end(), value) != vector.end(); | 202 return std::find(vector.begin(), vector.end(), value) != vector.end(); |
| 202 } | 203 } |
| 203 | 204 |
| 204 CandidateChromotocolConfig* CandidateChromotocolConfig::Clone() const { | 205 CandidateSessionConfig* CandidateSessionConfig::Clone() const { |
| 205 return new CandidateChromotocolConfig(*this); | 206 return new CandidateSessionConfig(*this); |
| 206 } | 207 } |
| 207 | 208 |
| 208 // static | 209 // static |
| 209 CandidateChromotocolConfig* CandidateChromotocolConfig::CreateEmpty() { | 210 CandidateSessionConfig* CandidateSessionConfig::CreateEmpty() { |
| 210 return new CandidateChromotocolConfig(); | 211 return new CandidateSessionConfig(); |
| 211 } | 212 } |
| 212 | 213 |
| 213 // static | 214 // static |
| 214 CandidateChromotocolConfig* CandidateChromotocolConfig::CreateFrom( | 215 CandidateSessionConfig* CandidateSessionConfig::CreateFrom( |
| 215 const ChromotocolConfig* config) { | 216 const SessionConfig* config) { |
| 216 CandidateChromotocolConfig* result = CreateEmpty(); | 217 CandidateSessionConfig* result = CreateEmpty(); |
| 217 result->AddControlConfig(config->control_config()); | 218 result->AddControlConfig(config->control_config()); |
| 218 result->AddEventConfig(config->event_config()); | 219 result->AddEventConfig(config->event_config()); |
| 219 result->AddVideoConfig(config->video_config()); | 220 result->AddVideoConfig(config->video_config()); |
| 220 result->SetInitialResolution(config->initial_resolution()); | 221 result->SetInitialResolution(config->initial_resolution()); |
| 221 return result; | 222 return result; |
| 222 } | 223 } |
| 223 | 224 |
| 224 // static | 225 // static |
| 225 CandidateChromotocolConfig* CandidateChromotocolConfig::CreateDefault() { | 226 CandidateSessionConfig* CandidateSessionConfig::CreateDefault() { |
| 226 CandidateChromotocolConfig* result = CreateEmpty(); | 227 CandidateSessionConfig* result = CreateEmpty(); |
| 227 result->AddControlConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | 228 result->AddControlConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, |
| 228 kDefaultStreamVersion, | 229 kDefaultStreamVersion, |
| 229 ChannelConfig::CODEC_UNDEFINED)); | 230 ChannelConfig::CODEC_UNDEFINED)); |
| 230 result->AddEventConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | 231 result->AddEventConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, |
| 231 kDefaultStreamVersion, | 232 kDefaultStreamVersion, |
| 232 ChannelConfig::CODEC_UNDEFINED)); | 233 ChannelConfig::CODEC_UNDEFINED)); |
| 233 | 234 |
| 234 result->AddVideoConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | 235 result->AddVideoConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, |
| 235 kDefaultStreamVersion, | 236 kDefaultStreamVersion, |
| 236 ChannelConfig::CODEC_ZIP)); | 237 ChannelConfig::CODEC_ZIP)); |
| 237 result->AddVideoConfig(ChannelConfig(ChannelConfig::TRANSPORT_SRTP, | 238 result->AddVideoConfig(ChannelConfig(ChannelConfig::TRANSPORT_SRTP, |
| 238 kDefaultStreamVersion, | 239 kDefaultStreamVersion, |
| 239 ChannelConfig::CODEC_VP8)); | 240 ChannelConfig::CODEC_VP8)); |
| 240 return result; | 241 return result; |
| 241 } | 242 } |
| 242 | 243 |
| 244 } // namespace protocol |
| 243 } // namespace remoting | 245 } // namespace remoting |
| OLD | NEW |