| 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 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc | 266 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc |
| 266 TRACE_EVENT_INSTANT2( | 267 TRACE_EVENT_INSTANT2( |
| 267 "cast_perf_test", "OnBufferReceived", | 268 "cast_perf_test", "OnBufferReceived", |
| 268 TRACE_EVENT_SCOPE_THREAD, | 269 TRACE_EVENT_SCOPE_THREAD, |
| 269 "timestamp", timestamp.ToInternalValue(), | 270 "timestamp", timestamp.ToInternalValue(), |
| 270 "time_delta", (timestamp - first_frame_timestamp_).ToInternalValue()); | 271 "time_delta", (timestamp - first_frame_timestamp_).ToInternalValue()); |
| 271 | 272 |
| 272 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); | 273 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); |
| 273 DCHECK(iter != client_buffers_.end()); | 274 DCHECK(iter != client_buffers_.end()); |
| 274 scoped_refptr<ClientBuffer> buffer = iter->second; | 275 scoped_refptr<ClientBuffer> buffer = iter->second; |
| 275 scoped_refptr<media::VideoFrame> frame = | 276 scoped_refptr<media::VideoFrame> frame = |
| 276 media::VideoFrame::WrapExternalPackedMemory( | 277 media::VideoFrame::WrapExternalPackedMemory( |
| 277 media::VideoFrame::I420, | 278 media::VideoFrame::I420, |
| 278 last_frame_format_.frame_size, | 279 last_frame_format_.frame_size, |
| 279 gfx::Rect(last_frame_format_.frame_size), | 280 gfx::Rect(last_frame_format_.frame_size), |
| 280 last_frame_format_.frame_size, | 281 last_frame_format_.frame_size, |
| 281 reinterpret_cast<uint8*>(buffer->buffer->memory()), | 282 reinterpret_cast<uint8*>(buffer->buffer->memory()), |
| 282 buffer->buffer_size, | 283 buffer->buffer_size, |
| 283 buffer->buffer->handle(), | 284 buffer->buffer->handle(), |
| 284 timestamp - first_frame_timestamp_, | 285 timestamp - first_frame_timestamp_, |
| 285 media::BindToCurrentLoop(base::Bind( | 286 media::BindToCurrentLoop( |
| 286 &VideoCaptureImpl::OnClientBufferFinished, | 287 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, |
| 287 weak_factory_.GetWeakPtr(), | 288 weak_factory_.GetWeakPtr(), |
| 288 buffer_id, | 289 buffer_id, |
| 289 buffer, | 290 buffer, |
| 290 base::Passed(scoped_ptr<gpu::MailboxHolder>().Pass())))); | 291 std::vector<uint32>()))); |
| 291 | 292 |
| 292 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) | 293 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) |
| 293 it->first->OnFrameReady(this, frame); | 294 it->first->OnFrameReady(this, frame); |
| 294 } | 295 } |
| 295 | 296 |
| 296 static void NullReadPixelsCB(const SkBitmap& bitmap) { NOTIMPLEMENTED(); } | 297 static void NullReadPixelsCB(const SkBitmap& bitmap) { NOTIMPLEMENTED(); } |
| 297 | 298 |
| 298 void VideoCaptureImpl::OnMailboxBufferReceived( | 299 void VideoCaptureImpl::OnMailboxBufferReceived( |
| 299 int buffer_id, | 300 int buffer_id, |
| 300 const gpu::MailboxHolder& mailbox_holder, | 301 const gpu::MailboxHolder& mailbox_holder, |
| 301 const media::VideoCaptureFormat& format, | 302 const media::VideoCaptureFormat& format, |
| 302 base::TimeTicks timestamp) { | 303 base::TimeTicks timestamp) { |
| 303 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 304 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 304 | 305 |
| 305 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { | 306 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { |
| 306 Send(new VideoCaptureHostMsg_BufferReady( | 307 Send(new VideoCaptureHostMsg_BufferReady( |
| 307 device_id_, buffer_id, mailbox_holder.sync_point)); | 308 device_id_, buffer_id, std::vector<uint32>())); |
| 308 return; | 309 return; |
| 309 } | 310 } |
| 310 | 311 |
| 311 last_frame_format_ = format; | 312 last_frame_format_ = format; |
| 312 if (first_frame_timestamp_.is_null()) | 313 if (first_frame_timestamp_.is_null()) |
| 313 first_frame_timestamp_ = timestamp; | 314 first_frame_timestamp_ = timestamp; |
| 314 | 315 |
| 315 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::WrapNativeTexture( | 316 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::WrapNativeTexture( |
| 316 make_scoped_ptr(new gpu::MailboxHolder(mailbox_holder)), | 317 make_scoped_ptr(new gpu::MailboxHolder(mailbox_holder)), |
| 317 media::BindToCurrentLoop( | 318 media::BindToCurrentLoop( |
| 318 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, | 319 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, |
| 319 weak_factory_.GetWeakPtr(), | 320 weak_factory_.GetWeakPtr(), |
| 320 buffer_id, | 321 buffer_id, |
| 321 scoped_refptr<ClientBuffer>())), | 322 scoped_refptr<ClientBuffer>())), |
| 322 last_frame_format_.frame_size, | 323 last_frame_format_.frame_size, |
| 323 gfx::Rect(last_frame_format_.frame_size), | 324 gfx::Rect(last_frame_format_.frame_size), |
| 324 last_frame_format_.frame_size, | 325 last_frame_format_.frame_size, |
| 325 timestamp - first_frame_timestamp_, | 326 timestamp - first_frame_timestamp_, |
| 326 base::Bind(&NullReadPixelsCB)); | 327 base::Bind(&NullReadPixelsCB)); |
| 327 | 328 |
| 328 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) | 329 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) |
| 329 it->first->OnFrameReady(this, frame); | 330 it->first->OnFrameReady(this, frame); |
| 330 } | 331 } |
| 331 | 332 |
| 332 void VideoCaptureImpl::OnClientBufferFinished( | 333 void VideoCaptureImpl::OnClientBufferFinished( |
| 333 int buffer_id, | 334 int buffer_id, |
| 334 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, | 335 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, |
| 335 scoped_ptr<gpu::MailboxHolder> mailbox_holder) { | 336 const std::vector<uint32>& release_sync_points) { |
| 336 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 337 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 337 const uint32 sync_point = (mailbox_holder ? mailbox_holder->sync_point : 0); | 338 Send(new VideoCaptureHostMsg_BufferReady( |
| 338 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, sync_point)); | 339 device_id_, buffer_id, release_sync_points)); |
| 339 } | 340 } |
| 340 | 341 |
| 341 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { | 342 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { |
| 342 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 343 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 343 | 344 |
| 344 switch (state) { | 345 switch (state) { |
| 345 case VIDEO_CAPTURE_STATE_STARTED: | 346 case VIDEO_CAPTURE_STATE_STARTED: |
| 346 break; | 347 break; |
| 347 case VIDEO_CAPTURE_STATE_STOPPED: | 348 case VIDEO_CAPTURE_STATE_STOPPED: |
| 348 state_ = VIDEO_CAPTURE_STATE_STOPPED; | 349 state_ = VIDEO_CAPTURE_STATE_STOPPED; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 if (it != clients->end()) { | 472 if (it != clients->end()) { |
| 472 handler->OnStopped(this); | 473 handler->OnStopped(this); |
| 473 handler->OnRemoved(this); | 474 handler->OnRemoved(this); |
| 474 clients->erase(it); | 475 clients->erase(it); |
| 475 found = true; | 476 found = true; |
| 476 } | 477 } |
| 477 return found; | 478 return found; |
| 478 } | 479 } |
| 479 | 480 |
| 480 } // namespace content | 481 } // namespace content |
| OLD | NEW |