OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/proxy/video_source_resource.h" | 5 #include "ppapi/proxy/video_source_resource.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "ipc/ipc_message.h" | 8 #include "ipc/ipc_message.h" |
9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
10 #include "ppapi/c/private/pp_video_frame_private.h" | 10 #include "ppapi/c/private/pp_video_frame_private.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 int32_t VideoSourceResource::GetFrame( | 59 int32_t VideoSourceResource::GetFrame( |
60 PP_VideoFrame_Private* frame, | 60 PP_VideoFrame_Private* frame, |
61 scoped_refptr<TrackedCallback> callback) { | 61 scoped_refptr<TrackedCallback> callback) { |
62 if (!is_open_) | 62 if (!is_open_) |
63 return PP_ERROR_FAILED; | 63 return PP_ERROR_FAILED; |
64 | 64 |
65 if (TrackedCallback::IsPending(get_frame_callback_)) | 65 if (TrackedCallback::IsPending(get_frame_callback_)) |
66 return PP_ERROR_INPROGRESS; | 66 return PP_ERROR_INPROGRESS; |
67 | 67 |
68 get_frame_callback_ = callback; | 68 get_frame_callback_ = callback; |
69 | |
70 Call<PpapiPluginMsg_VideoSource_GetFrameReply>(RENDERER, | 69 Call<PpapiPluginMsg_VideoSource_GetFrameReply>(RENDERER, |
71 PpapiHostMsg_VideoSource_GetFrame(), | 70 PpapiHostMsg_VideoSource_GetFrame(), |
72 base::Bind(&VideoSourceResource::OnPluginMsgGetFrameComplete, this, | 71 base::Bind(&VideoSourceResource::OnPluginMsgGetFrameComplete, this, |
73 frame)); | 72 frame)); |
74 return PP_OK_COMPLETIONPENDING; | 73 return PP_OK_COMPLETIONPENDING; |
75 } | 74 } |
76 | 75 |
77 void VideoSourceResource::Close() { | 76 void VideoSourceResource::Close() { |
78 Post(RENDERER, PpapiHostMsg_VideoSource_Close()); | 77 Post(RENDERER, PpapiHostMsg_VideoSource_Close()); |
79 | 78 |
80 if (TrackedCallback::IsPending(open_callback_)) | 79 if (TrackedCallback::IsPending(open_callback_)) |
81 open_callback_->PostAbort(); | 80 open_callback_->PostAbort(); |
82 if (TrackedCallback::IsPending(get_frame_callback_)) | 81 if (TrackedCallback::IsPending(get_frame_callback_)) |
83 get_frame_callback_->PostAbort(); | 82 get_frame_callback_->PostAbort(); |
84 } | 83 } |
85 | 84 |
86 void VideoSourceResource::OnPluginMsgOpenComplete( | 85 void VideoSourceResource::OnPluginMsgOpenComplete( |
87 const ResourceMessageReplyParams& reply_params) { | 86 const ResourceMessageReplyParams& reply_params) { |
88 if (TrackedCallback::IsPending(open_callback_)) { | 87 if (TrackedCallback::IsPending(open_callback_)) { |
89 int32_t result = reply_params.result(); | 88 int32_t result = reply_params.result(); |
90 if (result == PP_OK) | 89 if (result == PP_OK) |
91 is_open_ = true; | 90 is_open_ = true; |
92 open_callback_->Run(result); | 91 open_callback_->Run(result); |
93 } | 92 } |
94 } | 93 } |
95 | 94 |
96 void VideoSourceResource::OnPluginMsgGetFrameComplete( | 95 void VideoSourceResource::OnPluginMsgGetFrameComplete( |
97 PP_VideoFrame_Private* frame, | 96 PP_VideoFrame_Private* frame, |
meacer
2013/06/19 02:05:11
It seems possible that frame->image_data is not in
bbudge
2013/06/19 16:55:00
Yes, the API contract is that the frame isn't writ
| |
98 const ResourceMessageReplyParams& reply_params, | 97 const ResourceMessageReplyParams& reply_params, |
99 const HostResource& image_data, | 98 const HostResource& image_data, |
100 const PP_ImageDataDesc& image_desc, | 99 const PP_ImageDataDesc& image_desc, |
101 int fd, | |
102 PP_TimeTicks timestamp) { | 100 PP_TimeTicks timestamp) { |
103 // The callback may have been aborted by Close(). | 101 // The callback may have been aborted by Close(). |
104 if (TrackedCallback::IsPending(get_frame_callback_)) { | 102 if (TrackedCallback::IsPending(get_frame_callback_)) { |
105 int32_t result = reply_params.result(); | 103 int32_t result = reply_params.result(); |
106 if (result == PP_OK && | 104 if (result == PP_OK && |
107 PPB_ImageData_Shared::IsImageDataDescValid(image_desc)) { | 105 PPB_ImageData_Shared::IsImageDataDescValid(image_desc)) { |
108 frame->timestamp = timestamp; | 106 frame->timestamp = timestamp; |
109 | 107 |
110 #if defined(OS_ANDROID) | |
111 frame->image_data = 0; | |
112 #elif defined(TOOLKIT_GTK) | |
113 frame->image_data = | |
114 (new PlatformImageData(image_data, image_desc, fd))->GetReference(); | |
115 #elif defined(OS_LINUX) || defined(OS_WIN) || defined(OS_MACOSX) | |
116 base::SharedMemoryHandle handle; | 108 base::SharedMemoryHandle handle; |
117 if (!reply_params.TakeSharedMemoryHandleAtIndex(0, &handle)) | 109 if (!reply_params.TakeSharedMemoryHandleAtIndex(0, &handle)) |
118 frame->image_data = 0; | 110 frame->image_data = 0; |
119 frame->image_data = | 111 frame->image_data = |
120 (new PlatformImageData( | 112 (new SimpleImageData( |
121 image_data, image_desc, handle))->GetReference(); | 113 image_data, image_desc, handle))->GetReference(); |
122 #else | |
123 #error Not implemented. | |
124 #endif | |
125 } | 114 } |
126 get_frame_callback_->Run(result); | 115 get_frame_callback_->Run(result); |
127 } | 116 } |
128 } | 117 } |
129 | 118 |
130 } // namespace proxy | 119 } // namespace proxy |
131 } // namespace ppapi | 120 } // namespace ppapi |
OLD | NEW |