| Index: remoting/host/local_desktop_environment.cc
|
| diff --git a/remoting/host/local_desktop_environment.cc b/remoting/host/local_desktop_environment.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9b1268a6b85e239d5b5cd0bb60c1f71b74f8e2c5
|
| --- /dev/null
|
| +++ b/remoting/host/local_desktop_environment.cc
|
| @@ -0,0 +1,148 @@
|
| +// Copyright (c) 2012 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/host/local_desktop_environment.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "base/single_thread_task_runner.h"
|
| +#include "remoting/capturer/video_frame_capturer.h"
|
| +#include "remoting/codec/audio_encoder.h"
|
| +#include "remoting/host/audio_capturer.h"
|
| +#include "remoting/host/audio_scheduler.h"
|
| +#include "remoting/host/event_executor.h"
|
| +#include "remoting/host/video_scheduler.h"
|
| +#include "remoting/protocol/clipboard_thread_proxy.h"
|
| +
|
| +namespace remoting {
|
| +
|
| +LocalDesktopEnvironment::LocalDesktopEnvironment(
|
| + scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
|
| + const CreateEventExecutorCallback& create_event_executor_callback)
|
| + : caller_task_runner_(caller_task_runner),
|
| + create_event_executor_callback_(create_event_executor_callback) {
|
| + DCHECK(caller_task_runner_->BelongsToCurrentThread());
|
| +}
|
| +
|
| +LocalDesktopEnvironment::~LocalDesktopEnvironment() {
|
| + DCHECK(caller_task_runner_->BelongsToCurrentThread());
|
| +
|
| + // Stop the video scheduler and clear references to the client's stubs.
|
| + if (video_scheduler_.get()) {
|
| + video_scheduler_->Stop();
|
| + video_scheduler_ = NULL;
|
| + }
|
| +
|
| + // Stop the audio scheduler and clear references to the client's stubs.
|
| + if (audio_scheduler_.get()) {
|
| + audio_scheduler_->Stop();
|
| + audio_scheduler_ = NULL;
|
| + }
|
| +}
|
| +
|
| +void LocalDesktopEnvironment::InjectClipboardEvent(
|
| + const protocol::ClipboardEvent& event) {
|
| + DCHECK(caller_task_runner_->BelongsToCurrentThread());
|
| +
|
| + event_executor_->InjectClipboardEvent(event);
|
| +}
|
| +
|
| +void LocalDesktopEnvironment::InjectKeyEvent(const protocol::KeyEvent& event) {
|
| + DCHECK(caller_task_runner_->BelongsToCurrentThread());
|
| +
|
| + event_executor_->InjectKeyEvent(event);
|
| +}
|
| +
|
| +void LocalDesktopEnvironment::InjectMouseEvent(
|
| + const protocol::MouseEvent& event) {
|
| + DCHECK(caller_task_runner_->BelongsToCurrentThread());
|
| +
|
| + event_executor_->InjectMouseEvent(event);
|
| +}
|
| +
|
| +void LocalDesktopEnvironment::StartAudio(
|
| + scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner,
|
| + scoped_ptr<AudioEncoder> audio_encoder,
|
| + protocol::AudioStub* audio_stub) {
|
| + DCHECK(caller_task_runner_->BelongsToCurrentThread());
|
| + DCHECK(!audio_scheduler_.get());
|
| +
|
| + // Create and start the audio scheduler. The |audio_stub| reference is cleared
|
| + // by ~LocalDesktopEnvironment().
|
| + audio_scheduler_ = AudioScheduler::Create(audio_task_runner,
|
| + caller_task_runner_,
|
| + AudioCapturer::Create(),
|
| + audio_encoder.Pass(),
|
| + audio_stub);
|
| +}
|
| +
|
| +void LocalDesktopEnvironment::PauseAudio(bool pause) {
|
| + DCHECK(caller_task_runner_->BelongsToCurrentThread());
|
| +
|
| + if (audio_scheduler_.get())
|
| + audio_scheduler_->Pause(pause);
|
| +}
|
| +
|
| +void LocalDesktopEnvironment::StartInput(
|
| + scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,
|
| + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
|
| + protocol::ClipboardStub* clipboard_stub) {
|
| + DCHECK(caller_task_runner_->BelongsToCurrentThread());
|
| + DCHECK(!clipboard_factory_);
|
| + DCHECK(!event_executor_);
|
| +
|
| + event_executor_ = create_event_executor_callback_.Run(input_task_runner,
|
| + ui_task_runner);
|
| + create_event_executor_callback_.Reset();
|
| +
|
| + // Create a weak pointer from |clipboard_stub| so that we can stop receiving
|
| + // local clipboard events during shutdown.
|
| + clipboard_factory_.reset(
|
| + new base::WeakPtrFactory<protocol::ClipboardStub>(clipboard_stub));
|
| + event_executor_->Start(scoped_ptr<protocol::ClipboardStub>(
|
| + new protocol::ClipboardThreadProxy(
|
| + clipboard_factory_->GetWeakPtr(), caller_task_runner_)));
|
| +}
|
| +
|
| +void LocalDesktopEnvironment::StartVideo(
|
| + scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner,
|
| + scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner,
|
| + scoped_ptr<VideoEncoder> video_encoder,
|
| + protocol::CursorShapeStub* cursor_shape_stub,
|
| + protocol::VideoStub* video_stub) {
|
| + DCHECK(caller_task_runner_->BelongsToCurrentThread());
|
| + DCHECK(!video_scheduler_.get());
|
| +
|
| + // Create and start video scheduler. The |cursor_shape_stub| and |video_stub|
|
| + // references are cleared by ~LocalDesktopEnvironment().
|
| + video_scheduler_ = VideoScheduler::Create(capture_task_runner,
|
| + encode_task_runner,
|
| + caller_task_runner_,
|
| + VideoFrameCapturer::Create(),
|
| + video_encoder.Pass(),
|
| + cursor_shape_stub,
|
| + video_stub);
|
| +}
|
| +
|
| +SkISize LocalDesktopEnvironment::GetScreenSize() const {
|
| + if (video_scheduler_.get())
|
| + return video_scheduler_->size_most_recent();
|
| + else
|
| + return SkISize::Make(0, 0);
|
| +}
|
| +
|
| +void LocalDesktopEnvironment::PauseVideo(bool pause) {
|
| + DCHECK(caller_task_runner_->BelongsToCurrentThread());
|
| +
|
| + if (video_scheduler_.get())
|
| + video_scheduler_->Pause(pause);
|
| +}
|
| +
|
| +void LocalDesktopEnvironment::UpdateSequenceNumber(int64 sequence_number) {
|
| + DCHECK(caller_task_runner_->BelongsToCurrentThread());
|
| +
|
| + if (video_scheduler_.get())
|
| + video_scheduler_->UpdateSequenceNumber(sequence_number);
|
| +}
|
| +
|
| +} // namespace remoting
|
|
|