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 "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" |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 ppp_videocapture_->OnError(pp_instance(), pp_resource(), PP_ERROR_FAILED); | 202 ppp_videocapture_->OnError(pp_instance(), pp_resource(), PP_ERROR_FAILED); |
203 } | 203 } |
204 | 204 |
205 void PPB_VideoCapture_Impl::OnRemoved(media::VideoCapture* capture) { | 205 void PPB_VideoCapture_Impl::OnRemoved(media::VideoCapture* capture) { |
206 Release(); | 206 Release(); |
207 } | 207 } |
208 | 208 |
209 void PPB_VideoCapture_Impl::OnBufferReady( | 209 void PPB_VideoCapture_Impl::OnBufferReady( |
210 media::VideoCapture* capture, | 210 media::VideoCapture* capture, |
211 scoped_refptr<media::VideoCapture::VideoFrameBuffer> buffer) { | 211 scoped_refptr<media::VideoCapture::VideoFrameBuffer> buffer) { |
212 if (is_dead_) | 212 if (!is_dead_) { |
213 return; | 213 DCHECK(buffer.get()); |
214 | 214 for (uint32_t i = 0; i < buffers_.size(); ++i) { |
215 DCHECK(buffer.get()); | 215 if (!buffers_[i].in_use) { |
216 for (uint32_t i = 0; i < buffers_.size(); ++i) { | 216 // TODO(ihf): Switch to a size calculation based on stride. |
217 if (!buffers_[i].in_use) { | 217 // Stride is filled out now but not more meaningful than size |
218 // TODO(piman): it looks like stride isn't actually used/filled. | 218 // until wjia unifies VideoFrameBuffer and media::VideoFrame. |
219 DCHECK(buffer->stride == 0); | 219 size_t size = std::min(static_cast<size_t>(buffers_[i].buffer->size()), |
220 size_t size = std::min(static_cast<size_t>(buffers_[i].buffer->size()), | 220 buffer->buffer_size); |
221 buffer->buffer_size); | 221 memcpy(buffers_[i].data, buffer->memory_pointer, size); |
222 memcpy(buffers_[i].data, buffer->memory_pointer, size); | 222 buffers_[i].in_use = true; |
223 buffers_[i].in_use = true; | 223 platform_video_capture_->FeedBuffer(buffer); |
224 platform_video_capture_->FeedBuffer(buffer); | 224 ppp_videocapture_->OnBufferReady(pp_instance(), pp_resource(), i); |
225 ppp_videocapture_->OnBufferReady(pp_instance(), pp_resource(), i); | 225 return; |
226 return; | 226 } |
227 } | 227 } |
228 } | 228 } |
229 // TODO(piman): signal dropped buffers ? | 229 // Even after we have stopped and are dead we have to return buffers that |
| 230 // are in flight to us. Otherwise VideoCaptureController will not tear down. |
230 platform_video_capture_->FeedBuffer(buffer); | 231 platform_video_capture_->FeedBuffer(buffer); |
231 } | 232 } |
232 | 233 |
233 void PPB_VideoCapture_Impl::OnDeviceInfoReceived( | 234 void PPB_VideoCapture_Impl::OnDeviceInfoReceived( |
234 media::VideoCapture* capture, | 235 media::VideoCapture* capture, |
235 const media::VideoCaptureParams& device_info) { | 236 const media::VideoCaptureParams& device_info) { |
236 // No need to call |ReleaseBuffers()|: if we're dead, |StopCapture()| should | 237 // No need to call |ReleaseBuffers()|: if we're dead, |StopCapture()| should |
237 // already have been called. | 238 // already have been called. |
238 if (is_dead_) | 239 if (is_dead_) |
239 return; | 240 return; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 : in_use(false), | 305 : in_use(false), |
305 data(NULL), | 306 data(NULL), |
306 buffer() { | 307 buffer() { |
307 } | 308 } |
308 | 309 |
309 PPB_VideoCapture_Impl::BufferInfo::~BufferInfo() { | 310 PPB_VideoCapture_Impl::BufferInfo::~BufferInfo() { |
310 } | 311 } |
311 | 312 |
312 } // namespace ppapi | 313 } // namespace ppapi |
313 } // namespace webkit | 314 } // namespace webkit |
OLD | NEW |