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/gpu/browser_gpu_memory_buffer_manager.h" |
14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.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 const int VideoCaptureBufferPool::kInvalidId = -1; | |
20 | |
21 // Tracker specifics for SharedMemory. | 19 // Tracker specifics for SharedMemory. |
22 class VideoCaptureBufferPool::SharedMemTracker final : public Tracker { | 20 class VideoCaptureBufferPool::SharedMemTracker final : public Tracker { |
23 public: | 21 public: |
24 SharedMemTracker() : Tracker() {} | 22 SharedMemTracker() : Tracker() {} |
25 | 23 |
26 bool Init(const gfx::Size& dimensions, | 24 bool Init(const gfx::Size& dimensions, |
27 media::VideoPixelFormat format, | 25 media::VideoPixelFormat format, |
28 media::VideoPixelStorage storage_type, | 26 media::VideoPixelStorage storage_type, |
29 base::Lock* lock) override { | 27 base::Lock* lock) override { |
30 DVLOG(2) << "allocating ShMem of " << dimensions.ToString(); | 28 DVLOG(2) << "allocating ShMem of " << dimensions.ToString(); |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 it->second->storage_type() == storage) { | 376 it->second->storage_type() == storage) { |
379 it->second->set_held_by_producer(true); | 377 it->second->set_held_by_producer(true); |
380 const int resurrected_buffer_id = last_relinquished_buffer_id_; | 378 const int resurrected_buffer_id = last_relinquished_buffer_id_; |
381 last_relinquished_buffer_id_ = kInvalidId; | 379 last_relinquished_buffer_id_ = kInvalidId; |
382 return resurrected_buffer_id; | 380 return resurrected_buffer_id; |
383 } | 381 } |
384 | 382 |
385 return kInvalidId; | 383 return kInvalidId; |
386 } | 384 } |
387 | 385 |
388 double VideoCaptureBufferPool::GetBufferPoolUtilization() const { | 386 double VideoCaptureBufferPool::GetBufferPoolUtilization() { |
389 base::AutoLock lock(lock_); | 387 base::AutoLock lock(lock_); |
390 int num_buffers_held = 0; | 388 int num_buffers_held = 0; |
391 for (const auto& entry : trackers_) { | 389 for (const auto& entry : trackers_) { |
392 Tracker* const tracker = entry.second; | 390 Tracker* const tracker = entry.second; |
393 if (tracker->held_by_producer() || tracker->consumer_hold_count() > 0) | 391 if (tracker->held_by_producer() || tracker->consumer_hold_count() > 0) |
394 ++num_buffers_held; | 392 ++num_buffers_held; |
395 } | 393 } |
396 return static_cast<double>(num_buffers_held) / count_; | 394 return static_cast<double>(num_buffers_held) / count_; |
397 } | 395 } |
398 | 396 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 return buffer_id; | 472 return buffer_id; |
475 } | 473 } |
476 | 474 |
477 VideoCaptureBufferPool::Tracker* VideoCaptureBufferPool::GetTracker( | 475 VideoCaptureBufferPool::Tracker* VideoCaptureBufferPool::GetTracker( |
478 int buffer_id) { | 476 int buffer_id) { |
479 TrackerMap::const_iterator it = trackers_.find(buffer_id); | 477 TrackerMap::const_iterator it = trackers_.find(buffer_id); |
480 return (it == trackers_.end()) ? NULL : it->second; | 478 return (it == trackers_.end()) ? NULL : it->second; |
481 } | 479 } |
482 | 480 |
483 } // namespace content | 481 } // namespace content |
OLD | NEW |