Commit 4c2109d8 authored by vrk@google.com's avatar vrk@google.com

Add initialization callback support for Video Decoder PPAPI.

Initializing a decoder is asynchronous, so add a callback to tell client
when the decoder is ready to use.
I confirmed that this works locally using a C plugin that I wrote on my machine.

BUG=NONE
TEST=NONE

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86699 0039d316-1c4b-4281-b951-d872f2087c98
parent 6e001bbb
......@@ -606,6 +606,9 @@ IPC_MESSAGE_ROUTED3(AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers,
IPC_MESSAGE_ROUTED1(AcceleratedVideoDecoderHostMsg_CreateDone,
int32) /* Decoder ID */
// Notify client that decoder has been initialized.
IPC_MESSAGE_ROUTED0(AcceleratedVideoDecoderHostMsg_InitializeDone)
// Decoder reports that a picture is ready and buffer does not need to be passed
// back to the decoder.
IPC_MESSAGE_ROUTED1(AcceleratedVideoDecoderHostMsg_DismissPictureBuffer,
......
......@@ -173,6 +173,11 @@ void GpuVideoDecodeAccelerator::NotifyEndOfBitstreamBuffer(
}
}
void GpuVideoDecodeAccelerator::NotifyInitializeDone() {
if (!Send(new AcceleratedVideoDecoderHostMsg_InitializeDone(route_id_)))
LOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_InitializeDone) failed";
}
void GpuVideoDecodeAccelerator::NotifyFlushDone() {
if (!Send(new AcceleratedVideoDecoderHostMsg_FlushDone(route_id_)))
LOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_FlushDone) failed";
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_GPU_GPU_VIDEO_DECODE_ACCELERATOR_H_
#define CONTENT_GPU_GPU_VIDEO_DECODE_ACCELERATOR_H_
#ifndef CONTENT_COMMON_GPU_GPU_VIDEO_DECODE_ACCELERATOR_H_
#define CONTENT_COMMON_GPU_GPU_VIDEO_DECODE_ACCELERATOR_H_
#include <vector>
......@@ -34,6 +34,7 @@ class GpuVideoDecodeAccelerator
media::VideoDecodeAccelerator::MemoryType type) OVERRIDE;
virtual void DismissPictureBuffer(int32 picture_buffer_id) OVERRIDE;
virtual void PictureReady(const media::Picture& picture) OVERRIDE;
virtual void NotifyInitializeDone() OVERRIDE;
virtual void NotifyEndOfStream() OVERRIDE;
virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE;
virtual void NotifyEndOfBitstreamBuffer(int32 bitstream_buffer_id) OVERRIDE;
......@@ -77,4 +78,4 @@ class GpuVideoDecodeAccelerator
DISALLOW_IMPLICIT_CONSTRUCTORS(GpuVideoDecodeAccelerator);
};
#endif // CONTENT_GPU_GPU_VIDEO_DECODE_ACCELERATOR_H_
#endif // CONTENT_COMMON_GPU_GPU_VIDEO_DECODE_ACCELERATOR_H_
......@@ -46,6 +46,8 @@ bool GpuVideoDecodeAcceleratorHost::OnMessageReceived(const IPC::Message& msg) {
OnProvidePictureBuffer)
IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderHostMsg_CreateDone,
OnCreateDone)
IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderHostMsg_InitializeDone,
OnInitializeDone)
IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderHostMsg_PictureReady,
OnPictureReady)
IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderHostMsg_FlushDone,
......@@ -175,6 +177,10 @@ void GpuVideoDecodeAcceleratorHost::OnCreateDone(int32 decoder_id) {
}
}
void GpuVideoDecodeAcceleratorHost::OnInitializeDone() {
client_->NotifyInitializeDone();
}
void GpuVideoDecodeAcceleratorHost::OnPictureReady(
int32 picture_buffer_id, int32 bitstream_buffer_id,
const gfx::Size& visible_size, const gfx::Size& decoded_size) {
......
......@@ -53,6 +53,7 @@ class GpuVideoDecodeAcceleratorHost : public IPC::Channel::Listener,
uint32 num_requested_buffers, const gfx::Size& buffer_size, int32 mem_type);
void OnDismissPictureBuffer(int32 picture_buffer_id);
void OnCreateDone(int32 decoder_id);
void OnInitializeDone();
void OnPictureReady(int32 picture_buffer_id,
int32 bitstream_buffer_id,
const gfx::Size& visible_size,
......
......@@ -42,6 +42,7 @@ bool GpuVideoServiceHost::OnMessageReceived(const IPC::Message& msg) {
case AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed::ID:
case AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers::ID:
case AcceleratedVideoDecoderHostMsg_CreateDone::ID:
case AcceleratedVideoDecoderHostMsg_InitializeDone::ID:
case AcceleratedVideoDecoderHostMsg_DismissPictureBuffer::ID:
case AcceleratedVideoDecoderHostMsg_PictureReady::ID:
case AcceleratedVideoDecoderHostMsg_FlushDone::ID:
......
......@@ -51,9 +51,6 @@ bool PlatformVideoDecoderImpl::Initialize(const std::vector<uint32>& config) {
// Set a callback to ensure decoder is only initialized after channel is
// connected and GpuVidoServiceHost message filter is added to channel.
//
// TODO(vrk): Initialize should take a callback to be called (on the
// renderer's thread) when initialization is completed.
base::Closure initialize = base::Bind(
&PlatformVideoDecoderImpl::InitializeDecoder,
base::Unretained(this),
......@@ -139,6 +136,10 @@ void PlatformVideoDecoderImpl::PictureReady(const media::Picture& picture) {
client_->PictureReady(picture);
}
void PlatformVideoDecoderImpl::NotifyInitializeDone() {
client_->NotifyInitializeDone();
}
void PlatformVideoDecoderImpl::NotifyEndOfBitstreamBuffer(
int32 bitstream_buffer_id) {
client_->NotifyEndOfBitstreamBuffer(bitstream_buffer_id);
......
......@@ -45,6 +45,7 @@ class PlatformVideoDecoderImpl
media::VideoDecodeAccelerator::MemoryType type) OVERRIDE;
virtual void PictureReady(const media::Picture& picture) OVERRIDE;
virtual void DismissPictureBuffer(int32 picture_buffer_id) OVERRIDE;
virtual void NotifyInitializeDone() OVERRIDE;
virtual void NotifyEndOfStream() OVERRIDE;
virtual void NotifyError(
media::VideoDecodeAccelerator::Error error) OVERRIDE;
......
......@@ -186,6 +186,9 @@ class VideoDecodeAccelerator {
public:
virtual ~Client() {}
// Callback to notify client that decoder has been initialized.
virtual void NotifyInitializeDone() = 0;
// Callback to tell the information needed by the client to provide decoding
// buffer to the decoder.
virtual void ProvidePictureBuffers(
......
......@@ -9,8 +9,8 @@
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_var.h"
#define PPB_VIDEODECODER_DEV_INTERFACE_0_7 "PPB_VideoDecoder(Dev);0.7"
#define PPB_VIDEODECODER_DEV_INTERFACE PPB_VIDEODECODER_DEV_INTERFACE_0_7
#define PPB_VIDEODECODER_DEV_INTERFACE_0_8 "PPB_VideoDecoder(Dev);0.8"
#define PPB_VIDEODECODER_DEV_INTERFACE PPB_VIDEODECODER_DEV_INTERFACE_0_8
// Video decoder interface.
//
......@@ -131,10 +131,12 @@ struct PPB_VideoDecoder_Dev {
// Parameters:
// |instance| pointer to the plugin instance.
// |dec_config| the configuration which to use to initialize the decoder.
// |callback| called after initialize is complete.
//
// The created decoder is returned as PP_Resource. NULL means failure.
PP_Resource (*Create)(PP_Instance instance,
PP_VideoConfigElement* dec_config);
PP_VideoConfigElement* dec_config,
struct PP_CompletionCallback callback);
// Tests whether |resource| is a video decoder created through Create
// function of this interface.
......
......@@ -26,6 +26,7 @@ template <> const char* interface_name<PPB_VideoDecoder_Dev>() {
VideoDecoder::VideoDecoder(const Instance* /* instance */,
const std::vector<uint32_t>& /* config */,
CompletionCallback /* callback */,
Client* client)
: client_(client) {
if (!has_interface<PPB_VideoDecoder_Dev>())
......
......@@ -54,10 +54,11 @@ class VideoDecoder : public Resource {
// Parameters:
// |instance| is the pointer to the plug-in instance.
// |config| is the configuration on which the decoder should be initialized.
// |callback| will be called when decoder is initialized.
// |client| is the pointer to the client object. Ownership of the object is
// not transferred and it must outlive the lifetime of this class.
VideoDecoder(const Instance* instance, const std::vector<uint32_t>& config,
Client* client);
CompletionCallback callback, Client* client);
~VideoDecoder();
// GetConfigs returns supported configurations that are subsets of given
......
......@@ -29,7 +29,7 @@ void TestVideoDecoder::QuitMessageLoop() {
std::string TestVideoDecoder::TestCreate() {
PP_Resource decoder = video_decoder_interface_->Create(
instance_->pp_instance(), NULL);
instance_->pp_instance(), NULL, PP_MakeCompletionCallback(NULL, NULL));
if (decoder == 0) {
return "Error creating the decoder";
}
......
......@@ -44,7 +44,8 @@ PP_Bool GetConfigs(PP_Instance instance_id,
}
PP_Resource Create(PP_Instance instance_id,
PP_VideoConfigElement* decoder_config) {
PP_VideoConfigElement* decoder_config,
PP_CompletionCallback callback) {
PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return 0;
......@@ -52,8 +53,10 @@ PP_Resource Create(PP_Instance instance_id,
scoped_refptr<PPB_VideoDecoder_Impl> decoder(
new PPB_VideoDecoder_Impl(instance));
if (!decoder->Init(const_cast<PP_VideoConfigElement*>(decoder_config)))
if (!decoder->Init(
const_cast<PP_VideoConfigElement*>(decoder_config), callback)) {
return 0;
}
return decoder->GetReference();
}
......@@ -212,7 +215,8 @@ bool PPB_VideoDecoder_Impl::GetConfigs(
return true;
}
bool PPB_VideoDecoder_Impl::Init(PP_VideoConfigElement* decoder_config) {
bool PPB_VideoDecoder_Impl::Init(PP_VideoConfigElement* decoder_config,
PP_CompletionCallback callback) {
if (!instance())
return false;
......@@ -224,6 +228,8 @@ bool PPB_VideoDecoder_Impl::Init(PP_VideoConfigElement* decoder_config) {
CopyToConfigList(decoder_config, &copied);
platform_video_decoder_->Initialize(copied);
initialization_callback_ = callback;
return platform_video_decoder_.get()? true : false;
}
......@@ -392,6 +398,15 @@ void PPB_VideoDecoder_Impl::NotifyFlushDone() {
PP_RunCompletionCallback(&callback, PP_OK);
}
void PPB_VideoDecoder_Impl::NotifyInitializeDone() {
if (initialization_callback_.func == NULL)
return;
PP_CompletionCallback callback = PP_BlockUntilComplete();
std::swap(callback, initialization_callback_);
PP_RunCompletionCallback(&callback, PP_OK);
}
} // namespace ppapi
} // namespace webkit
......
......@@ -46,7 +46,7 @@ class PPB_VideoDecoder_Impl : public Resource,
PP_VideoConfigElement* matching_configs,
uint32_t matching_configs_size,
uint32_t* num_of_matching_configs);
bool Init(PP_VideoConfigElement* dec_config);
bool Init(PP_VideoConfigElement* dec_config, PP_CompletionCallback callback);
bool Decode(PP_VideoBitstreamBuffer_Dev* bitstream_buffer,
PP_CompletionCallback callback);
void AssignGLESBuffers(uint32_t no_of_buffers,
......@@ -64,6 +64,7 @@ class PPB_VideoDecoder_Impl : public Resource,
media::VideoDecodeAccelerator::MemoryType type) OVERRIDE;
virtual void DismissPictureBuffer(int32 picture_buffer_id) OVERRIDE;
virtual void PictureReady(const media::Picture& picture) OVERRIDE;
virtual void NotifyInitializeDone() OVERRIDE;
virtual void NotifyEndOfStream() OVERRIDE;
virtual void NotifyError(
media::VideoDecodeAccelerator::Error error) OVERRIDE;
......@@ -79,6 +80,7 @@ class PPB_VideoDecoder_Impl : public Resource,
// Factory to produce our callbacks.
base::ScopedCallbackFactory<PPB_VideoDecoder_Impl> callback_factory_;
PP_CompletionCallback initialization_callback_;
PP_CompletionCallback abort_callback_;
PP_CompletionCallback flush_callback_;
PP_CompletionCallback bitstream_buffer_callback_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment