Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(925)

Side by Side Diff: webkit/plugins/ppapi/ppb_video_capture_impl.cc

Issue 7669055: Remove webkit::ppapi::Resource. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nulls auditeed Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "webkit/plugins/ppapi/ppb_video_capture_impl.h" 5 #include "webkit/plugins/ppapi/ppb_video_capture_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "ppapi/c/dev/pp_video_capture_dev.h" 11 #include "ppapi/c/dev/pp_video_capture_dev.h"
12 #include "ppapi/c/dev/ppb_video_capture_dev.h" 12 #include "ppapi/c/dev/ppb_video_capture_dev.h"
13 #include "ppapi/c/pp_completion_callback.h" 13 #include "ppapi/c/pp_completion_callback.h"
14 #include "ppapi/c/pp_errors.h" 14 #include "ppapi/c/pp_errors.h"
15 #include "ppapi/thunk/enter.h" 15 #include "ppapi/thunk/enter.h"
16 #include "webkit/plugins/ppapi/common.h" 16 #include "webkit/plugins/ppapi/common.h"
17 #include "webkit/plugins/ppapi/plugin_module.h" 17 #include "webkit/plugins/ppapi/plugin_module.h"
18 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 18 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
19 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" 19 #include "webkit/plugins/ppapi/ppb_buffer_impl.h"
20 #include "webkit/plugins/ppapi/resource_helper.h"
20 #include "webkit/plugins/ppapi/resource_tracker.h" 21 #include "webkit/plugins/ppapi/resource_tracker.h"
21 22
22 using ppapi::thunk::EnterResourceNoLock; 23 using ppapi::thunk::EnterResourceNoLock;
23 using ppapi::thunk::PPB_Buffer_API; 24 using ppapi::thunk::PPB_Buffer_API;
24 using ppapi::thunk::PPB_VideoCapture_API; 25 using ppapi::thunk::PPB_VideoCapture_API;
25 26
26 namespace webkit { 27 namespace webkit {
27 namespace ppapi { 28 namespace ppapi {
28 29
29 PPB_VideoCapture_Impl::PPB_VideoCapture_Impl(PluginInstance* instance) 30 PPB_VideoCapture_Impl::PPB_VideoCapture_Impl(PP_Instance instance)
30 : Resource(instance), 31 : Resource(instance),
31 buffer_count_hint_(0), 32 buffer_count_hint_(0),
32 ppp_videocapture_(NULL), 33 ppp_videocapture_(NULL),
33 status_(PP_VIDEO_CAPTURE_STATUS_STOPPED) { 34 status_(PP_VIDEO_CAPTURE_STATUS_STOPPED) {
34 } 35 }
35 36
36 PPB_VideoCapture_Impl::~PPB_VideoCapture_Impl() { 37 PPB_VideoCapture_Impl::~PPB_VideoCapture_Impl() {
37 if (platform_video_capture_.get()) 38 if (platform_video_capture_.get())
38 StopCapture(); 39 StopCapture();
39 } 40 }
40 41
41 bool PPB_VideoCapture_Impl::Init() { 42 bool PPB_VideoCapture_Impl::Init() {
42 ppp_videocapture_ = 43 PluginInstance* instance = ResourceHelper::GetPluginInstance(this);
43 static_cast<const PPP_VideoCapture_Dev*>(instance()->module()-> 44 if (!instance)
44 GetPluginInterface(PPP_VIDEO_CAPTURE_DEV_INTERFACE)); 45 return false;
46 ppp_videocapture_ = static_cast<const PPP_VideoCapture_Dev*>(
47 instance->module()->GetPluginInterface(PPP_VIDEO_CAPTURE_DEV_INTERFACE));
45 if (!ppp_videocapture_) 48 if (!ppp_videocapture_)
46 return false; 49 return false;
47 50
48 platform_video_capture_.reset( 51 platform_video_capture_.reset(
49 instance()->delegate()->CreateVideoCapture(this)); 52 instance->delegate()->CreateVideoCapture(this));
50 return !!platform_video_capture_.get(); 53 return !!platform_video_capture_.get();
51 } 54 }
52 55
53 PPB_VideoCapture_API* PPB_VideoCapture_Impl::AsPPB_VideoCapture_API() { 56 PPB_VideoCapture_API* PPB_VideoCapture_Impl::AsPPB_VideoCapture_API() {
54 return this; 57 return this;
55 } 58 }
56 59
57 int32_t PPB_VideoCapture_Impl::StartCapture( 60 int32_t PPB_VideoCapture_Impl::StartCapture(
58 const PP_VideoCaptureDeviceInfo_Dev& requested_info, 61 const PP_VideoCaptureDeviceInfo_Dev& requested_info,
59 uint32_t buffer_count) { 62 uint32_t buffer_count) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 157 }
155 158
156 void PPB_VideoCapture_Impl::OnError(media::VideoCapture* capture, 159 void PPB_VideoCapture_Impl::OnError(media::VideoCapture* capture,
157 int error_code) { 160 int error_code) {
158 // Today, the media layer only sends "1" as an error. 161 // Today, the media layer only sends "1" as an error.
159 DCHECK(error_code == 1); 162 DCHECK(error_code == 1);
160 // It either comes because some error was detected while starting (e.g. 2 163 // It either comes because some error was detected while starting (e.g. 2
161 // conflicting "master" resolution), or because the browser failed to start 164 // conflicting "master" resolution), or because the browser failed to start
162 // the capture. 165 // the capture.
163 status_ = PP_VIDEO_CAPTURE_STATUS_STOPPED; 166 status_ = PP_VIDEO_CAPTURE_STATUS_STOPPED;
164 ppp_videocapture_->OnError(instance()->pp_instance(), 167 ppp_videocapture_->OnError(pp_instance(), pp_resource(), PP_ERROR_FAILED);
165 ScopedResourceId(this).id,
166 PP_ERROR_FAILED);
167 } 168 }
168 169
169 void PPB_VideoCapture_Impl::OnBufferReady( 170 void PPB_VideoCapture_Impl::OnBufferReady(
170 media::VideoCapture* capture, 171 media::VideoCapture* capture,
171 scoped_refptr<media::VideoCapture::VideoFrameBuffer> buffer) { 172 scoped_refptr<media::VideoCapture::VideoFrameBuffer> buffer) {
172 DCHECK(buffer.get()); 173 DCHECK(buffer.get());
173 for (uint32_t i = 0; i < buffers_.size(); ++i) { 174 for (uint32_t i = 0; i < buffers_.size(); ++i) {
174 if (!buffers_[i].in_use) { 175 if (!buffers_[i].in_use) {
175 // TODO(piman): it looks like stride isn't actually used/filled. 176 // TODO(piman): it looks like stride isn't actually used/filled.
176 DCHECK(buffer->stride == 0); 177 DCHECK(buffer->stride == 0);
177 size_t size = std::min(static_cast<size_t>(buffers_[i].buffer->size()), 178 size_t size = std::min(static_cast<size_t>(buffers_[i].buffer->size()),
178 buffer->buffer_size); 179 buffer->buffer_size);
179 memcpy(buffers_[i].data, buffer->memory_pointer, size); 180 memcpy(buffers_[i].data, buffer->memory_pointer, size);
180 platform_video_capture_->FeedBuffer(buffer); 181 platform_video_capture_->FeedBuffer(buffer);
181 ppp_videocapture_->OnBufferReady(instance()->pp_instance(), 182 ppp_videocapture_->OnBufferReady(pp_instance(), pp_resource(), i);
182 ScopedResourceId(this).id,
183 i);
184 return; 183 return;
185 } 184 }
186 } 185 }
187 // TODO(piman): signal dropped buffers ? 186 // TODO(piman): signal dropped buffers ?
188 platform_video_capture_->FeedBuffer(buffer); 187 platform_video_capture_->FeedBuffer(buffer);
189 } 188 }
190 189
191 void PPB_VideoCapture_Impl::OnDeviceInfoReceived( 190 void PPB_VideoCapture_Impl::OnDeviceInfoReceived(
192 media::VideoCapture* capture, 191 media::VideoCapture* capture,
193 const media::VideoCaptureParams& device_info) { 192 const media::VideoCaptureParams& device_info) {
194 PP_VideoCaptureDeviceInfo_Dev info = { 193 PP_VideoCaptureDeviceInfo_Dev info = {
195 device_info.width, 194 device_info.width,
196 device_info.height, 195 device_info.height,
197 device_info.frame_per_second 196 device_info.frame_per_second
198 }; 197 };
199 ReleaseBuffers(); 198 ReleaseBuffers();
200 199
201 // Allocate buffers. We keep a reference to them, that is released in 200 // Allocate buffers. We keep a reference to them, that is released in
202 // ReleaseBuffers. 201 // ReleaseBuffers.
203 // YUV 4:2:0 202 // YUV 4:2:0
204 int uv_width = info.width / 2; 203 int uv_width = info.width / 2;
205 int uv_height = info.height / 2; 204 int uv_height = info.height / 2;
206 size_t size = info.width * info.height + 2 * uv_width * uv_height; 205 size_t size = info.width * info.height + 2 * uv_width * uv_height;
207 scoped_array<PP_Resource> resources(new PP_Resource[buffer_count_hint_]); 206 scoped_array<PP_Resource> resources(new PP_Resource[buffer_count_hint_]);
208 207
209 buffers_.reserve(buffer_count_hint_); 208 buffers_.reserve(buffer_count_hint_);
210 for (size_t i = 0; i < buffer_count_hint_; ++i) { 209 for (size_t i = 0; i < buffer_count_hint_; ++i) {
211 resources[i] = PPB_Buffer_Impl::Create(instance(), size); 210 resources[i] = PPB_Buffer_Impl::Create(pp_instance(), size);
212 if (!resources[i]) 211 if (!resources[i])
213 break; 212 break;
214 213
215 EnterResourceNoLock<PPB_Buffer_API> enter(resources[i], true); 214 EnterResourceNoLock<PPB_Buffer_API> enter(resources[i], true);
216 DCHECK(enter.succeeded()); 215 DCHECK(enter.succeeded());
217 216
218 BufferInfo info; 217 BufferInfo info;
219 info.buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); 218 info.buffer = static_cast<PPB_Buffer_Impl*>(enter.object());
220 info.data = info.buffer->Map(); 219 info.data = info.buffer->Map();
221 if (!info.data) { 220 if (!info.data) {
222 ResourceTracker::Get()->ReleaseResource(resources[i]); 221 ResourceTracker::Get()->ReleaseResource(resources[i]);
223 break; 222 break;
224 } 223 }
225 buffers_.push_back(info); 224 buffers_.push_back(info);
226 } 225 }
227 226
228 if (buffers_.empty()) { 227 if (buffers_.empty()) {
229 // We couldn't allocate/map buffers at all. Send an error and stop the 228 // We couldn't allocate/map buffers at all. Send an error and stop the
230 // capture. 229 // capture.
231 ppp_videocapture_->OnError(instance()->pp_instance(), 230 ppp_videocapture_->OnError(pp_instance(), pp_resource(), PP_ERROR_NOMEMORY);
232 ScopedResourceId(this).id,
233 PP_ERROR_NOMEMORY);
234 status_ = PP_VIDEO_CAPTURE_STATUS_STOPPING; 231 status_ = PP_VIDEO_CAPTURE_STATUS_STOPPING;
235 platform_video_capture_->StopCapture(this); 232 platform_video_capture_->StopCapture(this);
236 return; 233 return;
237 } 234 }
238 235
239 ppp_videocapture_->OnDeviceInfo(instance()->pp_instance(), 236 ppp_videocapture_->OnDeviceInfo(pp_instance(), pp_resource(), &info,
240 ScopedResourceId(this).id, 237 buffers_.size(), resources.get());
241 &info,
242 buffers_.size(),
243 resources.get());
244 } 238 }
245 239
246 void PPB_VideoCapture_Impl::ReleaseBuffers() { 240 void PPB_VideoCapture_Impl::ReleaseBuffers() {
247 ResourceTracker *tracker = ResourceTracker::Get(); 241 ResourceTracker *tracker = ResourceTracker::Get();
248 for (size_t i = 0; i < buffers_.size(); ++i) { 242 for (size_t i = 0; i < buffers_.size(); ++i) {
249 buffers_[i].buffer->Unmap(); 243 buffers_[i].buffer->Unmap();
250 tracker->ReleaseResource(buffers_[i].buffer->pp_resource()); 244 tracker->ReleaseResource(buffers_[i].buffer->pp_resource());
251 } 245 }
252 buffers_.clear(); 246 buffers_.clear();
253 } 247 }
254 248
255 void PPB_VideoCapture_Impl::SendStatus() { 249 void PPB_VideoCapture_Impl::SendStatus() {
256 ppp_videocapture_->OnStatus(instance()->pp_instance(), 250 ppp_videocapture_->OnStatus(pp_instance(), pp_resource(), status_);
257 ScopedResourceId(this).id,
258 status_);
259 } 251 }
260 252
261 PPB_VideoCapture_Impl::BufferInfo::BufferInfo() 253 PPB_VideoCapture_Impl::BufferInfo::BufferInfo()
262 : in_use(false), 254 : in_use(false),
263 data(NULL), 255 data(NULL),
264 buffer() { 256 buffer() {
265 } 257 }
266 258
267 PPB_VideoCapture_Impl::BufferInfo::~BufferInfo() { 259 PPB_VideoCapture_Impl::BufferInfo::~BufferInfo() {
268 } 260 }
269 261
270 } // namespace ppapi 262 } // namespace ppapi
271 } // namespace webkit 263 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_video_capture_impl.h ('k') | webkit/plugins/ppapi/ppb_video_decoder_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698