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_
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
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
{
31 CODEC_UNDEFINED
, // Used for event and control channels.
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().
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
;
59 // SessionConfig is used by the chromoting Session to store negotiated
60 // chromotocol configuration.
65 void set_control_config(const ChannelConfig
& control_config
) {
66 control_config_
= control_config
;
68 const ChannelConfig
& control_config() const { return control_config_
; }
69 void set_event_config(const ChannelConfig
& event_config
) {
70 event_config_
= event_config
;
72 const ChannelConfig
& event_config() const { return event_config_
; }
73 void set_video_config(const ChannelConfig
& video_config
) {
74 video_config_
= video_config
;
76 const ChannelConfig
& video_config() const { return video_config_
; }
77 void set_audio_config(const ChannelConfig
& audio_config
) {
78 audio_config_
= audio_config
;
80 const ChannelConfig
& audio_config() const { return audio_config_
; }
82 bool is_audio_enabled() const {
83 return audio_config_
.transport
!= ChannelConfig::TRANSPORT_NONE
;
86 // Returns a suitable session configuration for use in tests.
87 static SessionConfig
ForTest();
90 ChannelConfig control_config_
;
91 ChannelConfig event_config_
;
92 ChannelConfig video_config_
;
93 ChannelConfig audio_config_
;
96 // Defines session description that is sent from client to the host in the
97 // session-initiate message. It is different from the regular Config
98 // because it allows one to specify multiple configurations for each channel.
99 class CandidateSessionConfig
{
101 static scoped_ptr
<CandidateSessionConfig
> CreateEmpty();
102 static scoped_ptr
<CandidateSessionConfig
> CreateFrom(
103 const SessionConfig
& config
);
104 static scoped_ptr
<CandidateSessionConfig
> CreateDefault();
106 ~CandidateSessionConfig();
108 const std::list
<ChannelConfig
>& control_configs() const {
109 return control_configs_
;
112 std::list
<ChannelConfig
>* mutable_control_configs() {
113 return &control_configs_
;
116 const std::list
<ChannelConfig
>& event_configs() const {
117 return event_configs_
;
120 std::list
<ChannelConfig
>* mutable_event_configs() {
121 return &event_configs_
;
124 const std::list
<ChannelConfig
>& video_configs() const {
125 return video_configs_
;
128 std::list
<ChannelConfig
>* mutable_video_configs() {
129 return &video_configs_
;
132 const std::list
<ChannelConfig
>& audio_configs() const {
133 return audio_configs_
;
136 std::list
<ChannelConfig
>* mutable_audio_configs() {
137 return &audio_configs_
;
140 // Selects session configuration that is supported by both participants.
141 // nullptr is returned if such configuration doesn't exist. When selecting
142 // channel configuration priority is given to the configs listed first
143 // in |client_config|.
144 bool Select(const CandidateSessionConfig
* client_config
,
145 SessionConfig
* result
);
147 // Returns true if |config| is supported.
148 bool IsSupported(const SessionConfig
& config
) const;
150 // Extracts final protocol configuration. Must be used for the description
151 // received in the session-accept stanza. If the selection is ambiguous
152 // (e.g. there is more than one configuration for one of the channel)
153 // or undefined (e.g. no configurations for a channel) then nullptr is
155 bool GetFinalConfig(SessionConfig
* result
) const;
157 scoped_ptr
<CandidateSessionConfig
> Clone() const;
159 // Helpers for enabling/disabling specific features.
160 void DisableAudioChannel();
161 void EnableVideoCodec(ChannelConfig::Codec codec
);
164 CandidateSessionConfig();
165 explicit CandidateSessionConfig(const CandidateSessionConfig
& config
);
166 CandidateSessionConfig
& operator=(const CandidateSessionConfig
& b
);
168 static bool SelectCommonChannelConfig(
169 const std::list
<ChannelConfig
>& host_configs_
,
170 const std::list
<ChannelConfig
>& client_configs_
,
171 ChannelConfig
* config
);
172 static bool IsChannelConfigSupported(const std::list
<ChannelConfig
>& list
,
173 const ChannelConfig
& value
);
175 std::list
<ChannelConfig
> control_configs_
;
176 std::list
<ChannelConfig
> event_configs_
;
177 std::list
<ChannelConfig
> video_configs_
;
178 std::list
<ChannelConfig
> audio_configs_
;
181 } // namespace protocol
182 } // namespace remoting
184 #endif // REMOTING_PROTOCOL_SESSION_CONFIG_H_