OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ppb_video_capture_proxy.h" | 5 #include "ppapi/proxy/ppb_video_capture_proxy.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "ppapi/c/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
12 #include "ppapi/c/pp_resource.h" | 12 #include "ppapi/c/pp_resource.h" |
13 #include "ppapi/c/ppb_core.h" | 13 #include "ppapi/c/ppb_core.h" |
14 #include "ppapi/c/dev/ppb_video_capture_dev.h" | 14 #include "ppapi/c/dev/ppb_video_capture_dev.h" |
15 #include "ppapi/c/dev/ppp_video_capture_dev.h" | 15 #include "ppapi/c/dev/ppp_video_capture_dev.h" |
16 #include "ppapi/proxy/enter_proxy.h" | 16 #include "ppapi/proxy/enter_proxy.h" |
17 #include "ppapi/proxy/host_dispatcher.h" | 17 #include "ppapi/proxy/host_dispatcher.h" |
18 #include "ppapi/proxy/plugin_dispatcher.h" | 18 #include "ppapi/proxy/plugin_dispatcher.h" |
19 #include "ppapi/proxy/plugin_resource.h" | |
20 #include "ppapi/proxy/ppapi_messages.h" | 19 #include "ppapi/proxy/ppapi_messages.h" |
21 #include "ppapi/proxy/ppb_buffer_proxy.h" | 20 #include "ppapi/proxy/ppb_buffer_proxy.h" |
22 #include "ppapi/thunk/ppb_buffer_api.h" | 21 #include "ppapi/thunk/ppb_buffer_api.h" |
23 #include "ppapi/thunk/ppb_buffer_trusted_api.h" | 22 #include "ppapi/thunk/ppb_buffer_trusted_api.h" |
24 #include "ppapi/thunk/ppb_video_capture_api.h" | 23 #include "ppapi/thunk/ppb_video_capture_api.h" |
25 #include "ppapi/thunk/thunk.h" | 24 #include "ppapi/thunk/thunk.h" |
26 | 25 |
27 using ppapi::HostResource; | 26 using ppapi::HostResource; |
| 27 using ppapi::Resource; |
28 using ppapi::thunk::EnterResourceNoLock; | 28 using ppapi::thunk::EnterResourceNoLock; |
29 using ppapi::thunk::PPB_Buffer_API; | 29 using ppapi::thunk::PPB_Buffer_API; |
30 using ppapi::thunk::PPB_BufferTrusted_API; | 30 using ppapi::thunk::PPB_BufferTrusted_API; |
31 using ppapi::thunk::PPB_VideoCapture_API; | 31 using ppapi::thunk::PPB_VideoCapture_API; |
32 | 32 |
33 namespace pp { | 33 namespace pp { |
34 namespace proxy { | 34 namespace proxy { |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 PPP_VideoCapture_Dev ppp_video_capture = { | 138 PPP_VideoCapture_Dev ppp_video_capture = { |
139 OnDeviceInfo, | 139 OnDeviceInfo, |
140 OnStatus, | 140 OnStatus, |
141 OnError, | 141 OnError, |
142 OnBufferReady | 142 OnBufferReady |
143 }; | 143 }; |
144 | 144 |
145 } // namespace | 145 } // namespace |
146 | 146 |
147 class VideoCapture : public ppapi::thunk::PPB_VideoCapture_API, | 147 class VideoCapture : public ppapi::thunk::PPB_VideoCapture_API, |
148 public PluginResource { | 148 public Resource { |
149 public: | 149 public: |
150 VideoCapture(const HostResource& resource); | 150 VideoCapture(const HostResource& resource); |
151 virtual ~VideoCapture(); | 151 virtual ~VideoCapture(); |
152 | 152 |
153 // ResourceObjectBase overrides. | 153 // Resource overrides. |
154 virtual ppapi::thunk::PPB_VideoCapture_API* AsPPB_VideoCapture_API() OVERRIDE; | 154 virtual ppapi::thunk::PPB_VideoCapture_API* AsPPB_VideoCapture_API() OVERRIDE; |
155 | 155 |
156 // PPB_VideoCapture_API implementation. | 156 // PPB_VideoCapture_API implementation. |
157 virtual int32_t StartCapture( | 157 virtual int32_t StartCapture( |
158 const PP_VideoCaptureDeviceInfo_Dev& requested_info, | 158 const PP_VideoCaptureDeviceInfo_Dev& requested_info, |
159 uint32_t buffer_count) { | 159 uint32_t buffer_count) { |
160 switch (status_) { | 160 switch (status_) { |
161 case PP_VIDEO_CAPTURE_STATUS_STARTING: | 161 case PP_VIDEO_CAPTURE_STATUS_STARTING: |
162 case PP_VIDEO_CAPTURE_STATUS_STARTED: | 162 case PP_VIDEO_CAPTURE_STATUS_STARTED: |
163 case PP_VIDEO_CAPTURE_STATUS_PAUSED: | 163 case PP_VIDEO_CAPTURE_STATUS_PAUSED: |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 239 |
240 void SetBufferCount(size_t count) { | 240 void SetBufferCount(size_t count) { |
241 buffer_in_use_ = std::vector<bool>(count); | 241 buffer_in_use_ = std::vector<bool>(count); |
242 } | 242 } |
243 void SetBufferInUse(uint32_t buffer) { | 243 void SetBufferInUse(uint32_t buffer) { |
244 DCHECK(buffer < buffer_in_use_.size()); | 244 DCHECK(buffer < buffer_in_use_.size()); |
245 buffer_in_use_[buffer] = true; | 245 buffer_in_use_[buffer] = true; |
246 } | 246 } |
247 | 247 |
248 private: | 248 private: |
| 249 PluginDispatcher* GetDispatcher() const { |
| 250 return PluginDispatcher::GetForResource(this); |
| 251 } |
| 252 |
249 uint32_t status_; | 253 uint32_t status_; |
250 std::vector<bool> buffer_in_use_; | 254 std::vector<bool> buffer_in_use_; |
251 DISALLOW_COPY_AND_ASSIGN(VideoCapture); | 255 DISALLOW_COPY_AND_ASSIGN(VideoCapture); |
252 }; | 256 }; |
253 | 257 |
254 VideoCapture::VideoCapture(const HostResource& resource) | 258 VideoCapture::VideoCapture(const HostResource& resource) |
255 : PluginResource(resource), | 259 : Resource(resource), |
256 status_(PP_VIDEO_CAPTURE_STATUS_STOPPED) { | 260 status_(PP_VIDEO_CAPTURE_STATUS_STOPPED) { |
257 } | 261 } |
258 | 262 |
259 VideoCapture::~VideoCapture() { | 263 VideoCapture::~VideoCapture() { |
260 } | 264 } |
261 | 265 |
262 ppapi::thunk::PPB_VideoCapture_API* VideoCapture::AsPPB_VideoCapture_API() { | 266 ppapi::thunk::PPB_VideoCapture_API* VideoCapture::AsPPB_VideoCapture_API() { |
263 return this; | 267 return this; |
264 } | 268 } |
265 | 269 |
(...skipping 21 matching lines...) Expand all Loading... |
287 PP_Resource PPB_VideoCapture_Proxy::CreateProxyResource(PP_Instance instance) { | 291 PP_Resource PPB_VideoCapture_Proxy::CreateProxyResource(PP_Instance instance) { |
288 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 292 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
289 if (!dispatcher) | 293 if (!dispatcher) |
290 return 0; | 294 return 0; |
291 | 295 |
292 HostResource result; | 296 HostResource result; |
293 dispatcher->Send(new PpapiHostMsg_PPBVideoCapture_Create( | 297 dispatcher->Send(new PpapiHostMsg_PPBVideoCapture_Create( |
294 INTERFACE_ID_PPB_VIDEO_CAPTURE_DEV, instance, &result)); | 298 INTERFACE_ID_PPB_VIDEO_CAPTURE_DEV, instance, &result)); |
295 if (result.is_null()) | 299 if (result.is_null()) |
296 return 0; | 300 return 0; |
297 | 301 return (new VideoCapture(result))->GetReference(); |
298 return PluginResourceTracker::GetInstance()->AddResource( | |
299 new VideoCapture(result)); | |
300 } | 302 } |
301 | 303 |
302 bool PPB_VideoCapture_Proxy::OnMessageReceived(const IPC::Message& msg) { | 304 bool PPB_VideoCapture_Proxy::OnMessageReceived(const IPC::Message& msg) { |
303 bool handled = true; | 305 bool handled = true; |
304 IPC_BEGIN_MESSAGE_MAP(PPB_VideoCapture_Proxy, msg) | 306 IPC_BEGIN_MESSAGE_MAP(PPB_VideoCapture_Proxy, msg) |
305 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoCapture_Create, OnMsgCreate) | 307 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoCapture_Create, OnMsgCreate) |
306 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoCapture_StartCapture, | 308 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoCapture_StartCapture, |
307 OnMsgStartCapture) | 309 OnMsgStartCapture) |
308 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoCapture_ReuseBuffer, | 310 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoCapture_ReuseBuffer, |
309 OnMsgReuseBuffer) | 311 OnMsgReuseBuffer) |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 PP_Resource resource = tracker->PluginResourceForHostResource(host_resource); | 446 PP_Resource resource = tracker->PluginResourceForHostResource(host_resource); |
445 if (!resource || !ppp_video_capture_target() || enter.failed()) | 447 if (!resource || !ppp_video_capture_target() || enter.failed()) |
446 return; | 448 return; |
447 static_cast<VideoCapture*>(enter.object())->SetBufferInUse(buffer); | 449 static_cast<VideoCapture*>(enter.object())->SetBufferInUse(buffer); |
448 ppp_video_capture_target()->OnBufferReady( | 450 ppp_video_capture_target()->OnBufferReady( |
449 host_resource.instance(), resource, buffer); | 451 host_resource.instance(), resource, buffer); |
450 } | 452 } |
451 | 453 |
452 } // namespace proxy | 454 } // namespace proxy |
453 } // namespace pp | 455 } // namespace pp |
OLD | NEW |