OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_buffer_pool.h" | 5 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 13 #include "content/browser/renderer_host/media/video_capture_buffer_tracker.h" |
14 #include "content/public/browser/browser_thread.h" | 14 #include "content/browser/renderer_host/media/video_capture_buffer_tracker_facto
ry.h" |
15 #include "ui/gfx/buffer_format_util.h" | 15 #include "ui/gfx/buffer_format_util.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 | 18 |
19 // Tracker specifics for SharedMemory. | |
20 class VideoCaptureBufferPoolImpl::SharedMemTracker final : public Tracker { | |
21 public: | |
22 SharedMemTracker() : Tracker() {} | |
23 | |
24 bool Init(const gfx::Size& dimensions, | |
25 media::VideoPixelFormat format, | |
26 media::VideoPixelStorage storage_type, | |
27 base::Lock* lock) override { | |
28 DVLOG(2) << "allocating ShMem of " << dimensions.ToString(); | |
29 set_dimensions(dimensions); | |
30 // |dimensions| can be 0x0 for trackers that do not require memory backing. | |
31 set_max_pixel_count(dimensions.GetArea()); | |
32 set_pixel_format(format); | |
33 set_storage_type(storage_type); | |
34 mapped_size_ = | |
35 media::VideoCaptureFormat(dimensions, 0.0f, format, storage_type) | |
36 .ImageAllocationSize(); | |
37 if (!mapped_size_) | |
38 return true; | |
39 return shared_memory_.CreateAndMapAnonymous(mapped_size_); | |
40 } | |
41 | |
42 std::unique_ptr<BufferHandle> GetBufferHandle() override { | |
43 return base::MakeUnique<SharedMemBufferHandle>(this); | |
44 } | |
45 bool ShareToProcess(base::ProcessHandle process_handle, | |
46 base::SharedMemoryHandle* new_handle) override { | |
47 return shared_memory_.ShareToProcess(process_handle, new_handle); | |
48 } | |
49 bool ShareToProcess2(int plane, | |
50 base::ProcessHandle process_handle, | |
51 gfx::GpuMemoryBufferHandle* new_handle) override { | |
52 NOTREACHED(); | |
53 return false; | |
54 } | |
55 | |
56 private: | |
57 // A simple proxy that implements the BufferHandle interface, providing | |
58 // accessors to SharedMemTracker's memory and properties. | |
59 class SharedMemBufferHandle | |
60 : public VideoCaptureBufferPoolImpl::BufferHandle { | |
61 public: | |
62 // |tracker| must outlive SimpleBufferHandle. This is ensured since a | |
63 // tracker is pinned until ownership of this SimpleBufferHandle is returned | |
64 // to VideoCaptureBufferPoolImpl. | |
65 explicit SharedMemBufferHandle(SharedMemTracker* tracker) | |
66 : tracker_(tracker) {} | |
67 ~SharedMemBufferHandle() override {} | |
68 | |
69 gfx::Size dimensions() const override { return tracker_->dimensions(); } | |
70 size_t mapped_size() const override { return tracker_->mapped_size_; } | |
71 void* data(int plane) override { | |
72 DCHECK_EQ(plane, 0); | |
73 return tracker_->shared_memory_.memory(); | |
74 } | |
75 ClientBuffer AsClientBuffer(int plane) override { | |
76 NOTREACHED(); | |
77 return nullptr; | |
78 } | |
79 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
80 base::FileDescriptor AsPlatformFile() override { | |
81 return tracker_->shared_memory_.handle(); | |
82 } | |
83 #endif | |
84 | |
85 private: | |
86 SharedMemTracker* const tracker_; | |
87 }; | |
88 | |
89 // The memory created to be shared with renderer processes. | |
90 base::SharedMemory shared_memory_; | |
91 size_t mapped_size_; | |
92 }; | |
93 | |
94 // Tracker specifics for GpuMemoryBuffer. Owns GpuMemoryBuffers and its | |
95 // associated pixel dimensions. | |
96 class VideoCaptureBufferPoolImpl::GpuMemoryBufferTracker final | |
97 : public Tracker { | |
98 public: | |
99 GpuMemoryBufferTracker() : Tracker() {} | |
100 | |
101 ~GpuMemoryBufferTracker() override { | |
102 for (const auto& gmb : gpu_memory_buffers_) | |
103 gmb->Unmap(); | |
104 } | |
105 | |
106 bool Init(const gfx::Size& dimensions, | |
107 media::VideoPixelFormat format, | |
108 media::VideoPixelStorage storage_type, | |
109 base::Lock* lock) override { | |
110 DVLOG(2) << "allocating GMB for " << dimensions.ToString(); | |
111 // BrowserGpuMemoryBufferManager::current() may not be accessed on IO | |
112 // Thread. | |
113 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
114 DCHECK(BrowserGpuMemoryBufferManager::current()); | |
115 // This class is only expected to be called with I420 buffer requests at | |
116 // this point. | |
117 DCHECK_EQ(format, media::PIXEL_FORMAT_I420); | |
118 set_dimensions(dimensions); | |
119 set_max_pixel_count(dimensions.GetArea()); | |
120 set_pixel_format(format); | |
121 set_storage_type(storage_type); | |
122 // |dimensions| can be 0x0 for trackers that do not require memory backing. | |
123 if (dimensions.GetArea() == 0u) | |
124 return true; | |
125 | |
126 base::AutoUnlock auto_unlock(*lock); | |
127 const size_t num_planes = media::VideoFrame::NumPlanes(pixel_format()); | |
128 for (size_t i = 0; i < num_planes; ++i) { | |
129 const gfx::Size& size = | |
130 media::VideoFrame::PlaneSize(pixel_format(), i, dimensions); | |
131 gpu_memory_buffers_.push_back( | |
132 BrowserGpuMemoryBufferManager::current()->AllocateGpuMemoryBuffer( | |
133 size, gfx::BufferFormat::R_8, | |
134 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, | |
135 gpu::kNullSurfaceHandle)); | |
136 | |
137 DLOG_IF(ERROR, !gpu_memory_buffers_[i]) << "Allocating GpuMemoryBuffer"; | |
138 if (!gpu_memory_buffers_[i] || !gpu_memory_buffers_[i]->Map()) | |
139 return false; | |
140 } | |
141 return true; | |
142 } | |
143 | |
144 std::unique_ptr<BufferHandle> GetBufferHandle() override { | |
145 DCHECK_EQ(gpu_memory_buffers_.size(), | |
146 media::VideoFrame::NumPlanes(pixel_format())); | |
147 return base::MakeUnique<GpuMemoryBufferBufferHandle>(this); | |
148 } | |
149 | |
150 bool ShareToProcess(base::ProcessHandle process_handle, | |
151 base::SharedMemoryHandle* new_handle) override { | |
152 NOTREACHED(); | |
153 return false; | |
154 } | |
155 | |
156 bool ShareToProcess2(int plane, | |
157 base::ProcessHandle process_handle, | |
158 gfx::GpuMemoryBufferHandle* new_handle) override { | |
159 DCHECK_LE(plane, static_cast<int>(gpu_memory_buffers_.size())); | |
160 | |
161 const auto& current_gmb_handle = gpu_memory_buffers_[plane]->GetHandle(); | |
162 switch (current_gmb_handle.type) { | |
163 case gfx::EMPTY_BUFFER: | |
164 NOTREACHED(); | |
165 return false; | |
166 case gfx::SHARED_MEMORY_BUFFER: { | |
167 DCHECK(base::SharedMemory::IsHandleValid(current_gmb_handle.handle)); | |
168 base::SharedMemory shared_memory( | |
169 base::SharedMemory::DuplicateHandle(current_gmb_handle.handle), | |
170 false); | |
171 shared_memory.ShareToProcess(process_handle, &new_handle->handle); | |
172 DCHECK(base::SharedMemory::IsHandleValid(new_handle->handle)); | |
173 new_handle->type = gfx::SHARED_MEMORY_BUFFER; | |
174 return true; | |
175 } | |
176 case gfx::IO_SURFACE_BUFFER: | |
177 case gfx::SURFACE_TEXTURE_BUFFER: | |
178 case gfx::OZONE_NATIVE_PIXMAP: | |
179 *new_handle = current_gmb_handle; | |
180 return true; | |
181 } | |
182 NOTREACHED(); | |
183 return true; | |
184 } | |
185 | |
186 private: | |
187 // A simple proxy that implements the BufferHandle interface, providing | |
188 // accessors to GpuMemoryBufferTracker's memory and properties. | |
189 class GpuMemoryBufferBufferHandle | |
190 : public VideoCaptureBufferPoolImpl::BufferHandle { | |
191 public: | |
192 // |tracker| must outlive GpuMemoryBufferBufferHandle. This is ensured since | |
193 // a tracker is pinned until ownership of this GpuMemoryBufferBufferHandle | |
194 // is returned to VideoCaptureBufferPoolImpl. | |
195 explicit GpuMemoryBufferBufferHandle(GpuMemoryBufferTracker* tracker) | |
196 : tracker_(tracker) {} | |
197 ~GpuMemoryBufferBufferHandle() override {} | |
198 | |
199 gfx::Size dimensions() const override { return tracker_->dimensions(); } | |
200 size_t mapped_size() const override { | |
201 return tracker_->dimensions().GetArea(); | |
202 } | |
203 void* data(int plane) override { | |
204 DCHECK_GE(plane, 0); | |
205 DCHECK_LT(plane, static_cast<int>(tracker_->gpu_memory_buffers_.size())); | |
206 DCHECK(tracker_->gpu_memory_buffers_[plane]); | |
207 return tracker_->gpu_memory_buffers_[plane]->memory(0); | |
208 } | |
209 ClientBuffer AsClientBuffer(int plane) override { | |
210 DCHECK_GE(plane, 0); | |
211 DCHECK_LT(plane, static_cast<int>(tracker_->gpu_memory_buffers_.size())); | |
212 return tracker_->gpu_memory_buffers_[plane]->AsClientBuffer(); | |
213 } | |
214 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
215 base::FileDescriptor AsPlatformFile() override { | |
216 NOTREACHED(); | |
217 return base::FileDescriptor(); | |
218 } | |
219 #endif | |
220 | |
221 private: | |
222 GpuMemoryBufferTracker* const tracker_; | |
223 }; | |
224 | |
225 // Owned references to GpuMemoryBuffers. | |
226 std::vector<std::unique_ptr<gfx::GpuMemoryBuffer>> gpu_memory_buffers_; | |
227 }; | |
228 | |
229 // static | |
230 std::unique_ptr<VideoCaptureBufferPoolImpl::Tracker> | |
231 VideoCaptureBufferPoolImpl::Tracker::CreateTracker( | |
232 media::VideoPixelStorage storage) { | |
233 switch (storage) { | |
234 case media::PIXEL_STORAGE_GPUMEMORYBUFFER: | |
235 return base::MakeUnique<GpuMemoryBufferTracker>(); | |
236 case media::PIXEL_STORAGE_CPU: | |
237 return base::MakeUnique<SharedMemTracker>(); | |
238 } | |
239 NOTREACHED(); | |
240 return std::unique_ptr<VideoCaptureBufferPoolImpl::Tracker>(); | |
241 } | |
242 | |
243 VideoCaptureBufferPoolImpl::Tracker::~Tracker() {} | |
244 | |
245 VideoCaptureBufferPoolImpl::VideoCaptureBufferPoolImpl(int count) | 19 VideoCaptureBufferPoolImpl::VideoCaptureBufferPoolImpl(int count) |
246 : count_(count), | 20 : count_(count), |
247 next_buffer_id_(0), | 21 next_buffer_id_(0), |
248 last_relinquished_buffer_id_(kInvalidId) { | 22 last_relinquished_buffer_id_(kInvalidId) { |
249 DCHECK_GT(count, 0); | 23 DCHECK_GT(count, 0); |
250 } | 24 } |
251 | 25 |
252 VideoCaptureBufferPoolImpl::~VideoCaptureBufferPoolImpl() { | 26 VideoCaptureBufferPoolImpl::~VideoCaptureBufferPoolImpl() { |
253 base::STLDeleteValues(&trackers_); | 27 base::STLDeleteValues(&trackers_); |
254 } | 28 } |
255 | 29 |
256 bool VideoCaptureBufferPoolImpl::ShareToProcess( | 30 bool VideoCaptureBufferPoolImpl::ShareToProcess( |
257 int buffer_id, | 31 int buffer_id, |
258 base::ProcessHandle process_handle, | 32 base::ProcessHandle process_handle, |
259 base::SharedMemoryHandle* new_handle) { | 33 base::SharedMemoryHandle* new_handle) { |
260 base::AutoLock lock(lock_); | 34 base::AutoLock lock(lock_); |
261 | 35 |
262 Tracker* tracker = GetTracker(buffer_id); | 36 VideoCaptureBufferTracker* tracker = GetTracker(buffer_id); |
263 if (!tracker) { | 37 if (!tracker) { |
264 NOTREACHED() << "Invalid buffer_id."; | 38 NOTREACHED() << "Invalid buffer_id."; |
265 return false; | 39 return false; |
266 } | 40 } |
267 if (tracker->ShareToProcess(process_handle, new_handle)) | 41 if (tracker->ShareToProcess(process_handle, new_handle)) |
268 return true; | 42 return true; |
269 DPLOG(ERROR) << "Error mapping memory"; | 43 DPLOG(ERROR) << "Error mapping memory"; |
270 return false; | 44 return false; |
271 } | 45 } |
272 | 46 |
273 bool VideoCaptureBufferPoolImpl::ShareToProcess2( | 47 bool VideoCaptureBufferPoolImpl::ShareToProcess2( |
274 int buffer_id, | 48 int buffer_id, |
275 int plane, | 49 int plane, |
276 base::ProcessHandle process_handle, | 50 base::ProcessHandle process_handle, |
277 gfx::GpuMemoryBufferHandle* new_handle) { | 51 gfx::GpuMemoryBufferHandle* new_handle) { |
278 base::AutoLock lock(lock_); | 52 base::AutoLock lock(lock_); |
279 | 53 |
280 Tracker* tracker = GetTracker(buffer_id); | 54 VideoCaptureBufferTracker* tracker = GetTracker(buffer_id); |
281 if (!tracker) { | 55 if (!tracker) { |
282 NOTREACHED() << "Invalid buffer_id."; | 56 NOTREACHED() << "Invalid buffer_id."; |
283 return false; | 57 return false; |
284 } | 58 } |
285 if (tracker->ShareToProcess2(plane, process_handle, new_handle)) | 59 if (tracker->ShareToProcess2(plane, process_handle, new_handle)) |
286 return true; | 60 return true; |
287 DPLOG(ERROR) << "Error mapping memory"; | 61 DPLOG(ERROR) << "Error mapping memory"; |
288 return false; | 62 return false; |
289 } | 63 } |
290 | 64 |
291 std::unique_ptr<VideoCaptureBufferPoolImpl::BufferHandle> | 65 std::unique_ptr<VideoCaptureBufferHandle> |
292 VideoCaptureBufferPoolImpl::GetBufferHandle(int buffer_id) { | 66 VideoCaptureBufferPoolImpl::GetBufferHandle(int buffer_id) { |
293 base::AutoLock lock(lock_); | 67 base::AutoLock lock(lock_); |
294 | 68 |
295 Tracker* tracker = GetTracker(buffer_id); | 69 VideoCaptureBufferTracker* tracker = GetTracker(buffer_id); |
296 if (!tracker) { | 70 if (!tracker) { |
297 NOTREACHED() << "Invalid buffer_id."; | 71 NOTREACHED() << "Invalid buffer_id."; |
298 return std::unique_ptr<BufferHandle>(); | 72 return std::unique_ptr<VideoCaptureBufferHandle>(); |
299 } | 73 } |
300 | 74 |
301 DCHECK(tracker->held_by_producer()); | 75 DCHECK(tracker->held_by_producer()); |
302 return tracker->GetBufferHandle(); | 76 return tracker->GetBufferHandle(); |
303 } | 77 } |
304 | 78 |
305 int VideoCaptureBufferPoolImpl::ReserveForProducer( | 79 int VideoCaptureBufferPoolImpl::ReserveForProducer( |
306 const gfx::Size& dimensions, | 80 const gfx::Size& dimensions, |
307 media::VideoPixelFormat format, | 81 media::VideoPixelFormat format, |
308 media::VideoPixelStorage storage, | 82 media::VideoPixelStorage storage, |
309 int* buffer_id_to_drop) { | 83 int* buffer_id_to_drop) { |
310 base::AutoLock lock(lock_); | 84 base::AutoLock lock(lock_); |
311 return ReserveForProducerInternal(dimensions, format, storage, | 85 return ReserveForProducerInternal(dimensions, format, storage, |
312 buffer_id_to_drop); | 86 buffer_id_to_drop); |
313 } | 87 } |
314 | 88 |
315 void VideoCaptureBufferPoolImpl::RelinquishProducerReservation(int buffer_id) { | 89 void VideoCaptureBufferPoolImpl::RelinquishProducerReservation(int buffer_id) { |
316 base::AutoLock lock(lock_); | 90 base::AutoLock lock(lock_); |
317 Tracker* tracker = GetTracker(buffer_id); | 91 VideoCaptureBufferTracker* tracker = GetTracker(buffer_id); |
318 if (!tracker) { | 92 if (!tracker) { |
319 NOTREACHED() << "Invalid buffer_id."; | 93 NOTREACHED() << "Invalid buffer_id."; |
320 return; | 94 return; |
321 } | 95 } |
322 DCHECK(tracker->held_by_producer()); | 96 DCHECK(tracker->held_by_producer()); |
323 tracker->set_held_by_producer(false); | 97 tracker->set_held_by_producer(false); |
324 last_relinquished_buffer_id_ = buffer_id; | 98 last_relinquished_buffer_id_ = buffer_id; |
325 } | 99 } |
326 | 100 |
327 void VideoCaptureBufferPoolImpl::HoldForConsumers(int buffer_id, | 101 void VideoCaptureBufferPoolImpl::HoldForConsumers(int buffer_id, |
328 int num_clients) { | 102 int num_clients) { |
329 base::AutoLock lock(lock_); | 103 base::AutoLock lock(lock_); |
330 Tracker* tracker = GetTracker(buffer_id); | 104 VideoCaptureBufferTracker* tracker = GetTracker(buffer_id); |
331 if (!tracker) { | 105 if (!tracker) { |
332 NOTREACHED() << "Invalid buffer_id."; | 106 NOTREACHED() << "Invalid buffer_id."; |
333 return; | 107 return; |
334 } | 108 } |
335 DCHECK(tracker->held_by_producer()); | 109 DCHECK(tracker->held_by_producer()); |
336 DCHECK(!tracker->consumer_hold_count()); | 110 DCHECK(!tracker->consumer_hold_count()); |
337 | 111 |
338 tracker->set_consumer_hold_count(num_clients); | 112 tracker->set_consumer_hold_count(num_clients); |
339 // Note: |held_by_producer()| will stay true until | 113 // Note: |held_by_producer()| will stay true until |
340 // RelinquishProducerReservation() (usually called by destructor of the object | 114 // RelinquishProducerReservation() (usually called by destructor of the object |
341 // wrapping this tracker, e.g. a media::VideoFrame). | 115 // wrapping this tracker, e.g. a media::VideoFrame). |
342 } | 116 } |
343 | 117 |
344 void VideoCaptureBufferPoolImpl::RelinquishConsumerHold(int buffer_id, | 118 void VideoCaptureBufferPoolImpl::RelinquishConsumerHold(int buffer_id, |
345 int num_clients) { | 119 int num_clients) { |
346 base::AutoLock lock(lock_); | 120 base::AutoLock lock(lock_); |
347 Tracker* tracker = GetTracker(buffer_id); | 121 VideoCaptureBufferTracker* tracker = GetTracker(buffer_id); |
348 if (!tracker) { | 122 if (!tracker) { |
349 NOTREACHED() << "Invalid buffer_id."; | 123 NOTREACHED() << "Invalid buffer_id."; |
350 return; | 124 return; |
351 } | 125 } |
352 DCHECK_GE(tracker->consumer_hold_count(), num_clients); | 126 DCHECK_GE(tracker->consumer_hold_count(), num_clients); |
353 | 127 |
354 tracker->set_consumer_hold_count(tracker->consumer_hold_count() - | 128 tracker->set_consumer_hold_count(tracker->consumer_hold_count() - |
355 num_clients); | 129 num_clients); |
356 } | 130 } |
357 | 131 |
(...skipping 24 matching lines...) Expand all Loading... |
382 return resurrected_buffer_id; | 156 return resurrected_buffer_id; |
383 } | 157 } |
384 | 158 |
385 return kInvalidId; | 159 return kInvalidId; |
386 } | 160 } |
387 | 161 |
388 double VideoCaptureBufferPoolImpl::GetBufferPoolUtilization() const { | 162 double VideoCaptureBufferPoolImpl::GetBufferPoolUtilization() const { |
389 base::AutoLock lock(lock_); | 163 base::AutoLock lock(lock_); |
390 int num_buffers_held = 0; | 164 int num_buffers_held = 0; |
391 for (const auto& entry : trackers_) { | 165 for (const auto& entry : trackers_) { |
392 Tracker* const tracker = entry.second; | 166 VideoCaptureBufferTracker* const tracker = entry.second; |
393 if (tracker->held_by_producer() || tracker->consumer_hold_count() > 0) | 167 if (tracker->held_by_producer() || tracker->consumer_hold_count() > 0) |
394 ++num_buffers_held; | 168 ++num_buffers_held; |
395 } | 169 } |
396 return static_cast<double>(num_buffers_held) / count_; | 170 return static_cast<double>(num_buffers_held) / count_; |
397 } | 171 } |
398 | 172 |
399 int VideoCaptureBufferPoolImpl::ReserveForProducerInternal( | 173 int VideoCaptureBufferPoolImpl::ReserveForProducerInternal( |
400 const gfx::Size& dimensions, | 174 const gfx::Size& dimensions, |
401 media::VideoPixelFormat pixel_format, | 175 media::VideoPixelFormat pixel_format, |
402 media::VideoPixelStorage storage_type, | 176 media::VideoPixelStorage storage_type, |
403 int* buffer_id_to_drop) { | 177 int* buffer_id_to_drop) { |
404 lock_.AssertAcquired(); | 178 lock_.AssertAcquired(); |
405 | 179 |
406 const size_t size_in_pixels = dimensions.GetArea(); | 180 const size_t size_in_pixels = dimensions.GetArea(); |
407 // Look for a tracker that's allocated, big enough, and not in use. Track the | 181 // Look for a tracker that's allocated, big enough, and not in use. Track the |
408 // largest one that's not big enough, in case we have to reallocate a tracker. | 182 // largest one that's not big enough, in case we have to reallocate a tracker. |
409 *buffer_id_to_drop = kInvalidId; | 183 *buffer_id_to_drop = kInvalidId; |
410 size_t largest_size_in_pixels = 0; | 184 size_t largest_size_in_pixels = 0; |
411 TrackerMap::iterator tracker_of_last_resort = trackers_.end(); | 185 TrackerMap::iterator tracker_of_last_resort = trackers_.end(); |
412 TrackerMap::iterator tracker_to_drop = trackers_.end(); | 186 TrackerMap::iterator tracker_to_drop = trackers_.end(); |
413 for (TrackerMap::iterator it = trackers_.begin(); it != trackers_.end(); | 187 for (TrackerMap::iterator it = trackers_.begin(); it != trackers_.end(); |
414 ++it) { | 188 ++it) { |
415 Tracker* const tracker = it->second; | 189 VideoCaptureBufferTracker* const tracker = it->second; |
416 if (!tracker->consumer_hold_count() && !tracker->held_by_producer()) { | 190 if (!tracker->consumer_hold_count() && !tracker->held_by_producer()) { |
417 if (tracker->max_pixel_count() >= size_in_pixels && | 191 if (tracker->max_pixel_count() >= size_in_pixels && |
418 (tracker->pixel_format() == pixel_format) && | 192 (tracker->pixel_format() == pixel_format) && |
419 (tracker->storage_type() == storage_type)) { | 193 (tracker->storage_type() == storage_type)) { |
420 if (it->first == last_relinquished_buffer_id_) { | 194 if (it->first == last_relinquished_buffer_id_) { |
421 // This buffer would do just fine, but avoid returning it because the | 195 // This buffer would do just fine, but avoid returning it because the |
422 // client may want to resurrect it. It will be returned perforce if | 196 // client may want to resurrect it. It will be returned perforce if |
423 // the pool has reached it's maximum limit (see code below). | 197 // the pool has reached it's maximum limit (see code below). |
424 tracker_of_last_resort = it; | 198 tracker_of_last_resort = it; |
425 continue; | 199 continue; |
(...skipping 27 matching lines...) Expand all Loading... |
453 if (tracker_to_drop->first == last_relinquished_buffer_id_) | 227 if (tracker_to_drop->first == last_relinquished_buffer_id_) |
454 last_relinquished_buffer_id_ = kInvalidId; | 228 last_relinquished_buffer_id_ = kInvalidId; |
455 *buffer_id_to_drop = tracker_to_drop->first; | 229 *buffer_id_to_drop = tracker_to_drop->first; |
456 delete tracker_to_drop->second; | 230 delete tracker_to_drop->second; |
457 trackers_.erase(tracker_to_drop); | 231 trackers_.erase(tracker_to_drop); |
458 } | 232 } |
459 | 233 |
460 // Create the new tracker. | 234 // Create the new tracker. |
461 const int buffer_id = next_buffer_id_++; | 235 const int buffer_id = next_buffer_id_++; |
462 | 236 |
463 std::unique_ptr<Tracker> tracker = Tracker::CreateTracker(storage_type); | 237 std::unique_ptr<VideoCaptureBufferTracker> tracker = |
| 238 VideoCaptureBufferTrackerFactory::CreateTracker(storage_type); |
464 // TODO(emircan): We pass the lock here to solve GMB allocation issue, see | 239 // TODO(emircan): We pass the lock here to solve GMB allocation issue, see |
465 // crbug.com/545238. | 240 // crbug.com/545238. |
466 if (!tracker->Init(dimensions, pixel_format, storage_type, &lock_)) { | 241 if (!tracker->Init(dimensions, pixel_format, storage_type, &lock_)) { |
467 DLOG(ERROR) << "Error initializing Tracker"; | 242 DLOG(ERROR) << "Error initializing VideoCaptureBufferTracker"; |
468 return kInvalidId; | 243 return kInvalidId; |
469 } | 244 } |
470 | 245 |
471 tracker->set_held_by_producer(true); | 246 tracker->set_held_by_producer(true); |
472 trackers_[buffer_id] = tracker.release(); | 247 trackers_[buffer_id] = tracker.release(); |
473 | 248 |
474 return buffer_id; | 249 return buffer_id; |
475 } | 250 } |
476 | 251 |
477 VideoCaptureBufferPoolImpl::Tracker* VideoCaptureBufferPoolImpl::GetTracker( | 252 VideoCaptureBufferTracker* VideoCaptureBufferPoolImpl::GetTracker( |
478 int buffer_id) { | 253 int buffer_id) { |
479 TrackerMap::const_iterator it = trackers_.find(buffer_id); | 254 TrackerMap::const_iterator it = trackers_.find(buffer_id); |
480 return (it == trackers_.end()) ? NULL : it->second; | 255 return (it == trackers_.end()) ? NULL : it->second; |
481 } | 256 } |
482 | 257 |
483 } // namespace content | 258 } // namespace content |
OLD | NEW |