summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-07 21:47:58 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-07 21:47:58 +0000
commit885ff1dfd127346d8fd1bfa239c7375773aabe48 (patch)
tree6004858fef22e08c5c1b4570231e01e1f0290a43 /chrome/renderer
parent3bb08606c22e357896714764731a7af21e04377d (diff)
downloadchromium_src-885ff1dfd127346d8fd1bfa239c7375773aabe48.zip
chromium_src-885ff1dfd127346d8fd1bfa239c7375773aabe48.tar.gz
chromium_src-885ff1dfd127346d8fd1bfa239c7375773aabe48.tar.bz2
GpuVideoDecoderHost runs on IO thread instead of Render thread
Move GpuVideoDecoderHost to IO thread and change GpuVideoServiceHost to be a MessageFilter. BUG=53714 TEST=Tree is green. Will pending on WebKit changes to make this work. Review URL: http://codereview.chromium.org/3462015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61854 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/ggl/ggl.cc2
-rw-r--r--chrome/renderer/gpu_channel_host.cc7
-rw-r--r--chrome/renderer/gpu_channel_host.h9
-rw-r--r--chrome/renderer/gpu_video_decoder_host.h4
-rw-r--r--chrome/renderer/gpu_video_service_host.cc58
-rw-r--r--chrome/renderer/gpu_video_service_host.h33
-rw-r--r--chrome/renderer/media/ipc_video_decoder.cc20
-rw-r--r--chrome/renderer/media/ipc_video_decoder.h4
-rw-r--r--chrome/renderer/render_thread.cc2
-rw-r--r--chrome/renderer/render_view.cc3
10 files changed, 68 insertions, 74 deletions
diff --git a/chrome/renderer/ggl/ggl.cc b/chrome/renderer/ggl/ggl.cc
index 1a0e6e9..f69e3c3 100644
--- a/chrome/renderer/ggl/ggl.cc
+++ b/chrome/renderer/ggl/ggl.cc
@@ -367,7 +367,7 @@ bool Context::SwapBuffers() {
}
media::VideoDecodeEngine* Context::CreateVideoDecodeEngine() {
- return GpuVideoServiceHost::get()->CreateVideoDecoder(
+ return channel_->gpu_video_service_host()->CreateVideoDecoder(
command_buffer_->route_id());
}
diff --git a/chrome/renderer/gpu_channel_host.cc b/chrome/renderer/gpu_channel_host.cc
index 0b576b8..de89774 100644
--- a/chrome/renderer/gpu_channel_host.cc
+++ b/chrome/renderer/gpu_channel_host.cc
@@ -47,9 +47,10 @@ void GpuChannelHost::OnMessageReceived(const IPC::Message& message) {
}
void GpuChannelHost::OnChannelConnected(int32 peer_pid) {
- GpuVideoServiceHost::get()->OnGpuChannelConnected(this,
- &router_,
- channel_.get());
+ // When the channel is connected we create a GpuVideoServiceHost and add it
+ // as a message filter.
+ gpu_video_service_host_.reset(new GpuVideoServiceHost());
+ channel_->AddFilter(gpu_video_service_host_.get());
}
void GpuChannelHost::OnChannelError() {
diff --git a/chrome/renderer/gpu_channel_host.h b/chrome/renderer/gpu_channel_host.h
index c139219..e6eecea 100644
--- a/chrome/renderer/gpu_channel_host.h
+++ b/chrome/renderer/gpu_channel_host.h
@@ -20,6 +20,7 @@
#include "ipc/ipc_sync_channel.h"
class CommandBufferProxy;
+class GpuVideoServiceHost;
// Encapsulates an IPC channel between the renderer and one plugin process.
// On the plugin side there's a corresponding GpuChannel.
@@ -72,6 +73,10 @@ class GpuChannelHost : public IPC::Channel::Listener,
// Destroy a command buffer created by this channel.
void DestroyCommandBuffer(CommandBufferProxy* command_buffer);
+ GpuVideoServiceHost* gpu_video_service_host() {
+ return gpu_video_service_host_.get();
+ }
+
private:
State state_;
@@ -88,6 +93,10 @@ class GpuChannelHost : public IPC::Channel::Listener,
typedef base::hash_map<int, IPC::Channel::Listener*> ProxyMap;
ProxyMap proxies_;
+ // This is a MessageFilter to intercept IPC messages and distribute them
+ // to the corresponding GpuVideoDecoderHost.
+ scoped_ptr<GpuVideoServiceHost> gpu_video_service_host_;
+
DISALLOW_COPY_AND_ASSIGN(GpuChannelHost);
};
diff --git a/chrome/renderer/gpu_video_decoder_host.h b/chrome/renderer/gpu_video_decoder_host.h
index 5ca520e..baf0ffe 100644
--- a/chrome/renderer/gpu_video_decoder_host.h
+++ b/chrome/renderer/gpu_video_decoder_host.h
@@ -37,6 +37,10 @@ class MessageRouter;
class GpuVideoDecoderHost : public media::VideoDecodeEngine,
public IPC::Channel::Listener {
public:
+ // |router| is used to dispatch IPC messages to this object.
+ // |ipc_sender| is used to send IPC messages to GPU process.
+ // It is important that the above two objects are accessed on the
+ // |message_loop_|.
GpuVideoDecoderHost(MessageRouter* router,
IPC::Message::Sender* ipc_sender,
int context_route_id,
diff --git a/chrome/renderer/gpu_video_service_host.cc b/chrome/renderer/gpu_video_service_host.cc
index 9c4f433..2971ff2 100644
--- a/chrome/renderer/gpu_video_service_host.cc
+++ b/chrome/renderer/gpu_video_service_host.cc
@@ -9,52 +9,46 @@
#include "chrome/renderer/render_thread.h"
GpuVideoServiceHost::GpuVideoServiceHost()
- : channel_host_(NULL),
- router_(NULL),
- message_loop_(NULL),
+ : channel_(NULL),
next_decoder_host_id_(0) {
- memset(&service_info_, 0, sizeof(service_info_));
}
-void GpuVideoServiceHost::OnChannelError() {
- LOG(ERROR) << "GpuVideoServiceHost::OnChannelError";
- channel_host_ = NULL;
- router_ = NULL;
+void GpuVideoServiceHost::OnFilterAdded(IPC::Channel* channel) {
+ channel_ = channel;
}
-void GpuVideoServiceHost::OnMessageReceived(const IPC::Message& msg) {
-#if 0
- IPC_BEGIN_MESSAGE_MAP(GpuVideoServiceHost, msg)
- IPC_MESSAGE_UNHANDLED_ERROR()
- IPC_END_MESSAGE_MAP()
-#endif
+void GpuVideoServiceHost::OnFilterRemoved() {
+ // TODO(hclam): Implement.
}
-void GpuVideoServiceHost::OnRendererThreadInit(MessageLoop* message_loop) {
- message_loop_ = message_loop;
+void GpuVideoServiceHost::OnChannelClosing() {
+ // TODO(hclam): Implement.
}
-void GpuVideoServiceHost::OnGpuChannelConnected(
- GpuChannelHost* channel_host,
- MessageRouter* router,
- IPC::SyncChannel* channel) {
-
- channel_host_ = channel_host;
- router_ = router;
-
- // Get the routing_id of video service in GPU process.
- service_info_.service_available = 0;
- if (!channel_host_->Send(new GpuChannelMsg_GetVideoService(&service_info_))) {
- LOG(ERROR) << "GpuChannelMsg_GetVideoService failed";
+bool GpuVideoServiceHost::OnMessageReceived(const IPC::Message& msg) {
+ switch (msg.type()) {
+ case GpuVideoDecoderHostMsg_CreateVideoDecoderDone::ID:
+ case GpuVideoDecoderHostMsg_InitializeACK::ID:
+ case GpuVideoDecoderHostMsg_DestroyACK::ID:
+ case GpuVideoDecoderHostMsg_FlushACK::ID:
+ case GpuVideoDecoderHostMsg_PrerollDone::ID:
+ case GpuVideoDecoderHostMsg_EmptyThisBufferACK::ID:
+ case GpuVideoDecoderHostMsg_EmptyThisBufferDone::ID:
+ case GpuVideoDecoderHostMsg_ConsumeVideoFrame::ID:
+ case GpuVideoDecoderHostMsg_AllocateVideoFrames::ID:
+ case GpuVideoDecoderHostMsg_ReleaseAllVideoFrames::ID:
+ if (!router_.RouteMessage(msg)) {
+ LOG(ERROR) << "GpuVideoDecoderHostMsg cannot be dispatched.";
+ }
+ return true;
+ default:
+ return false;
}
-
- if (service_info_.service_available)
- router->AddRoute(service_info_.video_service_host_route_id, this);
}
GpuVideoDecoderHost* GpuVideoServiceHost::CreateVideoDecoder(
int context_route_id) {
- GpuVideoDecoderHost* host = new GpuVideoDecoderHost(router_, channel_host_,
+ GpuVideoDecoderHost* host = new GpuVideoDecoderHost(&router_, channel_,
context_route_id,
next_decoder_host_id_);
// TODO(hclam): Handle thread safety of incrementing the ID.
diff --git a/chrome/renderer/gpu_video_service_host.h b/chrome/renderer/gpu_video_service_host.h
index ff54cd2..e4f3be0 100644
--- a/chrome/renderer/gpu_video_service_host.h
+++ b/chrome/renderer/gpu_video_service_host.h
@@ -13,23 +13,17 @@
#include "media/base/buffers.h"
#include "media/base/video_frame.h"
-// A GpuVideoServiceHost is a singleton in the renderer process that provides
-// access to hardware accelerated video decoding device in the GPU process
-// though a GpuVideoDecoderHost.
-class GpuVideoServiceHost : public IPC::Channel::Listener,
- public Singleton<GpuVideoServiceHost> {
+// GpuVideoServiceHost lives on IO thread and is used to dispatch IPC messages
+// to GpuVideoDecoderHost objects.
+class GpuVideoServiceHost : public IPC::ChannelProxy::MessageFilter {
public:
- // IPC::Channel::Listener.
- virtual void OnChannelConnected(int32 peer_pid) {}
- virtual void OnChannelError();
- virtual void OnMessageReceived(const IPC::Message& message);
-
- void OnRendererThreadInit(MessageLoop* message_loop);
+ GpuVideoServiceHost();
- // Called by GpuChannelHost when a GPU channel is established.
- void OnGpuChannelConnected(GpuChannelHost* channel_host,
- MessageRouter* router,
- IPC::SyncChannel* channel);
+ // IPC::ChannelProxy::MessageFilter implementations.
+ virtual bool OnMessageReceived(const IPC::Message& message);
+ virtual void OnFilterAdded(IPC::Channel* channel);
+ virtual void OnFilterRemoved();
+ virtual void OnChannelClosing();
// Called on RenderThread to create a hardware accelerated video decoder
// in the GPU process.
@@ -46,17 +40,14 @@ class GpuVideoServiceHost : public IPC::Channel::Listener,
GpuVideoDecoderHost* CreateVideoDecoder(int context_route_id);
private:
- GpuVideoServiceHost();
+ IPC::Channel* channel_;
- GpuChannelHost* channel_host_;
- MessageRouter* router_;
- GpuVideoServiceInfoParam service_info_;
- MessageLoop* message_loop_; // Message loop of render thread.
+ // Router to send messages to a GpuVideoDecoderHost.
+ MessageRouter router_;
// ID for the next GpuVideoDecoderHost.
int32 next_decoder_host_id_;
- friend struct DefaultSingletonTraits<GpuVideoServiceHost>;
DISALLOW_COPY_AND_ASSIGN(GpuVideoServiceHost);
};
diff --git a/chrome/renderer/media/ipc_video_decoder.cc b/chrome/renderer/media/ipc_video_decoder.cc
index c8f8096..d06130e 100644
--- a/chrome/renderer/media/ipc_video_decoder.cc
+++ b/chrome/renderer/media/ipc_video_decoder.cc
@@ -5,6 +5,7 @@
#include "chrome/renderer/media/ipc_video_decoder.h"
#include "base/task.h"
+#include "chrome/common/child_process.h"
#include "chrome/renderer/ggl/ggl.h"
#include "media/base/callback.h"
#include "media/base/filters.h"
@@ -21,7 +22,7 @@ IpcVideoDecoder::IpcVideoDecoder(MessageLoop* message_loop,
ggl::Context* ggl_context)
: width_(0),
height_(0),
- decode_engine_message_loop_(message_loop),
+ decode_context_message_loop_(message_loop),
ggl_context_(ggl_context) {
}
@@ -56,10 +57,9 @@ void IpcVideoDecoder::Initialize(media::DemuxerStream* demuxer_stream,
// Create a video decode context that assocates with the graphics
// context.
- // TODO(hclam): Need to define a message loop that hosts decode context.
decode_context_.reset(
ggl::CreateVideoDecodeContext(
- ggl_context_, decode_engine_message_loop_, true));
+ ggl_context_, decode_context_message_loop_, true));
// Create a hardware video decoder handle.
decode_engine_.reset(ggl::CreateVideoDecodeEngine(ggl_context_));
@@ -70,11 +70,9 @@ void IpcVideoDecoder::Initialize(media::DemuxerStream* demuxer_stream,
param.width = width_;
param.height = height_;
- // TODO(hclam): Move VideoDecodeEngine to IO Thread, this will avoid
- // dead lock during teardown.
// VideoDecodeEngine will perform initialization on the message loop
// given to it so it doesn't matter on which thread we are calling this.
- decode_engine_->Initialize(decode_engine_message_loop_, this,
+ decode_engine_->Initialize(ChildProcess::current()->io_message_loop(), this,
decode_context_.get(), param);
}
@@ -102,7 +100,7 @@ void IpcVideoDecoder::Seek(base::TimeDelta time,
}
void IpcVideoDecoder::OnInitializeComplete(const media::VideoCodecInfo& info) {
- DCHECK_EQ(decode_engine_message_loop_, MessageLoop::current());
+ DCHECK_EQ(ChildProcess::current()->io_message_loop(), MessageLoop::current());
if (info.success) {
media_format_.SetAsString(media::MediaFormat::kMimeType,
@@ -128,7 +126,7 @@ void IpcVideoDecoder::OnInitializeComplete(const media::VideoCodecInfo& info) {
}
void IpcVideoDecoder::OnUninitializeComplete() {
- DCHECK_EQ(decode_engine_message_loop_, MessageLoop::current());
+ DCHECK_EQ(ChildProcess::current()->io_message_loop(), MessageLoop::current());
// After the decode engine is uninitialized we are safe to destroy the decode
// context. The task will add a refcount to this object so don't need to worry
@@ -144,19 +142,19 @@ void IpcVideoDecoder::OnUninitializeComplete() {
}
void IpcVideoDecoder::OnFlushComplete() {
- DCHECK_EQ(decode_engine_message_loop_, MessageLoop::current());
+ DCHECK_EQ(ChildProcess::current()->io_message_loop(), MessageLoop::current());
flush_callback_->Run();
flush_callback_.reset();
}
void IpcVideoDecoder::OnSeekComplete() {
- DCHECK_EQ(decode_engine_message_loop_, MessageLoop::current());
+ DCHECK_EQ(ChildProcess::current()->io_message_loop(), MessageLoop::current());
seek_callback_->Run();
seek_callback_.reset();
}
void IpcVideoDecoder::OnError() {
- DCHECK_EQ(decode_engine_message_loop_, MessageLoop::current());
+ DCHECK_EQ(ChildProcess::current()->io_message_loop(), MessageLoop::current());
host()->SetError(media::PIPELINE_ERROR_DECODE);
}
diff --git a/chrome/renderer/media/ipc_video_decoder.h b/chrome/renderer/media/ipc_video_decoder.h
index d0aba70..c9d800d 100644
--- a/chrome/renderer/media/ipc_video_decoder.h
+++ b/chrome/renderer/media/ipc_video_decoder.h
@@ -72,8 +72,8 @@ class IpcVideoDecoder : public media::VideoDecoder,
// Pointer to the demuxer stream that will feed us compressed buffers.
scoped_refptr<media::DemuxerStream> demuxer_stream_;
- // This is the message loop that we should assign to VideoDecodeEngine.
- MessageLoop* decode_engine_message_loop_;
+ // This is the message loop that we should assign to VideoDecodeContext.
+ MessageLoop* decode_context_message_loop_;
// A context for allocating textures and issuing GLES2 commands.
// TODO(hclam): A ggl::Context lives on the Render Thread while this object
diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc
index bef96f9..a0cdd5f 100644
--- a/chrome/renderer/render_thread.cc
+++ b/chrome/renderer/render_thread.cc
@@ -296,8 +296,6 @@ void RenderThread::Init() {
kPrelauchGpuProcessDelayMS);
}
- GpuVideoServiceHost::get()->OnRendererThreadInit(MessageLoop::current());
-
TRACE_EVENT_END("RenderThread::Init", 0, "");
}
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index b164a39..1e8a533 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -2476,8 +2476,7 @@ WebMediaPlayer* RenderView::createMediaPlayer(
CHECK(ret) << "Failed to switch context";
factory->AddFactory(IpcVideoDecoder::CreateFactory(
- MessageLoop::current(),
- ggl::GetCurrentContext()));
+ MessageLoop::current(), ggl::GetCurrentContext()));
}
WebApplicationCacheHostImpl* appcache_host =