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