From c3ddba29664d91b8910489150171496b28355bbb Mon Sep 17 00:00:00 2001 From: "garykac@chromium.org" Date: Mon, 8 Nov 2010 23:34:23 +0000 Subject: Chromoting: Rename ChromotocolConfig -> SessionConfig BUG=none TEST=build chrome, chromoting Review URL: http://codereview.chromium.org/4446005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65451 0039d316-1c4b-4281-b951-d872f2087c98 --- remoting/protocol/chromotocol_config.cc | 243 ------------------------ remoting/protocol/chromotocol_config.h | 162 ---------------- remoting/protocol/fake_session.cc | 13 +- remoting/protocol/fake_session.h | 12 +- remoting/protocol/jingle_connection_to_host.cc | 4 +- remoting/protocol/jingle_session.cc | 10 +- remoting/protocol/jingle_session.h | 12 +- remoting/protocol/jingle_session_manager.cc | 22 +-- remoting/protocol/jingle_session_manager.h | 12 +- remoting/protocol/jingle_session_unittest.cc | 8 +- remoting/protocol/protocol_test_client.cc | 6 +- remoting/protocol/session.h | 10 +- remoting/protocol/session_config.cc | 245 +++++++++++++++++++++++++ remoting/protocol/session_config.h | 165 +++++++++++++++++ remoting/protocol/session_manager.h | 10 +- remoting/protocol/video_reader.cc | 4 +- remoting/protocol/video_reader.h | 12 +- remoting/protocol/video_writer.cc | 4 +- remoting/protocol/video_writer.h | 12 +- 19 files changed, 476 insertions(+), 490 deletions(-) delete mode 100644 remoting/protocol/chromotocol_config.cc delete mode 100644 remoting/protocol/chromotocol_config.h create mode 100644 remoting/protocol/session_config.cc create mode 100644 remoting/protocol/session_config.h (limited to 'remoting/protocol') diff --git a/remoting/protocol/chromotocol_config.cc b/remoting/protocol/chromotocol_config.cc deleted file mode 100644 index 943fdbb..0000000 --- a/remoting/protocol/chromotocol_config.cc +++ /dev/null @@ -1,243 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "remoting/protocol/chromotocol_config.h" - -#include - -namespace remoting { - -const int kDefaultStreamVersion = 1; - -namespace { -const int kDefaultWidth = 800; -const int kDefaultHeight = 600; -} // namespace - -ChannelConfig::ChannelConfig() { - Reset(); -} - -ChannelConfig::ChannelConfig(TransportType transport, int version, Codec codec) - : transport(transport), - version(version), - codec(codec) { -} - -bool ChannelConfig::operator==(const ChannelConfig& b) const { - return transport == b.transport && version == b.version && codec == b.codec; -} - -void ChannelConfig::Reset() { - transport = TRANSPORT_STREAM; - version = kDefaultStreamVersion; - codec = CODEC_UNDEFINED; -} - -ScreenResolution::ScreenResolution() - : width(kDefaultWidth), - height(kDefaultHeight) { -} - -ScreenResolution::ScreenResolution(int width, int height) - : width(width), - height(height) { -} - -bool ScreenResolution::IsValid() const { - return width > 0 && height > 0; -} - -ChromotocolConfig::ChromotocolConfig() { } - -ChromotocolConfig::ChromotocolConfig(const ChromotocolConfig& config) - : control_config_(config.control_config_), - event_config_(config.event_config_), - video_config_(config.video_config_), - initial_resolution_(config.initial_resolution_) { -} - -ChromotocolConfig::~ChromotocolConfig() { } - -void ChromotocolConfig::SetControlConfig(const ChannelConfig& control_config) { - control_config_ = control_config; -} -void ChromotocolConfig::SetEventConfig(const ChannelConfig& event_config) { - event_config_ = event_config; -} -void ChromotocolConfig::SetVideoConfig(const ChannelConfig& video_config) { - video_config_ = video_config; -} -void ChromotocolConfig::SetInitialResolution(const ScreenResolution& resolution) { - initial_resolution_ = resolution; -} - -ChromotocolConfig* ChromotocolConfig::Clone() const { - return new ChromotocolConfig(*this); -} - -// static -ChromotocolConfig* ChromotocolConfig::CreateDefault() { - ChromotocolConfig* result = new ChromotocolConfig(); - result->SetControlConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, - kDefaultStreamVersion, - ChannelConfig::CODEC_UNDEFINED)); - result->SetEventConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, - kDefaultStreamVersion, - ChannelConfig::CODEC_UNDEFINED)); - result->SetVideoConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, - kDefaultStreamVersion, - ChannelConfig::CODEC_ZIP)); - return result; -} - -CandidateChromotocolConfig::CandidateChromotocolConfig() { } - -CandidateChromotocolConfig::CandidateChromotocolConfig( - const CandidateChromotocolConfig& config) - : control_configs_(config.control_configs_), - event_configs_(config.event_configs_), - video_configs_(config.video_configs_), - initial_resolution_(config.initial_resolution_) { -} - -CandidateChromotocolConfig::~CandidateChromotocolConfig() { } - -void CandidateChromotocolConfig::AddControlConfig( - const ChannelConfig& control_config) { - control_configs_.push_back(control_config); -} - -void CandidateChromotocolConfig::AddEventConfig( - const ChannelConfig& event_config) { - event_configs_.push_back(event_config); -} - -void CandidateChromotocolConfig::AddVideoConfig( - const ChannelConfig& video_config) { - video_configs_.push_back(video_config); -} - -void CandidateChromotocolConfig::SetInitialResolution( - const ScreenResolution& resolution) { - initial_resolution_ = resolution; -} - -ChromotocolConfig* CandidateChromotocolConfig::Select( - const CandidateChromotocolConfig* client_config, - bool force_host_resolution) { - ChannelConfig control_config; - ChannelConfig event_config; - ChannelConfig video_config; - if (!SelectCommonChannelConfig( - control_configs_, client_config->control_configs_, &control_config) || - !SelectCommonChannelConfig( - event_configs_, client_config->event_configs_, &event_config) || - !SelectCommonChannelConfig( - video_configs_, client_config->video_configs_, &video_config)) { - return NULL; - } - - ChromotocolConfig* result = ChromotocolConfig::CreateDefault(); - result->SetControlConfig(control_config); - result->SetEventConfig(event_config); - result->SetVideoConfig(video_config); - - if (force_host_resolution) { - result->SetInitialResolution(initial_resolution()); - } else { - result->SetInitialResolution(client_config->initial_resolution()); - } - - return result; -} - -bool CandidateChromotocolConfig::IsSupported( - const ChromotocolConfig* config) const { - return - IsChannelConfigSupported(control_configs_, config->control_config()) && - IsChannelConfigSupported(event_configs_, config->event_config()) && - IsChannelConfigSupported(video_configs_, config->video_config()) && - config->initial_resolution().IsValid(); -} - -ChromotocolConfig* CandidateChromotocolConfig::GetFinalConfig() const { - if (control_configs_.size() != 1 || - event_configs_.size() != 1 || - video_configs_.size() != 1) { - return NULL; - } - - ChromotocolConfig* result = ChromotocolConfig::CreateDefault(); - result->SetControlConfig(control_configs_.front()); - result->SetEventConfig(event_configs_.front()); - result->SetVideoConfig(video_configs_.front()); - result->SetInitialResolution(initial_resolution_); - return result; -} - -// static -bool CandidateChromotocolConfig::SelectCommonChannelConfig( - const std::vector& host_configs, - const std::vector& client_configs, - ChannelConfig* config) { - // Usually each of these vectors will contain just several elements, - // so iterating over all of them is not a problem. - std::vector::const_iterator it; - for (it = client_configs.begin(); it != client_configs.end(); ++it) { - if (IsChannelConfigSupported(host_configs, *it)) { - *config = *it; - return true; - } - } - return false; -} - -// static -bool CandidateChromotocolConfig::IsChannelConfigSupported( - const std::vector& vector, - const ChannelConfig& value) { - return std::find(vector.begin(), vector.end(), value) != vector.end(); -} - -CandidateChromotocolConfig* CandidateChromotocolConfig::Clone() const { - return new CandidateChromotocolConfig(*this); -} - -// static -CandidateChromotocolConfig* CandidateChromotocolConfig::CreateEmpty() { - return new CandidateChromotocolConfig(); -} - -// static -CandidateChromotocolConfig* CandidateChromotocolConfig::CreateFrom( - const ChromotocolConfig* config) { - CandidateChromotocolConfig* result = CreateEmpty(); - result->AddControlConfig(config->control_config()); - result->AddEventConfig(config->event_config()); - result->AddVideoConfig(config->video_config()); - result->SetInitialResolution(config->initial_resolution()); - return result; -} - -// static -CandidateChromotocolConfig* CandidateChromotocolConfig::CreateDefault() { - CandidateChromotocolConfig* result = CreateEmpty(); - result->AddControlConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, - kDefaultStreamVersion, - ChannelConfig::CODEC_UNDEFINED)); - result->AddEventConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, - kDefaultStreamVersion, - ChannelConfig::CODEC_UNDEFINED)); - - result->AddVideoConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, - kDefaultStreamVersion, - ChannelConfig::CODEC_ZIP)); - result->AddVideoConfig(ChannelConfig(ChannelConfig::TRANSPORT_SRTP, - kDefaultStreamVersion, - ChannelConfig::CODEC_VP8)); - return result; -} - -} // namespace remoting diff --git a/remoting/protocol/chromotocol_config.h b/remoting/protocol/chromotocol_config.h deleted file mode 100644 index aef2ecc..0000000 --- a/remoting/protocol/chromotocol_config.h +++ /dev/null @@ -1,162 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef REMOTING_PROTOCOL_CHROMOTOCOL_CONFIG_H_ -#define REMOTING_PROTOCOL_CHROMOTOCOL_CONFIG_H_ - -#include -#include - -#include "base/basictypes.h" - -namespace remoting { - -extern const int kDefaultStreamVersion; - -// Struct for configuration parameters of a single channel. -struct ChannelConfig { - enum TransportType { - TRANSPORT_STREAM, - TRANSPORT_DATAGRAM, - TRANSPORT_SRTP, - TRANSPORT_RTP_DTLS, - }; - - enum Codec { - CODEC_UNDEFINED, // Used for event and control channels. - CODEC_VERBATIM, - CODEC_ZIP, - CODEC_VP8, - }; - - ChannelConfig(); - ChannelConfig(TransportType transport, int version, Codec codec); - - // operator== is overloaded so that std::find() works with - // std::vector. - bool operator==(const ChannelConfig& b) const; - - void Reset(); - - TransportType transport; - int version; - Codec codec; -}; - -struct ScreenResolution { - ScreenResolution(); - ScreenResolution(int width, int height); - - bool IsValid() const; - - int width; - int height; -}; - -// ChromotocolConfig is used by ChromotingConnection to store negotiated -// chromotocol configuration. -class ChromotocolConfig { - public: - ~ChromotocolConfig(); - - const ChannelConfig& control_config() const { return control_config_; } - const ChannelConfig& event_config() const { return event_config_; } - const ChannelConfig& video_config() const { return video_config_; } - const ScreenResolution& initial_resolution() const { - return initial_resolution_; - } - - void SetControlConfig(const ChannelConfig& control_config); - void SetEventConfig(const ChannelConfig& event_config); - void SetVideoConfig(const ChannelConfig& video_config); - void SetInitialResolution(const ScreenResolution& initial_resolution); - - ChromotocolConfig* Clone() const; - - static ChromotocolConfig* CreateDefault(); - - private: - ChromotocolConfig(); - explicit ChromotocolConfig(const ChromotocolConfig& config); - ChromotocolConfig& operator=(const ChromotocolConfig& b); - - ChannelConfig control_config_; - ChannelConfig event_config_; - ChannelConfig video_config_; - ScreenResolution initial_resolution_; -}; - -// Defines session description that is sent from client to the host in the -// session-initiate message. It is different from the regular ChromotocolConfig -// because it allows one to specify multiple configurations for each channel. -class CandidateChromotocolConfig { - public: - ~CandidateChromotocolConfig(); - - const std::vector& control_configs() const { - return control_configs_; - } - - const std::vector& event_configs() const { - return event_configs_; - } - - const std::vector& video_configs() const { - return video_configs_; - } - - const ScreenResolution& initial_resolution() const { - return initial_resolution_; - } - - void AddControlConfig(const ChannelConfig& control_config); - void AddEventConfig(const ChannelConfig& event_config); - void AddVideoConfig(const ChannelConfig& video_config); - void SetInitialResolution(const ScreenResolution& initial_resolution); - - // Selects session configuration that is supported by both participants. - // NULL is returned if such configuration doesn't exist. When selecting - // channel configuration priority is given to the configs listed first - // in |client_config|. - ChromotocolConfig* Select(const CandidateChromotocolConfig* client_config, - bool force_host_resolution); - - // Returns true if |config| is supported. - bool IsSupported(const ChromotocolConfig* config) const; - - // Extracts final protocol configuration. Must be used for the description - // received in the session-accept stanza. If the selection is ambiguous - // (e.g. there is more than one configuration for one of the channel) - // or undefined (e.g. no configurations for a channel) then NULL is returned. - ChromotocolConfig* GetFinalConfig() const; - - CandidateChromotocolConfig* Clone() const; - - static CandidateChromotocolConfig* CreateEmpty(); - static CandidateChromotocolConfig* CreateFrom( - const ChromotocolConfig* config); - static CandidateChromotocolConfig* CreateDefault(); - - private: - CandidateChromotocolConfig(); - explicit CandidateChromotocolConfig(const CandidateChromotocolConfig& config); - CandidateChromotocolConfig& operator=(const CandidateChromotocolConfig& b); - - static bool SelectCommonChannelConfig( - const std::vector& host_configs_, - const std::vector& client_configs_, - ChannelConfig* config); - static bool IsChannelConfigSupported(const std::vector& vector, - const ChannelConfig& value); - - std::vector control_configs_; - std::vector event_configs_; - std::vector video_configs_; - - ScreenResolution initial_resolution_; -}; - -} // namespace remoting - -#endif // REMOTING_PROTOCOL_CHROMOTOCOL_CONFIG_H_ diff --git a/remoting/protocol/fake_session.cc b/remoting/protocol/fake_session.cc index 492f4d8..4b3ff51 100644 --- a/remoting/protocol/fake_session.cc +++ b/remoting/protocol/fake_session.cc @@ -9,7 +9,6 @@ #include "net/base/net_errors.h" namespace remoting { - namespace protocol { const char kTestJid[] = "host1@gmail.com/chromoting123"; @@ -72,8 +71,8 @@ bool FakeSocket::SetSendBufferSize(int32 size) { } FakeSession::FakeSession() - : candidate_config_(CandidateChromotocolConfig::CreateDefault()), - config_(ChromotocolConfig::CreateDefault()), + : candidate_config_(CandidateSessionConfig::CreateDefault()), + config_(SessionConfig::CreateDefault()), message_loop_(NULL), jid_(kTestJid) { } @@ -113,17 +112,16 @@ MessageLoop* FakeSession::message_loop() { return message_loop_; } -const CandidateChromotocolConfig* -FakeSession::candidate_config() { +const CandidateSessionConfig* FakeSession::candidate_config() { return candidate_config_.get(); } -const ChromotocolConfig* FakeSession::config() { +const SessionConfig* FakeSession::config() { CHECK(config_.get()); return config_.get(); } -void FakeSession::set_config(const ChromotocolConfig* config) { +void FakeSession::set_config(const SessionConfig* config) { config_.reset(config); } @@ -134,5 +132,4 @@ void FakeSession::Close(Task* closed_task) { } } // namespace protocol - } // namespace remoting diff --git a/remoting/protocol/fake_session.h b/remoting/protocol/fake_session.h index d325351..9b216fe 100644 --- a/remoting/protocol/fake_session.h +++ b/remoting/protocol/fake_session.h @@ -12,7 +12,6 @@ #include "remoting/protocol/session.h" namespace remoting { - namespace protocol { extern const char kTestJid[]; @@ -79,16 +78,16 @@ class FakeSession : public Session { virtual const std::string& jid(); virtual MessageLoop* message_loop(); - virtual const CandidateChromotocolConfig* candidate_config(); - virtual const ChromotocolConfig* config(); - virtual void set_config(const ChromotocolConfig* config); + virtual const CandidateSessionConfig* candidate_config(); + virtual const SessionConfig* config(); + virtual void set_config(const SessionConfig* config); virtual void Close(Task* closed_task); public: scoped_ptr callback_; - scoped_ptr candidate_config_; - scoped_ptr config_; + scoped_ptr candidate_config_; + scoped_ptr config_; MessageLoop* message_loop_; FakeSocket control_channel_; FakeSocket event_channel_; @@ -100,7 +99,6 @@ class FakeSession : public Session { }; } // namespace protocol - } // namespace remoting #endif // REMOTING_PROTOCOL_FAKE_SESSION_H_ diff --git a/remoting/protocol/jingle_connection_to_host.cc b/remoting/protocol/jingle_connection_to_host.cc index ec73780..e31d351 100644 --- a/remoting/protocol/jingle_connection_to_host.cc +++ b/remoting/protocol/jingle_connection_to_host.cc @@ -82,8 +82,8 @@ void JingleConnectionToHost::InitSession() { NewCallback(this, &JingleConnectionToHost::OnNewSession)); session_manager_ = session_manager; - CandidateChromotocolConfig* candidate_config = - CandidateChromotocolConfig::CreateDefault(); + CandidateSessionConfig* candidate_config = + CandidateSessionConfig::CreateDefault(); // TODO(sergeyu): Set resolution in the |candidate_config| to the desired // resolution. diff --git a/remoting/protocol/jingle_session.cc b/remoting/protocol/jingle_session.cc index 4ed6b4f..9988f30 100644 --- a/remoting/protocol/jingle_session.cc +++ b/remoting/protocol/jingle_session.cc @@ -114,25 +114,25 @@ MessageLoop* JingleSession::message_loop() { return jingle_session_manager_->message_loop(); } -const CandidateChromotocolConfig* +const CandidateSessionConfig* JingleSession::candidate_config() { DCHECK(candidate_config_.get()); return candidate_config_.get(); } void JingleSession::set_candidate_config( - const CandidateChromotocolConfig* candidate_config) { + const CandidateSessionConfig* candidate_config) { DCHECK(!candidate_config_.get()); DCHECK(candidate_config); candidate_config_.reset(candidate_config); } -const ChromotocolConfig* JingleSession::config() { +const SessionConfig* JingleSession::config() { DCHECK(config_.get()); return config_.get(); } -void JingleSession::set_config(const ChromotocolConfig* config) { +void JingleSession::set_config(const SessionConfig* config) { DCHECK(!config_.get()); DCHECK(config); config_.reset(config); @@ -281,7 +281,7 @@ void JingleSession::OnAccept() { const protocol::ContentDescription* content_description = static_cast(content->description); - ChromotocolConfig* config = content_description->config()->GetFinalConfig(); + SessionConfig* config = content_description->config()->GetFinalConfig(); // Terminate the session if the config we received is invalid. if (!config || !candidate_config()->IsSupported(config)) { diff --git a/remoting/protocol/jingle_session.h b/remoting/protocol/jingle_session.h index dcebbd1..32654fc 100644 --- a/remoting/protocol/jingle_session.h +++ b/remoting/protocol/jingle_session.h @@ -51,10 +51,10 @@ class JingleSession : public protocol::Session, virtual const std::string& jid(); virtual MessageLoop* message_loop(); - virtual const CandidateChromotocolConfig* candidate_config(); - virtual const ChromotocolConfig* config(); + virtual const CandidateSessionConfig* candidate_config(); + virtual const SessionConfig* config(); - virtual void set_config(const ChromotocolConfig* config); + virtual void set_config(const SessionConfig* config); virtual void Close(Task* closed_task); @@ -65,7 +65,7 @@ class JingleSession : public protocol::Session, friend class JingleSessionManager; // Called by JingleSessionManager. - void set_candidate_config(const CandidateChromotocolConfig* candidate_config); + void set_candidate_config(const CandidateSessionConfig* candidate_config); void Init(cricket::Session* cricket_session); bool HasSession(cricket::Session* cricket_session); cricket::Session* ReleaseSession(); @@ -95,8 +95,8 @@ class JingleSession : public protocol::Session, // The corresponding libjingle session. cricket::Session* cricket_session_; - scoped_ptr candidate_config_; - scoped_ptr config_; + scoped_ptr candidate_config_; + scoped_ptr config_; cricket::PseudoTcpChannel* control_channel_; scoped_ptr control_channel_adapter_; diff --git a/remoting/protocol/jingle_session_manager.cc b/remoting/protocol/jingle_session_manager.cc index 8784f83..e5e17bf 100644 --- a/remoting/protocol/jingle_session_manager.cc +++ b/remoting/protocol/jingle_session_manager.cc @@ -18,7 +18,6 @@ using buzz::QName; using buzz::XmlElement; namespace remoting { - namespace protocol { namespace { @@ -151,8 +150,8 @@ bool ParseChannelConfig(const XmlElement* element, bool codec_required, } // namespace ContentDescription::ContentDescription( - const CandidateChromotocolConfig* config) - : candidate_config_(config) { + const CandidateSessionConfig* candidate_config) + : candidate_config_(candidate_config) { } ContentDescription::~ContentDescription() { } @@ -220,12 +219,12 @@ void JingleSessionManager::set_allow_local_ips(bool allow_local_ips) { scoped_refptr JingleSessionManager::Connect( const std::string& jid, - CandidateChromotocolConfig* chromotocol_config, + CandidateSessionConfig* candidate_config, protocol::Session::StateChangeCallback* state_change_callback) { // Can be called from any thread. scoped_refptr jingle_session( new JingleSession(this)); - jingle_session->set_candidate_config(chromotocol_config); + jingle_session->set_candidate_config(candidate_config); message_loop()->PostTask( FROM_HERE, NewRunnableMethod(this, &JingleSessionManager::DoConnect, jingle_session, jid, @@ -320,8 +319,8 @@ void JingleSessionManager::AcceptConnection( case protocol::SessionManager::ACCEPT: { // Connection must be configured by the callback. DCHECK(jingle_session->config()); - CandidateChromotocolConfig* candidate_config = - CandidateChromotocolConfig::CreateFrom(jingle_session->config()); + CandidateSessionConfig* candidate_config = + CandidateSessionConfig::CreateFrom(jingle_session->config()); cricket_session->Accept(CreateSessionDescription(candidate_config)); break; } @@ -349,8 +348,8 @@ bool JingleSessionManager::ParseContent( const cricket::ContentDescription** content, cricket::ParseError* error) { if (element->Name() == QName(kChromotingXmlNamespace, kDescriptionTag)) { - scoped_ptr config( - CandidateChromotocolConfig::CreateEmpty()); + scoped_ptr config( + CandidateSessionConfig::CreateEmpty()); const XmlElement* child = NULL; // tags. @@ -432,7 +431,7 @@ bool JingleSessionManager::WriteContent( XmlElement* root = new XmlElement( QName(kChromotingXmlNamespace, kDescriptionTag), true); - const CandidateChromotocolConfig* config = desc->config(); + const CandidateSessionConfig* config = desc->config(); std::vector::const_iterator it; for (it = config->control_configs().begin(); @@ -465,7 +464,7 @@ bool JingleSessionManager::WriteContent( } SessionDescription* JingleSessionManager::CreateSessionDescription( - const CandidateChromotocolConfig* config) { + const CandidateSessionConfig* config) { SessionDescription* desc = new SessionDescription(); desc->AddContent(JingleSession::kChromotingContentName, kChromotingXmlNamespace, @@ -474,5 +473,4 @@ SessionDescription* JingleSessionManager::CreateSessionDescription( } } // namespace protocol - } // namespace remoting diff --git a/remoting/protocol/jingle_session_manager.h b/remoting/protocol/jingle_session_manager.h index 7241002..f6ad45ab 100644 --- a/remoting/protocol/jingle_session_manager.h +++ b/remoting/protocol/jingle_session_manager.h @@ -29,20 +29,20 @@ class JingleThread; namespace protocol { // ContentDescription used for chromoting sessions. It simply wraps -// CandidateChromotocolConfig. CandidateChromotocolConfig doesn't inherit +// CandidateSessionConfig. CandidateSessionConfig doesn't inherit // from ContentDescription to avoid dependency on libjingle in // Chromotocol Session interface. class ContentDescription : public cricket::ContentDescription { public: - explicit ContentDescription(const CandidateChromotocolConfig* config); + explicit ContentDescription(const CandidateSessionConfig* config); ~ContentDescription(); - const CandidateChromotocolConfig* config() const { + const CandidateSessionConfig* config() const { return candidate_config_.get(); } private: - scoped_ptr candidate_config_; + scoped_ptr candidate_config_; }; // This class implements SessionClient for Chromoting sessions. It acts as a @@ -64,7 +64,7 @@ class JingleSessionManager // ChromotocolServer interface. virtual scoped_refptr Connect( const std::string& jid, - CandidateChromotocolConfig* chromotocol_config, + CandidateSessionConfig* candidate_config, protocol::Session::StateChangeCallback* state_change_callback); virtual void Close(Task* closed_task); @@ -93,7 +93,7 @@ class JingleSessionManager // Creates outgoing session description for an incoming session. cricket::SessionDescription* CreateSessionDescription( - const CandidateChromotocolConfig* config); + const CandidateSessionConfig* candidate_config); // cricket::SessionClient interface. virtual void OnSessionCreate(cricket::Session* cricket_session, diff --git a/remoting/protocol/jingle_session_unittest.cc b/remoting/protocol/jingle_session_unittest.cc index eb02831..20463ed 100644 --- a/remoting/protocol/jingle_session_unittest.cc +++ b/remoting/protocol/jingle_session_unittest.cc @@ -35,7 +35,6 @@ class JingleSessionTest; DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::protocol::JingleSessionTest); namespace remoting { - namespace protocol { namespace { @@ -69,7 +68,7 @@ class JingleSessionTest : public testing::Test { NewCallback(&host_connection_callback_, &MockSessionCallback::OnStateChange)); - session->set_config(ChromotocolConfig::CreateDefault()); + session->set_config(SessionConfig::CreateDefault()); } protected: @@ -167,7 +166,7 @@ class JingleSessionTest : public testing::Test { client_session_ = client_server_->Connect( SessionManagerPair::kHostJid, - CandidateChromotocolConfig::CreateDefault(), + CandidateSessionConfig::CreateDefault(), NewCallback(&client_connection_callback_, &MockSessionCallback::OnStateChange)); @@ -538,7 +537,7 @@ TEST_F(JingleSessionTest, RejectConnection) { client_session_ = client_server_->Connect( SessionManagerPair::kHostJid, - CandidateChromotocolConfig::CreateDefault(), + CandidateSessionConfig::CreateDefault(), NewCallback(&client_connection_callback_, &MockSessionCallback::OnStateChange)); @@ -615,5 +614,4 @@ TEST_F(JingleSessionTest, TestVideoRtpChannel) { } } // namespace protocol - } // namespace remoting diff --git a/remoting/protocol/protocol_test_client.cc b/remoting/protocol/protocol_test_client.cc index 3ea145a..aa40195 100644 --- a/remoting/protocol/protocol_test_client.cc +++ b/remoting/protocol/protocol_test_client.cc @@ -29,7 +29,6 @@ extern "C" { using remoting::kChromotingTokenServiceName; namespace remoting { - namespace protocol { namespace { @@ -286,7 +285,7 @@ void ProtocolTestClient::OnStateChange( ProtocolTestConnection* connection = new ProtocolTestConnection(this, client_->message_loop()); connection->Init(session_manager_->Connect( - host_jid_, CandidateChromotocolConfig::CreateDefault(), + host_jid_, CandidateSessionConfig::CreateDefault(), NewCallback(connection, &ProtocolTestConnection::OnStateChange))); connections_.push_back(make_scoped_refptr(connection)); @@ -301,7 +300,7 @@ void ProtocolTestClient::OnNewSession( SessionManager::IncomingSessionResponse* response) { std::cerr << "Accepting connection from " << session->jid() << std::endl; - session->set_config(ChromotocolConfig::CreateDefault()); + session->set_config(SessionConfig::CreateDefault()); *response = SessionManager::ACCEPT; ProtocolTestConnection* test_connection = @@ -331,7 +330,6 @@ void ProtocolTestClient::DestroyConnection( } } // namespace protocol - } // namespace remoting using remoting::protocol::ProtocolTestClient; diff --git a/remoting/protocol/session.h b/remoting/protocol/session.h index 0b63d17..fd100e0 100644 --- a/remoting/protocol/session.h +++ b/remoting/protocol/session.h @@ -8,7 +8,7 @@ #include #include "base/callback.h" -#include "remoting/protocol/chromotocol_config.h" +#include "remoting/protocol/session_config.h" class MessageLoop; class Task; @@ -18,7 +18,6 @@ class Socket; } // namespace net namespace remoting { - namespace protocol { // Generic interface for Chromotocol connection used by both client and host. @@ -64,17 +63,17 @@ class Session : public base::RefCountedThreadSafe { // Configuration of the protocol that was sent or received in the // session-initiate jingle message. Returned pointer is valid until // connection is closed. - virtual const CandidateChromotocolConfig* candidate_config() = 0; + virtual const CandidateSessionConfig* candidate_config() = 0; // Protocol configuration. Can be called only after session has been accepted. // Returned pointer is valid until connection is closed. - virtual const ChromotocolConfig* config() = 0; + virtual const SessionConfig* config() = 0; // Set protocol configuration for an incoming session. Must be called // on the host before the connection is accepted, from // ChromotocolServer::IncomingConnectionCallback. Ownership of |config| is // given to the connection. - virtual void set_config(const ChromotocolConfig* config) = 0; + virtual void set_config(const SessionConfig* config) = 0; // Closes connection. Callbacks are guaranteed not to be called after // |closed_task| is executed. @@ -91,7 +90,6 @@ class Session : public base::RefCountedThreadSafe { }; } // namespace protocol - } // namespace remoting #endif // REMOTING_PROTOCOL_SESSION_H_ diff --git a/remoting/protocol/session_config.cc b/remoting/protocol/session_config.cc new file mode 100644 index 0000000..608510b --- /dev/null +++ b/remoting/protocol/session_config.cc @@ -0,0 +1,245 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "remoting/protocol/session_config.h" + +#include + +namespace remoting { +namespace protocol { + +const int kDefaultStreamVersion = 1; + +namespace { +const int kDefaultWidth = 800; +const int kDefaultHeight = 600; +} // namespace + +ChannelConfig::ChannelConfig() { + Reset(); +} + +ChannelConfig::ChannelConfig(TransportType transport, int version, Codec codec) + : transport(transport), + version(version), + codec(codec) { +} + +bool ChannelConfig::operator==(const ChannelConfig& b) const { + return transport == b.transport && version == b.version && codec == b.codec; +} + +void ChannelConfig::Reset() { + transport = TRANSPORT_STREAM; + version = kDefaultStreamVersion; + codec = CODEC_UNDEFINED; +} + +ScreenResolution::ScreenResolution() + : width(kDefaultWidth), + height(kDefaultHeight) { +} + +ScreenResolution::ScreenResolution(int width, int height) + : width(width), + height(height) { +} + +bool ScreenResolution::IsValid() const { + return width > 0 && height > 0; +} + +SessionConfig::SessionConfig() { } + +SessionConfig::SessionConfig(const SessionConfig& config) + : control_config_(config.control_config_), + event_config_(config.event_config_), + video_config_(config.video_config_), + initial_resolution_(config.initial_resolution_) { +} + +SessionConfig::~SessionConfig() { } + +void SessionConfig::SetControlConfig(const ChannelConfig& control_config) { + control_config_ = control_config; +} +void SessionConfig::SetEventConfig(const ChannelConfig& event_config) { + event_config_ = event_config; +} +void SessionConfig::SetVideoConfig(const ChannelConfig& video_config) { + video_config_ = video_config; +} +void SessionConfig::SetInitialResolution(const ScreenResolution& resolution) { + initial_resolution_ = resolution; +} + +SessionConfig* SessionConfig::Clone() const { + return new SessionConfig(*this); +} + +// static +SessionConfig* SessionConfig::CreateDefault() { + SessionConfig* result = new SessionConfig(); + result->SetControlConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, + kDefaultStreamVersion, + ChannelConfig::CODEC_UNDEFINED)); + result->SetEventConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, + kDefaultStreamVersion, + ChannelConfig::CODEC_UNDEFINED)); + result->SetVideoConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, + kDefaultStreamVersion, + ChannelConfig::CODEC_ZIP)); + return result; +} + +CandidateSessionConfig::CandidateSessionConfig() { } + +CandidateSessionConfig::CandidateSessionConfig( + const CandidateSessionConfig& config) + : control_configs_(config.control_configs_), + event_configs_(config.event_configs_), + video_configs_(config.video_configs_), + initial_resolution_(config.initial_resolution_) { +} + +CandidateSessionConfig::~CandidateSessionConfig() { } + +void CandidateSessionConfig::AddControlConfig( + const ChannelConfig& control_config) { + control_configs_.push_back(control_config); +} + +void CandidateSessionConfig::AddEventConfig( + const ChannelConfig& event_config) { + event_configs_.push_back(event_config); +} + +void CandidateSessionConfig::AddVideoConfig( + const ChannelConfig& video_config) { + video_configs_.push_back(video_config); +} + +void CandidateSessionConfig::SetInitialResolution( + const ScreenResolution& resolution) { + initial_resolution_ = resolution; +} + +SessionConfig* CandidateSessionConfig::Select( + const CandidateSessionConfig* client_config, + bool force_host_resolution) { + ChannelConfig control_config; + ChannelConfig event_config; + ChannelConfig video_config; + if (!SelectCommonChannelConfig( + control_configs_, client_config->control_configs_, &control_config) || + !SelectCommonChannelConfig( + event_configs_, client_config->event_configs_, &event_config) || + !SelectCommonChannelConfig( + video_configs_, client_config->video_configs_, &video_config)) { + return NULL; + } + + SessionConfig* result = SessionConfig::CreateDefault(); + result->SetControlConfig(control_config); + result->SetEventConfig(event_config); + result->SetVideoConfig(video_config); + + if (force_host_resolution) { + result->SetInitialResolution(initial_resolution()); + } else { + result->SetInitialResolution(client_config->initial_resolution()); + } + + return result; +} + +bool CandidateSessionConfig::IsSupported( + const SessionConfig* config) const { + return + IsChannelConfigSupported(control_configs_, config->control_config()) && + IsChannelConfigSupported(event_configs_, config->event_config()) && + IsChannelConfigSupported(video_configs_, config->video_config()) && + config->initial_resolution().IsValid(); +} + +SessionConfig* CandidateSessionConfig::GetFinalConfig() const { + if (control_configs_.size() != 1 || + event_configs_.size() != 1 || + video_configs_.size() != 1) { + return NULL; + } + + SessionConfig* result = SessionConfig::CreateDefault(); + result->SetControlConfig(control_configs_.front()); + result->SetEventConfig(event_configs_.front()); + result->SetVideoConfig(video_configs_.front()); + result->SetInitialResolution(initial_resolution_); + return result; +} + +// static +bool CandidateSessionConfig::SelectCommonChannelConfig( + const std::vector& host_configs, + const std::vector& client_configs, + ChannelConfig* config) { + // Usually each of these vectors will contain just several elements, + // so iterating over all of them is not a problem. + std::vector::const_iterator it; + for (it = client_configs.begin(); it != client_configs.end(); ++it) { + if (IsChannelConfigSupported(host_configs, *it)) { + *config = *it; + return true; + } + } + return false; +} + +// static +bool CandidateSessionConfig::IsChannelConfigSupported( + const std::vector& vector, + const ChannelConfig& value) { + return std::find(vector.begin(), vector.end(), value) != vector.end(); +} + +CandidateSessionConfig* CandidateSessionConfig::Clone() const { + return new CandidateSessionConfig(*this); +} + +// static +CandidateSessionConfig* CandidateSessionConfig::CreateEmpty() { + return new CandidateSessionConfig(); +} + +// static +CandidateSessionConfig* CandidateSessionConfig::CreateFrom( + const SessionConfig* config) { + CandidateSessionConfig* result = CreateEmpty(); + result->AddControlConfig(config->control_config()); + result->AddEventConfig(config->event_config()); + result->AddVideoConfig(config->video_config()); + result->SetInitialResolution(config->initial_resolution()); + return result; +} + +// static +CandidateSessionConfig* CandidateSessionConfig::CreateDefault() { + CandidateSessionConfig* result = CreateEmpty(); + result->AddControlConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, + kDefaultStreamVersion, + ChannelConfig::CODEC_UNDEFINED)); + result->AddEventConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, + kDefaultStreamVersion, + ChannelConfig::CODEC_UNDEFINED)); + + result->AddVideoConfig(ChannelConfig(ChannelConfig::TRANSPORT_STREAM, + kDefaultStreamVersion, + ChannelConfig::CODEC_ZIP)); + result->AddVideoConfig(ChannelConfig(ChannelConfig::TRANSPORT_SRTP, + kDefaultStreamVersion, + ChannelConfig::CODEC_VP8)); + return result; +} + +} // namespace protocol +} // namespace remoting diff --git a/remoting/protocol/session_config.h b/remoting/protocol/session_config.h new file mode 100644 index 0000000..830ab79 --- /dev/null +++ b/remoting/protocol/session_config.h @@ -0,0 +1,165 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef REMOTING_PROTOCOL_SESSION_CONFIG_H_ +#define REMOTING_PROTOCOL_SESSION_CONFIG_H_ + +#include +#include + +#include "base/basictypes.h" + +namespace remoting { +namespace protocol { + +extern const int kDefaultStreamVersion; + +// Struct for configuration parameters of a single channel. +// Some channels (like video) may have multiple underlying sockets that need +// to be configured simultaneously. +struct ChannelConfig { + enum TransportType { + TRANSPORT_STREAM, + TRANSPORT_DATAGRAM, + TRANSPORT_SRTP, + TRANSPORT_RTP_DTLS, + }; + + enum Codec { + CODEC_UNDEFINED, // Used for event and control channels. + CODEC_VERBATIM, + CODEC_ZIP, + CODEC_VP8, + }; + + ChannelConfig(); + ChannelConfig(TransportType transport, int version, Codec codec); + + // operator== is overloaded so that std::find() works with + // std::vector. + bool operator==(const ChannelConfig& b) const; + + void Reset(); + + TransportType transport; + int version; + Codec codec; +}; + +struct ScreenResolution { + ScreenResolution(); + ScreenResolution(int width, int height); + + bool IsValid() const; + + int width; + int height; +}; + +// SessionConfig is used by the chromoting Session to store negotiated +// chromotocol configuration. +class SessionConfig { + public: + ~SessionConfig(); + + const ChannelConfig& control_config() const { return control_config_; } + const ChannelConfig& event_config() const { return event_config_; } + const ChannelConfig& video_config() const { return video_config_; } + const ScreenResolution& initial_resolution() const { + return initial_resolution_; + } + + void SetControlConfig(const ChannelConfig& control_config); + void SetEventConfig(const ChannelConfig& event_config); + void SetVideoConfig(const ChannelConfig& video_config); + void SetInitialResolution(const ScreenResolution& initial_resolution); + + SessionConfig* Clone() const; + + static SessionConfig* CreateDefault(); + + private: + SessionConfig(); + explicit SessionConfig(const SessionConfig& config); + SessionConfig& operator=(const SessionConfig& b); + + ChannelConfig control_config_; + ChannelConfig event_config_; + ChannelConfig video_config_; + ScreenResolution initial_resolution_; +}; + +// Defines session description that is sent from client to the host in the +// session-initiate message. It is different from the regular Config +// because it allows one to specify multiple configurations for each channel. +class CandidateSessionConfig { + public: + ~CandidateSessionConfig(); + + const std::vector& control_configs() const { + return control_configs_; + } + + const std::vector& event_configs() const { + return event_configs_; + } + + const std::vector& video_configs() const { + return video_configs_; + } + + const ScreenResolution& initial_resolution() const { + return initial_resolution_; + } + + void AddControlConfig(const ChannelConfig& control_config); + void AddEventConfig(const ChannelConfig& event_config); + void AddVideoConfig(const ChannelConfig& video_config); + void SetInitialResolution(const ScreenResolution& initial_resolution); + + // Selects session configuration that is supported by both participants. + // NULL is returned if such configuration doesn't exist. When selecting + // channel configuration priority is given to the configs listed first + // in |client_config|. + SessionConfig* Select(const CandidateSessionConfig* client_config, + bool force_host_resolution); + + // Returns true if |config| is supported. + bool IsSupported(const SessionConfig* config) const; + + // Extracts final protocol configuration. Must be used for the description + // received in the session-accept stanza. If the selection is ambiguous + // (e.g. there is more than one configuration for one of the channel) + // or undefined (e.g. no configurations for a channel) then NULL is returned. + SessionConfig* GetFinalConfig() const; + + CandidateSessionConfig* Clone() const; + + static CandidateSessionConfig* CreateEmpty(); + static CandidateSessionConfig* CreateFrom(const SessionConfig* config); + static CandidateSessionConfig* CreateDefault(); + + private: + CandidateSessionConfig(); + explicit CandidateSessionConfig(const CandidateSessionConfig& config); + CandidateSessionConfig& operator=(const CandidateSessionConfig& b); + + static bool SelectCommonChannelConfig( + const std::vector& host_configs_, + const std::vector& client_configs_, + ChannelConfig* config); + static bool IsChannelConfigSupported(const std::vector& vector, + const ChannelConfig& value); + + std::vector control_configs_; + std::vector event_configs_; + std::vector video_configs_; + + ScreenResolution initial_resolution_; +}; + +} // namespace protocol +} // namespace remoting + +#endif // REMOTING_PROTOCOL_SESSION_CONFIG_H_ diff --git a/remoting/protocol/session_manager.h b/remoting/protocol/session_manager.h index ab8cdcf..f953e43 100644 --- a/remoting/protocol/session_manager.h +++ b/remoting/protocol/session_manager.h @@ -34,8 +34,8 @@ // configuration. The configuration specified in the session-accept is used // for the session. // -// The CandidateChromotocolConfig class represents list of configurations -// supported by an endpoint. The |chromotocol_config| argument in the Connect() +// The CandidateSessionConfig class represents list of configurations +// supported by an endpoint. The |candidate_config| argument in the Connect() // specifies configuration supported on the client side. When the host receives // session-initiate stanza, the IncomingSessionCallback is called. The // configuration sent in the session-intiate staza is available via @@ -55,7 +55,6 @@ class Task; namespace remoting { - namespace protocol { // Generic interface for Chromoting session manager. @@ -78,10 +77,10 @@ class SessionManager : public base::RefCountedThreadSafe { IncomingSessionCallback; // Initializes session to the host |jid|. Ownership of the - // |chromotocol_config| is passed to the new session. + // |config| is passed to the new session. virtual scoped_refptr Connect( const std::string& jid, - CandidateChromotocolConfig* chromotocol_config, + CandidateSessionConfig* config, Session::StateChangeCallback* state_change_callback) = 0; // Close session manager and all current sessions. |close_task| is executed @@ -100,7 +99,6 @@ class SessionManager : public base::RefCountedThreadSafe { }; } // namespace protocol - } // namespace remoting #endif // REMOTING_PROTOCOL_SESSION_MANAGER_H_ diff --git a/remoting/protocol/video_reader.cc b/remoting/protocol/video_reader.cc index b026ac9..832eb04 100644 --- a/remoting/protocol/video_reader.cc +++ b/remoting/protocol/video_reader.cc @@ -4,7 +4,7 @@ #include "remoting/protocol/video_reader.h" -#include "remoting/protocol/chromotocol_config.h" +#include "remoting/protocol/session_config.h" #include "remoting/protocol/protobuf_video_reader.h" #include "remoting/protocol/rtp_video_reader.h" @@ -14,7 +14,7 @@ namespace protocol { VideoReader::~VideoReader() { } // static -VideoReader* VideoReader::Create(const ChromotocolConfig* config) { +VideoReader* VideoReader::Create(const SessionConfig* config) { const ChannelConfig& video_config = config->video_config(); if (video_config.transport == ChannelConfig::TRANSPORT_SRTP) { return new RtpVideoReader(); diff --git a/remoting/protocol/video_reader.h b/remoting/protocol/video_reader.h index 9ead3c9f..ab94913 100644 --- a/remoting/protocol/video_reader.h +++ b/remoting/protocol/video_reader.h @@ -14,24 +14,22 @@ namespace remoting { -namespace protocol { -class Session; -} // namespace protocol - -class ChromotocolConfig; class ChromotocolConnection; namespace protocol { +class Session; +class SessionConfig; + class VideoReader { public: - static VideoReader* Create(const ChromotocolConfig* config); + static VideoReader* Create(const SessionConfig* config); virtual ~VideoReader(); // Initializies the reader. Doesn't take ownership of either |connection| // or |video_stub|. - virtual void Init(protocol::Session* session, + virtual void Init(Session* session, VideoStub* video_stub) = 0; // Closes the reader. The stub should not be called after Close(). diff --git a/remoting/protocol/video_writer.cc b/remoting/protocol/video_writer.cc index 6fc7a88..2336fe3 100644 --- a/remoting/protocol/video_writer.cc +++ b/remoting/protocol/video_writer.cc @@ -4,7 +4,7 @@ #include "remoting/protocol/video_writer.h" -#include "remoting/protocol/chromotocol_config.h" +#include "remoting/protocol/session_config.h" #include "remoting/protocol/protobuf_video_writer.h" #include "remoting/protocol/rtp_video_writer.h" @@ -14,7 +14,7 @@ namespace protocol { VideoWriter::~VideoWriter() { } // static -VideoWriter* VideoWriter::Create(const ChromotocolConfig* config) { +VideoWriter* VideoWriter::Create(const SessionConfig* config) { const ChannelConfig& video_config = config->video_config(); if (video_config.transport == ChannelConfig::TRANSPORT_SRTP) { return new RtpVideoWriter(); diff --git a/remoting/protocol/video_writer.h b/remoting/protocol/video_writer.h index 0b39bcb..eae6b6e 100644 --- a/remoting/protocol/video_writer.h +++ b/remoting/protocol/video_writer.h @@ -15,24 +15,22 @@ namespace remoting { -namespace protocol { -class Session; -} // namespace protocol - -class ChromotocolConfig; class ChromotocolConnection; namespace protocol { +class Session; +class SessionConfig; + // TODO(sergeyu): VideoWriter should implement VideoStub interface. class VideoWriter { public: virtual ~VideoWriter(); - static VideoWriter* Create(const ChromotocolConfig* config); + static VideoWriter* Create(const SessionConfig* config); // Initializes the writer. - virtual void Init(protocol::Session* session) = 0; + virtual void Init(Session* session) = 0; // Sends the |packet|. virtual void SendPacket(const VideoPacket& packet) = 0; -- cgit v1.1