Index: ppapi/proxy/video_source_resource.cc |
diff --git a/ppapi/proxy/video_source_resource.cc b/ppapi/proxy/video_source_resource.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1bdb544c9a6802d90208cc8be18733d2f5d3908a |
--- /dev/null |
+++ b/ppapi/proxy/video_source_resource.cc |
@@ -0,0 +1,95 @@ |
+// 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_source_resource.h" |
+ |
+#include "base/bind.h" |
+#include "ipc/ipc_message.h" |
+#include "ppapi/c/pp_errors.h" |
+#include "ppapi/c/private/pp_video_frame_private.h" |
+#include "ppapi/proxy/ppapi_messages.h" |
+#include "ppapi/shared_impl/array_writer.h" |
yzshen1
2013/05/01 23:18:33
this is not needed.
bbudge
2013/05/02 21:39:06
Done.
|
+#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_VideoSource_Private_API; |
+ |
+namespace { |
yzshen1
2013/05/01 23:18:33
this is not needed.
bbudge
2013/05/02 21:39:06
Done.
|
+ |
+} // namespace |
+ |
+namespace ppapi { |
+namespace proxy { |
+ |
+VideoSourceResource::VideoSourceResource( |
+ Connection connection, |
+ PP_Instance instance) |
+ : PluginResource(connection, instance) { |
+ SendCreate(RENDERER, PpapiHostMsg_VideoSource_Create()); |
+} |
+ |
+VideoSourceResource::~VideoSourceResource() { |
+} |
+ |
+PPB_VideoSource_Private_API* |
+ VideoSourceResource::AsPPB_VideoSource_Private_API() { |
+ return this; |
+} |
+ |
+int32_t VideoSourceResource::Open( |
+ PP_Var stream_url, |
+ scoped_refptr<TrackedCallback> callback) { |
+ scoped_refptr<StringVar> stream_url_var = StringVar::FromPPVar(stream_url); |
+ const uint32_t kMaxStreamIdSizeInBytes = 16384; |
+ if (!stream_url_var || |
+ stream_url_var->value().size() > kMaxStreamIdSizeInBytes) |
+ return PP_ERROR_BADARGUMENT; |
+ Call<PpapiPluginMsg_VideoSource_OpenReply>(RENDERER, |
+ PpapiHostMsg_VideoSource_Open(stream_url_var->value()), |
+ base::Bind(&VideoSourceResource::OnPluginMsgOpenComplete, this, |
+ callback)); |
+ return PP_OK_COMPLETIONPENDING; |
+} |
+ |
+int32_t VideoSourceResource::GetFrame( |
+ PP_VideoFrame_Private* frame, |
+ scoped_refptr<TrackedCallback> callback) { |
+ Call<PpapiPluginMsg_VideoSource_GetFrameReply>(RENDERER, |
+ PpapiHostMsg_VideoSource_GetFrame(), |
+ base::Bind(&VideoSourceResource::OnPluginMsgGetFrameComplete, this, |
+ callback, frame)); |
+ return PP_OK_COMPLETIONPENDING; |
+} |
+ |
+void VideoSourceResource::Close() { |
+ Post(RENDERER, PpapiHostMsg_VideoSource_Close()); |
+} |
+ |
+void VideoSourceResource::OnPluginMsgOpenComplete( |
+ scoped_refptr<TrackedCallback> callback, |
+ const ResourceMessageReplyParams& params) { |
+ int32_t result = params.result(); |
+ callback->Run(result); |
+} |
+ |
+void VideoSourceResource::OnPluginMsgGetFrameComplete( |
+ scoped_refptr<TrackedCallback> callback, |
+ PP_VideoFrame_Private* frame, |
+ const ResourceMessageReplyParams& params, |
+ const HostResource& image_data, |
+ double timestamp) { |
+ int32_t result = params.result(); |
yzshen1
2013/05/01 23:18:33
We need to test whether the callback is still pend
bbudge
2013/05/02 21:39:06
Done. I redid the whole callback setup for both re
|
+ if (result == PP_OK) { |
+ frame->timestamp = static_cast<PP_TimeTicks>(timestamp); |
+ frame->image_data = image_data.host_resource(); |
+ } |
+ |
+ callback->Run(result); |
+} |
+ |
+} // namespace proxy |
+} // namespace ppapi |