| 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 "media/capture/video/video_capture_buffer_pool_impl.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/renderer_host/media/video_capture_buffer_handle.h" | 13 #include "media/capture/video/video_capture_buffer_tracker.h" |
| 14 #include "content/browser/renderer_host/media/video_capture_buffer_tracker.h" | |
| 15 #include "content/browser/renderer_host/media/video_capture_buffer_tracker_facto
ry.h" | |
| 16 #include "ui/gfx/buffer_format_util.h" | 14 #include "ui/gfx/buffer_format_util.h" |
| 17 | 15 |
| 18 namespace content { | 16 namespace media { |
| 19 | 17 |
| 20 VideoCaptureBufferPoolImpl::VideoCaptureBufferPoolImpl(int count) | 18 VideoCaptureBufferPoolImpl::VideoCaptureBufferPoolImpl( |
| 19 std::unique_ptr<VideoCaptureBufferTrackerFactory> buffer_tracker_factory, |
| 20 int count) |
| 21 : count_(count), | 21 : count_(count), |
| 22 next_buffer_id_(0), | 22 next_buffer_id_(0), |
| 23 last_relinquished_buffer_id_(kInvalidId) { | 23 last_relinquished_buffer_id_(kInvalidId), |
| 24 buffer_tracker_factory_(std::move(buffer_tracker_factory)) { |
| 24 DCHECK_GT(count, 0); | 25 DCHECK_GT(count, 0); |
| 25 } | 26 } |
| 26 | 27 |
| 27 VideoCaptureBufferPoolImpl::~VideoCaptureBufferPoolImpl() { | 28 VideoCaptureBufferPoolImpl::~VideoCaptureBufferPoolImpl() { |
| 28 base::STLDeleteValues(&trackers_); | 29 base::STLDeleteValues(&trackers_); |
| 29 } | 30 } |
| 30 | 31 |
| 31 bool VideoCaptureBufferPoolImpl::ShareToProcess( | 32 bool VideoCaptureBufferPoolImpl::ShareToProcess( |
| 32 int buffer_id, | 33 int buffer_id, |
| 33 base::ProcessHandle process_handle, | 34 base::ProcessHandle process_handle, |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 last_relinquished_buffer_id_ = kInvalidId; | 230 last_relinquished_buffer_id_ = kInvalidId; |
| 230 *buffer_id_to_drop = tracker_to_drop->first; | 231 *buffer_id_to_drop = tracker_to_drop->first; |
| 231 delete tracker_to_drop->second; | 232 delete tracker_to_drop->second; |
| 232 trackers_.erase(tracker_to_drop); | 233 trackers_.erase(tracker_to_drop); |
| 233 } | 234 } |
| 234 | 235 |
| 235 // Create the new tracker. | 236 // Create the new tracker. |
| 236 const int buffer_id = next_buffer_id_++; | 237 const int buffer_id = next_buffer_id_++; |
| 237 | 238 |
| 238 std::unique_ptr<VideoCaptureBufferTracker> tracker = | 239 std::unique_ptr<VideoCaptureBufferTracker> tracker = |
| 239 VideoCaptureBufferTrackerFactory::CreateTracker(storage_type); | 240 buffer_tracker_factory_->CreateTracker(storage_type); |
| 240 // TODO(emircan): We pass the lock here to solve GMB allocation issue, see | 241 // TODO(emircan): We pass the lock here to solve GMB allocation issue, see |
| 241 // crbug.com/545238. | 242 // crbug.com/545238. |
| 242 if (!tracker->Init(dimensions, pixel_format, storage_type, &lock_)) { | 243 if (!tracker->Init(dimensions, pixel_format, storage_type, &lock_)) { |
| 243 DLOG(ERROR) << "Error initializing VideoCaptureBufferTracker"; | 244 DLOG(ERROR) << "Error initializing VideoCaptureBufferTracker"; |
| 244 return kInvalidId; | 245 return kInvalidId; |
| 245 } | 246 } |
| 246 | 247 |
| 247 tracker->set_held_by_producer(true); | 248 tracker->set_held_by_producer(true); |
| 248 trackers_[buffer_id] = tracker.release(); | 249 trackers_[buffer_id] = tracker.release(); |
| 249 | 250 |
| 250 return buffer_id; | 251 return buffer_id; |
| 251 } | 252 } |
| 252 | 253 |
| 253 VideoCaptureBufferTracker* VideoCaptureBufferPoolImpl::GetTracker( | 254 VideoCaptureBufferTracker* VideoCaptureBufferPoolImpl::GetTracker( |
| 254 int buffer_id) { | 255 int buffer_id) { |
| 255 TrackerMap::const_iterator it = trackers_.find(buffer_id); | 256 TrackerMap::const_iterator it = trackers_.find(buffer_id); |
| 256 return (it == trackers_.end()) ? NULL : it->second; | 257 return (it == trackers_.end()) ? NULL : it->second; |
| 257 } | 258 } |
| 258 | 259 |
| 259 } // namespace content | 260 } // namespace media |
| OLD | NEW |