Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Unified Diff: ppapi/shared_impl/video_decoder_impl.cc

Issue 7545014: Implement PPAPI VideoDecode out-of-process support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..e4c08f75fd0d68dd3acc99ba3d06700c6b29c7eb
--- /dev/null
+++ b/ppapi/shared_impl/video_decoder_impl.cc
@@ -0,0 +1,127 @@
+// 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"
brettw 2011/08/03 19:19:57 The point of the shared_impl directory is that it'
vrk (LEFT CHROMIUM) 2011/08/03 22:05:22 Using the pure virtual methods instead and DEPS re
+
+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,
+ PPB_Context3D_API* context3d,
+ const PP_VideoConfigElement* decoder_config) {
+ if (!context3d || !decoder_config || !context3d_id)
+ return false;
+
+ DCHECK(!gles2_impl_ && !context3d_id_);
+ gles2_impl_ = context3d->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) {
+ // TODO(fischman,vrk): consider implications of already-outstanding callback.
Ami GONE FROM CHROMIUM 2011/08/03 20:25:53 Instead of future-considering it would you accept
vrk (LEFT CHROMIUM) 2011/08/03 22:05:22 SGTM. Done!
+ CHECK(callback.func);
+ flush_callback_ = callback;
+}
+
+void VideoDecoderImpl::SetResetCallback(PP_CompletionCallback callback) {
+ // TODO(fischman,vrk): consider implications of already-outstanding callback.
+ CHECK(callback.func);
+ reset_callback_ = callback;
+}
+
+void VideoDecoderImpl::SetBitstreamBufferCallback(
+ int32 bitstream_buffer_id, PP_CompletionCallback callback) {
+ CHECK(bitstream_buffer_callbacks_.insert(
+ std::make_pair(bitstream_buffer_id, callback)).second);
+}
+
+void VideoDecoderImpl::RunFlushCallback(int32 result) {
+ DCHECK(flush_callback_.func);
+ PP_RunAndClearCompletionCallback(&flush_callback_, result);
+}
+
+void VideoDecoderImpl::RunResetCallback(int32 result) {
+ DCHECK(reset_callback_.func);
+ PP_RunAndClearCompletionCallback(&reset_callback_, result);
+}
+
+void VideoDecoderImpl::RunBitstreamBufferCallback(
+ int32 bitstream_buffer_id, int32 result) {
+ 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<PP_VideoConfigElement>* out_configs) {
+ // TODO(fischman/vrk): This is still broken. We need to get rid of the silly
+ // PP_VideoConfigElement vector in favor of a struct (see TODO in
+ // ppb_video_decoder_dev.h).
+ const PP_VideoConfigElement* current = configs_to_copy;
+ while (*current && *current != PP_VIDEOATTR_DICTIONARY_TERMINATOR) {
Ami GONE FROM CHROMIUM 2011/08/03 20:25:53 The first *current isn't useful. You want either
vrk (LEFT CHROMIUM) 2011/08/03 22:05:22 Dang it now I'm adding stars to everything!! Must
+ if (*(current + 1) == PP_VIDEOATTR_DICTIONARY_TERMINATOR)
Ami GONE FROM CHROMIUM 2011/08/03 20:25:53 No, I think you want to drop this test entirely.
vrk (LEFT CHROMIUM) 2011/08/03 22:05:22 Hahaha yeah. Removed.
+ return false;
+ out_configs->push_back(*current);
+ out_configs->push_back(*(current + 1));
+ current += 2;
+ }
+ return true;
+}
+
+void VideoDecoderImpl::AddRefResource(PP_Resource resource) {
+ if (in_renderer_process_)
+ ::webkit::ppapi::ResourceTracker::Get()->AddRefResource(resource);
+ else
+ ::pp::proxy::PluginResourceTracker::GetInstance()->AddRefResource(resource);
+}
+
+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

Powered by Google App Engine
This is Rietveld 408576698