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().
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
;
56 Codec codec
= CODEC_UNDEFINED
;
59 class CandidateSessionConfig
;
61 // SessionConfig is used by the chromoting Session to store negotiated
62 // chromotocol configuration.
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
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();
83 static scoped_ptr
<SessionConfig
> WithLegacyIceForTest();
85 bool standard_ice() const { return standard_ice_
; }
87 const ChannelConfig
& control_config() const { return control_config_
; }
88 const ChannelConfig
& event_config() const { return event_config_
; }
89 const ChannelConfig
& video_config() const { return video_config_
; }
90 const ChannelConfig
& audio_config() const { return audio_config_
; }
92 bool is_audio_enabled() const {
93 return audio_config_
.transport
!= ChannelConfig::TRANSPORT_NONE
;
99 bool standard_ice_
= true;
101 ChannelConfig control_config_
;
102 ChannelConfig event_config_
;
103 ChannelConfig video_config_
;
104 ChannelConfig audio_config_
;
107 // Defines session description that is sent from client to the host in the
108 // session-initiate message. It is different from the regular Config
109 // because it allows one to specify multiple configurations for each channel.
110 class CandidateSessionConfig
{
112 static scoped_ptr
<CandidateSessionConfig
> CreateEmpty();
113 static scoped_ptr
<CandidateSessionConfig
> CreateFrom(
114 const SessionConfig
& config
);
115 static scoped_ptr
<CandidateSessionConfig
> CreateDefault();
117 ~CandidateSessionConfig();
119 bool standard_ice() const { return standard_ice_
; }
120 void set_standard_ice(bool standard_ice
) { standard_ice_
= standard_ice
; }
122 const std::list
<ChannelConfig
>& control_configs() const {
123 return control_configs_
;
126 std::list
<ChannelConfig
>* mutable_control_configs() {
127 return &control_configs_
;
130 const std::list
<ChannelConfig
>& event_configs() const {
131 return event_configs_
;
134 std::list
<ChannelConfig
>* mutable_event_configs() {
135 return &event_configs_
;
138 const std::list
<ChannelConfig
>& video_configs() const {
139 return video_configs_
;
142 std::list
<ChannelConfig
>* mutable_video_configs() {
143 return &video_configs_
;
146 const std::list
<ChannelConfig
>& audio_configs() const {
147 return audio_configs_
;
150 std::list
<ChannelConfig
>* mutable_audio_configs() {
151 return &audio_configs_
;
154 // Returns true if |config| is supported.
155 bool IsSupported(const SessionConfig
& config
) 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 bool standard_ice_
= true;
170 std::list
<ChannelConfig
> control_configs_
;
171 std::list
<ChannelConfig
> event_configs_
;
172 std::list
<ChannelConfig
> video_configs_
;
173 std::list
<ChannelConfig
> audio_configs_
;
176 } // namespace protocol
177 } // namespace remoting
179 #endif // REMOTING_PROTOCOL_SESSION_CONFIG_H_