Chromium Code Reviews| 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_source_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/private/pp_video_frame_private.h" | |
| 11 #include "ppapi/proxy/ppapi_messages.h" | |
| 12 #include "ppapi/shared_impl/ppapi_globals.h" | |
| 13 #include "ppapi/shared_impl/resource_tracker.h" | |
| 14 #include "ppapi/thunk/enter.h" | |
| 15 | |
| 16 using ppapi::thunk::EnterResourceNoLock; | |
| 17 using ppapi::thunk::PPB_VideoSource_Private_API; | |
| 18 | |
| 19 namespace ppapi { | |
| 20 namespace proxy { | |
| 21 | |
| 22 VideoSourceResource::VideoSourceResource( | |
| 23 Connection connection, | |
| 24 PP_Instance instance) | |
| 25 : PluginResource(connection, instance), | |
| 26 is_open_(false) { | |
| 27 SendCreate(RENDERER, PpapiHostMsg_VideoSource_Create()); | |
| 28 } | |
| 29 | |
| 30 VideoSourceResource::~VideoSourceResource() { | |
| 31 } | |
| 32 | |
| 33 PPB_VideoSource_Private_API* | |
| 34 VideoSourceResource::AsPPB_VideoSource_Private_API() { | |
| 35 return this; | |
| 36 } | |
| 37 | |
| 38 int32_t VideoSourceResource::Open( | |
| 39 const PP_Var& stream_url, | |
| 40 scoped_refptr<TrackedCallback> callback) { | |
| 41 if (TrackedCallback::IsPending(open_callback_)) | |
| 42 return PP_ERROR_INPROGRESS; | |
| 43 | |
| 44 open_callback_ = callback; | |
| 45 | |
| 46 scoped_refptr<StringVar> stream_url_var = StringVar::FromPPVar(stream_url); | |
| 47 const uint32_t kMaxStreamIdSizeInBytes = 16384; | |
| 48 if (!stream_url_var || | |
| 49 stream_url_var->value().size() > kMaxStreamIdSizeInBytes) | |
| 50 return PP_ERROR_BADARGUMENT; | |
| 51 Call<PpapiPluginMsg_VideoSource_OpenReply>(RENDERER, | |
| 52 PpapiHostMsg_VideoSource_Open(stream_url_var->value()), | |
| 53 base::Bind(&VideoSourceResource::OnPluginMsgOpenComplete, this)); | |
| 54 return PP_OK_COMPLETIONPENDING; | |
| 55 } | |
| 56 | |
| 57 int32_t VideoSourceResource::GetFrame( | |
| 58 PP_VideoFrame_Private* frame, | |
| 59 scoped_refptr<TrackedCallback> callback) { | |
| 60 if (!is_open_) | |
| 61 return PP_ERROR_FAILED; | |
| 62 | |
| 63 if (TrackedCallback::IsPending(get_frame_callback_)) | |
| 64 return PP_ERROR_INPROGRESS; | |
| 65 | |
| 66 get_frame_callback_ = callback; | |
| 67 | |
| 68 Call<PpapiPluginMsg_VideoSource_GetFrameReply>(RENDERER, | |
| 69 PpapiHostMsg_VideoSource_GetFrame(), | |
| 70 base::Bind(&VideoSourceResource::OnPluginMsgGetFrameComplete, this, | |
| 71 frame)); | |
| 72 return PP_OK_COMPLETIONPENDING; | |
| 73 } | |
| 74 | |
| 75 void VideoSourceResource::Close() { | |
| 76 Post(RENDERER, PpapiHostMsg_VideoSource_Close()); | |
| 77 | |
| 78 if (TrackedCallback::IsPending(open_callback_)) | |
| 79 open_callback_->PostAbort(); | |
| 80 if (TrackedCallback::IsPending(get_frame_callback_)) | |
| 81 get_frame_callback_->PostAbort(); | |
| 82 } | |
| 83 | |
| 84 void VideoSourceResource::OnPluginMsgOpenComplete( | |
| 85 const ResourceMessageReplyParams& params) { | |
| 86 is_open_ = true; | |
|
yzshen1
2013/05/02 22:03:05
It seems better to set is_open_ to true only if th
bbudge
2013/05/02 23:12:19
Done.
| |
| 87 if (TrackedCallback::IsPending(open_callback_)) | |
| 88 open_callback_->Run(params.result()); | |
| 89 } | |
| 90 | |
| 91 void VideoSourceResource::OnPluginMsgGetFrameComplete( | |
| 92 PP_VideoFrame_Private* frame, | |
| 93 const ResourceMessageReplyParams& params, | |
| 94 const HostResource& image_data, | |
| 95 PP_TimeTicks timestamp) { | |
| 96 // The callback may have been aborted by Close(). | |
| 97 if (TrackedCallback::IsPending(get_frame_callback_)) { | |
| 98 int32_t result = params.result(); | |
| 99 if (result == PP_OK) { | |
| 100 frame->timestamp = timestamp; | |
| 101 frame->image_data = image_data.host_resource(); | |
| 102 } | |
| 103 | |
| 104 get_frame_callback_->Run(result); | |
| 105 } | |
| 106 } | |
| 107 | |
| 108 } // namespace proxy | |
| 109 } // namespace ppapi | |
| OLD | NEW |