| 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 VideoCaptureBufferPoolImpl::GetHandleForTransit( | 30 mojo::ScopedSharedBufferHandle |
| 31 int buffer_id) { | 31 VideoCaptureBufferPoolImpl::GetHandleForInterProcessTransit(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 base::SharedMemoryHandle |
| 43 VideoCaptureBufferPoolImpl::GetBufferHandle(int buffer_id) { | 43 VideoCaptureBufferPoolImpl::GetNonOwnedSharedMemoryHandleForLegacyIPC( |
| 44 int buffer_id) { |
| 44 base::AutoLock lock(lock_); | 45 base::AutoLock lock(lock_); |
| 45 | 46 |
| 46 VideoCaptureBufferTracker* tracker = GetTracker(buffer_id); | 47 VideoCaptureBufferTracker* tracker = GetTracker(buffer_id); |
| 47 if (!tracker) { | 48 if (!tracker) { |
| 48 NOTREACHED() << "Invalid buffer_id."; | 49 NOTREACHED() << "Invalid buffer_id."; |
| 49 return std::unique_ptr<VideoCaptureBufferHandle>(); | 50 return base::SharedMemoryHandle(); |
| 51 } |
| 52 return tracker->GetNonOwnedSharedMemoryHandleForLegacyIPC(); |
| 53 } |
| 54 |
| 55 std::unique_ptr<VideoCaptureBufferHandle> |
| 56 VideoCaptureBufferPoolImpl::GetHandleForInProcessAccess(int buffer_id) { |
| 57 base::AutoLock lock(lock_); |
| 58 |
| 59 VideoCaptureBufferTracker* tracker = GetTracker(buffer_id); |
| 60 if (!tracker) { |
| 61 NOTREACHED() << "Invalid buffer_id."; |
| 62 return nullptr; |
| 50 } | 63 } |
| 51 | 64 |
| 52 DCHECK(tracker->held_by_producer()); | 65 return tracker->GetMemoryMappedAccess(); |
| 53 return tracker->GetBufferHandle(); | |
| 54 } | 66 } |
| 55 | 67 |
| 56 int VideoCaptureBufferPoolImpl::ReserveForProducer( | 68 int VideoCaptureBufferPoolImpl::ReserveForProducer( |
| 57 const gfx::Size& dimensions, | 69 const gfx::Size& dimensions, |
| 58 media::VideoPixelFormat format, | 70 media::VideoPixelFormat format, |
| 59 media::VideoPixelStorage storage, | 71 media::VideoPixelStorage storage, |
| 60 int frame_feedback_id, | 72 int frame_feedback_id, |
| 61 int* buffer_id_to_drop) { | 73 int* buffer_id_to_drop) { |
| 62 base::AutoLock lock(lock_); | 74 base::AutoLock lock(lock_); |
| 63 return ReserveForProducerInternal(dimensions, format, storage, | 75 return ReserveForProducerInternal(dimensions, format, storage, |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 return buffer_id; | 241 return buffer_id; |
| 230 } | 242 } |
| 231 | 243 |
| 232 VideoCaptureBufferTracker* VideoCaptureBufferPoolImpl::GetTracker( | 244 VideoCaptureBufferTracker* VideoCaptureBufferPoolImpl::GetTracker( |
| 233 int buffer_id) { | 245 int buffer_id) { |
| 234 auto it = trackers_.find(buffer_id); | 246 auto it = trackers_.find(buffer_id); |
| 235 return (it == trackers_.end()) ? nullptr : it->second.get(); | 247 return (it == trackers_.end()) ? nullptr : it->second.get(); |
| 236 } | 248 } |
| 237 | 249 |
| 238 } // namespace media | 250 } // namespace media |
| OLD | NEW |