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 "content/renderer/pepper/pepper_video_source_host.h" | 5 #include "content/renderer/pepper/pepper_video_source_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/safe_numerics.h" | 8 #include "base/safe_numerics.h" |
9 #include "content/public/renderer/renderer_ppapi_host.h" | 9 #include "content/public/renderer/renderer_ppapi_host.h" |
10 #include "content/renderer/render_thread_impl.h" | 10 #include "content/renderer/render_thread_impl.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 | 130 |
131 void PepperVideoSourceHost::SendGetFrameReply() { | 131 void PepperVideoSourceHost::SendGetFrameReply() { |
132 DCHECK(get_frame_pending_); | 132 DCHECK(get_frame_pending_); |
133 get_frame_pending_ = false; | 133 get_frame_pending_ = false; |
134 | 134 |
135 DCHECK(last_frame_.get()); | 135 DCHECK(last_frame_.get()); |
136 scoped_ptr<cricket::VideoFrame> frame(last_frame_.release()); | 136 scoped_ptr<cricket::VideoFrame> frame(last_frame_.release()); |
137 | 137 |
138 int32_t width = base::checked_numeric_cast<int32_t>(frame->GetWidth()); | 138 int32_t width = base::checked_numeric_cast<int32_t>(frame->GetWidth()); |
139 int32_t height = base::checked_numeric_cast<int32_t>(frame->GetHeight()); | 139 int32_t height = base::checked_numeric_cast<int32_t>(frame->GetHeight()); |
140 // Create an image data resource to hold the frame pixels. | 140 // Create an image data resource to hold the frame pixels. We don't require |
141 // access to a platform DIB so always create it "NaCl style". | |
141 PP_ImageDataDesc image_desc; | 142 PP_ImageDataDesc image_desc; |
142 IPC::PlatformFileForTransit image_handle; | 143 IPC::PlatformFileForTransit image_handle; |
143 uint32_t byte_count; | 144 uint32_t byte_count; |
144 ppapi::ScopedPPResource resource( | 145 ppapi::ScopedPPResource resource( |
145 ppapi::ScopedPPResource::PassRef(), | 146 ppapi::ScopedPPResource::PassRef(), |
146 ppapi::proxy::PPB_ImageData_Proxy::CreateImageData( | 147 ppapi::proxy::PPB_ImageData_Proxy::CreateImageData( |
147 pp_instance(), | 148 pp_instance(), |
148 PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 149 PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
149 PP_MakeSize(width, height), | 150 PP_MakeSize(width, height), |
150 false /* init_to_zero */, | 151 false /* init_to_zero */, |
151 false /* is_nacl_plugin */, | 152 true /* is_nacl_plugin */, |
152 &image_desc, &image_handle, &byte_count)); | 153 &image_desc, &image_handle, &byte_count)); |
153 if (!resource.get()) { | 154 if (!resource.get()) { |
154 SendGetFrameErrorReply(PP_ERROR_FAILED); | 155 SendGetFrameErrorReply(PP_ERROR_FAILED); |
155 return; | 156 return; |
156 } | 157 } |
157 | 158 |
158 ppapi::thunk::EnterResourceNoLock<ppapi::thunk::PPB_ImageData_API> | 159 ppapi::thunk::EnterResourceNoLock<ppapi::thunk::PPB_ImageData_API> |
159 enter_resource(resource, false); | 160 enter_resource(resource, false); |
160 if (enter_resource.failed()) { | 161 if (enter_resource.failed()) { |
161 SendGetFrameErrorReply(PP_ERROR_FAILED); | 162 SendGetFrameErrorReply(PP_ERROR_FAILED); |
(...skipping 28 matching lines...) Expand all Loading... | |
190 ppapi::HostResource host_resource; | 191 ppapi::HostResource host_resource; |
191 host_resource.SetHostResource(pp_instance(), resource.get()); | 192 host_resource.SetHostResource(pp_instance(), resource.get()); |
192 | 193 |
193 // Convert a video timestamp (int64, in nanoseconds) to a time delta (int64, | 194 // Convert a video timestamp (int64, in nanoseconds) to a time delta (int64, |
194 // microseconds) and then to a PP_TimeTicks (a double, in seconds). All times | 195 // microseconds) and then to a PP_TimeTicks (a double, in seconds). All times |
195 // are relative to the Unix Epoch. | 196 // are relative to the Unix Epoch. |
196 base::TimeDelta time_delta = base::TimeDelta::FromMicroseconds( | 197 base::TimeDelta time_delta = base::TimeDelta::FromMicroseconds( |
197 frame->GetTimeStamp() / base::Time::kNanosecondsPerMicrosecond); | 198 frame->GetTimeStamp() / base::Time::kNanosecondsPerMicrosecond); |
198 PP_TimeTicks timestamp = time_delta.InSecondsF(); | 199 PP_TimeTicks timestamp = time_delta.InSecondsF(); |
199 | 200 |
200 reply_context_.params.set_result(PP_OK); | 201 int shmem_key = |
dmichael (off chromium)
2013/06/05 01:54:42
You should be able to get rid of this and the asso
bbudge
2013/06/05 19:18:52
It's still needed on Linux for trusted plugins.
On
bbudge
2013/06/19 00:22:32
Done.
| |
201 | |
202 #if defined(TOOLKIT_GTK) | 202 #if defined(TOOLKIT_GTK) |
203 // For GTK, we pass the SysV shared memory key in the message. | 203 // For GTK, we pass the SysV shared memory key in the message. |
204 PpapiPluginMsg_VideoSource_GetFrameReply reply_msg(host_resource, | 204 image_handle.fd; |
205 image_desc, | |
206 image_handle.fd, | |
207 timestamp); | |
208 #elif defined(OS_POSIX) || defined(OS_WIN) | |
209 ppapi::proxy::SerializedHandle serialized_handle; | |
210 PpapiPluginMsg_VideoSource_GetFrameReply reply_msg(host_resource, | |
211 image_desc, | |
212 0, | |
213 timestamp); | |
214 serialized_handle.set_shmem(image_handle, byte_count); | |
215 reply_context_.params.AppendHandle(serialized_handle); | |
216 #else | 205 #else |
206 0; | |
207 #endif | |
208 | |
209 #if !defined(OS_POSIX) && !defined(OS_WIN) | |
217 // Not supported on other platforms. | 210 // Not supported on other platforms. |
218 // This is a stub reply_msg to not break the build. | |
219 PpapiPluginMsg_VideoSource_GetFrameReply reply_msg(host_resource, | |
220 image_desc, | |
221 0, | |
222 timestamp); | |
223 NOTIMPLEMENTED(); | 211 NOTIMPLEMENTED(); |
224 SendGetFrameErrorReply(PP_ERROR_NOTSUPPORTED); | 212 SendGetFrameErrorReply(PP_ERROR_NOTSUPPORTED); |
225 return; | 213 return; |
226 #endif | 214 #endif |
227 | 215 |
228 host()->SendReply(reply_context_, reply_msg); | 216 reply_context_.params.set_result(PP_OK); |
217 ppapi::proxy::SerializedHandle serialized_handle; | |
218 serialized_handle.set_shmem(image_handle, byte_count); | |
219 reply_context_.params.AppendHandle(serialized_handle); | |
220 | |
221 host()->SendReply(reply_context_, | |
222 PpapiPluginMsg_VideoSource_GetFrameReply(host_resource, | |
223 image_desc, | |
224 shmem_key, | |
225 timestamp)); | |
229 | 226 |
230 reply_context_ = ppapi::host::ReplyMessageContext(); | 227 reply_context_ = ppapi::host::ReplyMessageContext(); |
231 | 228 |
232 // Keep a reference once we know this method succeeds. | 229 // Keep a reference once we know this method succeeds. |
233 resource.Release(); | 230 resource.Release(); |
234 } | 231 } |
235 | 232 |
236 void PepperVideoSourceHost::SendGetFrameErrorReply(int32_t error) { | 233 void PepperVideoSourceHost::SendGetFrameErrorReply(int32_t error) { |
237 reply_context_.params.set_result(error); | 234 reply_context_.params.set_result(error); |
238 host()->SendReply( | 235 host()->SendReply( |
239 reply_context_, | 236 reply_context_, |
240 PpapiPluginMsg_VideoSource_GetFrameReply( | 237 PpapiPluginMsg_VideoSource_GetFrameReply(ppapi::HostResource(), |
241 ppapi::HostResource(), PP_ImageDataDesc(), -1, 0.0)); | 238 PP_ImageDataDesc(), |
239 -1 /* shmem_key */, | |
240 0.0 /* timestamp */)); | |
242 reply_context_ = ppapi::host::ReplyMessageContext(); | 241 reply_context_ = ppapi::host::ReplyMessageContext(); |
243 } | 242 } |
244 | 243 |
245 void PepperVideoSourceHost::Close() { | 244 void PepperVideoSourceHost::Close() { |
246 if (source_handler_.get() && !stream_url_.empty()) | 245 if (source_handler_.get() && !stream_url_.empty()) |
247 source_handler_->Close(stream_url_, frame_receiver_.get()); | 246 source_handler_->Close(stream_url_, frame_receiver_.get()); |
248 | 247 |
249 source_handler_.reset(NULL); | 248 source_handler_.reset(NULL); |
250 stream_url_.clear(); | 249 stream_url_.clear(); |
251 } | 250 } |
252 | 251 |
253 } // namespace content | 252 } // namespace content |
OLD | NEW |