| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/browser/renderer_host/media/video_capture_texture_wrapper.h" | 5 #include "content/browser/renderer_host/media/video_capture_texture_wrapper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_to_current_loop.h" |
| 8 #include "content/browser/compositor/image_transport_factory.h" | 9 #include "content/browser/compositor/image_transport_factory.h" |
| 9 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 10 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
| 10 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 11 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
| 11 #include "content/browser/gpu/gpu_data_manager_impl.h" | 12 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 12 #include "content/browser/renderer_host/media/video_capture_controller.h" | 13 #include "content/browser/renderer_host/media/video_capture_controller.h" |
| 13 #include "content/common/gpu/client/context_provider_command_buffer.h" | 14 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 14 #include "content/common/gpu/client/gl_helper.h" | 15 #include "content/common/gpu/client/gl_helper.h" |
| 15 #include "content/common/gpu/client/gpu_channel_host.h" | 16 #include "content/common/gpu/client/gpu_channel_host.h" |
| 16 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 17 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 17 #include "content/common/gpu/gpu_process_launch_causes.h" | 18 #include "content/common/gpu/gpu_process_launch_causes.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 #include "gpu/command_buffer/common/mailbox_holder.h" | 20 #include "gpu/command_buffer/common/mailbox_holder.h" |
| 20 #include "media/base/bind_to_current_loop.h" | |
| 21 #include "media/base/video_capture_types.h" | 21 #include "media/base/video_capture_types.h" |
| 22 #include "media/base/video_frame.h" | 22 #include "media/base/video_frame.h" |
| 23 #include "third_party/khronos/GLES2/gl2ext.h" | 23 #include "third_party/khronos/GLES2/gl2ext.h" |
| 24 #include "third_party/libyuv/include/libyuv.h" | 24 #include "third_party/libyuv/include/libyuv.h" |
| 25 | 25 |
| 26 namespace content { | 26 namespace content { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // VideoCaptureController has at most 3 capture frames in flight. | 30 // VideoCaptureController has at most 3 capture frames in flight. |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 scoped_ptr<gpu::MailboxHolder> mailbox_holder(new gpu::MailboxHolder( | 314 scoped_ptr<gpu::MailboxHolder> mailbox_holder(new gpu::MailboxHolder( |
| 315 gl_helper_->ProduceMailboxHolderFromTexture(texture_id))); | 315 gl_helper_->ProduceMailboxHolderFromTexture(texture_id))); |
| 316 DCHECK(!mailbox_holder->mailbox.IsZero()); | 316 DCHECK(!mailbox_holder->mailbox.IsZero()); |
| 317 DCHECK(mailbox_holder->mailbox.Verify()); | 317 DCHECK(mailbox_holder->mailbox.Verify()); |
| 318 DCHECK(mailbox_holder->texture_target); | 318 DCHECK(mailbox_holder->texture_target); |
| 319 DCHECK(mailbox_holder->sync_point); | 319 DCHECK(mailbox_holder->sync_point); |
| 320 | 320 |
| 321 scoped_refptr<media::VideoFrame> video_frame = | 321 scoped_refptr<media::VideoFrame> video_frame = |
| 322 media::VideoFrame::WrapNativeTexture( | 322 media::VideoFrame::WrapNativeTexture( |
| 323 mailbox_holder.Pass(), | 323 mailbox_holder.Pass(), |
| 324 media::BindToCurrentLoop( | 324 base::BindToCurrentLoop( |
| 325 base::Bind(&VideoCaptureTextureWrapper::TextureWrapperDelegate:: | 325 base::Bind(&VideoCaptureTextureWrapper::TextureWrapperDelegate:: |
| 326 ReleaseCallback, | 326 ReleaseCallback, |
| 327 this, image_id, texture_id, gpu_memory_buffer)), | 327 this, image_id, texture_id, gpu_memory_buffer)), |
| 328 frame_size, | 328 frame_size, |
| 329 gfx::Rect(frame_size), | 329 gfx::Rect(frame_size), |
| 330 frame_size, | 330 frame_size, |
| 331 base::TimeDelta(), | 331 base::TimeDelta(), |
| 332 true /* allow_overlay */); | 332 true /* allow_overlay */); |
| 333 | 333 |
| 334 BrowserThread::PostTask( | 334 BrowserThread::PostTask( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 gpu_memory_buffers_.push(gpu_memory_buffer); | 383 gpu_memory_buffers_.push(gpu_memory_buffer); |
| 384 } | 384 } |
| 385 | 385 |
| 386 // In threaded compositing mode, we have to create our own context for Capture | 386 // In threaded compositing mode, we have to create our own context for Capture |
| 387 // to avoid using the GPU command queue from multiple threads. Context | 387 // to avoid using the GPU command queue from multiple threads. Context |
| 388 // creation must happen on UI thread; then the context needs to be bound to | 388 // creation must happen on UI thread; then the context needs to be bound to |
| 389 // the appropriate thread, which is done in CreateGlHelper(). | 389 // the appropriate thread, which is done in CreateGlHelper(). |
| 390 BrowserThread::PostTask( | 390 BrowserThread::PostTask( |
| 391 BrowserThread::UI, FROM_HERE, | 391 BrowserThread::UI, FROM_HERE, |
| 392 base::Bind(&CreateContextOnUIThread, | 392 base::Bind(&CreateContextOnUIThread, |
| 393 media::BindToCurrentLoop( | 393 base::BindToCurrentLoop( |
| 394 base::Bind(&VideoCaptureTextureWrapper:: | 394 base::Bind(&VideoCaptureTextureWrapper:: |
| 395 TextureWrapperDelegate::CreateGlHelper, | 395 TextureWrapperDelegate::CreateGlHelper, |
| 396 this)))); | 396 this)))); |
| 397 } | 397 } |
| 398 | 398 |
| 399 void VideoCaptureTextureWrapper::TextureWrapperDelegate::CreateGlHelper( | 399 void VideoCaptureTextureWrapper::TextureWrapperDelegate::CreateGlHelper( |
| 400 scoped_refptr<ContextProviderCommandBuffer> capture_thread_context) { | 400 scoped_refptr<ContextProviderCommandBuffer> capture_thread_context) { |
| 401 DCHECK(capture_task_runner_->BelongsToCurrentThread()); | 401 DCHECK(capture_task_runner_->BelongsToCurrentThread()); |
| 402 | 402 |
| 403 if (!capture_thread_context.get()) { | 403 if (!capture_thread_context.get()) { |
| 404 DLOG(ERROR) << "No offscreen GL Context!"; | 404 DLOG(ERROR) << "No offscreen GL Context!"; |
| 405 return; | 405 return; |
| 406 } | 406 } |
| 407 // This may not happen in IO Thread. The destructor resets the context lost | 407 // This may not happen in IO Thread. The destructor resets the context lost |
| 408 // callback, so base::Unretained is safe; otherwise it'd be a circular ref | 408 // callback, so base::Unretained is safe; otherwise it'd be a circular ref |
| 409 // counted dependency. | 409 // counted dependency. |
| 410 capture_thread_context->SetLostContextCallback(media::BindToCurrentLoop( | 410 capture_thread_context->SetLostContextCallback(base::BindToCurrentLoop( |
| 411 base::Bind( | 411 base::Bind( |
| 412 &VideoCaptureTextureWrapper::TextureWrapperDelegate:: | 412 &VideoCaptureTextureWrapper::TextureWrapperDelegate:: |
| 413 LostContextCallback, | 413 LostContextCallback, |
| 414 base::Unretained(this)))); | 414 base::Unretained(this)))); |
| 415 if (!capture_thread_context->BindToCurrentThread()) { | 415 if (!capture_thread_context->BindToCurrentThread()) { |
| 416 capture_thread_context = NULL; | 416 capture_thread_context = NULL; |
| 417 DLOG(ERROR) << "Couldn't bind the Capture Context to the Capture Thread."; | 417 DLOG(ERROR) << "Couldn't bind the Capture Context to the Capture Thread."; |
| 418 return; | 418 return; |
| 419 } | 419 } |
| 420 DCHECK(capture_thread_context); | 420 DCHECK(capture_thread_context); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 void VideoCaptureTextureWrapper::TextureWrapperDelegate::OnError( | 454 void VideoCaptureTextureWrapper::TextureWrapperDelegate::OnError( |
| 455 const std::string& message) { | 455 const std::string& message) { |
| 456 DCHECK(capture_task_runner_->BelongsToCurrentThread()); | 456 DCHECK(capture_task_runner_->BelongsToCurrentThread()); |
| 457 DLOG(ERROR) << message; | 457 DLOG(ERROR) << message; |
| 458 BrowserThread::PostTask( | 458 BrowserThread::PostTask( |
| 459 BrowserThread::IO, FROM_HERE, | 459 BrowserThread::IO, FROM_HERE, |
| 460 base::Bind(&VideoCaptureController::DoErrorOnIOThread, controller_)); | 460 base::Bind(&VideoCaptureController::DoErrorOnIOThread, controller_)); |
| 461 } | 461 } |
| 462 | 462 |
| 463 } // namespace content | 463 } // namespace content |
| OLD | NEW |