Index: ppapi/proxy/video_writer_resource.cc |
diff --git a/ppapi/proxy/video_writer_resource.cc b/ppapi/proxy/video_writer_resource.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9ff6cca74d8ac940e790685dba667cf5219fd356 |
--- /dev/null |
+++ b/ppapi/proxy/video_writer_resource.cc |
@@ -0,0 +1,81 @@ |
+// Copyright (c) 2013 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/proxy/video_writer_resource.h" |
+ |
+#include "base/bind.h" |
+#include "ipc/ipc_message.h" |
+#include "ppapi/c/pp_errors.h" |
+#include "ppapi/c/pp_video_frame.h" |
+#include "ppapi/proxy/ppapi_messages.h" |
+#include "ppapi/shared_impl/array_writer.h" |
+#include "ppapi/shared_impl/ppapi_globals.h" |
+#include "ppapi/shared_impl/resource_tracker.h" |
+#include "ppapi/shared_impl/var.h" |
+#include "ppapi/thunk/enter.h" |
+ |
+using ppapi::thunk::EnterResourceNoLock; |
+using ppapi::thunk::PPB_VideoWriter_API; |
+ |
+namespace { |
+ |
+} // namespace |
+ |
+namespace ppapi { |
+namespace proxy { |
+ |
+VideoWriterResource::VideoWriterResource( |
+ Connection connection, |
+ PP_Instance instance) |
+ : PluginResource(connection, instance) { |
+ SendCreate(RENDERER, PpapiHostMsg_VideoWriter_Create()); |
+} |
+ |
+VideoWriterResource::~VideoWriterResource() { |
+} |
+ |
+PPB_VideoWriter_API* VideoWriterResource::AsPPB_VideoWriter_API() { |
+ return this; |
+} |
+ |
+int32_t VideoWriterResource::Open( |
+ PP_Var* stream_id, |
+ scoped_refptr<TrackedCallback> callback) { |
+ Call<PpapiPluginMsg_VideoWriter_OpenReply>(RENDERER, |
+ PpapiHostMsg_VideoWriter_Open(), |
+ base::Bind(&VideoWriterResource::OnPluginMsgOpenComplete, this, |
+ stream_id, callback)); |
+ return PP_OK_COMPLETIONPENDING; |
+} |
+ |
+int32_t VideoWriterResource::PutFrame(const PP_VideoFrame& frame) { |
+ Resource* image_object = |
+ PpapiGlobals::Get()->GetResourceTracker()->GetResource(frame.image_data); |
+ if (!image_object || pp_instance() != image_object->pp_instance()) { |
+ Log(PP_LOGLEVEL_ERROR, |
+ "VideoWriterResource.PutFrame: Bad image resource."); |
+ return PP_ERROR_BADARGUMENT; |
+ } |
+ Post(RENDERER, |
+ PpapiHostMsg_VideoWriter_PutFrame(image_object->host_resource(), |
+ frame.timestamp)); |
+ return PP_OK; |
+} |
+ |
+void VideoWriterResource::Close() { |
+ Post(RENDERER, PpapiHostMsg_VideoWriter_Close()); |
+} |
+ |
+void VideoWriterResource::OnPluginMsgOpenComplete( |
+ PP_Var* pp_stream_id, |
+ scoped_refptr<TrackedCallback> callback, |
+ const ResourceMessageReplyParams& params, |
+ const std::string& stream_id) { |
+ int32_t result = params.result(); |
+ *pp_stream_id = StringVar::StringToPPVar(stream_id); |
+ callback->Run(result); |
+} |
+ |
+} // namespace proxy |
+} // namespace ppapi |