Index: ppapi/shared_impl/video_decoder_impl.cc |
diff --git a/ppapi/shared_impl/video_decoder_impl.cc b/ppapi/shared_impl/video_decoder_impl.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..30fbfeba14c96266a24a5e6f43d3fe390629502f |
--- /dev/null |
+++ b/ppapi/shared_impl/video_decoder_impl.cc |
@@ -0,0 +1,133 @@ |
+// Copyright (c) 2011 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 "ppapi/shared_impl/video_decoder_impl.h" |
+ |
+#include "base/logging.h" |
+#include "gpu/command_buffer/client/gles2_implementation.h" |
+#include "ppapi/c/pp_errors.h" |
+#include "ppapi/proxy/plugin_resource_tracker.h" |
+#include "ppapi/thunk/ppb_context_3d_api.h" |
+#include "ppapi/thunk/enter.h" |
+#include "webkit/plugins/ppapi/resource_tracker.h" |
+ |
+using ppapi::thunk::PPB_Context3D_API; |
+ |
+namespace ppapi { |
+ |
+VideoDecoderImpl::VideoDecoderImpl(bool in_renderer_process) |
+ : context3d_id_(0), |
+ in_renderer_process_(in_renderer_process), |
+ gles2_impl_(NULL) { |
+} |
+ |
+thunk::PPB_VideoDecoder_API* VideoDecoderImpl::AsPPB_VideoDecoder_API() { |
+ return this; |
+} |
+ |
+VideoDecoderImpl::~VideoDecoderImpl() { |
+} |
+ |
+bool VideoDecoderImpl::Init(PP_Resource context3d_id, |
+ const PP_VideoConfigElement* decoder_config) { |
+ if (!context3d_id || !decoder_config) |
+ return false; |
+ |
+ ppapi::thunk::EnterResourceNoLock<PPB_Context3D_API> |
+ enter_context(context3d_id, true); |
+ if (!enter_context.succeeded()) |
+ return false; |
+ SetGLES2Impl(enter_context.object()->GetGLES2Impl()); |
+ |
+ AddRefResource(context3d_id); |
+ context3d_id_ = context3d_id; |
+ return true; |
+} |
+ |
+void VideoDecoderImpl::Destroy() { |
+ context3d_id_ = 0; |
+ gles2_impl_ = NULL; |
+ UnrefResource(context3d_id_); |
+} |
+ |
+void VideoDecoderImpl::SetFlushCallback(PP_CompletionCallback callback) { |
+ flush_callback_ = callback; |
+} |
+ |
+void VideoDecoderImpl::SetResetCallback(PP_CompletionCallback callback) { |
+ reset_callback_ = callback; |
+} |
+ |
+void VideoDecoderImpl::AddBitstreamBufferCallback( |
+ int32 bitstream_buffer_id, PP_CompletionCallback callback) { |
+ DCHECK(bitstream_buffer_callbacks_.insert( |
piman
2011/08/02 00:40:08
DCHECK(side effect) ??
Very bad idea... The side e
vrk (LEFT CHROMIUM)
2011/08/03 19:04:31
Yeaaaaah, was supposed to be a CHECK, not a DCHECK
|
+ std::make_pair(bitstream_buffer_id, callback)).second); |
+} |
+ |
+void VideoDecoderImpl::RunFlushCallback() { |
+ if (flush_callback_.func != NULL) |
+ PP_RunAndClearCompletionCallback(&flush_callback_, PP_OK); |
+} |
+ |
+void VideoDecoderImpl::RunResetCallback() { |
+ if (reset_callback_.func != NULL) |
+ PP_RunAndClearCompletionCallback(&reset_callback_, PP_OK); |
+} |
+ |
+void VideoDecoderImpl::RunBitstreamBufferCallback(int32 bitstream_buffer_id) { |
+ CallbackById::iterator it = |
+ bitstream_buffer_callbacks_.find(bitstream_buffer_id); |
+ DCHECK(it != bitstream_buffer_callbacks_.end()); |
+ PP_CompletionCallback cc = it->second; |
+ bitstream_buffer_callbacks_.erase(it); |
+ PP_RunCompletionCallback(&cc, PP_OK); |
+} |
+ |
+void VideoDecoderImpl::FlushCommandBuffer() { |
+ if (gles2_impl_) |
+ gles2_impl_->Flush(); |
+} |
+ |
+bool VideoDecoderImpl::CopyConfigsToVector( |
+ const PP_VideoConfigElement* configs_to_copy, |
+ std::vector<int32>* out_configs) { |
+ // TODO(vrk): This is assuming PP_VideoAttributeDictionary and |
+ // VideoAttributeKey have identical enum values. There is no compiler |
+ // assert to guarantee this. We either need to add such asserts or |
+ // merge PP_VideoAttributeDictionary and VideoAttributeKey. |
piman
2011/08/02 00:40:08
You can add COMPILE_ASSERT for those.
vrk (LEFT CHROMIUM)
2011/08/03 19:04:31
Moved this comment to PPB_VideoDecoder_Impl::Creat
|
+ const PP_VideoConfigElement* current = configs_to_copy; |
+ while (current && *current != PP_VIDEOATTR_DICTIONARY_TERMINATOR) { |
+ if (!(current + 1)) |
+ return false; |
+ |
+ out_configs->push_back(static_cast<int32>(*current)); |
piman
2011/08/02 00:40:08
Is the static_cast needed ? enums should cast impl
vrk (LEFT CHROMIUM)
2011/08/03 19:04:31
Done.
|
+ out_configs->push_back(static_cast<int32>(*(current + 1))); |
+ current += 2; |
+ } |
+ return true; |
+} |
+ |
+void VideoDecoderImpl::SetGLES2Impl( |
+ gpu::gles2::GLES2Implementation* gles2_impl) { |
+ DCHECK(!gles2_impl_); |
+ gles2_impl_ = gles2_impl; |
+} |
+ |
+void VideoDecoderImpl::AddRefResource(PP_Resource resource) { |
+ if (in_renderer_process_) |
+ ::webkit::ppapi::ResourceTracker::Get()->AddRefResource(resource); |
+ else |
+ ::pp::proxy::PluginResourceTracker::GetInstance()->AddRefResource(resource); |
piman
2011/08/02 00:40:08
That sort of logic is kinda bad. Why not pass the
vrk (LEFT CHROMIUM)
2011/08/03 19:04:31
Originally that is what I intended to do, but then
|
+} |
+ |
+void VideoDecoderImpl::UnrefResource(PP_Resource resource) { |
+ if (in_renderer_process_) { |
+ ::webkit::ppapi::ResourceTracker::Get()->UnrefResource(resource); |
+ } else { |
+ ::pp::proxy::PluginResourceTracker:: |
+ GetInstance()->ReleaseResource(resource); |
+ } |
+} |
+ |
+} // namespace ppapi |