Skip to content

Commit

Permalink
Resubmit - Some cleanup work in GpuVideoDecoderHost and IpcVideoDecoder
Browse files Browse the repository at this point in the history
TBR=sergeyu

BUG=None.
TEST=None.

Review URL: http://codereview.chromium.org/3571007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60959 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
hclam@chromium.org committed Sep 29, 2010
1 parent 9cb851f commit 3190f36
Show file tree
Hide file tree
Showing 11 changed files with 299 additions and 445 deletions.
4 changes: 0 additions & 4 deletions chrome/common/gpu_messages.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@

#if defined(OS_MACOSX)

// TODO(hclam): This is a dummy comment just to get Mac build bots to pick
// up changes to gpu_messages_internal.h. Remove me after it builds
// correctly.

// Parameters for the GpuHostMsg_AcceleratedSurfaceSetIOSurface
// message, which has too many parameters to be sent with the
// predefined IPC macros.
Expand Down
24 changes: 20 additions & 4 deletions chrome/renderer/ggl/ggl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "chrome/renderer/ggl/ggl.h"
#include "chrome/renderer/gpu_channel_host.h"
#include "chrome/renderer/gpu_video_service_host.h"
#include "chrome/renderer/media/gles2_video_decode_context.h"
#include "chrome/renderer/render_thread.h"
#include "chrome/renderer/render_widget.h"
#include "ipc/ipc_channel_handle.h"

Expand Down Expand Up @@ -99,7 +101,10 @@ class Context : public base::SupportsWeakPtr<Context> {
bool SwapBuffers();

// Create a hardware accelerated video decoder associated with this context.
GpuVideoDecoderHost* CreateVideoDecoder();
media::VideoDecodeEngine* CreateVideoDecodeEngine();

// Create a hardware video decode context associated with this context.
media::VideoDecodeContext* CreateVideoDecodeContext(bool hardware_decoder);

// Get the current error code.
Error GetError();
Expand Down Expand Up @@ -324,11 +329,17 @@ bool Context::SwapBuffers() {
return true;
}

GpuVideoDecoderHost* Context::CreateVideoDecoder() {
media::VideoDecodeEngine* Context::CreateVideoDecodeEngine() {
return GpuVideoServiceHost::get()->CreateVideoDecoder(
command_buffer_->route_id());
}

media::VideoDecodeContext* Context::CreateVideoDecodeContext(
bool hardware_decoder) {
return new Gles2VideoDecodeContext(
RenderThread::current()->message_loop(), hardware_decoder, this);
}

Error Context::GetError() {
gpu::CommandBuffer::State state = command_buffer_->GetState();
if (state.error == gpu::error::kNoError) {
Expand Down Expand Up @@ -465,8 +476,13 @@ bool DestroyContext(Context* context) {
#endif
}

GpuVideoDecoderHost* CreateVideoDecoder(Context* context) {
return context->CreateVideoDecoder();
media::VideoDecodeEngine* CreateVideoDecodeEngine(Context* context) {
return context->CreateVideoDecodeEngine();
}

media::VideoDecodeContext* CreateVideoDecodeContext(
Context* context, bool hardware_decoder) {
return context->CreateVideoDecodeContext(hardware_decoder);
}

Error GetError() {
Expand Down
20 changes: 17 additions & 3 deletions chrome/renderer/ggl/ggl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
#include "gfx/size.h"

class GpuChannelHost;
class GpuVideoDecoderHost;

namespace media {

class VideoDecodeContext;
class VideoDecodeEngine;

}

namespace ggl {

Expand Down Expand Up @@ -115,8 +121,16 @@ bool SwapBuffers(Context* context);
// Destroy the given GGL context.
bool DestroyContext(Context* context);

// Create a hardware video decoder corresponding to the context.
GpuVideoDecoderHost* CreateVideoDecoder(Context* context);
// Create a hardware video decode engine corresponding to the context.
media::VideoDecodeEngine* CreateVideoDecodeEngine(Context* context);

// Create a hardware video decode context to pair with the hardware video
// decode engine. It can also be used with a software decode engine.
//
// Set |hardware_decoder| to true if this context is for a hardware video
// engine.
media::VideoDecodeContext* CreateVideoDecodeContext(Context* context,
bool hardware_decoder);

// TODO(gman): Remove this
void DisableShaderTranslation(Context* context);
Expand Down
101 changes: 56 additions & 45 deletions chrome/renderer/gpu_video_decoder_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
#include "chrome/renderer/render_thread.h"

GpuVideoDecoderHost::GpuVideoDecoderHost(GpuVideoServiceHost* service_host,
GpuChannelHost* channel_host,
IPC::Message::Sender* ipc_sender,
int context_route_id)
: gpu_video_service_host_(service_host),
channel_host_(channel_host),
ipc_sender_(ipc_sender),
context_route_id_(context_route_id),
event_handler_(NULL),
buffer_id_serial_(0),
state_(kStateUninitialized),
input_buffer_busy_(false) {
memset(&init_param_, 0, sizeof(init_param_));
memset(&config_, 0, sizeof(config_));
memset(&done_param_, 0, sizeof(done_param_));
}

void GpuVideoDecoderHost::OnChannelError() {
channel_host_ = NULL;
ipc_sender_ = NULL;
}

void GpuVideoDecoderHost::OnMessageReceived(const IPC::Message& msg) {
Expand All @@ -42,48 +42,44 @@ void GpuVideoDecoderHost::OnMessageReceived(const IPC::Message& msg) {
IPC_END_MESSAGE_MAP()
}

bool GpuVideoDecoderHost::Initialize(EventHandler* event_handler,
const GpuVideoDecoderInitParam& param) {
void GpuVideoDecoderHost::Initialize(
MessageLoop* message_loop, VideoDecodeEngine::EventHandler* event_handler,
media::VideoDecodeContext* context, const media::VideoCodecConfig& config) {
// TODO(hclam): Call |event_handler| here.
DCHECK_EQ(state_, kStateUninitialized);

// Save the event handler before we perform initialization operations so
// that we can report initialization events.
event_handler_ = event_handler;

// TODO(hclam): Pass the context route ID here.
// TODO(hclam): This create video decoder operation is synchronous, need to
// make it asynchronous.
decoder_info_.context_id = context_route_id_;
if (!channel_host_->Send(
if (!ipc_sender_->Send(
new GpuChannelMsg_CreateVideoDecoder(&decoder_info_))) {
LOG(ERROR) << "GpuChannelMsg_CreateVideoDecoder failed";
return false;
return;
}

// Add the route so we'll receive messages.
gpu_video_service_host_->AddRoute(my_route_id(), this);

init_param_ = param;
if (!channel_host_ || !channel_host_->Send(
// Save the configuration parameters.
config_ = config;

// TODO(hclam): Initialize |param| with the right values.
GpuVideoDecoderInitParam param;
param.width = config.width;
param.height = config.height;

if (!ipc_sender_ || !ipc_sender_->Send(
new GpuVideoDecoderMsg_Initialize(route_id(), param))) {
LOG(ERROR) << "GpuVideoDecoderMsg_Initialize failed";
return false;
}
return true;
}

bool GpuVideoDecoderHost::Uninitialize() {
if (!channel_host_ || !channel_host_->Send(
new GpuVideoDecoderMsg_Destroy(route_id()))) {
LOG(ERROR) << "GpuVideoDecoderMsg_Destroy failed";
return false;
return;
}

gpu_video_service_host_->RemoveRoute(my_route_id());
return true;
}

void GpuVideoDecoderHost::EmptyThisBuffer(scoped_refptr<Buffer> buffer) {
void GpuVideoDecoderHost::ConsumeVideoSample(scoped_refptr<Buffer> buffer) {
DCHECK_NE(state_, kStateUninitialized);
DCHECK_NE(state_, kStateFlushing);

Expand All @@ -96,7 +92,7 @@ void GpuVideoDecoderHost::EmptyThisBuffer(scoped_refptr<Buffer> buffer) {
SendInputBufferToGpu();
}

void GpuVideoDecoderHost::FillThisBuffer(scoped_refptr<VideoFrame> frame) {
void GpuVideoDecoderHost::ProduceVideoFrame(scoped_refptr<VideoFrame> frame) {
DCHECK_NE(state_, kStateUninitialized);

// Depends on who provides buffer. client could return buffer to
Expand All @@ -109,19 +105,34 @@ void GpuVideoDecoderHost::FillThisBuffer(scoped_refptr<VideoFrame> frame) {
// This eliminates one conversion step.
}

bool GpuVideoDecoderHost::Flush() {
void GpuVideoDecoderHost::Uninitialize() {
if (!ipc_sender_ || !ipc_sender_->Send(
new GpuVideoDecoderMsg_Destroy(route_id()))) {
LOG(ERROR) << "GpuVideoDecoderMsg_Destroy failed";
return;
}

gpu_video_service_host_->RemoveRoute(my_route_id());
return;
}

void GpuVideoDecoderHost::Flush() {
state_ = kStateFlushing;
if (!channel_host_ || !channel_host_->Send(
if (!ipc_sender_ || !ipc_sender_->Send(
new GpuVideoDecoderMsg_Flush(route_id()))) {
LOG(ERROR) << "GpuVideoDecoderMsg_Flush failed";
return false;
return;
}
input_buffer_queue_.clear();
// TODO(jiesun): because GpuVideoDeocder/GpuVideoDecoder are asynchronously.
// We need a way to make flush logic more clear. but I think ring buffer
// should make the busy flag obsolete, therefore I will leave it for now.
input_buffer_busy_ = false;
return true;
return;
}

void GpuVideoDecoderHost::Seek() {
// TODO(hclam): Implement.
}

void GpuVideoDecoderHost::OnInitializeDone(
Expand All @@ -144,23 +155,29 @@ void GpuVideoDecoderHost::OnInitializeDone(
} while (0);

state_ = success ? kStateNormal : kStateError;
event_handler_->OnInitializeDone(success, param);

media::VideoCodecInfo info;
info.success = success;
// TODO(hclam): There's too many unnecessary copies for width and height!
// Need to clean it up.
// TODO(hclam): Need to fill in more information.
info.stream_info.surface_width = config_.width;
info.stream_info.surface_height = config_.height;
event_handler_->OnInitializeComplete(info);
}

void GpuVideoDecoderHost::OnUninitializeDone() {
input_transfer_buffer_.reset();

event_handler_->OnUninitializeDone();
event_handler_->OnUninitializeComplete();
}

void GpuVideoDecoderHost::OnFlushDone() {
state_ = kStateNormal;
event_handler_->OnFlushDone();
event_handler_->OnFlushComplete();
}

void GpuVideoDecoderHost::OnEmptyThisBufferDone() {
scoped_refptr<Buffer> buffer;
event_handler_->OnEmptyBufferDone(buffer);
event_handler_->ProduceVideoSample(NULL);
}

void GpuVideoDecoderHost::OnConsumeVideoFrame(int32 frame_id, int64 timestamp,
Expand All @@ -171,16 +188,10 @@ void GpuVideoDecoderHost::OnConsumeVideoFrame(int32 frame_id, int64 timestamp,
VideoFrame::CreateEmptyFrame(&frame);
} else {
// TODO(hclam): Use |frame_id| to find the VideoFrame.
VideoFrame::GlTexture textures[3] = { 0, 0, 0 };
media::VideoFrame::CreateFrameGlTexture(
media::VideoFrame::RGBA, init_param_.width, init_param_.height,
textures,
base::TimeDelta::FromMicroseconds(timestamp),
base::TimeDelta::FromMicroseconds(duration),
&frame);
}

event_handler_->OnFillBufferDone(frame);
// TODO(hclam): Call the event handler.
event_handler_->ConsumeVideoFrame(frame);
}

void GpuVideoDecoderHost::OnEmptyThisBufferACK() {
Expand All @@ -204,7 +215,7 @@ void GpuVideoDecoderHost::SendInputBufferToGpu() {
param.size = buffer->GetDataSize();
param.timestamp = buffer->GetTimestamp().InMicroseconds();
memcpy(input_transfer_buffer_->memory(), buffer->GetData(), param.size);
if (!channel_host_ || !channel_host_->Send(
if (!ipc_sender_ || !ipc_sender_->Send(
new GpuVideoDecoderMsg_EmptyThisBuffer(route_id(), param))) {
LOG(ERROR) << "GpuVideoDecoderMsg_EmptyThisBuffer failed";
}
Expand Down
Loading

0 comments on commit 3190f36

Please sign in to comment.