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