| 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(base::Bind( |
| 279 &VideoCaptureImpl::OnClientBufferFinished, | 280 &VideoCaptureImpl::OnClientBufferFinished, |
| 280 weak_factory_.GetWeakPtr(), | 281 weak_factory_.GetWeakPtr(), |
| 281 buffer_id, | 282 buffer_id, |
| 282 buffer, | 283 buffer, |
| 283 base::Passed(scoped_ptr<gpu::MailboxHolder>().Pass())))); | 284 std::vector<uint32>()))); |
| 284 | 285 |
| 285 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) | 286 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) |
| 286 it->first->OnFrameReady(this, frame); | 287 it->first->OnFrameReady(this, frame); |
| 287 } | 288 } |
| 288 | 289 |
| 289 static void NullReadPixelsCB(const SkBitmap& bitmap) { NOTIMPLEMENTED(); } | 290 static void NullReadPixelsCB(const SkBitmap& bitmap) { NOTIMPLEMENTED(); } |
| 290 | 291 |
| 291 void VideoCaptureImpl::OnMailboxBufferReceived( | 292 void VideoCaptureImpl::OnMailboxBufferReceived( |
| 292 int buffer_id, | 293 int buffer_id, |
| 293 const gpu::MailboxHolder& mailbox_holder, | 294 const gpu::MailboxHolder& mailbox_holder, |
| 294 const media::VideoCaptureFormat& format, | 295 const media::VideoCaptureFormat& format, |
| 295 base::TimeTicks timestamp) { | 296 base::TimeTicks timestamp) { |
| 296 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 297 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 297 | 298 |
| 298 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { | 299 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { |
| 299 Send(new VideoCaptureHostMsg_BufferReady( | 300 Send(new VideoCaptureHostMsg_BufferReady( |
| 300 device_id_, buffer_id, mailbox_holder.sync_point)); | 301 device_id_, buffer_id, std::vector<uint32>())); |
| 301 return; | 302 return; |
| 302 } | 303 } |
| 303 | 304 |
| 304 last_frame_format_ = format; | 305 last_frame_format_ = format; |
| 305 if (first_frame_timestamp_.is_null()) | 306 if (first_frame_timestamp_.is_null()) |
| 306 first_frame_timestamp_ = timestamp; | 307 first_frame_timestamp_ = timestamp; |
| 307 | 308 |
| 308 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::WrapNativeTexture( | 309 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::WrapNativeTexture( |
| 309 make_scoped_ptr(new gpu::MailboxHolder(mailbox_holder)), | 310 make_scoped_ptr(new gpu::MailboxHolder(mailbox_holder)), |
| 310 media::BindToCurrentLoop( | 311 media::BindToCurrentLoop( |
| 311 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, | 312 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, |
| 312 weak_factory_.GetWeakPtr(), | 313 weak_factory_.GetWeakPtr(), |
| 313 buffer_id, | 314 buffer_id, |
| 314 scoped_refptr<ClientBuffer>())), | 315 scoped_refptr<ClientBuffer>())), |
| 315 last_frame_format_.frame_size, | 316 last_frame_format_.frame_size, |
| 316 gfx::Rect(last_frame_format_.frame_size), | 317 gfx::Rect(last_frame_format_.frame_size), |
| 317 last_frame_format_.frame_size, | 318 last_frame_format_.frame_size, |
| 318 timestamp - first_frame_timestamp_, | 319 timestamp - first_frame_timestamp_, |
| 319 base::Bind(&NullReadPixelsCB)); | 320 base::Bind(&NullReadPixelsCB)); |
| 320 | 321 |
| 321 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) | 322 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) |
| 322 it->first->OnFrameReady(this, frame); | 323 it->first->OnFrameReady(this, frame); |
| 323 } | 324 } |
| 324 | 325 |
| 325 void VideoCaptureImpl::OnClientBufferFinished( | 326 void VideoCaptureImpl::OnClientBufferFinished( |
| 326 int buffer_id, | 327 int buffer_id, |
| 327 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, | 328 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, |
| 328 scoped_ptr<gpu::MailboxHolder> mailbox_holder) { | 329 const std::vector<uint32>& release_sync_points) { |
| 329 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 330 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 330 const uint32 sync_point = (mailbox_holder ? mailbox_holder->sync_point : 0); | 331 Send(new VideoCaptureHostMsg_BufferReady( |
| 331 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, sync_point)); | 332 device_id_, buffer_id, release_sync_points)); |
| 332 } | 333 } |
| 333 | 334 |
| 334 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { | 335 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { |
| 335 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 336 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 336 | 337 |
| 337 switch (state) { | 338 switch (state) { |
| 338 case VIDEO_CAPTURE_STATE_STARTED: | 339 case VIDEO_CAPTURE_STATE_STARTED: |
| 339 break; | 340 break; |
| 340 case VIDEO_CAPTURE_STATE_STOPPED: | 341 case VIDEO_CAPTURE_STATE_STOPPED: |
| 341 state_ = VIDEO_CAPTURE_STATE_STOPPED; | 342 state_ = VIDEO_CAPTURE_STATE_STOPPED; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 if (it != clients->end()) { | 465 if (it != clients->end()) { |
| 465 handler->OnStopped(this); | 466 handler->OnStopped(this); |
| 466 handler->OnRemoved(this); | 467 handler->OnRemoved(this); |
| 467 clients->erase(it); | 468 clients->erase(it); |
| 468 found = true; | 469 found = true; |
| 469 } | 470 } |
| 470 return found; | 471 return found; |
| 471 } | 472 } |
| 472 | 473 |
| 473 } // namespace content | 474 } // namespace content |
| OLD | NEW |