Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / remoting / protocol / session_config.h
blob0168a97eb69a1381ee6f6c5914ac1328aa7afa8b
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_DATAGRAM,
27 TRANSPORT_NONE,
30 enum Codec {
31 CODEC_UNDEFINED, // Used for event and control channels.
32 CODEC_VERBATIM,
33 CODEC_ZIP,
34 CODEC_VP8,
35 CODEC_VP9,
36 CODEC_OPUS,
37 CODEC_SPEEX,
40 // Creates a config with transport field set to TRANSPORT_NONE which indicates
41 // that corresponding channel is disabled.
42 static ChannelConfig None();
44 // Default constructor. Equivalent to None().
45 ChannelConfig() = default;
47 // Creates a channel config with the specified parameters.
48 ChannelConfig(TransportType transport, int version, Codec codec);
50 // operator== is overloaded so that std::find() works with
51 // std::list<ChannelConfig>.
52 bool operator==(const ChannelConfig& b) const;
54 TransportType transport = TRANSPORT_NONE;
55 int version = 0;
56 Codec codec = CODEC_UNDEFINED;
59 class CandidateSessionConfig;
61 // SessionConfig is used by the chromoting Session to store negotiated
62 // chromotocol configuration.
63 class SessionConfig {
64 public:
65 // Selects session configuration that is supported by both participants.
66 // nullptr is returned if such configuration doesn't exist. When selecting
67 // channel configuration priority is given to the configs listed first
68 // in |client_config|.
69 static scoped_ptr<SessionConfig> SelectCommon(
70 const CandidateSessionConfig* client_config,
71 const CandidateSessionConfig* host_config);
73 // Extracts final protocol configuration. Must be used for the description
74 // received in the session-accept stanza. If the selection is ambiguous
75 // (e.g. there is more than one configuration for one of the channel)
76 // or undefined (e.g. no configurations for a channel) then nullptr is
77 // returned.
78 static scoped_ptr<SessionConfig> GetFinalConfig(
79 const CandidateSessionConfig* candidate_config);
81 // Returns a suitable session configuration for use in tests.
82 static scoped_ptr<SessionConfig> ForTest();
84 bool standard_ice() const { return standard_ice_; }
86 const ChannelConfig& control_config() const { return control_config_; }
87 const ChannelConfig& event_config() const { return event_config_; }
88 const ChannelConfig& video_config() const { return video_config_; }
89 const ChannelConfig& audio_config() const { return audio_config_; }
91 bool is_audio_enabled() const {
92 return audio_config_.transport != ChannelConfig::TRANSPORT_NONE;
95 private:
96 SessionConfig();
98 bool standard_ice_ = true;
100 ChannelConfig control_config_;
101 ChannelConfig event_config_;
102 ChannelConfig video_config_;
103 ChannelConfig audio_config_;
106 // Defines session description that is sent from client to the host in the
107 // session-initiate message. It is different from the regular Config
108 // because it allows one to specify multiple configurations for each channel.
109 class CandidateSessionConfig {
110 public:
111 static scoped_ptr<CandidateSessionConfig> CreateEmpty();
112 static scoped_ptr<CandidateSessionConfig> CreateFrom(
113 const SessionConfig& config);
114 static scoped_ptr<CandidateSessionConfig> CreateDefault();
116 ~CandidateSessionConfig();
118 bool standard_ice() const { return standard_ice_; }
119 void set_standard_ice(bool standard_ice) { standard_ice_ = standard_ice; }
121 const std::list<ChannelConfig>& control_configs() const {
122 return control_configs_;
125 std::list<ChannelConfig>* mutable_control_configs() {
126 return &control_configs_;
129 const std::list<ChannelConfig>& event_configs() const {
130 return event_configs_;
133 std::list<ChannelConfig>* mutable_event_configs() {
134 return &event_configs_;
137 const std::list<ChannelConfig>& video_configs() const {
138 return video_configs_;
141 std::list<ChannelConfig>* mutable_video_configs() {
142 return &video_configs_;
145 const std::list<ChannelConfig>& audio_configs() const {
146 return audio_configs_;
149 std::list<ChannelConfig>* mutable_audio_configs() {
150 return &audio_configs_;
153 // Old clients always list VP9 as supported and preferred even though they
154 // shouldn't have it enabled yet. I.e. the host cannot trust VP9 codec
155 // preference received from the client. To workaround this issue the client
156 // adds a hint in the session-initiate message to indicate that it actually
157 // wants VP9 to be enabled.
159 // TODO(sergeyu): Remove this kludge as soon as VP9 is enabled by default.
160 bool vp9_experiment_enabled() const { return vp9_experiment_enabled_; }
161 void set_vp9_experiment_enabled(bool value) {
162 vp9_experiment_enabled_ = value;
165 // Returns true if |config| is supported.
166 bool IsSupported(const SessionConfig& config) const;
168 scoped_ptr<CandidateSessionConfig> Clone() const;
170 // Helpers for enabling/disabling specific features.
171 void DisableAudioChannel();
173 private:
174 CandidateSessionConfig();
175 explicit CandidateSessionConfig(const CandidateSessionConfig& config);
176 CandidateSessionConfig& operator=(const CandidateSessionConfig& b);
178 bool standard_ice_ = true;
180 std::list<ChannelConfig> control_configs_;
181 std::list<ChannelConfig> event_configs_;
182 std::list<ChannelConfig> video_configs_;
183 std::list<ChannelConfig> audio_configs_;
185 bool vp9_experiment_enabled_ = false;
188 } // namespace protocol
189 } // namespace remoting
191 #endif // REMOTING_PROTOCOL_SESSION_CONFIG_H_