Index: webkit/plugins/ppapi/ppb_video_decoder_impl.cc |
=================================================================== |
--- webkit/plugins/ppapi/ppb_video_decoder_impl.cc (revision 87892) |
+++ webkit/plugins/ppapi/ppb_video_decoder_impl.cc (working copy) |
@@ -44,37 +44,39 @@ |
num_of_matching_configs)); |
} |
-PP_Resource Create(PP_Instance instance_id, |
- const PP_VideoConfigElement* decoder_config, |
- PP_CompletionCallback callback) { |
+PP_Resource Create(PP_Instance instance_id) { |
PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
if (!instance) |
return 0; |
+ PPB_VideoDecoder_Impl* decoder = new PPB_VideoDecoder_Impl(instance); |
+ return decoder->GetReference(); |
+} |
+ |
+int32_t Initialize(PP_Resource video_decoder, |
+ const PP_VideoConfigElement* decoder_config, |
+ struct PP_CompletionCallback callback) { |
scoped_refptr<PPB_VideoDecoder_Impl> decoder( |
- new PPB_VideoDecoder_Impl(instance)); |
+ Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder)); |
+ if (!decoder) |
+ return PP_ERROR_BADRESOURCE; |
- if (!decoder->Init( |
- const_cast<PP_VideoConfigElement*>(decoder_config), callback)) { |
- return 0; |
- } |
- |
- return decoder->GetReference(); |
+ return decoder->Initialize(decoder_config, callback); |
} |
PP_Bool IsVideoDecoder(PP_Resource resource) { |
return BoolToPPBool(!!Resource::GetAs<PPB_VideoDecoder_Impl>(resource)); |
} |
-PP_Bool Decode(PP_Resource decoder_id, |
+int32_t Decode(PP_Resource decoder_id, |
const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, |
PP_CompletionCallback callback) { |
scoped_refptr<PPB_VideoDecoder_Impl> decoder( |
Resource::GetAs<PPB_VideoDecoder_Impl>(decoder_id)); |
if (!decoder) |
- return PP_FALSE; |
+ return PP_ERROR_BADRESOURCE; |
- return BoolToPPBool(decoder->Decode(bitstream_buffer, callback)); |
+ return decoder->Decode(bitstream_buffer, callback); |
} |
void AssignGLESBuffers(PP_Resource video_decoder, |
@@ -108,28 +110,29 @@ |
decoder->ReusePictureBuffer(picture_buffer_id); |
} |
-PP_Bool Flush(PP_Resource video_decoder, PP_CompletionCallback callback) { |
+int32_t Flush(PP_Resource video_decoder, PP_CompletionCallback callback) { |
scoped_refptr<PPB_VideoDecoder_Impl> decoder( |
Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder)); |
if (!decoder) |
- return PP_FALSE; |
+ return PP_ERROR_BADRESOURCE; |
- return BoolToPPBool(decoder->Flush(callback)); |
+ return decoder->Flush(callback); |
} |
-PP_Bool Abort(PP_Resource video_decoder, |
+int32_t Abort(PP_Resource video_decoder, |
PP_CompletionCallback callback) { |
scoped_refptr<PPB_VideoDecoder_Impl> decoder( |
Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder)); |
if (!decoder) |
- return PP_FALSE; |
+ return PP_ERROR_BADRESOURCE; |
- return BoolToPPBool(decoder->Abort(callback)); |
+ return decoder->Abort(callback); |
} |
const PPB_VideoDecoder_Dev ppb_videodecoder = { |
&GetConfigs, |
&Create, |
+ &Initialize, |
&IsVideoDecoder, |
&Decode, |
&AssignGLESBuffers, |
@@ -216,34 +219,41 @@ |
return true; |
} |
-bool PPB_VideoDecoder_Impl::Init(const PP_VideoConfigElement* decoder_config, |
- PP_CompletionCallback callback) { |
+int32_t PPB_VideoDecoder_Impl::Initialize( |
+ const PP_VideoConfigElement* decoder_config, |
+ PP_CompletionCallback callback) { |
+ if (!callback.func) |
+ return PP_ERROR_BADARGUMENT; |
if (!instance()) |
- return false; |
+ return PP_ERROR_FAILED; |
platform_video_decoder_.reset( |
instance()->delegate()->CreateVideoDecoder(this)); |
+ if (!platform_video_decoder_.get()) |
+ return PP_ERROR_FAILED; |
+ |
std::vector<uint32> copied; |
// TODO(vrk): Validate configs before copy. |
CopyToConfigList(decoder_config, &copied); |
- platform_video_decoder_->Initialize(copied); |
- |
- initialization_callback_ = callback; |
- |
- return platform_video_decoder_.get()? true : false; |
+ if (platform_video_decoder_->Initialize(copied)) { |
+ initialization_callback_ = callback; |
+ return PP_OK_COMPLETIONPENDING; |
+ } else { |
+ return PP_ERROR_FAILED; |
+ } |
} |
-bool PPB_VideoDecoder_Impl::Decode( |
+int32_t PPB_VideoDecoder_Impl::Decode( |
const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, |
PP_CompletionCallback callback) { |
if (!platform_video_decoder_.get()) |
- return false; |
+ return PP_ERROR_BADRESOURCE; |
::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_Buffer_API> |
enter(bitstream_buffer->data, true); |
if (enter.failed()) |
- return false; |
+ return PP_ERROR_FAILED; |
PPB_Buffer_Impl* buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); |
media::BitstreamBuffer decode_buffer(bitstream_buffer->id, |
@@ -254,7 +264,10 @@ |
// TODO(vmr): handle simultaneous decodes + callbacks. |
bitstream_buffer_callback_ = callback; |
- return platform_video_decoder_->Decode(decode_buffer); |
+ if (platform_video_decoder_->Decode(decode_buffer)) |
+ return PP_OK_COMPLETIONPENDING; |
+ else |
+ return PP_ERROR_FAILED; |
} |
void PPB_VideoDecoder_Impl::AssignGLESBuffers( |
@@ -293,26 +306,32 @@ |
platform_video_decoder_->ReusePictureBuffer(picture_buffer_id); |
} |
-bool PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) { |
+int32_t PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) { |
if (!platform_video_decoder_.get()) |
- return false; |
+ return PP_ERROR_BADRESOURCE; |
// Store the callback to be called when Flush() is done. |
// TODO(vmr): Check for current flush/abort operations. |
flush_callback_ = callback; |
- return platform_video_decoder_->Flush(); |
+ if (platform_video_decoder_->Flush()) |
+ return PP_OK_COMPLETIONPENDING; |
+ else |
+ return PP_ERROR_FAILED; |
} |
-bool PPB_VideoDecoder_Impl::Abort(PP_CompletionCallback callback) { |
+int32_t PPB_VideoDecoder_Impl::Abort(PP_CompletionCallback callback) { |
if (!platform_video_decoder_.get()) |
- return false; |
+ return PP_ERROR_BADRESOURCE; |
// Store the callback to be called when Abort() is done. |
// TODO(vmr): Check for current flush/abort operations. |
abort_callback_ = callback; |
- return platform_video_decoder_->Abort(); |
+ if (platform_video_decoder_->Abort()) |
+ return PP_OK_COMPLETIONPENDING; |
+ else |
+ return PP_ERROR_FAILED; |
} |
void PPB_VideoDecoder_Impl::ProvidePictureBuffers( |