MD Downloads: prevent search text from overlapping with the cancel search (X)
[chromium-blink-merge.git] / remoting / protocol / session_config.h
blobcc444a08d502d31476f2ed98d801ccff201f0de0
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
3 // found in the LICENSE file.
5 #ifndef REMOTING_PROTOCOL_SESSION_CONFIG_H_
6 #define REMOTING_PROTOCOL_SESSION_CONFIG_H_
8 #include <list>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
14 namespace remoting {
15 namespace protocol {
17 extern const int kDefaultStreamVersion;
19 // Struct for configuration parameters of a single channel.
20 // Some channels (like video) may have multiple underlying sockets that need
21 // to be configured simultaneously.
22 struct ChannelConfig {
23 enum TransportType {
24 TRANSPORT_STREAM,
25 TRANSPORT_MUX_STREAM,
26 TRANSPORT_QUIC_STREAM,
27 TRANSPORT_DATAGRAM,
28 TRANSPORT_NONE,
31 enum Codec {
32 CODEC_UNDEFINED, // Used for event and control channels.
33 CODEC_VERBATIM,
34 CODEC_ZIP,
35 CODEC_VP8,
36 CODEC_VP9,
37 CODEC_OPUS,
38 CODEC_SPEEX,
41 // Creates a config with transport field set to TRANSPORT_NONE which indicates
42 // that corresponding channel is disabled.
43 static ChannelConfig None();
45 // Default constructor. Equivalent to None().
46 ChannelConfig() = default;
48 // Creates a channel config with the specified parameters.
49 ChannelConfig(TransportType transport, int version, Codec codec);
51 // operator== is overloaded so that std::find() works with
52 // std::list<ChannelConfig>.
53 bool operator==(const ChannelConfig& b) const;
55 TransportType transport = TRANSPORT_NONE;
56 int version = 0;
57 Codec codec = CODEC_UNDEFINED;
60 class CandidateSessionConfig;
62 // SessionConfig is used by the chromoting Session to store negotiated
63 // chromotocol configuration.
64 class SessionConfig {
65 public:
66 // Selects session configuration that is supported by both participants.
67 // nullptr is returned if such configuration doesn't exist. When selecting
68 // channel configuration priority is given to the configs listed first
69 // in |client_config|.
70 static scoped_ptr<SessionConfig> SelectCommon(
71 const CandidateSessionConfig* client_config,
72 const CandidateSessionConfig* host_config);
74 // Extracts final protocol configuration. Must be used for the description
75 // received in the session-accept stanza. If the selection is ambiguous
76 // (e.g. there is more than one configuration for one of the channel)
77 // or undefined (e.g. no configurations for a channel) then nullptr is
78 // returned.
79 static scoped_ptr<SessionConfig> GetFinalConfig(
80 const CandidateSessionConfig* candidate_config);
82 // Returns a suitable session configuration for use in tests.
83 static scoped_ptr<SessionConfig> ForTest();
84 static scoped_ptr<SessionConfig> ForTestWithVerbatimVideo();
86 bool standard_ice() const { return standard_ice_; }
88 const ChannelConfig& control_config() const { return control_config_; }
89 const ChannelConfig& event_config() const { return event_config_; }
90 const ChannelConfig& video_config() const { return video_config_; }
91 const ChannelConfig& audio_config() const { return audio_config_; }
93 bool is_audio_enabled() const {
94 return audio_config_.transport != ChannelConfig::TRANSPORT_NONE;
97 // Returns true if any of the channels is using QUIC.
98 bool is_using_quic() const {
99 return control_config_.transport == ChannelConfig::TRANSPORT_QUIC_STREAM ||
100 event_config_.transport == ChannelConfig::TRANSPORT_QUIC_STREAM ||
101 video_config_.transport == ChannelConfig::TRANSPORT_QUIC_STREAM ||
102 audio_config_.transport == ChannelConfig::TRANSPORT_QUIC_STREAM;
105 private:
106 SessionConfig();
108 bool standard_ice_ = true;
110 ChannelConfig control_config_;
111 ChannelConfig event_config_;
112 ChannelConfig video_config_;
113 ChannelConfig audio_config_;
116 // Defines session description that is sent from client to the host in the
117 // session-initiate message. It is different from the regular Config
118 // because it allows one to specify multiple configurations for each channel.
119 class CandidateSessionConfig {
120 public:
121 static scoped_ptr<CandidateSessionConfig> CreateEmpty();
122 static scoped_ptr<CandidateSessionConfig> CreateFrom(
123 const SessionConfig& config);
124 static scoped_ptr<CandidateSessionConfig> CreateDefault();
126 ~CandidateSessionConfig();
128 bool standard_ice() const { return standard_ice_; }
129 void set_standard_ice(bool standard_ice) { standard_ice_ = standard_ice; }
131 const std::list<ChannelConfig>& control_configs() const {
132 return control_configs_;
135 std::list<ChannelConfig>* mutable_control_configs() {
136 return &control_configs_;
139 const std::list<ChannelConfig>& event_configs() const {
140 return event_configs_;
143 std::list<ChannelConfig>* mutable_event_configs() {
144 return &event_configs_;
147 const std::list<ChannelConfig>& video_configs() const {
148 return video_configs_;
151 std::list<ChannelConfig>* mutable_video_configs() {
152 return &video_configs_;
155 const std::list<ChannelConfig>& audio_configs() const {
156 return audio_configs_;
159 std::list<ChannelConfig>* mutable_audio_configs() {
160 return &audio_configs_;
163 // Old clients always list VP9 as supported and preferred even though they
164 // shouldn't have it enabled yet. I.e. the host cannot trust VP9 codec
165 // preference received from the client. To workaround this issue the client
166 // adds a hint in the session-initiate message to indicate that it actually
167 // wants VP9 to be enabled.
169 // TODO(sergeyu): Remove this kludge as soon as VP9 is enabled by default.
170 bool vp9_experiment_enabled() const { return vp9_experiment_enabled_; }
171 void set_vp9_experiment_enabled(bool value) {
172 vp9_experiment_enabled_ = value;
175 // Returns true if |config| is supported.
176 bool IsSupported(const SessionConfig& config) const;
178 scoped_ptr<CandidateSessionConfig> Clone() const;
180 // Helpers for enabling/disabling specific features.
181 void DisableAudioChannel();
182 void PreferTransport(ChannelConfig::TransportType transport);
184 private:
185 CandidateSessionConfig();
186 explicit CandidateSessionConfig(const CandidateSessionConfig& config);
187 CandidateSessionConfig& operator=(const CandidateSessionConfig& b);
189 bool standard_ice_ = true;
191 std::list<ChannelConfig> control_configs_;
192 std::list<ChannelConfig> event_configs_;
193 std::list<ChannelConfig> video_configs_;
194 std::list<ChannelConfig> audio_configs_;
196 bool vp9_experiment_enabled_ = false;
199 } // namespace protocol
200 } // namespace remoting
202 #endif // REMOTING_PROTOCOL_SESSION_CONFIG_H_