summaryrefslogtreecommitdiffstats
path: root/remoting/client
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-06 10:38:47 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-06 10:38:47 +0000
commitfd146835762ea78ac9a9b87f7e489fc64357d2ad (patch)
treeabf845563cdd80f1e643a77407da264a4621167e /remoting/client
parent4950ea06017b4c727edc367f30c1bc9c2c68fee6 (diff)
downloadchromium_src-fd146835762ea78ac9a9b87f7e489fc64357d2ad.zip
chromium_src-fd146835762ea78ac9a9b87f7e489fc64357d2ad.tar.gz
chromium_src-fd146835762ea78ac9a9b87f7e489fc64357d2ad.tar.bz2
Chromoting client: video renderer based on MediaSource API.
The new render is not enabled yet by default, but can be enabled using remoting.settings.USE_MEDIA_SOURCE_RENDERING flag in the webapp. BUG=321825 Review URL: https://codereview.chromium.org/134163005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@249338 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/client')
-rw-r--r--remoting/client/plugin/DEPS3
-rw-r--r--remoting/client/plugin/chromoting_instance.cc135
-rw-r--r--remoting/client/plugin/chromoting_instance.h26
-rw-r--r--remoting/client/plugin/media_source_video_renderer.cc189
-rw-r--r--remoting/client/plugin/media_source_video_renderer.h70
-rw-r--r--remoting/client/plugin/pepper_view.h6
6 files changed, 379 insertions, 50 deletions
diff --git a/remoting/client/plugin/DEPS b/remoting/client/plugin/DEPS
new file mode 100644
index 0000000..dd27068
--- /dev/null
+++ b/remoting/client/plugin/DEPS
@@ -0,0 +1,3 @@
+include_rules = [
+ "+third_party/libwebm",
+]
diff --git a/remoting/client/plugin/chromoting_instance.cc b/remoting/client/plugin/chromoting_instance.cc
index b94c207..ef5f428 100644
--- a/remoting/client/plugin/chromoting_instance.cc
+++ b/remoting/client/plugin/chromoting_instance.cc
@@ -34,6 +34,7 @@
#include "remoting/client/client_config.h"
#include "remoting/client/frame_consumer_proxy.h"
#include "remoting/client/plugin/delegating_signal_strategy.h"
+#include "remoting/client/plugin/media_source_video_renderer.h"
#include "remoting/client/plugin/pepper_audio_player.h"
#include "remoting/client/plugin/pepper_input_handler.h"
#include "remoting/client/plugin/pepper_port_allocator.h"
@@ -171,7 +172,7 @@ logging::LogMessageHandlerFunction g_logging_old_handler = NULL;
const char ChromotingInstance::kApiFeatures[] =
"highQualityScaling injectKeyEvent sendClipboardItem remapKey trapKey "
"notifyClientResolution pauseVideo pauseAudio asyncPin thirdPartyAuth "
- "pinlessAuth extensionMessage allowMouseLock";
+ "pinlessAuth extensionMessage allowMouseLock mediaSourceRendering";
const char ChromotingInstance::kRequestedCapabilities[] = "";
const char ChromotingInstance::kSupportedCapabilities[] = "desktopShape";
@@ -205,6 +206,7 @@ ChromotingInstance::ChromotingInstance(PP_Instance pp_instance)
normalizing_input_filter_(CreateNormalizingInputFilter(&key_mapper_)),
input_handler_(this, normalizing_input_filter_.get()),
use_async_pin_dialog_(false),
+ use_media_source_rendering_(false),
weak_factory_(this) {
RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL);
RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
@@ -227,7 +229,7 @@ ChromotingInstance::ChromotingInstance(PP_Instance pp_instance)
data->SetString("requestedCapabilities", kRequestedCapabilities);
data->SetString("supportedCapabilities", kSupportedCapabilities);
- PostChromotingMessage("hello", data.Pass());
+ PostLegacyJsonMessage("hello", data.Pass());
}
ChromotingInstance::~ChromotingInstance() {
@@ -340,6 +342,8 @@ void ChromotingInstance::HandleMessage(const pp::Var& message) {
HandleExtensionMessage(*data);
} else if (method == "allowMouseLock") {
HandleAllowMouseLockMessage();
+ } else if (method == "enableMediaSourceRendering") {
+ HandleEnableMediaSourceRendering();
}
}
@@ -353,10 +357,11 @@ void ChromotingInstance::DidChangeView(const pp::View& view) {
DCHECK(plugin_task_runner_->BelongsToCurrentThread());
plugin_view_ = view;
- if (view_) {
+ mouse_input_filter_.set_input_size(
+ webrtc::DesktopSize(view.GetRect().width(), view.GetRect().height()));
+
+ if (view_)
view_->SetView(view);
- mouse_input_filter_.set_input_size(view_->get_view_size_dips());
- }
}
bool ChromotingInstance::HandleInputEvent(const pp::InputEvent& event) {
@@ -379,7 +384,7 @@ void ChromotingInstance::SetDesktopSize(const webrtc::DesktopSize& size,
data->SetInteger("x_dpi", dpi.x());
if (dpi.y())
data->SetInteger("y_dpi", dpi.y());
- PostChromotingMessage("onDesktopSize", data.Pass());
+ PostLegacyJsonMessage("onDesktopSize", data.Pass());
}
void ChromotingInstance::SetDesktopShape(const webrtc::DesktopRegion& shape) {
@@ -401,7 +406,7 @@ void ChromotingInstance::SetDesktopShape(const webrtc::DesktopRegion& shape) {
scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
data->Set("rects", rects_value.release());
- PostChromotingMessage("onDesktopShape", data.Pass());
+ PostLegacyJsonMessage("onDesktopShape", data.Pass());
}
void ChromotingInstance::OnConnectionState(
@@ -410,7 +415,7 @@ void ChromotingInstance::OnConnectionState(
scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
data->SetString("state", ConnectionStateToString(state));
data->SetString("error", ConnectionErrorToString(error));
- PostChromotingMessage("onConnectionStatus", data.Pass());
+ PostLegacyJsonMessage("onConnectionStatus", data.Pass());
}
void ChromotingInstance::FetchThirdPartyToken(
@@ -427,13 +432,13 @@ void ChromotingInstance::FetchThirdPartyToken(
data->SetString("tokenUrl", token_url.spec());
data->SetString("hostPublicKey", host_public_key);
data->SetString("scope", scope);
- PostChromotingMessage("fetchThirdPartyToken", data.Pass());
+ PostLegacyJsonMessage("fetchThirdPartyToken", data.Pass());
}
void ChromotingInstance::OnConnectionReady(bool ready) {
scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
data->SetBoolean("ready", ready);
- PostChromotingMessage("onConnectionReady", data.Pass());
+ PostLegacyJsonMessage("onConnectionReady", data.Pass());
}
void ChromotingInstance::OnRouteChanged(const std::string& channel_name,
@@ -442,13 +447,13 @@ void ChromotingInstance::OnRouteChanged(const std::string& channel_name,
std::string message = "Channel " + channel_name + " using " +
protocol::TransportRoute::GetTypeString(route.type) + " connection.";
data->SetString("message", message);
- PostChromotingMessage("logDebugMessage", data.Pass());
+ PostLegacyJsonMessage("logDebugMessage", data.Pass());
}
void ChromotingInstance::SetCapabilities(const std::string& capabilities) {
scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
data->SetString("capabilities", capabilities);
- PostChromotingMessage("setCapabilities", data.Pass());
+ PostLegacyJsonMessage("setCapabilities", data.Pass());
}
void ChromotingInstance::SetPairingResponse(
@@ -456,7 +461,7 @@ void ChromotingInstance::SetPairingResponse(
scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
data->SetString("clientId", pairing_response.client_id());
data->SetString("sharedSecret", pairing_response.shared_secret());
- PostChromotingMessage("pairingResponse", data.Pass());
+ PostLegacyJsonMessage("pairingResponse", data.Pass());
}
void ChromotingInstance::DeliverHostMessage(
@@ -464,7 +469,7 @@ void ChromotingInstance::DeliverHostMessage(
scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
data->SetString("type", message.type());
data->SetString("data", message.data());
- PostChromotingMessage("extensionMessage", data.Pass());
+ PostLegacyJsonMessage("extensionMessage", data.Pass());
}
void ChromotingInstance::FetchSecretFromDialog(
@@ -477,7 +482,7 @@ void ChromotingInstance::FetchSecretFromDialog(
secret_fetched_callback_ = secret_fetched_callback;
scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
data->SetBoolean("pairingSupported", pairing_supported);
- PostChromotingMessage("fetchPin", data.Pass());
+ PostLegacyJsonMessage("fetchPin", data.Pass());
}
void ChromotingInstance::FetchSecretFromString(
@@ -510,7 +515,7 @@ void ChromotingInstance::InjectClipboardEvent(
scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
data->SetString("mimeType", event.mime_type());
data->SetString("item", event.data());
- PostChromotingMessage("injectClipboardItem", data.Pass());
+ PostLegacyJsonMessage("injectClipboardItem", data.Pass());
}
void ChromotingInstance::SetCursorShape(
@@ -580,7 +585,7 @@ void ChromotingInstance::SetCursorShape(
void ChromotingInstance::OnFirstFrameReceived() {
scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
- PostChromotingMessage("onFirstFrameReceived", data.Pass());
+ PostLegacyJsonMessage("onFirstFrameReceived", data.Pass());
}
void ChromotingInstance::HandleConnect(const base::DictionaryValue& data) {
@@ -629,23 +634,28 @@ void ChromotingInstance::ConnectWithConfig(const ClientConfig& config,
jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop();
-
- view_.reset(new PepperView(this, &context_));
- view_weak_factory_.reset(
- new base::WeakPtrFactory<FrameConsumer>(view_.get()));
-
- // SoftwareVideoRenderer runs on a separate thread so for now we wrap
- // PepperView with a ref-counted proxy object.
- scoped_refptr<FrameConsumerProxy> consumer_proxy =
- new FrameConsumerProxy(plugin_task_runner_,
- view_weak_factory_->GetWeakPtr());
-
- SoftwareVideoRenderer* decoder =
- new SoftwareVideoRenderer(context_.main_task_runner(),
- context_.decode_task_runner(),
- consumer_proxy);
- view_->Initialize(decoder);
- video_renderer_.reset(decoder);
+ if (use_media_source_rendering_) {
+ video_renderer_.reset(new MediaSourceVideoRenderer(this));
+ } else {
+ view_.reset(new PepperView(this, &context_));
+ view_weak_factory_.reset(
+ new base::WeakPtrFactory<FrameConsumer>(view_.get()));
+
+ // SoftwareVideoRenderer runs on a separate thread so for now we wrap
+ // PepperView with a ref-counted proxy object.
+ scoped_refptr<FrameConsumerProxy> consumer_proxy =
+ new FrameConsumerProxy(plugin_task_runner_,
+ view_weak_factory_->GetWeakPtr());
+
+ SoftwareVideoRenderer* renderer =
+ new SoftwareVideoRenderer(context_.main_task_runner(),
+ context_.decode_task_runner(),
+ consumer_proxy);
+ view_->Initialize(renderer);
+ if (!plugin_view_.is_null())
+ view_->SetView(plugin_view_);
+ video_renderer_.reset(renderer);
+ }
host_connection_.reset(new protocol::ConnectionToHost(true));
scoped_ptr<AudioPlayer> audio_player(new PepperAudioPlayer(this));
@@ -653,12 +663,12 @@ void ChromotingInstance::ConnectWithConfig(const ClientConfig& config,
this, video_renderer_.get(),
audio_player.Pass()));
- if (!plugin_view_.is_null())
- view_->SetView(plugin_view_);
-
// Connect the input pipeline to the protocol stub & initialize components.
mouse_input_filter_.set_input_stub(host_connection_->input_stub());
- mouse_input_filter_.set_input_size(view_->get_view_size_dips());
+ if (!plugin_view_.is_null()) {
+ mouse_input_filter_.set_input_size(webrtc::DesktopSize(
+ plugin_view_.GetRect().width(), plugin_view_.GetRect().height()));
+ }
VLOG(0) << "Connecting to " << config.host_jid
<< ". Local jid: " << local_jid << ".";
@@ -909,13 +919,25 @@ void ChromotingInstance::HandleAllowMouseLockMessage() {
input_handler_.AllowMouseLock();
}
+void ChromotingInstance::HandleEnableMediaSourceRendering() {
+ use_media_source_rendering_ = true;
+}
+
ChromotingStats* ChromotingInstance::GetStats() {
if (!video_renderer_.get())
return NULL;
return video_renderer_->GetStats();
}
-void ChromotingInstance::PostChromotingMessage(
+void ChromotingInstance::PostChromotingMessage(const std::string& method,
+ const pp::VarDictionary& data) {
+ pp::VarDictionary message;
+ message.Set(pp::Var("method"), pp::Var(method));
+ message.Set(pp::Var("data"), data);
+ PostMessage(message);
+}
+
+void ChromotingInstance::PostLegacyJsonMessage(
const std::string& method,
scoped_ptr<base::DictionaryValue> data) {
scoped_ptr<base::DictionaryValue> message(new base::DictionaryValue());
@@ -931,13 +953,13 @@ void ChromotingInstance::SendTrappedKey(uint32 usb_keycode, bool pressed) {
scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
data->SetInteger("usbKeycode", usb_keycode);
data->SetBoolean("pressed", pressed);
- PostChromotingMessage("trappedKeyEvent", data.Pass());
+ PostLegacyJsonMessage("trappedKeyEvent", data.Pass());
}
void ChromotingInstance::SendOutgoingIq(const std::string& iq) {
scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
data->SetString("iq", iq);
- PostChromotingMessage("sendOutgoingIq", data.Pass());
+ PostLegacyJsonMessage("sendOutgoingIq", data.Pass());
}
void ChromotingInstance::SendPerfStats() {
@@ -959,7 +981,7 @@ void ChromotingInstance::SendPerfStats() {
data->SetDouble("decodeLatency", stats->video_decode_ms()->Average());
data->SetDouble("renderLatency", stats->video_paint_ms()->Average());
data->SetDouble("roundtripLatency", stats->round_trip_ms()->Average());
- PostChromotingMessage("onPerfStats", data.Pass());
+ PostLegacyJsonMessage("onPerfStats", data.Pass());
}
// static
@@ -1060,7 +1082,7 @@ void ChromotingInstance::ProcessLogToUI(const std::string& message) {
g_logging_to_plugin = true;
scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
data->SetString("message", message);
- PostChromotingMessage("logDebugMessage", data.Pass());
+ PostLegacyJsonMessage("logDebugMessage", data.Pass());
g_logging_to_plugin = false;
}
@@ -1085,4 +1107,31 @@ bool ChromotingInstance::IsConnected() {
(host_connection_->state() == protocol::ConnectionToHost::CONNECTED);
}
+void ChromotingInstance::OnMediaSourceSize(const webrtc::DesktopSize& size,
+ const webrtc::DesktopVector& dpi) {
+ SetDesktopSize(size, dpi);
+}
+
+void ChromotingInstance::OnMediaSourceShape(
+ const webrtc::DesktopRegion& shape) {
+ SetDesktopShape(shape);
+}
+
+void ChromotingInstance::OnMediaSourceReset(const std::string& format) {
+ scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
+ data->SetString("format", format);
+ PostLegacyJsonMessage("mediaSourceReset", data.Pass());
+}
+
+void ChromotingInstance::OnMediaSourceData(uint8_t* buffer,
+ size_t buffer_size) {
+ pp::VarArrayBuffer array_buffer(buffer_size);
+ void* data_ptr = array_buffer.Map();
+ memcpy(data_ptr, buffer, buffer_size);
+ array_buffer.Unmap();
+ pp::VarDictionary data_dictionary;
+ data_dictionary.Set(pp::Var("buffer"), array_buffer);
+ PostChromotingMessage("mediaSourceData", data_dictionary);
+}
+
} // namespace remoting
diff --git a/remoting/client/plugin/chromoting_instance.h b/remoting/client/plugin/chromoting_instance.h
index 3b0ad76..b5e480d 100644
--- a/remoting/client/plugin/chromoting_instance.h
+++ b/remoting/client/plugin/chromoting_instance.h
@@ -21,6 +21,7 @@
#include "remoting/client/client_context.h"
#include "remoting/client/client_user_interface.h"
#include "remoting/client/key_event_mapper.h"
+#include "remoting/client/plugin/media_source_video_renderer.h"
#include "remoting/client/plugin/normalizing_input_filter.h"
#include "remoting/client/plugin/pepper_input_handler.h"
#include "remoting/client/plugin/pepper_plugin_thread_delegate.h"
@@ -68,6 +69,7 @@ struct ClientConfig;
class ChromotingInstance :
public ClientUserInterface,
+ public MediaSourceVideoRenderer::Delegate,
public protocol::ClipboardStub,
public protocol::CursorShapeStub,
public pp::Instance {
@@ -204,6 +206,7 @@ class ChromotingInstance :
void HandleRequestPairing(const base::DictionaryValue& data);
void HandleExtensionMessage(const base::DictionaryValue& data);
void HandleAllowMouseLockMessage();
+ void HandleEnableMediaSourceRendering();
// Helper method called from Connect() to connect with parsed config.
void ConnectWithConfig(const ClientConfig& config,
@@ -211,7 +214,16 @@ class ChromotingInstance :
// Helper method to post messages to the webapp.
void PostChromotingMessage(const std::string& method,
- scoped_ptr<base::DictionaryValue> data);
+ const pp::VarDictionary& data);
+
+ // Same as above, but serializes messages to JSON before sending them. This
+ // method is used for backward compatibility with older version of the webapp
+ // that expect to received most messages formatted using JSON.
+ //
+ // TODO(sergeyu): When all current versions of the webapp support raw messages
+ // remove this method and use PostChromotingMessage() instead.
+ void PostLegacyJsonMessage(const std::string& method,
+ scoped_ptr<base::DictionaryValue> data);
// Posts trapped keys to the web-app to handle.
void SendTrappedKey(uint32 usb_keycode, bool pressed);
@@ -235,6 +247,13 @@ class ChromotingInstance :
bool pairing_supported,
const protocol::SecretFetchedCallback& secret_fetched_callback);
+ // MediaSourceVideoRenderer::Delegate implementation.
+ virtual void OnMediaSourceSize(const webrtc::DesktopSize& size,
+ const webrtc::DesktopVector& dpi) OVERRIDE;
+ virtual void OnMediaSourceShape(const webrtc::DesktopRegion& shape) OVERRIDE;
+ virtual void OnMediaSourceReset(const std::string& format) OVERRIDE;
+ virtual void OnMediaSourceData(uint8_t* buffer, size_t buffer_size) OVERRIDE;
+
bool initialized_;
PepperPluginThreadDelegate plugin_thread_delegate_;
@@ -264,6 +283,11 @@ class ChromotingInstance :
bool use_async_pin_dialog_;
protocol::SecretFetchedCallback secret_fetched_callback_;
+ // Set to true if the webapp has requested to use MediaSource API for
+ // rendering. In that case all the encoded video will be passed to the
+ // webapp for decoding.
+ bool use_media_source_rendering_;
+
base::WeakPtr<PepperTokenFetcher> pepper_token_fetcher_;
// Weak reference to this instance, used for global logging and task posting.
diff --git a/remoting/client/plugin/media_source_video_renderer.cc b/remoting/client/plugin/media_source_video_renderer.cc
new file mode 100644
index 0000000..f14a61e
--- /dev/null
+++ b/remoting/client/plugin/media_source_video_renderer.cc
@@ -0,0 +1,189 @@
+// Copyright 2014 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/client/plugin/media_source_video_renderer.h"
+
+#include <string.h>
+
+#include "base/callback_helpers.h"
+#include "base/logging.h"
+#include "remoting/proto/video.pb.h"
+#include "remoting/protocol/session_config.h"
+#include "third_party/libwebm/source/mkvmuxer.hpp"
+
+namespace remoting {
+
+static int kFrameIntervalNs = 1000000;
+
+class MediaSourceVideoRenderer::VideoWriter : public mkvmuxer::IMkvWriter {
+ public:
+ typedef std::vector<uint8_t> DataBuffer;
+
+ VideoWriter(const webrtc::DesktopSize& frame_size);
+ virtual ~VideoWriter();
+
+ const webrtc::DesktopSize& size() { return frame_size_; }
+ int64_t last_frame_timestamp() { return timecode_ - kFrameIntervalNs; }
+
+ // IMkvWriter interface.
+ virtual mkvmuxer::int32 Write(const void* buf, mkvmuxer::uint32 len) OVERRIDE;
+ virtual mkvmuxer::int64 Position() const OVERRIDE;
+ virtual mkvmuxer::int32 Position(mkvmuxer::int64 position) OVERRIDE;
+ virtual bool Seekable() const OVERRIDE;
+ virtual void ElementStartNotify(mkvmuxer::uint64 element_id,
+ mkvmuxer::int64 position) OVERRIDE;
+
+ scoped_ptr<DataBuffer> OnVideoFrame(const std::string& video_data);
+
+ private:
+ webrtc::DesktopSize frame_size_;
+ scoped_ptr<DataBuffer> output_data_;
+ int64_t position_;
+ scoped_ptr<mkvmuxer::Segment> segment_;
+ int64_t timecode_;
+};
+
+MediaSourceVideoRenderer::VideoWriter::VideoWriter(
+ const webrtc::DesktopSize& frame_size)
+ : frame_size_(frame_size),
+ position_(0),
+ timecode_(0) {
+ segment_.reset(new mkvmuxer::Segment());
+ segment_->Init(this);
+ segment_->set_mode(mkvmuxer::Segment::kLive);
+ segment_->AddVideoTrack(frame_size_.width(), frame_size_.height(), 1);
+ mkvmuxer::SegmentInfo* const info = segment_->GetSegmentInfo();
+ info->set_writing_app("ChromotingViewer");
+ info->set_muxing_app("ChromotingViewer");
+}
+
+MediaSourceVideoRenderer::VideoWriter::~VideoWriter() {}
+
+mkvmuxer::int32 MediaSourceVideoRenderer::VideoWriter::Write(
+ const void* buf,
+ mkvmuxer::uint32 len) {
+ output_data_->insert(output_data_->end(),
+ reinterpret_cast<const char*>(buf),
+ reinterpret_cast<const char*>(buf) + len);
+ position_ += len;
+ return 0;
+}
+
+mkvmuxer::int64 MediaSourceVideoRenderer::VideoWriter::Position() const {
+ return position_;
+}
+
+mkvmuxer::int32 MediaSourceVideoRenderer::VideoWriter::Position(
+ mkvmuxer::int64 position) {
+ return -1;
+}
+
+bool MediaSourceVideoRenderer::VideoWriter::Seekable() const {
+ return false;
+}
+
+void MediaSourceVideoRenderer::VideoWriter::ElementStartNotify(
+ mkvmuxer::uint64 element_id,
+ mkvmuxer::int64 position) {
+}
+
+scoped_ptr<MediaSourceVideoRenderer::VideoWriter::DataBuffer>
+MediaSourceVideoRenderer::VideoWriter::OnVideoFrame(
+ const std::string& video_data) {
+ DCHECK(!output_data_);
+
+ output_data_.reset(new DataBuffer());
+ bool first_frame = (timecode_ == 0);
+ segment_->AddFrame(reinterpret_cast<const uint8_t*>(video_data.data()),
+ video_data.size(), 1, timecode_, first_frame);
+ timecode_ += kFrameIntervalNs;
+ return output_data_.Pass();
+}
+
+MediaSourceVideoRenderer::MediaSourceVideoRenderer(Delegate* delegate)
+ : delegate_(delegate),
+ latest_sequence_number_(0) {
+}
+
+MediaSourceVideoRenderer::~MediaSourceVideoRenderer() {}
+
+void MediaSourceVideoRenderer::Initialize(
+ const protocol::SessionConfig& config) {
+ DCHECK_EQ(config.video_config().codec, protocol::ChannelConfig::CODEC_VP8);
+}
+
+ChromotingStats* MediaSourceVideoRenderer::GetStats() {
+ return &stats_;
+}
+
+void MediaSourceVideoRenderer::ProcessVideoPacket(
+ scoped_ptr<VideoPacket> packet,
+ const base::Closure& done) {
+ base::ScopedClosureRunner done_runner(done);
+
+ // Don't need to do anything if the packet is empty. Host sends empty video
+ // packets when the screen is not changing.
+ if (!packet->data().size())
+ return;
+
+ // Update statistics.
+ stats_.video_frame_rate()->Record(1);
+ stats_.video_bandwidth()->Record(packet->data().size());
+ if (packet->has_capture_time_ms())
+ stats_.video_capture_ms()->Record(packet->capture_time_ms());
+ if (packet->has_encode_time_ms())
+ stats_.video_encode_ms()->Record(packet->encode_time_ms());
+ if (packet->has_client_sequence_number() &&
+ packet->client_sequence_number() > latest_sequence_number_) {
+ latest_sequence_number_ = packet->client_sequence_number();
+ base::TimeDelta round_trip_latency =
+ base::Time::Now() -
+ base::Time::FromInternalValue(packet->client_sequence_number());
+ stats_.round_trip_ms()->Record(round_trip_latency.InMilliseconds());
+ }
+
+ bool media_source_needs_reset = false;
+
+ webrtc::DesktopSize frame_size(packet->format().screen_width(),
+ packet->format().screen_height());
+ if (!writer_ ||
+ (!writer_->size().equals(frame_size) && !frame_size.is_empty())) {
+ media_source_needs_reset = true;
+ writer_.reset(new VideoWriter(frame_size));
+ delegate_->OnMediaSourceReset("video/webm; codecs=\"vp8\"");
+ }
+
+ webrtc::DesktopVector frame_dpi(packet->format().x_dpi(),
+ packet->format().y_dpi());
+ if (media_source_needs_reset || !frame_dpi_.equals(frame_dpi)) {
+ frame_dpi_ = frame_dpi;
+ delegate_->OnMediaSourceSize(frame_size, frame_dpi);
+ }
+
+ // Update the desktop shape region.
+ webrtc::DesktopRegion desktop_shape;
+ if (packet->has_use_desktop_shape()) {
+ for (int i = 0; i < packet->desktop_shape_rects_size(); ++i) {
+ Rect remoting_rect = packet->desktop_shape_rects(i);
+ desktop_shape.AddRect(webrtc::DesktopRect::MakeXYWH(
+ remoting_rect.x(), remoting_rect.y(),
+ remoting_rect.width(), remoting_rect.height()));
+ }
+ } else {
+ // Fallback for the case when the host didn't include the desktop shape.
+ desktop_shape =
+ webrtc::DesktopRegion(webrtc::DesktopRect::MakeSize(frame_size));
+ }
+
+ if (!desktop_shape_.Equals(desktop_shape)) {
+ desktop_shape_.Swap(&desktop_shape);
+ delegate_->OnMediaSourceShape(desktop_shape_);
+ }
+
+ scoped_ptr<VideoWriter::DataBuffer> buffer =
+ writer_->OnVideoFrame(packet->data());
+ delegate_->OnMediaSourceData(&(*(buffer->begin())), buffer->size());
+}
+
+} // namespace remoting
diff --git a/remoting/client/plugin/media_source_video_renderer.h b/remoting/client/plugin/media_source_video_renderer.h
new file mode 100644
index 0000000..2df7758
--- /dev/null
+++ b/remoting/client/plugin/media_source_video_renderer.h
@@ -0,0 +1,70 @@
+// Copyright 2014 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_CLIENT_PLUGIN_MEDIA_SOURCE_VIDEO_RENDERER_H_
+#define REMOTING_CLIENT_PLUGIN_MEDIA_SOURCE_VIDEO_RENDERER_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/callback.h"
+#include "base/memory/scoped_ptr.h"
+#include "remoting/client/chromoting_stats.h"
+#include "remoting/client/video_renderer.h"
+#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
+#include "third_party/webrtc/modules/desktop_capture/desktop_region.h"
+
+namespace remoting {
+
+// VideoRenderer implementation that packs data into a WebM stream that can be
+// passed to <video> tag using MediaSource API.
+class MediaSourceVideoRenderer : public VideoRenderer {
+ public:
+ class Delegate {
+ public:
+ Delegate() {}
+ virtual ~Delegate() {}
+
+ // Called when stream size changes.
+ virtual void OnMediaSourceSize(const webrtc::DesktopSize& size,
+ const webrtc::DesktopVector& dpi) = 0;
+
+ // Called when desktop shape changes.
+ virtual void OnMediaSourceShape(const webrtc::DesktopRegion& shape) = 0;
+
+ // Called when the MediaSource needs to be reset (e.g. because screen size
+ // has changed).
+ virtual void OnMediaSourceReset(const std::string& format) = 0;
+
+ // Called when new data becomes available.
+ virtual void OnMediaSourceData(uint8_t* buffer, size_t buffer_size) = 0;
+ };
+
+ MediaSourceVideoRenderer(Delegate* delegate);
+ virtual ~MediaSourceVideoRenderer();
+
+ // VideoRenderer interface.
+ virtual void Initialize(const protocol::SessionConfig& config) OVERRIDE;
+ virtual ChromotingStats* GetStats() OVERRIDE;
+ virtual void ProcessVideoPacket(scoped_ptr<VideoPacket> packet,
+ const base::Closure& done) OVERRIDE;
+
+ private:
+ // Helper class used to generate WebM stream.
+ class VideoWriter;
+
+ Delegate* delegate_;
+ scoped_ptr<VideoWriter> writer_;
+ webrtc::DesktopVector frame_dpi_;
+ webrtc::DesktopRegion desktop_shape_;
+
+ ChromotingStats stats_;
+ int64 latest_sequence_number_;
+
+ DISALLOW_COPY_AND_ASSIGN(MediaSourceVideoRenderer);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_CLIENT_PLUGIN_MEDIA_SOURCE_VIDEO_RENDERER_H_
diff --git a/remoting/client/plugin/pepper_view.h b/remoting/client/plugin/pepper_view.h
index 4f35277..098ab68 100644
--- a/remoting/client/plugin/pepper_view.h
+++ b/remoting/client/plugin/pepper_view.h
@@ -64,12 +64,6 @@ class PepperView : public FrameConsumer {
return source_size_;
}
- // Return the dimensions of the view in Density Independent Pixels (DIPs).
- // Note that there may be multiple device pixels per DIP.
- const webrtc::DesktopSize& get_view_size_dips() const {
- return dips_size_;
- }
-
private:
// Allocates a new frame buffer to supply to the FrameProducer to render into.
// Returns NULL if the maximum number of buffers has already been allocated.