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" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 #elif defined(OS_POSIX) | 80 #elif defined(OS_POSIX) |
81 handle; | 81 handle; |
82 #else | 82 #else |
83 #error Not implemented. | 83 #error Not implemented. |
84 #endif | 84 #endif |
85 buffers[i].handle = | 85 buffers[i].handle = |
86 dispatcher->ShareHandleWithRemote(platform_file, false); | 86 dispatcher->ShareHandleWithRemote(platform_file, false); |
87 } | 87 } |
88 } | 88 } |
89 dispatcher->Send(new PpapiMsg_PPPVideoCapture_OnDeviceInfo( | 89 dispatcher->Send(new PpapiMsg_PPPVideoCapture_OnDeviceInfo( |
90 INTERFACE_ID_PPP_VIDEO_CAPTURE_DEV, host_resource, *info, buffers)); | 90 API_ID_PPP_VIDEO_CAPTURE_DEV, host_resource, *info, buffers)); |
91 } | 91 } |
92 | 92 |
93 void OnStatus(PP_Instance instance, PP_Resource resource, uint32_t status) { | 93 void OnStatus(PP_Instance instance, PP_Resource resource, uint32_t status) { |
94 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 94 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
95 if (!dispatcher) { | 95 if (!dispatcher) { |
96 NOTREACHED(); | 96 NOTREACHED(); |
97 return; | 97 return; |
98 } | 98 } |
99 HostResource host_resource; | 99 HostResource host_resource; |
100 host_resource.SetHostResource(instance, resource); | 100 host_resource.SetHostResource(instance, resource); |
101 dispatcher->Send(new PpapiMsg_PPPVideoCapture_OnStatus( | 101 dispatcher->Send(new PpapiMsg_PPPVideoCapture_OnStatus( |
102 INTERFACE_ID_PPP_VIDEO_CAPTURE_DEV, host_resource, status)); | 102 API_ID_PPP_VIDEO_CAPTURE_DEV, host_resource, status)); |
103 } | 103 } |
104 | 104 |
105 void OnError(PP_Instance instance, PP_Resource resource, uint32_t error_code) { | 105 void OnError(PP_Instance instance, PP_Resource resource, uint32_t error_code) { |
106 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 106 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
107 if (!dispatcher) { | 107 if (!dispatcher) { |
108 NOTREACHED(); | 108 NOTREACHED(); |
109 return; | 109 return; |
110 } | 110 } |
111 HostResource host_resource; | 111 HostResource host_resource; |
112 host_resource.SetHostResource(instance, resource); | 112 host_resource.SetHostResource(instance, resource); |
113 dispatcher->Send(new PpapiMsg_PPPVideoCapture_OnError( | 113 dispatcher->Send(new PpapiMsg_PPPVideoCapture_OnError( |
114 INTERFACE_ID_PPP_VIDEO_CAPTURE_DEV, host_resource, error_code)); | 114 API_ID_PPP_VIDEO_CAPTURE_DEV, host_resource, error_code)); |
115 } | 115 } |
116 | 116 |
117 void OnBufferReady(PP_Instance instance, | 117 void OnBufferReady(PP_Instance instance, |
118 PP_Resource resource, | 118 PP_Resource resource, |
119 uint32_t buffer) { | 119 uint32_t buffer) { |
120 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 120 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
121 if (!dispatcher) { | 121 if (!dispatcher) { |
122 NOTREACHED(); | 122 NOTREACHED(); |
123 return; | 123 return; |
124 } | 124 } |
125 HostResource host_resource; | 125 HostResource host_resource; |
126 host_resource.SetHostResource(instance, resource); | 126 host_resource.SetHostResource(instance, resource); |
127 dispatcher->Send(new PpapiMsg_PPPVideoCapture_OnBufferReady( | 127 dispatcher->Send(new PpapiMsg_PPPVideoCapture_OnBufferReady( |
128 INTERFACE_ID_PPP_VIDEO_CAPTURE_DEV, host_resource, buffer)); | 128 API_ID_PPP_VIDEO_CAPTURE_DEV, host_resource, buffer)); |
129 } | 129 } |
130 | 130 |
131 PPP_VideoCapture_Dev ppp_video_capture = { | 131 PPP_VideoCapture_Dev ppp_video_capture = { |
132 OnDeviceInfo, | 132 OnDeviceInfo, |
133 OnStatus, | 133 OnStatus, |
134 OnError, | 134 OnError, |
135 OnBufferReady | 135 OnBufferReady |
136 }; | 136 }; |
137 | 137 |
138 } // namespace | 138 } // namespace |
(...skipping 16 matching lines...) Expand all Loading... |
155 case PP_VIDEO_CAPTURE_STATUS_STARTED: | 155 case PP_VIDEO_CAPTURE_STATUS_STARTED: |
156 case PP_VIDEO_CAPTURE_STATUS_PAUSED: | 156 case PP_VIDEO_CAPTURE_STATUS_PAUSED: |
157 default: | 157 default: |
158 return PP_ERROR_FAILED; | 158 return PP_ERROR_FAILED; |
159 case PP_VIDEO_CAPTURE_STATUS_STOPPED: | 159 case PP_VIDEO_CAPTURE_STATUS_STOPPED: |
160 case PP_VIDEO_CAPTURE_STATUS_STOPPING: | 160 case PP_VIDEO_CAPTURE_STATUS_STOPPING: |
161 break; | 161 break; |
162 } | 162 } |
163 status_ = PP_VIDEO_CAPTURE_STATUS_STARTING; | 163 status_ = PP_VIDEO_CAPTURE_STATUS_STARTING; |
164 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoCapture_StartCapture( | 164 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoCapture_StartCapture( |
165 INTERFACE_ID_PPB_VIDEO_CAPTURE_DEV, host_resource(), | 165 API_ID_PPB_VIDEO_CAPTURE_DEV, host_resource(), |
166 requested_info, buffer_count)); | 166 requested_info, buffer_count)); |
167 return PP_OK; | 167 return PP_OK; |
168 } | 168 } |
169 | 169 |
170 virtual int32_t ReuseBuffer(uint32_t buffer) { | 170 virtual int32_t ReuseBuffer(uint32_t buffer) { |
171 if (buffer >= buffer_in_use_.size() || !buffer_in_use_[buffer]) | 171 if (buffer >= buffer_in_use_.size() || !buffer_in_use_[buffer]) |
172 return PP_ERROR_BADARGUMENT; | 172 return PP_ERROR_BADARGUMENT; |
173 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoCapture_ReuseBuffer( | 173 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoCapture_ReuseBuffer( |
174 INTERFACE_ID_PPB_VIDEO_CAPTURE_DEV, host_resource(), buffer)); | 174 API_ID_PPB_VIDEO_CAPTURE_DEV, host_resource(), buffer)); |
175 return PP_OK; | 175 return PP_OK; |
176 } | 176 } |
177 | 177 |
178 virtual int32_t StopCapture() { | 178 virtual int32_t StopCapture() { |
179 switch (status_) { | 179 switch (status_) { |
180 case PP_VIDEO_CAPTURE_STATUS_STOPPED: | 180 case PP_VIDEO_CAPTURE_STATUS_STOPPED: |
181 case PP_VIDEO_CAPTURE_STATUS_STOPPING: | 181 case PP_VIDEO_CAPTURE_STATUS_STOPPING: |
182 default: | 182 default: |
183 return PP_ERROR_FAILED; | 183 return PP_ERROR_FAILED; |
184 case PP_VIDEO_CAPTURE_STATUS_STARTING: | 184 case PP_VIDEO_CAPTURE_STATUS_STARTING: |
185 case PP_VIDEO_CAPTURE_STATUS_STARTED: | 185 case PP_VIDEO_CAPTURE_STATUS_STARTED: |
186 case PP_VIDEO_CAPTURE_STATUS_PAUSED: | 186 case PP_VIDEO_CAPTURE_STATUS_PAUSED: |
187 break; | 187 break; |
188 } | 188 } |
189 buffer_in_use_.clear(); | 189 buffer_in_use_.clear(); |
190 status_ = PP_VIDEO_CAPTURE_STATUS_STOPPING; | 190 status_ = PP_VIDEO_CAPTURE_STATUS_STOPPING; |
191 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoCapture_StopCapture( | 191 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoCapture_StopCapture( |
192 INTERFACE_ID_PPB_VIDEO_CAPTURE_DEV, host_resource())); | 192 API_ID_PPB_VIDEO_CAPTURE_DEV, host_resource())); |
193 return PP_OK; | 193 return PP_OK; |
194 } | 194 } |
195 | 195 |
196 bool OnStatus(uint32_t status) { | 196 bool OnStatus(uint32_t status) { |
197 switch (status) { | 197 switch (status) { |
198 case PP_VIDEO_CAPTURE_STATUS_STARTING: | 198 case PP_VIDEO_CAPTURE_STATUS_STARTING: |
199 case PP_VIDEO_CAPTURE_STATUS_STOPPING: | 199 case PP_VIDEO_CAPTURE_STATUS_STOPPING: |
200 default: | 200 default: |
201 // Those states are not sent by the browser. | 201 // Those states are not sent by the browser. |
202 NOTREACHED(); | 202 NOTREACHED(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 } | 268 } |
269 | 269 |
270 // static | 270 // static |
271 PP_Resource PPB_VideoCapture_Proxy::CreateProxyResource(PP_Instance instance) { | 271 PP_Resource PPB_VideoCapture_Proxy::CreateProxyResource(PP_Instance instance) { |
272 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 272 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
273 if (!dispatcher) | 273 if (!dispatcher) |
274 return 0; | 274 return 0; |
275 | 275 |
276 HostResource result; | 276 HostResource result; |
277 dispatcher->Send(new PpapiHostMsg_PPBVideoCapture_Create( | 277 dispatcher->Send(new PpapiHostMsg_PPBVideoCapture_Create( |
278 INTERFACE_ID_PPB_VIDEO_CAPTURE_DEV, instance, &result)); | 278 API_ID_PPB_VIDEO_CAPTURE_DEV, instance, &result)); |
279 if (result.is_null()) | 279 if (result.is_null()) |
280 return 0; | 280 return 0; |
281 return (new VideoCapture(result))->GetReference(); | 281 return (new VideoCapture(result))->GetReference(); |
282 } | 282 } |
283 | 283 |
284 bool PPB_VideoCapture_Proxy::OnMessageReceived(const IPC::Message& msg) { | 284 bool PPB_VideoCapture_Proxy::OnMessageReceived(const IPC::Message& msg) { |
285 bool handled = true; | 285 bool handled = true; |
286 IPC_BEGIN_MESSAGE_MAP(PPB_VideoCapture_Proxy, msg) | 286 IPC_BEGIN_MESSAGE_MAP(PPB_VideoCapture_Proxy, msg) |
287 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoCapture_Create, OnMsgCreate) | 287 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoCapture_Create, OnMsgCreate) |
288 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoCapture_StartCapture, | 288 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoCapture_StartCapture, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 } | 339 } |
340 | 340 |
341 PPP_VideoCapture_Proxy::~PPP_VideoCapture_Proxy() { | 341 PPP_VideoCapture_Proxy::~PPP_VideoCapture_Proxy() { |
342 } | 342 } |
343 | 343 |
344 // static | 344 // static |
345 const InterfaceProxy::Info* PPP_VideoCapture_Proxy::GetInfo() { | 345 const InterfaceProxy::Info* PPP_VideoCapture_Proxy::GetInfo() { |
346 static const Info info = { | 346 static const Info info = { |
347 &ppp_video_capture, | 347 &ppp_video_capture, |
348 PPP_VIDEO_CAPTURE_DEV_INTERFACE, | 348 PPP_VIDEO_CAPTURE_DEV_INTERFACE, |
349 INTERFACE_ID_PPP_VIDEO_CAPTURE_DEV, | 349 API_ID_PPP_VIDEO_CAPTURE_DEV, |
350 false, | 350 false, |
351 &CreatePPPVideoCaptureProxy, | 351 &CreatePPPVideoCaptureProxy, |
352 }; | 352 }; |
353 return &info; | 353 return &info; |
354 } | 354 } |
355 | 355 |
356 bool PPP_VideoCapture_Proxy::OnMessageReceived(const IPC::Message& msg) { | 356 bool PPP_VideoCapture_Proxy::OnMessageReceived(const IPC::Message& msg) { |
357 bool handled = true; | 357 bool handled = true; |
358 IPC_BEGIN_MESSAGE_MAP(PPP_VideoCapture_Proxy, msg) | 358 IPC_BEGIN_MESSAGE_MAP(PPP_VideoCapture_Proxy, msg) |
359 IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoCapture_OnDeviceInfo, | 359 IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoCapture_OnDeviceInfo, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 return; | 431 return; |
432 | 432 |
433 VideoCapture* capture = static_cast<VideoCapture*>(enter.object()); | 433 VideoCapture* capture = static_cast<VideoCapture*>(enter.object()); |
434 capture->SetBufferInUse(buffer); | 434 capture->SetBufferInUse(buffer); |
435 ppp_video_capture_impl_->OnBufferReady( | 435 ppp_video_capture_impl_->OnBufferReady( |
436 host_resource.instance(), capture->pp_resource(), buffer); | 436 host_resource.instance(), capture->pp_resource(), buffer); |
437 } | 437 } |
438 | 438 |
439 } // namespace proxy | 439 } // namespace proxy |
440 } // namespace ppapi | 440 } // namespace ppapi |
OLD | NEW |