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

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: Fix self-assignment 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 ppp_videocapture_ = static_cast<const PPP_VideoCapture_Dev*>(
44 GetPluginInterface(PPP_VIDEO_CAPTURE_DEV_INTERFACE)); 45 instance->module()->GetPluginInterface(PPP_VIDEO_CAPTURE_DEV_INTERFACE));
45 if (!ppp_videocapture_) 46 if (!ppp_videocapture_)
46 return false; 47 return false;
47 48
48 platform_video_capture_.reset( 49 platform_video_capture_.reset(
49 instance()->delegate()->CreateVideoCapture(this)); 50 instance->delegate()->CreateVideoCapture(this));
50 return !!platform_video_capture_.get(); 51 return !!platform_video_capture_.get();
51 } 52 }
52 53
53 PPB_VideoCapture_API* PPB_VideoCapture_Impl::AsPPB_VideoCapture_API() { 54 PPB_VideoCapture_API* PPB_VideoCapture_Impl::AsPPB_VideoCapture_API() {
54 return this; 55 return this;
55 } 56 }
56 57
57 int32_t PPB_VideoCapture_Impl::StartCapture( 58 int32_t PPB_VideoCapture_Impl::StartCapture(
58 const PP_VideoCaptureDeviceInfo_Dev& requested_info, 59 const PP_VideoCaptureDeviceInfo_Dev& requested_info,
59 uint32_t buffer_count) { 60 uint32_t buffer_count) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 155 }
155 156
156 void PPB_VideoCapture_Impl::OnError(media::VideoCapture* capture, 157 void PPB_VideoCapture_Impl::OnError(media::VideoCapture* capture,
157 int error_code) { 158 int error_code) {
158 // Today, the media layer only sends "1" as an error. 159 // Today, the media layer only sends "1" as an error.
159 DCHECK(error_code == 1); 160 DCHECK(error_code == 1);
160 // It either comes because some error was detected while starting (e.g. 2 161 // It either comes because some error was detected while starting (e.g. 2
161 // conflicting "master" resolution), or because the browser failed to start 162 // conflicting "master" resolution), or because the browser failed to start
162 // the capture. 163 // the capture.
163 status_ = PP_VIDEO_CAPTURE_STATUS_STOPPED; 164 status_ = PP_VIDEO_CAPTURE_STATUS_STOPPED;
164 ppp_videocapture_->OnError(instance()->pp_instance(), 165 ppp_videocapture_->OnError(pp_instance(), pp_resource(), PP_ERROR_FAILED);
165 ScopedResourceId(this).id,
166 PP_ERROR_FAILED);
167 } 166 }
168 167
169 void PPB_VideoCapture_Impl::OnBufferReady( 168 void PPB_VideoCapture_Impl::OnBufferReady(
170 media::VideoCapture* capture, 169 media::VideoCapture* capture,
171 scoped_refptr<media::VideoCapture::VideoFrameBuffer> buffer) { 170 scoped_refptr<media::VideoCapture::VideoFrameBuffer> buffer) {
172 DCHECK(buffer.get()); 171 DCHECK(buffer.get());
173 for (uint32_t i = 0; i < buffers_.size(); ++i) { 172 for (uint32_t i = 0; i < buffers_.size(); ++i) {
174 if (!buffers_[i].in_use) { 173 if (!buffers_[i].in_use) {
175 // TODO(piman): it looks like stride isn't actually used/filled. 174 // TODO(piman): it looks like stride isn't actually used/filled.
176 DCHECK(buffer->stride == 0); 175 DCHECK(buffer->stride == 0);
177 size_t size = std::min(static_cast<size_t>(buffers_[i].buffer->size()), 176 size_t size = std::min(static_cast<size_t>(buffers_[i].buffer->size()),
178 buffer->buffer_size); 177 buffer->buffer_size);
179 memcpy(buffers_[i].data, buffer->memory_pointer, size); 178 memcpy(buffers_[i].data, buffer->memory_pointer, size);
180 platform_video_capture_->FeedBuffer(buffer); 179 platform_video_capture_->FeedBuffer(buffer);
181 ppp_videocapture_->OnBufferReady(instance()->pp_instance(), 180 ppp_videocapture_->OnBufferReady(pp_instance(), pp_resource(), i);
182 ScopedResourceId(this).id,
183 i);
184 return; 181 return;
185 } 182 }
186 } 183 }
187 // TODO(piman): signal dropped buffers ? 184 // TODO(piman): signal dropped buffers ?
188 platform_video_capture_->FeedBuffer(buffer); 185 platform_video_capture_->FeedBuffer(buffer);
189 } 186 }
190 187
191 void PPB_VideoCapture_Impl::OnDeviceInfoReceived( 188 void PPB_VideoCapture_Impl::OnDeviceInfoReceived(
192 media::VideoCapture* capture, 189 media::VideoCapture* capture,
193 const media::VideoCaptureParams& device_info) { 190 const media::VideoCaptureParams& device_info) {
194 PP_VideoCaptureDeviceInfo_Dev info = { 191 PP_VideoCaptureDeviceInfo_Dev info = {
195 device_info.width, 192 device_info.width,
196 device_info.height, 193 device_info.height,
197 device_info.frame_per_second 194 device_info.frame_per_second
198 }; 195 };
199 ReleaseBuffers(); 196 ReleaseBuffers();
200 197
201 // Allocate buffers. We keep a reference to them, that is released in 198 // Allocate buffers. We keep a reference to them, that is released in
202 // ReleaseBuffers. 199 // ReleaseBuffers.
203 // YUV 4:2:0 200 // YUV 4:2:0
204 int uv_width = info.width / 2; 201 int uv_width = info.width / 2;
205 int uv_height = info.height / 2; 202 int uv_height = info.height / 2;
206 size_t size = info.width * info.height + 2 * uv_width * uv_height; 203 size_t size = info.width * info.height + 2 * uv_width * uv_height;
207 scoped_array<PP_Resource> resources(new PP_Resource[buffer_count_hint_]); 204 scoped_array<PP_Resource> resources(new PP_Resource[buffer_count_hint_]);
208 205
209 buffers_.reserve(buffer_count_hint_); 206 buffers_.reserve(buffer_count_hint_);
210 for (size_t i = 0; i < buffer_count_hint_; ++i) { 207 for (size_t i = 0; i < buffer_count_hint_; ++i) {
211 resources[i] = PPB_Buffer_Impl::Create(instance(), size); 208 resources[i] = PPB_Buffer_Impl::Create(pp_instance(), size);
212 if (!resources[i]) 209 if (!resources[i])
213 break; 210 break;
214 211
215 EnterResourceNoLock<PPB_Buffer_API> enter(resources[i], true); 212 EnterResourceNoLock<PPB_Buffer_API> enter(resources[i], true);
216 DCHECK(enter.succeeded()); 213 DCHECK(enter.succeeded());
217 214
218 BufferInfo info; 215 BufferInfo info;
219 info.buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); 216 info.buffer = static_cast<PPB_Buffer_Impl*>(enter.object());
220 info.data = info.buffer->Map(); 217 info.data = info.buffer->Map();
221 if (!info.data) { 218 if (!info.data) {
222 ResourceTracker::Get()->ReleaseResource(resources[i]); 219 ResourceTracker::Get()->ReleaseResource(resources[i]);
223 break; 220 break;
224 } 221 }
225 buffers_.push_back(info); 222 buffers_.push_back(info);
226 } 223 }
227 224
228 if (buffers_.empty()) { 225 if (buffers_.empty()) {
229 // We couldn't allocate/map buffers at all. Send an error and stop the 226 // We couldn't allocate/map buffers at all. Send an error and stop the
230 // capture. 227 // capture.
231 ppp_videocapture_->OnError(instance()->pp_instance(), 228 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; 229 status_ = PP_VIDEO_CAPTURE_STATUS_STOPPING;
235 platform_video_capture_->StopCapture(this); 230 platform_video_capture_->StopCapture(this);
236 return; 231 return;
237 } 232 }
238 233
239 ppp_videocapture_->OnDeviceInfo(instance()->pp_instance(), 234 ppp_videocapture_->OnDeviceInfo(pp_instance(), pp_resource(), &info,
240 ScopedResourceId(this).id, 235 buffers_.size(), resources.get());
241 &info,
242 buffers_.size(),
243 resources.get());
244 } 236 }
245 237
246 void PPB_VideoCapture_Impl::ReleaseBuffers() { 238 void PPB_VideoCapture_Impl::ReleaseBuffers() {
247 ResourceTracker *tracker = ResourceTracker::Get(); 239 ResourceTracker *tracker = ResourceTracker::Get();
248 for (size_t i = 0; i < buffers_.size(); ++i) { 240 for (size_t i = 0; i < buffers_.size(); ++i) {
249 buffers_[i].buffer->Unmap(); 241 buffers_[i].buffer->Unmap();
250 tracker->ReleaseResource(buffers_[i].buffer->pp_resource()); 242 tracker->ReleaseResource(buffers_[i].buffer->pp_resource());
251 } 243 }
252 buffers_.clear(); 244 buffers_.clear();
253 } 245 }
254 246
255 void PPB_VideoCapture_Impl::SendStatus() { 247 void PPB_VideoCapture_Impl::SendStatus() {
256 ppp_videocapture_->OnStatus(instance()->pp_instance(), 248 ppp_videocapture_->OnStatus(pp_instance(), pp_resource(), status_);
257 ScopedResourceId(this).id,
258 status_);
259 } 249 }
260 250
261 PPB_VideoCapture_Impl::BufferInfo::BufferInfo() 251 PPB_VideoCapture_Impl::BufferInfo::BufferInfo()
262 : in_use(false), 252 : in_use(false),
263 data(NULL), 253 data(NULL),
264 buffer() { 254 buffer() {
265 } 255 }
266 256
267 PPB_VideoCapture_Impl::BufferInfo::~BufferInfo() { 257 PPB_VideoCapture_Impl::BufferInfo::~BufferInfo() {
268 } 258 }
269 259
270 } // namespace ppapi 260 } // namespace ppapi
271 } // namespace webkit 261 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698