Commit 524fbf35 authored by wez@chromium.org's avatar wez@chromium.org

Switch CandidateSession to use lists rather than vectors.

This makes it possible to add candidate configurations at either the
back (least-preferred) or front (most-preferred) of each channel's
candidate list.

This CL also disables VP9, by default, in candidate session
configurations, replaces DisableVideoCodec with 
EnableVideoCodec, and makes the Enable/Disable<foo>Codec
helpers members of CandidateSessionConfig..

Review URL: https://codereview.chromium.org/292093002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272324 0039d316-1c4b-4281-b951-d872f2087c98
parent c0198f64
...@@ -92,15 +92,13 @@ ChromotingHost::ChromotingHost( ...@@ -92,15 +92,13 @@ ChromotingHost::ChromotingHost(
jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop();
// Disable VP9 unless it is explicitly enabled via the command-line. // Enable VP9 if specified on the command-line.
if (!CommandLine::ForCurrentProcess()->HasSwitch(kEnableVp9SwitchName)) { if (CommandLine::ForCurrentProcess()->HasSwitch(kEnableVp9SwitchName)) {
protocol::CandidateSessionConfig::DisableVideoCodec( protocol_config_->EnableVideoCodec(protocol::ChannelConfig::CODEC_VP9);
protocol_config_.get(), protocol::ChannelConfig::CODEC_VP9);
} }
if (!desktop_environment_factory_->SupportsAudioCapture()) { if (!desktop_environment_factory_->SupportsAudioCapture()) {
protocol::CandidateSessionConfig::DisableAudioChannel( protocol_config_->DisableAudioChannel();
protocol_config_.get());
} }
} }
......
...@@ -212,7 +212,7 @@ void It2MeHost::FinishConnect() { ...@@ -212,7 +212,7 @@ void It2MeHost::FinishConnect() {
// TODO(sergeyu): Add UI to enable it. // TODO(sergeyu): Add UI to enable it.
scoped_ptr<protocol::CandidateSessionConfig> protocol_config = scoped_ptr<protocol::CandidateSessionConfig> protocol_config =
protocol::CandidateSessionConfig::CreateDefault(); protocol::CandidateSessionConfig::CreateDefault();
protocol::CandidateSessionConfig::DisableAudioChannel(protocol_config.get()); protocol_config->DisableAudioChannel();
host_->set_protocol_config(protocol_config.Pass()); host_->set_protocol_config(protocol_config.Pass());
......
...@@ -142,8 +142,9 @@ void ConnectionToHost::OnSessionManagerReady() { ...@@ -142,8 +142,9 @@ void ConnectionToHost::OnSessionManagerReady() {
// After SessionManager is initialized we can try to connect to the host. // After SessionManager is initialized we can try to connect to the host.
scoped_ptr<CandidateSessionConfig> candidate_config = scoped_ptr<CandidateSessionConfig> candidate_config =
CandidateSessionConfig::CreateDefault(); CandidateSessionConfig::CreateDefault();
if (!audio_stub_) if (!audio_stub_) {
CandidateSessionConfig::DisableAudioChannel(candidate_config.get()); candidate_config->DisableAudioChannel();
}
session_ = session_manager_->Connect( session_ = session_manager_->Connect(
host_jid_, authenticator_.Pass(), candidate_config.Pass()); host_jid_, authenticator_.Pass(), candidate_config.Pass());
......
...@@ -145,7 +145,7 @@ XmlElement* ContentDescription::ToXml() const { ...@@ -145,7 +145,7 @@ XmlElement* ContentDescription::ToXml() const {
XmlElement* root = new XmlElement( XmlElement* root = new XmlElement(
QName(kChromotingXmlNamespace, kDescriptionTag), true); QName(kChromotingXmlNamespace, kDescriptionTag), true);
std::vector<ChannelConfig>::const_iterator it; std::list<ChannelConfig>::const_iterator it;
for (it = config()->control_configs().begin(); for (it = config()->control_configs().begin();
it != config()->control_configs().end(); ++it) { it != config()->control_configs().end(); ++it) {
...@@ -191,7 +191,7 @@ bool ContentDescription::ParseChannelConfigs( ...@@ -191,7 +191,7 @@ bool ContentDescription::ParseChannelConfigs(
const char tag_name[], const char tag_name[],
bool codec_required, bool codec_required,
bool optional, bool optional,
std::vector<ChannelConfig>* const configs) { std::list<ChannelConfig>* const configs) {
QName tag(kChromotingXmlNamespace, tag_name); QName tag(kChromotingXmlNamespace, tag_name);
const XmlElement* child = element->FirstNamed(tag); const XmlElement* child = element->FirstNamed(tag);
......
...@@ -55,7 +55,7 @@ class ContentDescription : public cricket::ContentDescription { ...@@ -55,7 +55,7 @@ class ContentDescription : public cricket::ContentDescription {
const char tag_name[], const char tag_name[],
bool codec_required, bool codec_required,
bool optional, bool optional,
std::vector<ChannelConfig>* const configs); std::list<ChannelConfig>* const configs);
}; };
} // namespace protocol } // namespace protocol
......
...@@ -51,7 +51,7 @@ TEST(ContentDescriptionTest, ParseUnknown) { ...@@ -51,7 +51,7 @@ TEST(ContentDescriptionTest, ParseUnknown) {
ContentDescription::ParseXml(xml.get())); ContentDescription::ParseXml(xml.get()));
ASSERT_TRUE(parsed.get()); ASSERT_TRUE(parsed.get());
EXPECT_EQ(1U, parsed->config()->event_configs().size()); EXPECT_EQ(1U, parsed->config()->event_configs().size());
EXPECT_TRUE(parsed->config()->event_configs()[0] == EXPECT_TRUE(parsed->config()->event_configs().front() ==
ChannelConfig(ChannelConfig::TRANSPORT_STREAM, ChannelConfig(ChannelConfig::TRANSPORT_STREAM,
kDefaultStreamVersion, kDefaultStreamVersion,
ChannelConfig::CODEC_UNDEFINED)); ChannelConfig::CODEC_UNDEFINED));
...@@ -74,7 +74,7 @@ TEST(ContentDescriptionTest, NoneTransport) { ...@@ -74,7 +74,7 @@ TEST(ContentDescriptionTest, NoneTransport) {
ContentDescription::ParseXml(xml.get())); ContentDescription::ParseXml(xml.get()));
ASSERT_TRUE(parsed.get()); ASSERT_TRUE(parsed.get());
EXPECT_EQ(1U, parsed->config()->audio_configs().size()); EXPECT_EQ(1U, parsed->config()->audio_configs().size());
EXPECT_TRUE(parsed->config()->audio_configs()[0] == ChannelConfig()); EXPECT_TRUE(parsed->config()->audio_configs().front() == ChannelConfig());
} }
// Verify that we can parse configs with none transport with version and // Verify that we can parse configs with none transport with version and
...@@ -94,7 +94,7 @@ TEST(ContentDescriptionTest, NoneTransportWithCodec) { ...@@ -94,7 +94,7 @@ TEST(ContentDescriptionTest, NoneTransportWithCodec) {
ContentDescription::ParseXml(xml.get())); ContentDescription::ParseXml(xml.get()));
ASSERT_TRUE(parsed.get()); ASSERT_TRUE(parsed.get());
EXPECT_EQ(1U, parsed->config()->audio_configs().size()); EXPECT_EQ(1U, parsed->config()->audio_configs().size());
EXPECT_TRUE(parsed->config()->audio_configs()[0] == ChannelConfig()); EXPECT_TRUE(parsed->config()->audio_configs().front() == ChannelConfig());
} }
} // namespace protocol } // namespace protocol
......
...@@ -129,12 +129,12 @@ bool CandidateSessionConfig::GetFinalConfig(SessionConfig* result) const { ...@@ -129,12 +129,12 @@ bool CandidateSessionConfig::GetFinalConfig(SessionConfig* result) const {
// static // static
bool CandidateSessionConfig::SelectCommonChannelConfig( bool CandidateSessionConfig::SelectCommonChannelConfig(
const std::vector<ChannelConfig>& host_configs, const std::list<ChannelConfig>& host_configs,
const std::vector<ChannelConfig>& client_configs, const std::list<ChannelConfig>& client_configs,
ChannelConfig* config) { ChannelConfig* config) {
// Usually each of these vectors will contain just several elements, // Usually each of these vectors will contain just several elements,
// so iterating over all of them is not a problem. // so iterating over all of them is not a problem.
std::vector<ChannelConfig>::const_iterator it; std::list<ChannelConfig>::const_iterator it;
for (it = client_configs.begin(); it != client_configs.end(); ++it) { for (it = client_configs.begin(); it != client_configs.end(); ++it) {
if (IsChannelConfigSupported(host_configs, *it)) { if (IsChannelConfigSupported(host_configs, *it)) {
*config = *it; *config = *it;
...@@ -146,7 +146,7 @@ bool CandidateSessionConfig::SelectCommonChannelConfig( ...@@ -146,7 +146,7 @@ bool CandidateSessionConfig::SelectCommonChannelConfig(
// static // static
bool CandidateSessionConfig::IsChannelConfigSupported( bool CandidateSessionConfig::IsChannelConfigSupported(
const std::vector<ChannelConfig>& vector, const std::list<ChannelConfig>& vector,
const ChannelConfig& value) { const ChannelConfig& value) {
return std::find(vector.begin(), vector.end(), value) != vector.end(); return std::find(vector.begin(), vector.end(), value) != vector.end();
} }
...@@ -192,10 +192,6 @@ scoped_ptr<CandidateSessionConfig> CandidateSessionConfig::CreateDefault() { ...@@ -192,10 +192,6 @@ scoped_ptr<CandidateSessionConfig> CandidateSessionConfig::CreateDefault() {
ChannelConfig::CODEC_UNDEFINED)); ChannelConfig::CODEC_UNDEFINED));
// Video channel. // Video channel.
result->mutable_video_configs()->push_back(
ChannelConfig(ChannelConfig::TRANSPORT_STREAM,
kDefaultStreamVersion,
ChannelConfig::CODEC_VP9));
result->mutable_video_configs()->push_back( result->mutable_video_configs()->push_back(
ChannelConfig(ChannelConfig::TRANSPORT_STREAM, ChannelConfig(ChannelConfig::TRANSPORT_STREAM,
kDefaultStreamVersion, kDefaultStreamVersion,
...@@ -211,26 +207,16 @@ scoped_ptr<CandidateSessionConfig> CandidateSessionConfig::CreateDefault() { ...@@ -211,26 +207,16 @@ scoped_ptr<CandidateSessionConfig> CandidateSessionConfig::CreateDefault() {
return result.Pass(); return result.Pass();
} }
// static void CandidateSessionConfig::DisableAudioChannel() {
void CandidateSessionConfig::DisableAudioChannel( mutable_audio_configs()->clear();
CandidateSessionConfig* config) { mutable_audio_configs()->push_back(ChannelConfig());
config->mutable_audio_configs()->clear();
config->mutable_audio_configs()->push_back(ChannelConfig());
} }
// static void CandidateSessionConfig::EnableVideoCodec(ChannelConfig::Codec codec) {
void CandidateSessionConfig::DisableVideoCodec( mutable_video_configs()->push_front(
CandidateSessionConfig* config, ChannelConfig(ChannelConfig::TRANSPORT_STREAM,
ChannelConfig::Codec codec) { kDefaultStreamVersion,
std ::vector<ChannelConfig>::iterator i; codec));
for (i = config->mutable_video_configs()->begin();
i != config->mutable_video_configs()->end();) {
if (i->codec == codec) {
i = config->mutable_video_configs()->erase(i);
} else {
++i;
}
}
} }
} // namespace protocol } // namespace protocol
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
#ifndef REMOTING_PROTOCOL_SESSION_CONFIG_H_ #ifndef REMOTING_PROTOCOL_SESSION_CONFIG_H_
#define REMOTING_PROTOCOL_SESSION_CONFIG_H_ #define REMOTING_PROTOCOL_SESSION_CONFIG_H_
#include <list>
#include <string> #include <string>
#include <vector>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
...@@ -48,7 +48,7 @@ struct ChannelConfig { ...@@ -48,7 +48,7 @@ struct ChannelConfig {
ChannelConfig(TransportType transport, int version, Codec codec); ChannelConfig(TransportType transport, int version, Codec codec);
// operator== is overloaded so that std::find() works with // operator== is overloaded so that std::find() works with
// std::vector<ChannelConfig>. // std::list<ChannelConfig>.
bool operator==(const ChannelConfig& b) const; bool operator==(const ChannelConfig& b) const;
TransportType transport; TransportType transport;
...@@ -101,37 +101,42 @@ class SessionConfig { ...@@ -101,37 +101,42 @@ class SessionConfig {
// because it allows one to specify multiple configurations for each channel. // because it allows one to specify multiple configurations for each channel.
class CandidateSessionConfig { class CandidateSessionConfig {
public: public:
static scoped_ptr<CandidateSessionConfig> CreateEmpty();
static scoped_ptr<CandidateSessionConfig> CreateFrom(
const SessionConfig& config);
static scoped_ptr<CandidateSessionConfig> CreateDefault();
~CandidateSessionConfig(); ~CandidateSessionConfig();
const std::vector<ChannelConfig>& control_configs() const { const std::list<ChannelConfig>& control_configs() const {
return control_configs_; return control_configs_;
} }
std::vector<ChannelConfig>* mutable_control_configs() { std::list<ChannelConfig>* mutable_control_configs() {
return &control_configs_; return &control_configs_;
} }
const std::vector<ChannelConfig>& event_configs() const { const std::list<ChannelConfig>& event_configs() const {
return event_configs_; return event_configs_;
} }
std::vector<ChannelConfig>* mutable_event_configs() { std::list<ChannelConfig>* mutable_event_configs() {
return &event_configs_; return &event_configs_;
} }
const std::vector<ChannelConfig>& video_configs() const { const std::list<ChannelConfig>& video_configs() const {
return video_configs_; return video_configs_;
} }
std::vector<ChannelConfig>* mutable_video_configs() { std::list<ChannelConfig>* mutable_video_configs() {
return &video_configs_; return &video_configs_;
} }
const std::vector<ChannelConfig>& audio_configs() const { const std::list<ChannelConfig>& audio_configs() const {
return audio_configs_; return audio_configs_;
} }
std::vector<ChannelConfig>* mutable_audio_configs() { std::list<ChannelConfig>* mutable_audio_configs() {
return &audio_configs_; return &audio_configs_;
} }
...@@ -153,15 +158,9 @@ class CandidateSessionConfig { ...@@ -153,15 +158,9 @@ class CandidateSessionConfig {
scoped_ptr<CandidateSessionConfig> Clone() const; scoped_ptr<CandidateSessionConfig> Clone() const;
static scoped_ptr<CandidateSessionConfig> CreateEmpty(); // Helpers for enabling/disabling specific features.
static scoped_ptr<CandidateSessionConfig> CreateFrom( void DisableAudioChannel();
const SessionConfig& config); void EnableVideoCodec(ChannelConfig::Codec codec);
static scoped_ptr<CandidateSessionConfig> CreateDefault();
// Modifies |config| to disable specific features.
static void DisableAudioChannel(CandidateSessionConfig* config);
static void DisableVideoCodec(CandidateSessionConfig* config,
ChannelConfig::Codec codec);
private: private:
CandidateSessionConfig(); CandidateSessionConfig();
...@@ -169,16 +168,16 @@ class CandidateSessionConfig { ...@@ -169,16 +168,16 @@ class CandidateSessionConfig {
CandidateSessionConfig& operator=(const CandidateSessionConfig& b); CandidateSessionConfig& operator=(const CandidateSessionConfig& b);
static bool SelectCommonChannelConfig( static bool SelectCommonChannelConfig(
const std::vector<ChannelConfig>& host_configs_, const std::list<ChannelConfig>& host_configs_,
const std::vector<ChannelConfig>& client_configs_, const std::list<ChannelConfig>& client_configs_,
ChannelConfig* config); ChannelConfig* config);
static bool IsChannelConfigSupported(const std::vector<ChannelConfig>& vector, static bool IsChannelConfigSupported(const std::list<ChannelConfig>& list,
const ChannelConfig& value); const ChannelConfig& value);
std::vector<ChannelConfig> control_configs_; std::list<ChannelConfig> control_configs_;
std::vector<ChannelConfig> event_configs_; std::list<ChannelConfig> event_configs_;
std::vector<ChannelConfig> video_configs_; std::list<ChannelConfig> video_configs_;
std::vector<ChannelConfig> audio_configs_; std::list<ChannelConfig> audio_configs_;
}; };
} // namespace protocol } // namespace protocol
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment