summaryrefslogtreecommitdiffstats
path: root/remoting/host
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-23 22:18:12 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-23 22:18:12 +0000
commitf901a073b8b705393c01f2f99e86d266c95ba4de (patch)
treecb8516a46306b15f53f5952068b0e64e9191466e /remoting/host
parentc003320ea12585f044da47de763b637b90e70e0a (diff)
downloadchromium_src-f901a073b8b705393c01f2f99e86d266c95ba4de.zip
chromium_src-f901a073b8b705393c01f2f99e86d266c95ba4de.tar.gz
chromium_src-f901a073b8b705393c01f2f99e86d266c95ba4de.tar.bz2
Use VP8 over PseudoTCP by default.
Added option in simple_host to choose video codec. Removed ugly ifdefs from chromoting_host.cc. BUG=None TEST=Unittests Review URL: http://codereview.chromium.org/5298001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67164 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host')
-rw-r--r--remoting/host/capturer.h6
-rw-r--r--remoting/host/capturer_gdi.cc5
-rw-r--r--remoting/host/capturer_linux.cc5
-rw-r--r--remoting/host/capturer_mac.cc5
-rw-r--r--remoting/host/chromoting_host.cc75
-rw-r--r--remoting/host/chromoting_host.h28
-rw-r--r--remoting/host/event_executor.h24
-rw-r--r--remoting/host/event_executor_linux.cc5
-rw-r--r--remoting/host/event_executor_linux.h5
-rw-r--r--remoting/host/event_executor_mac.cc5
-rw-r--r--remoting/host/event_executor_mac.h6
-rw-r--r--remoting/host/event_executor_win.cc5
-rw-r--r--remoting/host/event_executor_win.h4
-rw-r--r--remoting/host/simple_host_process.cc59
14 files changed, 160 insertions, 77 deletions
diff --git a/remoting/host/capturer.h b/remoting/host/capturer.h
index 481b1f3..548b685 100644
--- a/remoting/host/capturer.h
+++ b/remoting/host/capturer.h
@@ -44,9 +44,11 @@ class Capturer {
// CaptureCompletedCallback is called when the capturer has completed.
typedef Callback1<scoped_refptr<CaptureData> >::Type CaptureCompletedCallback;
- explicit Capturer(MessageLoop* message_loop);
virtual ~Capturer();
+ // Create platform-specific cpaturer.
+ static Capturer* Create(MessageLoop* message_loop);
+
// Called when the screen configuration is changed.
virtual void ScreenConfigurationChanged() = 0;
@@ -84,6 +86,8 @@ class Capturer {
virtual void CaptureInvalidRects(CaptureCompletedCallback* callback);
protected:
+ explicit Capturer(MessageLoop* message_loop);
+
// Update the list of |invalid_rects| to prepare for capturing the
// screen data.
// Depending on the platform implementation, this routine might:
diff --git a/remoting/host/capturer_gdi.cc b/remoting/host/capturer_gdi.cc
index 7b4acc6..0465491 100644
--- a/remoting/host/capturer_gdi.cc
+++ b/remoting/host/capturer_gdi.cc
@@ -136,4 +136,9 @@ void CapturerGdi::CaptureImage() {
SRCCOPY | CAPTUREBLT);
}
+// static
+Capturer* Capturer::Create(MessageLoop* message_loop) {
+ return new CapturerGdi(message_loop);
+}
+
} // namespace remoting
diff --git a/remoting/host/capturer_linux.cc b/remoting/host/capturer_linux.cc
index 404d527..70c956d 100644
--- a/remoting/host/capturer_linux.cc
+++ b/remoting/host/capturer_linux.cc
@@ -339,4 +339,9 @@ void CapturerLinuxPimpl::SlowBlit(XImage* image, int dest_x, int dest_y,
}
}
+// static
+Capturer* Capturer::Create(MessageLoop* message_loop) {
+ return new CapturerLinux(message_loop);
+}
+
} // namespace remoting
diff --git a/remoting/host/capturer_mac.cc b/remoting/host/capturer_mac.cc
index 7b5d942..9cd0e75 100644
--- a/remoting/host/capturer_mac.cc
+++ b/remoting/host/capturer_mac.cc
@@ -165,4 +165,9 @@ void CapturerMac::DisplaysReconfiguredCallback(
}
}
+// static
+Capturer* Capturer::Create(MessageLoop* message_loop) {
+ return new CapturerMac(message_loop);
+}
+
} // namespace remoting
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc
index 67798a9..95b9a6e 100644
--- a/remoting/host/chromoting_host.cc
+++ b/remoting/host/chromoting_host.cc
@@ -8,21 +8,13 @@
#include "base/task.h"
#include "build/build_config.h"
#include "remoting/base/constants.h"
-#if defined(OS_WIN)
-#include "remoting/host/capturer_gdi.h"
-#include "remoting/host/event_executor_win.h"
-#elif defined(OS_LINUX)
-#include "remoting/host/capturer_linux.h"
-#include "remoting/host/event_executor_linux.h"
-#elif defined(OS_MACOSX)
-#include "remoting/host/capturer_mac.h"
-#include "remoting/host/event_executor_mac.h"
-#endif
#include "remoting/base/encoder.h"
#include "remoting/base/encoder_verbatim.h"
#include "remoting/base/encoder_vp8.h"
#include "remoting/base/encoder_zlib.h"
+#include "remoting/host/capturer.h"
#include "remoting/host/chromoting_host_context.h"
+#include "remoting/host/event_executor.h"
#include "remoting/host/host_config.h"
#include "remoting/host/host_stub_fake.h"
#include "remoting/host/session_manager.h"
@@ -36,28 +28,18 @@ using remoting::protocol::ConnectionToClient;
namespace remoting {
-ChromotingHost::ChromotingHost(ChromotingHostContext* context,
- MutableHostConfig* config)
- : context_(context),
- config_(config),
-#if defined(OS_WIN)
- capturer_(new remoting::CapturerGdi(
- context->main_message_loop())),
- input_stub_(new remoting::EventExecutorWin(
- context->main_message_loop(), capturer_.get())),
-#elif defined(OS_LINUX)
- capturer_(new remoting::CapturerLinux(
- context->main_message_loop())),
- input_stub_(new remoting::EventExecutorLinux(
- context->main_message_loop(), capturer_.get())),
-#elif defined(OS_MACOSX)
- capturer_(new remoting::CapturerMac(
- context->main_message_loop())),
- input_stub_(new remoting::EventExecutorMac(
- context->main_message_loop(), capturer_.get())),
-#endif
- host_stub_(new HostStubFake()),
- state_(kInitial) {
+// static
+ChromotingHost* ChromotingHost::Create(ChromotingHostContext* context,
+ MutableHostConfig* config) {
+ return Create(context, config,
+ Capturer::Create(context->main_message_loop()));
+}
+
+// static
+ChromotingHost* ChromotingHost::Create(ChromotingHostContext* context,
+ MutableHostConfig* config,
+ Capturer* capturer) {
+ return new ChromotingHost(context, config, capturer);
}
ChromotingHost::ChromotingHost(ChromotingHostContext* context,
@@ -65,20 +47,14 @@ ChromotingHost::ChromotingHost(ChromotingHostContext* context,
: context_(context),
config_(config),
capturer_(capturer),
-#if defined(OS_WIN)
- input_stub_(new remoting::EventExecutorWin(
- context->main_message_loop(), capturer)),
-#elif defined(OS_LINUX)
- input_stub_(new remoting::EventExecutorLinux(
+ input_stub_(CreateEventExecutor(
context->main_message_loop(), capturer)),
-#elif defined(OS_MACOSX)
- input_stub_(new remoting::EventExecutorMac(
- context->main_message_loop(), capturer)),
-#endif
host_stub_(new HostStubFake()),
- state_(kInitial) {
+ state_(kInitial),
+ protocol_config_(protocol::CandidateSessionConfig::CreateDefault()) {
}
+
ChromotingHost::~ChromotingHost() {
}
@@ -293,12 +269,10 @@ void ChromotingHost::OnNewClientSession(
return;
}
- scoped_ptr<protocol::CandidateSessionConfig>
- local_config(protocol::CandidateSessionConfig::CreateDefault());
- local_config->SetInitialResolution(
- protocol::ScreenResolution(capturer_->width(), capturer_->height()));
+ *protocol_config_->mutable_initial_resolution() =
+ protocol::ScreenResolution(capturer_->width(), capturer_->height());
// TODO(sergeyu): Respect resolution requested by the client if supported.
- protocol::SessionConfig* config = local_config->Select(
+ protocol::SessionConfig* config = protocol_config_->Select(
session->candidate_config(), true /* force_host_resolution */);
if (!config) {
@@ -322,6 +296,13 @@ void ChromotingHost::OnNewClientSession(
connection_->Init(session);
}
+void ChromotingHost::set_protocol_config(
+ protocol::CandidateSessionConfig* config) {
+ DCHECK(config_.get());
+ DCHECK_EQ(state_, kInitial);
+ protocol_config_.reset(config);
+}
+
void ChromotingHost::OnServerClosed() {
// Don't need to do anything here.
}
diff --git a/remoting/host/chromoting_host.h b/remoting/host/chromoting_host.h
index 2294fdd..aa8cb5f 100644
--- a/remoting/host/chromoting_host.h
+++ b/remoting/host/chromoting_host.h
@@ -26,6 +26,7 @@ class ConnectionToClient;
class HostStub;
class InputStub;
class SessionConfig;
+class CandidateSessionConfig;
} // namespace protocol
class Capturer;
@@ -63,10 +64,13 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>,
public protocol::ConnectionToClient::EventHandler,
public JingleClient::Callback {
public:
- ChromotingHost(ChromotingHostContext* context, MutableHostConfig* config);
- ChromotingHost(ChromotingHostContext* context, MutableHostConfig* config,
- Capturer* capturer);
- virtual ~ChromotingHost();
+ // Factory methods that must be used to create ChromotingHost
+ // instances. Default capturer is used if it is not specified.
+ static ChromotingHost* Create(ChromotingHostContext* context,
+ MutableHostConfig* config);
+ static ChromotingHost* Create(ChromotingHostContext* context,
+ MutableHostConfig* config,
+ Capturer* capturer);
// Asynchronously start the host process.
//
@@ -103,17 +107,22 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>,
protocol::Session* session,
protocol::SessionManager::IncomingSessionResponse* response);
+ // Sets desired configuration for the protocol. Ownership of the
+ // |config| is transferred to the object. Must be called before Start().
+ void set_protocol_config(protocol::CandidateSessionConfig* config);
+
private:
+ friend class base::RefCountedThreadSafe<ChromotingHost>;
+ ChromotingHost(ChromotingHostContext* context, MutableHostConfig* config,
+ Capturer* capturer);
+ virtual ~ChromotingHost();
+
enum State {
kInitial,
kStarted,
kStopped,
};
- // This method connects to the talk network and start listening for incoming
- // connections.
- void DoStart(Task* shutdown_task);
-
// Callback for protocol::SessionManager::Close().
void OnServerClosed();
@@ -168,6 +177,9 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>,
// Lock is to lock the access to |state_|.
Lock lock_;
+ // Configuration of the protocol.
+ scoped_ptr<protocol::CandidateSessionConfig> protocol_config_;
+
DISALLOW_COPY_AND_ASSIGN(ChromotingHost);
};
diff --git a/remoting/host/event_executor.h b/remoting/host/event_executor.h
new file mode 100644
index 0000000..13fe511
--- /dev/null
+++ b/remoting/host/event_executor.h
@@ -0,0 +1,24 @@
+// 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_HOST_EVENT_EXECUTOR_H_
+#define REMOTING_HOST_EVENT_EXECUTOR_H_
+
+class MessageLoop;
+
+namespace remoting {
+
+class Capturer;
+
+namespace protocol {
+class InputStub;
+} // namespace protocol
+
+// Creates default event executor for the current platform.
+protocol::InputStub* CreateEventExecutor(MessageLoop* message_loop,
+ Capturer* capturer);
+
+} // namespace remoting
+
+#endif // REMOTING_HOST_EVENT_EXECUTOR_H_
diff --git a/remoting/host/event_executor_linux.cc b/remoting/host/event_executor_linux.cc
index 1421277..dcc7dc0 100644
--- a/remoting/host/event_executor_linux.cc
+++ b/remoting/host/event_executor_linux.cc
@@ -437,4 +437,9 @@ void EventExecutorLinux::InjectMouseEvent(const MouseEvent* event,
delete done;
}
+protocol::InputStub* CreateEventExecutor(MessageLoop* message_loop,
+ Capturer* capturer) {
+ return new EventExecutorLinux(message_loop, capturer);
+}
+
} // namespace remoting
diff --git a/remoting/host/event_executor_linux.h b/remoting/host/event_executor_linux.h
index ef28660..af765f8 100644
--- a/remoting/host/event_executor_linux.h
+++ b/remoting/host/event_executor_linux.h
@@ -10,14 +10,11 @@
#include "base/task.h"
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
+#include "remoting/host/event_executor.h"
#include "remoting/protocol/input_stub.h"
-class MessageLoop;
-
namespace remoting {
-class Capturer;
-class ChromotingClientMessage;
class EventExecutorLinuxPimpl;
// A class to generate events on Linux.
diff --git a/remoting/host/event_executor_mac.cc b/remoting/host/event_executor_mac.cc
index 553222a..e89ad33 100644
--- a/remoting/host/event_executor_mac.cc
+++ b/remoting/host/event_executor_mac.cc
@@ -29,4 +29,9 @@ void EventExecutorMac::InjectMouseEvent(const MouseEvent* event, Task* done) {
delete done;
}
+protocol::InputStub* CreateEventExecutor(MessageLoop* message_loop,
+ Capturer* capturer) {
+ return new EventExecutorMac(message_loop, capturer);
+}
+
} // namespace remoting
diff --git a/remoting/host/event_executor_mac.h b/remoting/host/event_executor_mac.h
index 052ca48..0e38852 100644
--- a/remoting/host/event_executor_mac.h
+++ b/remoting/host/event_executor_mac.h
@@ -8,15 +8,11 @@
#include <vector>
#include "base/basictypes.h"
+#include "remoting/host/event_executor.h"
#include "remoting/protocol/input_stub.h"
-class MessageLoop;
-
namespace remoting {
-class Capturer;
-class ChromotingClientMessage;
-
// A class to generate events on Mac.
class EventExecutorMac : public protocol::InputStub {
public:
diff --git a/remoting/host/event_executor_win.cc b/remoting/host/event_executor_win.cc
index 2ee24bd..9cabeb1 100644
--- a/remoting/host/event_executor_win.cc
+++ b/remoting/host/event_executor_win.cc
@@ -174,4 +174,9 @@ void EventExecutorWin::HandleKey(const KeyEvent& event) {
SendInput(1, &input, sizeof(INPUT));
}
+protocol::InputStub* CreateEventExecutor(MessageLoop* message_loop,
+ Capturer* capturer) {
+ return new EventExecutorWin(message_loop, capturer);
+}
+
} // namespace remoting
diff --git a/remoting/host/event_executor_win.h b/remoting/host/event_executor_win.h
index b98d7be..3e2ddc6 100644
--- a/remoting/host/event_executor_win.h
+++ b/remoting/host/event_executor_win.h
@@ -10,13 +10,11 @@
#include "base/task.h"
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
+#include "remoting/host/event_executor.h"
#include "remoting/protocol/input_stub.h"
-class MessageLoop;
-
namespace remoting {
-class Capturer;
class KeyEvent;
class MouseDownEvent;
class MouseSetPositionEvent;
diff --git a/remoting/host/simple_host_process.cc b/remoting/host/simple_host_process.cc
index 269b76f..9fc057c 100644
--- a/remoting/host/simple_host_process.cc
+++ b/remoting/host/simple_host_process.cc
@@ -35,13 +35,20 @@
#include "remoting/host/json_host_config.h"
#include "remoting/proto/video.pb.h"
+using remoting::ChromotingHost;
+using remoting::protocol::CandidateSessionConfig;
+using remoting::protocol::ChannelConfig;
+using std::string;
+using std::wstring;
+
#if defined(OS_WIN)
-const std::wstring kDefaultConfigPath = L".ChromotingConfig.json";
+const wchar_t kDefaultConfigPath[] = L".ChromotingConfig.json";
const wchar_t kHomeDrive[] = L"HOMEDRIVE";
const wchar_t kHomePath[] = L"HOMEPATH";
+// TODO(sergeyu): Use environment utils from base/environment.h.
const wchar_t* GetEnvironmentVar(const wchar_t* x) { return _wgetenv(x); }
#else
-const std::string kDefaultConfigPath = ".ChromotingConfig.json";
+const char kDefaultConfigPath[] = ".ChromotingConfig.json";
static char* GetEnvironmentVar(const char* x) { return getenv(x); }
#endif
@@ -49,8 +56,15 @@ void ShutdownTask(MessageLoop* message_loop) {
message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask());
}
-const std::string kFakeSwitchName = "fake";
-const std::string kConfigSwitchName = "config";
+const char kFakeSwitchName[] = "fake";
+const char kConfigSwitchName[] = "config";
+const char kVideoSwitchName[] = "video";
+
+const char kVideoSwitchValueVerbatim[] = "verbatim";
+const char kVideoSwitchValueZip[] = "zip";
+const char kVideoSwitchValueVp8[] = "vp8";
+const char kVideoSwitchValueVp8Rtp[] = "vp8rtp";
+
int main(int argc, char** argv) {
// Needed for the Mac, so we don't leak objects when threads are created.
@@ -68,10 +82,10 @@ int main(int argc, char** argv) {
#if defined(OS_WIN)
- std::wstring home_path = GetEnvironmentVar(kHomeDrive);
+ wstring home_path = GetEnvironmentVar(kHomeDrive);
home_path += GetEnvironmentVar(kHomePath);
#else
- std::string home_path = GetEnvironmentVar(base::env_vars::kHome);
+ string home_path = GetEnvironmentVar(base::env_vars::kHome);
#endif
FilePath config_path(home_path);
config_path = config_path.Append(kDefaultConfigPath);
@@ -98,15 +112,42 @@ int main(int argc, char** argv) {
<< "Cannot load media library";
// Construct a chromoting host.
- scoped_refptr<remoting::ChromotingHost> host;
+ scoped_refptr<ChromotingHost> host;
bool fake = cmd_line->HasSwitch(kFakeSwitchName);
if (fake) {
- host = new remoting::ChromotingHost(
+ host = ChromotingHost::Create(
&context, config,
new remoting::CapturerFake(context.main_message_loop()));
} else {
- host = new remoting::ChromotingHost(&context, config);
+ host = ChromotingHost::Create(&context, config);
+ }
+
+ if (cmd_line->HasSwitch(kVideoSwitchName)) {
+ string video_codec = cmd_line->GetSwitchValueASCII(kVideoSwitchName);
+ scoped_ptr<CandidateSessionConfig> config(
+ CandidateSessionConfig::CreateDefault());
+ config->mutable_video_configs()->clear();
+
+ ChannelConfig::TransportType transport = ChannelConfig::TRANSPORT_STREAM;
+ ChannelConfig::Codec codec;
+ if (video_codec == kVideoSwitchValueVerbatim) {
+ codec = ChannelConfig::CODEC_VERBATIM;
+ } else if (video_codec == kVideoSwitchValueZip) {
+ codec = ChannelConfig::CODEC_ZIP;
+ } else if (video_codec == kVideoSwitchValueVp8) {
+ codec = ChannelConfig::CODEC_VP8;
+ } else if (video_codec == kVideoSwitchValueVp8Rtp) {
+ transport = ChannelConfig::TRANSPORT_SRTP;
+ codec = ChannelConfig::CODEC_VP8;
+ } else {
+ LOG(ERROR) << "Unknown video codec: " << video_codec;
+ context.Stop();
+ return 1;
+ }
+ config->mutable_video_configs()->push_back(ChannelConfig(
+ transport, remoting::protocol::kDefaultStreamVersion, codec));
+ host->set_protocol_config(config.release());
}
// Let the chromoting host run until the shutdown task is executed.