OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ppapi/proxy/video_reader_resource.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "ipc/ipc_message.h" |
| 9 #include "ppapi/c/pp_errors.h" |
| 10 #include "ppapi/c/pp_video_frame.h" |
| 11 #include "ppapi/proxy/ppapi_messages.h" |
| 12 #include "ppapi/shared_impl/array_writer.h" |
| 13 #include "ppapi/shared_impl/ppapi_globals.h" |
| 14 #include "ppapi/shared_impl/resource_tracker.h" |
| 15 #include "ppapi/shared_impl/var.h" |
| 16 #include "ppapi/thunk/enter.h" |
| 17 |
| 18 using ppapi::thunk::EnterResourceNoLock; |
| 19 using ppapi::thunk::PPB_VideoReader_API; |
| 20 |
| 21 namespace { |
| 22 |
| 23 } // namespace |
| 24 |
| 25 namespace ppapi { |
| 26 namespace proxy { |
| 27 |
| 28 VideoReaderResource::VideoReaderResource( |
| 29 Connection connection, |
| 30 PP_Instance instance) |
| 31 : PluginResource(connection, instance) { |
| 32 SendCreate(RENDERER, PpapiHostMsg_VideoReader_Create()); |
| 33 } |
| 34 |
| 35 VideoReaderResource::~VideoReaderResource() { |
| 36 } |
| 37 |
| 38 PPB_VideoReader_API* VideoReaderResource::AsPPB_VideoReader_API() { |
| 39 return this; |
| 40 } |
| 41 |
| 42 int32_t VideoReaderResource::Open( |
| 43 PP_Var stream_id, |
| 44 scoped_refptr<TrackedCallback> callback) { |
| 45 scoped_refptr<StringVar> stream_id_var = StringVar::FromPPVar(stream_id); |
| 46 const uint32_t kMaxStreamIdSizeInBytes = 16384; |
| 47 if (!stream_id_var || stream_id_var->value().size() > kMaxStreamIdSizeInBytes) |
| 48 return PP_ERROR_BADARGUMENT; |
| 49 Call<PpapiPluginMsg_VideoReader_OpenReply>(RENDERER, |
| 50 PpapiHostMsg_VideoReader_Open(stream_id_var->value()), |
| 51 base::Bind(&VideoReaderResource::OnPluginMsgOpenComplete, this, |
| 52 callback)); |
| 53 return PP_OK_COMPLETIONPENDING; |
| 54 } |
| 55 |
| 56 int32_t VideoReaderResource::GetFrame( |
| 57 PP_VideoFrame* frame, |
| 58 scoped_refptr<TrackedCallback> callback) { |
| 59 Call<PpapiPluginMsg_VideoReader_GetFrameReply>(RENDERER, |
| 60 PpapiHostMsg_VideoReader_GetFrame(), |
| 61 base::Bind(&VideoReaderResource::OnPluginMsgGetFrameComplete, this, |
| 62 callback, frame)); |
| 63 return PP_OK_COMPLETIONPENDING; |
| 64 } |
| 65 |
| 66 void VideoReaderResource::Close() { |
| 67 Post(RENDERER, PpapiHostMsg_VideoReader_Close()); |
| 68 } |
| 69 |
| 70 void VideoReaderResource::OnPluginMsgOpenComplete( |
| 71 scoped_refptr<TrackedCallback> callback, |
| 72 const ResourceMessageReplyParams& params) { |
| 73 int32_t result = params.result(); |
| 74 callback->Run(result); |
| 75 } |
| 76 |
| 77 void VideoReaderResource::OnPluginMsgGetFrameComplete( |
| 78 scoped_refptr<TrackedCallback> callback, |
| 79 PP_VideoFrame* frame, |
| 80 const ResourceMessageReplyParams& params, |
| 81 const HostResource& image_data, |
| 82 double timestamp) { |
| 83 int32_t result = params.result(); |
| 84 if (result == PP_OK) { |
| 85 frame->timestamp = static_cast<PP_TimeTicks>(timestamp); |
| 86 frame->image_data = image_data.host_resource(); |
| 87 } |
| 88 |
| 89 callback->Run(result); |
| 90 } |
| 91 |
| 92 } // namespace proxy |
| 93 } // namespace ppapi |
OLD | NEW |