OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/media/video_capture_impl.h" | 5 #include "content/renderer/media/video_capture_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "content/child/child_process.h" | 9 #include "content/child/child_process.h" |
10 #include "content/common/media/video_capture_messages.h" | 10 #include "content/common/media/video_capture_messages.h" |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 | 247 |
248 void VideoCaptureImpl::OnBufferReceived(int buffer_id, | 248 void VideoCaptureImpl::OnBufferReceived(int buffer_id, |
249 const media::VideoCaptureFormat& format, | 249 const media::VideoCaptureFormat& format, |
250 base::TimeTicks timestamp) { | 250 base::TimeTicks timestamp) { |
251 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 251 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
252 | 252 |
253 // The capture pipeline supports only I420 for now. | 253 // The capture pipeline supports only I420 for now. |
254 DCHECK_EQ(format.pixel_format, media::PIXEL_FORMAT_I420); | 254 DCHECK_EQ(format.pixel_format, media::PIXEL_FORMAT_I420); |
255 | 255 |
256 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { | 256 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { |
257 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, 0)); | 257 Send(new VideoCaptureHostMsg_BufferReady( |
258 device_id_, buffer_id, std::vector<uint32>())); | |
258 return; | 259 return; |
259 } | 260 } |
260 | 261 |
261 last_frame_format_ = format; | 262 last_frame_format_ = format; |
262 if (first_frame_timestamp_.is_null()) | 263 if (first_frame_timestamp_.is_null()) |
263 first_frame_timestamp_ = timestamp; | 264 first_frame_timestamp_ = timestamp; |
264 | 265 |
265 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); | 266 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); |
266 DCHECK(iter != client_buffers_.end()); | 267 DCHECK(iter != client_buffers_.end()); |
267 scoped_refptr<ClientBuffer> buffer = iter->second; | 268 scoped_refptr<ClientBuffer> buffer = iter->second; |
268 scoped_refptr<media::VideoFrame> frame = | 269 scoped_refptr<media::VideoFrame> frame = |
269 media::VideoFrame::WrapExternalPackedMemory( | 270 media::VideoFrame::WrapExternalPackedMemory( |
270 media::VideoFrame::I420, | 271 media::VideoFrame::I420, |
271 last_frame_format_.frame_size, | 272 last_frame_format_.frame_size, |
272 gfx::Rect(last_frame_format_.frame_size), | 273 gfx::Rect(last_frame_format_.frame_size), |
273 last_frame_format_.frame_size, | 274 last_frame_format_.frame_size, |
274 reinterpret_cast<uint8*>(buffer->buffer->memory()), | 275 reinterpret_cast<uint8*>(buffer->buffer->memory()), |
275 buffer->buffer_size, | 276 buffer->buffer_size, |
276 buffer->buffer->handle(), | 277 buffer->buffer->handle(), |
277 timestamp - first_frame_timestamp_, | 278 timestamp - first_frame_timestamp_, |
278 media::BindToCurrentLoop(base::Bind( | 279 media::BindToCurrentLoop( |
279 &VideoCaptureImpl::OnClientBufferFinished, | 280 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, |
280 weak_this_factory_.GetWeakPtr(), | 281 weak_this_factory_.GetWeakPtr(), |
281 buffer_id, | 282 buffer_id, |
282 buffer, | 283 buffer, |
283 base::Passed(scoped_ptr<gpu::MailboxHolder>().Pass())))); | 284 base::Passed(scoped_ptr<gpu::MailboxHolder>().Pass()), |
285 std::vector<uint32>()))); | |
284 | 286 |
285 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) | 287 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) |
286 it->first->OnFrameReady(this, frame); | 288 it->first->OnFrameReady(this, frame); |
287 } | 289 } |
288 | 290 |
289 static void NullReadPixelsCB(const SkBitmap& bitmap) { NOTIMPLEMENTED(); } | 291 // TODO(dshwang): implement it. |
292 static void NullReadPixelsCB(const scoped_refptr<media::VideoFrame>&, | |
293 const SkBitmap& bitmap) { | |
294 NOTIMPLEMENTED(); | |
dshwang
2014/03/10 17:38:08
Now GpuVideoAcceleratorFactories::ReadPixels() rec
| |
295 } | |
290 | 296 |
291 void VideoCaptureImpl::OnMailboxBufferReceived( | 297 void VideoCaptureImpl::OnMailboxBufferReceived( |
292 int buffer_id, | 298 int buffer_id, |
293 const gpu::MailboxHolder& mailbox_holder, | 299 const gpu::MailboxHolder& mailbox_holder, |
294 const media::VideoCaptureFormat& format, | 300 const media::VideoCaptureFormat& format, |
295 base::TimeTicks timestamp) { | 301 base::TimeTicks timestamp) { |
296 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 302 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
297 | 303 |
298 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { | 304 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { |
299 Send(new VideoCaptureHostMsg_BufferReady( | 305 Send(new VideoCaptureHostMsg_BufferReady( |
300 device_id_, buffer_id, mailbox_holder.sync_point)); | 306 device_id_, buffer_id, std::vector<uint32>())); |
301 return; | 307 return; |
302 } | 308 } |
303 | 309 |
304 last_frame_format_ = format; | 310 last_frame_format_ = format; |
305 if (first_frame_timestamp_.is_null()) | 311 if (first_frame_timestamp_.is_null()) |
306 first_frame_timestamp_ = timestamp; | 312 first_frame_timestamp_ = timestamp; |
307 | 313 |
308 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::WrapNativeTexture( | 314 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::WrapNativeTexture( |
309 make_scoped_ptr(new gpu::MailboxHolder(mailbox_holder)), | 315 make_scoped_ptr(new gpu::MailboxHolder(mailbox_holder)), |
310 media::BindToCurrentLoop( | 316 media::BindToCurrentLoop( |
311 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, | 317 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, |
312 weak_this_factory_.GetWeakPtr(), | 318 weak_this_factory_.GetWeakPtr(), |
313 buffer_id, | 319 buffer_id, |
314 scoped_refptr<ClientBuffer>())), | 320 scoped_refptr<ClientBuffer>())), |
315 last_frame_format_.frame_size, | 321 last_frame_format_.frame_size, |
316 gfx::Rect(last_frame_format_.frame_size), | 322 gfx::Rect(last_frame_format_.frame_size), |
317 last_frame_format_.frame_size, | 323 last_frame_format_.frame_size, |
318 timestamp - first_frame_timestamp_, | 324 timestamp - first_frame_timestamp_, |
319 base::Bind(&NullReadPixelsCB)); | 325 base::Bind(&NullReadPixelsCB)); |
320 | 326 |
321 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) | 327 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) |
322 it->first->OnFrameReady(this, frame); | 328 it->first->OnFrameReady(this, frame); |
323 } | 329 } |
324 | 330 |
325 void VideoCaptureImpl::OnClientBufferFinished( | 331 void VideoCaptureImpl::OnClientBufferFinished( |
326 int buffer_id, | 332 int buffer_id, |
327 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, | 333 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, |
328 scoped_ptr<gpu::MailboxHolder> mailbox_holder) { | 334 scoped_ptr<gpu::MailboxHolder> mailbox_holder, |
335 const std::vector<uint32>& release_sync_points) { | |
329 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 336 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
330 const uint32 sync_point = (mailbox_holder ? mailbox_holder->sync_point : 0); | 337 Send(new VideoCaptureHostMsg_BufferReady( |
331 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, sync_point)); | 338 device_id_, buffer_id, release_sync_points)); |
332 } | 339 } |
333 | 340 |
334 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { | 341 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { |
335 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 342 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
336 | 343 |
337 switch (state) { | 344 switch (state) { |
338 case VIDEO_CAPTURE_STATE_STARTED: | 345 case VIDEO_CAPTURE_STATE_STARTED: |
339 break; | 346 break; |
340 case VIDEO_CAPTURE_STATE_STOPPED: | 347 case VIDEO_CAPTURE_STATE_STOPPED: |
341 state_ = VIDEO_CAPTURE_STATE_STOPPED; | 348 state_ = VIDEO_CAPTURE_STATE_STOPPED; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
464 if (it != clients->end()) { | 471 if (it != clients->end()) { |
465 handler->OnStopped(this); | 472 handler->OnStopped(this); |
466 handler->OnRemoved(this); | 473 handler->OnRemoved(this); |
467 clients->erase(it); | 474 clients->erase(it); |
468 found = true; | 475 found = true; |
469 } | 476 } |
470 return found; | 477 return found; |
471 } | 478 } |
472 | 479 |
473 } // namespace content | 480 } // namespace content |
OLD | NEW |