| 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 "media/capture/video/video_capture_buffer_pool_impl.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 "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "media/capture/video/video_capture_buffer_handle.h" | 12 #include "media/capture/video/video_capture_buffer_handle.h" |
| 13 #include "media/capture/video/video_capture_buffer_tracker.h" | 13 #include "media/capture/video/video_capture_buffer_tracker.h" |
| 14 #include "ui/gfx/buffer_format_util.h" | 14 #include "ui/gfx/buffer_format_util.h" |
| 15 | 15 |
| 16 namespace media { | 16 namespace media { |
| 17 | 17 |
| 18 VideoCaptureBufferPoolImpl::VideoCaptureBufferPoolImpl( | 18 VideoCaptureBufferPoolImpl::VideoCaptureBufferPoolImpl( |
| 19 std::unique_ptr<VideoCaptureBufferTrackerFactory> buffer_tracker_factory, | 19 std::unique_ptr<VideoCaptureBufferTrackerFactory> buffer_tracker_factory, |
| 20 int count) | 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 buffer_tracker_factory_(std::move(buffer_tracker_factory)) { |
| 25 DCHECK_GT(count, 0); | 25 DCHECK_GT(count, 0); |
| 26 } | 26 } |
| 27 | 27 |
| 28 VideoCaptureBufferPoolImpl::~VideoCaptureBufferPoolImpl() {} | 28 VideoCaptureBufferPoolImpl::~VideoCaptureBufferPoolImpl() {} |
| 29 | 29 |
| 30 mojo::ScopedSharedBufferHandle | 30 mojo::ScopedSharedBufferHandle VideoCaptureBufferPoolImpl::GetHandleForTransit( |
| 31 VideoCaptureBufferPoolImpl::GetHandleForInterProcessTransit(int buffer_id) { | 31 int buffer_id) { |
| 32 base::AutoLock lock(lock_); | 32 base::AutoLock lock(lock_); |
| 33 | 33 |
| 34 VideoCaptureBufferTracker* tracker = GetTracker(buffer_id); | 34 VideoCaptureBufferTracker* tracker = GetTracker(buffer_id); |
| 35 if (!tracker) { | 35 if (!tracker) { |
| 36 NOTREACHED() << "Invalid buffer_id."; | 36 NOTREACHED() << "Invalid buffer_id."; |
| 37 return mojo::ScopedSharedBufferHandle(); | 37 return mojo::ScopedSharedBufferHandle(); |
| 38 } | 38 } |
| 39 return tracker->GetHandleForTransit(); | 39 return tracker->GetHandleForTransit(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 std::unique_ptr<VideoCaptureBufferHandle> | 42 std::unique_ptr<VideoCaptureBufferHandle> |
| 43 VideoCaptureBufferPoolImpl::GetHandleForInProcessAccess(int buffer_id) { | 43 VideoCaptureBufferPoolImpl::GetBufferHandle(int buffer_id) { |
| 44 base::AutoLock lock(lock_); | 44 base::AutoLock lock(lock_); |
| 45 | 45 |
| 46 VideoCaptureBufferTracker* tracker = GetTracker(buffer_id); | 46 VideoCaptureBufferTracker* tracker = GetTracker(buffer_id); |
| 47 if (!tracker) { | 47 if (!tracker) { |
| 48 NOTREACHED() << "Invalid buffer_id."; | 48 NOTREACHED() << "Invalid buffer_id."; |
| 49 return nullptr; | 49 return std::unique_ptr<VideoCaptureBufferHandle>(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 return tracker->GetMemoryMappedAccess(); | 52 DCHECK(tracker->held_by_producer()); |
| 53 return tracker->GetBufferHandle(); |
| 53 } | 54 } |
| 54 | 55 |
| 55 int VideoCaptureBufferPoolImpl::ReserveForProducer( | 56 int VideoCaptureBufferPoolImpl::ReserveForProducer( |
| 56 const gfx::Size& dimensions, | 57 const gfx::Size& dimensions, |
| 57 media::VideoPixelFormat format, | 58 media::VideoPixelFormat format, |
| 58 media::VideoPixelStorage storage, | 59 media::VideoPixelStorage storage, |
| 59 int frame_feedback_id, | 60 int frame_feedback_id, |
| 60 int* buffer_id_to_drop) { | 61 int* buffer_id_to_drop) { |
| 61 base::AutoLock lock(lock_); | 62 base::AutoLock lock(lock_); |
| 62 return ReserveForProducerInternal(dimensions, format, storage, | 63 return ReserveForProducerInternal(dimensions, format, storage, |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 return buffer_id; | 229 return buffer_id; |
| 229 } | 230 } |
| 230 | 231 |
| 231 VideoCaptureBufferTracker* VideoCaptureBufferPoolImpl::GetTracker( | 232 VideoCaptureBufferTracker* VideoCaptureBufferPoolImpl::GetTracker( |
| 232 int buffer_id) { | 233 int buffer_id) { |
| 233 auto it = trackers_.find(buffer_id); | 234 auto it = trackers_.find(buffer_id); |
| 234 return (it == trackers_.end()) ? nullptr : it->second.get(); | 235 return (it == trackers_.end()) ? nullptr : it->second.get(); |
| 235 } | 236 } |
| 236 | 237 |
| 237 } // namespace media | 238 } // namespace media |
| OLD | NEW |