Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 : width(width), | 45 : width(width), |
| 46 height(height) { | 46 height(height) { |
| 47 } | 47 } |
| 48 | 48 |
| 49 bool ScreenResolution::IsValid() const { | 49 bool ScreenResolution::IsValid() const { |
| 50 return width > 0 && height > 0; | 50 return width > 0 && height > 0; |
| 51 } | 51 } |
| 52 | 52 |
| 53 SessionConfig::SessionConfig() { } | 53 SessionConfig::SessionConfig() { } |
| 54 | 54 |
| 55 SessionConfig::SessionConfig(const SessionConfig& config) | |
| 56 : control_config_(config.control_config_), | |
| 57 event_config_(config.event_config_), | |
| 58 video_config_(config.video_config_), | |
| 59 initial_resolution_(config.initial_resolution_) { | |
| 60 } | |
| 61 | |
| 62 SessionConfig::~SessionConfig() { } | 55 SessionConfig::~SessionConfig() { } |
| 63 | 56 |
| 64 void SessionConfig::SetControlConfig(const ChannelConfig& control_config) { | 57 void SessionConfig::SetControlConfig(const ChannelConfig& control_config) { |
| 65 control_config_ = control_config; | 58 control_config_ = control_config; |
| 66 } | 59 } |
| 67 void SessionConfig::SetEventConfig(const ChannelConfig& event_config) { | 60 void SessionConfig::SetEventConfig(const ChannelConfig& event_config) { |
| 68 event_config_ = event_config; | 61 event_config_ = event_config; |
| 69 } | 62 } |
| 70 void SessionConfig::SetVideoConfig(const ChannelConfig& video_config) { | 63 void SessionConfig::SetVideoConfig(const ChannelConfig& video_config) { |
| 71 video_config_ = video_config; | 64 video_config_ = video_config; |
| 72 } | 65 } |
| 73 void SessionConfig::SetInitialResolution(const ScreenResolution& resolution) { | 66 void SessionConfig::SetInitialResolution(const ScreenResolution& resolution) { |
| 74 initial_resolution_ = resolution; | 67 initial_resolution_ = resolution; |
| 75 } | 68 } |
| 76 | 69 |
| 77 SessionConfig* SessionConfig::Clone() const { | |
| 78 return new SessionConfig(*this); | |
| 79 } | |
| 80 | |
| 81 // static | 70 // static |
| 82 SessionConfig* SessionConfig::CreateDefault() { | 71 SessionConfig SessionConfig::GetDefault() { |
| 83 SessionConfig* result = new SessionConfig(); | 72 SessionConfig result; |
| 84 result->SetControlConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | 73 result.SetControlConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, |
| 85 kDefaultStreamVersion, | 74 kDefaultStreamVersion, |
| 86 ChannelConfig::CODEC_UNDEFINED)); | 75 ChannelConfig::CODEC_UNDEFINED)); |
| 87 result->SetEventConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | 76 result.SetEventConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, |
| 88 kDefaultStreamVersion, | 77 kDefaultStreamVersion, |
| 89 ChannelConfig::CODEC_UNDEFINED)); | 78 ChannelConfig::CODEC_UNDEFINED)); |
| 90 result->SetVideoConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | 79 result.SetVideoConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, |
| 91 kDefaultStreamVersion, | 80 kDefaultStreamVersion, |
| 92 ChannelConfig::CODEC_VP8)); | 81 ChannelConfig::CODEC_VP8)); |
| 93 return result; | 82 return result; |
| 94 } | 83 } |
| 95 | 84 |
| 96 CandidateSessionConfig::CandidateSessionConfig() { } | 85 CandidateSessionConfig::CandidateSessionConfig() { } |
| 97 | 86 |
| 98 CandidateSessionConfig::CandidateSessionConfig( | 87 CandidateSessionConfig::CandidateSessionConfig( |
| 99 const CandidateSessionConfig& config) | 88 const CandidateSessionConfig& config) |
| 100 : control_configs_(config.control_configs_), | 89 : control_configs_(config.control_configs_), |
| 101 event_configs_(config.event_configs_), | 90 event_configs_(config.event_configs_), |
| 102 video_configs_(config.video_configs_), | 91 video_configs_(config.video_configs_), |
| 103 initial_resolution_(config.initial_resolution_) { | 92 initial_resolution_(config.initial_resolution_) { |
| 104 } | 93 } |
| 105 | 94 |
| 106 CandidateSessionConfig::~CandidateSessionConfig() { } | 95 CandidateSessionConfig::~CandidateSessionConfig() { } |
| 107 | 96 |
| 108 SessionConfig* CandidateSessionConfig::Select( | 97 bool CandidateSessionConfig::Select( |
| 109 const CandidateSessionConfig* client_config, | 98 const CandidateSessionConfig* client_config, |
| 110 bool force_host_resolution) { | 99 bool force_host_resolution, |
| 100 SessionConfig* result) { | |
| 111 ChannelConfig control_config; | 101 ChannelConfig control_config; |
| 112 ChannelConfig event_config; | 102 ChannelConfig event_config; |
| 113 ChannelConfig video_config; | 103 ChannelConfig video_config; |
| 114 | 104 |
| 115 if (!SelectCommonChannelConfig( | 105 if (!SelectCommonChannelConfig( |
| 116 control_configs_, client_config->control_configs_, &control_config) || | 106 control_configs_, client_config->control_configs_, &control_config) || |
| 117 !SelectCommonChannelConfig( | 107 !SelectCommonChannelConfig( |
| 118 event_configs_, client_config->event_configs_, &event_config) || | 108 event_configs_, client_config->event_configs_, &event_config) || |
| 119 !SelectCommonChannelConfig( | 109 !SelectCommonChannelConfig( |
| 120 video_configs_, client_config->video_configs_, &video_config)) { | 110 video_configs_, client_config->video_configs_, &video_config)) { |
| 121 return NULL; | 111 return false; |
| 122 } | 112 } |
| 123 | 113 |
| 124 SessionConfig* result = SessionConfig::CreateDefault(); | |
| 125 result->SetControlConfig(control_config); | 114 result->SetControlConfig(control_config); |
| 126 result->SetEventConfig(event_config); | 115 result->SetEventConfig(event_config); |
| 127 result->SetVideoConfig(video_config); | 116 result->SetVideoConfig(video_config); |
| 128 | 117 |
| 129 if (force_host_resolution) { | 118 if (force_host_resolution) { |
| 130 result->SetInitialResolution(initial_resolution()); | 119 result->SetInitialResolution(initial_resolution()); |
| 131 } else { | 120 } else { |
| 132 result->SetInitialResolution(client_config->initial_resolution()); | 121 result->SetInitialResolution(client_config->initial_resolution()); |
| 133 } | 122 } |
| 134 | 123 |
| 135 return result; | 124 return true; |
| 136 } | 125 } |
| 137 | 126 |
| 138 bool CandidateSessionConfig::IsSupported( | 127 bool CandidateSessionConfig::IsSupported( |
| 139 const SessionConfig* config) const { | 128 const SessionConfig& config) const { |
| 140 return | 129 return |
| 141 IsChannelConfigSupported(control_configs_, config->control_config()) && | 130 IsChannelConfigSupported(control_configs_, config.control_config()) && |
| 142 IsChannelConfigSupported(event_configs_, config->event_config()) && | 131 IsChannelConfigSupported(event_configs_, config.event_config()) && |
| 143 IsChannelConfigSupported(video_configs_, config->video_config()) && | 132 IsChannelConfigSupported(video_configs_, config.video_config()) && |
| 144 config->initial_resolution().IsValid(); | 133 config.initial_resolution().IsValid(); |
| 145 } | 134 } |
| 146 | 135 |
| 147 SessionConfig* CandidateSessionConfig::GetFinalConfig() const { | 136 bool CandidateSessionConfig::GetFinalConfig(SessionConfig* result) const { |
| 148 if (control_configs_.size() != 1 || | 137 if (control_configs_.size() != 1 || |
| 149 event_configs_.size() != 1 || | 138 event_configs_.size() != 1 || |
| 150 video_configs_.size() != 1) { | 139 video_configs_.size() != 1) { |
| 151 return NULL; | 140 return false; |
| 152 } | 141 } |
| 153 | 142 |
| 154 SessionConfig* result = SessionConfig::CreateDefault(); | |
| 155 result->SetControlConfig(control_configs_.front()); | 143 result->SetControlConfig(control_configs_.front()); |
| 156 result->SetEventConfig(event_configs_.front()); | 144 result->SetEventConfig(event_configs_.front()); |
| 157 result->SetVideoConfig(video_configs_.front()); | 145 result->SetVideoConfig(video_configs_.front()); |
| 158 result->SetInitialResolution(initial_resolution_); | 146 result->SetInitialResolution(initial_resolution_); |
| 159 return result; | 147 |
| 148 return true; | |
| 160 } | 149 } |
| 161 | 150 |
| 162 // static | 151 // static |
| 163 bool CandidateSessionConfig::SelectCommonChannelConfig( | 152 bool CandidateSessionConfig::SelectCommonChannelConfig( |
| 164 const std::vector<ChannelConfig>& host_configs, | 153 const std::vector<ChannelConfig>& host_configs, |
| 165 const std::vector<ChannelConfig>& client_configs, | 154 const std::vector<ChannelConfig>& client_configs, |
| 166 ChannelConfig* config) { | 155 ChannelConfig* config) { |
| 167 // Usually each of these vectors will contain just several elements, | 156 // Usually each of these vectors will contain just several elements, |
| 168 // so iterating over all of them is not a problem. | 157 // so iterating over all of them is not a problem. |
| 169 std::vector<ChannelConfig>::const_iterator it; | 158 std::vector<ChannelConfig>::const_iterator it; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 187 return new CandidateSessionConfig(*this); | 176 return new CandidateSessionConfig(*this); |
| 188 } | 177 } |
| 189 | 178 |
| 190 // static | 179 // static |
| 191 CandidateSessionConfig* CandidateSessionConfig::CreateEmpty() { | 180 CandidateSessionConfig* CandidateSessionConfig::CreateEmpty() { |
| 192 return new CandidateSessionConfig(); | 181 return new CandidateSessionConfig(); |
| 193 } | 182 } |
| 194 | 183 |
| 195 // static | 184 // static |
| 196 CandidateSessionConfig* CandidateSessionConfig::CreateFrom( | 185 CandidateSessionConfig* CandidateSessionConfig::CreateFrom( |
| 197 const SessionConfig* config) { | 186 const SessionConfig& config) { |
| 198 CandidateSessionConfig* result = CreateEmpty(); | 187 CandidateSessionConfig* result = CreateEmpty(); |
| 199 result->mutable_control_configs()->push_back(config->control_config()); | 188 result->mutable_control_configs()->push_back(config.control_config()); |
| 200 result->mutable_event_configs()->push_back(config->event_config()); | 189 result->mutable_event_configs()->push_back(config.event_config()); |
| 201 result->mutable_video_configs()->push_back(config->video_config()); | 190 result->mutable_video_configs()->push_back(config.video_config()); |
| 202 *result->mutable_initial_resolution() = (config->initial_resolution()); | 191 *result->mutable_initial_resolution() = (config.initial_resolution()); |
|
Wez
2011/09/10 01:04:29
Typo!
Sergey Ulanov
2011/09/10 06:45:58
Where? The star in the beginning is needed. Remove
Wez
2011/09/11 01:17:41
|result| is a pointer-to-CandidateSessionConfig, s
| |
| 203 return result; | 192 return result; |
| 204 } | 193 } |
| 205 | 194 |
| 206 // static | 195 // static |
| 207 CandidateSessionConfig* CandidateSessionConfig::CreateDefault() { | 196 CandidateSessionConfig* CandidateSessionConfig::CreateDefault() { |
| 208 CandidateSessionConfig* result = CreateEmpty(); | 197 CandidateSessionConfig* result = CreateEmpty(); |
| 209 result->mutable_control_configs()->push_back( | 198 result->mutable_control_configs()->push_back( |
| 210 ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | 199 ChannelConfig(ChannelConfig::TRANSPORT_STREAM, |
| 211 kDefaultStreamVersion, | 200 kDefaultStreamVersion, |
| 212 ChannelConfig::CODEC_UNDEFINED)); | 201 ChannelConfig::CODEC_UNDEFINED)); |
| 213 result->mutable_event_configs()->push_back( | 202 result->mutable_event_configs()->push_back( |
| 214 ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | 203 ChannelConfig(ChannelConfig::TRANSPORT_STREAM, |
| 215 kDefaultStreamVersion, | 204 kDefaultStreamVersion, |
| 216 ChannelConfig::CODEC_UNDEFINED)); | 205 ChannelConfig::CODEC_UNDEFINED)); |
| 217 result->mutable_video_configs()->push_back( | 206 result->mutable_video_configs()->push_back( |
| 218 ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | 207 ChannelConfig(ChannelConfig::TRANSPORT_STREAM, |
| 219 kDefaultStreamVersion, | 208 kDefaultStreamVersion, |
| 220 ChannelConfig::CODEC_VP8)); | 209 ChannelConfig::CODEC_VP8)); |
| 221 return result; | 210 return result; |
| 222 } | 211 } |
| 223 | 212 |
| 224 } // namespace protocol | 213 } // namespace protocol |
| 225 } // namespace remoting | 214 } // namespace remoting |
| OLD | NEW |