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 // Notes about usage of this object by VideoCaptureImplManager. | 5 // Notes about usage of this object by VideoCaptureImplManager. |
6 // | 6 // |
7 // VideoCaptureImplManager access this object by using a Unretained() | 7 // VideoCaptureImplManager access this object by using a Unretained() |
8 // binding and tasks on the IO thread. It is then important that | 8 // binding and tasks on the IO thread. It is then important that |
9 // VideoCaptureImpl never post task to itself. All operations must be | 9 // VideoCaptureImpl never post task to itself. All operations must be |
10 // synchronous. | 10 // synchronous. |
11 | 11 |
12 #include "content/renderer/media/video_capture_impl.h" | 12 #include "content/renderer/media/video_capture_impl.h" |
13 | 13 |
14 #include <stddef.h> | 14 #include <stddef.h> |
15 #include <utility> | 15 #include <utility> |
16 | 16 |
17 #include "base/bind.h" | 17 #include "base/bind.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
20 #include "base/thread_task_runner_handle.h" | 20 #include "base/thread_task_runner_handle.h" |
21 #include "content/child/child_process.h" | 21 #include "content/child/child_process.h" |
22 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" | |
23 #include "content/common/media/video_capture_messages.h" | 22 #include "content/common/media/video_capture_messages.h" |
| 23 #include "gpu/ipc/client/gpu_memory_buffer_impl.h" |
24 #include "media/base/bind_to_current_loop.h" | 24 #include "media/base/bind_to_current_loop.h" |
25 #include "media/base/limits.h" | 25 #include "media/base/limits.h" |
26 #include "media/base/video_frame.h" | 26 #include "media/base/video_frame.h" |
27 | 27 |
28 namespace content { | 28 namespace content { |
29 | 29 |
30 // A holder of a memory-backed buffer and accessors to it. | 30 // A holder of a memory-backed buffer and accessors to it. |
31 class VideoCaptureImpl::ClientBuffer | 31 class VideoCaptureImpl::ClientBuffer |
32 : public base::RefCountedThreadSafe<ClientBuffer> { | 32 : public base::RefCountedThreadSafe<ClientBuffer> { |
33 public: | 33 public: |
(...skipping 22 matching lines...) Expand all Loading... |
56 ClientBuffer2( | 56 ClientBuffer2( |
57 const std::vector<gfx::GpuMemoryBufferHandle>& client_handles, | 57 const std::vector<gfx::GpuMemoryBufferHandle>& client_handles, |
58 const gfx::Size& size) | 58 const gfx::Size& size) |
59 : handles_(client_handles), | 59 : handles_(client_handles), |
60 size_(size) { | 60 size_(size) { |
61 const media::VideoPixelFormat format = media::PIXEL_FORMAT_I420; | 61 const media::VideoPixelFormat format = media::PIXEL_FORMAT_I420; |
62 DCHECK_EQ(handles_.size(), media::VideoFrame::NumPlanes(format)); | 62 DCHECK_EQ(handles_.size(), media::VideoFrame::NumPlanes(format)); |
63 for (size_t i = 0; i < handles_.size(); ++i) { | 63 for (size_t i = 0; i < handles_.size(); ++i) { |
64 const size_t width = media::VideoFrame::Columns(i, format, size_.width()); | 64 const size_t width = media::VideoFrame::Columns(i, format, size_.width()); |
65 const size_t height = media::VideoFrame::Rows(i, format, size_.height()); | 65 const size_t height = media::VideoFrame::Rows(i, format, size_.height()); |
66 buffers_.push_back(GpuMemoryBufferImpl::CreateFromHandle( | 66 buffers_.push_back(gpu::GpuMemoryBufferImpl::CreateFromHandle( |
67 handles_[i], gfx::Size(width, height), gfx::BufferFormat::R_8, | 67 handles_[i], gfx::Size(width, height), gfx::BufferFormat::R_8, |
68 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, | 68 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, |
69 base::Bind(&ClientBuffer2::DestroyGpuMemoryBuffer, | 69 base::Bind(&ClientBuffer2::DestroyGpuMemoryBuffer, |
70 base::Unretained(this)))); | 70 base::Unretained(this)))); |
71 bool rv = buffers_[i]->Map(); | 71 bool rv = buffers_[i]->Map(); |
72 DCHECK(rv); | 72 DCHECK(rv); |
73 data_[i] = reinterpret_cast<uint8_t*>(buffers_[i]->memory(0u)); | 73 data_[i] = reinterpret_cast<uint8_t*>(buffers_[i]->memory(0u)); |
74 strides_[i] = width; | 74 strides_[i] = width; |
75 } | 75 } |
76 } | 76 } |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 double consumer_resource_utilization = -1.0; | 552 double consumer_resource_utilization = -1.0; |
553 if (!metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION, | 553 if (!metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION, |
554 &consumer_resource_utilization)) { | 554 &consumer_resource_utilization)) { |
555 consumer_resource_utilization = -1.0; | 555 consumer_resource_utilization = -1.0; |
556 } | 556 } |
557 | 557 |
558 callback_to_io_thread.Run(*release_sync_token, consumer_resource_utilization); | 558 callback_to_io_thread.Run(*release_sync_token, consumer_resource_utilization); |
559 } | 559 } |
560 | 560 |
561 } // namespace content | 561 } // namespace content |
OLD | NEW |